@centreon/ui 26.9.0 → 26.11.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "26.9.0",
3
+ "version": "26.11.0",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -162,7 +162,7 @@
162
162
  "ramda": "0.30.1",
163
163
  "react-grid-layout": "^2.2.2",
164
164
  "react-resizable": "^3.0.5",
165
- "react-router": "7.12.0",
165
+ "react-router": "7.14.2",
166
166
  "react-transition-group": "^4.4.5",
167
167
  "sanitize-html": "^2.14.0",
168
168
  "ulog": "^2.0.0-beta.19"
@@ -70,19 +70,8 @@ const initialize = ({
70
70
  cy.viewport('macbook-13');
71
71
  };
72
72
 
73
- const checkWidth = (orientation): void => {
74
- if (orientation === 'vertical') {
75
- cy.get('g[class*="visx-rows"] > line')
76
- .eq(0)
77
- .should('have.attr', 'x2')
78
- .and('equal', '1133');
79
-
80
- return;
81
- }
82
- cy.get('g[class*="visx-rows"] > line')
83
- .eq(0)
84
- .should('have.attr', 'x2')
85
- .and('equal', '1168');
73
+ const checkWidth = (): void => {
74
+ cy.get('g[class*="visx-rows"] > line').eq(0).should('have.attr', 'x2');
86
75
  };
87
76
 
88
77
  describe('Bar chart', () => {
@@ -91,7 +80,7 @@ describe('Bar chart', () => {
91
80
  orientation: 'horizontal'
92
81
  });
93
82
 
94
- checkWidth('horizontal');
83
+ checkWidth();
95
84
  cy.contains('0 ms').should('be.visible');
96
85
  cy.contains('20').should('be.visible');
97
86
  cy.contains(':40 AM').should('be.visible');
@@ -117,7 +106,7 @@ describe('Bar chart', () => {
117
106
  }
118
107
  });
119
108
 
120
- checkWidth('horizontal');
109
+ checkWidth();
121
110
  cy.contains('0 ms').should('be.visible');
122
111
  cy.contains('20').should('be.visible');
123
112
  cy.contains(':40 AM').should('be.visible');
@@ -147,7 +136,7 @@ describe('Bar chart', () => {
147
136
  const userData = renderHook(() => useAtomValue(userAtom));
148
137
  userData.result.current.locale = 'en';
149
138
 
150
- checkWidth(orientation);
139
+ checkWidth();
151
140
  cy.contains('0 ms').should('be.visible');
152
141
  cy.contains('20').should('be.visible');
153
142
  cy.contains(':40 AM').should('be.visible');
@@ -160,7 +149,7 @@ describe('Bar chart', () => {
160
149
  it(`displays the bar chart ${orientation}ly centered in zero`, () => {
161
150
  initialize({ axis: { isCenteredZero: true }, orientation });
162
151
 
163
- checkWidth(orientation);
152
+ checkWidth();
164
153
  cy.contains('0 ms').should('be.visible');
165
154
  cy.contains('20').should('be.visible');
166
155
  cy.contains(':40 AM').should('be.visible');
@@ -173,7 +162,7 @@ describe('Bar chart', () => {
173
162
  it(`displays the stacked bar chart ${orientation}ly`, () => {
174
163
  initialize({ data: dataPingServiceStacked, orientation });
175
164
 
176
- checkWidth(orientation);
165
+ checkWidth();
177
166
  cy.contains('0 ms').should('be.visible');
178
167
  cy.contains('20').should('be.visible');
179
168
  cy.contains(':40 AM').should('be.visible');
@@ -186,7 +175,7 @@ describe('Bar chart', () => {
186
175
  it(`displays bar chart ${orientation}ly with a mix of stacked and non-stacked data`, () => {
187
176
  initialize({ data: dataPingServiceMixedStacked, orientation });
188
177
 
189
- checkWidth(orientation);
178
+ checkWidth();
190
179
  cy.contains('0 ms').should('be.visible');
191
180
  cy.contains('20').should('be.visible');
192
181
  cy.contains(':40 AM').should('be.visible');
@@ -201,7 +190,7 @@ describe('Bar chart', () => {
201
190
  orientation
202
191
  });
203
192
 
204
- checkWidth(orientation);
193
+ checkWidth();
205
194
  cy.contains('0 ms').should('be.visible');
206
195
  cy.contains('20').should('be.visible');
207
196
  cy.contains(':40 AM').should('be.visible');
@@ -216,7 +205,7 @@ describe('Bar chart', () => {
216
205
  orientation
217
206
  });
218
207
 
219
- checkWidth(orientation);
208
+ checkWidth();
220
209
  cy.contains('0 ms').should('be.visible');
221
210
  cy.contains('20').should('be.visible');
222
211
  cy.contains(':40 AM').should('be.visible');
@@ -231,7 +220,7 @@ describe('Bar chart', () => {
231
220
  orientation
232
221
  });
233
222
 
234
- checkWidth(orientation);
223
+ checkWidth();
235
224
  cy.contains('0 ms').should('be.visible');
236
225
  cy.contains('20').should('be.visible');
237
226
  cy.contains(':40 AM').should('be.visible');
@@ -250,7 +239,7 @@ describe('Bar chart', () => {
250
239
  }
251
240
  });
252
241
 
253
- checkWidth('horizontal');
242
+ checkWidth();
254
243
  cy.contains('0 ms').should('be.visible');
255
244
  cy.contains('20').should('be.visible');
256
245
  cy.contains(':40 AM').should('be.visible');
@@ -91,6 +91,9 @@ const ResponsiveBarChart = ({
91
91
  zoomPreview,
92
92
  annotationEvent
93
93
  }: Props): ReactElement => {
94
+ const maxLeftAxisCharactersRef = useRef(0);
95
+ const maxRightAxisCharactersRef = useRef(0);
96
+
94
97
  const { title, timeSeries, baseAxis, lines } = graphData || {};
95
98
 
96
99
  const { classes, cx } = useTooltipStyles();
@@ -111,23 +114,14 @@ const ResponsiveBarChart = ({
111
114
  const [firstUnit, secondUnit] = getUnits(displayedLines);
112
115
  const allUnits = getUnits(lines || []);
113
116
 
114
- const { maxLeftAxisCharacters, maxRightAxisCharacters } =
115
- useComputeYAxisMaxCharacters({
116
- axis,
117
- firstUnit,
118
- graphData,
119
- secondUnit,
120
- thresholds,
121
- thresholdUnit
122
- });
123
-
124
117
  const { legendRef, graphWidth, graphHeight, titleRef } =
125
118
  useComputeBaseChartDimensions({
126
119
  hasSecondUnit: Boolean(secondUnit),
127
120
  height,
128
121
  legendDisplay: legend?.display,
129
122
  legendPlacement: legend?.placement,
130
- maxAxisCharacters: maxRightAxisCharacters || maxLeftAxisCharacters,
123
+ maxLeftAxisCharacters: maxLeftAxisCharactersRef.current,
124
+ maxRightAxisCharacters: maxRightAxisCharactersRef.current,
131
125
  title,
132
126
  units: allUnits,
133
127
  width
@@ -202,6 +196,22 @@ const ResponsiveBarChart = ({
202
196
 
203
197
  const leftScale = yScalesPerUnit[firstUnit ?? allUnits[0]];
204
198
  const rightScale = yScalesPerUnit[secondUnit ?? allUnits[1]];
199
+
200
+ const { maxLeftAxisCharacters, maxRightAxisCharacters } =
201
+ useComputeYAxisMaxCharacters({
202
+ axis,
203
+ base: baseAxis,
204
+ displayedLines,
205
+ graphHeight,
206
+ graphWidth,
207
+ isHorizontal,
208
+ leftScale,
209
+ rightScale
210
+ });
211
+
212
+ maxRightAxisCharactersRef.current = maxRightAxisCharacters;
213
+ maxLeftAxisCharactersRef.current = maxLeftAxisCharacters;
214
+
205
215
  const pixelsToShift = computPixelsToShiftMouse(xScaleLinear);
206
216
 
207
217
  useEffect(
@@ -286,9 +296,8 @@ const ResponsiveBarChart = ({
286
296
  graphHeight={graphHeight}
287
297
  graphWidth={graphWidth - (isHorizontal ? 0 : margin.left - 15)}
288
298
  gridLinesType={axis?.gridLinesType}
289
- hasSecondUnit={Boolean(secondUnit)}
290
299
  leftScale={leftScale}
291
- maxAxisCharacters={maxLeftAxisCharacters}
300
+ maxLeftAxisCharacters={maxLeftAxisCharacters}
292
301
  orientation={isHorizontal ? 'horizontal' : 'vertical'}
293
302
  rightScale={rightScale}
294
303
  showGridLines={showGridLines}
@@ -112,7 +112,6 @@ const Lines = ({
112
112
  <GuidingLines
113
113
  graphHeight={height}
114
114
  graphWidth={width}
115
- hasSecondUnit={hasSecondUnit}
116
115
  hasUnit={hasUnitDisplayed}
117
116
  leftScale={leftScale}
118
117
  lines={displayedLines}
@@ -235,7 +234,6 @@ const Lines = ({
235
234
  <g key={metric_id}>
236
235
  {displayGuidingLines && (
237
236
  <RegularAnchorPoint
238
- hasSecondUnit={hasSecondUnit}
239
237
  lineColor={lineColor}
240
238
  maxLeftAxisCharacters={maxLeftAxisCharacters}
241
239
  metric_id={metric_id}
@@ -177,8 +177,8 @@ describe('Line chart', () => {
177
177
 
178
178
  cy.contains('06/18/2023').should('be.visible');
179
179
 
180
- cy.contains('0.44 s').should('be.visible');
181
- cy.contains('75.19%').should('be.visible');
180
+ cy.contains('0.56 s').should('be.visible');
181
+ cy.contains('73.25%').should('be.visible');
182
182
 
183
183
  cy.makeSnapshot();
184
184
  });
@@ -218,7 +218,7 @@ describe('Line chart', () => {
218
218
 
219
219
  cy.contains('Min: 70.31').should('be.visible');
220
220
 
221
- cy.findByTestId('graph-interaction-zone').realMouseMove(1198, 100);
221
+ cy.findByTestId('graph-interaction-zone').realMouseMove(1205, 100);
222
222
 
223
223
  cy.get('[data-metric="querytime"]').should('not.exist');
224
224
 
@@ -291,7 +291,7 @@ describe('Line chart', () => {
291
291
 
292
292
  cy.findByTestId('graph-interaction-zone')
293
293
  .should('have.attr', 'width')
294
- .and('equal', '1200');
294
+ .and('equal', '1230');
295
295
 
296
296
  cy.get('[data-icon="true"]')
297
297
  .eq(0)
@@ -530,8 +530,7 @@ describe('Line chart', () => {
530
530
 
531
531
  checkGraphWidth();
532
532
  cy.contains(':00 AM').should('be.visible');
533
- cy.get('circle[cx="245.83333333333334"]').should('be.visible');
534
- cy.get('circle[cy="256.7205013298516"]').should('be.visible');
533
+ cy.get('circle').should('have.length', 864);
535
534
 
536
535
  cy.makeSnapshot();
537
536
  });
@@ -589,7 +588,7 @@ describe('Line chart', () => {
589
588
  cy.get('path.visx-area-closed')
590
589
  .should('have.attr', 'stroke-dasharray')
591
590
  .and('equals', '5 4');
592
- cy.get('circle[cx="32.77777777777778"]').should('be.visible');
591
+ cy.get('circle').should('have.length', 288);
593
592
 
594
593
  cy.makeSnapshot();
595
594
  });
@@ -745,10 +744,10 @@ describe('Lines and bars', () => {
745
744
  checkGraphWidth();
746
745
 
747
746
  cy.get(
748
- 'path[d="M7.435261707988982,289.92398616599974 h55.91735537190083 h1v1 v100.07601383400026 a1,1 0 0 1 -1,1 h-55.91735537190083 a1,1 0 0 1 -1,-1 v-100.07601383400026 v-1h1z"]'
747
+ 'path[d="M7.473829201101932,289.92398616599974 h56.26446280991734 h1v1 v100.07601383400026 a1,1 0 0 1 -1,1 h-56.26446280991734 a1,1 0 0 1 -1,-1 v-100.07601383400026 v-1h1z"]'
749
748
  ).should('be.visible');
750
749
  cy.get(
751
- 'path[d="M23.81046831955923,235.36727985204413 h23.166942148760334 a17.37520661157025,17.37520661157025 0 0 1 17.37520661157025,17.37520661157025 v19.806293090815103 v17.37520661157025h-17.37520661157025 h-23.166942148760334 h-17.37520661157025v-17.37520661157025 v-19.806293090815103 a17.37520661157025,17.37520661157025 0 0 1 17.37520661157025,-17.37520661157025z"]'
750
+ 'path[d="M23.953168044077135,235.36727985204413 h23.305785123966935 a17.479338842975203,17.479338842975203 0 0 1 17.479338842975203,17.479338842975203 v19.598028628005196 v17.479338842975203h-17.479338842975203 h-23.305785123966935 h-17.479338842975203v-17.479338842975203 v-19.598028628005196 a17.479338842975203,17.479338842975203 0 0 1 17.479338842975203,-17.479338842975203z"]'
752
751
  ).should('be.visible');
753
752
 
754
753
  cy.makeSnapshot();
@@ -119,6 +119,8 @@ const Chart = ({
119
119
  boundariesUnit
120
120
  }: Props): ReactElement => {
121
121
  const { classes } = useChartStyles();
122
+ const maxLeftAxisCharactersRef = useRef(0);
123
+ const maxRightAxisCharactersRef = useRef(0);
122
124
 
123
125
  const { title, timeSeries, baseAxis, lines } = graphData;
124
126
 
@@ -146,16 +148,6 @@ const Chart = ({
146
148
  [displayedLines]
147
149
  );
148
150
 
149
- const { maxLeftAxisCharacters, maxRightAxisCharacters } =
150
- useComputeYAxisMaxCharacters({
151
- axis,
152
- firstUnit,
153
- graphData,
154
- secondUnit,
155
- thresholds,
156
- thresholdUnit
157
- });
158
-
159
151
  const allUnits = getUnits(linesGraph);
160
152
 
161
153
  const { legendRef, graphWidth, graphHeight, titleRef } =
@@ -165,7 +157,8 @@ const Chart = ({
165
157
  legendDisplay: legend?.display,
166
158
  legendHeight: legend?.height,
167
159
  legendPlacement: legend?.placement,
168
- maxAxisCharacters: maxRightAxisCharacters || maxLeftAxisCharacters,
160
+ maxLeftAxisCharacters: maxLeftAxisCharactersRef.current,
161
+ maxRightAxisCharacters: maxRightAxisCharactersRef.current,
169
162
  title,
170
163
  units: allUnits,
171
164
  width
@@ -230,6 +223,21 @@ const Chart = ({
230
223
  const leftScale = yScalesPerUnit[fallbackLeftUnit];
231
224
  const rightScale = yScalesPerUnit[fallbackRightUnit];
232
225
 
226
+ const { maxLeftAxisCharacters, maxRightAxisCharacters } =
227
+ useComputeYAxisMaxCharacters({
228
+ axis,
229
+ base: baseAxis,
230
+ displayedLines,
231
+ graphHeight,
232
+ graphWidth,
233
+ isHorizontal: false,
234
+ leftScale,
235
+ rightScale
236
+ });
237
+
238
+ maxRightAxisCharactersRef.current = maxRightAxisCharacters;
239
+ maxLeftAxisCharactersRef.current = maxLeftAxisCharacters;
240
+
233
241
  const linesDisplayedAsLine = useMemo(
234
242
  () =>
235
243
  displayedLines.filter(
@@ -325,9 +333,8 @@ const Chart = ({
325
333
  graphHeight={graphHeight}
326
334
  graphWidth={graphWidth}
327
335
  gridLinesType={axis?.gridLinesType}
328
- hasSecondUnit={hasSecondUnit}
329
336
  leftScale={leftScale}
330
- maxAxisCharacters={maxLeftAxisCharacters}
337
+ maxLeftAxisCharacters={maxLeftAxisCharacters}
331
338
  rightScale={rightScale}
332
339
  showGridLines={showGridLines}
333
340
  svgRef={graphSvgRef}
@@ -388,7 +395,6 @@ const Chart = ({
388
395
  xScale,
389
396
  yScalesPerUnit
390
397
  }}
391
- hasSecondUnit={hasSecondUnit}
392
398
  maxLeftAxisCharacters={maxLeftAxisCharacters}
393
399
  timeShiftZonesData={{
394
400
  ...timeShiftZones,
@@ -12,14 +12,12 @@ const GuidingLines = ({
12
12
  graphHeight,
13
13
  graphWidth,
14
14
  maxLeftAxisCharacters,
15
- hasSecondUnit,
16
15
  lines,
17
16
  leftScale,
18
17
  rightScale,
19
18
  hasUnit
20
19
  }: GuidingLinesModel): ReactElement | null => {
21
20
  const { positionX, positionY } = useTickGraph({
22
- hasSecondUnit,
23
21
  hasUnit,
24
22
  leftScale,
25
23
  lines,
@@ -13,7 +13,6 @@ interface Props {
13
13
  timeSeries: Array<TimeValue>;
14
14
  xScale: ScaleTime<number, number>;
15
15
  yScale: ScaleLinear<number, number>;
16
- hasSecondUnit?: boolean;
17
16
  maxLeftAxisCharacters: number;
18
17
  }
19
18
 
@@ -39,11 +38,9 @@ const RegularAnchorPoint = ({
39
38
  metric_id,
40
39
  timeSeries,
41
40
  lineColor,
42
- maxLeftAxisCharacters,
43
- hasSecondUnit
41
+ maxLeftAxisCharacters
44
42
  }: Props): JSX.Element | null => {
45
43
  const { tickAxisBottom: timeTick } = useTickGraph({
46
- hasSecondUnit,
47
44
  maxLeftAxisCharacters,
48
45
  timeSeries,
49
46
  xScale
@@ -13,7 +13,6 @@ interface Props {
13
13
  timeSeries: Array<TimeValue>;
14
14
  xScale: ScaleTime<number, number>;
15
15
  yScale: ScaleLinear<number, number>;
16
- hasSecondUnit?: boolean;
17
16
  maxLeftAxisCharacters: number;
18
17
  }
19
18
 
@@ -59,11 +58,9 @@ const StackedAnchorPoint = ({
59
58
  stackValues,
60
59
  timeSeries,
61
60
  lineColor,
62
- hasSecondUnit,
63
61
  maxLeftAxisCharacters
64
62
  }: Props): JSX.Element | null => {
65
63
  const { tickAxisBottom: timeTick } = useTickGraph({
66
- hasSecondUnit,
67
64
  maxLeftAxisCharacters,
68
65
  timeSeries,
69
66
  xScale
@@ -30,7 +30,6 @@ export interface GuidingLines {
30
30
  timeSeries: Array<TimeValue>;
31
31
  xScale: ScaleTime<number, number>;
32
32
  maxLeftAxisCharacters: number;
33
- hasSecondUnit?: boolean;
34
33
  leftScale?: ScaleLinear<number, number>;
35
34
  lines: Array<Line>;
36
35
  rightScale?: ScaleLinear<number, number>;
@@ -27,7 +27,6 @@ interface Props {
27
27
  rightScale?: ScaleLinear<number, number>;
28
28
  timeSeries: Array<TimeValue>;
29
29
  xScale: ScaleTime<number, number>;
30
- hasSecondUnit?: boolean;
31
30
  maxLeftAxisCharacters: number;
32
31
  hasUnit?: boolean;
33
32
  }
@@ -39,7 +38,6 @@ const useTickGraph = ({
39
38
  rightScale,
40
39
  lines = [],
41
40
  baseAxis = 1000,
42
- hasSecondUnit,
43
41
  maxLeftAxisCharacters,
44
42
  hasUnit
45
43
  }: Props): AnchorPointResult => {
@@ -53,11 +51,7 @@ const useTickGraph = ({
53
51
  const mousePosition = useAtomValue(mousePositionAtom);
54
52
 
55
53
  const positionX = mousePosition
56
- ? mousePosition[0] -
57
- computeGElementMarginLeft({
58
- hasSecondUnit,
59
- maxCharacters: maxLeftAxisCharacters
60
- })
54
+ ? mousePosition[0] - computeGElementMarginLeft(maxLeftAxisCharacters)
61
55
  : undefined;
62
56
  const positionY = mousePosition
63
57
  ? mousePosition[1] - (hasUnit ? 29 : 4)
@@ -74,10 +68,7 @@ const useTickGraph = ({
74
68
  const pixelToShift = computPixelsToShiftMouse(xScale);
75
69
  const mousePositionTimeTick = mousePosition
76
70
  ? getTimeValue({
77
- marginLeft: computeGElementMarginLeft({
78
- hasSecondUnit,
79
- maxCharacters: maxLeftAxisCharacters
80
- }),
71
+ marginLeft: computeGElementMarginLeft(maxLeftAxisCharacters),
81
72
  timeSeries,
82
73
  x: mousePosition[0] - pixelToShift,
83
74
  xScale
@@ -90,7 +90,6 @@ interface Props {
90
90
  fx?: (pointX: number) => number;
91
91
  fy?: (pointY: number) => number;
92
92
  };
93
- hasSecondUnit?: boolean;
94
93
  maxLeftAxisCharacters: number;
95
94
  additionalZoomMargin?: number;
96
95
  }
@@ -101,7 +100,6 @@ const InteractionWithGraph = ({
101
100
  annotationData,
102
101
  timeShiftZonesData,
103
102
  transformMatrix,
104
- hasSecondUnit,
105
103
  maxLeftAxisCharacters,
106
104
  additionalZoomMargin = 0
107
105
  }: Props): ReactElement => {
@@ -170,11 +168,8 @@ const InteractionWithGraph = ({
170
168
 
171
169
  const graphMarginLeft = useMemo(
172
170
  () =>
173
- computeGElementMarginLeft({
174
- hasSecondUnit,
175
- maxCharacters: maxLeftAxisCharacters
176
- }) + additionalZoomMargin,
177
- [additionalZoomMargin, maxLeftAxisCharacters, hasSecondUnit]
171
+ computeGElementMarginLeft(maxLeftAxisCharacters) + additionalZoomMargin,
172
+ [additionalZoomMargin, maxLeftAxisCharacters]
178
173
  );
179
174
 
180
175
  const updateMousePosition = (pointPosition: MousePosition): void => {
@@ -73,6 +73,10 @@ const Axes = ({
73
73
  const AxisLeft = isHorizontal ? Axis.AxisLeft : Axis.AxisTop;
74
74
  const AxisRight = isHorizontal ? Axis.AxisRight : Axis.AxisBottom;
75
75
 
76
+ const axisBottomProps = isHorizontal
77
+ ? {}
78
+ : ({ angle: 90, textAnchor: 'middle' } as const);
79
+
76
80
  return (
77
81
  <g>
78
82
  <AxisBottom
@@ -82,7 +86,8 @@ const Axes = ({
82
86
  tickFormat={formatAxisTick}
83
87
  tickLabelProps={() => ({
84
88
  ...(axisLeft.tickLabelProps as () => Record<string, unknown>)(),
85
- dx: data?.axisX?.dx ?? (isHorizontal ? 16 : -4)
89
+ dx: data?.axisX?.dx ?? (isHorizontal ? 16 : -12),
90
+ ...axisBottomProps
86
91
  })}
87
92
  top={isHorizontal ? height - margin.bottom : 0}
88
93
  />
@@ -30,8 +30,7 @@ interface Props {
30
30
  | ScaleTime<number, number>
31
31
  | ScaleLinear<number, number>
32
32
  | ScaleBand<number>;
33
- maxAxisCharacters?: number;
34
- hasSecondUnit?: boolean;
33
+ maxLeftAxisCharacters?: number;
35
34
  title?: string;
36
35
  }
37
36
 
@@ -51,8 +50,7 @@ const ChartSvgWrapper = ({
51
50
  children,
52
51
  orientation = 'horizontal',
53
52
  allUnits,
54
- maxAxisCharacters = 0,
55
- hasSecondUnit,
53
+ maxLeftAxisCharacters = 0,
56
54
  title
57
55
  }: Props): ReactElement => {
58
56
  const isHorizontal = equals(orientation, 'horizontal');
@@ -73,10 +71,7 @@ const ChartSvgWrapper = ({
73
71
  >
74
72
  <title>chart</title>
75
73
  <Group.Group
76
- left={computeGElementMarginLeft({
77
- hasSecondUnit,
78
- maxCharacters: maxAxisCharacters
79
- })}
74
+ left={computeGElementMarginLeft(maxLeftAxisCharacters)}
80
75
  top={marginTop}
81
76
  >
82
77
  {showGridLines && (canRenderGridRows || canRenderGridColumns) && (
@@ -2,7 +2,6 @@ import { equals, isNil } from 'ramda';
2
2
  import type { RefCallback } from 'react';
3
3
  import useResizeObserver from 'use-resize-observer';
4
4
 
5
- import { margin } from '../../Chart/common';
6
5
  import { margins } from '../margins';
7
6
  import { useMarginTop } from '../useMarginTop';
8
7
 
@@ -15,7 +14,8 @@ interface UseComputeBaseChartDimensionsProps {
15
14
  legendHeight?: number;
16
15
  legendPlacement?: string;
17
16
  width: number;
18
- maxAxisCharacters: number;
17
+ maxLeftAxisCharacters: number;
18
+ maxRightAxisCharacters: number;
19
19
  title?: string;
20
20
  units: Array<string>;
21
21
  }
@@ -32,9 +32,9 @@ export const useComputeBaseChartDimensions = ({
32
32
  height,
33
33
  legendDisplay,
34
34
  legendPlacement,
35
- hasSecondUnit,
36
35
  legendHeight,
37
- maxAxisCharacters,
36
+ maxLeftAxisCharacters,
37
+ maxRightAxisCharacters,
38
38
  units,
39
39
  title
40
40
  }: UseComputeBaseChartDimensionsProps): UseComputeBaseChartDimensionsState => {
@@ -63,8 +63,8 @@ export const useComputeBaseChartDimensions = ({
63
63
  const graphWidth =
64
64
  width > 0
65
65
  ? width -
66
- (hasSecondUnit ? maxAxisCharacters * 2 : maxAxisCharacters) * 6 -
67
- (hasSecondUnit ? margins.left * 0.8 : margin.left) -
66
+ (maxLeftAxisCharacters * 5 + maxRightAxisCharacters * 5) -
67
+ margins.left / 2 -
68
68
  legendBoundingWidth
69
69
  : 0;
70
70
  const graphHeight =
@@ -1,18 +1,21 @@
1
+ import { getTicks } from '@visx/scale';
2
+ import { ScaleLinear } from 'd3-scale';
1
3
  import { isEmpty } from 'ramda';
2
4
  import { useMemo } from 'react';
3
5
 
4
6
  import type { ChartAxis } from '../../Chart/models';
5
- import type { Data } from '../Axes/models';
6
- import type { Thresholds } from '../models';
7
- import { getFormattedAxisValues } from '../utils';
7
+ import useAxisY from '../Axes/useAxisY';
8
+ import { Line } from '../timeSeries/models';
8
9
 
9
10
  interface UseComputeYAxisMaxCharactersProps {
10
- firstUnit: string;
11
- secondUnit: string;
12
- thresholdUnit?: string;
13
- thresholds?: Thresholds;
14
- graphData: Data;
15
11
  axis?: ChartAxis;
12
+ base: number;
13
+ displayedLines: Array<Line>;
14
+ graphWidth: number;
15
+ graphHeight: number;
16
+ isHorizontal: boolean;
17
+ leftScale: ScaleLinear<number, number, never>;
18
+ rightScale: ScaleLinear<number, number, never>;
16
19
  }
17
20
 
18
21
  interface UseComputteYAxisMaxCharactersState {
@@ -21,71 +24,52 @@ interface UseComputteYAxisMaxCharactersState {
21
24
  }
22
25
 
23
26
  export const useComputeYAxisMaxCharacters = ({
24
- thresholds,
25
- firstUnit,
26
- secondUnit,
27
- graphData,
28
27
  axis,
29
- thresholdUnit
28
+ base,
29
+ displayedLines,
30
+ graphWidth,
31
+ graphHeight,
32
+ isHorizontal,
33
+ leftScale,
34
+ rightScale
30
35
  }: UseComputeYAxisMaxCharactersProps): UseComputteYAxisMaxCharactersState => {
31
- const maxLeftValue = useMemo(
32
- () =>
33
- getFormattedAxisValues({
34
- axisUnit: axis?.axisYLeft?.unit ?? firstUnit,
35
- base: graphData?.baseAxis,
36
- lines: graphData?.lines ?? [],
37
- threshold: thresholds?.critical ?? [],
38
- thresholdUnit,
39
- timeSeries: graphData?.timeSeries ?? []
40
- }),
41
- [
42
- thresholds?.critical,
43
- axis?.axisYLeft?.unit,
44
- firstUnit,
45
- graphData?.timeSeries,
46
- thresholdUnit,
47
- graphData?.lines,
48
- graphData?.baseAxis
49
- ]
50
- );
51
-
52
- const maxRightValue = useMemo(
53
- () =>
54
- getFormattedAxisValues({
55
- axisUnit: axis?.axisYRight?.unit ?? secondUnit,
56
- base: graphData.baseAxis,
57
- lines: graphData.lines ?? [],
58
- threshold: thresholds?.critical ?? [],
59
- thresholdUnit,
60
- timeSeries: graphData.timeSeries ?? []
61
- }),
62
- [
63
- thresholds?.critical,
64
- axis?.axisYRight?.unit,
65
- secondUnit,
66
- graphData.timeSeries,
67
- thresholdUnit,
68
- graphData.lines,
69
- graphData.baseAxis
70
- ]
71
- );
36
+ const { axisLeft, axisRight } = useAxisY({
37
+ data: {
38
+ baseAxis: base,
39
+ lines: displayedLines,
40
+ ...axis
41
+ },
42
+ graphHeight,
43
+ graphWidth,
44
+ isHorizontal
45
+ });
72
46
 
73
47
  // Always add a character space in case the algorithm does not compute the displayed value in axis.
74
- const maxLeftAxisCharacters = useMemo(
75
- () =>
76
- isEmpty(maxLeftValue)
77
- ? 2
78
- : Math.max(...maxLeftValue.map((value) => value.length), 2) + 1,
79
- [maxLeftValue]
80
- );
48
+ const maxLeftAxisCharacters = useMemo(() => {
49
+ if (!leftScale) {
50
+ return 0;
51
+ }
52
+
53
+ const ticks = getTicks(leftScale, axisLeft.numTicks);
54
+ const formattedTicks = ticks.map(axisLeft.tickFormat);
55
+
56
+ return isEmpty(formattedTicks)
57
+ ? 2
58
+ : Math.max(...formattedTicks.map((value) => value.length), 2) + 1;
59
+ }, [leftScale, axisLeft]);
60
+
61
+ const maxRightAxisCharacters = useMemo(() => {
62
+ if (!rightScale) {
63
+ return 0;
64
+ }
65
+
66
+ const ticks = getTicks(rightScale, axisRight.numTicks);
67
+ const formattedTicks = ticks.map(axisRight.tickFormat);
81
68
 
82
- const maxRightAxisCharacters = useMemo(
83
- () =>
84
- isEmpty(maxRightValue)
85
- ? 5
86
- : Math.max(...maxRightValue.map((value) => value.length), 5) + 1,
87
- [maxRightValue]
88
- );
69
+ return isEmpty(formattedTicks)
70
+ ? 2
71
+ : Math.max(...formattedTicks.map((value) => value.length), 2) + 1;
72
+ }, [rightScale, axisRight]);
89
73
 
90
74
  return {
91
75
  maxLeftAxisCharacters,
@@ -22,7 +22,6 @@ import {
22
22
  } from 'ramda';
23
23
 
24
24
  import type { BarStyle } from '../BarChart/models';
25
- import { margin } from '../Chart/common';
26
25
  import type { LineStyle } from '../Chart/models';
27
26
  import type { Threshold, Thresholds } from './models';
28
27
  import { formatMetricValueWithUnit } from './timeSeries';
@@ -263,16 +262,8 @@ export const getFormattedAxisValues = ({
263
262
  .filter((v) => v) as Array<string>;
264
263
  };
265
264
 
266
- interface ComputeGElementMarginLeftProps {
267
- maxCharacters: number;
268
- hasSecondUnit?: boolean;
269
- }
270
-
271
- export const computeGElementMarginLeft = ({
272
- maxCharacters,
273
- hasSecondUnit
274
- }: ComputeGElementMarginLeftProps): number =>
275
- maxCharacters * 5 + (hasSecondUnit ? margin.top * 0.8 : margin.top * 0.6);
265
+ export const computeGElementMarginLeft = (maxLeftCharacters: number): number =>
266
+ maxLeftCharacters * 5;
276
267
 
277
268
  export const computPixelsToShiftMouse = (
278
269
  xScale: import('d3-scale').ScaleTime<number, number>