@centreon/ui 24.6.2 → 24.6.4

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.
Files changed (54) hide show
  1. package/package.json +1 -1
  2. package/src/Graph/BarChart/BarChart.cypress.spec.tsx +233 -0
  3. package/src/Graph/BarChart/BarChart.stories.tsx +213 -0
  4. package/src/Graph/BarChart/BarChart.tsx +101 -0
  5. package/src/Graph/BarChart/BarGroup.tsx +246 -0
  6. package/src/Graph/BarChart/BarStack.tsx +126 -0
  7. package/src/Graph/BarChart/ResponsiveBarChart.tsx +263 -0
  8. package/src/Graph/BarChart/SingleBar.tsx +62 -0
  9. package/src/Graph/BarChart/Tooltip/BarChartTooltip.tsx +122 -0
  10. package/src/Graph/BarChart/Tooltip/useBarChartTooltipStyles.ts +28 -0
  11. package/src/Graph/BarChart/atoms.ts +5 -0
  12. package/src/Graph/BarChart/models.ts +21 -0
  13. package/src/Graph/BarChart/useBarChartStyles.tsx +5 -0
  14. package/src/Graph/BarChart/useBarStack.ts +114 -0
  15. package/src/Graph/BarChart/useSingleBar.ts +199 -0
  16. package/src/Graph/Gauge/Gauge.cypress.spec.tsx +1 -1
  17. package/src/Graph/Gauge/Gauge.stories.tsx +1 -1
  18. package/src/Graph/LineChart/LineChart.cypress.spec.tsx +4 -4
  19. package/src/Graph/LineChart/LineChart.styles.ts +0 -5
  20. package/src/Graph/LineChart/LineChart.tsx +118 -122
  21. package/src/Graph/LineChart/index.stories.tsx +12 -12
  22. package/src/Graph/SingleBar/SingleBar.cypress.spec.tsx +1 -1
  23. package/src/Graph/SingleBar/SingleBar.stories.tsx +1 -1
  24. package/src/Graph/Text/Text.cypress.spec.tsx +1 -1
  25. package/src/Graph/Text/Text.stories.tsx +1 -1
  26. package/src/Graph/common/Axes/index.tsx +40 -13
  27. package/src/Graph/common/BaseChart/BaseChart.tsx +25 -6
  28. package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +15 -4
  29. package/src/Graph/{LineChart → common/BaseChart}/Header/index.tsx +3 -3
  30. package/src/Graph/common/BaseChart/Header/models.ts +4 -0
  31. package/src/Graph/common/BaseChart/Header/useHeaderStyles.ts +9 -0
  32. package/src/Graph/common/BaseChart/useBaseChartStyles.ts +6 -0
  33. package/src/Graph/{LineChart/BasicComponents → common/Thresholds}/ThresholdLine.tsx +20 -10
  34. package/src/Graph/{LineChart/BasicComponents → common/Thresholds}/Thresholds.tsx +8 -4
  35. package/src/Graph/common/timeSeries/index.ts +33 -11
  36. package/src/Graph/common/timeSeries/models.ts +1 -0
  37. package/src/Graph/common/useTooltipStyles.ts +1 -0
  38. package/src/Graph/mockedData/pingService.json +203 -0
  39. package/src/Graph/mockedData/pingServiceMixedStacked.json +203 -0
  40. package/src/Graph/mockedData/pingServiceStacked.json +203 -0
  41. /package/src/Graph/{LineChart/mockedData → mockedData}/annotationData.json +0 -0
  42. /package/src/Graph/{LineChart/mockedData → mockedData}/curvesWithSameColor.json +0 -0
  43. /package/src/Graph/{LineChart/mockedData → mockedData}/exclusionPeriodFirstPeriod.json +0 -0
  44. /package/src/Graph/{LineChart/mockedData → mockedData}/exclusionPeriodSecondPeriod.json +0 -0
  45. /package/src/Graph/{LineChart/mockedData → mockedData}/exclusionPeriodThirdPeriod.json +0 -0
  46. /package/src/Graph/{LineChart/mockedData → mockedData}/lastDay.json +0 -0
  47. /package/src/Graph/{LineChart/mockedData → mockedData}/lastDayAreaStack.json +0 -0
  48. /package/src/Graph/{LineChart/mockedData → mockedData}/lastDayForward.json +0 -0
  49. /package/src/Graph/{LineChart/mockedData → mockedData}/lastDayThreshold.json +0 -0
  50. /package/src/Graph/{LineChart/mockedData → mockedData}/lastDayWithIncompleteValues.json +0 -0
  51. /package/src/Graph/{LineChart/mockedData → mockedData}/lastDayWithNullValues.json +0 -0
  52. /package/src/Graph/{LineChart/mockedData → mockedData}/lastMonth.json +0 -0
  53. /package/src/Graph/{LineChart/mockedData → mockedData}/lastWeek.json +0 -0
  54. /package/src/Graph/{LineChart/mockedData → mockedData}/zoomPreview.json +0 -0
@@ -18,18 +18,17 @@ import { useTooltipStyles } from '../common/useTooltipStyles';
18
18
  import BaseChart from '../common/BaseChart/BaseChart';
19
19
  import { useComputeBaseChartDimensions } from '../common/BaseChart/useComputeBaseChartDimensions';
20
20
  import ChartSvgWrapper from '../common/BaseChart/ChartSvgWrapper';
21
+ import Thresholds from '../common/Thresholds/Thresholds';
21
22
 
22
23
  import Lines from './BasicComponents/Lines';
23
24
  import { canDisplayThreshold } from './BasicComponents/Lines/Threshold/models';
24
25
  import useFilterLines from './BasicComponents/useFilterLines';
25
- import Header from './Header';
26
26
  import InteractionWithGraph from './InteractiveComponents';
27
27
  import GraphTooltip from './InteractiveComponents/Tooltip';
28
28
  import useGraphTooltip from './InteractiveComponents/Tooltip/useGraphTooltip';
29
29
  import { margin } from './common';
30
30
  import { Data, GlobalAreaLines, GraphInterval, LineChartProps } from './models';
31
31
  import { useIntersection } from './useLineChartIntersection';
32
- import Thresholds from './BasicComponents/Thresholds';
33
32
  import GraphValueTooltip from './InteractiveComponents/GraphValueTooltip/GraphValueTooltip';
34
33
  import { useLineChartStyles } from './LineChart.styles';
35
34
 
@@ -190,134 +189,131 @@ const LineChart = ({
190
189
  }
191
190
 
192
191
  return (
193
- <>
194
- <Header header={header} title={title} />
195
- <ClickAwayListener onClickAway={graphTooltipData?.hideTooltip}>
196
- <>
197
- <BaseChart
198
- base={baseAxis}
199
- graphWidth={graphWidth}
200
- height={height}
201
- legend={{
202
- displayLegend,
203
- mode: legend?.mode,
204
- placement: legend?.placement,
205
- renderExtraComponent: legend?.renderExtraComponent
192
+ <ClickAwayListener onClickAway={graphTooltipData?.hideTooltip}>
193
+ <>
194
+ <BaseChart
195
+ base={baseAxis}
196
+ graphWidth={graphWidth}
197
+ header={header}
198
+ height={height}
199
+ legend={{
200
+ displayLegend,
201
+ mode: legend?.mode,
202
+ placement: legend?.placement,
203
+ renderExtraComponent: legend?.renderExtraComponent
204
+ }}
205
+ legendRef={legendRef}
206
+ limitLegend={limitLegend}
207
+ lines={displayedLines}
208
+ setLines={setLinesGraph}
209
+ title={title}
210
+ >
211
+ <MuiTooltip
212
+ classes={{
213
+ tooltip: cx(
214
+ tooltipClasses.tooltip,
215
+ tooltipClasses.tooltipDisablePadding
216
+ )
206
217
  }}
207
- legendRef={legendRef}
208
- limitLegend={limitLegend}
209
- lines={displayedLines}
210
- setLines={setLinesGraph}
218
+ placement="top-start"
219
+ title={
220
+ equals('hidden', tooltip?.mode) ? null : (
221
+ <GraphValueTooltip
222
+ base={baseAxis}
223
+ isSingleMode={equals('single', tooltip?.mode)}
224
+ sortOrder={tooltip?.sortOrder}
225
+ />
226
+ )
227
+ }
211
228
  >
212
- <MuiTooltip
213
- classes={{
214
- tooltip: cx(
215
- tooltipClasses.tooltip,
216
- tooltipClasses.tooltipDisablePadding
217
- )
218
- }}
219
- placement="top-start"
220
- title={
221
- equals('hidden', tooltip?.mode) ? null : (
222
- <GraphValueTooltip
223
- base={baseAxis}
224
- isSingleMode={equals('single', tooltip?.mode)}
225
- sortOrder={tooltip?.sortOrder}
229
+ <div className={classes.tooltipChildren}>
230
+ <ChartSvgWrapper
231
+ axis={axis}
232
+ base={baseAxis}
233
+ displayedLines={displayedLines}
234
+ graphHeight={graphHeight}
235
+ graphWidth={graphWidth}
236
+ gridLinesType={axis?.gridLinesType}
237
+ leftScale={leftScale}
238
+ rightScale={rightScale}
239
+ showGridLines={showGridLines}
240
+ svgRef={graphSvgRef}
241
+ timeSeries={timeSeries}
242
+ xScale={xScale}
243
+ >
244
+ <>
245
+ <Lines
246
+ areaTransparency={lineStyle?.areaTransparency}
247
+ curve={lineStyle?.curve || 'linear'}
248
+ dashLength={lineStyle?.dashLength}
249
+ dashOffset={lineStyle?.dashOffset}
250
+ displayAnchor={displayAnchor}
251
+ displayedLines={displayedLines}
252
+ dotOffset={lineStyle?.dotOffset}
253
+ graphSvgRef={graphSvgRef}
254
+ height={graphHeight - margin.top}
255
+ leftScale={leftScale}
256
+ lineWidth={lineStyle?.lineWidth}
257
+ rightScale={rightScale}
258
+ showArea={lineStyle?.showArea}
259
+ showPoints={lineStyle?.showPoints}
260
+ timeSeries={timeSeries}
261
+ width={graphWidth}
262
+ xScale={xScale}
263
+ {...shapeLines}
226
264
  />
227
- )
228
- }
229
- >
230
- <div className={classes.tooltipChildren}>
231
- <ChartSvgWrapper
232
- axis={axis}
233
- base={baseAxis}
234
- displayedLines={displayedLines}
235
- graphHeight={graphHeight}
236
- graphWidth={graphWidth}
237
- gridLinesType={axis?.gridLinesType}
238
- leftScale={leftScale}
239
- rightScale={rightScale}
240
- showGridLines={showGridLines}
241
- svgRef={graphSvgRef}
242
- timeSeries={timeSeries}
243
- xScale={xScale}
244
- >
245
- <>
246
- <Lines
247
- areaTransparency={lineStyle?.areaTransparency}
248
- curve={lineStyle?.curve || 'linear'}
249
- dashLength={lineStyle?.dashLength}
250
- dashOffset={lineStyle?.dashOffset}
251
- displayAnchor={displayAnchor}
265
+ <InteractionWithGraph
266
+ annotationData={{ ...annotationEvent }}
267
+ commonData={{
268
+ graphHeight,
269
+ graphSvgRef,
270
+ graphWidth,
271
+ leftScale,
272
+ lines: displayedLines,
273
+ rightScale,
274
+ timeSeries,
275
+ xScale
276
+ }}
277
+ timeShiftZonesData={{
278
+ ...timeShiftZones,
279
+ graphInterval
280
+ }}
281
+ zoomData={{ ...zoomPreview }}
282
+ />
283
+ {thresholds?.enabled && (
284
+ <Thresholds
252
285
  displayedLines={displayedLines}
253
- dotOffset={lineStyle?.dotOffset}
254
- graphSvgRef={graphSvgRef}
255
- height={graphHeight - margin.top}
286
+ hideTooltip={hideThresholdTooltip}
256
287
  leftScale={leftScale}
257
- lineWidth={lineStyle?.lineWidth}
258
288
  rightScale={rightScale}
259
- showArea={lineStyle?.showArea}
260
- showPoints={lineStyle?.showPoints}
261
- timeSeries={timeSeries}
289
+ showTooltip={showThresholdTooltip}
290
+ thresholdUnit={thresholdUnit}
291
+ thresholds={thresholds as ThresholdsModel}
262
292
  width={graphWidth}
263
- xScale={xScale}
264
- {...shapeLines}
265
293
  />
266
- <InteractionWithGraph
267
- annotationData={{ ...annotationEvent }}
268
- commonData={{
269
- graphHeight,
270
- graphSvgRef,
271
- graphWidth,
272
- leftScale,
273
- lines: displayedLines,
274
- rightScale,
275
- timeSeries,
276
- xScale
277
- }}
278
- timeShiftZonesData={{
279
- ...timeShiftZones,
280
- graphInterval
281
- }}
282
- zoomData={{ ...zoomPreview }}
283
- />
284
- {thresholds?.enabled && (
285
- <Thresholds
286
- displayedLines={displayedLines}
287
- hideTooltip={hideThresholdTooltip}
288
- leftScale={leftScale}
289
- rightScale={rightScale}
290
- showTooltip={showThresholdTooltip}
291
- thresholdUnit={thresholdUnit}
292
- thresholds={thresholds as ThresholdsModel}
293
- width={graphWidth}
294
- />
295
- )}
296
- </>
297
- </ChartSvgWrapper>
298
- </div>
299
- </MuiTooltip>
300
- </BaseChart>
301
- {displayTooltip && (
302
- <GraphTooltip {...tooltip} {...graphTooltipData} />
303
- )}
304
- <Fade in={thresholdTooltipOpen}>
305
- <Tooltip.Tooltip
306
- left={thresholdTooltipLeft}
307
- style={{
308
- ...baseStyles,
309
- backgroundColor: theme.palette.background.paper,
310
- color: theme.palette.text.primary,
311
- transform: `translate(${graphWidth / 2}px, -10px)`
312
- }}
313
- top={thresholdTooltipTop}
314
- >
315
- {thresholdTooltipData}
316
- </Tooltip.Tooltip>
317
- </Fade>
318
- </>
319
- </ClickAwayListener>
320
- </>
294
+ )}
295
+ </>
296
+ </ChartSvgWrapper>
297
+ </div>
298
+ </MuiTooltip>
299
+ </BaseChart>
300
+ {displayTooltip && <GraphTooltip {...tooltip} {...graphTooltipData} />}
301
+ <Fade in={thresholdTooltipOpen}>
302
+ <Tooltip.Tooltip
303
+ left={thresholdTooltipLeft}
304
+ style={{
305
+ ...baseStyles,
306
+ backgroundColor: theme.palette.background.paper,
307
+ color: theme.palette.text.primary,
308
+ transform: `translate(${graphWidth / 2}px, -10px)`
309
+ }}
310
+ top={thresholdTooltipTop}
311
+ >
312
+ {thresholdTooltipData}
313
+ </Tooltip.Tooltip>
314
+ </Fade>
315
+ </>
316
+ </ClickAwayListener>
321
317
  );
322
318
  };
323
319
 
@@ -11,8 +11,18 @@ import { useLocaleDateTimeFormat } from '@centreon/ui';
11
11
 
12
12
  import TimePeriod from '../../TimePeriods';
13
13
  import { LineChartData } from '../common/models';
14
+ import annotationData from '../mockedData/annotationData.json';
15
+ import exclusionPeriodFirstPeriod from '../mockedData/exclusionPeriodFirstPeriod.json';
16
+ import exclusionPeriodSecondPeriod from '../mockedData/exclusionPeriodSecondPeriod.json';
17
+ import exclusionPeriodThirdPeriod from '../mockedData/exclusionPeriodThirdPeriod.json';
18
+ import dataLastDayForword from '../mockedData/lastDayForward.json';
19
+ import dataLastDayThreshold from '../mockedData/lastDayThreshold.json';
20
+ import dataLastMonth from '../mockedData/lastMonth.json';
21
+ import dataLastWeek from '../mockedData/lastWeek.json';
22
+ import dataZoomPreview from '../mockedData/zoomPreview.json';
23
+ import dataLastDay from '../mockedData/lastDay.json';
24
+ import dataCurvesSameColor from '../mockedData/curvesWithSameColor.json';
14
25
 
15
- import { dateTimeFormat } from './common';
16
26
  import {
17
27
  argTypes,
18
28
  args as argumentsData,
@@ -23,17 +33,7 @@ import {
23
33
  lastDayForwardDate,
24
34
  zoomPreviewDate
25
35
  } from './helpers/doc';
26
- import annotationData from './mockedData/annotationData.json';
27
- import exclusionPeriodFirstPeriod from './mockedData/exclusionPeriodFirstPeriod.json';
28
- import exclusionPeriodSecondPeriod from './mockedData/exclusionPeriodSecondPeriod.json';
29
- import exclusionPeriodThirdPeriod from './mockedData/exclusionPeriodThirdPeriod.json';
30
- import dataLastDayForword from './mockedData/lastDayForward.json';
31
- import dataLastDayThreshold from './mockedData/lastDayThreshold.json';
32
- import dataLastMonth from './mockedData/lastMonth.json';
33
- import dataLastWeek from './mockedData/lastWeek.json';
34
- import dataZoomPreview from './mockedData/zoomPreview.json';
35
- import dataLastDay from './mockedData/lastDay.json';
36
- import dataCurvesSameColor from './mockedData/curvesWithSameColor.json';
36
+ import { dateTimeFormat } from './common';
37
37
  import { Interval, ThresholdType, TooltipData } from './models';
38
38
 
39
39
  import WrapperLineChart from './index';
@@ -1,4 +1,4 @@
1
- import dataLastWeek from '../LineChart/mockedData/lastWeek.json';
1
+ import dataLastWeek from '../mockedData/lastWeek.json';
2
2
  import {
3
3
  criticalThresholds,
4
4
  rangedThresholds,
@@ -1,6 +1,6 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
 
3
- import dataLastWeek from '../LineChart/mockedData/lastWeek.json';
3
+ import dataLastWeek from '../mockedData/lastWeek.json';
4
4
 
5
5
  import { SingleBar } from '.';
6
6
 
@@ -1,4 +1,4 @@
1
- import dataLastWeek from '../LineChart/mockedData/lastWeek.json';
1
+ import dataLastWeek from '../mockedData/lastWeek.json';
2
2
  import {
3
3
  criticalThresholds,
4
4
  rangedThresholds,
@@ -1,6 +1,6 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
 
3
- import dataLastWeek from '../LineChart/mockedData/lastWeek.json';
3
+ import dataLastWeek from '../mockedData/lastWeek.json';
4
4
 
5
5
  import { Text } from '.';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { Axis } from '@visx/visx';
2
2
  import { ScaleLinear } from 'd3-scale';
3
- import { isNil } from 'ramda';
3
+ import { equals, isNil } from 'ramda';
4
4
 
5
5
  import { useLocaleDateTimeFormat } from '@centreon/ui';
6
6
 
@@ -15,6 +15,7 @@ interface Props {
15
15
  data: Data;
16
16
  height: number;
17
17
  leftScale: ScaleLinear<number, number>;
18
+ orientation: 'horizontal' | 'vertical';
18
19
  rightScale: ScaleLinear<number, number>;
19
20
  width: number;
20
21
  xScale: ScaleLinear<number, number>;
@@ -26,7 +27,8 @@ const Axes = ({
26
27
  data,
27
28
  rightScale,
28
29
  leftScale,
29
- xScale
30
+ xScale,
31
+ orientation
30
32
  }: Props): JSX.Element => {
31
33
  const { format } = useLocaleDateTimeFormat();
32
34
  const { lines, showBorder, yAxisTickLabelRotation } = data;
@@ -50,47 +52,72 @@ const Axes = ({
50
52
  const hasMoreThanTwoUnits = !isNil(thirdUnit);
51
53
  const displayAxisRight = !isNil(secondUnit) && !hasMoreThanTwoUnits;
52
54
 
55
+ const isHorizontal = equals(orientation, 'horizontal');
56
+
57
+ const AxisBottom = isHorizontal ? Axis.AxisBottom : Axis.AxisLeft;
58
+ const AxisLeft = isHorizontal ? Axis.AxisLeft : Axis.AxisTop;
59
+ const AxisRight = isHorizontal ? Axis.AxisRight : Axis.AxisBottom;
60
+
53
61
  return (
54
62
  <g>
55
- <Axis.AxisBottom
63
+ <AxisBottom
56
64
  numTicks={xTickCount}
57
65
  scale={xScale}
58
66
  strokeWidth={!isNil(showBorder) && !showBorder ? 0 : 1}
59
67
  tickFormat={formatAxisTick}
60
- top={height - 5}
68
+ tickLabelProps={() => ({
69
+ ...axisLeft.tickLabelProps(),
70
+ dx: isHorizontal ? 16 : -4
71
+ })}
72
+ top={isHorizontal ? height - 5 : 0}
61
73
  />
62
74
 
63
- {axisLeft.displayUnit && <UnitLabel unit={firstUnit} x={-4} />}
75
+ {axisLeft.displayUnit && (
76
+ <UnitLabel
77
+ unit={firstUnit}
78
+ x={isHorizontal ? -8 : width + 8}
79
+ y={isHorizontal ? 16 : 0}
80
+ />
81
+ )}
64
82
 
65
- <Axis.AxisLeft
83
+ <AxisLeft
66
84
  numTicks={axisLeft?.numTicks}
67
- orientation="left"
68
85
  scale={leftScale}
69
86
  strokeWidth={!isNil(showBorder) && !showBorder ? 0 : 1}
70
87
  tickFormat={axisLeft.tickFormat}
71
88
  tickLabelProps={() => ({
72
89
  ...axisLeft.tickLabelProps(),
73
- angle: yAxisTickLabelRotation
90
+ angle: yAxisTickLabelRotation,
91
+ dx: isHorizontal ? -8 : 2,
92
+ dy: isHorizontal ? 4 : -4
74
93
  })}
75
94
  tickLength={2}
76
95
  />
77
96
 
78
97
  {displayAxisRight && (
79
- <Axis.AxisRight
80
- left={width}
98
+ <AxisRight
99
+ left={isHorizontal ? width : 0}
81
100
  numTicks={axisRight?.numTicks}
82
- orientation="right"
83
101
  scale={rightScale}
84
102
  strokeWidth={!isNil(showBorder) && !showBorder ? 0 : 1}
85
103
  tickFormat={axisRight.tickFormat}
86
104
  tickLabelProps={() => ({
87
105
  ...axisRight.tickLabelProps(),
88
- angle: yAxisTickLabelRotation
106
+ angle: yAxisTickLabelRotation,
107
+ dx: isHorizontal ? 4 : -8,
108
+ dy: 4
89
109
  })}
90
110
  tickLength={2}
111
+ top={isHorizontal ? 0 : height}
112
+ />
113
+ )}
114
+ {axisRight.displayUnit && (
115
+ <UnitLabel
116
+ unit={secondUnit}
117
+ x={width + 8}
118
+ y={isHorizontal ? 16 : -(height + 8)}
91
119
  />
92
120
  )}
93
- {axisRight.displayUnit && <UnitLabel unit={secondUnit} x={width} />}
94
121
  </g>
95
122
  );
96
123
  };
@@ -15,22 +15,29 @@ import { legendWidth } from '../../LineChart/Legend/Legend.styles';
15
15
  import { Line } from '../timeSeries/models';
16
16
 
17
17
  import { useBaseChartStyles } from './useBaseChartStyles';
18
+ import Header from './Header';
19
+ import { LineChartHeader } from './Header/models';
18
20
 
19
21
  interface Props {
20
22
  base?: number;
21
23
  children: JSX.Element;
22
24
  graphWidth: number;
25
+ header?: LineChartHeader;
23
26
  height: number | null;
27
+ isHorizontal?: boolean;
24
28
  legend: {
25
29
  displayLegend: boolean;
26
- mode: 'grid' | 'list';
27
- placement: string;
30
+ mode?: 'grid' | 'list';
31
+ placement?: 'left' | 'right' | 'bottom';
28
32
  renderExtraComponent?: ReactNode;
29
33
  };
30
34
  legendRef: MutableRefObject<HTMLDivElement | null>;
31
35
  limitLegend?: number | false;
32
36
  lines: Array<Line>;
33
- setLines: Dispatch<SetStateAction<Array<Line> | null>>;
37
+ setLines:
38
+ | Dispatch<SetStateAction<Array<Line> | null>>
39
+ | Dispatch<SetStateAction<Array<Line>>>;
40
+ title: string;
34
41
  }
35
42
 
36
43
  const BaseChart = ({
@@ -42,9 +49,12 @@ const BaseChart = ({
42
49
  limitLegend = false,
43
50
  setLines,
44
51
  children,
45
- legendRef
52
+ legendRef,
53
+ title,
54
+ header,
55
+ isHorizontal = true
46
56
  }: Props): JSX.Element => {
47
- const { classes } = useBaseChartStyles();
57
+ const { classes, cx } = useBaseChartStyles();
48
58
 
49
59
  const legendItemsWidth = useMemo(
50
60
  () => reduce((acc) => acc + legendWidth * 8 + 24, 0, lines),
@@ -66,6 +76,7 @@ const BaseChart = ({
66
76
 
67
77
  return (
68
78
  <>
79
+ <Header header={header} title={title} />
69
80
  <div className={classes.container}>
70
81
  <Stack
71
82
  direction={equals(legend?.placement, 'left') ? 'row' : 'row-reverse'}
@@ -73,7 +84,15 @@ const BaseChart = ({
73
84
  {legend.displayLegend &&
74
85
  (equals(legend?.placement, 'left') ||
75
86
  equals(legend?.placement, 'right')) && (
76
- <div ref={legendRef} style={{ maxWidth: '60%' }}>
87
+ <div
88
+ className={cx(
89
+ classes.legendContainer,
90
+ equals(legend?.placement, 'right') &&
91
+ !isHorizontal &&
92
+ classes.legendContainerVerticalSide
93
+ )}
94
+ ref={legendRef}
95
+ >
77
96
  <Legend
78
97
  base={base}
79
98
  height={height}
@@ -1,6 +1,7 @@
1
1
  import { MutableRefObject } from 'react';
2
2
 
3
3
  import { Group } from '@visx/visx';
4
+ import { equals } from 'ramda';
4
5
 
5
6
  import { margin } from '../../LineChart/common';
6
7
  import Grids from '../Grids';
@@ -19,6 +20,7 @@ interface Props {
19
20
  graphWidth: number;
20
21
  gridLinesType?: string;
21
22
  leftScale;
23
+ orientation?: 'horizontal' | 'vertical';
22
24
  rightScale;
23
25
  showGridLines: boolean;
24
26
  svgRef: MutableRefObject<SVGSVGElement | null>;
@@ -39,18 +41,26 @@ const ChartSvgWrapper = ({
39
41
  displayedLines,
40
42
  timeSeries,
41
43
  axis,
42
- children
44
+ children,
45
+ orientation = 'horizontal'
43
46
  }: Props): JSX.Element => {
47
+ const isHorizontal = equals(orientation, 'horizontal');
48
+
44
49
  return (
45
- <svg height={graphHeight + margin.top} ref={svgRef} width="100%">
50
+ <svg
51
+ aria-label="graph"
52
+ height={graphHeight + margin.top}
53
+ ref={svgRef}
54
+ width="100%"
55
+ >
46
56
  <Group.Group left={margin.left + extraMargin / 2} top={margin.top}>
47
57
  {showGridLines && (
48
58
  <Grids
49
59
  gridLinesType={gridLinesType}
50
60
  height={graphHeight - margin.top}
51
- leftScale={leftScale}
61
+ leftScale={isHorizontal ? leftScale : xScale}
52
62
  width={graphWidth}
53
- xScale={xScale}
63
+ xScale={isHorizontal ? xScale : leftScale}
54
64
  />
55
65
  )}
56
66
  <Axes
@@ -62,6 +72,7 @@ const ChartSvgWrapper = ({
62
72
  }}
63
73
  height={graphHeight - margin.top}
64
74
  leftScale={leftScale}
75
+ orientation={orientation}
65
76
  rightScale={rightScale}
66
77
  width={graphWidth}
67
78
  xScale={xScale}
@@ -2,8 +2,8 @@ import Typography from '@mui/material/Typography';
2
2
 
3
3
  import { useMemoComponent } from '@centreon/ui';
4
4
 
5
- import { useLineChartStyles } from '../LineChart.styles';
6
- import { LineChartHeader } from '../models';
5
+ import { ussHeaderChartStyles } from './useHeaderStyles';
6
+ import { LineChartHeader } from './models';
7
7
 
8
8
  interface Props {
9
9
  header?: LineChartHeader;
@@ -11,7 +11,7 @@ interface Props {
11
11
  }
12
12
 
13
13
  const Header = ({ title, header }: Props): JSX.Element => {
14
- const { classes } = useLineChartStyles();
14
+ const { classes } = ussHeaderChartStyles();
15
15
 
16
16
  const displayTitle = header?.displayTitle ?? true;
17
17
 
@@ -0,0 +1,4 @@
1
+ export interface LineChartHeader {
2
+ displayTitle?: boolean;
3
+ extraComponent?: ReactNode;
4
+ }
@@ -0,0 +1,9 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ export const ussHeaderChartStyles = makeStyles()({
4
+ header: {
5
+ display: 'grid',
6
+ gridTemplateColumns: '0.4fr 1fr 0.4fr',
7
+ width: '100%'
8
+ }
9
+ });
@@ -34,5 +34,11 @@ export const useBaseChartStyles = makeStyles()((theme) => ({
34
34
  },
35
35
  fill: theme.palette.text.primary,
36
36
  position: 'relative'
37
+ },
38
+ legendContainer: {
39
+ maxWidth: '60%'
40
+ },
41
+ legendContainerVerticalSide: {
42
+ marginRight: theme.spacing(6)
37
43
  }
38
44
  }));