Skip to content

Commit 4fbc19a

Browse files
committed
fix: Fixed issue with thresholds.
1 parent 94d1cc3 commit 4fbc19a

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/utils/metricUtils.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,22 @@ export function thresholdValue(max: number, percentage: number): number {
3636
return (percentage * max) / 100
3737
}
3838

39-
export function useThresholds(defaultColor: Color, max: number, useDefaultThresholds = false) {
39+
export function useThresholds(
40+
defaultColor: Color,
41+
max: number,
42+
useDefaultThresholds = false
43+
) {
4044
const warningThreshold = useNumberField({
4145
field: 'warning_threshold',
42-
defaultValue: 50
46+
defaultValue: useDefaultThresholds ? 50 : 0
4347
})
4448
const warningColor = useColorField({
4549
field: 'warning_color',
4650
defaultColor: useDefaultThresholds ? '#ffff1e' : undefined
4751
})
4852
const criticalThreshold = useNumberField({
4953
field: 'critical_threshold',
50-
defaultValue: 90
54+
defaultValue: useDefaultThresholds ? 90 : 0
5155
})
5256
const criticalColor = useColorField({
5357
field: 'critical_color',
@@ -65,11 +69,11 @@ export function useThresholds(defaultColor: Color, max: number, useDefaultThresh
6569
getColor(value: number) {
6670
let color = defaultColor
6771

68-
if (value >= warningValue && value < criticalValue) {
72+
if (warningValue && warningColor.toRgbaCss() && value >= warningValue) {
6973
color = warningColor
7074
}
7175

72-
if (value >= criticalValue) {
76+
if (criticalValue && criticalColor.toRgbaCss() && value >= criticalValue) {
7377
color = criticalColor
7478
}
7579

src/widgets/DonutChart/DonutChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const DonutChart: FunctionComponent = () => {
2121
radius,
2222
value
2323
} = useDefaultPieFields()
24-
const { getColor } = useThresholds(color, max)
24+
const { getColor } = useThresholds(color, max, false)
2525
const metricConfigured = useIsMetricFieldConfigured({ field: 'metric' })
2626

2727
if (!metricConfigured) {

0 commit comments

Comments
 (0)