@centreon/ui 24.8.2 → 24.8.3

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 (111) hide show
  1. package/package.json +14 -17
  2. package/src/Graph/BarChart/BarChart.cypress.spec.tsx +38 -79
  3. package/src/Graph/BarChart/BarChart.tsx +4 -4
  4. package/src/Graph/BarChart/BarGroup.tsx +81 -92
  5. package/src/Graph/BarChart/BarStack.tsx +21 -13
  6. package/src/Graph/BarChart/ResponsiveBarChart.tsx +26 -50
  7. package/src/Graph/BarChart/Tooltip/BarChartTooltip.tsx +1 -1
  8. package/src/Graph/BarChart/useBarStack.ts +1 -1
  9. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Point.tsx +1 -1
  10. package/src/Graph/Chart/BasicComponents/Lines/StackedLines/useStackedLines.ts +67 -0
  11. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/ThresholdWithPatternLines.tsx +4 -7
  12. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/index.tsx +6 -9
  13. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/models.ts +1 -2
  14. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/useScaleThreshold.ts +8 -20
  15. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/index.tsx +64 -43
  16. package/src/Graph/{LineChart/LineChart.cypress.spec.tsx → Chart/Chart.cypress.spec.tsx} +272 -23
  17. package/src/Graph/{LineChart/index.stories.tsx → Chart/Chart.stories.tsx} +217 -24
  18. package/src/Graph/{LineChart/LineChart.styles.ts → Chart/Chart.styles.ts} +1 -1
  19. package/src/Graph/{LineChart/LineChart.tsx → Chart/Chart.tsx} +84 -100
  20. package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/RegularAnchorPoint.tsx +5 -1
  21. package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/StackedAnchorPoint.tsx +6 -1
  22. package/src/Graph/Chart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx +61 -0
  23. package/src/Graph/{LineChart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx → Chart/InteractiveComponents/GraphValueTooltip/GraphValueTooltipContent.tsx} +2 -2
  24. package/src/Graph/{LineChart → Chart}/InteractiveComponents/index.tsx +11 -15
  25. package/src/Graph/{LineChart → Chart}/Legend/Legend.styles.ts +1 -7
  26. package/src/Graph/{LineChart → Chart}/Legend/LegendHeader.tsx +9 -5
  27. package/src/Graph/{LineChart → Chart}/Legend/index.tsx +2 -1
  28. package/src/Graph/Chart/graphAtoms.ts +6 -0
  29. package/src/Graph/{LineChart → Chart}/index.tsx +10 -7
  30. package/src/Graph/{LineChart → Chart}/models.ts +8 -3
  31. package/src/Graph/common/Axes/AxisStyles.ts +11 -0
  32. package/src/Graph/common/Axes/UnitLabel.tsx +41 -10
  33. package/src/Graph/common/Axes/index.tsx +18 -12
  34. package/src/Graph/common/Axes/models.ts +4 -2
  35. package/src/Graph/common/Axes/useAxisY.ts +22 -12
  36. package/src/Graph/common/BaseChart/BaseChart.tsx +2 -2
  37. package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +8 -5
  38. package/src/Graph/common/BaseChart/useComputeBaseChartDimensions.ts +1 -1
  39. package/src/Graph/common/Grids/index.tsx +2 -2
  40. package/src/Graph/common/Thresholds/ThresholdLine.tsx +1 -1
  41. package/src/Graph/common/Thresholds/Thresholds.tsx +10 -15
  42. package/src/Graph/common/timeSeries/index.ts +109 -131
  43. package/src/Graph/common/timeSeries/models.ts +4 -5
  44. package/src/Graph/index.ts +4 -4
  45. package/src/Graph/mockedData/lastDayWithLotOfUnits.json +1668 -0
  46. package/src/Graph/mockedData/pingService.json +46 -1
  47. package/src/Graph/mockedData/pingServiceLinesBars.json +253 -0
  48. package/src/Graph/mockedData/pingServiceLinesBarsMixed.json +253 -0
  49. package/src/Graph/mockedData/pingServiceLinesBarsStacked.json +253 -0
  50. package/src/Graph/mockedData/pingServiceMixedStacked.json +46 -1
  51. package/src/Graph/mockedData/pingServiceStacked.json +46 -1
  52. package/src/Typography/EllipsisTypography.tsx +5 -2
  53. package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +16 -24
  54. package/src/components/Form/AccessRights/AccessRights.stories.tsx +5 -5
  55. package/src/components/Form/AccessRights/AccessRights.tsx +3 -3
  56. package/src/components/Form/index.ts +2 -2
  57. package/src/utils/index.ts +2 -2
  58. package/src/Graph/BarChart/SingleBar.tsx +0 -62
  59. package/src/Graph/BarChart/useSingleBar.ts +0 -199
  60. package/src/Graph/LineChart/BasicComponents/Lines/StackedLines/useStackedLines.ts +0 -39
  61. package/src/Graph/LineChart/graphAtoms.ts +0 -3
  62. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/RegularLines/index.tsx +0 -0
  63. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/RegularLines/useRegularLines.ts +0 -0
  64. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/StackedLines/index.tsx +0 -0
  65. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/BasicThreshold.tsx +0 -0
  66. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/Circle.tsx +0 -0
  67. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/ThresholdWithVariation.tsx +0 -0
  68. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/helpers/index.ts +0 -0
  69. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/useCoordinateCircle.ts +0 -0
  70. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/models.ts +0 -0
  71. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/GuidingLines.tsx +0 -0
  72. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/index.tsx +0 -0
  73. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/models.ts +0 -0
  74. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/useTickGraph.ts +0 -0
  75. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/Area.tsx +0 -0
  76. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/Line.tsx +0 -0
  77. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/index.tsx +0 -0
  78. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Area/Downtime.tsx +0 -0
  79. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/EventAnnotations.tsx +0 -0
  80. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Line/Acknowledgement.tsx +0 -0
  81. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Line/Comments.tsx +0 -0
  82. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/annotationsAtoms.ts +0 -0
  83. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/index.tsx +0 -0
  84. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/models.ts +0 -0
  85. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/useAnnotation.ts +0 -0
  86. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Bar.tsx +0 -0
  87. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +0 -0
  88. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/GraphValueTooltip/useGraphValueTooltipStyles.ts +0 -0
  89. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/TimeShiftIcon.tsx +0 -0
  90. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/TimeShiftZone.tsx +0 -0
  91. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/index.tsx +0 -0
  92. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/models.ts +0 -0
  93. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/useTimeShiftZones.ts +0 -0
  94. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/index.tsx +0 -0
  95. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/models.ts +0 -0
  96. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/useGraphTooltip.ts +0 -0
  97. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/index.tsx +0 -0
  98. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/models.ts +0 -0
  99. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/useZoomPreview.ts +0 -0
  100. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/zoomPreviewAtoms.ts +0 -0
  101. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/interactionWithGraphAtoms.ts +0 -0
  102. /package/src/Graph/{LineChart → Chart}/Legend/LegendContent.tsx +0 -0
  103. /package/src/Graph/{LineChart → Chart}/Legend/models.ts +0 -0
  104. /package/src/Graph/{LineChart → Chart}/Legend/useLegend.ts +0 -0
  105. /package/src/Graph/{LineChart → Chart}/LoadingSkeleton.tsx +0 -0
  106. /package/src/Graph/{LineChart → Chart}/common/index.ts +0 -0
  107. /package/src/Graph/{LineChart → Chart}/helpers/doc.ts +0 -0
  108. /package/src/Graph/{LineChart → Chart}/helpers/index.ts +0 -0
  109. /package/src/Graph/{LineChart → Chart}/translatedLabels.ts +0 -0
  110. /package/src/Graph/{LineChart/useLineChartData.ts → Chart/useChartData.ts} +0 -0
  111. /package/src/Graph/{LineChart/useLineChartIntersection.ts → Chart/useChartIntersection.ts} +0 -0
@@ -0,0 +1,61 @@
1
+ import { equals } from 'ramda';
2
+
3
+ import { Typography } from '@mui/material';
4
+
5
+ import { Tooltip as MuiTooltip } from '../../../../components/Tooltip';
6
+ import { ThresholdTooltip, Tooltip } from '../../models';
7
+ import { useTooltipStyles } from '../../../common/useTooltipStyles';
8
+
9
+ import GraphValueTooltipContent from './GraphValueTooltipContent';
10
+
11
+ interface Props {
12
+ baseAxis: number;
13
+ children: JSX.Element;
14
+ thresholdTooltip: ThresholdTooltip | null;
15
+ tooltip?: Tooltip;
16
+ }
17
+
18
+ const GraphValueTooltip = ({
19
+ children,
20
+ tooltip,
21
+ baseAxis,
22
+ thresholdTooltip
23
+ }: Props): JSX.Element => {
24
+ const { classes, cx } = useTooltipStyles();
25
+
26
+ if (thresholdTooltip) {
27
+ return (
28
+ <MuiTooltip
29
+ classes={{
30
+ tooltip: classes.tooltip
31
+ }}
32
+ placement="top-start"
33
+ title={<Typography>{thresholdTooltip?.thresholdLabel}</Typography>}
34
+ >
35
+ {children}
36
+ </MuiTooltip>
37
+ );
38
+ }
39
+
40
+ return (
41
+ <MuiTooltip
42
+ classes={{
43
+ tooltip: cx(classes.tooltip, classes.tooltipDisablePadding)
44
+ }}
45
+ placement="top-start"
46
+ title={
47
+ equals('hidden', tooltip?.mode) ? null : (
48
+ <GraphValueTooltipContent
49
+ base={baseAxis}
50
+ isSingleMode={equals('single', tooltip?.mode)}
51
+ sortOrder={tooltip?.sortOrder}
52
+ />
53
+ )
54
+ }
55
+ >
56
+ {children}
57
+ </MuiTooltip>
58
+ );
59
+ };
60
+
61
+ export default GraphValueTooltip;
@@ -15,7 +15,7 @@ interface Props extends Pick<Tooltip, 'sortOrder'> {
15
15
  isSingleMode: boolean;
16
16
  }
17
17
 
18
- const GraphValueTooltip = ({
18
+ const GraphValueTooltipContent = ({
19
19
  base,
20
20
  isSingleMode,
21
21
  sortOrder
@@ -71,4 +71,4 @@ const GraphValueTooltip = ({
71
71
  );
72
72
  };
73
73
 
74
- export default GraphValueTooltip;
74
+ export default GraphValueTooltipContent;
@@ -1,7 +1,7 @@
1
1
  import { MutableRefObject } from 'react';
2
2
 
3
3
  import { Event } from '@visx/visx';
4
- import { ScaleTime } from 'd3-scale';
4
+ import { ScaleTime, ScaleLinear } from 'd3-scale';
5
5
  import { useSetAtom } from 'jotai';
6
6
  import {
7
7
  all,
@@ -11,6 +11,7 @@ import {
11
11
  isNil,
12
12
  keys,
13
13
  map,
14
+ negate,
14
15
  pick,
15
16
  pipe,
16
17
  pluck,
@@ -31,7 +32,6 @@ import {
31
32
  getLineForMetric,
32
33
  getLinesForMetrics,
33
34
  getTimeValue,
34
- getUnits,
35
35
  getYScale
36
36
  } from '../../common/timeSeries';
37
37
  import { Line, TimeValue } from '../../common/timeSeries/models';
@@ -61,11 +61,10 @@ interface CommonData {
61
61
  graphHeight: number;
62
62
  graphSvgRef: MutableRefObject<SVGSVGElement | null>;
63
63
  graphWidth: number;
64
- leftScale;
65
64
  lines;
66
- rightScale;
67
65
  timeSeries: Array<TimeValue>;
68
66
  xScale: ScaleTime<number, number>;
67
+ yScalesPerUnit: Record<string, ScaleLinear<string, string>>;
69
68
  }
70
69
 
71
70
  interface TimeShiftZonesData extends InteractedZone {
@@ -99,9 +98,8 @@ const InteractionWithGraph = ({
99
98
  graphSvgRef,
100
99
  xScale,
101
100
  timeSeries,
102
- leftScale,
103
- rightScale,
104
- lines
101
+ lines,
102
+ yScalesPerUnit
105
103
  } = commonData;
106
104
 
107
105
  const displayZoomPreview = zoomData?.enable ?? true;
@@ -164,7 +162,6 @@ const InteractionWithGraph = ({
164
162
  const date = timeValue.timeTick;
165
163
  const displayedMetricIds = pluck('metric_id', lines);
166
164
  const filteredMetricsValue = pick(displayedMetricIds, timeValue);
167
- const [, secondUnit, thirdUnit] = getUnits(lines as Array<Line>);
168
165
  const areAllValuesEmpty = pipe(values, all(isNil))(filteredMetricsValue);
169
166
 
170
167
  const linesData = getLinesForMetrics({
@@ -190,12 +187,9 @@ const InteractionWithGraph = ({
190
187
  metric_id: Number(metricId)
191
188
  });
192
189
  const yScale = getYScale({
193
- hasMoreThanTwoUnits: Boolean(thirdUnit),
194
190
  invert: (lineData as Line).invert,
195
- leftScale,
196
- rightScale,
197
- secondUnit,
198
- unit: (lineData as Line).unit
191
+ unit: (lineData as Line).unit,
192
+ yScalesPerUnit
199
193
  });
200
194
 
201
195
  const y0 = yScale(value);
@@ -225,12 +219,14 @@ const InteractionWithGraph = ({
225
219
  date,
226
220
  highlightedMetricId: Number(nearestLine[0]),
227
221
  metrics: map(
228
- ({ metric_id, color, unit, legend, name }) => ({
222
+ ({ metric_id, color, unit, legend, name, invert }) => ({
229
223
  color,
230
224
  id: metric_id,
231
225
  name: formatMetricName({ legend, name }),
232
226
  unit,
233
- value: timeValue?.[metric_id]
227
+ value: invert
228
+ ? negate(timeValue?.[metric_id])
229
+ : timeValue?.[metric_id]
234
230
  }),
235
231
  linesData
236
232
  ).filter(({ value }) => !isNil(value))
@@ -93,10 +93,7 @@ export const useLegendHeaderStyles = makeStyles<StylesProps>()(
93
93
  width: theme.spacing(1.5)
94
94
  },
95
95
  legendName: {
96
- maxWidth: '95%'
97
- },
98
- legendNameSide: {
99
- maxWidth: '95%'
96
+ width: '91%'
100
97
  },
101
98
  markerAndLegendName: {
102
99
  alignItems: 'center',
@@ -122,9 +119,6 @@ export const useLegendHeaderStyles = makeStyles<StylesProps>()(
122
119
  },
123
120
  textListBottom: {
124
121
  width: 'auto'
125
- },
126
- textListSide: {
127
- width: '95%'
128
122
  }
129
123
  })
130
124
  );
@@ -19,6 +19,7 @@ interface Props {
19
19
  isListMode: boolean;
20
20
  line: Line;
21
21
  minMaxAvg?;
22
+ unit: string;
22
23
  value?: string | null;
23
24
  }
24
25
 
@@ -29,7 +30,8 @@ const LegendHeader = ({
29
30
  value,
30
31
  minMaxAvg,
31
32
  isListMode,
32
- isDisplayedOnSide
33
+ isDisplayedOnSide,
34
+ unit
33
35
  }: Props): JSX.Element => {
34
36
  const { classes, cx } = useLegendHeaderStyles({ color });
35
37
 
@@ -74,12 +76,11 @@ const LegendHeader = ({
74
76
  className={cx(classes.icon, { [classes.disabled]: disabled })}
75
77
  />
76
78
  <EllipsisTypography
77
- className={cx(
78
- classes.text,
79
+ className={classes.text}
80
+ containerClassname={cx(
79
81
  !isListMode && classes.legendName,
80
- !isListMode && isDisplayedOnSide && classes.legendNameSide,
81
82
  isListMode && !isDisplayedOnSide && classes.textListBottom,
82
- isListMode && isDisplayedOnSide && classes.textListSide
83
+ isListMode && isDisplayedOnSide && classes.legendName
83
84
  )}
84
85
  data-mode={
85
86
  value ? LegendDisplayMode.Compact : LegendDisplayMode.Normal
@@ -87,6 +88,9 @@ const LegendHeader = ({
87
88
  >
88
89
  {metricName}
89
90
  </EllipsisTypography>
91
+ <Typography sx={{ lineHeight: 1.25 }} variant="caption">
92
+ {unit}
93
+ </Typography>
90
94
  </div>
91
95
  </Tooltip>
92
96
  </div>
@@ -113,7 +113,7 @@ const MainLegend = ({
113
113
  data-mode={itemMode}
114
114
  >
115
115
  {displayedLines.map((line) => {
116
- const { color, display, highlight, metric_id } = line;
116
+ const { color, display, highlight, metric_id, unit } = line;
117
117
 
118
118
  const markerColor = display
119
119
  ? color
@@ -155,6 +155,7 @@ const MainLegend = ({
155
155
  minMaxAvg={
156
156
  shouldDisplayLegendInCompactMode ? minMaxAvg : undefined
157
157
  }
158
+ unit={unit}
158
159
  />
159
160
  {!shouldDisplayLegendInCompactMode && !isListMode && (
160
161
  <div>
@@ -0,0 +1,6 @@
1
+ import { atom } from 'jotai';
2
+
3
+ import { ThresholdTooltip } from './models';
4
+
5
+ export const timeTickGraphAtom = atom<Date | null>(null);
6
+ export const thresholdTooltipAtom = atom<ThresholdTooltip | null>(null);
@@ -1,4 +1,4 @@
1
- import { MutableRefObject, useRef } from 'react';
1
+ import { memo, MutableRefObject, useRef } from 'react';
2
2
 
3
3
  import dayjs from 'dayjs';
4
4
  import 'dayjs/locale/en';
@@ -8,15 +8,16 @@ import 'dayjs/locale/pt';
8
8
  import localizedFormat from 'dayjs/plugin/localizedFormat';
9
9
  import timezonePlugin from 'dayjs/plugin/timezone';
10
10
  import utcPlugin from 'dayjs/plugin/utc';
11
+ import { equals } from 'ramda';
11
12
 
12
13
  import { ParentSize } from '../..';
13
14
  import { LineChartData, Thresholds } from '../common/models';
14
15
  import Loading from '../../LoadingSkeleton';
15
16
 
16
- import LineChart from './LineChart';
17
+ import Chart from './Chart';
17
18
  import LoadingSkeleton from './LoadingSkeleton';
18
19
  import { GlobalAreaLines, LineChartProps } from './models';
19
- import useLineChartData from './useLineChartData';
20
+ import useChartData from './useChartData';
20
21
 
21
22
  dayjs.extend(localizedFormat);
22
23
  dayjs.extend(utcPlugin);
@@ -33,7 +34,7 @@ interface Props extends Partial<LineChartProps> {
33
34
  thresholds?: Thresholds;
34
35
  }
35
36
 
36
- const WrapperLineChart = ({
37
+ const WrapperChart = ({
37
38
  end,
38
39
  start,
39
40
  height = 500,
@@ -57,11 +58,12 @@ const WrapperLineChart = ({
57
58
  },
58
59
  header,
59
60
  lineStyle,
61
+ barStyle,
60
62
  thresholds,
61
63
  thresholdUnit,
62
64
  limitLegend
63
65
  }: Props): JSX.Element | null => {
64
- const { adjustedData } = useLineChartData({ data, end, start });
66
+ const { adjustedData } = useChartData({ data, end, start });
65
67
  const lineChartRef = useRef<HTMLDivElement | null>(null);
66
68
 
67
69
  if (loading && !adjustedData) {
@@ -88,9 +90,10 @@ const WrapperLineChart = ({
88
90
  width: responsiveWidth
89
91
  }): JSX.Element => {
90
92
  return (
91
- <LineChart
93
+ <Chart
92
94
  annotationEvent={annotationEvent}
93
95
  axis={axis}
96
+ barStyle={barStyle}
94
97
  displayAnchor={displayAnchor}
95
98
  graphData={adjustedData}
96
99
  graphInterval={{ end, start }}
@@ -115,4 +118,4 @@ const WrapperLineChart = ({
115
118
  );
116
119
  };
117
120
 
118
- export default WrapperLineChart;
121
+ export default memo(WrapperChart, equals);
@@ -5,6 +5,7 @@ import { ScaleLinear } from 'd3-scale';
5
5
  import { Line, TimeValue } from '../common/timeSeries/models';
6
6
  import { LineChartData } from '../common/models';
7
7
  import { AxisX, Axis as AxisYLeft, AxisYRight } from '../common/Axes/models';
8
+ import { BarStyle } from '../BarChart/models';
8
9
 
9
10
  import {
10
11
  AreaRegularLines,
@@ -44,13 +45,13 @@ export interface ShapeLines {
44
45
  areaStackedLines?: AreaStackedLines;
45
46
  }
46
47
 
47
- export interface LineChartAxis {
48
+ export interface ChartAxis {
48
49
  axisX?: AxisX;
49
50
  axisYLeft?: AxisYLeft;
50
51
  axisYRight?: AxisYRight;
51
52
  gridLinesType?: 'horizontal' | 'vertical' | 'all';
52
53
  isCenteredZero?: boolean;
53
- scale?: 'linear' | 'logarithimc';
54
+ scale?: 'linear' | 'logarithmic';
54
55
  scaleLogarithmicBase?: number;
55
56
  showBorder?: boolean;
56
57
  showGridLines?: boolean;
@@ -67,6 +68,9 @@ export interface TooltipData {
67
68
  hideTooltip: () => void;
68
69
  tooltipOpen: boolean;
69
70
  }
71
+ export interface ThresholdTooltip {
72
+ thresholdLabel?: string;
73
+ }
70
74
  export interface Tooltip {
71
75
  mode: 'all' | 'single' | 'hidden';
72
76
  renderComponent?: (args: TooltipData) => ReactNode;
@@ -101,7 +105,8 @@ export interface LineStyle {
101
105
 
102
106
  export interface LineChartProps {
103
107
  annotationEvent?: AnnotationEvent;
104
- axis?: LineChartAxis;
108
+ axis?: ChartAxis;
109
+ barStyle?: BarStyle;
105
110
  displayAnchor?: DisplayAnchor;
106
111
  header?: LineChartHeader;
107
112
  height?: number | null;
@@ -0,0 +1,11 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ export const useYAxisStyles = makeStyles()((theme) => ({
4
+ axisInput: {
5
+ maxHeight: theme.spacing(3),
6
+ minHeight: theme.spacing(3)
7
+ },
8
+ unitContainer: {
9
+ marginTop: '2px'
10
+ }
11
+ }));
@@ -1,20 +1,51 @@
1
+ import SelectField from '../../../InputField/Select';
1
2
  import { commonTickLabelProps } from '../utils';
2
3
 
4
+ import { useYAxisStyles } from './AxisStyles';
5
+
3
6
  interface UnitLabelProps {
7
+ onUnitChange?: (newUnit: string) => void;
4
8
  unit: string;
9
+ units: Array<string>;
5
10
  x: number;
6
11
  y?: number;
7
12
  }
8
13
 
9
- const UnitLabel = ({ x, y = 16, unit }: UnitLabelProps): JSX.Element => (
10
- <text
11
- fontFamily={commonTickLabelProps.fontFamily}
12
- fontSize={commonTickLabelProps.fontSize}
13
- x={x}
14
- y={-y}
15
- >
16
- {unit}
17
- </text>
18
- );
14
+ const UnitLabel = ({
15
+ x,
16
+ y = 16,
17
+ unit,
18
+ onUnitChange,
19
+ units
20
+ }: UnitLabelProps): JSX.Element => {
21
+ const { classes } = useYAxisStyles();
22
+
23
+ return onUnitChange ? (
24
+ <foreignObject height={36} width={60} x={x - 20} y={-y * 2}>
25
+ <div className={classes.unitContainer}>
26
+ <SelectField
27
+ className={classes.axisInput}
28
+ dataTestId="unit-selector"
29
+ options={units.map((unitOption) => ({
30
+ id: unitOption,
31
+ name: unitOption
32
+ }))}
33
+ selectedOptionId={unit}
34
+ size="small"
35
+ onChange={(e) => onUnitChange(e.target.value)}
36
+ />
37
+ </div>
38
+ </foreignObject>
39
+ ) : (
40
+ <text
41
+ fontFamily={commonTickLabelProps.fontFamily}
42
+ fontSize={commonTickLabelProps.fontSize}
43
+ x={x}
44
+ y={-y}
45
+ >
46
+ {unit}
47
+ </text>
48
+ );
49
+ };
19
50
 
20
51
  export default UnitLabel;
@@ -4,14 +4,16 @@ import { equals, isNil } from 'ramda';
4
4
 
5
5
  import { useLocaleDateTimeFormat } from '@centreon/ui';
6
6
 
7
- import { getXAxisTickFormat } from '../../LineChart/helpers';
7
+ import { getXAxisTickFormat } from '../../Chart/helpers';
8
8
  import { getUnits } from '../timeSeries';
9
+ import { margin } from '../../Chart/common';
9
10
 
10
11
  import UnitLabel from './UnitLabel';
11
12
  import { Data } from './models';
12
13
  import useAxisY from './useAxisY';
13
14
 
14
15
  interface Props {
16
+ allUnits: Array<string>;
15
17
  data: Data;
16
18
  height: number;
17
19
  leftScale: ScaleLinear<number, number>;
@@ -28,7 +30,8 @@ const Axes = ({
28
30
  rightScale,
29
31
  leftScale,
30
32
  xScale,
31
- orientation
33
+ orientation,
34
+ allUnits
32
35
  }: Props): JSX.Element => {
33
36
  const { format } = useLocaleDateTimeFormat();
34
37
  const { lines, showBorder, yAxisTickLabelRotation } = data;
@@ -41,7 +44,7 @@ const Axes = ({
41
44
  isHorizontal
42
45
  });
43
46
 
44
- const [firstUnit, secondUnit, thirdUnit] = getUnits(lines);
47
+ const [, secondUnit] = getUnits(lines);
45
48
 
46
49
  const xTickCount = Math.min(Math.ceil(width / 82), 12);
47
50
 
@@ -53,8 +56,7 @@ const Axes = ({
53
56
  const formatAxisTick = (tick): string =>
54
57
  format({ date: new Date(tick), formatString: tickFormat });
55
58
 
56
- const hasMoreThanTwoUnits = !isNil(thirdUnit);
57
- const displayAxisRight = !isNil(secondUnit) && !hasMoreThanTwoUnits;
59
+ const displayAxisRight = !isNil(secondUnit);
58
60
 
59
61
  const AxisBottom = isHorizontal ? Axis.AxisBottom : Axis.AxisLeft;
60
62
  const AxisLeft = isHorizontal ? Axis.AxisLeft : Axis.AxisTop;
@@ -71,14 +73,16 @@ const Axes = ({
71
73
  ...axisLeft.tickLabelProps(),
72
74
  dx: isHorizontal ? 16 : -4
73
75
  })}
74
- top={isHorizontal ? height - 5 : 0}
76
+ top={isHorizontal ? height - margin.bottom : 0}
75
77
  />
76
78
 
77
79
  {axisLeft.displayUnit && (
78
80
  <UnitLabel
79
- unit={firstUnit}
81
+ unit={axisLeft.unit}
82
+ units={allUnits}
80
83
  x={isHorizontal ? -8 : width + 8}
81
84
  y={isHorizontal ? 16 : -2}
85
+ onUnitChange={data.axisYLeft?.onUnitChange}
82
86
  />
83
87
  )}
84
88
 
@@ -90,7 +94,7 @@ const Axes = ({
90
94
  tickLabelProps={() => ({
91
95
  ...axisLeft.tickLabelProps(),
92
96
  angle: yAxisTickLabelRotation,
93
- dx: isHorizontal ? -8 : 16,
97
+ dx: isHorizontal ? -8 : 4,
94
98
  dy: isHorizontal ? 4 : -6
95
99
  })}
96
100
  tickLength={2}
@@ -106,18 +110,20 @@ const Axes = ({
106
110
  tickLabelProps={() => ({
107
111
  ...axisRight.tickLabelProps(),
108
112
  angle: yAxisTickLabelRotation,
109
- dx: isHorizontal ? 4 : -8,
113
+ dx: isHorizontal ? 4 : -4,
110
114
  dy: 4
111
115
  })}
112
116
  tickLength={2}
113
- top={isHorizontal ? 0 : height}
117
+ top={isHorizontal ? 0 : height - margin.bottom}
114
118
  />
115
119
  )}
116
120
  {axisRight.displayUnit && (
117
121
  <UnitLabel
118
- unit={secondUnit}
119
- x={width + 8}
122
+ unit={axisRight.unit}
123
+ units={allUnits}
124
+ x={width}
120
125
  y={isHorizontal ? 16 : -(height + 8)}
126
+ onUnitChange={data.axisYRight?.onUnitChange}
121
127
  />
122
128
  )}
123
129
  </g>
@@ -1,5 +1,5 @@
1
1
  import { Line, TimeValue } from '../timeSeries/models';
2
- import { LineChartAxis } from '../../LineChart/models';
2
+ import { ChartAxis } from '../../Chart/models';
3
3
 
4
4
  export interface LabelProps {
5
5
  [x: string]: unknown;
@@ -8,6 +8,8 @@ export interface LabelProps {
8
8
 
9
9
  export interface Axis {
10
10
  displayUnit?: boolean;
11
+ onUnitChange?: (newUnit: string) => void;
12
+ unit?: string;
11
13
  }
12
14
 
13
15
  export interface AxisYRight extends Axis {
@@ -18,7 +20,7 @@ export interface AxisX {
18
20
  xAxisTickFormat?: string;
19
21
  }
20
22
  export interface Data
21
- extends Omit<LineChartAxis, 'axisX' | 'axisYLeft' | 'axisYRight'> {
23
+ extends Omit<ChartAxis, 'axisX' | 'axisYLeft' | 'axisYRight'> {
22
24
  axisX?: AxisX;
23
25
  axisYLeft?: Axis;
24
26
  axisYRight?: AxisYRight;
@@ -1,3 +1,5 @@
1
+ import { useMemo } from 'react';
2
+
1
3
  import { isNil } from 'ramda';
2
4
  import { Axis } from '@visx/visx';
3
5
 
@@ -13,6 +15,7 @@ interface AxisYData {
13
15
  numTicks?: number;
14
16
  tickFormat: (value: unknown) => string;
15
17
  tickLabelProps: Axis.TickLabelProps<unknown>;
18
+ unit: string;
16
19
  }
17
20
 
18
21
  interface AxisRightData extends AxisYData {
@@ -40,19 +43,24 @@ const useAxisY = ({
40
43
  const theme = useTheme();
41
44
 
42
45
  const { lines } = data;
43
- const [firstUnit, secondUnit, thirdUnit] = getUnits(lines);
46
+ const [firstUnit, secondUnit] = getUnits(lines);
44
47
 
45
48
  const numTicks = isHorizontal
46
49
  ? graphHeight && Math.ceil(graphHeight / 30)
47
50
  : graphWidth && Math.ceil(graphWidth / 60);
48
51
 
49
- const hasMoreThanTwoUnits = !isNil(thirdUnit);
50
- const hasTwoUnits = !isNil(secondUnit) && !hasMoreThanTwoUnits;
51
-
52
- const displayAxisRight = data?.axisYRight?.display ?? hasTwoUnits;
53
- const displayUnitAxisRight = data?.axisYRight?.displayUnit ?? hasTwoUnits;
54
- const displayUnitAxisLeft =
55
- data?.axisYLeft?.displayUnit ?? !hasMoreThanTwoUnits;
52
+ const displayAxisRight = data?.axisYRight?.display || Boolean(secondUnit);
53
+ const displayUnitAxisRight =
54
+ data?.axisYRight?.displayUnit || Boolean(secondUnit);
55
+ const displayUnitAxisLeft = data?.axisYLeft?.displayUnit || true;
56
+ const leftUnit = useMemo(
57
+ () => data.axisYLeft?.unit ?? firstUnit,
58
+ [data.axisYLeft?.unit, firstUnit]
59
+ );
60
+ const rightUnit = useMemo(
61
+ () => data.axisYRight?.unit ?? secondUnit,
62
+ [data.axisYRight?.unit, secondUnit]
63
+ );
56
64
 
57
65
  const formatTick =
58
66
  ({ unit }) =>
@@ -92,16 +100,18 @@ const useAxisY = ({
92
100
  displayUnit: displayUnitAxisLeft,
93
101
  numTicks,
94
102
  tickFormat: formatTick({
95
- unit: hasMoreThanTwoUnits ? '' : firstUnit
103
+ unit: leftUnit
96
104
  }),
97
- tickLabelProps: tickLabelPropsAxisLeft
105
+ tickLabelProps: tickLabelPropsAxisLeft,
106
+ unit: leftUnit
98
107
  },
99
108
  axisRight: {
100
109
  display: displayAxisRight,
101
110
  displayUnit: displayUnitAxisRight,
102
111
  numTicks,
103
- tickFormat: formatTick({ unit: secondUnit }),
104
- tickLabelProps: tickLabelPropsAxisRight
112
+ tickFormat: formatTick({ unit: rightUnit }),
113
+ tickLabelProps: tickLabelPropsAxisRight,
114
+ unit: rightUnit
105
115
  }
106
116
  };
107
117
  };
@@ -10,8 +10,8 @@ import { equals, gt, isNil, lte, reduce } from 'ramda';
10
10
 
11
11
  import { Stack } from '@mui/material';
12
12
 
13
- import Legend from '../../LineChart/Legend';
14
- import { legendWidth } from '../../LineChart/Legend/Legend.styles';
13
+ import Legend from '../../Chart/Legend';
14
+ import { legendWidth } from '../../Chart/Legend/Legend.styles';
15
15
  import { Line } from '../timeSeries/models';
16
16
 
17
17
  import { useBaseChartStyles } from './useBaseChartStyles';