synchro-charts
synchro-charts copied to clipboard
breachedThreshold doesn't return breached threshold
Describe the bug
When given multiple thresholds, and the datastream doesn't breach all of the thresholds, breachedThreshold
focuses on determining the order of the threshold and doesn't properly return any of the breached threshold.
To Reproduce Steps to reproduce the behavior:
- Create two thresholds, such as:
isEditable: true,
comparisonOperator: COMPARISON_OPERATOR.GREATER_THAN,
value: 25,
label: {
text: '2',
show: true,
},
showValue: true,
color: 'green',
id: 'green-y-threshold',
severity: 2,
};
const threshold2: Threshold<number> = {
isEditable: true,
comparisonOperator: COMPARISON_OPERATOR.LESS_THAN,
value: 35,
label: {
text: '1',
show: true,
},
showValue: true,
color: 'red',
id: 'red-y-threshold',
severity: 1,
};
Note that I added a severity
property to the thresholds, but testing this behavior with or without the severity both lead to the same incorrect behavior.
2. Create a data stream such as:
const dataStream = {
id: 'data-stream',
name: 'some name',
color: 'red',
resolution: 0,
data: [{ x: Date.now(), y: 20 }],
dataType: DataType.NUMBER,
};
- Call on
breachedThreshold
:
value: dataStream.data[0].y,
date: new Date(dataStream.data[0].x),
thresholds: [threshold1, threshold2],
dataStreams: [],
dataStream: dataStream as SynchroChartsDataStream,
});
-
breachedThresh
is undefined
Expected behavior
When given multiple thresholds, breachedThreshold
should return the threshold of the highest severity that has been breached. Whether a threshold is breached or not is independent of other thresholds and their severities. In the case of the example in the reproduction process, we expect breachedThresh
to be threshold2
since the datapoint breaches that threshold.
Screenshots https://user-images.githubusercontent.com/40257222/178842543-c582ac6c-bfe3-488e-8595-beaa65a797e8.mov
Desktop (please complete the following information):
- OS: macOS Monterey
- Browser Firefox
- Version 91.10.0esr