@centreon/ui 26.3.14 → 26.3.16
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/Chart/BasicComponents/Lines/index.tsx +26 -1
- package/src/Graph/Chart/Chart.tsx +3 -0
- package/src/Graph/Chart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +18 -5
- package/src/Graph/Chart/InteractiveComponents/AnchorPoint/models.ts +6 -0
- package/src/Graph/Chart/InteractiveComponents/AnchorPoint/useTickGraph.ts +12 -22
- package/src/Graph/common/timeSeries/index.ts +1 -1
- package/src/utils/useViewportIntersection.ts +6 -1
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import type { ScaleLinear } from 'd3-scale';
|
|
|
2
2
|
import { isNil } from 'ramda';
|
|
3
3
|
import type { MutableRefObject } from 'react';
|
|
4
4
|
|
|
5
|
+
import { Axis, AxisYRight } from '../../../common/Axes/models';
|
|
5
6
|
import {
|
|
6
7
|
getDates,
|
|
7
8
|
getTimeSeriesForLines,
|
|
@@ -40,6 +41,12 @@ interface Props extends GlobalAreaLines {
|
|
|
40
41
|
lineStyle: LineStyle | Array<LineStyle>;
|
|
41
42
|
hasSecondUnit?: boolean;
|
|
42
43
|
maxLeftAxisCharacters: number;
|
|
44
|
+
firstUnit?: string;
|
|
45
|
+
secondUnit?: string;
|
|
46
|
+
axis?: {
|
|
47
|
+
axisYLeft?: Axis;
|
|
48
|
+
axisYRight?: AxisYRight;
|
|
49
|
+
};
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
const Lines = ({
|
|
@@ -58,7 +65,10 @@ const Lines = ({
|
|
|
58
65
|
scaleLogarithmicBase,
|
|
59
66
|
lineStyle,
|
|
60
67
|
hasSecondUnit,
|
|
61
|
-
maxLeftAxisCharacters
|
|
68
|
+
maxLeftAxisCharacters,
|
|
69
|
+
firstUnit,
|
|
70
|
+
secondUnit,
|
|
71
|
+
axis
|
|
62
72
|
}: Props): JSX.Element => {
|
|
63
73
|
const { stackedLinesData, invertedStackedLinesData } = useStackedLines({
|
|
64
74
|
lines: displayedLines,
|
|
@@ -84,6 +94,15 @@ const Lines = ({
|
|
|
84
94
|
maxLeftAxisCharacters,
|
|
85
95
|
xScale
|
|
86
96
|
};
|
|
97
|
+
const leftScale = yScalesPerUnit[axis?.axisYLeft?.unit ?? firstUnit];
|
|
98
|
+
const rightScale = yScalesPerUnit[axis?.axisYRight?.unit ?? secondUnit];
|
|
99
|
+
const hasUnitDisplayed =
|
|
100
|
+
Boolean(firstUnit || secondUnit) ||
|
|
101
|
+
Boolean(
|
|
102
|
+
axis?.axisYLeft?.unit ||
|
|
103
|
+
axis?.axisYLeft?.displayUnit ||
|
|
104
|
+
(axis?.axisYRight?.unit && axis?.axisYRight?.displayUnit)
|
|
105
|
+
);
|
|
87
106
|
|
|
88
107
|
return (
|
|
89
108
|
<g>
|
|
@@ -91,6 +110,12 @@ const Lines = ({
|
|
|
91
110
|
<GuidingLines
|
|
92
111
|
graphHeight={height}
|
|
93
112
|
graphWidth={width}
|
|
113
|
+
hasSecondUnit={hasSecondUnit}
|
|
114
|
+
hasUnit={hasUnitDisplayed}
|
|
115
|
+
leftScale={leftScale}
|
|
116
|
+
lines={displayedLines}
|
|
117
|
+
maxLeftAxisCharacters={maxLeftAxisCharacters}
|
|
118
|
+
rightScale={rightScale}
|
|
94
119
|
timeSeries={timeSeries}
|
|
95
120
|
xScale={xScale}
|
|
96
121
|
/>
|
|
@@ -339,8 +339,10 @@ const Chart = ({
|
|
|
339
339
|
)}
|
|
340
340
|
{!isEmpty(linesDisplayedAsLine) && (
|
|
341
341
|
<Lines
|
|
342
|
+
axis={axis}
|
|
342
343
|
displayAnchor={displayAnchor}
|
|
343
344
|
displayedLines={linesDisplayedAsLine}
|
|
345
|
+
firstUnit={firstUnit}
|
|
344
346
|
graphSvgRef={graphSvgRef}
|
|
345
347
|
hasSecondUnit={hasSecondUnit}
|
|
346
348
|
height={graphHeight - marginTop}
|
|
@@ -348,6 +350,7 @@ const Chart = ({
|
|
|
348
350
|
maxLeftAxisCharacters={maxLeftAxisCharacters}
|
|
349
351
|
scale={axis?.scale}
|
|
350
352
|
scaleLogarithmicBase={axis?.scaleLogarithmicBase}
|
|
353
|
+
secondUnit={secondUnit}
|
|
351
354
|
timeSeries={timeSeries}
|
|
352
355
|
width={graphWidth}
|
|
353
356
|
xScale={xScale}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { grey } from '@mui/material/colors';
|
|
2
2
|
|
|
3
3
|
import { Shape } from '@visx/visx';
|
|
4
|
+
import { ReactElement } from 'react';
|
|
4
5
|
|
|
5
6
|
import type { GuidingLines as GuidingLinesModel } from './models';
|
|
6
7
|
import useTickGraph from './useTickGraph';
|
|
@@ -9,9 +10,21 @@ const GuidingLines = ({
|
|
|
9
10
|
timeSeries,
|
|
10
11
|
xScale,
|
|
11
12
|
graphHeight,
|
|
12
|
-
graphWidth
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
graphWidth,
|
|
14
|
+
maxLeftAxisCharacters,
|
|
15
|
+
hasSecondUnit,
|
|
16
|
+
lines,
|
|
17
|
+
leftScale,
|
|
18
|
+
rightScale,
|
|
19
|
+
hasUnit
|
|
20
|
+
}: GuidingLinesModel): ReactElement | null => {
|
|
21
|
+
const { positionX, positionY } = useTickGraph({
|
|
22
|
+
hasSecondUnit,
|
|
23
|
+
hasUnit,
|
|
24
|
+
leftScale,
|
|
25
|
+
lines,
|
|
26
|
+
maxLeftAxisCharacters,
|
|
27
|
+
rightScale,
|
|
15
28
|
timeSeries,
|
|
16
29
|
xScale
|
|
17
30
|
});
|
|
@@ -20,7 +33,7 @@ const GuidingLines = ({
|
|
|
20
33
|
}
|
|
21
34
|
|
|
22
35
|
return (
|
|
23
|
-
|
|
36
|
+
<>
|
|
24
37
|
<Shape.Line
|
|
25
38
|
fill="dotted"
|
|
26
39
|
from={{ x: positionX, y: 0 }}
|
|
@@ -38,7 +51,7 @@ const GuidingLines = ({
|
|
|
38
51
|
strokeWidth={1}
|
|
39
52
|
to={{ x: graphWidth, y: positionY }}
|
|
40
53
|
/>
|
|
41
|
-
|
|
54
|
+
</>
|
|
42
55
|
);
|
|
43
56
|
};
|
|
44
57
|
|
|
@@ -29,6 +29,12 @@ export interface GuidingLines {
|
|
|
29
29
|
graphWidth: number;
|
|
30
30
|
timeSeries: Array<TimeValue>;
|
|
31
31
|
xScale: ScaleLinear<number, number>;
|
|
32
|
+
maxLeftAxisCharacters: number;
|
|
33
|
+
hasSecondUnit?: boolean;
|
|
34
|
+
leftScale?: ScaleLinear<number, number>;
|
|
35
|
+
lines: Array<Line>;
|
|
36
|
+
rightScale?: ScaleLinear<number, number>;
|
|
37
|
+
hasUnit?: boolean;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export interface GetYAnchorPoint {
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import type { ScaleLinear } from 'd3-scale';
|
|
2
2
|
import { useAtomValue } from 'jotai';
|
|
3
|
-
import {
|
|
4
|
-
type MutableRefObject,
|
|
5
|
-
useEffect,
|
|
6
|
-
useMemo,
|
|
7
|
-
useRef,
|
|
8
|
-
useState
|
|
9
|
-
} from 'react';
|
|
3
|
+
import { type MutableRefObject, useEffect, useState } from 'react';
|
|
10
4
|
|
|
11
5
|
import useAxisY from '../../../common/Axes/useAxisY';
|
|
12
6
|
import { getTimeValue } from '../../../common/timeSeries';
|
|
@@ -15,7 +9,6 @@ import {
|
|
|
15
9
|
computeGElementMarginLeft,
|
|
16
10
|
computPixelsToShiftMouse
|
|
17
11
|
} from '../../../common/utils';
|
|
18
|
-
import { margin } from '../../common';
|
|
19
12
|
import { mousePositionAtom } from '../interactionWithGraphAtoms';
|
|
20
13
|
|
|
21
14
|
interface AnchorPointResult {
|
|
@@ -36,6 +29,7 @@ interface Props {
|
|
|
36
29
|
xScale: ScaleLinear<number, number>;
|
|
37
30
|
hasSecondUnit?: boolean;
|
|
38
31
|
maxLeftAxisCharacters: number;
|
|
32
|
+
hasUnit?: boolean;
|
|
39
33
|
}
|
|
40
34
|
|
|
41
35
|
const useTickGraph = ({
|
|
@@ -46,9 +40,9 @@ const useTickGraph = ({
|
|
|
46
40
|
lines = [],
|
|
47
41
|
baseAxis = 1000,
|
|
48
42
|
hasSecondUnit,
|
|
49
|
-
maxLeftAxisCharacters
|
|
43
|
+
maxLeftAxisCharacters,
|
|
44
|
+
hasUnit
|
|
50
45
|
}: Props): AnchorPointResult => {
|
|
51
|
-
const guidingLinesRef = useRef<SVGGElement | null>(null);
|
|
52
46
|
const [tickAxisBottom, setTickAxisBottom] = useState<Date | null>(null);
|
|
53
47
|
const [tickAxisLeft, setTickAxisLeft] = useState<string | null>(null);
|
|
54
48
|
const [tickAxisRight, setTickAxisRight] = useState<string | null>(null);
|
|
@@ -57,19 +51,16 @@ const useTickGraph = ({
|
|
|
57
51
|
|
|
58
52
|
const mousePosition = useAtomValue(mousePositionAtom);
|
|
59
53
|
|
|
60
|
-
const paddingLeftString = useMemo(
|
|
61
|
-
() =>
|
|
62
|
-
(
|
|
63
|
-
guidingLinesRef.current?.parentElement?.parentElement?.attributes
|
|
64
|
-
?.transform.value || ''
|
|
65
|
-
).match(/translate\(([0-9.]+), ([0-9.]+)\)/)?.[1] || '0',
|
|
66
|
-
[]
|
|
67
|
-
);
|
|
68
|
-
|
|
69
54
|
const positionX = mousePosition
|
|
70
|
-
? mousePosition[0] -
|
|
55
|
+
? mousePosition[0] -
|
|
56
|
+
computeGElementMarginLeft({
|
|
57
|
+
hasSecondUnit,
|
|
58
|
+
maxCharacters: maxLeftAxisCharacters
|
|
59
|
+
})
|
|
60
|
+
: undefined;
|
|
61
|
+
const positionY = mousePosition
|
|
62
|
+
? mousePosition[1] - (hasUnit ? 29 : 4)
|
|
71
63
|
: undefined;
|
|
72
|
-
const positionY = mousePosition ? mousePosition[1] - margin.top : undefined;
|
|
73
64
|
|
|
74
65
|
useEffect(() => {
|
|
75
66
|
if (!mousePosition) {
|
|
@@ -113,7 +104,6 @@ const useTickGraph = ({
|
|
|
113
104
|
}, [mousePosition]);
|
|
114
105
|
|
|
115
106
|
return {
|
|
116
|
-
guidingLinesRef,
|
|
117
107
|
positionX,
|
|
118
108
|
positionY,
|
|
119
109
|
tickAxisBottom,
|
|
@@ -395,7 +395,7 @@ const getScale = ({
|
|
|
395
395
|
: getMin(graphValues),
|
|
396
396
|
!isEmpty(stackedValues) &&
|
|
397
397
|
!equals(stackedValues, [0]) &&
|
|
398
|
-
getMin(stackedValues),
|
|
398
|
+
getMin([0, ...stackedValues]),
|
|
399
399
|
Math.min(...thresholds)
|
|
400
400
|
]);
|
|
401
401
|
const minValue = Math.min(...sanitizedValuesForMinimum.filter(isNotNil));
|
|
@@ -18,6 +18,11 @@ export const useViewportIntersection = (
|
|
|
18
18
|
const [element, setElement] = useState<HTMLElement | null>(null);
|
|
19
19
|
|
|
20
20
|
const observer = useRef<IntersectionObserver | null>(null);
|
|
21
|
+
|
|
22
|
+
const sanitizedOptions = {
|
|
23
|
+
...options,
|
|
24
|
+
root: options?.root instanceof HTMLElement ? `${options.root.tagName}_${options.root.className}` : null
|
|
25
|
+
}
|
|
21
26
|
|
|
22
27
|
useEffect(() => {
|
|
23
28
|
if (observer.current) {
|
|
@@ -36,7 +41,7 @@ export const useViewportIntersection = (
|
|
|
36
41
|
return (): void => {
|
|
37
42
|
observer.current?.disconnect();
|
|
38
43
|
};
|
|
39
|
-
}, [element,
|
|
44
|
+
}, [element, JSON.stringify(sanitizedOptions)]);
|
|
40
45
|
|
|
41
46
|
return {
|
|
42
47
|
isInViewport: entry?.isIntersecting ?? true,
|