@centreon/ui 24.10.16 → 24.10.17
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/BarChart/BarChart.cypress.spec.tsx +6 -4
- package/src/Graph/BarChart/ResponsiveBarChart.tsx +4 -1
- package/src/Graph/Chart/Chart.cypress.spec.tsx +5 -5
- package/src/Graph/Chart/Chart.tsx +6 -3
- package/src/Graph/common/BaseChart/useComputeBaseChartDimensions.ts +18 -13
- package/src/Graph/common/useMarginTop.ts +17 -0
package/package.json
CHANGED
|
@@ -60,15 +60,17 @@ const checkWidth = (orientation): void => {
|
|
|
60
60
|
if (orientation === 'vertical') {
|
|
61
61
|
cy.get('g[class*="visx-rows"] > line')
|
|
62
62
|
.eq(0)
|
|
63
|
-
.
|
|
64
|
-
|
|
63
|
+
.then((graph) => {
|
|
64
|
+
expect(Number(graph[0].attributes.x2.value)).to.be.greaterThan(1140);
|
|
65
|
+
});
|
|
65
66
|
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
68
69
|
cy.get('g[class*="visx-rows"] > line')
|
|
69
70
|
.eq(0)
|
|
70
|
-
.
|
|
71
|
-
|
|
71
|
+
.then((graph) => {
|
|
72
|
+
expect(Number(graph[0].attributes.x2.value)).to.be.greaterThan(1177);
|
|
73
|
+
});
|
|
72
74
|
};
|
|
73
75
|
|
|
74
76
|
describe('Bar chart', () => {
|
|
@@ -92,7 +92,10 @@ const ResponsiveBarChart = ({
|
|
|
92
92
|
legendDisplay: legend?.display,
|
|
93
93
|
legendPlacement: legend?.placement,
|
|
94
94
|
width,
|
|
95
|
-
|
|
95
|
+
maxRightAxisCharacters,
|
|
96
|
+
maxLeftAxisCharacters,
|
|
97
|
+
title,
|
|
98
|
+
units: allUnits
|
|
96
99
|
});
|
|
97
100
|
|
|
98
101
|
const thresholdValues = flatten([
|
|
@@ -131,10 +131,10 @@ const initializeCustomUnits = ({
|
|
|
131
131
|
const checkGraphWidth = (): void => {
|
|
132
132
|
cy.findByTestId('graph-interaction-zone')
|
|
133
133
|
.should('have.attr', 'height')
|
|
134
|
-
.and('equal', '
|
|
134
|
+
.and('equal', '398');
|
|
135
135
|
|
|
136
136
|
cy.findByTestId('graph-interaction-zone').then((graph) => {
|
|
137
|
-
expect(Number(graph[0].attributes.width.value)).to.be.greaterThan(
|
|
137
|
+
expect(Number(graph[0].attributes.width.value)).to.be.greaterThan(1150);
|
|
138
138
|
});
|
|
139
139
|
};
|
|
140
140
|
|
|
@@ -158,7 +158,7 @@ describe('Line chart', () => {
|
|
|
158
158
|
cy.contains('06/18/2023').should('be.visible');
|
|
159
159
|
|
|
160
160
|
cy.contains('0.45 s').should('be.visible');
|
|
161
|
-
cy.contains('
|
|
161
|
+
cy.contains('75.19%').should('be.visible');
|
|
162
162
|
|
|
163
163
|
cy.makeSnapshot();
|
|
164
164
|
});
|
|
@@ -443,7 +443,7 @@ describe('Line chart', () => {
|
|
|
443
443
|
|
|
444
444
|
cy.contains(':00 AM').should('be.visible');
|
|
445
445
|
|
|
446
|
-
cy.get('text[transform="rotate(-35, -2,
|
|
446
|
+
cy.get('text[transform="rotate(-35, -2, 290.537103928414)"]').should(
|
|
447
447
|
'be.visible'
|
|
448
448
|
);
|
|
449
449
|
|
|
@@ -521,7 +521,7 @@ describe('Line chart', () => {
|
|
|
521
521
|
|
|
522
522
|
checkGraphWidth();
|
|
523
523
|
cy.contains(':00 AM').should('be.visible');
|
|
524
|
-
cy.get('circle[cx="37.
|
|
524
|
+
cy.get('circle[cx="37.375"]').should('be.visible');
|
|
525
525
|
|
|
526
526
|
cy.makeSnapshot();
|
|
527
527
|
});
|
|
@@ -137,6 +137,8 @@ const Chart = ({
|
|
|
137
137
|
secondUnit
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
+
const allUnits = getUnits(linesGraph);
|
|
141
|
+
|
|
140
142
|
const { legendRef, graphWidth, graphHeight } = useComputeBaseChartDimensions({
|
|
141
143
|
hasSecondUnit: Boolean(secondUnit),
|
|
142
144
|
height,
|
|
@@ -144,7 +146,10 @@ const Chart = ({
|
|
|
144
146
|
legendHeight: legend?.height,
|
|
145
147
|
legendPlacement: legend?.placement,
|
|
146
148
|
width,
|
|
147
|
-
|
|
149
|
+
maxLeftAxisCharacters,
|
|
150
|
+
maxRightAxisCharacters,
|
|
151
|
+
title,
|
|
152
|
+
units: allUnits
|
|
148
153
|
});
|
|
149
154
|
|
|
150
155
|
const xScale = useMemo(
|
|
@@ -205,8 +210,6 @@ const Chart = ({
|
|
|
205
210
|
[displayedLines]
|
|
206
211
|
);
|
|
207
212
|
|
|
208
|
-
const allUnits = getUnits(linesGraph);
|
|
209
|
-
|
|
210
213
|
useEffect(
|
|
211
214
|
() => {
|
|
212
215
|
setLinesGraph(
|
|
@@ -4,7 +4,7 @@ import { equals, isNil } from 'ramda';
|
|
|
4
4
|
|
|
5
5
|
import useResizeObserver from 'use-resize-observer';
|
|
6
6
|
import { margin } from '../../Chart/common';
|
|
7
|
-
import {
|
|
7
|
+
import { useMarginTop } from '../useMarginTop';
|
|
8
8
|
|
|
9
9
|
export const extraMargin = 10;
|
|
10
10
|
|
|
@@ -15,7 +15,10 @@ interface UseComputeBaseChartDimensionsProps {
|
|
|
15
15
|
legendHeight?: number;
|
|
16
16
|
legendPlacement?: string;
|
|
17
17
|
width: number;
|
|
18
|
-
|
|
18
|
+
maxLeftAxisCharacters: number;
|
|
19
|
+
maxRightAxisCharacters: number;
|
|
20
|
+
title?: string;
|
|
21
|
+
units: Array<string>;
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
interface UseComputeBaseChartDimensionsState {
|
|
@@ -32,17 +35,22 @@ export const useComputeBaseChartDimensions = ({
|
|
|
32
35
|
legendPlacement,
|
|
33
36
|
hasSecondUnit,
|
|
34
37
|
legendHeight,
|
|
35
|
-
|
|
38
|
+
maxLeftAxisCharacters,
|
|
39
|
+
maxRightAxisCharacters,
|
|
40
|
+
units,
|
|
41
|
+
title
|
|
36
42
|
}: UseComputeBaseChartDimensionsProps): UseComputeBaseChartDimensionsState => {
|
|
37
43
|
const {
|
|
38
44
|
ref: legendRef,
|
|
39
45
|
width: legendRefWidth,
|
|
40
46
|
height: legendRefHeight
|
|
41
47
|
} = useResizeObserver();
|
|
42
|
-
const { height: titleRefHeight } = useResizeObserver();
|
|
48
|
+
const { ref: titleRef, height: titleRefHeight } = useResizeObserver();
|
|
43
49
|
|
|
44
50
|
const currentLegendHeight = legendHeight ?? (legendRefHeight || 0);
|
|
45
51
|
|
|
52
|
+
const marginTop = useMarginTop({ title, units });
|
|
53
|
+
|
|
46
54
|
const legendBoundingHeight =
|
|
47
55
|
!equals(legendDisplay, false) &&
|
|
48
56
|
(isNil(legendPlacement) || equals(legendPlacement, 'bottom'))
|
|
@@ -57,22 +65,19 @@ export const useComputeBaseChartDimensions = ({
|
|
|
57
65
|
const graphWidth =
|
|
58
66
|
width > 0
|
|
59
67
|
? width -
|
|
60
|
-
(hasSecondUnit ?
|
|
61
|
-
|
|
68
|
+
(hasSecondUnit ? maxRightAxisCharacters * 2 : maxRightAxisCharacters) *
|
|
69
|
+
6 -
|
|
70
|
+
(hasSecondUnit ? maxLeftAxisCharacters * 6 : margin.left) -
|
|
62
71
|
legendBoundingWidth
|
|
63
72
|
: 0;
|
|
64
73
|
const graphHeight =
|
|
65
74
|
(height || 0) > 0
|
|
66
|
-
? (height || 0) -
|
|
67
|
-
margin.top -
|
|
68
|
-
legendBoundingHeight -
|
|
69
|
-
(titleRefHeight || 0) -
|
|
70
|
-
5
|
|
75
|
+
? (height || 0) - marginTop - legendBoundingHeight - (titleRefHeight || 0)
|
|
71
76
|
: 0;
|
|
72
|
-
|
|
73
77
|
return {
|
|
74
78
|
graphHeight,
|
|
75
79
|
graphWidth,
|
|
76
|
-
legendRef
|
|
80
|
+
legendRef,
|
|
81
|
+
titleRef
|
|
77
82
|
};
|
|
78
83
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { identity } from 'ramda';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { margin } from '../Chart/common';
|
|
4
|
+
|
|
5
|
+
export const useMarginTop = ({
|
|
6
|
+
title,
|
|
7
|
+
units
|
|
8
|
+
}: { title?: string; units: Array<string> }): number => {
|
|
9
|
+
const hasUnits = useMemo(() => units.some(identity), [units]);
|
|
10
|
+
|
|
11
|
+
const marginTop = useMemo(
|
|
12
|
+
() => (title || hasUnits ? margin.top : 4),
|
|
13
|
+
[title, hasUnits]
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
return marginTop;
|
|
17
|
+
};
|