@centreon/ui 24.8.2 → 24.8.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 (112) hide show
  1. package/package.json +32 -34
  2. package/public/mockServiceWorker.js +1 -1
  3. package/src/Graph/BarChart/BarChart.cypress.spec.tsx +38 -81
  4. package/src/Graph/BarChart/BarChart.tsx +4 -4
  5. package/src/Graph/BarChart/BarGroup.tsx +81 -92
  6. package/src/Graph/BarChart/BarStack.tsx +21 -13
  7. package/src/Graph/BarChart/ResponsiveBarChart.tsx +26 -50
  8. package/src/Graph/BarChart/Tooltip/BarChartTooltip.tsx +1 -1
  9. package/src/Graph/BarChart/useBarStack.ts +1 -1
  10. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Point.tsx +1 -1
  11. package/src/Graph/Chart/BasicComponents/Lines/StackedLines/useStackedLines.ts +67 -0
  12. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/ThresholdWithPatternLines.tsx +4 -7
  13. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/index.tsx +6 -9
  14. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/models.ts +1 -2
  15. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/useScaleThreshold.ts +8 -20
  16. package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/index.tsx +64 -43
  17. package/src/Graph/{LineChart/LineChart.cypress.spec.tsx → Chart/Chart.cypress.spec.tsx} +272 -23
  18. package/src/Graph/{LineChart/index.stories.tsx → Chart/Chart.stories.tsx} +217 -24
  19. package/src/Graph/{LineChart/LineChart.styles.ts → Chart/Chart.styles.ts} +1 -1
  20. package/src/Graph/{LineChart/LineChart.tsx → Chart/Chart.tsx} +84 -100
  21. package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/RegularAnchorPoint.tsx +5 -1
  22. package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/StackedAnchorPoint.tsx +6 -1
  23. package/src/Graph/Chart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx +61 -0
  24. package/src/Graph/{LineChart/InteractiveComponents/GraphValueTooltip/GraphValueTooltip.tsx → Chart/InteractiveComponents/GraphValueTooltip/GraphValueTooltipContent.tsx} +2 -2
  25. package/src/Graph/{LineChart → Chart}/InteractiveComponents/index.tsx +11 -15
  26. package/src/Graph/{LineChart → Chart}/Legend/Legend.styles.ts +1 -7
  27. package/src/Graph/{LineChart → Chart}/Legend/LegendHeader.tsx +9 -5
  28. package/src/Graph/{LineChart → Chart}/Legend/index.tsx +2 -1
  29. package/src/Graph/Chart/graphAtoms.ts +6 -0
  30. package/src/Graph/{LineChart → Chart}/index.tsx +10 -7
  31. package/src/Graph/{LineChart → Chart}/models.ts +8 -3
  32. package/src/Graph/common/Axes/AxisStyles.ts +11 -0
  33. package/src/Graph/common/Axes/UnitLabel.tsx +41 -10
  34. package/src/Graph/common/Axes/index.tsx +18 -12
  35. package/src/Graph/common/Axes/models.ts +4 -2
  36. package/src/Graph/common/Axes/useAxisY.ts +22 -12
  37. package/src/Graph/common/BaseChart/BaseChart.tsx +2 -2
  38. package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +8 -5
  39. package/src/Graph/common/BaseChart/useComputeBaseChartDimensions.ts +1 -1
  40. package/src/Graph/common/Grids/index.tsx +2 -2
  41. package/src/Graph/common/Thresholds/ThresholdLine.tsx +1 -1
  42. package/src/Graph/common/Thresholds/Thresholds.tsx +10 -15
  43. package/src/Graph/common/timeSeries/index.ts +109 -131
  44. package/src/Graph/common/timeSeries/models.ts +4 -5
  45. package/src/Graph/index.ts +4 -4
  46. package/src/Graph/mockedData/lastDayWithLotOfUnits.json +1668 -0
  47. package/src/Graph/mockedData/pingService.json +46 -1
  48. package/src/Graph/mockedData/pingServiceLinesBars.json +253 -0
  49. package/src/Graph/mockedData/pingServiceLinesBarsMixed.json +253 -0
  50. package/src/Graph/mockedData/pingServiceLinesBarsStacked.json +253 -0
  51. package/src/Graph/mockedData/pingServiceMixedStacked.json +46 -1
  52. package/src/Graph/mockedData/pingServiceStacked.json +46 -1
  53. package/src/Typography/EllipsisTypography.tsx +5 -2
  54. package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +16 -24
  55. package/src/components/Form/AccessRights/AccessRights.stories.tsx +5 -5
  56. package/src/components/Form/AccessRights/AccessRights.tsx +3 -3
  57. package/src/components/Form/index.ts +2 -2
  58. package/src/utils/index.ts +2 -2
  59. package/src/Graph/BarChart/SingleBar.tsx +0 -62
  60. package/src/Graph/BarChart/useSingleBar.ts +0 -199
  61. package/src/Graph/LineChart/BasicComponents/Lines/StackedLines/useStackedLines.ts +0 -39
  62. package/src/Graph/LineChart/graphAtoms.ts +0 -3
  63. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/RegularLines/index.tsx +0 -0
  64. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/RegularLines/useRegularLines.ts +0 -0
  65. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/StackedLines/index.tsx +0 -0
  66. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/BasicThreshold.tsx +0 -0
  67. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/Circle.tsx +0 -0
  68. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/ThresholdWithVariation.tsx +0 -0
  69. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/helpers/index.ts +0 -0
  70. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/Threshold/useCoordinateCircle.ts +0 -0
  71. /package/src/Graph/{LineChart → Chart}/BasicComponents/Lines/models.ts +0 -0
  72. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/GuidingLines.tsx +0 -0
  73. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/index.tsx +0 -0
  74. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/models.ts +0 -0
  75. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/AnchorPoint/useTickGraph.ts +0 -0
  76. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/Area.tsx +0 -0
  77. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/Line.tsx +0 -0
  78. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Annotation/index.tsx +0 -0
  79. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Area/Downtime.tsx +0 -0
  80. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/EventAnnotations.tsx +0 -0
  81. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Line/Acknowledgement.tsx +0 -0
  82. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/Line/Comments.tsx +0 -0
  83. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/annotationsAtoms.ts +0 -0
  84. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/index.tsx +0 -0
  85. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/models.ts +0 -0
  86. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Annotations/useAnnotation.ts +0 -0
  87. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Bar.tsx +0 -0
  88. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +0 -0
  89. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/GraphValueTooltip/useGraphValueTooltipStyles.ts +0 -0
  90. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/TimeShiftIcon.tsx +0 -0
  91. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/TimeShiftZone.tsx +0 -0
  92. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/index.tsx +0 -0
  93. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/models.ts +0 -0
  94. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/TimeShiftZones/useTimeShiftZones.ts +0 -0
  95. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/index.tsx +0 -0
  96. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/models.ts +0 -0
  97. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/Tooltip/useGraphTooltip.ts +0 -0
  98. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/index.tsx +0 -0
  99. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/models.ts +0 -0
  100. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/useZoomPreview.ts +0 -0
  101. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/ZoomPreview/zoomPreviewAtoms.ts +0 -0
  102. /package/src/Graph/{LineChart → Chart}/InteractiveComponents/interactionWithGraphAtoms.ts +0 -0
  103. /package/src/Graph/{LineChart → Chart}/Legend/LegendContent.tsx +0 -0
  104. /package/src/Graph/{LineChart → Chart}/Legend/models.ts +0 -0
  105. /package/src/Graph/{LineChart → Chart}/Legend/useLegend.ts +0 -0
  106. /package/src/Graph/{LineChart → Chart}/LoadingSkeleton.tsx +0 -0
  107. /package/src/Graph/{LineChart → Chart}/common/index.ts +0 -0
  108. /package/src/Graph/{LineChart → Chart}/helpers/doc.ts +0 -0
  109. /package/src/Graph/{LineChart → Chart}/helpers/index.ts +0 -0
  110. /package/src/Graph/{LineChart → Chart}/translatedLabels.ts +0 -0
  111. /package/src/Graph/{LineChart/useLineChartData.ts → Chart/useChartData.ts} +0 -0
  112. /package/src/Graph/{LineChart/useLineChartIntersection.ts → Chart/useChartIntersection.ts} +0 -0
@@ -1,34 +1,32 @@
1
1
  import { memo, useMemo } from 'react';
2
2
 
3
3
  import { BarGroupHorizontal, BarGroup as VisxBarGroup } from '@visx/shape';
4
- import { difference, equals, isEmpty, keys, omit, pick } from 'ramda';
4
+ import { difference, equals, keys, omit, pick, pluck, uniq } from 'ramda';
5
5
  import { scaleBand, scaleOrdinal } from '@visx/scale';
6
6
  import { Group } from '@visx/group';
7
+ import { ScaleLinear } from 'd3-scale';
7
8
 
8
9
  import { useDeepMemo } from '../../utils';
9
10
  import { Line, TimeValue } from '../common/timeSeries/models';
10
11
  import {
11
12
  getSortedStackedLines,
12
13
  getTime,
13
- getTimeSeriesForLines
14
+ getTimeSeriesForLines,
15
+ getUnits
14
16
  } from '../common/timeSeries';
15
17
 
16
- import SingleBar from './SingleBar';
17
18
  import BarStack from './BarStack';
18
19
  import { BarStyle } from './models';
19
20
 
20
21
  interface Props {
21
22
  barStyle: BarStyle;
22
- isCenteredZero?: boolean;
23
23
  isTooltipHidden: boolean;
24
- leftScale;
25
24
  lines: Array<Line>;
26
25
  orientation: 'horizontal' | 'vertical';
27
- rightScale;
28
- secondUnit?: string;
29
26
  size: number;
30
27
  timeSeries: Array<TimeValue>;
31
28
  xScale;
29
+ yScalesPerUnit: Record<string, ScaleLinear<number, number>>;
32
30
  }
33
31
 
34
32
  const BarGroup = ({
@@ -37,44 +35,50 @@ const BarGroup = ({
37
35
  size,
38
36
  lines,
39
37
  xScale,
40
- leftScale,
41
- rightScale,
42
- secondUnit,
43
- isCenteredZero,
38
+ yScalesPerUnit,
44
39
  isTooltipHidden,
45
40
  barStyle
46
41
  }: Props): JSX.Element => {
47
42
  const isHorizontal = equals(orientation, 'horizontal');
48
43
 
44
+ const [firstUnit] = getUnits(lines);
45
+
49
46
  const BarComponent = useMemo(
50
47
  () => (isHorizontal ? VisxBarGroup : BarGroupHorizontal),
51
48
  [isHorizontal]
52
49
  );
53
50
 
54
51
  const stackedLines = getSortedStackedLines(lines);
52
+ const stackedUnits = uniq(pluck('unit', stackedLines));
55
53
  const notStackedLines = difference(lines, stackedLines);
56
54
 
57
- const stackLinesRight = stackedLines.filter(({ unit }) =>
58
- equals(unit, secondUnit)
55
+ const stackedKeys = stackedUnits.reduce(
56
+ (acc, unit) => ({
57
+ ...acc,
58
+ [`stacked-${unit}`]: null
59
+ }),
60
+ {}
59
61
  );
60
- const stackLinesLeft = stackedLines.filter(
61
- ({ unit }) => !equals(unit, secondUnit)
62
+ const stackedLinesTimeSeriesPerUnit = stackedUnits.reduce(
63
+ (acc, stackedUnit) => {
64
+ const relatedLines = stackedLines.filter(({ unit }) =>
65
+ equals(unit, stackedUnit)
66
+ );
67
+
68
+ return {
69
+ ...acc,
70
+ [stackedUnit]: {
71
+ lines: relatedLines,
72
+ timeSeries: getTimeSeriesForLines({
73
+ lines: relatedLines,
74
+ timeSeries
75
+ })
76
+ }
77
+ };
78
+ },
79
+ {}
62
80
  );
63
- const hasStackedLinesRight = !isEmpty(stackLinesRight)
64
- ? { stackedRight: null }
65
- : {};
66
- const hasStackedLinesLeft = !isEmpty(stackLinesLeft)
67
- ? { stackedLeft: null }
68
- : {};
69
-
70
- const stackedTimeSeriesRight = getTimeSeriesForLines({
71
- lines: stackLinesRight,
72
- timeSeries
73
- });
74
- const stackedTimeSeriesLeft = getTimeSeriesForLines({
75
- lines: stackLinesLeft,
76
- timeSeries
77
- });
81
+
78
82
  const notStackedTimeSeries = getTimeSeriesForLines({
79
83
  lines: notStackedLines,
80
84
  timeSeries
@@ -82,8 +86,7 @@ const BarGroup = ({
82
86
 
83
87
  const normalizedTimeSeries = notStackedTimeSeries.map((timeSerie) => ({
84
88
  ...timeSerie,
85
- ...hasStackedLinesRight,
86
- ...hasStackedLinesLeft
89
+ ...stackedKeys
87
90
  }));
88
91
 
89
92
  const lineKeys = useDeepMemo({
@@ -119,6 +122,8 @@ const BarGroup = ({
119
122
  [...lineKeys, xScale.bandwidth()]
120
123
  );
121
124
 
125
+ const placeholderScale = yScalesPerUnit[firstUnit];
126
+
122
127
  const barComponentBaseProps = useMemo(
123
128
  () =>
124
129
  isHorizontal
@@ -126,15 +131,15 @@ const BarGroup = ({
126
131
  x0: getTime,
127
132
  x0Scale: xScale,
128
133
  x1Scale: metricScale,
129
- yScale: leftScale
134
+ yScale: placeholderScale
130
135
  }
131
136
  : {
132
- xScale: leftScale,
137
+ xScale: placeholderScale,
133
138
  y0: getTime,
134
139
  y0Scale: xScale,
135
140
  y1Scale: metricScale
136
141
  },
137
- [isHorizontal, leftScale, rightScale, xScale, metricScale]
142
+ [isHorizontal, placeholderScale, xScale, metricScale]
138
143
  );
139
144
 
140
145
  return (
@@ -152,49 +157,48 @@ const BarGroup = ({
152
157
  left={barGroup.x0}
153
158
  top={barGroup.y0}
154
159
  >
155
- {barGroup.bars.map((bar) => (
156
- <>
157
- <SingleBar
158
- bar={bar}
160
+ {barGroup.bars.map((bar) => {
161
+ const isStackedBar = bar.key.startsWith('stacked-');
162
+ const linesBar = isStackedBar
163
+ ? stackedLinesTimeSeriesPerUnit[bar.key.replace('stacked-', '')]
164
+ .lines
165
+ : (notStackedLines.find(({ metric_id }) =>
166
+ equals(metric_id, Number(bar.key))
167
+ ) as Line);
168
+ const timeSeriesBar = isStackedBar
169
+ ? stackedLinesTimeSeriesPerUnit[bar.key.replace('stacked-', '')]
170
+ .timeSeries
171
+ : notStackedTimeSeries.map((timeSerie) => ({
172
+ timeTick: timeSerie.timeTick,
173
+ [bar.key]: timeSerie[Number(bar.key)]
174
+ }));
175
+
176
+ return isStackedBar ? (
177
+ <BarStack
178
+ barIndex={barGroup.index}
179
+ barPadding={isHorizontal ? bar.x : bar.y}
159
180
  barStyle={barStyle}
160
- isCenteredZero={isCenteredZero}
181
+ barWidth={isHorizontal ? bar.width : bar.height}
161
182
  isHorizontal={isHorizontal}
162
183
  isTooltipHidden={isTooltipHidden}
163
- key={`bar-group-bar-${barGroup.index}-${bar.index}-${bar.value}-${bar.key}`}
164
- leftScale={leftScale}
165
- lines={lines}
166
- rightScale={rightScale}
167
- secondUnit={secondUnit}
168
- size={size}
184
+ lines={linesBar}
185
+ timeSeries={timeSeriesBar}
186
+ yScale={yScalesPerUnit[bar.key.replace('stacked-', '')]}
169
187
  />
170
- {equals(bar.key, 'stackedRight') && (
171
- <BarStack
172
- barIndex={barGroup.index}
173
- barPadding={isHorizontal ? bar.x : bar.y}
174
- barStyle={barStyle}
175
- barWidth={isHorizontal ? bar.width : bar.height}
176
- isHorizontal={isHorizontal}
177
- isTooltipHidden={isTooltipHidden}
178
- lines={stackLinesRight}
179
- timeSeries={stackedTimeSeriesRight}
180
- yScale={rightScale}
181
- />
182
- )}
183
- {equals(bar.key, 'stackedLeft') && (
184
- <BarStack
185
- barIndex={barGroup.index}
186
- barPadding={isHorizontal ? bar.x : bar.y}
187
- barStyle={barStyle}
188
- barWidth={isHorizontal ? bar.width : bar.height}
189
- isHorizontal={isHorizontal}
190
- isTooltipHidden={isTooltipHidden}
191
- lines={stackLinesLeft}
192
- timeSeries={stackedTimeSeriesLeft}
193
- yScale={leftScale}
194
- />
195
- )}
196
- </>
197
- ))}
188
+ ) : (
189
+ <BarStack
190
+ barIndex={barGroup.index}
191
+ barPadding={isHorizontal ? bar.x : bar.y}
192
+ barStyle={barStyle}
193
+ barWidth={isHorizontal ? bar.width : bar.height}
194
+ isHorizontal={isHorizontal}
195
+ isTooltipHidden={isTooltipHidden}
196
+ lines={[linesBar]}
197
+ timeSeries={timeSeriesBar}
198
+ yScale={yScalesPerUnit[linesBar.unit]}
199
+ />
200
+ );
201
+ })}
198
202
  </Group>
199
203
  ))
200
204
  }
@@ -213,27 +217,13 @@ const propsToMemoize = [
213
217
  ];
214
218
 
215
219
  export default memo(BarGroup, (prevProps, nextProps) => {
216
- const prevLeftScale = [
217
- ...prevProps.leftScale.domain(),
218
- ...prevProps.leftScale.range()
219
- ];
220
- const prevRightScale = [
221
- ...prevProps.rightScale.domain(),
222
- ...prevProps.rightScale.range()
223
- ];
220
+ const prevYScale = prevProps.yScalesPerUnit;
224
221
  const prevXScale = [
225
222
  ...prevProps.xScale.domain(),
226
223
  ...prevProps.xScale.range()
227
224
  ];
228
225
 
229
- const nextLeftScale = [
230
- ...nextProps.leftScale.domain(),
231
- ...nextProps.leftScale.range()
232
- ];
233
- const nextRightScale = [
234
- ...nextProps.rightScale.domain(),
235
- ...nextProps.rightScale.range()
236
- ];
226
+ const nextYScale = nextProps.yScalesPerUnit;
237
227
  const nextXScale = [
238
228
  ...nextProps.xScale.domain(),
239
229
  ...nextProps.xScale.range()
@@ -241,8 +231,7 @@ export default memo(BarGroup, (prevProps, nextProps) => {
241
231
 
242
232
  return (
243
233
  equals(pick(propsToMemoize, prevProps), pick(propsToMemoize, nextProps)) &&
244
- equals(prevLeftScale, nextLeftScale) &&
245
- equals(prevRightScale, nextRightScale) &&
234
+ equals(prevYScale, nextYScale) &&
246
235
  equals(prevXScale, nextXScale)
247
236
  );
248
237
  });
@@ -1,7 +1,8 @@
1
1
  import { memo } from 'react';
2
2
 
3
3
  import { scaleBand } from '@visx/scale';
4
- import { equals, gt, pick } from 'ramda';
4
+ import { dec, equals, gt, pick } from 'ramda';
5
+ import { BarRounded } from '@visx/shape';
5
6
 
6
7
  import { useBarStack, UseBarStackProps } from './useBarStack';
7
8
  import { BarStyle } from './models';
@@ -37,7 +38,7 @@ const BarStack = ({
37
38
  barPadding,
38
39
  barIndex,
39
40
  isTooltipHidden,
40
- barStyle
41
+ barStyle = { opacity: 1, radius: 0.2 }
41
42
  }: Props): JSX.Element => {
42
43
  const {
43
44
  BarStackComponent,
@@ -56,21 +57,28 @@ const BarStack = ({
56
57
  {...commonBarStackProps}
57
58
  >
58
59
  {(barStacks) => {
59
- return barStacks.map((barStack) =>
60
+ return barStacks.map((barStack, index) =>
60
61
  barStack.bars.map((bar) => {
62
+ const shouldApplyRadiusOnBottom = equals(index, 0);
63
+ const shouldApplyRadiusOnTop = equals(index, dec(barStacks.length));
61
64
  const isNegativeValue = gt(0, bar.bar[1]);
62
65
 
66
+ const barRoundedProps = {
67
+ [isHorizontal ? 'top' : 'right']: shouldApplyRadiusOnTop,
68
+ [isHorizontal ? 'bottom' : 'left']: shouldApplyRadiusOnBottom
69
+ };
70
+
63
71
  return (
64
- <rect
72
+ <BarRounded
73
+ {...barRoundedProps}
65
74
  data-testid={`stacked-bar-${bar.key}-${bar.index}-${bar.bar[1]}`}
66
75
  fill={bar.color}
67
- height={Math.ceil(
68
- isHorizontal ? Math.abs(bar.height) : barWidth
69
- )}
76
+ height={isHorizontal ? Math.abs(bar.height) : barWidth}
70
77
  key={`bar-stack-${barStack.index}-${bar.index}`}
71
- opacity={barStyle.opacity}
72
- width={Math.ceil(isHorizontal ? barWidth : Math.abs(bar.width))}
73
- x={Math.ceil(
78
+ opacity={barStyle.opacity ?? 1}
79
+ radius={barWidth * barStyle.radius}
80
+ width={isHorizontal ? barWidth : Math.abs(bar.width)}
81
+ x={
74
82
  isHorizontal
75
83
  ? barPadding
76
84
  : getPadding({
@@ -78,8 +86,8 @@ const BarStack = ({
78
86
  padding: bar.x,
79
87
  size: bar.width
80
88
  })
81
- )}
82
- y={Math.ceil(
89
+ }
90
+ y={
83
91
  isHorizontal
84
92
  ? getPadding({
85
93
  isNegativeValue,
@@ -87,7 +95,7 @@ const BarStack = ({
87
95
  size: bar.height
88
96
  })
89
97
  : barPadding
90
- )}
98
+ }
91
99
  onMouseEnter={
92
100
  isTooltipHidden
93
101
  ? undefined
@@ -5,21 +5,20 @@ import { useAtom } from 'jotai';
5
5
 
6
6
  import { Skeleton } from '@mui/material';
7
7
 
8
- import { Data, LineChartProps } from '../LineChart/models';
8
+ import { Data, LineChartProps } from '../Chart/models';
9
9
  import { Thresholds as ThresholdsModel } from '../common/models';
10
- import { useIntersection } from '../LineChart/useLineChartIntersection';
10
+ import { useIntersection } from '../Chart/useChartIntersection';
11
11
  import { Line } from '../common/timeSeries/models';
12
12
  import { useComputeBaseChartDimensions } from '../common/BaseChart/useComputeBaseChartDimensions';
13
13
  import {
14
- getLeftScale,
15
- getRightScale,
16
14
  getUnits,
17
- getXScaleBand
15
+ getXScaleBand,
16
+ getYScalePerUnit
18
17
  } from '../common/timeSeries';
19
18
  import BaseChart from '../common/BaseChart/BaseChart';
20
19
  import ChartSvgWrapper from '../common/BaseChart/ChartSvgWrapper';
21
20
  import { useTooltipStyles } from '../common/useTooltipStyles';
22
- import { margin } from '../LineChart/common';
21
+ import { margin } from '../Chart/common';
23
22
  import { Tooltip } from '../../components';
24
23
  import Thresholds from '../common/Thresholds/Thresholds';
25
24
  import { useDeepCompare } from '../../utils';
@@ -68,7 +67,13 @@ const ResponsiveBarChart = ({
68
67
 
69
68
  const { isInViewport } = useIntersection({ element: graphRef?.current });
70
69
 
71
- const [, secondUnit] = getUnits(linesGraph);
70
+ const displayedLines = useMemo(
71
+ () => linesGraph.filter(({ display }) => display),
72
+ [linesGraph]
73
+ );
74
+
75
+ const [firstUnit, secondUnit] = getUnits(displayedLines);
76
+ const allUnits = getUnits(lines);
72
77
 
73
78
  const { legendRef, graphWidth, graphHeight } = useComputeBaseChartDimensions({
74
79
  hasSecondUnit: Boolean(secondUnit),
@@ -100,10 +105,10 @@ const ResponsiveBarChart = ({
100
105
  [timeSeries, graphWidth, isHorizontal, graphHeight]
101
106
  );
102
107
 
103
- const leftScale = useMemo(
108
+ const yScalesPerUnit = useMemo(
104
109
  () =>
105
- getLeftScale({
106
- dataLines: linesGraph,
110
+ getYScalePerUnit({
111
+ dataLines: displayedLines,
107
112
  dataTimeSeries: timeSeries,
108
113
  isCenteredZero: axis?.isCenteredZero,
109
114
  isHorizontal,
@@ -111,46 +116,25 @@ const ResponsiveBarChart = ({
111
116
  scaleLogarithmicBase: axis?.scaleLogarithmicBase,
112
117
  thresholdUnit,
113
118
  thresholds: (thresholds?.enabled && thresholdValues) || [],
114
- valueGraphHeight: (isHorizontal ? graphHeight : graphWidth) - 35
119
+ valueGraphHeight:
120
+ (isHorizontal ? graphHeight : graphWidth) - margin.bottom
115
121
  }),
116
122
  [
117
- linesGraph,
123
+ displayedLines,
118
124
  timeSeries,
119
125
  graphHeight,
120
126
  thresholdValues,
121
- axis?.isCenteredZero,
122
- axis?.scale,
123
- axis?.scaleLogarithmicBase,
124
127
  graphWidth,
125
- isHorizontal
126
- ]
127
- );
128
-
129
- const rightScale = useMemo(
130
- () =>
131
- getRightScale({
132
- dataLines: linesGraph,
133
- dataTimeSeries: timeSeries,
134
- isCenteredZero: axis?.isCenteredZero,
135
- isHorizontal,
136
- scale: axis?.scale,
137
- scaleLogarithmicBase: axis?.scaleLogarithmicBase,
138
- thresholdUnit,
139
- thresholds: (thresholds?.enabled && thresholdValues) || [],
140
- valueGraphHeight: (isHorizontal ? graphHeight : graphWidth) - 35
141
- }),
142
- [
143
- timeSeries,
144
- linesGraph,
145
- graphHeight,
128
+ thresholds?.enabled,
146
129
  axis?.isCenteredZero,
147
130
  axis?.scale,
148
- axis?.scaleLogarithmicBase,
149
- graphWidth,
150
- isHorizontal
131
+ axis?.scaleLogarithmicBase
151
132
  ]
152
133
  );
153
134
 
135
+ const leftScale = yScalesPerUnit[firstUnit];
136
+ const rightScale = yScalesPerUnit[secondUnit];
137
+
154
138
  useEffect(
155
139
  () => {
156
140
  setLinesGraph(lines);
@@ -160,11 +144,6 @@ const ResponsiveBarChart = ({
160
144
 
161
145
  const displayLegend = legend?.display ?? true;
162
146
 
163
- const displayedLines = useMemo(
164
- () => linesGraph.filter(({ display }) => display),
165
- [linesGraph]
166
- );
167
-
168
147
  const showGridLines = useMemo(
169
148
  () => isNil(axis?.showGridLines) || axis?.showGridLines,
170
149
  [axis?.showGridLines]
@@ -221,6 +200,7 @@ const ResponsiveBarChart = ({
221
200
  >
222
201
  <div className={classes.tooltipChildren}>
223
202
  <ChartSvgWrapper
203
+ allUnits={allUnits}
224
204
  axis={axis}
225
205
  base={baseAxis}
226
206
  displayedLines={displayedLines}
@@ -238,24 +218,19 @@ const ResponsiveBarChart = ({
238
218
  <>
239
219
  <BarGroup
240
220
  barStyle={barStyle}
241
- isCenteredZero={axis?.isCenteredZero}
242
221
  isTooltipHidden={isTooltipHidden}
243
- leftScale={leftScale}
244
222
  lines={displayedLines}
245
223
  orientation={isHorizontal ? 'horizontal' : 'vertical'}
246
- rightScale={rightScale}
247
- secondUnit={secondUnit}
248
224
  size={isHorizontal ? graphHeight - margin.top - 5 : graphWidth}
249
225
  timeSeries={timeSeries}
250
226
  xScale={xScale}
227
+ yScalesPerUnit={yScalesPerUnit}
251
228
  />
252
229
  {thresholds?.enabled && (
253
230
  <Thresholds
254
231
  displayedLines={displayedLines}
255
232
  hideTooltip={() => setTooltipData(null)}
256
233
  isHorizontal={isHorizontal}
257
- leftScale={leftScale}
258
- rightScale={rightScale}
259
234
  showTooltip={({ tooltipData: thresholdLabel }) =>
260
235
  setTooltipData({
261
236
  thresholdLabel
@@ -264,6 +239,7 @@ const ResponsiveBarChart = ({
264
239
  thresholdUnit={thresholdUnit}
265
240
  thresholds={thresholds as ThresholdsModel}
266
241
  width={isHorizontal ? graphWidth : graphHeight - margin.top}
242
+ yScalesPerUnit={yScalesPerUnit}
267
243
  />
268
244
  )}
269
245
  </>
@@ -20,7 +20,7 @@ import { TimeValue } from '../../common/timeSeries/models';
20
20
  import { useLocaleDateTimeFormat } from '../../../utils';
21
21
  import { formatMetricValueWithUnit } from '../../common/timeSeries';
22
22
  import { tooltipDataAtom } from '../atoms';
23
- import { Tooltip } from '../../LineChart/models';
23
+ import { Tooltip } from '../../Chart/models';
24
24
 
25
25
  import { useBarChartTooltipStyles } from './useBarChartTooltipStyles';
26
26
 
@@ -35,8 +35,8 @@ interface UseBarStackState {
35
35
  export const useBarStack = ({
36
36
  timeSeries,
37
37
  isHorizontal,
38
- yScale,
39
38
  lines,
39
+ yScale,
40
40
  xScale
41
41
  }: UseBarStackProps): UseBarStackState => {
42
42
  const setTooltipData = useSetAtom(tooltipDataAtom);
@@ -5,7 +5,7 @@ interface Props {
5
5
  radius: number;
6
6
  timeTick: Date;
7
7
  xScale;
8
- yPoint: number;
8
+ yPoint: number | null;
9
9
  }
10
10
 
11
11
  const Point = ({
@@ -0,0 +1,67 @@
1
+ import { equals, pluck, uniq } from 'ramda';
2
+
3
+ import {
4
+ getInvertedStackedLines,
5
+ getNotInvertedStackedLines,
6
+ getTimeSeriesForLines
7
+ } from '../../../../common/timeSeries';
8
+ import { LinesData } from '../models';
9
+
10
+ interface StackedLinesState {
11
+ invertedStackedLinesData: Record<string, LinesData>;
12
+ stackedLinesData: Record<string, LinesData>;
13
+ }
14
+
15
+ const useStackedLines = ({ lines, timeSeries }): StackedLinesState => {
16
+ const regularStackedLines = getNotInvertedStackedLines(lines);
17
+ const regularStackedUnits = uniq(pluck('unit', regularStackedLines));
18
+ const regularStackedLinesTimeSeriesPerUnit = regularStackedUnits.reduce(
19
+ (acc, stackedUnit) => {
20
+ const relatedLines = regularStackedLines.filter(({ unit }) =>
21
+ equals(unit, stackedUnit)
22
+ );
23
+
24
+ return {
25
+ ...acc,
26
+ [stackedUnit]: {
27
+ lines: relatedLines,
28
+ timeSeries: getTimeSeriesForLines({
29
+ lines: relatedLines,
30
+ timeSeries
31
+ })
32
+ }
33
+ };
34
+ },
35
+ {}
36
+ );
37
+
38
+ const invertedStackedLines = getInvertedStackedLines(lines);
39
+ const invertedStackedUnits = uniq(pluck('unit', invertedStackedLines));
40
+ const invertedStackedLinesTimeSeriesPerUnit = invertedStackedUnits.reduce(
41
+ (acc, stackedUnit) => {
42
+ const relatedLines = invertedStackedLines.filter(({ unit }) =>
43
+ equals(unit, stackedUnit)
44
+ );
45
+
46
+ return {
47
+ ...acc,
48
+ [stackedUnit]: {
49
+ lines: relatedLines,
50
+ timeSeries: getTimeSeriesForLines({
51
+ invert: true,
52
+ lines: relatedLines,
53
+ timeSeries
54
+ })
55
+ }
56
+ };
57
+ },
58
+ {}
59
+ );
60
+
61
+ return {
62
+ invertedStackedLinesData: invertedStackedLinesTimeSeriesPerUnit,
63
+ stackedLinesData: regularStackedLinesTimeSeriesPerUnit
64
+ };
65
+ };
66
+
67
+ export default useStackedLines;
@@ -15,20 +15,18 @@ interface Props {
15
15
  data: LineChartData;
16
16
  graphHeight: number;
17
17
  id: string;
18
- leftScale: ScaleLinear<number, number>;
19
18
  orientation?: Array<PatternOrientation>;
20
- rightScale: ScaleLinear<number, number>;
21
19
  xScale: ScaleLinear<number, number>;
20
+ yScalesPerUnit: Record<string, ScaleLinear<number, number>>;
22
21
  }
23
22
 
24
23
  const ThresholdWithPatternLines = ({
25
24
  graphHeight,
26
25
  data,
27
26
  orientation = ['diagonal'],
28
- leftScale,
29
- rightScale,
30
27
  xScale,
31
28
  id,
29
+ yScalesPerUnit,
32
30
  curve
33
31
  }: Props): JSX.Element | null => {
34
32
  const theme = useTheme();
@@ -36,10 +34,9 @@ const ThresholdWithPatternLines = ({
36
34
  const { lines, timeSeries } = adjustGraphData(data);
37
35
 
38
36
  const result = useScaleThreshold({
39
- leftScale,
40
37
  lines,
41
- rightScale,
42
- xScale
38
+ xScale,
39
+ yScalesPerUnit
43
40
  });
44
41
  if (!result) {
45
42
  return null;
@@ -24,19 +24,17 @@ interface Props extends WrapperThresholdLinesModel {
24
24
  const WrapperThresholdLines = ({
25
25
  areaThresholdLines,
26
26
  graphHeight,
27
- leftScale,
28
27
  lines,
29
- rightScale,
30
28
  timeSeries,
31
29
  xScale,
32
- curve
30
+ curve,
31
+ yScalesPerUnit
33
32
  }: Props): JSX.Element | null => {
34
33
  const data = useScaleThreshold({
35
34
  areaThresholdLines,
36
- leftScale,
37
35
  lines,
38
- rightScale,
39
- xScale
36
+ xScale,
37
+ yScalesPerUnit
40
38
  });
41
39
 
42
40
  if (!data) {
@@ -110,10 +108,9 @@ const WrapperThresholdLines = ({
110
108
  data: element,
111
109
  graphHeight,
112
110
  key: ind,
113
- leftScale,
114
111
  orientation: dataPattern?.orientation,
115
- rightScale,
116
- xScale
112
+ xScale,
113
+ yScalesPerUnit
117
114
  }
118
115
  }));
119
116
  }