@redsift/charts 7.0.1 → 7.1.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/index.d.ts +114 -5
- package/index.js +719 -201
- package/index.js.map +1 -1
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { scaleOrdinal,
|
|
1
|
+
import { scaleOrdinal, select, axisBottom, scaleLinear, sum, pie, arc } from 'd3';
|
|
2
2
|
import React, { forwardRef, useState, useRef, useEffect, useImperativeHandle, useLayoutEffect, useId } from 'react';
|
|
3
3
|
import styled, { css } from 'styled-components';
|
|
4
4
|
import ReactDOM from 'react-dom';
|
|
@@ -10,21 +10,76 @@ const ColorTheme = {
|
|
|
10
10
|
monochrome: 'monochrome'
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Do not edit directly
|
|
15
|
+
* Generated on Wed, 14 Dec 2022 17:05:36 GMT
|
|
16
|
+
*/
|
|
17
|
+
const RedsiftDataVizColorPurpleDefault = '#C1AAEA';
|
|
18
|
+
const RedsiftDataVizColorPurpleDark = '#A78ADB';
|
|
19
|
+
const RedsiftDataVizColorPurpleDarker = '#8D6CC9';
|
|
20
|
+
const RedsiftDataVizColorPurpleLight = '#D9CAF5';
|
|
21
|
+
const RedsiftDataVizColorPurpleLighter = '#F0E9FC';
|
|
22
|
+
const RedsiftDataVizColorBlueDefault = '#B6DAEE';
|
|
23
|
+
const RedsiftDataVizColorBlueDark = '#97C5DE';
|
|
24
|
+
const RedsiftDataVizColorBlueDarker = '#73ADCC';
|
|
25
|
+
const RedsiftDataVizColorBlueLight = '#D8EDF8';
|
|
26
|
+
const RedsiftDataVizColorBlueLighter = '#F6FBFE';
|
|
27
|
+
const RedsiftDataVizColorGreenDefault = '#B3E3C5';
|
|
28
|
+
const RedsiftDataVizColorGreenDark = '#90D2A9';
|
|
29
|
+
const RedsiftDataVizColorGreenDarker = '#6DBE8B';
|
|
30
|
+
const RedsiftDataVizColorGreenLight = '#D3F0DE';
|
|
31
|
+
const RedsiftDataVizColorGreenLighter = '#EDFAF1';
|
|
32
|
+
const RedsiftDataVizColorRedDefault = '#EAADAC';
|
|
33
|
+
const RedsiftDataVizColorRedDark = '#D18785';
|
|
34
|
+
const RedsiftDataVizColorRedDarker = '#BA6361';
|
|
35
|
+
const RedsiftDataVizColorRedLight = '#FFD3D2';
|
|
36
|
+
const RedsiftDataVizColorRedLighter = '#FFE5E5';
|
|
37
|
+
const RedsiftDataVizColorPinkDefault = '#E2A7D7';
|
|
38
|
+
const RedsiftDataVizColorPinkDark = '#D185C3';
|
|
39
|
+
const RedsiftDataVizColorPinkDarker = '#BD63AC';
|
|
40
|
+
const RedsiftDataVizColorPinkLight = '#EFC8E8';
|
|
41
|
+
const RedsiftDataVizColorPinkLighter = '#F9E6F6';
|
|
42
|
+
const RedsiftDataVizColorCyanDefault = '#AFF5F3';
|
|
43
|
+
const RedsiftDataVizColorCyanDark = '#8CEAE6';
|
|
44
|
+
const RedsiftDataVizColorCyanDarker = '#6CDCD8';
|
|
45
|
+
const RedsiftDataVizColorCyanLight = '#D4FCFA';
|
|
46
|
+
const RedsiftDataVizColorCyanLighter = '#E1FFFF';
|
|
47
|
+
const RedsiftDataVizColorOrangeDefault = '#F2D39E';
|
|
48
|
+
const RedsiftDataVizColorOrangeDark = '#D8B475';
|
|
49
|
+
const RedsiftDataVizColorOrangeDarker = '#BD954F';
|
|
50
|
+
const RedsiftDataVizColorOrangeLight = '#FFE8C0';
|
|
51
|
+
const RedsiftDataVizColorOrangeLighter = '#FFF0D7';
|
|
52
|
+
const RedsiftDataVizColorYellowDefault = '#F6EFC7';
|
|
53
|
+
const RedsiftDataVizColorYellowDark = '#DED4A0';
|
|
54
|
+
const RedsiftDataVizColorYellowDarker = '#C6BB7A';
|
|
55
|
+
const RedsiftDataVizColorYellowLight = '#FFFBE1';
|
|
56
|
+
const RedsiftDataVizColorYellowLighter = '#FFFDF0';
|
|
57
|
+
const RedsiftDataVizColorBrownDefault = '#E6C2A0';
|
|
58
|
+
const RedsiftDataVizColorBrownDark = '#CDA279';
|
|
59
|
+
const RedsiftDataVizColorBrownDarker = '#B58556';
|
|
60
|
+
const RedsiftDataVizColorBrownLight = '#FFE3C9';
|
|
61
|
+
const RedsiftDataVizColorBrownLighter = '#FFEEDE';
|
|
62
|
+
const RedsiftDataVizColorGreyDefault = '#E5E5E5';
|
|
63
|
+
const RedsiftDataVizColorGreyDark = '#BDBDBD';
|
|
64
|
+
const RedsiftDataVizColorGreyDarker = '#666666';
|
|
65
|
+
const RedsiftDataVizColorGreyLight = '#F5F5F5';
|
|
66
|
+
const RedsiftDataVizColorGreyLighter = '#FFFFFF';
|
|
67
|
+
|
|
68
|
+
const monochrome = RedsiftDataVizColorBlueDefault;
|
|
14
69
|
const scheme = {
|
|
15
|
-
default: [
|
|
16
|
-
dark: [
|
|
17
|
-
darker: [
|
|
18
|
-
light: [
|
|
19
|
-
lighter: [
|
|
70
|
+
default: [RedsiftDataVizColorPurpleDefault, RedsiftDataVizColorBlueDefault, RedsiftDataVizColorGreenDefault, RedsiftDataVizColorRedDefault, RedsiftDataVizColorPinkDefault, RedsiftDataVizColorCyanDefault, RedsiftDataVizColorOrangeDefault, RedsiftDataVizColorYellowDefault, RedsiftDataVizColorBrownDefault, RedsiftDataVizColorGreyDefault],
|
|
71
|
+
dark: [RedsiftDataVizColorPurpleDark, RedsiftDataVizColorBlueDark, RedsiftDataVizColorGreenDark, RedsiftDataVizColorRedDark, RedsiftDataVizColorPinkDark, RedsiftDataVizColorCyanDark, RedsiftDataVizColorOrangeDark, RedsiftDataVizColorYellowDark, RedsiftDataVizColorBrownDark, RedsiftDataVizColorGreyDark],
|
|
72
|
+
darker: [RedsiftDataVizColorPurpleDarker, RedsiftDataVizColorBlueDarker, RedsiftDataVizColorGreenDarker, RedsiftDataVizColorRedDarker, RedsiftDataVizColorPinkDarker, RedsiftDataVizColorCyanDarker, RedsiftDataVizColorOrangeDarker, RedsiftDataVizColorYellowDarker, RedsiftDataVizColorBrownDarker, RedsiftDataVizColorGreyDarker],
|
|
73
|
+
light: [RedsiftDataVizColorPurpleLight, RedsiftDataVizColorBlueLight, RedsiftDataVizColorGreenLight, RedsiftDataVizColorRedLight, RedsiftDataVizColorPinkLight, RedsiftDataVizColorCyanLight, RedsiftDataVizColorOrangeLight, RedsiftDataVizColorYellowLight, RedsiftDataVizColorBrownLight, RedsiftDataVizColorGreyLight],
|
|
74
|
+
lighter: [RedsiftDataVizColorPurpleLighter, RedsiftDataVizColorBlueLighter, RedsiftDataVizColorGreenLighter, RedsiftDataVizColorRedLighter, RedsiftDataVizColorPinkLighter, RedsiftDataVizColorCyanLighter, RedsiftDataVizColorOrangeLighter, RedsiftDataVizColorYellowLighter, RedsiftDataVizColorBrownLighter, RedsiftDataVizColorGreyLighter],
|
|
20
75
|
monochrome: [monochrome],
|
|
21
|
-
empty: [
|
|
76
|
+
empty: [RedsiftDataVizColorGreyDark]
|
|
22
77
|
};
|
|
23
78
|
const successDangerScheme = {
|
|
24
|
-
success:
|
|
25
|
-
warning:
|
|
26
|
-
danger:
|
|
27
|
-
neutral:
|
|
79
|
+
success: RedsiftDataVizColorGreenDark,
|
|
80
|
+
warning: RedsiftDataVizColorOrangeDark,
|
|
81
|
+
danger: RedsiftDataVizColorRedDark,
|
|
82
|
+
neutral: RedsiftDataVizColorGreyDark
|
|
28
83
|
};
|
|
29
84
|
const getColorScale = (theme, isEmpty) => {
|
|
30
85
|
let d3colors = scaleOrdinal(scheme.default);
|
|
@@ -117,38 +172,19 @@ function _objectWithoutProperties(source, excluded) {
|
|
|
117
172
|
/**
|
|
118
173
|
* Component size.
|
|
119
174
|
*/
|
|
120
|
-
const
|
|
175
|
+
const HorizontalBarChartSize = {
|
|
121
176
|
small: 'small',
|
|
122
177
|
medium: 'medium',
|
|
123
178
|
large: 'large'
|
|
124
179
|
};
|
|
125
|
-
/**
|
|
126
|
-
* Component variant.
|
|
127
|
-
*/
|
|
128
|
-
const PieChartVariant = {
|
|
129
|
-
plain: 'plain',
|
|
130
|
-
spaced: 'spaced',
|
|
131
|
-
donut: 'donut',
|
|
132
|
-
spacedDonut: 'spacedDonut'
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Component's labels variant.
|
|
136
|
-
*/
|
|
137
|
-
const PieChartLabelVariant = {
|
|
138
|
-
none: 'none',
|
|
139
|
-
internal: 'internal',
|
|
140
|
-
externalLabel: 'externalLabel',
|
|
141
|
-
externalLabelValue: 'externalLabelValue',
|
|
142
|
-
externalLabelPercent: 'externalLabelPercent'
|
|
143
|
-
};
|
|
144
180
|
/**
|
|
145
181
|
* Component theme.
|
|
146
182
|
*/
|
|
147
|
-
const
|
|
183
|
+
const HorizontalBarChartTheme = ColorTheme;
|
|
148
184
|
/**
|
|
149
185
|
* Tooltip label variant.
|
|
150
186
|
*/
|
|
151
|
-
const
|
|
187
|
+
const HorizontalBarChartTooltipVariant = {
|
|
152
188
|
none: 'none',
|
|
153
189
|
label: 'label',
|
|
154
190
|
value: 'value',
|
|
@@ -158,12 +194,12 @@ const PieChartTooltipVariant = {
|
|
|
158
194
|
/**
|
|
159
195
|
* Component style.
|
|
160
196
|
*/
|
|
161
|
-
const
|
|
197
|
+
const StyledHorizontalBarChart = styled.div`
|
|
162
198
|
margin: 8px;
|
|
163
199
|
padding: 8px;
|
|
164
200
|
color: var(--redsift-color-neutral-black);
|
|
165
201
|
|
|
166
|
-
.redsift-
|
|
202
|
+
.redsift-horizontal-barchart__container {
|
|
167
203
|
display: flex;
|
|
168
204
|
align-items: center;
|
|
169
205
|
gap: 16px;
|
|
@@ -172,27 +208,32 @@ const StyledPieChart = styled.div`
|
|
|
172
208
|
justify-content: center;
|
|
173
209
|
margin: 8px 0;
|
|
174
210
|
|
|
175
|
-
.redsift-
|
|
211
|
+
.redsift-horizontal-barchart-container__chart {
|
|
176
212
|
position: relative;
|
|
177
213
|
}
|
|
178
214
|
}
|
|
215
|
+
|
|
179
216
|
svg {
|
|
180
217
|
display: block;
|
|
218
|
+
|
|
219
|
+
g {
|
|
220
|
+
margin: 8px;
|
|
221
|
+
}
|
|
181
222
|
}
|
|
182
223
|
`;
|
|
183
|
-
const
|
|
224
|
+
const StyledHorizontalBarChartTitle = styled.div`
|
|
184
225
|
font-family: var(--redsift-typography-h4-font-family);
|
|
185
226
|
font-size: var(--redsift-typography-h4-font-size);
|
|
186
227
|
font-weight: var(--redsift-typography-h4-font-weight);
|
|
187
228
|
line-height: var(--redsift-typography-h4-line-height);
|
|
188
229
|
`;
|
|
189
|
-
const
|
|
230
|
+
const StyledHorizontalBarChartCaption = styled.p`
|
|
190
231
|
font-family: var(--redsift-typography-caption-font-family);
|
|
191
232
|
font-size: var(--redsift-typography-caption-font-size);
|
|
192
233
|
font-weight: var(--redsift-typography-caption-font-weight);
|
|
193
234
|
line-height: var(--redsift-typography-caption-line-height);
|
|
194
235
|
`;
|
|
195
|
-
const
|
|
236
|
+
const StyledHorizontalBarChartEmptyText = styled.div`
|
|
196
237
|
position: absolute;
|
|
197
238
|
top: 0;
|
|
198
239
|
left: 0;
|
|
@@ -213,10 +254,9 @@ const StyledPieChartCenterText = styled.div`
|
|
|
213
254
|
}}px;
|
|
214
255
|
}
|
|
215
256
|
|
|
216
|
-
>
|
|
217
|
-
font-family: var(--redsift-typography-font-family-
|
|
257
|
+
> span {
|
|
258
|
+
font-family: var(--redsift-typography-font-family-raleway);
|
|
218
259
|
color: var(--redsift-color-neutral-black);
|
|
219
|
-
font-weight: var(--redsift-typography-font-weight-medium);
|
|
220
260
|
font-size: ${_ref2 => {
|
|
221
261
|
let {
|
|
222
262
|
$textSize
|
|
@@ -229,160 +269,39 @@ const StyledPieChartCenterText = styled.div`
|
|
|
229
269
|
} = _ref3;
|
|
230
270
|
return $textSize;
|
|
231
271
|
}}px;
|
|
232
|
-
|
|
233
|
-
&:nth-child(2) {
|
|
234
|
-
font-weight: normal;
|
|
235
|
-
margin-top: 8px;
|
|
236
|
-
font-family: var(--redsift-typography-font-family-raleway);
|
|
237
|
-
font-size: ${_ref4 => {
|
|
238
|
-
let {
|
|
239
|
-
$smallTextSize
|
|
240
|
-
} = _ref4;
|
|
241
|
-
return $smallTextSize;
|
|
242
|
-
}}px;
|
|
243
|
-
line-height: ${_ref5 => {
|
|
244
|
-
let {
|
|
245
|
-
$smallTextSize
|
|
246
|
-
} = _ref5;
|
|
247
|
-
return $smallTextSize;
|
|
248
|
-
}}px;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
> span {
|
|
252
|
-
color: var(--redsift-color-neutral-black);
|
|
253
|
-
font-size: ${_ref6 => {
|
|
254
|
-
let {
|
|
255
|
-
$textSize
|
|
256
|
-
} = _ref6;
|
|
257
|
-
return $textSize;
|
|
258
|
-
}}px;
|
|
259
|
-
line-height: ${_ref7 => {
|
|
260
|
-
let {
|
|
261
|
-
$textSize
|
|
262
|
-
} = _ref7;
|
|
263
|
-
return $textSize;
|
|
264
|
-
}}px;
|
|
265
|
-
&:nth-child(3) {
|
|
266
|
-
margin-top: 4px;
|
|
267
|
-
font-size: ${_ref8 => {
|
|
268
|
-
let {
|
|
269
|
-
$smallTextSize
|
|
270
|
-
} = _ref8;
|
|
271
|
-
return $smallTextSize;
|
|
272
|
-
}}px;
|
|
273
|
-
line-height: ${_ref9 => {
|
|
274
|
-
let {
|
|
275
|
-
$smallTextSize
|
|
276
|
-
} = _ref9;
|
|
277
|
-
return $smallTextSize;
|
|
278
|
-
}}px;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
> b + span {
|
|
282
|
-
font-size: var(--redsift-typography-body-font-size);
|
|
283
|
-
font-family: var(--redsift-typography-font-family-raleway);
|
|
284
|
-
line-height: var(--redsift-typography-badge-line-height);
|
|
285
|
-
color: rgba(0, 0, 0, 0.6);
|
|
286
|
-
text-align: center;
|
|
287
|
-
}
|
|
288
|
-
`;
|
|
289
|
-
const StyledPieChartEmptyText = styled.div`
|
|
290
|
-
position: absolute;
|
|
291
|
-
top: 0;
|
|
292
|
-
left: 0;
|
|
293
|
-
height: 100%;
|
|
294
|
-
width: 100%;
|
|
295
|
-
display: flex;
|
|
296
|
-
flex-direction: column;
|
|
297
|
-
justify-content: center;
|
|
298
|
-
align-items: center;
|
|
299
|
-
pointer-events: none;
|
|
300
|
-
|
|
301
|
-
> * {
|
|
302
|
-
max-width: ${_ref10 => {
|
|
303
|
-
let {
|
|
304
|
-
$maxWidth
|
|
305
|
-
} = _ref10;
|
|
306
|
-
return $maxWidth;
|
|
307
|
-
}}px;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
> span {
|
|
311
|
-
font-family: var(--redsift-typography-font-family-raleway);
|
|
312
|
-
color: ${_ref11 => {
|
|
313
|
-
let {
|
|
314
|
-
$isDonut
|
|
315
|
-
} = _ref11;
|
|
316
|
-
return $isDonut ? css`var(--redsift-color-neutral-midgrey)` : css`var(--redsift-color-neutral-black)`;
|
|
317
|
-
}};
|
|
318
|
-
font-size: ${_ref12 => {
|
|
319
|
-
let {
|
|
320
|
-
$textSize
|
|
321
|
-
} = _ref12;
|
|
322
|
-
return $textSize;
|
|
323
|
-
}}px;
|
|
324
|
-
line-height: ${_ref13 => {
|
|
325
|
-
let {
|
|
326
|
-
$textSize
|
|
327
|
-
} = _ref13;
|
|
328
|
-
return $textSize;
|
|
329
|
-
}}px;
|
|
330
272
|
}
|
|
331
273
|
`;
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
gap: 8px;
|
|
336
|
-
width: 100%;
|
|
337
|
-
max-width: 262px;
|
|
338
|
-
font-family: var(--redsift-typography-font-family-raleway);
|
|
339
|
-
font-weight: var(--redsift-typography-font-weight-regular);
|
|
340
|
-
font-size: var(--redsift-typography-caption-font-size);
|
|
341
|
-
|
|
342
|
-
> div {
|
|
343
|
-
height: 16px;
|
|
344
|
-
width: 16px;
|
|
345
|
-
min-width: 16px;
|
|
346
|
-
background-color: ${_ref14 => {
|
|
347
|
-
let {
|
|
348
|
-
$color
|
|
349
|
-
} = _ref14;
|
|
350
|
-
return $color;
|
|
351
|
-
}};
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
> b {
|
|
355
|
-
font-family: var(--redsift-typography-font-family-source-code-pro);
|
|
356
|
-
font-weight: var(--redsift-typography-font-weight-bold);
|
|
357
|
-
font-size: var(--redsift-typography-caption-font-size);
|
|
274
|
+
const StyledHorizontalBarChartBar = styled.g`
|
|
275
|
+
rect {
|
|
276
|
+
fill-opacity: 0.9;
|
|
358
277
|
}
|
|
359
|
-
`;
|
|
360
|
-
const StyledPieChartArc = styled.g`
|
|
361
|
-
${_ref15 => {
|
|
362
|
-
let {
|
|
363
|
-
$spaced
|
|
364
|
-
} = _ref15;
|
|
365
|
-
return $spaced ? css`
|
|
366
|
-
path {
|
|
367
|
-
stroke-width: 2px;
|
|
368
|
-
stroke: #fff;
|
|
369
|
-
}
|
|
370
|
-
` : '';
|
|
371
|
-
}}
|
|
372
278
|
|
|
373
|
-
${
|
|
279
|
+
${_ref4 => {
|
|
374
280
|
let {
|
|
375
281
|
$clickable
|
|
376
|
-
} =
|
|
282
|
+
} = _ref4;
|
|
377
283
|
return $clickable ? css`
|
|
378
284
|
cursor: pointer;
|
|
379
|
-
|
|
380
|
-
|
|
285
|
+
|
|
286
|
+
&:hover,
|
|
287
|
+
&:focus {
|
|
288
|
+
outline: none;
|
|
289
|
+
rect {
|
|
290
|
+
fill-opacity: 0.7;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
&:focus-visible {
|
|
295
|
+
rect {
|
|
296
|
+
stroke: var(--redsift-color-default-primary);
|
|
297
|
+
stroke-width: 4px;
|
|
298
|
+
paint-order: stroke;
|
|
299
|
+
}
|
|
381
300
|
}
|
|
382
301
|
` : '';
|
|
383
302
|
}}}
|
|
384
303
|
`;
|
|
385
|
-
const
|
|
304
|
+
const StyledHorizontalBarChartTooltip = styled.div`
|
|
386
305
|
font-family: var(--redsift-typography-font-family-raleway);
|
|
387
306
|
border: 1px solid rgb(0 0 0 / 20%);
|
|
388
307
|
padding: 10px;
|
|
@@ -390,6 +309,18 @@ const Tooltip = styled.div`
|
|
|
390
309
|
0 1px 3px 0 rgb(0 0 0 / 12%);
|
|
391
310
|
background-color: var(--redsift-color-neutral-white);
|
|
392
311
|
`;
|
|
312
|
+
const StyledHorizontalBarChartAxisBottom = styled.g`
|
|
313
|
+
line.grid-line {
|
|
314
|
+
fill: none;
|
|
315
|
+
stroke: #ccc;
|
|
316
|
+
shape-rendering: crispEdges;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
text {
|
|
320
|
+
font-family: var(--redsift-typography-font-family-source-code-pro);
|
|
321
|
+
font-size: 10px;
|
|
322
|
+
}
|
|
323
|
+
`;
|
|
393
324
|
|
|
394
325
|
function _extends() {
|
|
395
326
|
_extends = Object.assign || function (target) {
|
|
@@ -1015,36 +946,620 @@ var Popup = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
|
1015
946
|
return React.createElement(React.Fragment, null, renderTrigger(), isOpen && ReactDOM.createPortal(content, getRootPopup()));
|
|
1016
947
|
});
|
|
1017
948
|
|
|
1018
|
-
const _excluded$
|
|
1019
|
-
const COMPONENT_NAME$
|
|
1020
|
-
const CLASSNAME$
|
|
1021
|
-
const DEFAULT_PROPS$
|
|
1022
|
-
const
|
|
949
|
+
const _excluded$4 = ["chartId", "color", "data", "gap", "height", "index", "isEmpty", "onClick", "role", "showTooltip", "tooltipLabelOnly", "tooltipPercent", "width"];
|
|
950
|
+
const COMPONENT_NAME$4 = 'RedSiftHorizontalBarChartBar';
|
|
951
|
+
const CLASSNAME$4 = 'redsift-horizontal-barchart-bar';
|
|
952
|
+
const DEFAULT_PROPS$4 = {};
|
|
953
|
+
const HorizontalBarChartBar = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1023
954
|
const {
|
|
955
|
+
chartId,
|
|
1024
956
|
color,
|
|
1025
957
|
data,
|
|
958
|
+
gap,
|
|
959
|
+
height,
|
|
1026
960
|
index,
|
|
961
|
+
isEmpty,
|
|
1027
962
|
onClick,
|
|
1028
|
-
|
|
1029
|
-
spaced,
|
|
963
|
+
role,
|
|
1030
964
|
showTooltip,
|
|
1031
|
-
tooltipPercent,
|
|
1032
965
|
tooltipLabelOnly,
|
|
1033
|
-
|
|
966
|
+
tooltipPercent,
|
|
967
|
+
width
|
|
1034
968
|
} = props,
|
|
1035
|
-
forwardedProps = _objectWithoutProperties(props, _excluded$
|
|
969
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$4);
|
|
970
|
+
const onKeyDown = event => {
|
|
971
|
+
if (onClick) {
|
|
972
|
+
event.stopPropagation();
|
|
973
|
+
if (event.code === 'Enter' || event.code === 'Space') {
|
|
974
|
+
event.preventDefault();
|
|
975
|
+
onClick();
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
const Bar = /*#__PURE__*/React.createElement(StyledHorizontalBarChartBar, _extends$1({
|
|
980
|
+
ref: ref
|
|
981
|
+
}, forwardedProps, {
|
|
982
|
+
"aria-label": showTooltip && !isEmpty ? `${data.name}: ${data.value}` : undefined,
|
|
983
|
+
"aria-labelledby": !showTooltip && !isEmpty ? `id${chartId}__slice-${index}-title` : undefined,
|
|
984
|
+
id: `id${chartId}__slice-${index}`,
|
|
985
|
+
className: `row _${index}`,
|
|
986
|
+
onClick: onClick,
|
|
987
|
+
onKeyDown: onKeyDown,
|
|
988
|
+
role: role ? role : onClick ? 'button' : undefined,
|
|
989
|
+
tabIndex: onClick ? 0 : undefined,
|
|
990
|
+
transform: `translate(0,${gap * (index + 1) + height * index})`,
|
|
991
|
+
$clickable: Boolean(onClick)
|
|
992
|
+
}), /*#__PURE__*/React.createElement("rect", {
|
|
993
|
+
height: height,
|
|
994
|
+
width: width,
|
|
995
|
+
fill: color
|
|
996
|
+
}), /*#__PURE__*/React.createElement("text", {
|
|
997
|
+
x: "10",
|
|
998
|
+
y: height / 2,
|
|
999
|
+
dy: "0.35em",
|
|
1000
|
+
"aria-hidden": true
|
|
1001
|
+
}, data.name), !showTooltip && !isEmpty && /*#__PURE__*/React.createElement("title", null, `${data.name}: ${data.value}`));
|
|
1002
|
+
if (showTooltip) {
|
|
1003
|
+
const tooltipValue = tooltipPercent !== null ? `${tooltipPercent}%` : data.value;
|
|
1004
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
1005
|
+
on: "hover",
|
|
1006
|
+
arrow: false,
|
|
1007
|
+
position: "right center",
|
|
1008
|
+
trigger: Bar
|
|
1009
|
+
}, /*#__PURE__*/React.createElement(StyledHorizontalBarChartTooltip, null, `${data.name}${tooltipLabelOnly ? '' : ` - ${tooltipValue}`}`));
|
|
1010
|
+
}
|
|
1011
|
+
return Bar;
|
|
1012
|
+
});
|
|
1013
|
+
HorizontalBarChartBar.className = CLASSNAME$4;
|
|
1014
|
+
HorizontalBarChartBar.defaultProps = DEFAULT_PROPS$4;
|
|
1015
|
+
HorizontalBarChartBar.displayName = COMPONENT_NAME$4;
|
|
1016
|
+
|
|
1017
|
+
const _excluded$3 = ["areXLabelsRotated", "chartHeight", "d3scale"];
|
|
1018
|
+
const COMPONENT_NAME$3 = 'RedSiftHorizontalBarChartAxisBottom';
|
|
1019
|
+
const CLASSNAME$3 = 'redsift-horizontal-barchart-axis-bottom';
|
|
1020
|
+
const DEFAULT_PROPS$3 = {};
|
|
1021
|
+
const HorizontalBarChartAxisBottom = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1022
|
+
const {
|
|
1023
|
+
areXLabelsRotated,
|
|
1024
|
+
chartHeight,
|
|
1025
|
+
d3scale
|
|
1026
|
+
} = props,
|
|
1027
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$3);
|
|
1028
|
+
const axisRef = ref || useRef();
|
|
1029
|
+
useEffect(() => {
|
|
1030
|
+
if (axisRef.current) {
|
|
1031
|
+
select(axisRef.current).call(axisBottom(d3scale).ticks(5));
|
|
1032
|
+
select(axisRef.current).selectAll('g.tick').select('line.grid-line').remove();
|
|
1033
|
+
select(axisRef.current).selectAll('g.tick').append('line').attr('class', 'grid-line').attr('x1', 0).attr('y1', 0).attr('x2', 0).attr('y2', () => -chartHeight);
|
|
1034
|
+
if (areXLabelsRotated) {
|
|
1035
|
+
select(axisRef.current).attr('text-anchor', 'end').selectAll('text').attr('transform', 'translate(-6,5) rotate(-45)');
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
}, [d3scale]);
|
|
1039
|
+
return /*#__PURE__*/React.createElement(StyledHorizontalBarChartAxisBottom, _extends$1({
|
|
1040
|
+
className: "axis"
|
|
1041
|
+
}, forwardedProps, {
|
|
1042
|
+
ref: axisRef
|
|
1043
|
+
}));
|
|
1044
|
+
});
|
|
1045
|
+
HorizontalBarChartAxisBottom.className = CLASSNAME$3;
|
|
1046
|
+
HorizontalBarChartAxisBottom.defaultProps = DEFAULT_PROPS$3;
|
|
1047
|
+
HorizontalBarChartAxisBottom.displayName = COMPONENT_NAME$3;
|
|
1048
|
+
|
|
1049
|
+
const _excluded$2 = ["aria-label", "aria-labelledby", "areXLabelsRotated", "caping", "caption", "className", "data", "onBarClick", "others", "size", "barRole", "theme", "title", "tooltipVariant", "localeText"];
|
|
1050
|
+
const COMPONENT_NAME$2 = 'RedSiftHorizontalBarChart';
|
|
1051
|
+
const CLASSNAME$2 = 'redsift-horizontal-barchart';
|
|
1052
|
+
const DEFAULT_PROPS$2 = {
|
|
1053
|
+
others: true,
|
|
1054
|
+
size: HorizontalBarChartSize.medium,
|
|
1055
|
+
theme: HorizontalBarChartTheme.default,
|
|
1056
|
+
tooltipVariant: HorizontalBarChartTooltipVariant.value,
|
|
1057
|
+
localeText: {
|
|
1058
|
+
emptyChartText: 'No Data'
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
const sizeToDimension$1 = size => {
|
|
1062
|
+
switch (size) {
|
|
1063
|
+
case HorizontalBarChartSize.small:
|
|
1064
|
+
return {
|
|
1065
|
+
width: 300,
|
|
1066
|
+
height: 200
|
|
1067
|
+
};
|
|
1068
|
+
case HorizontalBarChartSize.large:
|
|
1069
|
+
return {
|
|
1070
|
+
width: 500,
|
|
1071
|
+
height: 400
|
|
1072
|
+
};
|
|
1073
|
+
case HorizontalBarChartSize.medium:
|
|
1074
|
+
default:
|
|
1075
|
+
return {
|
|
1076
|
+
width: 400,
|
|
1077
|
+
height: 300
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
const sizeToFontSize$1 = size => {
|
|
1082
|
+
switch (size) {
|
|
1083
|
+
case HorizontalBarChartSize.small:
|
|
1084
|
+
return 30;
|
|
1085
|
+
case HorizontalBarChartSize.large:
|
|
1086
|
+
return 38;
|
|
1087
|
+
case HorizontalBarChartSize.medium:
|
|
1088
|
+
default:
|
|
1089
|
+
return 34;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
const HorizontalBarChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1093
|
+
const id = useId();
|
|
1094
|
+
const {
|
|
1095
|
+
'aria-label': ariaLabel,
|
|
1096
|
+
'aria-labelledby': ariaLabelledby,
|
|
1097
|
+
areXLabelsRotated,
|
|
1098
|
+
caping,
|
|
1099
|
+
caption,
|
|
1100
|
+
className,
|
|
1101
|
+
data: propData,
|
|
1102
|
+
onBarClick,
|
|
1103
|
+
others,
|
|
1104
|
+
size,
|
|
1105
|
+
barRole,
|
|
1106
|
+
theme,
|
|
1107
|
+
title,
|
|
1108
|
+
tooltipVariant,
|
|
1109
|
+
localeText
|
|
1110
|
+
} = props,
|
|
1111
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$2);
|
|
1112
|
+
const {
|
|
1113
|
+
emptyChartText
|
|
1114
|
+
} = _objectSpread2(_objectSpread2({}, DEFAULT_PROPS$2.localeText), localeText);
|
|
1115
|
+
const isEmpty = propData.every(d => d.value === 0);
|
|
1116
|
+
let data = propData.sort((a, b) => a.value < b.value ? 1 : -1);
|
|
1117
|
+
if (caping) {
|
|
1118
|
+
if (typeof others === 'boolean' && !others) {
|
|
1119
|
+
data = data.slice(0, caping);
|
|
1120
|
+
} else {
|
|
1121
|
+
data = data.reduce((acc, curr, index) => {
|
|
1122
|
+
if (index < caping) {
|
|
1123
|
+
acc[index] = curr;
|
|
1124
|
+
} else if (index === caping) {
|
|
1125
|
+
acc[index] = {
|
|
1126
|
+
name: typeof others === 'string' ? others : 'Others',
|
|
1127
|
+
value: curr.value
|
|
1128
|
+
};
|
|
1129
|
+
} else {
|
|
1130
|
+
acc[caping] = _objectSpread2(_objectSpread2({}, acc[caping]), {}, {
|
|
1131
|
+
value: acc[caping].value + curr.value
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
return acc;
|
|
1135
|
+
}, []);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
if (isEmpty) {
|
|
1139
|
+
data = [];
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// Get charts dimensions based on the selected size.
|
|
1143
|
+
const chartDimensions = sizeToDimension$1(size);
|
|
1144
|
+
const width = chartDimensions.width - 16;
|
|
1145
|
+
const height = chartDimensions.height;
|
|
1146
|
+
const chartHeight = height - 48 - (areXLabelsRotated ? 30 : 0);
|
|
1147
|
+
const margins = {
|
|
1148
|
+
top: 16,
|
|
1149
|
+
left: 16,
|
|
1150
|
+
right: 16,
|
|
1151
|
+
bottom: 32
|
|
1152
|
+
};
|
|
1153
|
+
const numberOfRows = data.length;
|
|
1154
|
+
const gap = 5;
|
|
1155
|
+
|
|
1156
|
+
// Set color scheme.
|
|
1157
|
+
const d3colors = getColorScale(theme, isEmpty);
|
|
1158
|
+
|
|
1159
|
+
// Initialize the chart.
|
|
1160
|
+
const scaleX = scaleLinear().domain([0, Math.max(...data.map(_ref => {
|
|
1161
|
+
let {
|
|
1162
|
+
value
|
|
1163
|
+
} = _ref;
|
|
1164
|
+
return value;
|
|
1165
|
+
}))]).range([0, width - 32]);
|
|
1166
|
+
const barHeight = (chartHeight - (numberOfRows + 1) * gap) / numberOfRows;
|
|
1167
|
+
const total = sum(data, d => d.value);
|
|
1168
|
+
return /*#__PURE__*/React.createElement(StyledHorizontalBarChart, _extends$1({
|
|
1169
|
+
ref: ref
|
|
1170
|
+
}, forwardedProps, {
|
|
1171
|
+
className: className
|
|
1172
|
+
}), title ? /*#__PURE__*/React.createElement(StyledHorizontalBarChartTitle, {
|
|
1173
|
+
className: `${HorizontalBarChart.className}__title`,
|
|
1174
|
+
id: `id${id}__title`
|
|
1175
|
+
}, title) : null, /*#__PURE__*/React.createElement("div", {
|
|
1176
|
+
className: `${HorizontalBarChart.className}__container`
|
|
1177
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1178
|
+
className: `${HorizontalBarChart.className}-container__chart`,
|
|
1179
|
+
"aria-label": ariaLabel ? ariaLabel : ariaLabelledby || title ? undefined : 'Horizontal Bar Chart',
|
|
1180
|
+
"aria-labelledby": ariaLabelledby ? ariaLabelledby : title ? `id${id}__title` : undefined
|
|
1181
|
+
}, isEmpty ? /*#__PURE__*/React.createElement(StyledHorizontalBarChartEmptyText, {
|
|
1182
|
+
$maxWidth: width,
|
|
1183
|
+
$textSize: sizeToFontSize$1(size) / 2
|
|
1184
|
+
}, /*#__PURE__*/React.createElement("span", null, emptyChartText)) : null, /*#__PURE__*/React.createElement("svg", {
|
|
1185
|
+
width: width,
|
|
1186
|
+
height: height
|
|
1187
|
+
}, /*#__PURE__*/React.createElement("g", {
|
|
1188
|
+
transform: `translate(${margins.left},${margins.top})`
|
|
1189
|
+
}, /*#__PURE__*/React.createElement(HorizontalBarChartAxisBottom, {
|
|
1190
|
+
areXLabelsRotated: !!areXLabelsRotated,
|
|
1191
|
+
chartHeight: chartHeight,
|
|
1192
|
+
d3scale: scaleX,
|
|
1193
|
+
transform: `translate(0,${chartHeight})`
|
|
1194
|
+
}), data.map((_ref2, index) => {
|
|
1195
|
+
let {
|
|
1196
|
+
value,
|
|
1197
|
+
name
|
|
1198
|
+
} = _ref2;
|
|
1199
|
+
const percent = (value / total * 100).toFixed(2);
|
|
1200
|
+
return /*#__PURE__*/React.createElement(HorizontalBarChartBar, {
|
|
1201
|
+
chartId: id,
|
|
1202
|
+
color: d3colors(name),
|
|
1203
|
+
data: {
|
|
1204
|
+
value,
|
|
1205
|
+
name
|
|
1206
|
+
},
|
|
1207
|
+
gap: gap,
|
|
1208
|
+
height: barHeight,
|
|
1209
|
+
index: index,
|
|
1210
|
+
isEmpty: isEmpty,
|
|
1211
|
+
key: `row _${index}`,
|
|
1212
|
+
onClick: onBarClick ? () => onBarClick(data[index]) : undefined,
|
|
1213
|
+
role: barRole,
|
|
1214
|
+
showTooltip: tooltipVariant !== HorizontalBarChartTooltipVariant.none && !isEmpty,
|
|
1215
|
+
tooltipLabelOnly: tooltipVariant == HorizontalBarChartTooltipVariant.label,
|
|
1216
|
+
tooltipPercent: tooltipVariant === HorizontalBarChartTooltipVariant.percent ? percent : null,
|
|
1217
|
+
width: Math.abs(scaleX(value))
|
|
1218
|
+
});
|
|
1219
|
+
}))))), caption ? /*#__PURE__*/React.createElement(StyledHorizontalBarChartCaption, {
|
|
1220
|
+
className: `${HorizontalBarChart.className}__caption`
|
|
1221
|
+
}, caption) : null);
|
|
1222
|
+
});
|
|
1223
|
+
HorizontalBarChart.className = CLASSNAME$2;
|
|
1224
|
+
HorizontalBarChart.defaultProps = DEFAULT_PROPS$2;
|
|
1225
|
+
HorizontalBarChart.displayName = COMPONENT_NAME$2;
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Component size.
|
|
1229
|
+
*/
|
|
1230
|
+
const PieChartSize = {
|
|
1231
|
+
small: 'small',
|
|
1232
|
+
medium: 'medium',
|
|
1233
|
+
large: 'large'
|
|
1234
|
+
};
|
|
1235
|
+
/**
|
|
1236
|
+
* Component variant.
|
|
1237
|
+
*/
|
|
1238
|
+
const PieChartVariant = {
|
|
1239
|
+
plain: 'plain',
|
|
1240
|
+
spaced: 'spaced',
|
|
1241
|
+
donut: 'donut',
|
|
1242
|
+
spacedDonut: 'spacedDonut'
|
|
1243
|
+
};
|
|
1244
|
+
/**
|
|
1245
|
+
* Component's labels variant.
|
|
1246
|
+
*/
|
|
1247
|
+
const PieChartLabelVariant = {
|
|
1248
|
+
none: 'none',
|
|
1249
|
+
internal: 'internal',
|
|
1250
|
+
externalLabel: 'externalLabel',
|
|
1251
|
+
externalLabelValue: 'externalLabelValue',
|
|
1252
|
+
externalLabelPercent: 'externalLabelPercent'
|
|
1253
|
+
};
|
|
1254
|
+
/**
|
|
1255
|
+
* Component theme.
|
|
1256
|
+
*/
|
|
1257
|
+
const PieChartTheme = ColorTheme;
|
|
1258
|
+
/**
|
|
1259
|
+
* Tooltip label variant.
|
|
1260
|
+
*/
|
|
1261
|
+
const PieChartTooltipVariant = {
|
|
1262
|
+
none: 'none',
|
|
1263
|
+
label: 'label',
|
|
1264
|
+
value: 'value',
|
|
1265
|
+
percent: 'percent'
|
|
1266
|
+
};
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Component style.
|
|
1270
|
+
*/
|
|
1271
|
+
const StyledPieChart = styled.div`
|
|
1272
|
+
margin: 8px;
|
|
1273
|
+
padding: 8px;
|
|
1274
|
+
color: var(--redsift-color-neutral-black);
|
|
1275
|
+
|
|
1276
|
+
.redsift-piechart__container {
|
|
1277
|
+
display: flex;
|
|
1278
|
+
align-items: center;
|
|
1279
|
+
gap: 16px;
|
|
1280
|
+
font-family: var(--redsift-typography-font-family-source-code-pro);
|
|
1281
|
+
font-size: 11px;
|
|
1282
|
+
justify-content: center;
|
|
1283
|
+
margin: 8px 0;
|
|
1284
|
+
|
|
1285
|
+
.redsift-piechart-container__chart {
|
|
1286
|
+
position: relative;
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
svg {
|
|
1290
|
+
display: block;
|
|
1291
|
+
}
|
|
1292
|
+
`;
|
|
1293
|
+
const StyledPieChartTitle = styled.div`
|
|
1294
|
+
font-family: var(--redsift-typography-h4-font-family);
|
|
1295
|
+
font-size: var(--redsift-typography-h4-font-size);
|
|
1296
|
+
font-weight: var(--redsift-typography-h4-font-weight);
|
|
1297
|
+
line-height: var(--redsift-typography-h4-line-height);
|
|
1298
|
+
`;
|
|
1299
|
+
const StyledPieChartCaption = styled.p`
|
|
1300
|
+
font-family: var(--redsift-typography-caption-font-family);
|
|
1301
|
+
font-size: var(--redsift-typography-caption-font-size);
|
|
1302
|
+
font-weight: var(--redsift-typography-caption-font-weight);
|
|
1303
|
+
line-height: var(--redsift-typography-caption-line-height);
|
|
1304
|
+
`;
|
|
1305
|
+
const StyledPieChartCenterText = styled.div`
|
|
1306
|
+
position: absolute;
|
|
1307
|
+
top: 0;
|
|
1308
|
+
left: 0;
|
|
1309
|
+
height: 100%;
|
|
1310
|
+
width: 100%;
|
|
1311
|
+
display: flex;
|
|
1312
|
+
flex-direction: column;
|
|
1313
|
+
justify-content: center;
|
|
1314
|
+
align-items: center;
|
|
1315
|
+
pointer-events: none;
|
|
1316
|
+
|
|
1317
|
+
> * {
|
|
1318
|
+
max-width: ${_ref => {
|
|
1319
|
+
let {
|
|
1320
|
+
$maxWidth
|
|
1321
|
+
} = _ref;
|
|
1322
|
+
return $maxWidth;
|
|
1323
|
+
}}px;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
> b {
|
|
1327
|
+
font-family: var(--redsift-typography-font-family-source-code-pro);
|
|
1328
|
+
color: var(--redsift-color-neutral-black);
|
|
1329
|
+
font-weight: var(--redsift-typography-font-weight-medium);
|
|
1330
|
+
font-size: ${_ref2 => {
|
|
1331
|
+
let {
|
|
1332
|
+
$textSize
|
|
1333
|
+
} = _ref2;
|
|
1334
|
+
return $textSize;
|
|
1335
|
+
}}px;
|
|
1336
|
+
line-height: ${_ref3 => {
|
|
1337
|
+
let {
|
|
1338
|
+
$textSize
|
|
1339
|
+
} = _ref3;
|
|
1340
|
+
return $textSize;
|
|
1341
|
+
}}px;
|
|
1342
|
+
|
|
1343
|
+
&:nth-child(2) {
|
|
1344
|
+
font-weight: normal;
|
|
1345
|
+
margin-top: 8px;
|
|
1346
|
+
font-family: var(--redsift-typography-font-family-raleway);
|
|
1347
|
+
font-size: ${_ref4 => {
|
|
1348
|
+
let {
|
|
1349
|
+
$smallTextSize
|
|
1350
|
+
} = _ref4;
|
|
1351
|
+
return $smallTextSize;
|
|
1352
|
+
}}px;
|
|
1353
|
+
line-height: ${_ref5 => {
|
|
1354
|
+
let {
|
|
1355
|
+
$smallTextSize
|
|
1356
|
+
} = _ref5;
|
|
1357
|
+
return $smallTextSize;
|
|
1358
|
+
}}px;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
> span {
|
|
1362
|
+
color: var(--redsift-color-neutral-black);
|
|
1363
|
+
font-size: ${_ref6 => {
|
|
1364
|
+
let {
|
|
1365
|
+
$textSize
|
|
1366
|
+
} = _ref6;
|
|
1367
|
+
return $textSize;
|
|
1368
|
+
}}px;
|
|
1369
|
+
line-height: ${_ref7 => {
|
|
1370
|
+
let {
|
|
1371
|
+
$textSize
|
|
1372
|
+
} = _ref7;
|
|
1373
|
+
return $textSize;
|
|
1374
|
+
}}px;
|
|
1375
|
+
&:nth-child(3) {
|
|
1376
|
+
margin-top: 4px;
|
|
1377
|
+
font-size: ${_ref8 => {
|
|
1378
|
+
let {
|
|
1379
|
+
$smallTextSize
|
|
1380
|
+
} = _ref8;
|
|
1381
|
+
return $smallTextSize;
|
|
1382
|
+
}}px;
|
|
1383
|
+
line-height: ${_ref9 => {
|
|
1384
|
+
let {
|
|
1385
|
+
$smallTextSize
|
|
1386
|
+
} = _ref9;
|
|
1387
|
+
return $smallTextSize;
|
|
1388
|
+
}}px;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
> b + span {
|
|
1392
|
+
font-size: var(--redsift-typography-body-font-size);
|
|
1393
|
+
font-family: var(--redsift-typography-font-family-raleway);
|
|
1394
|
+
line-height: var(--redsift-typography-badge-line-height);
|
|
1395
|
+
color: rgba(0, 0, 0, 0.6);
|
|
1396
|
+
text-align: center;
|
|
1397
|
+
}
|
|
1398
|
+
`;
|
|
1399
|
+
const StyledPieChartEmptyText = styled.div`
|
|
1400
|
+
position: absolute;
|
|
1401
|
+
top: 0;
|
|
1402
|
+
left: 0;
|
|
1403
|
+
height: 100%;
|
|
1404
|
+
width: 100%;
|
|
1405
|
+
display: flex;
|
|
1406
|
+
flex-direction: column;
|
|
1407
|
+
justify-content: center;
|
|
1408
|
+
align-items: center;
|
|
1409
|
+
pointer-events: none;
|
|
1410
|
+
|
|
1411
|
+
> * {
|
|
1412
|
+
max-width: ${_ref10 => {
|
|
1413
|
+
let {
|
|
1414
|
+
$maxWidth
|
|
1415
|
+
} = _ref10;
|
|
1416
|
+
return $maxWidth;
|
|
1417
|
+
}}px;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
> span {
|
|
1421
|
+
font-family: var(--redsift-typography-font-family-raleway);
|
|
1422
|
+
color: ${_ref11 => {
|
|
1423
|
+
let {
|
|
1424
|
+
$isDonut
|
|
1425
|
+
} = _ref11;
|
|
1426
|
+
return $isDonut ? css`var(--redsift-color-neutral-midgrey)` : css`var(--redsift-color-neutral-black)`;
|
|
1427
|
+
}};
|
|
1428
|
+
font-size: ${_ref12 => {
|
|
1429
|
+
let {
|
|
1430
|
+
$textSize
|
|
1431
|
+
} = _ref12;
|
|
1432
|
+
return $textSize;
|
|
1433
|
+
}}px;
|
|
1434
|
+
line-height: ${_ref13 => {
|
|
1435
|
+
let {
|
|
1436
|
+
$textSize
|
|
1437
|
+
} = _ref13;
|
|
1438
|
+
return $textSize;
|
|
1439
|
+
}}px;
|
|
1440
|
+
}
|
|
1441
|
+
`;
|
|
1442
|
+
const StyledPieChartLabel = styled.li`
|
|
1443
|
+
display: flex;
|
|
1444
|
+
align-items: center;
|
|
1445
|
+
gap: 8px;
|
|
1446
|
+
width: 100%;
|
|
1447
|
+
max-width: 262px;
|
|
1448
|
+
font-family: var(--redsift-typography-font-family-raleway);
|
|
1449
|
+
font-weight: var(--redsift-typography-font-weight-regular);
|
|
1450
|
+
font-size: var(--redsift-typography-caption-font-size);
|
|
1451
|
+
|
|
1452
|
+
> div {
|
|
1453
|
+
height: 16px;
|
|
1454
|
+
width: 16px;
|
|
1455
|
+
min-width: 16px;
|
|
1456
|
+
background-color: ${_ref14 => {
|
|
1457
|
+
let {
|
|
1458
|
+
$color
|
|
1459
|
+
} = _ref14;
|
|
1460
|
+
return $color;
|
|
1461
|
+
}};
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
> b {
|
|
1465
|
+
font-family: var(--redsift-typography-font-family-source-code-pro);
|
|
1466
|
+
font-weight: var(--redsift-typography-font-weight-bold);
|
|
1467
|
+
font-size: var(--redsift-typography-caption-font-size);
|
|
1468
|
+
}
|
|
1469
|
+
`;
|
|
1470
|
+
const StyledPieChartArc = styled.g`
|
|
1471
|
+
${_ref15 => {
|
|
1472
|
+
let {
|
|
1473
|
+
$spaced
|
|
1474
|
+
} = _ref15;
|
|
1475
|
+
return $spaced ? css`
|
|
1476
|
+
path {
|
|
1477
|
+
stroke-width: 2px;
|
|
1478
|
+
stroke: #fff;
|
|
1479
|
+
}
|
|
1480
|
+
` : '';
|
|
1481
|
+
}}
|
|
1482
|
+
|
|
1483
|
+
${_ref16 => {
|
|
1484
|
+
let {
|
|
1485
|
+
$clickable
|
|
1486
|
+
} = _ref16;
|
|
1487
|
+
return $clickable ? css`
|
|
1488
|
+
cursor: pointer;
|
|
1489
|
+
|
|
1490
|
+
&:hover,
|
|
1491
|
+
&:focus {
|
|
1492
|
+
opacity: 0.8;
|
|
1493
|
+
outline: none;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
&:focus-visible {
|
|
1497
|
+
path {
|
|
1498
|
+
stroke: var(--redsift-color-default-primary);
|
|
1499
|
+
stroke-width: 4px;
|
|
1500
|
+
paint-order: stroke;
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
` : '';
|
|
1504
|
+
}}}
|
|
1505
|
+
`;
|
|
1506
|
+
const StyledPieChartTooltip = styled.div`
|
|
1507
|
+
font-family: var(--redsift-typography-font-family-raleway);
|
|
1508
|
+
border: 1px solid rgb(0 0 0 / 20%);
|
|
1509
|
+
padding: 10px;
|
|
1510
|
+
box-shadow: 0 2px 1px -1px rgb(0 0 0 / 20%), 0 1px 1px 0 rgb(0 0 0 / 14%),
|
|
1511
|
+
0 1px 3px 0 rgb(0 0 0 / 12%);
|
|
1512
|
+
background-color: var(--redsift-color-neutral-white);
|
|
1513
|
+
`;
|
|
1514
|
+
|
|
1515
|
+
const _excluded$1 = ["chartId", "color", "data", "index", "onClick", "path", "role", "spaced", "showTooltip", "tooltipPercent", "tooltipLabelOnly", "isEmpty"];
|
|
1516
|
+
const COMPONENT_NAME$1 = 'RedSiftPieChartArc';
|
|
1517
|
+
const CLASSNAME$1 = 'redsift-piechart-arc';
|
|
1518
|
+
const DEFAULT_PROPS$1 = {};
|
|
1519
|
+
const PieChartArc = /*#__PURE__*/forwardRef((props, ref) => {
|
|
1520
|
+
const {
|
|
1521
|
+
chartId,
|
|
1522
|
+
color,
|
|
1523
|
+
data,
|
|
1524
|
+
index,
|
|
1525
|
+
onClick,
|
|
1526
|
+
path,
|
|
1527
|
+
role,
|
|
1528
|
+
spaced,
|
|
1529
|
+
showTooltip,
|
|
1530
|
+
tooltipPercent,
|
|
1531
|
+
tooltipLabelOnly,
|
|
1532
|
+
isEmpty
|
|
1533
|
+
} = props,
|
|
1534
|
+
forwardedProps = _objectWithoutProperties(props, _excluded$1);
|
|
1535
|
+
const onKeyDown = event => {
|
|
1536
|
+
if (onClick) {
|
|
1537
|
+
event.stopPropagation();
|
|
1538
|
+
if (event.code === 'Enter' || event.code === 'Space') {
|
|
1539
|
+
event.preventDefault();
|
|
1540
|
+
onClick();
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1036
1544
|
const Arc = /*#__PURE__*/React.createElement(StyledPieChartArc, _extends$1({
|
|
1037
1545
|
ref: ref
|
|
1038
1546
|
}, forwardedProps, {
|
|
1039
|
-
|
|
1547
|
+
"aria-label": showTooltip && !isEmpty ? `${data.name}: ${data.value}` : undefined,
|
|
1548
|
+
"aria-labelledby": !showTooltip && !isEmpty ? `id${chartId}__slice-${index}-title` : undefined,
|
|
1040
1549
|
className: `pie-slice _${index}`,
|
|
1550
|
+
id: `id${chartId}__slice-${index}`,
|
|
1041
1551
|
onClick: onClick,
|
|
1552
|
+
onKeyDown: onKeyDown,
|
|
1553
|
+
role: role ? role : onClick ? 'button' : undefined,
|
|
1554
|
+
tabIndex: onClick ? 0 : undefined,
|
|
1042
1555
|
$clickable: Boolean(onClick),
|
|
1043
1556
|
$spaced: Boolean(spaced)
|
|
1044
1557
|
}), /*#__PURE__*/React.createElement("path", {
|
|
1045
1558
|
d: path,
|
|
1046
1559
|
fill: color
|
|
1047
|
-
}), !showTooltip && !isEmpty
|
|
1560
|
+
}), !showTooltip && !isEmpty ? /*#__PURE__*/React.createElement("title", {
|
|
1561
|
+
id: `id${chartId}__slice-${index}-title`
|
|
1562
|
+
}, `${data.name}: ${data.value}`) : null);
|
|
1048
1563
|
if (showTooltip) {
|
|
1049
1564
|
const tooltipValue = tooltipPercent !== null ? `${tooltipPercent}%` : data.value;
|
|
1050
1565
|
return /*#__PURE__*/React.createElement(Popup, {
|
|
@@ -1052,7 +1567,7 @@ const PieChartArc = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1052
1567
|
arrow: false,
|
|
1053
1568
|
position: "right center",
|
|
1054
1569
|
trigger: Arc
|
|
1055
|
-
}, /*#__PURE__*/React.createElement(
|
|
1570
|
+
}, /*#__PURE__*/React.createElement(StyledPieChartTooltip, null, `${data.name}${tooltipLabelOnly ? '' : ` - ${tooltipValue}`}`));
|
|
1056
1571
|
}
|
|
1057
1572
|
return Arc;
|
|
1058
1573
|
});
|
|
@@ -1060,7 +1575,7 @@ PieChartArc.className = CLASSNAME$1;
|
|
|
1060
1575
|
PieChartArc.defaultProps = DEFAULT_PROPS$1;
|
|
1061
1576
|
PieChartArc.displayName = COMPONENT_NAME$1;
|
|
1062
1577
|
|
|
1063
|
-
const _excluded = ["aria-label", "aria-labelledby", "caping", "caption", "className", "data", "labelVariant", "onSliceClick", "others", "size", "text", "middleText", "subtext", "theme", "title", "variant", "tooltipVariant", "localeText"];
|
|
1578
|
+
const _excluded = ["aria-label", "aria-labelledby", "caping", "caption", "className", "data", "labelVariant", "onSliceClick", "others", "size", "sliceRole", "text", "middleText", "subtext", "theme", "title", "variant", "tooltipVariant", "localeText"];
|
|
1064
1579
|
const COMPONENT_NAME = 'RedSiftPieChart';
|
|
1065
1580
|
const CLASSNAME = 'redsift-piechart';
|
|
1066
1581
|
const DEFAULT_PROPS = {
|
|
@@ -1140,6 +1655,7 @@ const PieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1140
1655
|
onSliceClick,
|
|
1141
1656
|
others,
|
|
1142
1657
|
size,
|
|
1658
|
+
sliceRole,
|
|
1143
1659
|
text,
|
|
1144
1660
|
middleText,
|
|
1145
1661
|
subtext,
|
|
@@ -1228,6 +1744,7 @@ const PieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1228
1744
|
}, pieData.map((datum, index) => {
|
|
1229
1745
|
const percent = (datum.data.value / total * 100).toFixed(2);
|
|
1230
1746
|
return /*#__PURE__*/React.createElement(PieChartArc, {
|
|
1747
|
+
chartId: id,
|
|
1231
1748
|
color: d3colors(datum.data.name),
|
|
1232
1749
|
data: datum.data,
|
|
1233
1750
|
isEmpty: isEmpty,
|
|
@@ -1235,6 +1752,7 @@ const PieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1235
1752
|
key: `pie-slice _${index}`,
|
|
1236
1753
|
onClick: onSliceClick ? () => onSliceClick(data[index]) : undefined,
|
|
1237
1754
|
showTooltip: tooltipVariant !== PieChartTooltipVariant.none && !isEmpty,
|
|
1755
|
+
role: sliceRole,
|
|
1238
1756
|
tooltipLabelOnly: tooltipVariant == PieChartTooltipVariant.label,
|
|
1239
1757
|
tooltipPercent: tooltipVariant === PieChartTooltipVariant.percent ? percent : null,
|
|
1240
1758
|
path: createArc(datum),
|
|
@@ -1244,7 +1762,7 @@ const PieChart = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
1244
1762
|
className: "pie-label-group"
|
|
1245
1763
|
}, pieData.filter(datum => {
|
|
1246
1764
|
const value = datum.data.value;
|
|
1247
|
-
return value > 0 && value / total >= 0.
|
|
1765
|
+
return value > 0 && value / total >= 0.1;
|
|
1248
1766
|
}).map((datum, index) => /*#__PURE__*/React.createElement("text", {
|
|
1249
1767
|
className: `pie-slice pie-label _${index}`,
|
|
1250
1768
|
key: `pie-slice pie-label _${index}`,
|
|
@@ -1267,5 +1785,5 @@ PieChart.className = CLASSNAME;
|
|
|
1267
1785
|
PieChart.defaultProps = DEFAULT_PROPS;
|
|
1268
1786
|
PieChart.displayName = COMPONENT_NAME;
|
|
1269
1787
|
|
|
1270
|
-
export { ColorTheme, PieChart, PieChartLabelVariant, PieChartSize, PieChartTheme, PieChartTooltipVariant, PieChartVariant, StyledPieChart, StyledPieChartArc, StyledPieChartCaption, StyledPieChartCenterText, StyledPieChartEmptyText, StyledPieChartLabel, StyledPieChartTitle,
|
|
1788
|
+
export { ColorTheme, HorizontalBarChart, HorizontalBarChartSize, HorizontalBarChartTheme, HorizontalBarChartTooltipVariant, PieChart, PieChartLabelVariant, PieChartSize, PieChartTheme, PieChartTooltipVariant, PieChartVariant, StyledHorizontalBarChart, StyledHorizontalBarChartAxisBottom, StyledHorizontalBarChartBar, StyledHorizontalBarChartCaption, StyledHorizontalBarChartEmptyText, StyledHorizontalBarChartTitle, StyledHorizontalBarChartTooltip, StyledPieChart, StyledPieChartArc, StyledPieChartCaption, StyledPieChartCenterText, StyledPieChartEmptyText, StyledPieChartLabel, StyledPieChartTitle, StyledPieChartTooltip, getColorScale, monochrome, scheme, successDangerScheme };
|
|
1271
1789
|
//# sourceMappingURL=index.js.map
|