@centreon/ui 23.10.57 → 23.10.59

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 (126) hide show
  1. package/package.json +3 -1
  2. package/src/Graph/Gauge/AnimatedPie.tsx +87 -0
  3. package/src/Graph/Gauge/Gauge.stories.tsx +45 -0
  4. package/src/Graph/Gauge/Gauge.tsx +44 -0
  5. package/src/Graph/Gauge/PieData.tsx +79 -0
  6. package/src/Graph/Gauge/ResponsiveGauge.tsx +135 -0
  7. package/src/Graph/Gauge/Thresholds.tsx +87 -0
  8. package/src/Graph/Gauge/index.ts +1 -0
  9. package/src/Graph/Gauge/models.ts +20 -0
  10. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Axes/index.tsx +1 -1
  11. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Axes/models.ts +1 -1
  12. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Axes/useAxisY.ts +1 -1
  13. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/RegularLines/index.tsx +2 -2
  14. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/RegularLines/useRegularLines.ts +2 -2
  15. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/StackedLines/index.tsx +2 -2
  16. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/StackedLines/useStackedLines.ts +1 -1
  17. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/BasicThreshold.tsx +1 -1
  18. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/ThresholdWithPatternLines.tsx +3 -2
  19. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/ThresholdWithVariation.tsx +1 -1
  20. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/index.tsx +1 -1
  21. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/models.ts +1 -1
  22. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/useScaleThreshold.ts +2 -2
  23. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/index.tsx +6 -2
  24. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/models.ts +3 -3
  25. package/src/Graph/{BasicComponents → LineChart/BasicComponents}/useFilterLines.ts +1 -1
  26. package/src/Graph/{Header → LineChart/Header}/index.tsx +4 -4
  27. package/src/Graph/{Icons → LineChart/Icons}/Downtime.tsx +1 -1
  28. package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/AnchorPoint/RegularAnchorPoint.tsx +2 -2
  29. package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/AnchorPoint/StackedAnchorPoint.tsx +2 -2
  30. package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/AnchorPoint/models.ts +1 -1
  31. package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/AnchorPoint/useTickGraph.ts +2 -2
  32. package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Tooltip/useGraphTooltip.ts +1 -1
  33. package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/index.tsx +2 -2
  34. package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/interactionWithGraphAtoms.ts +1 -1
  35. package/src/Graph/{Legend → LineChart/Legend}/LegendHeader.tsx +1 -1
  36. package/src/Graph/{Legend → LineChart/Legend}/index.tsx +2 -2
  37. package/src/Graph/{Legend → LineChart/Legend}/useInteractiveValues.ts +6 -2
  38. package/src/Graph/{Legend → LineChart/Legend}/useLegend.ts +1 -1
  39. package/src/Graph/{Graph.tsx → LineChart/LineChart.tsx} +8 -7
  40. package/src/Graph/{graphAtoms.ts → LineChart/graphAtoms.ts} +1 -1
  41. package/src/Graph/{helpers → LineChart/helpers}/index.ts +9 -4
  42. package/src/Graph/{index.stories.tsx → LineChart/index.stories.tsx} +39 -38
  43. package/src/Graph/{index.tsx → LineChart/index.tsx} +14 -12
  44. package/src/Graph/{models.ts → LineChart/models.ts} +8 -12
  45. package/src/Graph/{useGraphData.ts → LineChart/useLineChartData.ts} +5 -3
  46. package/src/Graph/SingleBar/ResponsiveSingleBar.tsx +163 -0
  47. package/src/Graph/SingleBar/SingleBar.stories.tsx +45 -0
  48. package/src/Graph/SingleBar/SingleBar.tsx +25 -0
  49. package/src/Graph/SingleBar/Thresholds.tsx +100 -0
  50. package/src/Graph/SingleBar/index.ts +1 -0
  51. package/src/Graph/SingleBar/models.ts +8 -0
  52. package/src/Graph/Text/Text.stories.tsx +54 -0
  53. package/src/Graph/Text/Text.styles.ts +17 -0
  54. package/src/Graph/Text/Text.tsx +80 -0
  55. package/src/Graph/Text/index.ts +1 -0
  56. package/src/Graph/common/margins.ts +1 -0
  57. package/src/Graph/common/models.ts +7 -0
  58. package/src/Graph/{timeSeries → common/timeSeries}/index.test.ts +2 -2
  59. package/src/Graph/{timeSeries → common/timeSeries}/index.ts +22 -6
  60. package/src/Graph/{timeSeries → common/timeSeries}/models.ts +2 -0
  61. package/src/Graph/common/utils.ts +20 -0
  62. package/src/Graph/index.ts +4 -0
  63. package/src/InputField/Select/Autocomplete/Connected/Multi/MultiConnectedAutocompleteField.cypress.spec.tsx +4 -6
  64. package/src/Listing/Listing.cypress.spec.tsx +2 -2
  65. package/src/RichTextEditor/RichTextEditor.cypress.spec.tsx +10 -6
  66. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +1 -1
  67. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +1 -1
  68. package/src/api/useGraphQuery/index.ts +7 -4
  69. package/src/components/CollapsibleItem/useCollapsibleItemStyles.ts +1 -0
  70. package/src/index.ts +3 -2
  71. package/src/utils/useLicenseExpirationWarning.cypress.spec.tsx +1 -1
  72. /package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Axes/UnitLabel.tsx +0 -0
  73. /package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Grids/index.tsx +0 -0
  74. /package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/Circle.tsx +0 -0
  75. /package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/helpers/index.ts +0 -0
  76. /package/src/Graph/{BasicComponents → LineChart/BasicComponents}/Lines/Threshold/useCoordinateCircle.ts +0 -0
  77. /package/src/Graph/{BasicComponents → LineChart/BasicComponents}/LoadingProgress.tsx +0 -0
  78. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/AnchorPoint/GuidingLines.tsx +0 -0
  79. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/AnchorPoint/TooltipAnchorPoint.tsx +0 -0
  80. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/AnchorPoint/index.tsx +0 -0
  81. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/AnchorPoint/useTooltipAnchorPoint.ts +0 -0
  82. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/Annotation/Area.tsx +0 -0
  83. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/Annotation/Line.tsx +0 -0
  84. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/Annotation/index.tsx +0 -0
  85. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/Area/Downtime.tsx +0 -0
  86. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/EventAnnotations.tsx +0 -0
  87. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/Line/Acknowledgement.tsx +0 -0
  88. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/Line/Comments.tsx +0 -0
  89. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/annotationsAtoms.ts +0 -0
  90. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/index.tsx +0 -0
  91. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/models.ts +0 -0
  92. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Annotations/useAnnotation.ts +0 -0
  93. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Bar.tsx +0 -0
  94. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/TimeShiftZones/TimeShiftIcon.tsx +0 -0
  95. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/TimeShiftZones/TimeShiftZone.tsx +0 -0
  96. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/TimeShiftZones/index.tsx +0 -0
  97. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/TimeShiftZones/models.ts +0 -0
  98. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/TimeShiftZones/useTimeShiftZones.ts +0 -0
  99. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Tooltip/index.tsx +0 -0
  100. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/Tooltip/models.ts +0 -0
  101. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/ZoomPreview/index.tsx +0 -0
  102. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/ZoomPreview/models.ts +0 -0
  103. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/ZoomPreview/useZoomPreview.ts +0 -0
  104. /package/src/Graph/{InteractiveComponents → LineChart/InteractiveComponents}/ZoomPreview/zoomPreviewAtoms.ts +0 -0
  105. /package/src/Graph/{Legend → LineChart/Legend}/InteractiveValue.tsx +0 -0
  106. /package/src/Graph/{Legend → LineChart/Legend}/Legend.styles.ts +0 -0
  107. /package/src/Graph/{Legend → LineChart/Legend}/LegendContent.tsx +0 -0
  108. /package/src/Graph/{Legend → LineChart/Legend}/Marker.tsx +0 -0
  109. /package/src/Graph/{Legend → LineChart/Legend}/models.ts +0 -0
  110. /package/src/Graph/{Graph.styles.ts → LineChart/LineChart.styles.ts} +0 -0
  111. /package/src/Graph/{LoadingSkeleton.tsx → LineChart/LoadingSkeleton.tsx} +0 -0
  112. /package/src/Graph/{common → LineChart/common}/index.ts +0 -0
  113. /package/src/Graph/{helpers → LineChart/helpers}/doc.ts +0 -0
  114. /package/src/Graph/{mockedData → LineChart/mockedData}/annotationData.json +0 -0
  115. /package/src/Graph/{mockedData → LineChart/mockedData}/exclusionPeriodFirstPeriod.json +0 -0
  116. /package/src/Graph/{mockedData → LineChart/mockedData}/exclusionPeriodSecondPeriod.json +0 -0
  117. /package/src/Graph/{mockedData → LineChart/mockedData}/exclusionPeriodThirdPeriod.json +0 -0
  118. /package/src/Graph/{mockedData → LineChart/mockedData}/lastDay.json +0 -0
  119. /package/src/Graph/{mockedData → LineChart/mockedData}/lastDayAreaStack.json +0 -0
  120. /package/src/Graph/{mockedData → LineChart/mockedData}/lastDayForward.json +0 -0
  121. /package/src/Graph/{mockedData → LineChart/mockedData}/lastDayThreshold.json +0 -0
  122. /package/src/Graph/{mockedData → LineChart/mockedData}/lastMonth.json +0 -0
  123. /package/src/Graph/{mockedData → LineChart/mockedData}/lastWeek.json +0 -0
  124. /package/src/Graph/{mockedData → LineChart/mockedData}/zoomPreview.json +0 -0
  125. /package/src/Graph/{translatedLabels.ts → LineChart/translatedLabels.ts} +0 -0
  126. /package/src/Graph/{useGraphIntersection.ts → LineChart/useLineChartIntersection.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "23.10.57",
3
+ "version": "23.10.59",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -107,7 +107,9 @@
107
107
  "@lexical/rich-text": "^0.11.3",
108
108
  "@lexical/selection": "0.11.3",
109
109
  "@lexical/utils": "0.11.3",
110
+ "@react-spring/web": "^9.7.3",
110
111
  "@visx/curve": "^2.1.0",
112
+ "@visx/group": "^3.3.0",
111
113
  "@visx/pattern": "^3.0.0",
112
114
  "@visx/scale": "^3.0.0",
113
115
  "@visx/shape": "^2.12.2",
@@ -0,0 +1,87 @@
1
+ import { PieArcDatum, ProvidedProps } from '@visx/shape/lib/shapes/Pie';
2
+ import { useTransition, interpolate, animated } from '@react-spring/web';
3
+ import { equals } from 'ramda';
4
+
5
+ import { Metric } from '../common/timeSeries/models';
6
+
7
+ import { ThresholdType } from './models';
8
+
9
+ type AnimatedStyles = { endAngle: number; opacity: number; startAngle: number };
10
+
11
+ const fromLeaveTransition = (): AnimatedStyles => ({
12
+ endAngle: 0,
13
+ opacity: 0,
14
+ startAngle: 0
15
+ });
16
+ const enterUpdateTransition = <T,>({
17
+ startAngle,
18
+ endAngle
19
+ }: PieArcDatum<T>): AnimatedStyles => ({
20
+ endAngle,
21
+ opacity: 1,
22
+ startAngle
23
+ });
24
+
25
+ type AnimatedPieProps<Datum> = ProvidedProps<Datum> & {
26
+ animate?: boolean;
27
+ delay?: number;
28
+ getColor: (d: PieArcDatum<Datum>) => string;
29
+ getKey: (d: PieArcDatum<Datum>) => string;
30
+ hideTooltip?: () => void;
31
+ metric?: Metric;
32
+ showTooltip?: (args) => void;
33
+ thresholdTooltipLabels?: Array<string>;
34
+ };
35
+
36
+ const AnimatedPie = <Datum,>({
37
+ animate,
38
+ arcs,
39
+ path,
40
+ getKey,
41
+ getColor,
42
+ showTooltip,
43
+ hideTooltip,
44
+ thresholdTooltipLabels = []
45
+ }: AnimatedPieProps<Datum>): JSX.Element => {
46
+ const transitions = useTransition<PieArcDatum<Datum>, AnimatedStyles>(arcs, {
47
+ enter: enterUpdateTransition,
48
+ from: animate ? fromLeaveTransition : enterUpdateTransition,
49
+ keys: getKey,
50
+ leave: animate ? fromLeaveTransition : enterUpdateTransition,
51
+ update: enterUpdateTransition
52
+ });
53
+
54
+ return transitions((props, arc, { key }) => (
55
+ <g key={key}>
56
+ <animated.path
57
+ d={interpolate(
58
+ [props.startAngle, props.endAngle],
59
+ (startAngle, endAngle) =>
60
+ path({
61
+ ...arc,
62
+ endAngle,
63
+ startAngle
64
+ })
65
+ )}
66
+ data-testid={`${arc.data?.value || arc.data}-arc`}
67
+ fill={getColor(arc)}
68
+ onMouseEnter={(event) => {
69
+ const thresholdType = arc.data.name;
70
+
71
+ if (equals(thresholdType, ThresholdType.Success)) {
72
+ return;
73
+ }
74
+
75
+ showTooltip?.({
76
+ tooltipData: thresholdTooltipLabels[thresholdType],
77
+ tooltipLeft: event.clientX,
78
+ tooltipTop: event.clientY
79
+ });
80
+ }}
81
+ onMouseLeave={() => hideTooltip?.()}
82
+ />
83
+ </g>
84
+ ));
85
+ };
86
+
87
+ export default AnimatedPie;
@@ -0,0 +1,45 @@
1
+ import { Meta, StoryObj } from '@storybook/react';
2
+
3
+ import dataLastWeek from '../LineChart/mockedData/lastWeek.json';
4
+
5
+ import { Gauge } from './Gauge';
6
+
7
+ const meta: Meta<typeof Gauge> = {
8
+ component: Gauge
9
+ };
10
+
11
+ export default meta;
12
+ type Story = StoryObj<typeof Gauge>;
13
+
14
+ const Template = (props): JSX.Element => (
15
+ <div style={{ height: '500px', width: '500px' }}>
16
+ <Gauge {...props} />
17
+ </div>
18
+ );
19
+
20
+ export const success: Story = {
21
+ args: {
22
+ data: dataLastWeek,
23
+ thresholdTooltipLabels: ['Warning', 'Critical'],
24
+ thresholds: [0.5, 0.6]
25
+ },
26
+ render: Template
27
+ };
28
+
29
+ export const warning: Story = {
30
+ args: {
31
+ data: dataLastWeek,
32
+ thresholdTooltipLabels: ['Warning', 'Critical'],
33
+ thresholds: [0.2, 0.5]
34
+ },
35
+ render: Template
36
+ };
37
+
38
+ export const critical: Story = {
39
+ args: {
40
+ data: dataLastWeek,
41
+ thresholdTooltipLabels: ['Warning', 'Critical'],
42
+ thresholds: [0.13, 0.35]
43
+ },
44
+ render: Template
45
+ };
@@ -0,0 +1,44 @@
1
+ import { Responsive } from '@visx/visx';
2
+ import { sort, subtract } from 'ramda';
3
+
4
+ import { LineChartData } from '../common/models';
5
+ import { getMetricWithLatestData } from '../common/timeSeries';
6
+ import { Metric } from '../common/timeSeries/models';
7
+
8
+ import ResponsiveGauge from './ResponsiveGauge';
9
+
10
+ interface Props {
11
+ data?: LineChartData;
12
+ disabledThresholds?: boolean;
13
+ thresholdTooltipLabels: Array<string>;
14
+ thresholds: Array<number>;
15
+ }
16
+
17
+ export const Gauge = ({
18
+ thresholds,
19
+ data,
20
+ thresholdTooltipLabels,
21
+ disabledThresholds
22
+ }: Props): JSX.Element | null => {
23
+ if (!data) {
24
+ return null;
25
+ }
26
+ const sortedThresholds = sort(subtract, thresholds);
27
+
28
+ const metric = getMetricWithLatestData(data) as Metric;
29
+
30
+ return (
31
+ <Responsive.ParentSize>
32
+ {({ width, height }) => (
33
+ <ResponsiveGauge
34
+ disabledThresholds={disabledThresholds}
35
+ height={height}
36
+ metric={metric}
37
+ thresholdTooltipLabels={thresholdTooltipLabels}
38
+ thresholds={sortedThresholds}
39
+ width={width}
40
+ />
41
+ )}
42
+ </Responsive.ParentSize>
43
+ );
44
+ };
@@ -0,0 +1,79 @@
1
+ import { scaleOrdinal } from '@visx/scale';
2
+ import { Pie } from '@visx/shape';
3
+ import { T, always, cond, gt, head, identity } from 'ramda';
4
+
5
+ import { Theme, useTheme } from '@mui/material';
6
+
7
+ import { thresholdThickness } from './Thresholds';
8
+ import AnimatedPie from './AnimatedPie';
9
+ import { GaugeProps } from './models';
10
+
11
+ const dataThickness = 45;
12
+
13
+ interface GetColorFromDataProps {
14
+ data: number;
15
+ theme: Theme;
16
+ thresholds: Array<number>;
17
+ }
18
+
19
+ const getColorFromData = ({
20
+ data,
21
+ thresholds,
22
+ theme
23
+ }: GetColorFromDataProps): string =>
24
+ cond([
25
+ [gt(head(thresholds) as number), always(theme.palette.success.main)],
26
+ [gt(thresholds[1]), always(theme.palette.warning.main)],
27
+ [T, always(theme.palette.error.main)]
28
+ ])(data);
29
+
30
+ const PieData = ({
31
+ metric,
32
+ adaptedMaxValue,
33
+ thresholds,
34
+ radius,
35
+ disabledThresholds
36
+ }: Omit<
37
+ GaugeProps,
38
+ 'width' | 'height' | 'showTooltip' | 'hideTooltip' | 'thresholdTooltipLabels'
39
+ >): JSX.Element => {
40
+ const theme = useTheme();
41
+
42
+ const pieData = [metric.data[0], adaptedMaxValue - metric.data[0]];
43
+ const pieColor = disabledThresholds
44
+ ? theme.palette.success.main
45
+ : getColorFromData({
46
+ data: metric.data[0],
47
+ theme,
48
+ thresholds
49
+ });
50
+
51
+ const getDataColor = scaleOrdinal({
52
+ domain: pieData,
53
+ range: [pieColor, 'transparent']
54
+ });
55
+
56
+ return (
57
+ <Pie
58
+ data={pieData}
59
+ endAngle={-Math.PI / 2}
60
+ innerRadius={radius - dataThickness}
61
+ outerRadius={radius - thresholdThickness * 1.3}
62
+ pieSortValues={() => -1}
63
+ pieValue={identity}
64
+ startAngle={Math.PI / 2}
65
+ >
66
+ {(pie) => (
67
+ <AnimatedPie<number>
68
+ {...pie}
69
+ animate
70
+ getColor={(arc) => getDataColor(arc.data)}
71
+ getKey={(arc) => `${arc.data}`}
72
+ thresholdTooltipLabels={[]}
73
+ />
74
+ )}
75
+ </Pie>
76
+ );
77
+ };
78
+
79
+ export default PieData;
@@ -0,0 +1,135 @@
1
+ import { useRef } from 'react';
2
+
3
+ import { Group } from '@visx/group';
4
+ import { head } from 'ramda';
5
+ import { Tooltip } from '@visx/visx';
6
+
7
+ import { Box, Fade, useTheme } from '@mui/material';
8
+
9
+ import { Metric } from '../common/timeSeries/models';
10
+ import { formatMetricValue } from '../common/timeSeries';
11
+ import { getColorFromDataAndTresholds } from '../common/utils';
12
+ import { margins } from '../common/margins';
13
+
14
+ import Thresholds from './Thresholds';
15
+ import PieData from './PieData';
16
+
17
+ interface Props {
18
+ disabledThresholds?: boolean;
19
+ height: number;
20
+ metric: Metric;
21
+ thresholdTooltipLabels: Array<string>;
22
+ thresholds: Array<number>;
23
+ width: number;
24
+ }
25
+
26
+ const baseStyles = {
27
+ ...Tooltip.defaultStyles,
28
+ textAlign: 'center'
29
+ };
30
+
31
+ const ResponsiveGauge = ({
32
+ width,
33
+ height,
34
+ thresholds,
35
+ metric,
36
+ thresholdTooltipLabels,
37
+ disabledThresholds
38
+ }: Props): JSX.Element => {
39
+ const svgRef = useRef<SVGSVGElement>(null);
40
+
41
+ const theme = useTheme();
42
+
43
+ const {
44
+ showTooltip,
45
+ hideTooltip,
46
+ tooltipOpen,
47
+ tooltipLeft,
48
+ tooltipTop,
49
+ tooltipData
50
+ } = Tooltip.useTooltip();
51
+
52
+ const innerWidth = width - margins.left - margins.right;
53
+ const innerHeight = height - margins.top - margins.bottom;
54
+ const centerY = innerHeight / 2;
55
+ const centerX = innerWidth / 2;
56
+ const radius = Math.min(innerWidth, innerHeight) / 2;
57
+ const adaptedMaxValue = Math.max(
58
+ metric.maximum_value || 0,
59
+ Math.max(...thresholds) * 1.1,
60
+ head(metric.data) as number
61
+ );
62
+
63
+ const pieColor = disabledThresholds
64
+ ? theme.palette.success.main
65
+ : getColorFromDataAndTresholds({
66
+ data: metric.data[0],
67
+ theme,
68
+ thresholds
69
+ });
70
+
71
+ const svgTop = svgRef.current?.getBoundingClientRect().top || 0;
72
+ const svgLeft = svgRef.current?.getBoundingClientRect().left || 0;
73
+
74
+ const isSmallHeight = height < 250;
75
+
76
+ return (
77
+ <Box sx={{ position: 'relative' }}>
78
+ <svg height={height} ref={svgRef} width={width}>
79
+ <Group left={centerX + margins.left} top={centerY + height / 6}>
80
+ <Thresholds
81
+ adaptedMaxValue={adaptedMaxValue}
82
+ disabledThresholds={disabledThresholds}
83
+ hideTooltip={hideTooltip}
84
+ metric={metric}
85
+ radius={radius}
86
+ showTooltip={showTooltip}
87
+ thresholdTooltipLabels={thresholdTooltipLabels}
88
+ thresholds={thresholds}
89
+ />
90
+ <PieData
91
+ adaptedMaxValue={adaptedMaxValue}
92
+ disabledThresholds={disabledThresholds}
93
+ metric={metric}
94
+ radius={radius}
95
+ thresholds={thresholds}
96
+ />
97
+ </Group>
98
+ <text
99
+ dominantBaseline="middle"
100
+ style={{
101
+ fill: pieColor,
102
+ ...theme.typography.h3,
103
+ fontSize: Math.min(width, height) / 7
104
+ }}
105
+ textAnchor="middle"
106
+ x="50%"
107
+ y={isSmallHeight ? 140 : 100 + Math.min(width, height) / 3}
108
+ >
109
+ {formatMetricValue({
110
+ base: 1000,
111
+ unit: metric.unit,
112
+ value: metric.data[0]
113
+ })}{' '}
114
+ {metric.unit}
115
+ </text>
116
+ </svg>
117
+ <Fade in={tooltipOpen && !disabledThresholds}>
118
+ <Tooltip.Tooltip
119
+ left={(tooltipLeft || 0) - svgLeft}
120
+ style={{
121
+ ...baseStyles,
122
+ backgroundColor: theme.palette.background.paper,
123
+ color: theme.palette.text.primary,
124
+ transform: 'translate(-50%, 0)'
125
+ }}
126
+ top={(tooltipTop || 0) - svgTop + 20}
127
+ >
128
+ {tooltipData}
129
+ </Tooltip.Tooltip>
130
+ </Fade>
131
+ </Box>
132
+ );
133
+ };
134
+
135
+ export default ResponsiveGauge;
@@ -0,0 +1,87 @@
1
+ import { scaleOrdinal } from '@visx/scale';
2
+ import { Pie } from '@visx/shape';
3
+ import { pluck } from 'ramda';
4
+
5
+ import { useTheme } from '@mui/material';
6
+
7
+ import AnimatedPie from './AnimatedPie';
8
+ import { GaugeProps, ThresholdType } from './models';
9
+
10
+ export const thresholdThickness = 12;
11
+
12
+ const Thresholds = ({
13
+ thresholds,
14
+ radius,
15
+ adaptedMaxValue,
16
+ showTooltip,
17
+ hideTooltip,
18
+ metric,
19
+ thresholdTooltipLabels,
20
+ disabledThresholds
21
+ }: Omit<GaugeProps, 'width' | 'height'>): JSX.Element => {
22
+ const theme = useTheme();
23
+
24
+ const namedThresholds = [
25
+ {
26
+ name: ThresholdType.Success,
27
+ value: thresholds[0]
28
+ },
29
+ {
30
+ name: ThresholdType.Warning,
31
+ value: thresholds[1]
32
+ },
33
+ {
34
+ name: ThresholdType.Error,
35
+ value: adaptedMaxValue
36
+ }
37
+ ];
38
+
39
+ const adaptedThresholds = namedThresholds.map(({ name, value }, index) => {
40
+ return {
41
+ name,
42
+ value: value - (namedThresholds[index - 1]?.value || 0)
43
+ };
44
+ });
45
+
46
+ const getThresholdColor = scaleOrdinal({
47
+ domain: pluck('name', adaptedThresholds),
48
+ range: disabledThresholds
49
+ ? [
50
+ theme.palette.success.main,
51
+ theme.palette.success.main,
52
+ theme.palette.success.main
53
+ ]
54
+ : [
55
+ theme.palette.success.main,
56
+ theme.palette.warning.main,
57
+ theme.palette.error.main
58
+ ]
59
+ });
60
+
61
+ return (
62
+ <Pie
63
+ data={adaptedThresholds}
64
+ endAngle={-Math.PI / 2}
65
+ innerRadius={radius - thresholdThickness}
66
+ outerRadius={radius}
67
+ pieSortValues={() => -1}
68
+ pieValue={(d) => d.value}
69
+ startAngle={Math.PI / 2}
70
+ >
71
+ {(pie) => (
72
+ <AnimatedPie<{ name: ThresholdType; value: number }>
73
+ {...pie}
74
+ animate
75
+ getColor={(arc) => getThresholdColor(arc.data.name)}
76
+ getKey={(arc) => `${arc.data.name}_${arc.data.value}`}
77
+ hideTooltip={hideTooltip}
78
+ metric={metric}
79
+ showTooltip={showTooltip}
80
+ thresholdTooltipLabels={thresholdTooltipLabels}
81
+ />
82
+ )}
83
+ </Pie>
84
+ );
85
+ };
86
+
87
+ export default Thresholds;
@@ -0,0 +1 @@
1
+ export { Gauge } from './Gauge';
@@ -0,0 +1,20 @@
1
+ import { Metric } from '../common/timeSeries/models';
2
+
3
+ export interface GaugeProps {
4
+ adaptedMaxValue: number;
5
+ disabledThresholds?: boolean;
6
+ height: number;
7
+ hideTooltip: () => void;
8
+ metric: Metric;
9
+ radius: number;
10
+ showTooltip: (args) => void;
11
+ thresholdTooltipLabels: Array<string>;
12
+ thresholds: Array<number>;
13
+ width: number;
14
+ }
15
+
16
+ export enum ThresholdType {
17
+ Warning,
18
+ Error,
19
+ Success
20
+ }
@@ -6,7 +6,7 @@ import { useLocaleDateTimeFormat } from '@centreon/ui';
6
6
 
7
7
  import { getXAxisTickFormat } from '../../helpers';
8
8
  import { GraphInterval } from '../../models';
9
- import { getUnits } from '../../timeSeries';
9
+ import { getUnits } from '../../../common/timeSeries';
10
10
 
11
11
  import UnitLabel from './UnitLabel';
12
12
  import { Data } from './models';
@@ -1,4 +1,4 @@
1
- import { Line, TimeValue } from '../../timeSeries/models';
1
+ import { Line, TimeValue } from '../../../common/timeSeries/models';
2
2
 
3
3
  export interface LabelProps {
4
4
  [x: string]: unknown;
@@ -3,7 +3,7 @@ import { Axis } from '@visx/visx';
3
3
 
4
4
  import { useTheme } from '@mui/material';
5
5
 
6
- import { formatMetricValue, getUnits } from '../../timeSeries';
6
+ import { formatMetricValue, getUnits } from '../../../common/timeSeries';
7
7
  import { commonTickLabelProps } from '../../common';
8
8
 
9
9
  import { Data, LabelProps } from './models';
@@ -4,8 +4,8 @@ import { Shape } from '@visx/visx';
4
4
  import { ScaleLinear, ScaleTime } from 'd3-scale';
5
5
  import { equals, isNil, prop } from 'ramda';
6
6
 
7
- import { getTime } from '../../../timeSeries';
8
- import { TimeValue } from '../../../timeSeries/models';
7
+ import { getTime } from '../../../../common/timeSeries';
8
+ import { TimeValue } from '../../../../common/timeSeries/models';
9
9
  import { getFillColor } from '../../../common';
10
10
  import { CurveType } from '../models';
11
11
 
@@ -1,7 +1,7 @@
1
1
  import { difference } from 'ramda';
2
2
 
3
- import { Line } from '../../../timeSeries/models';
4
- import { getSortedStackedLines } from '../../../timeSeries';
3
+ import { Line } from '../../../../common/timeSeries/models';
4
+ import { getSortedStackedLines } from '../../../../common/timeSeries';
5
5
 
6
6
  interface RegularLines {
7
7
  regularLines: Array<Line>;
@@ -5,8 +5,8 @@ import { all, isNil, map, not, nth, path, pipe, prop } from 'ramda';
5
5
  import StackedAnchorPoint from '../../../InteractiveComponents/AnchorPoint/StackedAnchorPoint';
6
6
  import { StackValue } from '../../../InteractiveComponents/AnchorPoint/models';
7
7
  import { getFillColor } from '../../../common';
8
- import { getTime } from '../../../timeSeries';
9
- import { Line, TimeValue } from '../../../timeSeries/models';
8
+ import { getTime } from '../../../../common/timeSeries';
9
+ import { Line, TimeValue } from '../../../../common/timeSeries/models';
10
10
  import { CurveType } from '../models';
11
11
 
12
12
  interface Props {
@@ -2,7 +2,7 @@ import {
2
2
  getInvertedStackedLines,
3
3
  getNotInvertedStackedLines,
4
4
  getTimeSeriesForLines
5
- } from '../../../timeSeries';
5
+ } from '../../../../common/timeSeries';
6
6
  import { LinesData } from '../models';
7
7
 
8
8
  interface StackedLines {
@@ -1,6 +1,6 @@
1
1
  import { Threshold } from '@visx/threshold';
2
2
 
3
- import { TimeValue } from '../../../timeSeries/models';
3
+ import { TimeValue } from '../../../../common/timeSeries/models';
4
4
  import { CurveType } from '../models';
5
5
 
6
6
  interface Props {
@@ -4,15 +4,16 @@ import { ScaleLinear } from 'd3-scale';
4
4
  import { useTheme } from '@mui/material/styles';
5
5
 
6
6
  import { adjustGraphData } from '../../../helpers/index';
7
- import { GraphData, PatternOrientation } from '../../../models';
7
+ import { PatternOrientation } from '../../../models';
8
8
  import { CurveType } from '../models';
9
+ import { LineChartData } from '../../../../common/models';
9
10
 
10
11
  import BasicThreshold from './BasicThreshold';
11
12
  import useScaleThreshold from './useScaleThreshold';
12
13
 
13
14
  interface Props {
14
15
  curve: CurveType;
15
- data: GraphData;
16
+ data: LineChartData;
16
17
  graphHeight: number;
17
18
  id: string;
18
19
  leftScale: ScaleLinear<number, number>;
@@ -3,7 +3,7 @@ import { LinePath } from '@visx/shape';
3
3
 
4
4
  import { useTheme } from '@mui/material/styles';
5
5
 
6
- import { TimeValue } from '../../../timeSeries/models';
6
+ import { TimeValue } from '../../../../common/timeSeries/models';
7
7
  import { CurveType } from '../models';
8
8
 
9
9
  import BasicThreshold from './BasicThreshold';
@@ -6,7 +6,7 @@ import {
6
6
  ThresholdType,
7
7
  VariationThreshold
8
8
  } from '../../../models';
9
- import { TimeValue } from '../../../timeSeries/models';
9
+ import { TimeValue } from '../../../../common/timeSeries/models';
10
10
  import { CurveType } from '../models';
11
11
 
12
12
  import BasicThreshold from './BasicThreshold';
@@ -2,7 +2,7 @@ import { ScaleLinear } from 'd3-scale';
2
2
  import { equals, reject } from 'ramda';
3
3
 
4
4
  import { GlobalAreaLines, ThresholdType } from '../../../models';
5
- import { Line, TimeValue } from '../../../timeSeries/models';
5
+ import { Line, TimeValue } from '../../../../common/timeSeries/models';
6
6
 
7
7
  export interface Data {
8
8
  lineColor: string;
@@ -1,8 +1,8 @@
1
1
  import { equals, isNil, prop } from 'ramda';
2
2
 
3
3
  import { ThresholdType, VariationThreshold } from '../../../models';
4
- import { TimeValue } from '../../../timeSeries/models';
5
- import { getTime, getUnits, getYScale } from '../../../timeSeries';
4
+ import { TimeValue } from '../../../../common/timeSeries/models';
5
+ import { getTime, getUnits, getYScale } from '../../../../common/timeSeries';
6
6
  import { displayArea } from '../../../helpers/index';
7
7
 
8
8
  import { envelopeVariationFormula } from './helpers';