-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cae31f
commit 2d7ccfe
Showing
5 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/react-components/src/components/chart/converters/convertThresholds.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { AnnotationValue, COMPARISON_OPERATOR, ComparisonOperator, Threshold } from '@iot-app-kit/core'; | ||
import { COMPARATOR_MAP } from '../../../common/constants'; | ||
|
||
const comparisonOperatorToLowerYAxis = (comparisonOperator: ComparisonOperator, value: AnnotationValue) => { | ||
switch (comparisonOperator) { | ||
case COMPARISON_OPERATOR.GT: | ||
case COMPARISON_OPERATOR.GTE: | ||
case COMPARISON_OPERATOR.EQ: | ||
return value; | ||
case COMPARISON_OPERATOR.LT: | ||
case COMPARISON_OPERATOR.LTE: | ||
return 0; | ||
default: | ||
return undefined; | ||
} | ||
}; | ||
|
||
const comparisonOperatorToUpperYAxis = (comparisonOperator: ComparisonOperator, value: AnnotationValue) => { | ||
switch (comparisonOperator) { | ||
case COMPARISON_OPERATOR.LT: | ||
case COMPARISON_OPERATOR.LTE: | ||
case COMPARISON_OPERATOR.EQ: | ||
return value; | ||
default: | ||
return undefined; | ||
} | ||
}; | ||
|
||
export const convertThresholds = (thresholds?: Threshold[]) => { | ||
if (!thresholds || !thresholds.length) return {}; | ||
return { | ||
markLine: { | ||
silent: true, | ||
symbol: 'none', | ||
lineStyle: 'dashOffset', | ||
animation: false, | ||
data: thresholds | ||
.filter((t) => typeof t.value === 'number') | ||
.map((t) => ({ | ||
label: { | ||
formatter: `${COMPARATOR_MAP[t.comparisonOperator]} ${t.value}`, | ||
}, | ||
lineStyle: { | ||
color: t.color, | ||
}, | ||
yAxis: t.value, | ||
})), | ||
}, | ||
markArea: { | ||
silent: true, | ||
animation: false, | ||
data: thresholds | ||
.filter((t) => typeof t.value === 'number') | ||
.map(({ comparisonOperator, value, color }) => [ | ||
{ | ||
yAxis: comparisonOperatorToLowerYAxis(comparisonOperator, value), | ||
itemStyle: { | ||
color: color, | ||
opacity: 0.1, | ||
}, | ||
}, | ||
{ | ||
yAxis: comparisonOperatorToUpperYAxis(comparisonOperator, value), | ||
}, | ||
]), | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters