@centreon/ui 25.10.12 → 25.10.13

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": "25.10.12",
3
+ "version": "25.10.13",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -28,8 +28,8 @@
28
28
  "url": "git+https://github.com/centreon/centreon.git"
29
29
  },
30
30
  "keywords": [
31
- "centreon",
32
- "react"
31
+ "react",
32
+ "centreon"
33
33
  ],
34
34
  "author": {
35
35
  "name": "centreon@centreon.com"
@@ -68,7 +68,7 @@ const ResponsiveBarChart = ({
68
68
 
69
69
  const { classes, cx } = useTooltipStyles();
70
70
 
71
- const [linesGraph, setLinesGraph] = useState<Array<Line>>(lines);
71
+ const [linesGraph, setLinesGraph] = useState<Array<Line>>(lines || []);
72
72
  const graphSvgRef = useRef<SVGSVGElement | null>(null);
73
73
 
74
74
  const [tooltipData, setTooltipData] = useAtom(tooltipDataAtom);
@@ -81,7 +81,7 @@ const ResponsiveBarChart = ({
81
81
  );
82
82
 
83
83
  const [firstUnit, secondUnit] = getUnits(displayedLines);
84
- const allUnits = getUnits(lines);
84
+ const allUnits = getUnits(lines || []);
85
85
 
86
86
  const { maxLeftAxisCharacters, maxRightAxisCharacters } =
87
87
  useComputeYAxisMaxCharacters({
@@ -156,12 +156,12 @@ const ResponsiveBarChart = ({
156
156
  ]
157
157
  );
158
158
 
159
- const leftScale = yScalesPerUnit[firstUnit];
160
- const rightScale = yScalesPerUnit[secondUnit];
159
+ const leftScale = yScalesPerUnit[firstUnit ?? allUnits?.[0]];
160
+ const rightScale = yScalesPerUnit[secondUnit ?? allUnits?.[1]];
161
161
 
162
162
  useEffect(
163
163
  () => {
164
- setLinesGraph(lines);
164
+ setLinesGraph(lines || []);
165
165
  },
166
166
  useDeepCompare([lines])
167
167
  );
@@ -138,7 +138,7 @@ const Chart = ({
138
138
  ]);
139
139
 
140
140
  const displayedLines = useMemo(
141
- () => linesGraph.filter(({ display }) => display),
141
+ () => (linesGraph || []).filter(({ display }) => display),
142
142
  [linesGraph]
143
143
  );
144
144
  const [firstUnit, secondUnit] = useMemo(
@@ -213,8 +213,13 @@ const Chart = ({
213
213
  ]
214
214
  );
215
215
 
216
- const leftScale = yScalesPerUnit[axis?.axisYLeft?.unit ?? firstUnit];
217
- const rightScale = yScalesPerUnit[axis?.axisYRight?.unit ?? secondUnit];
216
+ const allUnits = getUnits(linesGraph || []);
217
+
218
+ const fallbackLeftUnit = axis?.axisYLeft?.unit ?? firstUnit ?? allUnits?.[0];
219
+ const fallbackRightUnit = axis?.axisYRight?.unit ?? secondUnit ?? allUnits?.[1];
220
+
221
+ const leftScale = yScalesPerUnit[fallbackLeftUnit];
222
+ const rightScale = yScalesPerUnit[fallbackRightUnit];
218
223
 
219
224
  const linesDisplayedAsLine = useMemo(
220
225
  () =>
@@ -229,8 +234,6 @@ const Chart = ({
229
234
  [displayedLines]
230
235
  );
231
236
 
232
- const allUnits = getUnits(linesGraph);
233
-
234
237
  useEffect(
235
238
  () => {
236
239
  setLinesGraph(
@@ -396,4 +399,4 @@ const Chart = ({
396
399
  );
397
400
  };
398
401
 
399
- export default Chart;
402
+ export default Chart;
@@ -31,6 +31,15 @@ interface Props {
31
31
  }
32
32
 
33
33
  const getBoolean = (value) => Boolean(Number(value));
34
+ const defaultDsData = {
35
+ ds_color_line: '#000000',
36
+ ds_filled: false,
37
+ ds_invert: false,
38
+ ds_legend: '',
39
+ ds_order: '0',
40
+ ds_stack: '0',
41
+ ds_transparency: 80
42
+ };
34
43
 
35
44
  const useGraphData = ({ data, end, start }: Props): GraphDataResult => {
36
45
  const adjustedDataRef = useRef<Data>();
@@ -44,9 +53,21 @@ const useGraphData = ({ data, end, start }: Props): GraphDataResult => {
44
53
  return undefined;
45
54
  }
46
55
 
56
+ const metricsWithValidDsData = (data?.metrics || []).map((metric) => ({
57
+ ...metric,
58
+ ds_data: {
59
+ ...defaultDsData,
60
+ ...(metric?.ds_data || {}),
61
+ ds_color_area:
62
+ metric?.ds_data?.ds_color_area ??
63
+ metric?.ds_data?.ds_color_line ??
64
+ defaultDsData.ds_color_line
65
+ }
66
+ }));
67
+
47
68
  const metricsGroupedByColor = groupBy(
48
- (metric) => metric.ds_data.ds_color_line
49
- )(data?.metrics || []);
69
+ (metric) => metric.ds_data?.ds_color_line || '#000000'
70
+ )(metricsWithValidDsData);
50
71
 
51
72
  const newMetrics = Object.entries(metricsGroupedByColor).map(
52
73
  ([color, value]) => {
@@ -59,7 +59,7 @@ const Axes = ({
59
59
  const formatAxisTick = (tick): string =>
60
60
  format({ date: new Date(tick), formatString: tickFormat });
61
61
 
62
- const displayAxisRight = !isNil(secondUnit);
62
+ const displayAxisRight = !isNil(secondUnit) && !isNil(rightScale);
63
63
 
64
64
  const AxisBottom = isHorizontal ? Axis.AxisBottom : Axis.AxisLeft;
65
65
  const AxisLeft = isHorizontal ? Axis.AxisLeft : Axis.AxisTop;
@@ -50,6 +50,11 @@ const ChartSvgWrapper = ({
50
50
  hasSecondUnit
51
51
  }: Props): JSX.Element => {
52
52
  const isHorizontal = equals(orientation, 'horizontal');
53
+ const hasValidLeftScale = Boolean(leftScale);
54
+ const hasValidXScale = Boolean(xScale);
55
+ const canRenderAxes = hasValidLeftScale && hasValidXScale;
56
+ const canRenderGridRows = Boolean(isHorizontal ? leftScale : xScale);
57
+ const canRenderGridColumns = Boolean(isHorizontal ? xScale : leftScale);
53
58
 
54
59
  return (
55
60
  <svg
@@ -65,7 +70,7 @@ const ChartSvgWrapper = ({
65
70
  })}
66
71
  top={margin.top}
67
72
  >
68
- {showGridLines && (
73
+ {showGridLines && (canRenderGridRows || canRenderGridColumns) && (
69
74
  <Grids
70
75
  gridLinesType={gridLinesType}
71
76
  height={graphHeight - margin.top}
@@ -74,21 +79,23 @@ const ChartSvgWrapper = ({
74
79
  xScale={isHorizontal ? xScale : leftScale}
75
80
  />
76
81
  )}
77
- <Axes
78
- allUnits={allUnits}
79
- data={{
80
- baseAxis: base,
81
- lines: displayedLines,
82
- timeSeries,
83
- ...axis
84
- }}
85
- height={graphHeight}
86
- leftScale={leftScale}
87
- orientation={orientation}
88
- rightScale={rightScale}
89
- width={graphWidth}
90
- xScale={xScale}
91
- />
82
+ {canRenderAxes && (
83
+ <Axes
84
+ allUnits={allUnits}
85
+ data={{
86
+ baseAxis: base,
87
+ lines: displayedLines,
88
+ timeSeries,
89
+ ...axis
90
+ }}
91
+ height={graphHeight}
92
+ leftScale={leftScale}
93
+ orientation={orientation}
94
+ rightScale={rightScale}
95
+ width={graphWidth}
96
+ xScale={xScale}
97
+ />
98
+ )}
92
99
  {children}
93
100
  </Group.Group>
94
101
  </svg>
@@ -8,9 +8,9 @@ import { ChartAxis } from '../../Chart/models';
8
8
 
9
9
  interface Props extends Pick<ChartAxis, 'gridLinesType'> {
10
10
  height: number;
11
- leftScale: ScaleLinear<number, number>;
11
+ leftScale?: ScaleLinear<number, number>;
12
12
  width: number;
13
- xScale: ScaleLinear<number, number>;
13
+ xScale?: ScaleLinear<number, number>;
14
14
  }
15
15
 
16
16
  const Grids = ({
@@ -31,10 +31,10 @@ const Grids = ({
31
31
 
32
32
  return (
33
33
  <g>
34
- {displayRows && (
34
+ {displayRows && leftScale && (
35
35
  <Grid.GridRows height={height} scale={leftScale} width={width} />
36
36
  )}
37
- {displayColumns && (
37
+ {displayColumns && xScale && (
38
38
  <Grid.GridColumns height={height} scale={xScale} width={width} />
39
39
  )}
40
40
  </g>
@@ -54,6 +54,17 @@ interface TimeTickWithMetrics {
54
54
  timeTick: string;
55
55
  }
56
56
 
57
+ const defaultDsData = {
58
+ ds_color_line: '#000000',
59
+ ds_filled: false,
60
+ ds_invert: false,
61
+ ds_legend: '',
62
+ ds_order: '0',
63
+ ds_stack: '0',
64
+ ds_stack_key: null,
65
+ ds_transparency: 80
66
+ };
67
+
57
68
  const toTimeTickWithMetrics = ({
58
69
  metrics,
59
70
  times
@@ -120,29 +131,39 @@ const toLine = ({
120
131
  maximum_value,
121
132
  metric_id,
122
133
  displayAs
123
- }: Metric): Line => ({
124
- areaColor: ds_data.ds_color_area,
125
- average_value,
126
- color: ds_data.ds_color_line,
127
- display: true,
128
- displayAs,
129
- filled: ds_data.ds_filled,
130
- highlight: undefined,
131
- invert: ds_data.ds_invert,
132
- legend: ds_data.ds_legend,
133
- lineColor: ds_data.ds_color_line,
134
- maximum_value,
135
- metric,
136
- metric_id,
137
- minimum_value,
138
- name: legend,
139
- stackOrder:
140
- equals(ds_data.ds_stack, '1') || equals(ds_data.ds_stack, true)
141
- ? Number.parseInt(ds_data.ds_order || '0', 10)
142
- : null,
143
- transparency: ds_data.ds_transparency,
144
- unit
145
- });
134
+ }: Metric): Line => {
135
+ const safeDsData = {
136
+ ...defaultDsData,
137
+ ...(ds_data || {}),
138
+ ds_color_area:
139
+ ds_data?.ds_color_area ?? ds_data?.ds_color_line ?? defaultDsData.ds_color_line
140
+ };
141
+
142
+ return {
143
+ areaColor: safeDsData.ds_color_area,
144
+ average_value,
145
+ color: safeDsData.ds_color_line,
146
+ display: true,
147
+ displayAs,
148
+ filled: safeDsData.ds_filled,
149
+ highlight: undefined,
150
+ invert: safeDsData.ds_invert,
151
+ legend: safeDsData.ds_legend,
152
+ lineColor: safeDsData.ds_color_line,
153
+ maximum_value,
154
+ metric,
155
+ metric_id,
156
+ minimum_value,
157
+ name: legend,
158
+ stackKey: safeDsData.ds_stack_key || null,
159
+ stackOrder:
160
+ equals(safeDsData.ds_stack, '1') || equals(safeDsData.ds_stack, true)
161
+ ? Number.parseInt(safeDsData.ds_order || '0', 10)
162
+ : null,
163
+ transparency: safeDsData.ds_transparency,
164
+ unit
165
+ };
166
+ };
146
167
 
147
168
  const getLineData = (graphData: LineChartData): Array<Line> =>
148
169
  map(toLine, graphData.metrics);
@@ -791,4 +812,4 @@ export {
791
812
  formatMetricValueWithUnit,
792
813
  getYScaleUnit,
793
814
  getYScalePerUnit
794
- };
815
+ };
@@ -9,7 +9,8 @@ interface DsData {
9
9
  ds_invert: string | null;
10
10
  ds_legend: string | null;
11
11
  ds_order: string | null;
12
- ds_stack: string | null;
12
+ ds_stack: string | boolean | null;
13
+ ds_stack_key?: string | null;
13
14
  ds_transparency: number;
14
15
  }
15
16
 
@@ -56,6 +57,7 @@ export interface Line {
56
57
  minimum_value: number | null;
57
58
  name: string;
58
59
  stackOrder: number | null;
60
+ stackKey: string | null;
59
61
  transparency: number;
60
62
  unit: string;
61
63
  }