@centreon/ui 23.10.62 → 23.10.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Graph/Gauge/AnimatedPie.tsx +31 -20
- package/src/Graph/Gauge/Gauge.stories.tsx +97 -6
- package/src/Graph/Gauge/Gauge.tsx +4 -15
- package/src/Graph/Gauge/PieData.tsx +8 -24
- package/src/Graph/Gauge/ResponsiveGauge.tsx +11 -14
- package/src/Graph/Gauge/Thresholds.tsx +109 -56
- package/src/Graph/Gauge/models.ts +2 -3
- package/src/Graph/LineChart/BasicComponents/ThresholdLine.tsx +64 -0
- package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +31 -73
- package/src/Graph/LineChart/LineChart.tsx +14 -13
- package/src/Graph/LineChart/index.stories.tsx +67 -3
- package/src/Graph/LineChart/index.tsx +3 -9
- package/src/Graph/SingleBar/ResponsiveSingleBar.tsx +10 -8
- package/src/Graph/SingleBar/SingleBar.stories.tsx +119 -6
- package/src/Graph/SingleBar/ThresholdLine.tsx +74 -0
- package/src/Graph/SingleBar/Thresholds.tsx +28 -82
- package/src/Graph/SingleBar/models.ts +2 -4
- package/src/Graph/Text/Text.tsx +20 -16
- package/src/Graph/common/models.ts +12 -0
- package/src/Graph/common/utils.ts +59 -6
- package/src/utils/useThresholds.ts +0 -0
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Thresholds } from '../common/models';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export const barHeight = 50;
|
|
3
|
+
import { ThresholdLine } from './ThresholdLine';
|
|
6
4
|
|
|
7
5
|
export const groupMargin = 25;
|
|
8
6
|
|
|
9
|
-
const lineMargin = 10;
|
|
10
|
-
|
|
11
|
-
const thresholdLineHeight = 60 + 2 * lineMargin;
|
|
12
|
-
|
|
13
7
|
interface Props {
|
|
14
8
|
hideTooltip: () => void;
|
|
15
9
|
showTooltip: (args) => void;
|
|
16
|
-
|
|
17
|
-
thresholds: Array<number>;
|
|
10
|
+
thresholds: Thresholds;
|
|
18
11
|
xScale: (value: number) => number;
|
|
19
12
|
}
|
|
20
13
|
|
|
@@ -22,79 +15,32 @@ const Thresholds = ({
|
|
|
22
15
|
xScale,
|
|
23
16
|
thresholds,
|
|
24
17
|
showTooltip,
|
|
25
|
-
hideTooltip
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const onMouseEnter =
|
|
38
|
-
({ label, left }) =>
|
|
39
|
-
(): void =>
|
|
40
|
-
showTooltip({
|
|
41
|
-
tooltipData: label,
|
|
42
|
-
tooltipLeft: left,
|
|
43
|
-
tooltipTop: bottom
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<>
|
|
48
|
-
<line
|
|
49
|
-
data-testid="warning-line"
|
|
50
|
-
stroke={theme.palette.warning.main}
|
|
51
|
-
strokeDasharray={4}
|
|
52
|
-
strokeWidth={2}
|
|
53
|
-
x1={xScale(warningValue)}
|
|
54
|
-
x2={xScale(warningValue)}
|
|
55
|
-
y1={groupMargin + 3 * lineMargin}
|
|
56
|
-
y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
|
|
57
|
-
/>
|
|
58
|
-
<line
|
|
59
|
-
data-testid="critical-line"
|
|
60
|
-
stroke={theme.palette.error.main}
|
|
61
|
-
strokeDasharray={4}
|
|
62
|
-
strokeWidth={2}
|
|
63
|
-
x1={xScale(criticalValue)}
|
|
64
|
-
x2={xScale(criticalValue)}
|
|
65
|
-
y1={groupMargin + 3 * lineMargin}
|
|
66
|
-
y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
|
|
67
|
-
/>
|
|
68
|
-
<line
|
|
69
|
-
data-testid="warning-line-tooltip"
|
|
70
|
-
stroke="transparent"
|
|
71
|
-
strokeWidth={5}
|
|
72
|
-
x1={xScale(warningValue)}
|
|
73
|
-
x2={xScale(warningValue)}
|
|
74
|
-
y1={groupMargin + 3 * lineMargin}
|
|
75
|
-
y2={thresholdLineHeight + groupMargin + 3 * lineMargin}
|
|
76
|
-
onMouseEnter={onMouseEnter({
|
|
77
|
-
label: warningTooltipLabel,
|
|
78
|
-
left: xScale(warningValue)
|
|
79
|
-
})}
|
|
80
|
-
onMouseLeave={hideTooltip}
|
|
18
|
+
hideTooltip
|
|
19
|
+
}: Props): JSX.Element => (
|
|
20
|
+
<>
|
|
21
|
+
{thresholds.warning.map(({ value, label }) => (
|
|
22
|
+
<ThresholdLine
|
|
23
|
+
hideTooltip={hideTooltip}
|
|
24
|
+
key={`warning-${value.toString()}`}
|
|
25
|
+
label={label}
|
|
26
|
+
showTooltip={showTooltip}
|
|
27
|
+
thresholdType="warning"
|
|
28
|
+
value={value}
|
|
29
|
+
xScale={xScale}
|
|
81
30
|
/>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
left: xScale(criticalValue)
|
|
93
|
-
})}
|
|
94
|
-
onMouseLeave={hideTooltip}
|
|
31
|
+
))}
|
|
32
|
+
{thresholds.critical.map(({ value, label }) => (
|
|
33
|
+
<ThresholdLine
|
|
34
|
+
hideTooltip={hideTooltip}
|
|
35
|
+
key={`critical-${value.toString()}`}
|
|
36
|
+
label={label}
|
|
37
|
+
showTooltip={showTooltip}
|
|
38
|
+
thresholdType="critical"
|
|
39
|
+
value={value}
|
|
40
|
+
xScale={xScale}
|
|
95
41
|
/>
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
42
|
+
))}
|
|
43
|
+
</>
|
|
44
|
+
);
|
|
99
45
|
|
|
100
46
|
export default Thresholds;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { LineChartData } from '../common/models';
|
|
1
|
+
import { LineChartData, Thresholds } from '../common/models';
|
|
2
2
|
|
|
3
3
|
export interface SingleBarProps {
|
|
4
4
|
data?: LineChartData;
|
|
5
|
-
|
|
6
|
-
thresholdTooltipLabels: Array<string>;
|
|
7
|
-
thresholds: Array<number>;
|
|
5
|
+
thresholds: Thresholds;
|
|
8
6
|
}
|
package/src/Graph/Text/Text.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { isNil } from 'ramda';
|
|
|
2
2
|
|
|
3
3
|
import { Typography, useTheme } from '@mui/material';
|
|
4
4
|
|
|
5
|
-
import { LineChartData } from '../common/models';
|
|
5
|
+
import { LineChartData, Thresholds } from '../common/models';
|
|
6
6
|
import {
|
|
7
7
|
formatMetricValue,
|
|
8
8
|
getMetricWithLatestData
|
|
@@ -13,19 +13,17 @@ import { useTextStyles } from './Text.styles';
|
|
|
13
13
|
|
|
14
14
|
interface Props {
|
|
15
15
|
data?: LineChartData;
|
|
16
|
-
disabledThresholds?: boolean;
|
|
17
16
|
labels: {
|
|
18
17
|
critical: string;
|
|
19
18
|
warning: string;
|
|
20
19
|
};
|
|
21
|
-
thresholds:
|
|
20
|
+
thresholds: Thresholds;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
export const Text = ({
|
|
25
24
|
thresholds,
|
|
26
25
|
data,
|
|
27
|
-
labels
|
|
28
|
-
disabledThresholds
|
|
26
|
+
labels
|
|
29
27
|
}: Props): JSX.Element | null => {
|
|
30
28
|
const theme = useTheme();
|
|
31
29
|
const { classes } = useTextStyles();
|
|
@@ -44,6 +42,20 @@ export const Text = ({
|
|
|
44
42
|
thresholds
|
|
45
43
|
});
|
|
46
44
|
|
|
45
|
+
const warningThresholdLabels = thresholds.warning.map(({ value }) =>
|
|
46
|
+
formatMetricValue({
|
|
47
|
+
unit: metricUnit,
|
|
48
|
+
value
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const criticalThresholdLabels = thresholds.critical.map(({ value }) =>
|
|
53
|
+
formatMetricValue({
|
|
54
|
+
unit: metricUnit,
|
|
55
|
+
value
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
|
|
47
59
|
return (
|
|
48
60
|
<div className={classes.graphText}>
|
|
49
61
|
<Typography sx={{ color }} variant="h3">
|
|
@@ -53,25 +65,17 @@ export const Text = ({
|
|
|
53
65
|
})}{' '}
|
|
54
66
|
{metricUnit}
|
|
55
67
|
</Typography>
|
|
56
|
-
{
|
|
68
|
+
{thresholds.enabled && (
|
|
57
69
|
<div className={classes.thresholds}>
|
|
58
70
|
<Typography sx={{ color: 'warning.main' }} variant="h5">
|
|
59
71
|
{labels.warning}
|
|
60
72
|
{': '}
|
|
61
|
-
{
|
|
62
|
-
unit: metricUnit,
|
|
63
|
-
value: thresholds[0]
|
|
64
|
-
})}{' '}
|
|
65
|
-
{metricUnit}
|
|
73
|
+
{warningThresholdLabels.join(' - ')} {metricUnit}
|
|
66
74
|
</Typography>
|
|
67
75
|
<Typography sx={{ color: 'error.main' }} variant="h5">
|
|
68
76
|
{labels.critical}
|
|
69
77
|
{': '}
|
|
70
|
-
{
|
|
71
|
-
unit: metricUnit,
|
|
72
|
-
value: thresholds[1]
|
|
73
|
-
})}{' '}
|
|
74
|
-
{metricUnit}
|
|
78
|
+
{criticalThresholdLabels.join(' - ')} {metricUnit}
|
|
75
79
|
</Typography>
|
|
76
80
|
</div>
|
|
77
81
|
)}
|
|
@@ -5,3 +5,15 @@ export interface LineChartData {
|
|
|
5
5
|
metrics: Array<Metric>;
|
|
6
6
|
times: Array<string>;
|
|
7
7
|
}
|
|
8
|
+
|
|
9
|
+
export interface Thresholds {
|
|
10
|
+
critical: Array<{
|
|
11
|
+
label: string;
|
|
12
|
+
value: number;
|
|
13
|
+
}>;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
warning: Array<{
|
|
16
|
+
label: string;
|
|
17
|
+
value: number;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
@@ -1,20 +1,73 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
T,
|
|
3
|
+
always,
|
|
4
|
+
cond,
|
|
5
|
+
equals,
|
|
6
|
+
gt,
|
|
7
|
+
gte,
|
|
8
|
+
head,
|
|
9
|
+
length,
|
|
10
|
+
lt,
|
|
11
|
+
lte,
|
|
12
|
+
pluck
|
|
13
|
+
} from 'ramda';
|
|
2
14
|
|
|
3
15
|
import { Theme } from '@mui/material';
|
|
4
16
|
|
|
17
|
+
import { Thresholds } from './models';
|
|
18
|
+
|
|
5
19
|
interface GetColorFromDataAndThresholdsProps {
|
|
6
20
|
data: number;
|
|
7
21
|
theme: Theme;
|
|
8
|
-
thresholds:
|
|
22
|
+
thresholds: Thresholds;
|
|
9
23
|
}
|
|
10
24
|
|
|
11
25
|
export const getColorFromDataAndTresholds = ({
|
|
12
26
|
data,
|
|
13
27
|
thresholds,
|
|
14
28
|
theme
|
|
15
|
-
}: GetColorFromDataAndThresholdsProps): string =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
}: GetColorFromDataAndThresholdsProps): string => {
|
|
30
|
+
if (!thresholds.enabled) {
|
|
31
|
+
return theme.palette.success.main;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const criticalValues = pluck('value', thresholds.critical).sort();
|
|
35
|
+
const warningValues = pluck('value', thresholds.warning).sort();
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
equals(length(criticalValues), 2) &&
|
|
39
|
+
lte(criticalValues[0], data) &&
|
|
40
|
+
gte(criticalValues[1], data)
|
|
41
|
+
) {
|
|
42
|
+
return theme.palette.error.main;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
equals(length(warningValues), 2) &&
|
|
47
|
+
lte(warningValues[0], data) &&
|
|
48
|
+
gte(warningValues[1], data)
|
|
49
|
+
) {
|
|
50
|
+
return theme.palette.warning.main;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (equals(length(warningValues), 2)) {
|
|
54
|
+
return theme.palette.success.main;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const criticalValue = head(criticalValues) as number;
|
|
58
|
+
const warningValue = head(warningValues) as number;
|
|
59
|
+
|
|
60
|
+
if (gt(warningValue, criticalValue)) {
|
|
61
|
+
return cond([
|
|
62
|
+
[lt(warningValue), always(theme.palette.success.main)],
|
|
63
|
+
[lt(criticalValue), always(theme.palette.warning.main)],
|
|
64
|
+
[T, always(theme.palette.error.main)]
|
|
65
|
+
])(data);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return cond([
|
|
69
|
+
[gt(warningValue), always(theme.palette.success.main)],
|
|
70
|
+
[gt(criticalValue), always(theme.palette.warning.main)],
|
|
19
71
|
[T, always(theme.palette.error.main)]
|
|
20
72
|
])(data);
|
|
73
|
+
};
|
|
File without changes
|