@redsift/charts 11.5.0 → 11.6.0-alpha.0
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/_internal/Arc.js +2 -0
- package/_internal/Arc.js.map +1 -0
- package/_internal/Arc2.js +117 -0
- package/_internal/Arc2.js.map +1 -0
- package/_internal/Arcs.js +2 -0
- package/_internal/Arcs.js.map +1 -0
- package/_internal/Arcs2.js +94 -0
- package/_internal/Arcs2.js.map +1 -0
- package/_internal/Axis.js +2 -0
- package/_internal/Axis.js.map +1 -0
- package/_internal/Axis2.js +388 -0
- package/_internal/Axis2.js.map +1 -0
- package/_internal/Bar.js +2 -0
- package/_internal/Bar.js.map +1 -0
- package/_internal/Bar2.js +170 -0
- package/_internal/Bar2.js.map +1 -0
- package/_internal/BarChart.js +2 -0
- package/_internal/BarChart.js.map +1 -0
- package/_internal/BarChart2.js +1419 -0
- package/_internal/BarChart2.js.map +1 -0
- package/_internal/ChartContainer.js +2 -0
- package/_internal/ChartContainer.js.map +1 -0
- package/_internal/ChartContainer2.js +266 -0
- package/_internal/ChartContainer2.js.map +1 -0
- package/_internal/DataPoint.js +2 -0
- package/_internal/DataPoint.js.map +1 -0
- package/_internal/DataPoint2.js +110 -0
- package/_internal/DataPoint2.js.map +1 -0
- package/_internal/Dot.js +2 -0
- package/_internal/Dot.js.map +1 -0
- package/_internal/Dot2.js +110 -0
- package/_internal/Dot2.js.map +1 -0
- package/_internal/Legend.js +2 -0
- package/_internal/Legend.js.map +1 -0
- package/_internal/Legend3.js +84 -0
- package/_internal/Legend3.js.map +1 -0
- package/_internal/LegendItem.js +2 -0
- package/_internal/LegendItem.js.map +1 -0
- package/_internal/LegendItem2.js +153 -0
- package/_internal/LegendItem2.js.map +1 -0
- package/_internal/Line.js +2 -0
- package/_internal/Line.js.map +1 -0
- package/_internal/Line2.js +59 -0
- package/_internal/Line2.js.map +1 -0
- package/_internal/LineChart.js +2 -0
- package/_internal/LineChart.js.map +1 -0
- package/_internal/LineChart2.js +669 -0
- package/_internal/LineChart2.js.map +1 -0
- package/_internal/PieChart.js +2 -0
- package/_internal/PieChart.js.map +1 -0
- package/_internal/PieChart2.js +605 -0
- package/_internal/PieChart2.js.map +1 -0
- package/_internal/ScatterPlot.js +2 -0
- package/_internal/ScatterPlot.js.map +1 -0
- package/_internal/ScatterPlot2.js +744 -0
- package/_internal/ScatterPlot2.js.map +1 -0
- package/_internal/_rollupPluginBabelHelpers.js +93 -0
- package/_internal/_rollupPluginBabelHelpers.js.map +1 -0
- package/_internal/config.js +13 -0
- package/_internal/config.js.map +1 -0
- package/_internal/legend2.js +21 -0
- package/_internal/legend2.js.map +1 -0
- package/_internal/scheme.js +47 -0
- package/_internal/scheme.js.map +1 -0
- package/_internal/theme.js +79 -0
- package/_internal/theme.js.map +1 -0
- package/_internal/useFormatCategoricalData.js +56 -0
- package/_internal/useFormatCategoricalData.js.map +1 -0
- package/index.js +17 -5118
- package/index.js.map +1 -1
- package/index2.js +16 -0
- package/index2.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
import { _ as _objectWithoutProperties, a as _extends, b as _objectSpread2 } from './_rollupPluginBabelHelpers.js';
|
|
2
|
+
import React__default, { forwardRef, useRef, useEffect } from 'react';
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
import { Theme, useTheme, useMessageFormatter, useId } from '@redsift/design-system';
|
|
5
|
+
import { L as LegendVariant, T as TooltipVariant } from './legend2.js';
|
|
6
|
+
import { C as ChartSize, m as mergeLegends, g as getSortingMethod, a as ColorTheme } from './theme.js';
|
|
7
|
+
import styled, { css } from 'styled-components';
|
|
8
|
+
import { C as ChartContainer } from './ChartContainer2.js';
|
|
9
|
+
import { arc, pie, sum } from 'd3';
|
|
10
|
+
import { e as empty } from './scheme.js';
|
|
11
|
+
import { A as Arcs } from './Arcs2.js';
|
|
12
|
+
import { u as useFormatCategoricalData } from './useFormatCategoricalData.js';
|
|
13
|
+
import { L as Legend } from './Legend3.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Component variant.
|
|
17
|
+
*/
|
|
18
|
+
const PieChartVariant = {
|
|
19
|
+
plain: 'plain',
|
|
20
|
+
spaced: 'spaced',
|
|
21
|
+
donut: 'donut',
|
|
22
|
+
spacedDonut: 'spacedDonut'
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Component's labels variant.
|
|
26
|
+
*/
|
|
27
|
+
const PieChartLegendVariant = {
|
|
28
|
+
none: 'none',
|
|
29
|
+
internal: 'internal',
|
|
30
|
+
externalLabel: 'externalLabel',
|
|
31
|
+
externalLabelValue: 'externalLabelValue',
|
|
32
|
+
externalLabelPercent: 'externalLabelPercent',
|
|
33
|
+
custom: 'custom'
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Component props.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Component style.
|
|
42
|
+
*/
|
|
43
|
+
const StyledPieChart = styled(ChartContainer)`
|
|
44
|
+
.redsift-piechart__chart-wrapper {
|
|
45
|
+
position: relative;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const StyledPieChartCenterText = styled.div`
|
|
49
|
+
position: absolute;
|
|
50
|
+
top: 0;
|
|
51
|
+
left: 0;
|
|
52
|
+
height: 100%;
|
|
53
|
+
width: 100%;
|
|
54
|
+
display: flex;
|
|
55
|
+
flex-direction: column;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
align-items: center;
|
|
58
|
+
pointer-events: none;
|
|
59
|
+
|
|
60
|
+
> * {
|
|
61
|
+
max-width: ${_ref => {
|
|
62
|
+
let {
|
|
63
|
+
$maxWidth
|
|
64
|
+
} = _ref;
|
|
65
|
+
return $maxWidth;
|
|
66
|
+
}}px;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
> b {
|
|
70
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
71
|
+
color: ${_ref2 => {
|
|
72
|
+
let {
|
|
73
|
+
$theme
|
|
74
|
+
} = _ref2;
|
|
75
|
+
return `var(--redsift-color-${$theme}-components-text-primary)`;
|
|
76
|
+
}};
|
|
77
|
+
font-weight: var(--redsift-typography-font-weight-medium);
|
|
78
|
+
font-size: ${_ref3 => {
|
|
79
|
+
let {
|
|
80
|
+
$textSize
|
|
81
|
+
} = _ref3;
|
|
82
|
+
return $textSize;
|
|
83
|
+
}}px;
|
|
84
|
+
line-height: ${_ref4 => {
|
|
85
|
+
let {
|
|
86
|
+
$textSize
|
|
87
|
+
} = _ref4;
|
|
88
|
+
return $textSize;
|
|
89
|
+
}}px;
|
|
90
|
+
|
|
91
|
+
&:nth-child(2) {
|
|
92
|
+
font-weight: normal;
|
|
93
|
+
margin-top: 8px;
|
|
94
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
95
|
+
font-size: ${_ref5 => {
|
|
96
|
+
let {
|
|
97
|
+
$smallTextSize
|
|
98
|
+
} = _ref5;
|
|
99
|
+
return $smallTextSize;
|
|
100
|
+
}}px;
|
|
101
|
+
line-height: ${_ref6 => {
|
|
102
|
+
let {
|
|
103
|
+
$smallTextSize
|
|
104
|
+
} = _ref6;
|
|
105
|
+
return $smallTextSize;
|
|
106
|
+
}}px;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
> span {
|
|
110
|
+
color: ${_ref7 => {
|
|
111
|
+
let {
|
|
112
|
+
$theme
|
|
113
|
+
} = _ref7;
|
|
114
|
+
return `var(--redsift-color-${$theme}-components-text-primary)`;
|
|
115
|
+
}};
|
|
116
|
+
font-size: ${_ref8 => {
|
|
117
|
+
let {
|
|
118
|
+
$textSize
|
|
119
|
+
} = _ref8;
|
|
120
|
+
return $textSize;
|
|
121
|
+
}}px;
|
|
122
|
+
line-height: ${_ref9 => {
|
|
123
|
+
let {
|
|
124
|
+
$textSize
|
|
125
|
+
} = _ref9;
|
|
126
|
+
return $textSize;
|
|
127
|
+
}}px;
|
|
128
|
+
&:nth-child(3) {
|
|
129
|
+
margin-top: 4px;
|
|
130
|
+
font-size: ${_ref10 => {
|
|
131
|
+
let {
|
|
132
|
+
$smallTextSize
|
|
133
|
+
} = _ref10;
|
|
134
|
+
return $smallTextSize;
|
|
135
|
+
}}px;
|
|
136
|
+
line-height: ${_ref11 => {
|
|
137
|
+
let {
|
|
138
|
+
$smallTextSize
|
|
139
|
+
} = _ref11;
|
|
140
|
+
return $smallTextSize;
|
|
141
|
+
}}px;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
> b + span {
|
|
145
|
+
font-size: var(--redsift-typography-body-font-size);
|
|
146
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
147
|
+
line-height: var(--redsift-typography-badge-line-height);
|
|
148
|
+
color: ${_ref12 => {
|
|
149
|
+
let {
|
|
150
|
+
$theme
|
|
151
|
+
} = _ref12;
|
|
152
|
+
return $theme === Theme.light ? 'rgba(0, 0, 0, 0.6)' : 'rgba(255, 255, 255, 0.6)';
|
|
153
|
+
}};
|
|
154
|
+
text-align: center;
|
|
155
|
+
}
|
|
156
|
+
`;
|
|
157
|
+
const StyledPieChartEmptyText = styled.div`
|
|
158
|
+
position: absolute;
|
|
159
|
+
top: 0;
|
|
160
|
+
left: 0;
|
|
161
|
+
height: 100%;
|
|
162
|
+
width: 100%;
|
|
163
|
+
display: flex;
|
|
164
|
+
flex-direction: column;
|
|
165
|
+
justify-content: center;
|
|
166
|
+
align-items: center;
|
|
167
|
+
pointer-events: none;
|
|
168
|
+
|
|
169
|
+
> * {
|
|
170
|
+
max-width: ${_ref13 => {
|
|
171
|
+
let {
|
|
172
|
+
$maxWidth
|
|
173
|
+
} = _ref13;
|
|
174
|
+
return $maxWidth;
|
|
175
|
+
}}px;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
> span {
|
|
179
|
+
font-family: var(--redsift-typography-font-family-poppins);
|
|
180
|
+
color: ${_ref14 => {
|
|
181
|
+
let {
|
|
182
|
+
$isDonut,
|
|
183
|
+
$theme
|
|
184
|
+
} = _ref14;
|
|
185
|
+
return $isDonut ? css`var(--redsift-color-neutral-mid-grey)` : css`var(--redsift-color-${$theme}-components-text-primary)`;
|
|
186
|
+
}};
|
|
187
|
+
font-size: ${_ref15 => {
|
|
188
|
+
let {
|
|
189
|
+
$textSize
|
|
190
|
+
} = _ref15;
|
|
191
|
+
return $textSize;
|
|
192
|
+
}}px;
|
|
193
|
+
line-height: ${_ref16 => {
|
|
194
|
+
let {
|
|
195
|
+
$textSize
|
|
196
|
+
} = _ref16;
|
|
197
|
+
return $textSize;
|
|
198
|
+
}}px;
|
|
199
|
+
}
|
|
200
|
+
`;
|
|
201
|
+
|
|
202
|
+
const _excluded$3 = ["className"];
|
|
203
|
+
const LoadingPieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
204
|
+
const {
|
|
205
|
+
className
|
|
206
|
+
} = props,
|
|
207
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$3);
|
|
208
|
+
return /*#__PURE__*/React__default.createElement(StyledPieChart, _extends({}, forwardedProps, {
|
|
209
|
+
className: className,
|
|
210
|
+
ref: ref
|
|
211
|
+
}), "Loading...");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const sizeToDimension = (size, isHalf) => {
|
|
215
|
+
if (typeof size !== 'string') {
|
|
216
|
+
return size;
|
|
217
|
+
}
|
|
218
|
+
switch (size) {
|
|
219
|
+
case ChartSize.small:
|
|
220
|
+
return {
|
|
221
|
+
width: 200,
|
|
222
|
+
height: 200 * (isHalf ? 0.5 : 1),
|
|
223
|
+
smallFontSize: 13,
|
|
224
|
+
fontSize: 30,
|
|
225
|
+
innerRadius: 55
|
|
226
|
+
};
|
|
227
|
+
case ChartSize.large:
|
|
228
|
+
return {
|
|
229
|
+
width: 300,
|
|
230
|
+
height: 300 * (isHalf ? 0.5 : 1),
|
|
231
|
+
smallFontSize: 18,
|
|
232
|
+
fontSize: 38,
|
|
233
|
+
innerRadius: 80
|
|
234
|
+
};
|
|
235
|
+
case ChartSize.medium:
|
|
236
|
+
default:
|
|
237
|
+
return {
|
|
238
|
+
width: 240,
|
|
239
|
+
height: 240 * (isHalf ? 0.5 : 1),
|
|
240
|
+
smallFontSize: 14,
|
|
241
|
+
fontSize: 34,
|
|
242
|
+
innerRadius: 65
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const _excluded$2 = ["className", "emptyComponent", "localeText", "size", "variant"];
|
|
248
|
+
const EmptyPieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
249
|
+
const {
|
|
250
|
+
className,
|
|
251
|
+
emptyComponent,
|
|
252
|
+
localeText,
|
|
253
|
+
size,
|
|
254
|
+
variant
|
|
255
|
+
} = props,
|
|
256
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$2);
|
|
257
|
+
const theme = useTheme();
|
|
258
|
+
const isDonut = variant === PieChartVariant.donut || variant === PieChartVariant.spacedDonut;
|
|
259
|
+
const {
|
|
260
|
+
width,
|
|
261
|
+
height,
|
|
262
|
+
fontSize,
|
|
263
|
+
innerRadius
|
|
264
|
+
} = sizeToDimension(size);
|
|
265
|
+
const externalRadiusPadding = 8;
|
|
266
|
+
const createArc = arc().innerRadius(isDonut ? innerRadius : 0).outerRadius(width / 2 - externalRadiusPadding);
|
|
267
|
+
return /*#__PURE__*/React__default.createElement(StyledPieChart, _extends({}, forwardedProps, {
|
|
268
|
+
className: className,
|
|
269
|
+
ref: ref
|
|
270
|
+
}), emptyComponent !== null && emptyComponent !== void 0 ? emptyComponent : /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(StyledPieChartEmptyText, {
|
|
271
|
+
$maxWidth: innerRadius * 2,
|
|
272
|
+
$textSize: fontSize / 2,
|
|
273
|
+
$isDonut: isDonut,
|
|
274
|
+
$theme: theme
|
|
275
|
+
}, /*#__PURE__*/React__default.createElement("span", null, localeText === null || localeText === void 0 ? void 0 : localeText.emptyChartText)), /*#__PURE__*/React__default.createElement("svg", {
|
|
276
|
+
width: width,
|
|
277
|
+
height: height
|
|
278
|
+
}, /*#__PURE__*/React__default.createElement(Arcs, {
|
|
279
|
+
arcs: [{
|
|
280
|
+
createArc,
|
|
281
|
+
previousData: {
|
|
282
|
+
data: {
|
|
283
|
+
key: '',
|
|
284
|
+
value: 0
|
|
285
|
+
},
|
|
286
|
+
startAngle: 0,
|
|
287
|
+
endAngle: 0,
|
|
288
|
+
padAngle: 0,
|
|
289
|
+
value: 0,
|
|
290
|
+
index: 0
|
|
291
|
+
},
|
|
292
|
+
data: {
|
|
293
|
+
data: {
|
|
294
|
+
key: 'No Data',
|
|
295
|
+
value: 0
|
|
296
|
+
},
|
|
297
|
+
index: 0,
|
|
298
|
+
value: 0,
|
|
299
|
+
startAngle: 0,
|
|
300
|
+
endAngle: 2 * Math.PI,
|
|
301
|
+
padAngle: 0
|
|
302
|
+
},
|
|
303
|
+
dataset: [{
|
|
304
|
+
data: {
|
|
305
|
+
key: 'No Data',
|
|
306
|
+
value: 0
|
|
307
|
+
},
|
|
308
|
+
index: 0,
|
|
309
|
+
value: 0,
|
|
310
|
+
startAngle: 0,
|
|
311
|
+
endAngle: 2 * Math.PI,
|
|
312
|
+
padAngle: 0
|
|
313
|
+
}],
|
|
314
|
+
color: empty
|
|
315
|
+
}],
|
|
316
|
+
transform: `translate(${width / 2} ${height / 2})`
|
|
317
|
+
}))));
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
var definition$1 = "Pie Chart with {sliceLength} slices.";
|
|
321
|
+
var enUS = {
|
|
322
|
+
"interactive-chart": "Interactive Line Chart",
|
|
323
|
+
"static-chart": "Static Line Chart",
|
|
324
|
+
definition: definition$1
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
var definition = "Diagramme circulaire contenant {sliceLength} secteurs.";
|
|
328
|
+
var frFR = {
|
|
329
|
+
"interactive-chart": "Diagramme circulaire interactif",
|
|
330
|
+
"static-chart": "Diagramme circulaire statique",
|
|
331
|
+
definition: definition
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
var intlMessages = {
|
|
335
|
+
'en-US': enUS,
|
|
336
|
+
'fr-FR': frFR
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const _excluded$1 = ["caping", "className", "data", "disableAnimations", "getSliceAnchorProps", "id", "isHalf", "isSliceSelected", "labelDecorator", "legendDecorator", "legendVariant", "legendProps", "middleText", "onSliceClick", "others", "size", "sliceProps", "sliceRole", "sortingMethod", "subtext", "text", "colorTheme", "tooltipVariant", "variant"],
|
|
340
|
+
_excluded2 = ["extraLegendItems"];
|
|
341
|
+
const RenderedPieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
342
|
+
const {
|
|
343
|
+
caping,
|
|
344
|
+
className,
|
|
345
|
+
data: propsData,
|
|
346
|
+
disableAnimations,
|
|
347
|
+
getSliceAnchorProps,
|
|
348
|
+
id,
|
|
349
|
+
isHalf,
|
|
350
|
+
isSliceSelected,
|
|
351
|
+
labelDecorator,
|
|
352
|
+
legendDecorator,
|
|
353
|
+
legendVariant,
|
|
354
|
+
legendProps,
|
|
355
|
+
middleText: propsMiddleText,
|
|
356
|
+
onSliceClick,
|
|
357
|
+
others,
|
|
358
|
+
size,
|
|
359
|
+
sliceProps,
|
|
360
|
+
sliceRole,
|
|
361
|
+
sortingMethod,
|
|
362
|
+
subtext: propsSubtext,
|
|
363
|
+
text: propsText,
|
|
364
|
+
colorTheme,
|
|
365
|
+
tooltipVariant,
|
|
366
|
+
variant
|
|
367
|
+
} = props,
|
|
368
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$1);
|
|
369
|
+
const cache = useRef();
|
|
370
|
+
const theme = useTheme();
|
|
371
|
+
const format = useMessageFormatter(intlMessages);
|
|
372
|
+
const isDonut = variant === PieChartVariant.donut || variant === PieChartVariant.spacedDonut;
|
|
373
|
+
const isSpaced = variant === PieChartVariant.spaced || variant === PieChartVariant.spacedDonut;
|
|
374
|
+
const {
|
|
375
|
+
data,
|
|
376
|
+
colorScale
|
|
377
|
+
} = useFormatCategoricalData({
|
|
378
|
+
data: propsData,
|
|
379
|
+
colorTheme: colorTheme,
|
|
380
|
+
sortingMethod: sortingMethod,
|
|
381
|
+
caping,
|
|
382
|
+
others,
|
|
383
|
+
theme
|
|
384
|
+
});
|
|
385
|
+
useEffect(() => {
|
|
386
|
+
cache.current = data;
|
|
387
|
+
});
|
|
388
|
+
const {
|
|
389
|
+
width,
|
|
390
|
+
height,
|
|
391
|
+
smallFontSize,
|
|
392
|
+
fontSize,
|
|
393
|
+
innerRadius
|
|
394
|
+
} = sizeToDimension(size, isHalf);
|
|
395
|
+
const externalRadiusPadding = 8;
|
|
396
|
+
const createPie = pie().value(d => d.value).sort(null).startAngle(isHalf ? Math.PI * -0.5 : 0).endAngle(isHalf ? Math.PI * 0.5 : Math.PI * 2);
|
|
397
|
+
const createArc = arc().innerRadius(isDonut ? innerRadius : 0).outerRadius(width / 2 - externalRadiusPadding);
|
|
398
|
+
const pieData = createPie(data);
|
|
399
|
+
const previousPieData = cache.current ? createPie(cache.current) : undefined;
|
|
400
|
+
const total = sum(data, d => d.value);
|
|
401
|
+
const legendWidth = useRef();
|
|
402
|
+
if (data && !legendWidth.current) {
|
|
403
|
+
legendWidth.current = `${Math.max(...data.map(d => d.key.length + String(d.value).length)) * 8 + 32}px`;
|
|
404
|
+
}
|
|
405
|
+
const text = typeof propsText === 'function' ? propsText(pieData.map(datum => {
|
|
406
|
+
const percent = datum.data.value / total;
|
|
407
|
+
return _objectSpread2(_objectSpread2({}, datum), {}, {
|
|
408
|
+
data: _objectSpread2(_objectSpread2({}, datum.data), {}, {
|
|
409
|
+
percent
|
|
410
|
+
})
|
|
411
|
+
});
|
|
412
|
+
}), total) : propsText;
|
|
413
|
+
const subtext = typeof propsSubtext === 'function' ? propsSubtext(pieData.map(datum => {
|
|
414
|
+
const percent = datum.data.value / total;
|
|
415
|
+
return _objectSpread2(_objectSpread2({}, datum), {}, {
|
|
416
|
+
data: _objectSpread2(_objectSpread2({}, datum.data), {}, {
|
|
417
|
+
percent
|
|
418
|
+
})
|
|
419
|
+
});
|
|
420
|
+
}), total) : propsSubtext;
|
|
421
|
+
const middleText = typeof propsMiddleText === 'function' ? propsMiddleText(pieData.map(datum => {
|
|
422
|
+
const percent = datum.data.value / total;
|
|
423
|
+
return _objectSpread2(_objectSpread2({}, datum), {}, {
|
|
424
|
+
data: _objectSpread2(_objectSpread2({}, datum.data), {}, {
|
|
425
|
+
percent
|
|
426
|
+
})
|
|
427
|
+
});
|
|
428
|
+
}), total) : propsMiddleText;
|
|
429
|
+
const filteredPieData = pieData.filter(datum => datum.data.value);
|
|
430
|
+
const _ref = legendProps || {},
|
|
431
|
+
{
|
|
432
|
+
extraLegendItems
|
|
433
|
+
} = _ref,
|
|
434
|
+
forwardedLegendProps = _objectWithoutProperties(_ref, _excluded2);
|
|
435
|
+
return /*#__PURE__*/React__default.createElement(StyledPieChart, _extends({
|
|
436
|
+
mode: typeof onSliceClick === 'function' || typeof getSliceAnchorProps === 'function' ? 'interactive' : 'static',
|
|
437
|
+
definition: format('definition', {
|
|
438
|
+
sliceLength: filteredPieData.length
|
|
439
|
+
}),
|
|
440
|
+
dataTableRepresentation: {
|
|
441
|
+
header: /*#__PURE__*/React__default.createElement("thead", null, /*#__PURE__*/React__default.createElement("tr", null, /*#__PURE__*/React__default.createElement("th", {
|
|
442
|
+
scope: "col"
|
|
443
|
+
}, "Key"), /*#__PURE__*/React__default.createElement("th", {
|
|
444
|
+
scope: "col"
|
|
445
|
+
}, "Value"))),
|
|
446
|
+
body: /*#__PURE__*/React__default.createElement("tbody", null, filteredPieData.map(datum => /*#__PURE__*/React__default.createElement("tr", {
|
|
447
|
+
key: datum.data.key
|
|
448
|
+
}, /*#__PURE__*/React__default.createElement("th", {
|
|
449
|
+
scope: "row"
|
|
450
|
+
}, datum.data.key), /*#__PURE__*/React__default.createElement("td", null, datum.data.value))))
|
|
451
|
+
}
|
|
452
|
+
}, forwardedProps, {
|
|
453
|
+
className: className,
|
|
454
|
+
id: id,
|
|
455
|
+
ref: ref
|
|
456
|
+
}), /*#__PURE__*/React__default.createElement("div", {
|
|
457
|
+
className: `${PieChart.className}__chart-wrapper`
|
|
458
|
+
}, text ? /*#__PURE__*/React__default.createElement(StyledPieChartCenterText, {
|
|
459
|
+
$maxWidth: innerRadius * 2,
|
|
460
|
+
$textSize: fontSize,
|
|
461
|
+
$smallTextSize: smallFontSize,
|
|
462
|
+
$theme: theme
|
|
463
|
+
}, subtext ? /*#__PURE__*/React__default.createElement("b", null, text) : /*#__PURE__*/React__default.createElement("span", null, text), middleText ? /*#__PURE__*/React__default.createElement("b", null, middleText) : null, /*#__PURE__*/React__default.createElement("span", null, subtext)) : null, /*#__PURE__*/React__default.createElement("svg", {
|
|
464
|
+
width: width,
|
|
465
|
+
height: isHalf ? height + externalRadiusPadding : height,
|
|
466
|
+
"aria-label": typeof onSliceClick === 'function' || typeof getSliceAnchorProps === 'function' ? format('interactive-chart') : format('static-chart'),
|
|
467
|
+
"aria-hidden": "false"
|
|
468
|
+
}, /*#__PURE__*/React__default.createElement(Arcs, {
|
|
469
|
+
arcs: filteredPieData.map((datum, index) => {
|
|
470
|
+
const percent = datum.data.value / total;
|
|
471
|
+
const from = previousPieData ? previousPieData[index] : {
|
|
472
|
+
data: {
|
|
473
|
+
key: '',
|
|
474
|
+
value: 0
|
|
475
|
+
},
|
|
476
|
+
startAngle: isHalf ? Math.PI * -0.5 : 0,
|
|
477
|
+
endAngle: isHalf ? Math.PI * -0.5 : 0,
|
|
478
|
+
padAngle: 0,
|
|
479
|
+
value: 0,
|
|
480
|
+
index: index
|
|
481
|
+
};
|
|
482
|
+
const to = _objectSpread2(_objectSpread2({}, datum), {}, {
|
|
483
|
+
data: _objectSpread2(_objectSpread2({}, datum.data), {}, {
|
|
484
|
+
percent
|
|
485
|
+
})
|
|
486
|
+
});
|
|
487
|
+
return {
|
|
488
|
+
color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(to.data.key),
|
|
489
|
+
createArc,
|
|
490
|
+
previousData: from,
|
|
491
|
+
id: `id${id}__arc-${index}`,
|
|
492
|
+
index,
|
|
493
|
+
isSelected: isSliceSelected(to),
|
|
494
|
+
key: `id${id}__arc-${index}`,
|
|
495
|
+
data: to,
|
|
496
|
+
dataset: pieData,
|
|
497
|
+
anchorProps: getSliceAnchorProps ? getSliceAnchorProps(to) : undefined
|
|
498
|
+
};
|
|
499
|
+
}),
|
|
500
|
+
disableAnimations: disableAnimations,
|
|
501
|
+
hasLabels: legendVariant === PieChartLegendVariant.internal,
|
|
502
|
+
hasStroke: isSpaced,
|
|
503
|
+
labelDecorator: labelDecorator,
|
|
504
|
+
onClick: onSliceClick,
|
|
505
|
+
role: sliceRole,
|
|
506
|
+
sliceProps: sliceProps,
|
|
507
|
+
tooltipVariant: tooltipVariant,
|
|
508
|
+
transform: `translate(${width / 2} ${isHalf ? height : height / 2})`
|
|
509
|
+
}))), legendVariant !== PieChartLegendVariant.none && legendVariant !== PieChartLegendVariant.internal ? /*#__PURE__*/React__default.createElement(Legend, _extends({
|
|
510
|
+
data: (extraLegendItems ? mergeLegends(extraLegendItems, data).sort(getSortingMethod(sortingMethod)) : data).map(d => _objectSpread2(_objectSpread2({}, d), {}, {
|
|
511
|
+
color: colorScale === null || colorScale === void 0 ? void 0 : colorScale(d.key)
|
|
512
|
+
})),
|
|
513
|
+
variant: legendVariant === PieChartLegendVariant.externalLabelValue ? LegendVariant.value : legendVariant === PieChartLegendVariant.externalLabelPercent ? LegendVariant.percent : legendVariant === PieChartLegendVariant.externalLabel ? LegendVariant.label : LegendVariant.custom,
|
|
514
|
+
width: legendWidth.current,
|
|
515
|
+
labelDecorator: labelDecorator ? (datum, props) => labelDecorator(datum, props) : undefined,
|
|
516
|
+
legendDecorator: legendDecorator ? (datum, props) => legendDecorator(datum, props) : undefined
|
|
517
|
+
}, forwardedLegendProps)) : null);
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
const _excluded = ["caping", "chartRef", "className", "colorTheme", "data", "emptyComponent", "id", "isSliceSelected", "labelDecorator", "legendDecorator", "legendVariant", "localeText", "middleText", "onSliceClick", "others", "size", "sliceRole", "sortingMethod", "subtext", "text", "tooltipDecorator", "tooltipVariant", "variant"];
|
|
521
|
+
const COMPONENT_NAME = 'PieChart';
|
|
522
|
+
const CLASSNAME = 'redsift-piechart';
|
|
523
|
+
const PieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
524
|
+
const {
|
|
525
|
+
caping,
|
|
526
|
+
chartRef,
|
|
527
|
+
className,
|
|
528
|
+
colorTheme = ColorTheme.default,
|
|
529
|
+
data: propsData,
|
|
530
|
+
emptyComponent,
|
|
531
|
+
id: propsId,
|
|
532
|
+
isSliceSelected = () => true,
|
|
533
|
+
labelDecorator,
|
|
534
|
+
legendDecorator,
|
|
535
|
+
legendVariant: propsLegendVariant,
|
|
536
|
+
localeText = {
|
|
537
|
+
emptyChartText: 'No Data'
|
|
538
|
+
},
|
|
539
|
+
middleText,
|
|
540
|
+
onSliceClick,
|
|
541
|
+
others = true,
|
|
542
|
+
size = ChartSize.medium,
|
|
543
|
+
sliceRole,
|
|
544
|
+
sortingMethod = 'desc-value',
|
|
545
|
+
subtext,
|
|
546
|
+
text,
|
|
547
|
+
tooltipDecorator,
|
|
548
|
+
tooltipVariant = TooltipVariant.value,
|
|
549
|
+
variant = PieChartVariant.spaced
|
|
550
|
+
} = props,
|
|
551
|
+
forwardedProps = _objectWithoutProperties(props, _excluded);
|
|
552
|
+
const [_id] = useId();
|
|
553
|
+
const id = propsId !== null && propsId !== void 0 ? propsId : _id;
|
|
554
|
+
const legendVariant = propsLegendVariant !== null && propsLegendVariant !== void 0 ? propsLegendVariant : PieChartLegendVariant.none;
|
|
555
|
+
if (propsData === undefined || propsData === null) {
|
|
556
|
+
return /*#__PURE__*/React__default.createElement(LoadingPieChart, _extends({
|
|
557
|
+
id: id
|
|
558
|
+
}, forwardedProps, {
|
|
559
|
+
ref: ref
|
|
560
|
+
}));
|
|
561
|
+
}
|
|
562
|
+
if (propsData.length === 0) {
|
|
563
|
+
return /*#__PURE__*/React__default.createElement(EmptyPieChart, _extends({
|
|
564
|
+
data: propsData,
|
|
565
|
+
emptyComponent: emptyComponent,
|
|
566
|
+
id: id,
|
|
567
|
+
localeText: localeText,
|
|
568
|
+
size: size,
|
|
569
|
+
sortingMethod: sortingMethod,
|
|
570
|
+
variant: variant
|
|
571
|
+
}, forwardedProps, {
|
|
572
|
+
ref: ref
|
|
573
|
+
}));
|
|
574
|
+
}
|
|
575
|
+
return /*#__PURE__*/React__default.createElement(RenderedPieChart, _extends({
|
|
576
|
+
caping: caping,
|
|
577
|
+
chartRef: chartRef,
|
|
578
|
+
className: classNames(PieChart.className, className),
|
|
579
|
+
data: propsData,
|
|
580
|
+
id: id,
|
|
581
|
+
isSliceSelected: isSliceSelected,
|
|
582
|
+
labelDecorator: labelDecorator,
|
|
583
|
+
legendDecorator: legendDecorator,
|
|
584
|
+
legendVariant: legendVariant,
|
|
585
|
+
middleText: middleText,
|
|
586
|
+
onSliceClick: onSliceClick,
|
|
587
|
+
others: others,
|
|
588
|
+
size: size,
|
|
589
|
+
sliceRole: sliceRole,
|
|
590
|
+
sortingMethod: sortingMethod,
|
|
591
|
+
subtext: subtext,
|
|
592
|
+
text: text,
|
|
593
|
+
colorTheme: colorTheme,
|
|
594
|
+
tooltipDecorator: tooltipDecorator,
|
|
595
|
+
tooltipVariant: tooltipVariant,
|
|
596
|
+
variant: variant
|
|
597
|
+
}, forwardedProps, {
|
|
598
|
+
ref: ref
|
|
599
|
+
}));
|
|
600
|
+
});
|
|
601
|
+
PieChart.className = CLASSNAME;
|
|
602
|
+
PieChart.displayName = COMPONENT_NAME;
|
|
603
|
+
|
|
604
|
+
export { PieChart as P, StyledPieChart as S, PieChartVariant as a, PieChartLegendVariant as b, StyledPieChartCenterText as c, StyledPieChartEmptyText as d };
|
|
605
|
+
//# sourceMappingURL=PieChart2.js.map
|