@centreon/ui 24.4.63 → 24.4.64
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/LineChart/Header/index.tsx +3 -31
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTickGraph.ts +9 -11
- package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx +68 -0
- package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +27 -0
- package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltipStyles.ts +31 -0
- package/src/Graph/LineChart/InteractiveComponents/index.tsx +132 -16
- package/src/Graph/LineChart/InteractiveComponents/interactionWithGraphAtoms.ts +7 -27
- package/src/Graph/LineChart/Legend/LegendHeader.tsx +8 -5
- package/src/Graph/LineChart/Legend/index.tsx +10 -47
- package/src/Graph/LineChart/LineChart.cypress.spec.tsx +91 -0
- package/src/Graph/LineChart/LineChart.styles.ts +8 -0
- package/src/Graph/LineChart/LineChart.tsx +107 -109
- package/src/Graph/LineChart/mockedData/lastDayWithIncompleteValues.json +1320 -0
- package/src/Graph/LineChart/mockedData/lastDayWithNullValues.json +1314 -0
- package/src/Graph/LineChart/models.ts +12 -0
- package/src/Graph/common/timeSeries/index.ts +31 -1
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/TooltipAnchorPoint.tsx +0 -96
- package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTooltipAnchorPoint.ts +0 -107
- package/src/Graph/LineChart/Legend/InteractiveValue.tsx +0 -22
- package/src/Graph/LineChart/Legend/useInteractiveValues.ts +0 -99
|
@@ -144,3 +144,15 @@ export interface GetDate {
|
|
|
144
144
|
timeSeries: Array<TimeValue>;
|
|
145
145
|
xScale: ScaleLinear<number, number>;
|
|
146
146
|
}
|
|
147
|
+
|
|
148
|
+
export interface GraphTooltipData {
|
|
149
|
+
date: string;
|
|
150
|
+
highlightedMetricId: number | null;
|
|
151
|
+
metrics: Array<{
|
|
152
|
+
color: string;
|
|
153
|
+
id: number;
|
|
154
|
+
name: string;
|
|
155
|
+
unit: string;
|
|
156
|
+
value: number;
|
|
157
|
+
}>;
|
|
158
|
+
}
|
|
@@ -31,7 +31,9 @@ import {
|
|
|
31
31
|
last,
|
|
32
32
|
cond,
|
|
33
33
|
always,
|
|
34
|
-
T
|
|
34
|
+
T,
|
|
35
|
+
includes,
|
|
36
|
+
split
|
|
35
37
|
} from 'ramda';
|
|
36
38
|
|
|
37
39
|
import { margin } from '../../LineChart/common';
|
|
@@ -205,6 +207,17 @@ const getLineForMetric = ({
|
|
|
205
207
|
}: LineForMetricProps): Line | undefined =>
|
|
206
208
|
find(propEq(metric_id, 'metric_id'), lines);
|
|
207
209
|
|
|
210
|
+
interface LinesForMetricsProps {
|
|
211
|
+
lines: Array<Line>;
|
|
212
|
+
metricIds: Array<number>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export const getLinesForMetrics = ({
|
|
216
|
+
lines,
|
|
217
|
+
metricIds
|
|
218
|
+
}: LinesForMetricsProps): Array<Line> =>
|
|
219
|
+
filter(({ metric_id }) => metricIds.includes(metric_id), lines);
|
|
220
|
+
|
|
208
221
|
interface LinesTimeSeries {
|
|
209
222
|
lines: Array<Line>;
|
|
210
223
|
timeSeries: Array<TimeValue>;
|
|
@@ -601,6 +614,23 @@ const getMetricWithLatestData = (
|
|
|
601
614
|
};
|
|
602
615
|
};
|
|
603
616
|
|
|
617
|
+
interface FormatMetricNameProps {
|
|
618
|
+
legend: string | null;
|
|
619
|
+
name: string;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
export const formatMetricName = ({
|
|
623
|
+
legend,
|
|
624
|
+
name
|
|
625
|
+
}: FormatMetricNameProps): string => {
|
|
626
|
+
const legendName = legend || name;
|
|
627
|
+
const metricName = includes('#', legendName)
|
|
628
|
+
? split('#')(legendName)[1]
|
|
629
|
+
: legendName;
|
|
630
|
+
|
|
631
|
+
return metricName;
|
|
632
|
+
};
|
|
633
|
+
|
|
604
634
|
export {
|
|
605
635
|
getTimeSeries,
|
|
606
636
|
getLineData,
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Tooltip } from '@visx/visx';
|
|
2
|
-
|
|
3
|
-
import { Typography, useTheme } from '@mui/material';
|
|
4
|
-
|
|
5
|
-
import useTooltipAnchorPoint from './useTooltipAnchorPoint';
|
|
6
|
-
import { TooltipAnchorModel } from './models';
|
|
7
|
-
|
|
8
|
-
const baseStyles = {
|
|
9
|
-
...Tooltip.defaultStyles,
|
|
10
|
-
textAlign: 'center'
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const TooltipAnchorPoint = ({
|
|
14
|
-
timeSeries,
|
|
15
|
-
xScale,
|
|
16
|
-
graphHeight,
|
|
17
|
-
leftScale,
|
|
18
|
-
rightScale,
|
|
19
|
-
graphWidth,
|
|
20
|
-
lines,
|
|
21
|
-
baseAxis
|
|
22
|
-
}: TooltipAnchorModel): JSX.Element => {
|
|
23
|
-
const theme = useTheme();
|
|
24
|
-
|
|
25
|
-
const {
|
|
26
|
-
tooltipDataAxisX,
|
|
27
|
-
tooltipDataAxisYLeft,
|
|
28
|
-
tooltipLeftAxisX,
|
|
29
|
-
tooltipLeftAxisYLeft,
|
|
30
|
-
tooltipTopAxisYLeft,
|
|
31
|
-
tooltipDataAxisYRight,
|
|
32
|
-
tooltipTopAxisYRight,
|
|
33
|
-
tooltipLeftAxisYRight
|
|
34
|
-
} = useTooltipAnchorPoint({
|
|
35
|
-
baseAxis,
|
|
36
|
-
graphHeight,
|
|
37
|
-
graphWidth,
|
|
38
|
-
leftScale,
|
|
39
|
-
lines,
|
|
40
|
-
rightScale,
|
|
41
|
-
timeSeries,
|
|
42
|
-
xScale
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const cardStyles = {
|
|
46
|
-
backgroundColor: theme.palette.background.paper,
|
|
47
|
-
color: theme.palette.text.primary,
|
|
48
|
-
padding: theme.spacing(0.25, 0.5)
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<>
|
|
53
|
-
{tooltipDataAxisX && (
|
|
54
|
-
<Tooltip.Tooltip
|
|
55
|
-
left={tooltipLeftAxisX}
|
|
56
|
-
style={{
|
|
57
|
-
...baseStyles,
|
|
58
|
-
...cardStyles,
|
|
59
|
-
transform: 'translateX(-70%)'
|
|
60
|
-
}}
|
|
61
|
-
top={0}
|
|
62
|
-
>
|
|
63
|
-
<Typography variant="caption">{tooltipDataAxisX}</Typography>
|
|
64
|
-
</Tooltip.Tooltip>
|
|
65
|
-
)}
|
|
66
|
-
{tooltipDataAxisYLeft && (
|
|
67
|
-
<Tooltip.Tooltip
|
|
68
|
-
left={tooltipLeftAxisYLeft}
|
|
69
|
-
style={{
|
|
70
|
-
...baseStyles,
|
|
71
|
-
...cardStyles,
|
|
72
|
-
transform: 'translateX(-70%) translateY(-100%)'
|
|
73
|
-
}}
|
|
74
|
-
top={tooltipTopAxisYLeft}
|
|
75
|
-
>
|
|
76
|
-
<Typography variant="caption">{tooltipDataAxisYLeft}</Typography>
|
|
77
|
-
</Tooltip.Tooltip>
|
|
78
|
-
)}
|
|
79
|
-
{tooltipDataAxisYRight && (
|
|
80
|
-
<Tooltip.Tooltip
|
|
81
|
-
left={tooltipLeftAxisYRight}
|
|
82
|
-
style={{
|
|
83
|
-
...baseStyles,
|
|
84
|
-
...cardStyles,
|
|
85
|
-
transform: 'translateX(-70%) translateY(-80%)'
|
|
86
|
-
}}
|
|
87
|
-
top={tooltipTopAxisYRight}
|
|
88
|
-
>
|
|
89
|
-
<Typography variant="caption">{tooltipDataAxisYRight}</Typography>
|
|
90
|
-
</Tooltip.Tooltip>
|
|
91
|
-
)}
|
|
92
|
-
</>
|
|
93
|
-
);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
export default TooltipAnchorPoint;
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
2
|
-
|
|
3
|
-
import { Tooltip } from '@visx/visx';
|
|
4
|
-
import { isNil } from 'ramda';
|
|
5
|
-
|
|
6
|
-
import { useLocaleDateTimeFormat } from '@centreon/ui';
|
|
7
|
-
|
|
8
|
-
import { margin, timeFormat } from '../../common/index';
|
|
9
|
-
|
|
10
|
-
import { TooltipAnchorModel, UseTooltipAnchorPointResult } from './models';
|
|
11
|
-
import useTickGraph from './useTickGraph';
|
|
12
|
-
|
|
13
|
-
const useTooltipAnchorPoint = ({
|
|
14
|
-
timeSeries,
|
|
15
|
-
xScale,
|
|
16
|
-
graphHeight,
|
|
17
|
-
leftScale,
|
|
18
|
-
rightScale,
|
|
19
|
-
graphWidth,
|
|
20
|
-
lines,
|
|
21
|
-
baseAxis
|
|
22
|
-
}: TooltipAnchorModel): UseTooltipAnchorPointResult => {
|
|
23
|
-
const { format } = useLocaleDateTimeFormat();
|
|
24
|
-
|
|
25
|
-
const { positionX, positionY, tickAxisBottom, tickAxisLeft, tickAxisRight } =
|
|
26
|
-
useTickGraph({
|
|
27
|
-
baseAxis,
|
|
28
|
-
leftScale,
|
|
29
|
-
lines,
|
|
30
|
-
rightScale,
|
|
31
|
-
timeSeries,
|
|
32
|
-
xScale
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const {
|
|
36
|
-
showTooltip: showTooltipAxisYLeft,
|
|
37
|
-
tooltipData: tooltipDataAxisYLeft,
|
|
38
|
-
tooltipLeft: tooltipLeftAxisYLeft,
|
|
39
|
-
tooltipTop: tooltipTopAxisYLeft
|
|
40
|
-
} = Tooltip.useTooltip();
|
|
41
|
-
const {
|
|
42
|
-
showTooltip: showTooltipAxisX,
|
|
43
|
-
tooltipData: tooltipDataAxisX,
|
|
44
|
-
tooltipLeft: tooltipLeftAxisX,
|
|
45
|
-
tooltipTop: tooltipTopAxisX
|
|
46
|
-
} = Tooltip.useTooltip();
|
|
47
|
-
|
|
48
|
-
const {
|
|
49
|
-
showTooltip: showTooltipAxisYRight,
|
|
50
|
-
tooltipData: tooltipDataAxisYRight,
|
|
51
|
-
tooltipLeft: tooltipLeftAxisYRight,
|
|
52
|
-
tooltipTop: tooltipTopAxisYRight
|
|
53
|
-
} = Tooltip.useTooltip();
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (!positionX || !positionY || !tickAxisBottom) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const dataAxisX = format({
|
|
61
|
-
date: tickAxisBottom,
|
|
62
|
-
formatString: timeFormat
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
showTooltipAxisX({
|
|
66
|
-
tooltipData: dataAxisX,
|
|
67
|
-
tooltipLeft: positionX + margin.left,
|
|
68
|
-
tooltipTop: graphHeight + margin.top
|
|
69
|
-
});
|
|
70
|
-
}, [positionX, positionY, tickAxisBottom]);
|
|
71
|
-
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (!positionX || !positionY || !tickAxisLeft) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
showTooltipAxisYLeft({
|
|
77
|
-
tooltipData: tickAxisLeft,
|
|
78
|
-
tooltipLeft: margin.left,
|
|
79
|
-
tooltipTop: positionY + margin.top
|
|
80
|
-
});
|
|
81
|
-
}, [tickAxisLeft, positionX, positionY]);
|
|
82
|
-
|
|
83
|
-
useEffect(() => {
|
|
84
|
-
if (!positionX || !positionY || !tickAxisRight) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
showTooltipAxisYRight({
|
|
88
|
-
tooltipData: tickAxisRight,
|
|
89
|
-
tooltipLeft: graphWidth ? graphWidth + margin.left : 0,
|
|
90
|
-
tooltipTop: positionY + margin.top
|
|
91
|
-
});
|
|
92
|
-
}, [positionX, positionY, tickAxisRight]);
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
tooltipDataAxisX: !isNil(tickAxisBottom) ? tooltipDataAxisX : null,
|
|
96
|
-
tooltipDataAxisYLeft: !isNil(tickAxisLeft) ? tooltipDataAxisYLeft : null,
|
|
97
|
-
tooltipDataAxisYRight: !isNil(tickAxisRight) ? tooltipDataAxisYRight : null,
|
|
98
|
-
tooltipLeftAxisX,
|
|
99
|
-
tooltipLeftAxisYLeft,
|
|
100
|
-
tooltipLeftAxisYRight,
|
|
101
|
-
tooltipTopAxisX,
|
|
102
|
-
tooltipTopAxisYLeft,
|
|
103
|
-
tooltipTopAxisYRight
|
|
104
|
-
} as UseTooltipAnchorPointResult;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export default useTooltipAnchorPoint;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Typography } from '@mui/material';
|
|
2
|
-
|
|
3
|
-
import { useLegendValueStyles } from './Legend.styles';
|
|
4
|
-
|
|
5
|
-
interface Props {
|
|
6
|
-
value?: string | null;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const InteractiveValue = ({ value }: Props): JSX.Element | null => {
|
|
10
|
-
const { classes } = useLegendValueStyles({});
|
|
11
|
-
if (!value) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<Typography className={classes.text} variant="h6">
|
|
17
|
-
{value}
|
|
18
|
-
</Typography>
|
|
19
|
-
);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default InteractiveValue;
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
import { useAtomValue } from 'jotai';
|
|
4
|
-
import { equals, find, isNil } from 'ramda';
|
|
5
|
-
|
|
6
|
-
import { mousePositionAtom } from '../InteractiveComponents/interactionWithGraphAtoms';
|
|
7
|
-
import {
|
|
8
|
-
formatMetricValueWithUnit,
|
|
9
|
-
getLineForMetric,
|
|
10
|
-
getMetrics,
|
|
11
|
-
getTimeValue
|
|
12
|
-
} from '../../common/timeSeries';
|
|
13
|
-
import { Line, TimeValue } from '../../common/timeSeries/models';
|
|
14
|
-
|
|
15
|
-
import { FormattedMetricData } from './models';
|
|
16
|
-
|
|
17
|
-
interface InteractiveValues {
|
|
18
|
-
getFormattedValue: (line: Line) => string | null | undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface Props {
|
|
22
|
-
base: number;
|
|
23
|
-
lines: Array<Line>;
|
|
24
|
-
timeSeries: Array<TimeValue>;
|
|
25
|
-
xScale;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const useInteractiveValues = ({
|
|
29
|
-
timeSeries,
|
|
30
|
-
lines,
|
|
31
|
-
base,
|
|
32
|
-
xScale
|
|
33
|
-
}: Props): InteractiveValues => {
|
|
34
|
-
const mousePosition = useAtomValue(mousePositionAtom);
|
|
35
|
-
|
|
36
|
-
const timeValue = getTimeValue({
|
|
37
|
-
timeSeries,
|
|
38
|
-
x: mousePosition?.[0],
|
|
39
|
-
xScale
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const graphTimeValue = timeSeries?.find((item) =>
|
|
43
|
-
equals(item.timeTick, timeValue?.timeTick)
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const getMetricsToDisplay = (): Array<number> => {
|
|
47
|
-
if (isNil(graphTimeValue)) {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
const metricsData = getMetrics(graphTimeValue as TimeValue);
|
|
51
|
-
|
|
52
|
-
const metricsToDisplay = metricsData.filter((metric_id) => {
|
|
53
|
-
const line = getLineForMetric({ lines, metric_id: Number(metric_id) });
|
|
54
|
-
|
|
55
|
-
return !isNil(graphTimeValue[metric_id]) && !isNil(line);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return metricsToDisplay.map(Number);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const metrics = useMemo(() => getMetricsToDisplay(), [graphTimeValue]);
|
|
62
|
-
|
|
63
|
-
const getFormattedMetricData = (
|
|
64
|
-
metric_id: number
|
|
65
|
-
): FormattedMetricData | null => {
|
|
66
|
-
if (isNil(graphTimeValue)) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
const value = graphTimeValue[metric_id] as number;
|
|
70
|
-
|
|
71
|
-
const { color, name, unit } = getLineForMetric({
|
|
72
|
-
lines,
|
|
73
|
-
metric_id
|
|
74
|
-
}) as Line;
|
|
75
|
-
|
|
76
|
-
const formattedValue = formatMetricValueWithUnit({
|
|
77
|
-
base,
|
|
78
|
-
unit,
|
|
79
|
-
value
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
color,
|
|
84
|
-
formattedValue,
|
|
85
|
-
name,
|
|
86
|
-
unit
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const getFormattedValue = (line: Line): string | undefined | null => {
|
|
91
|
-
const metric_id = find(equals(line.metric_id), metrics);
|
|
92
|
-
|
|
93
|
-
return metric_id ? getFormattedMetricData(metric_id)?.formattedValue : null;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
return { getFormattedValue };
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export default useInteractiveValues;
|