@centreon/ui 24.6.0 → 24.6.2

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 (50) hide show
  1. package/package.json +1 -1
  2. package/src/Dashboard/Item.tsx +25 -8
  3. package/src/Dashboard/Layout.tsx +15 -1
  4. package/src/Dashboard/atoms.ts +3 -0
  5. package/src/Graph/BarStack/BarStack.cypress.spec.tsx +1 -1
  6. package/src/Graph/BarStack/BarStack.stories.tsx +15 -0
  7. package/src/Graph/BarStack/BarStack.styles.ts +5 -1
  8. package/src/Graph/BarStack/ResponsiveBarStack.tsx +18 -15
  9. package/src/Graph/BarStack/useResponsiveBarStack.ts +4 -8
  10. package/src/Graph/Gauge/AnimatedPie.tsx +3 -1
  11. package/src/Graph/Gauge/Gauge.stories.tsx +10 -2
  12. package/src/Graph/Gauge/PieData.tsx +9 -4
  13. package/src/Graph/Gauge/ResponsiveGauge.tsx +55 -69
  14. package/src/Graph/Gauge/Thresholds.tsx +5 -3
  15. package/src/Graph/Gauge/utils.ts +4 -0
  16. package/src/Graph/HeatMap/HeatMap.tsx +3 -1
  17. package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +12 -4
  18. package/src/Graph/LineChart/Header/index.tsx +2 -2
  19. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/useTickGraph.ts +1 -1
  20. package/src/Graph/LineChart/InteractiveComponents/GraphValueTooltip/useGraphValueTooltip.ts +5 -3
  21. package/src/Graph/LineChart/Legend/Legend.styles.ts +10 -3
  22. package/src/Graph/LineChart/Legend/LegendHeader.tsx +3 -1
  23. package/src/Graph/LineChart/Legend/index.tsx +19 -3
  24. package/src/Graph/LineChart/LineChart.styles.ts +4 -47
  25. package/src/Graph/LineChart/LineChart.tsx +132 -211
  26. package/src/Graph/LineChart/index.stories.tsx +3 -1
  27. package/src/Graph/LineChart/models.ts +1 -5
  28. package/src/Graph/PieChart/PieChart.cypress.spec.tsx +1 -1
  29. package/src/Graph/PieChart/PieChart.stories.tsx +14 -0
  30. package/src/Graph/PieChart/ResponsivePie.tsx +15 -9
  31. package/src/Graph/PieChart/useResponsivePie.ts +0 -3
  32. package/src/Graph/SingleBar/ResponsiveSingleBar.tsx +65 -68
  33. package/src/Graph/SingleBar/SingleBar.stories.tsx +28 -0
  34. package/src/Graph/SingleBar/ThresholdLine.tsx +14 -18
  35. package/src/Graph/SingleBar/Thresholds.tsx +9 -1
  36. package/src/Graph/Text/Text.stories.tsx +32 -0
  37. package/src/Graph/Text/Text.styles.ts +0 -1
  38. package/src/Graph/Text/Text.tsx +11 -7
  39. package/src/Graph/{LineChart/BasicComponents → common}/Axes/UnitLabel.tsx +1 -1
  40. package/src/Graph/{LineChart/BasicComponents → common}/Axes/index.tsx +8 -7
  41. package/src/Graph/{LineChart/BasicComponents → common}/Axes/models.ts +2 -2
  42. package/src/Graph/{LineChart/BasicComponents → common}/Axes/useAxisY.ts +2 -2
  43. package/src/Graph/common/BaseChart/BaseChart.tsx +114 -0
  44. package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +75 -0
  45. package/src/Graph/common/BaseChart/useBaseChartStyles.ts +38 -0
  46. package/src/Graph/common/BaseChart/useComputeBaseChartDimensions.ts +61 -0
  47. package/src/Graph/{LineChart/BasicComponents → common}/Grids/index.tsx +1 -1
  48. package/src/Graph/common/useTooltipStyles.ts +17 -0
  49. package/src/Graph/common/utils.ts +6 -0
  50. package/src/Typography/FluidTypography/index.tsx +5 -3
@@ -0,0 +1,114 @@
1
+ import {
2
+ Dispatch,
3
+ MutableRefObject,
4
+ ReactNode,
5
+ SetStateAction,
6
+ useMemo
7
+ } from 'react';
8
+
9
+ import { equals, gt, isNil, lte, reduce } from 'ramda';
10
+
11
+ import { Stack } from '@mui/material';
12
+
13
+ import Legend from '../../LineChart/Legend';
14
+ import { legendWidth } from '../../LineChart/Legend/Legend.styles';
15
+ import { Line } from '../timeSeries/models';
16
+
17
+ import { useBaseChartStyles } from './useBaseChartStyles';
18
+
19
+ interface Props {
20
+ base?: number;
21
+ children: JSX.Element;
22
+ graphWidth: number;
23
+ height: number | null;
24
+ legend: {
25
+ displayLegend: boolean;
26
+ mode: 'grid' | 'list';
27
+ placement: string;
28
+ renderExtraComponent?: ReactNode;
29
+ };
30
+ legendRef: MutableRefObject<HTMLDivElement | null>;
31
+ limitLegend?: number | false;
32
+ lines: Array<Line>;
33
+ setLines: Dispatch<SetStateAction<Array<Line> | null>>;
34
+ }
35
+
36
+ const BaseChart = ({
37
+ legend,
38
+ base = 1000,
39
+ height,
40
+ graphWidth,
41
+ lines,
42
+ limitLegend = false,
43
+ setLines,
44
+ children,
45
+ legendRef
46
+ }: Props): JSX.Element => {
47
+ const { classes } = useBaseChartStyles();
48
+
49
+ const legendItemsWidth = useMemo(
50
+ () => reduce((acc) => acc + legendWidth * 8 + 24, 0, lines),
51
+ [lines]
52
+ );
53
+
54
+ const displayLegendInBottom = useMemo(
55
+ () => isNil(legend.placement) || equals(legend.placement, 'bottom'),
56
+ [legend.placement]
57
+ );
58
+
59
+ const shouldDisplayLegendInCompactMode = useMemo(
60
+ () =>
61
+ lte(graphWidth, 808) &&
62
+ gt(legendItemsWidth, graphWidth) &&
63
+ displayLegendInBottom,
64
+ [graphWidth, displayLegendInBottom, legendItemsWidth]
65
+ );
66
+
67
+ return (
68
+ <>
69
+ <div className={classes.container}>
70
+ <Stack
71
+ direction={equals(legend?.placement, 'left') ? 'row' : 'row-reverse'}
72
+ >
73
+ {legend.displayLegend &&
74
+ (equals(legend?.placement, 'left') ||
75
+ equals(legend?.placement, 'right')) && (
76
+ <div ref={legendRef} style={{ maxWidth: '60%' }}>
77
+ <Legend
78
+ base={base}
79
+ height={height}
80
+ limitLegend={limitLegend}
81
+ lines={lines}
82
+ mode={legend?.mode}
83
+ placement="left"
84
+ renderExtraComponent={legend?.renderExtraComponent}
85
+ setLinesGraph={setLines}
86
+ shouldDisplayLegendInCompactMode={
87
+ shouldDisplayLegendInCompactMode
88
+ }
89
+ />
90
+ </div>
91
+ )}
92
+ {children}
93
+ </Stack>
94
+ </div>
95
+ {legend.displayLegend && displayLegendInBottom && (
96
+ <div ref={legendRef}>
97
+ <Legend
98
+ base={base}
99
+ height={height}
100
+ limitLegend={limitLegend}
101
+ lines={lines}
102
+ mode={legend.mode}
103
+ placement="bottom"
104
+ renderExtraComponent={legend.renderExtraComponent}
105
+ setLinesGraph={setLines}
106
+ shouldDisplayLegendInCompactMode={shouldDisplayLegendInCompactMode}
107
+ />
108
+ </div>
109
+ )}
110
+ </>
111
+ );
112
+ };
113
+
114
+ export default BaseChart;
@@ -0,0 +1,75 @@
1
+ import { MutableRefObject } from 'react';
2
+
3
+ import { Group } from '@visx/visx';
4
+
5
+ import { margin } from '../../LineChart/common';
6
+ import Grids from '../Grids';
7
+ import Axes from '../Axes';
8
+ import { Line, TimeValue } from '../timeSeries/models';
9
+ import { LineChartAxis } from '../../LineChart/models';
10
+
11
+ import { extraMargin } from './useComputeBaseChartDimensions';
12
+
13
+ interface Props {
14
+ axis?: LineChartAxis;
15
+ base?: number;
16
+ children: JSX.Element;
17
+ displayedLines: Array<Line>;
18
+ graphHeight: number;
19
+ graphWidth: number;
20
+ gridLinesType?: string;
21
+ leftScale;
22
+ rightScale;
23
+ showGridLines: boolean;
24
+ svgRef: MutableRefObject<SVGSVGElement | null>;
25
+ timeSeries: Array<TimeValue>;
26
+ xScale;
27
+ }
28
+
29
+ const ChartSvgWrapper = ({
30
+ svgRef,
31
+ graphHeight,
32
+ leftScale,
33
+ rightScale,
34
+ xScale,
35
+ graphWidth,
36
+ showGridLines,
37
+ gridLinesType,
38
+ base = 1000,
39
+ displayedLines,
40
+ timeSeries,
41
+ axis,
42
+ children
43
+ }: Props): JSX.Element => {
44
+ return (
45
+ <svg height={graphHeight + margin.top} ref={svgRef} width="100%">
46
+ <Group.Group left={margin.left + extraMargin / 2} top={margin.top}>
47
+ {showGridLines && (
48
+ <Grids
49
+ gridLinesType={gridLinesType}
50
+ height={graphHeight - margin.top}
51
+ leftScale={leftScale}
52
+ width={graphWidth}
53
+ xScale={xScale}
54
+ />
55
+ )}
56
+ <Axes
57
+ data={{
58
+ baseAxis: base,
59
+ lines: displayedLines,
60
+ timeSeries,
61
+ ...axis
62
+ }}
63
+ height={graphHeight - margin.top}
64
+ leftScale={leftScale}
65
+ rightScale={rightScale}
66
+ width={graphWidth}
67
+ xScale={xScale}
68
+ />
69
+ {children}
70
+ </Group.Group>
71
+ </svg>
72
+ );
73
+ };
74
+
75
+ export default ChartSvgWrapper;
@@ -0,0 +1,38 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ export const useBaseChartStyles = makeStyles()((theme) => ({
4
+ container: {
5
+ '& .visx-axis-bottom': {
6
+ '& .visx-axis-tick': {
7
+ '& .visx-line': {
8
+ stroke: theme.palette.text.primary
9
+ },
10
+ text: {
11
+ fill: theme.palette.text.primary
12
+ }
13
+ }
14
+ },
15
+ '& .visx-axis-line': {
16
+ stroke: theme.palette.text.primary
17
+ },
18
+ '& .visx-axis-right': {
19
+ '& .visx-axis-tick': {
20
+ '& .visx-line': {
21
+ stroke: theme.palette.text.primary
22
+ }
23
+ }
24
+ },
25
+ '& .visx-columns': {
26
+ '& .visx-line': {
27
+ stroke: theme.palette.divider
28
+ }
29
+ },
30
+ '& .visx-rows': {
31
+ '& .visx-line': {
32
+ stroke: theme.palette.divider
33
+ }
34
+ },
35
+ fill: theme.palette.text.primary,
36
+ position: 'relative'
37
+ }
38
+ }));
@@ -0,0 +1,61 @@
1
+ import { MutableRefObject, useRef } from 'react';
2
+
3
+ import { equals, isNil } from 'ramda';
4
+
5
+ import { margin } from '../../LineChart/common';
6
+
7
+ export const extraMargin = 10;
8
+
9
+ interface UseComputeBaseChartDimensionsProps {
10
+ hasSecondUnit?: boolean;
11
+ height: number | null;
12
+ legendDisplay?: boolean;
13
+ legendPlacement?: string;
14
+ width: number;
15
+ }
16
+
17
+ interface UseComputeBaseChartDimensionsState {
18
+ graphHeight: number;
19
+ graphWidth: number;
20
+ legendRef: MutableRefObject<HTMLDivElement | null>;
21
+ }
22
+
23
+ export const useComputeBaseChartDimensions = ({
24
+ width,
25
+ height,
26
+ legendDisplay,
27
+ legendPlacement,
28
+ hasSecondUnit
29
+ }: UseComputeBaseChartDimensionsProps): UseComputeBaseChartDimensionsState => {
30
+ const legendRef = useRef<HTMLDivElement | null>(null);
31
+
32
+ const legendBoundingHeight =
33
+ !equals(legendDisplay, false) &&
34
+ (isNil(legendPlacement) || equals(legendPlacement, 'bottom'))
35
+ ? legendRef.current?.getBoundingClientRect().height || 0
36
+ : 0;
37
+ const legendBoundingWidth =
38
+ !equals(legendDisplay, false) &&
39
+ (equals(legendPlacement, 'left') || equals(legendPlacement, 'right'))
40
+ ? legendRef.current?.getBoundingClientRect().width || 0
41
+ : 0;
42
+
43
+ const graphWidth =
44
+ width > 0
45
+ ? width -
46
+ margin.left -
47
+ (hasSecondUnit ? margin.right : 8) -
48
+ extraMargin -
49
+ legendBoundingWidth
50
+ : 0;
51
+ const graphHeight =
52
+ (height || 0) > 0
53
+ ? (height || 0) - margin.top - 5 - legendBoundingHeight
54
+ : 0;
55
+
56
+ return {
57
+ graphHeight,
58
+ graphWidth,
59
+ legendRef
60
+ };
61
+ };
@@ -4,7 +4,7 @@ import { Grid } from '@visx/visx';
4
4
  import { ScaleLinear } from 'd3-scale';
5
5
  import { includes } from 'ramda';
6
6
 
7
- import { LineChartAxis } from '../../models';
7
+ import { LineChartAxis } from '../../LineChart/models';
8
8
 
9
9
  interface Props extends Pick<LineChartAxis, 'gridLinesType'> {
10
10
  height: number;
@@ -0,0 +1,17 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ export const useTooltipStyles = makeStyles()((theme) => ({
4
+ tooltip: {
5
+ backgroundColor: theme.palette.background.paper,
6
+ borderRadius: theme.shape.borderRadius,
7
+ boxShadow: theme.shadows[3],
8
+ color: theme.palette.text.primary,
9
+ fontSize: theme.typography.caption.fontSize,
10
+ fontWeight: theme.typography.caption.fontWeight,
11
+ maxWidth: 'none',
12
+ padding: theme.spacing(0.5, 1)
13
+ },
14
+ tooltipDisablePadding: {
15
+ padding: theme.spacing(0)
16
+ }
17
+ }));
@@ -172,3 +172,9 @@ export const getStrokeDashArray = ({
172
172
 
173
173
  export const getPointRadius = (lineWidth?: number): number =>
174
174
  Math.max(Math.ceil((lineWidth ?? 2) * 1.2), 2);
175
+
176
+ export const commonTickLabelProps = {
177
+ fontFamily: 'Roboto, sans-serif',
178
+ fontSize: 10,
179
+ textAnchor: 'middle'
180
+ };
@@ -1,6 +1,6 @@
1
1
  import { Typography, TypographyProps } from '@mui/material';
2
2
 
3
- type CustomTypographyProps = Pick<TypographyProps, 'variant'>;
3
+ type CustomTypographyProps = Pick<TypographyProps, 'variant' | 'sx'>;
4
4
  export interface FluidTypographyProps extends CustomTypographyProps {
5
5
  className?: string;
6
6
  containerClassName?: string;
@@ -17,7 +17,8 @@ const FluidTypography = ({
17
17
  containerClassName,
18
18
  min = '10px',
19
19
  max = '1000px',
20
- pref = 19
20
+ pref = 19,
21
+ sx
21
22
  }: FluidTypographyProps): JSX.Element => {
22
23
  return (
23
24
  <div
@@ -31,7 +32,8 @@ const FluidTypography = ({
31
32
  <Typography
32
33
  className={className}
33
34
  sx={{
34
- fontSize: `clamp(${min}, ${pref}cqi, ${max})`
35
+ fontSize: `clamp(${min}, ${pref}cqi, ${max})`,
36
+ ...sx
35
37
  }}
36
38
  variant={variant}
37
39
  >