@centreon/ui 24.11.10 → 24.11.11

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": "24.11.10",
3
+ "version": "24.11.11",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -18,6 +18,12 @@ import { Line, TimeValue } from '../common/timeSeries/models';
18
18
  import BarStack from './BarStack';
19
19
  import { BarStyle } from './models';
20
20
 
21
+ // Minimum value for logarithmic scale to avoid log(0)
22
+ const minLogScaleValue = 0.001;
23
+
24
+ const getNeutralValue = (scaleType?: 'linear' | 'logarithmic') =>
25
+ equals(scaleType, 'logarithmic') ? minLogScaleValue : 0;
26
+
21
27
  interface Props {
22
28
  barStyle: BarStyle;
23
29
  isTooltipHidden: boolean;
@@ -27,6 +33,7 @@ interface Props {
27
33
  timeSeries: Array<TimeValue>;
28
34
  xScale;
29
35
  yScalesPerUnit: Record<string, ScaleLinear<number, number>>;
36
+ scaleType?: 'linear' | 'logarithmic';
30
37
  }
31
38
 
32
39
  const BarGroup = ({
@@ -37,7 +44,8 @@ const BarGroup = ({
37
44
  xScale,
38
45
  yScalesPerUnit,
39
46
  isTooltipHidden,
40
- barStyle
47
+ barStyle,
48
+ scaleType
41
49
  }: Props): JSX.Element => {
42
50
  const isHorizontal = equals(orientation, 'horizontal');
43
51
 
@@ -142,6 +150,8 @@ const BarGroup = ({
142
150
  [isHorizontal, placeholderScale, xScale, metricScale]
143
151
  );
144
152
 
153
+ const neutralValue = useMemo(() => getNeutralValue(scaleType), [scaleType]);
154
+
145
155
  return (
146
156
  <BarComponent<TimeValue>
147
157
  color={colorScale}
@@ -185,6 +195,7 @@ const BarGroup = ({
185
195
  lines={linesBar}
186
196
  timeSeries={timeSeriesBar}
187
197
  yScale={yScalesPerUnit[bar.key.replace('stacked-', '')]}
198
+ neutralValue={neutralValue}
188
199
  />
189
200
  ) : (
190
201
  <BarStack
@@ -198,6 +209,7 @@ const BarGroup = ({
198
209
  lines={[linesBar]}
199
210
  timeSeries={timeSeriesBar}
200
211
  yScale={yScalesPerUnit[linesBar.unit]}
212
+ neutralValue={neutralValue}
201
213
  />
202
214
  );
203
215
  })}
@@ -215,7 +227,8 @@ const propsToMemoize = [
215
227
  'lines',
216
228
  'secondUnit',
217
229
  'isCenteredZero',
218
- 'barStyle'
230
+ 'barStyle',
231
+ 'scaleType'
219
232
  ];
220
233
 
221
234
  export default memo(BarGroup, (prevProps, nextProps) => {
@@ -1,9 +1,10 @@
1
1
  import { memo } from 'react';
2
2
 
3
- import { scaleBand } from '@visx/scale';
3
+ import { ScaleType, scaleBand } from '@visx/scale';
4
4
  import { BarRounded } from '@visx/shape';
5
5
  import { dec, equals, gt, pick } from 'ramda';
6
6
 
7
+ import { BarGroupBar, SeriesPoint, StackKey } from '@visx/shape/lib/types';
7
8
  import { BarStyle } from './models';
8
9
  import { UseBarStackProps, useBarStack } from './useBarStack';
9
10
 
@@ -19,6 +20,7 @@ interface Props extends Omit<UseBarStackProps, 'xScale'> {
19
20
  barStyle: BarStyle;
20
21
  barWidth: number;
21
22
  isTooltipHidden: boolean;
23
+ neutralValue: number;
22
24
  }
23
25
 
24
26
  const getPadding = ({ padding, size, isNegativeValue }): number => {
@@ -29,6 +31,47 @@ const getPadding = ({ padding, size, isNegativeValue }): number => {
29
31
  return padding + size;
30
32
  };
31
33
 
34
+ interface GetFirstBarHeightProps {
35
+ bar: Omit<BarGroupBar<StackKey>, 'key' | 'value'> & {
36
+ bar: SeriesPoint<unknown>;
37
+ key: StackKey;
38
+ };
39
+ isHorizontal: boolean;
40
+ barWidth: number;
41
+ y: number;
42
+ isFirstBar: boolean;
43
+ yScale: ScaleType;
44
+ neutralValue: number;
45
+ }
46
+
47
+ const getFirstBarHeight = ({
48
+ bar,
49
+ isHorizontal,
50
+ barWidth,
51
+ y,
52
+ isFirstBar,
53
+ yScale,
54
+ neutralValue
55
+ }: GetFirstBarHeightProps): number => {
56
+ if (!isFirstBar || !isHorizontal) {
57
+ return isHorizontal ? Math.abs(bar.height) : barWidth;
58
+ }
59
+
60
+ if (equals(bar.height, 0)) {
61
+ return 0;
62
+ }
63
+
64
+ if (isHorizontal && bar.height < 0) {
65
+ return bar.height;
66
+ }
67
+
68
+ if (isHorizontal) {
69
+ return Math.abs(bar.width) - (y - yScale(neutralValue));
70
+ }
71
+
72
+ return barWidth;
73
+ };
74
+
32
75
  const BarStack = ({
33
76
  timeSeries,
34
77
  isHorizontal,
@@ -38,7 +81,8 @@ const BarStack = ({
38
81
  barPadding,
39
82
  barIndex,
40
83
  isTooltipHidden,
41
- barStyle = { opacity: 1, radius: 0.2 }
84
+ barStyle = { opacity: 1, radius: 0.2 },
85
+ neutralValue
42
86
  }: Props): JSX.Element => {
43
87
  const {
44
88
  BarStackComponent,
@@ -73,7 +117,21 @@ const BarStack = ({
73
117
  {...barRoundedProps}
74
118
  data-testid={`stacked-bar-${bar.key}-${bar.index}-${bar.bar[1]}`}
75
119
  fill={bar.color}
76
- height={isHorizontal ? Math.abs(bar.height) : barWidth}
120
+ height={getFirstBarHeight({
121
+ bar,
122
+ barWidth,
123
+ y: isHorizontal
124
+ ? getPadding({
125
+ isNegativeValue,
126
+ padding: bar.y,
127
+ size: bar.height
128
+ })
129
+ : barPadding,
130
+ isFirstBar: shouldApplyRadiusOnBottom,
131
+ isHorizontal,
132
+ yScale,
133
+ neutralValue
134
+ })}
77
135
  key={`bar-stack-${barStack.index}-${bar.index}`}
78
136
  opacity={barStyle.opacity ?? 1}
79
137
  radius={barWidth * barStyle.radius}
@@ -87,15 +145,7 @@ const BarStack = ({
87
145
  size: bar.width
88
146
  })
89
147
  }
90
- y={
91
- isHorizontal
92
- ? getPadding({
93
- isNegativeValue,
94
- padding: bar.y,
95
- size: bar.height
96
- })
97
- : barPadding
98
- }
148
+ y={isHorizontal ? bar.y : barPadding}
99
149
  onMouseEnter={
100
150
  isTooltipHidden
101
151
  ? undefined
@@ -122,7 +172,8 @@ const propsToMemoize = [
122
172
  'barPadding',
123
173
  'barIndex',
124
174
  'isTooltipHidden',
125
- 'barStyle'
175
+ 'barStyle',
176
+ 'neutralValue'
126
177
  ];
127
178
 
128
179
  export default memo(BarStack, (prevProps, nextProps) => {
@@ -39,6 +39,7 @@ interface Props
39
39
  thresholdUnit?: string;
40
40
  thresholds?: ThresholdsModel;
41
41
  width: number;
42
+ skipIntersectionObserver?: boolean;
42
43
  }
43
44
 
44
45
  const ResponsiveBarChart = ({
@@ -226,6 +227,7 @@ const ResponsiveBarChart = ({
226
227
  timeSeries={timeSeries}
227
228
  xScale={xScale}
228
229
  yScalesPerUnit={yScalesPerUnit}
230
+ scaleType={axis?.scale}
229
231
  />
230
232
  {thresholds?.enabled && (
231
233
  <Thresholds
@@ -59,7 +59,7 @@ interface Props extends LineChartProps {
59
59
  transformMatrix?: {
60
60
  fx?: (pointX: number) => number;
61
61
  fy?: (pointY: number) => number;
62
- }
62
+ };
63
63
  }
64
64
 
65
65
  const filterLines = (lines: Array<Line>, displayThreshold: boolean): Array<Line> => {