@centreon/ui 24.7.10 → 24.7.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.7.
|
|
3
|
+
"version": "24.7.11",
|
|
4
4
|
"description": "Centreon UI Components",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"update:deps": "pnpx npm-check-updates -i --format group",
|
|
@@ -106,8 +106,10 @@
|
|
|
106
106
|
"vite-plugin-svgr": "^4.2.0",
|
|
107
107
|
"vite-plugin-turbosnap": "^1.0.3"
|
|
108
108
|
},
|
|
109
|
+
"peerDependencies": {
|
|
110
|
+
"@centreon/ui-context": "file:../ui-context"
|
|
111
|
+
},
|
|
109
112
|
"dependencies": {
|
|
110
|
-
"@centreon/ui-context": "file:../ui-context",
|
|
111
113
|
"@lexical/html": "^0.16.1",
|
|
112
114
|
"@lexical/link": "^0.16.1",
|
|
113
115
|
"@lexical/list": "^0.16.1",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { lt } from 'ramda';
|
|
2
2
|
import { makeStyles } from 'tss-react/mui';
|
|
3
3
|
|
|
4
|
-
export const usePieStyles = makeStyles<{ svgSize: number }>()(
|
|
5
|
-
(theme, { svgSize }) => ({
|
|
4
|
+
export const usePieStyles = makeStyles<{ reverse: boolean; svgSize: number }>()(
|
|
5
|
+
(theme, { reverse, svgSize }) => ({
|
|
6
6
|
container: {
|
|
7
7
|
alignItems: 'center',
|
|
8
8
|
display: 'flex',
|
|
@@ -25,7 +25,7 @@ export const usePieStyles = makeStyles<{ svgSize: number }>()(
|
|
|
25
25
|
svgWrapper: {
|
|
26
26
|
alignItems: 'center',
|
|
27
27
|
display: 'flex',
|
|
28
|
-
flexDirection: 'column',
|
|
28
|
+
flexDirection: reverse ? 'column-reverse' : 'column',
|
|
29
29
|
gap: theme.spacing(1),
|
|
30
30
|
justifyContent: 'center'
|
|
31
31
|
},
|
|
@@ -18,7 +18,7 @@ import { PieProps } from './models';
|
|
|
18
18
|
import { usePieStyles } from './PieChart.styles';
|
|
19
19
|
import { useResponsivePie } from './useResponsivePie';
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const DefaultLegend = ({ scale, direction }: LegendProps): JSX.Element => (
|
|
22
22
|
<LegendComponent direction={direction} scale={scale} />
|
|
23
23
|
);
|
|
24
24
|
|
|
@@ -42,19 +42,25 @@ const getTooltipPlacement = ({ radianX, radianY }): Placement => {
|
|
|
42
42
|
|
|
43
43
|
const ResponsivePie = ({
|
|
44
44
|
title,
|
|
45
|
+
titlePosition,
|
|
46
|
+
displayTitle = true,
|
|
45
47
|
variant = 'pie',
|
|
46
48
|
width,
|
|
47
49
|
height,
|
|
48
50
|
data,
|
|
49
51
|
unit = 'number',
|
|
50
|
-
Legend =
|
|
52
|
+
Legend = DefaultLegend,
|
|
51
53
|
displayLegend = true,
|
|
54
|
+
displayTotal = true,
|
|
52
55
|
innerRadius: defaultInnerRadius = 40,
|
|
56
|
+
innerRadiusNoLimit = false,
|
|
53
57
|
onArcClick,
|
|
58
|
+
padAngle = 0,
|
|
54
59
|
displayValues,
|
|
55
60
|
TooltipContent,
|
|
56
61
|
legendDirection = 'column',
|
|
57
|
-
tooltipProps = {}
|
|
62
|
+
tooltipProps = {},
|
|
63
|
+
opacity = 1
|
|
58
64
|
}: PieProps & { height: number; width: number }): JSX.Element => {
|
|
59
65
|
const { t } = useTranslation();
|
|
60
66
|
const theme = useTheme();
|
|
@@ -74,6 +80,7 @@ const ResponsivePie = ({
|
|
|
74
80
|
data,
|
|
75
81
|
defaultInnerRadius,
|
|
76
82
|
height,
|
|
83
|
+
innerRadiusNoLimit,
|
|
77
84
|
legendRef,
|
|
78
85
|
titleRef,
|
|
79
86
|
unit,
|
|
@@ -85,7 +92,10 @@ const ResponsivePie = ({
|
|
|
85
92
|
const isSmall = lt(width, 130);
|
|
86
93
|
const mustDisplayLegend = isTooSmallForLegend ? false : displayLegend;
|
|
87
94
|
|
|
88
|
-
const { classes } = usePieStyles({
|
|
95
|
+
const { classes } = usePieStyles({
|
|
96
|
+
reverse: equals(titlePosition, 'bottom'),
|
|
97
|
+
svgSize
|
|
98
|
+
});
|
|
89
99
|
|
|
90
100
|
return (
|
|
91
101
|
<div
|
|
@@ -100,11 +110,16 @@ const ResponsivePie = ({
|
|
|
100
110
|
minHeight: equals(variant, 'donut') && isSmall ? 'auto' : height
|
|
101
111
|
}}
|
|
102
112
|
>
|
|
103
|
-
{(equals(variant, 'pie') ||
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
113
|
+
{(equals(variant, 'pie') ||
|
|
114
|
+
isSmall ||
|
|
115
|
+
(equals(variant, 'donut') && equals(titlePosition, 'bottom'))) &&
|
|
116
|
+
title &&
|
|
117
|
+
displayTitle && (
|
|
118
|
+
<div className={classes.title} data-testid="Title" ref={titleRef}>
|
|
119
|
+
{`${displayTotal ? numeral(total).format('0a').toUpperCase() : ''} `}
|
|
120
|
+
{t(title)}
|
|
121
|
+
</div>
|
|
122
|
+
)}
|
|
108
123
|
<div
|
|
109
124
|
className={classes.svgContainer}
|
|
110
125
|
data-testid="pieChart"
|
|
@@ -123,9 +138,14 @@ const ResponsivePie = ({
|
|
|
123
138
|
cornerRadius={4}
|
|
124
139
|
data={data}
|
|
125
140
|
innerRadius={() => {
|
|
126
|
-
|
|
141
|
+
const iRadius = innerRadiusNoLimit
|
|
142
|
+
? innerRadius
|
|
143
|
+
: half - innerRadius;
|
|
144
|
+
|
|
145
|
+
return equals(variant, 'pie') ? 0 : iRadius;
|
|
127
146
|
}}
|
|
128
147
|
outerRadius={half}
|
|
148
|
+
padAngle={padAngle}
|
|
129
149
|
pieValue={(items) => items.value}
|
|
130
150
|
>
|
|
131
151
|
{(pie) => {
|
|
@@ -187,6 +207,7 @@ const ResponsivePie = ({
|
|
|
187
207
|
data-testid="value"
|
|
188
208
|
dy=".33em"
|
|
189
209
|
fill="#000"
|
|
210
|
+
fillOpacity={opacity}
|
|
190
211
|
fontSize={12}
|
|
191
212
|
fontWeight={600}
|
|
192
213
|
pointerEvents="none"
|
|
@@ -207,27 +228,31 @@ const ResponsivePie = ({
|
|
|
207
228
|
});
|
|
208
229
|
}}
|
|
209
230
|
</Pie>
|
|
210
|
-
{equals(variant, 'donut') &&
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
+
{equals(variant, 'donut') &&
|
|
232
|
+
!isSmall &&
|
|
233
|
+
title &&
|
|
234
|
+
displayTitle &&
|
|
235
|
+
!equals(titlePosition, 'bottom') && (
|
|
236
|
+
<>
|
|
237
|
+
<Text
|
|
238
|
+
className={classes.title}
|
|
239
|
+
dy={lt(svgSize, 150) ? -10 : -15}
|
|
240
|
+
fill={theme.palette.text.primary}
|
|
241
|
+
textAnchor="middle"
|
|
242
|
+
>
|
|
243
|
+
{numeral(total).format('0a').toUpperCase()}
|
|
244
|
+
</Text>
|
|
245
|
+
<Text
|
|
246
|
+
className={classes.title}
|
|
247
|
+
data-testid="Title"
|
|
248
|
+
dy={lt(svgSize, 150) ? 10 : 15}
|
|
249
|
+
fill={theme.palette.text.primary}
|
|
250
|
+
textAnchor="middle"
|
|
251
|
+
>
|
|
252
|
+
{t(title)}
|
|
253
|
+
</Text>
|
|
254
|
+
</>
|
|
255
|
+
)}
|
|
231
256
|
</Group>
|
|
232
257
|
</svg>
|
|
233
258
|
</div>
|
|
@@ -9,11 +9,17 @@ export interface PieProps {
|
|
|
9
9
|
TooltipContent?: (arcData) => JSX.Element | boolean | null;
|
|
10
10
|
data: Array<ArcType>;
|
|
11
11
|
displayLegend?: boolean;
|
|
12
|
+
displayTitle?: boolean;
|
|
13
|
+
displayTotal?: boolean;
|
|
12
14
|
displayValues?: boolean;
|
|
13
15
|
innerRadius?: number;
|
|
16
|
+
innerRadiusNoLimit?: boolean;
|
|
14
17
|
legendDirection?: 'row' | 'column';
|
|
15
|
-
onArcClick?: (
|
|
18
|
+
onArcClick?: (arcData) => void;
|
|
19
|
+
opacity: number;
|
|
20
|
+
padAngle?: number;
|
|
16
21
|
title?: string;
|
|
22
|
+
titlePosition?: 'default' | 'bottom';
|
|
17
23
|
tooltipProps?: object;
|
|
18
24
|
unit?: 'percentage' | 'number';
|
|
19
25
|
variant?: 'pie' | 'donut';
|
|
@@ -9,6 +9,7 @@ interface ResponsivePieProps {
|
|
|
9
9
|
data: Array<ArcType>;
|
|
10
10
|
defaultInnerRadius: number;
|
|
11
11
|
height: number;
|
|
12
|
+
innerRadiusNoLimit: boolean;
|
|
12
13
|
legendRef;
|
|
13
14
|
titleRef;
|
|
14
15
|
unit: 'percentage' | 'number';
|
|
@@ -31,7 +32,8 @@ export const useResponsivePie = ({
|
|
|
31
32
|
width,
|
|
32
33
|
data,
|
|
33
34
|
unit,
|
|
34
|
-
defaultInnerRadius
|
|
35
|
+
defaultInnerRadius,
|
|
36
|
+
innerRadiusNoLimit
|
|
35
37
|
}: ResponsivePieProps): ResponsivePieState => {
|
|
36
38
|
const heightOfTitle = titleRef.current?.offsetHeight || 0;
|
|
37
39
|
const widthOfLegend = legendRef.current?.offsetWidth || 0;
|
|
@@ -52,7 +54,11 @@ export const useResponsivePie = ({
|
|
|
52
54
|
|
|
53
55
|
const total = Math.floor(data.reduce((acc, { value }) => acc + value, 0));
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
let innerRadius = Math.min(defaultInnerRadius, svgSize / 5);
|
|
58
|
+
|
|
59
|
+
if (innerRadiusNoLimit) {
|
|
60
|
+
innerRadius = half * defaultInnerRadius * 0.01;
|
|
61
|
+
}
|
|
56
62
|
|
|
57
63
|
const legendScale = {
|
|
58
64
|
domain: data.map(({ value }) => getValueByUnit({ total, unit, value })),
|