@react-magma/charts 15.0.0-rc.5 → 16.0.0-next.1
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/dist/charts.js +303 -224
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +304 -225
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +2701 -1592
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +25 -0
- package/package.json +3 -3
- package/src/components/CarbonChart/CarbonChart.test.js +490 -15
- package/src/components/CarbonChart/CarbonChart.tsx +479 -290
- package/src/components/CarbonChart/CarbonChartArea.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +3 -1
- package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartLine.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartPie.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +1 -1
- package/src/components/CarbonChart/CarbonChartStep.stories.tsx +1 -1
- package/src/components/CarbonChart/carbon-charts.css +89 -87
- package/src/components/ChartTable/ChartFullscreenButton.tsx +7 -1
- package/src/components/ChartTable/ChartMoreOptionsButton.tsx +3 -0
- package/src/components/ChartTable/ChartTable.stories.tsx +140 -1
- package/src/components/ChartTable/{ChartTable.test.tsx → ChartTable.test.js} +3 -1
- package/src/components/ChartTable/ChartTableButton.tsx +7 -1
- package/src/components/ChartTable/ChartTableModal.tsx +1 -1
- package/dist/components/ChartTable/ChartTable.test.d.ts +0 -1
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
Announce,
|
|
28
28
|
DropdownDivider,
|
|
29
29
|
DropdownMenuItem,
|
|
30
|
+
InverseContext,
|
|
30
31
|
ThemeInterface,
|
|
31
32
|
ThemeContext,
|
|
32
33
|
useDeviceDetect,
|
|
@@ -111,6 +112,22 @@ export interface ChartToolbarConfig {
|
|
|
111
112
|
* @default 2
|
|
112
113
|
*/
|
|
113
114
|
titleLevel?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
115
|
+
/**
|
|
116
|
+
* Custom content rendered before the chart title.
|
|
117
|
+
*
|
|
118
|
+
* The content is placed inline in the title row and follows the same
|
|
119
|
+
* accessibility rules as `titleSuffix`.
|
|
120
|
+
*/
|
|
121
|
+
titlePrefix?: React.ReactNode;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Custom content rendered after the chart title and before toolbar actions.
|
|
125
|
+
*
|
|
126
|
+
* The content is placed inline in the title row and renders outside the
|
|
127
|
+
* heading element to preserve `options.title` as the heading's accessible name.
|
|
128
|
+
* Useful for patterns like Tooltip + IconButton.
|
|
129
|
+
*/
|
|
130
|
+
titleSuffix?: React.ReactNode;
|
|
114
131
|
}
|
|
115
132
|
|
|
116
133
|
export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
@@ -139,6 +156,16 @@ export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
139
156
|
* toolbar is automatically disabled.
|
|
140
157
|
*/
|
|
141
158
|
chartToolbar?: ChartToolbarConfig;
|
|
159
|
+
/**
|
|
160
|
+
* Custom content rendered below the toolbar row and above the chart itself,
|
|
161
|
+
* for example a filter. Requires `chartToolbar`; ignored without it.
|
|
162
|
+
*
|
|
163
|
+
* Providing this lays the toolbar out in normal flow instead of overlaying
|
|
164
|
+
* the single row Carbon reserves for its title, so the rendered height
|
|
165
|
+
* becomes toolbar + content + chart rather than the chart box alone. Set
|
|
166
|
+
* `options.height` so the chart still has a definite height of its own.
|
|
167
|
+
*/
|
|
168
|
+
additionalContent?: React.ReactNode;
|
|
142
169
|
}
|
|
143
170
|
|
|
144
171
|
const ChartContentWrapper = styled.div`
|
|
@@ -147,6 +174,7 @@ const ChartContentWrapper = styled.div`
|
|
|
147
174
|
`;
|
|
148
175
|
|
|
149
176
|
const FullscreenRoot = styled.div<{
|
|
177
|
+
isFlowLayout?: boolean;
|
|
150
178
|
isInverse?: boolean;
|
|
151
179
|
theme: ThemeInterface;
|
|
152
180
|
}>`
|
|
@@ -157,11 +185,36 @@ const FullscreenRoot = styled.div<{
|
|
|
157
185
|
&:-webkit-full-screen {
|
|
158
186
|
background: ${props =>
|
|
159
187
|
props.isInverse
|
|
160
|
-
? props.theme.colors.
|
|
188
|
+
? props.theme.colors.indigo700
|
|
161
189
|
: props.theme.colors.neutral100};
|
|
190
|
+
|
|
191
|
+
${props =>
|
|
192
|
+
props.isFlowLayout
|
|
193
|
+
? `
|
|
194
|
+
box-sizing: border-box;
|
|
195
|
+
display: flex;
|
|
196
|
+
flex-direction: column;
|
|
197
|
+
padding: 2em;
|
|
198
|
+
|
|
199
|
+
.carbon-chart-wrapper,
|
|
200
|
+
.carbon-chart-content {
|
|
201
|
+
display: flex;
|
|
202
|
+
flex: 1 1 auto;
|
|
203
|
+
flex-direction: column;
|
|
204
|
+
min-height: 0;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.cds--chart-holder {
|
|
208
|
+
flex: 1 1 auto;
|
|
209
|
+
height: auto !important;
|
|
210
|
+
min-height: 0;
|
|
211
|
+
}
|
|
212
|
+
`
|
|
213
|
+
: `
|
|
162
214
|
.cds--chart-holder {
|
|
163
215
|
height: 100vh !important;
|
|
164
216
|
}
|
|
217
|
+
`}
|
|
165
218
|
}
|
|
166
219
|
`;
|
|
167
220
|
|
|
@@ -191,7 +244,7 @@ const CarbonChartWrapper = styled.div<{
|
|
|
191
244
|
&:-webkit-full-screen {
|
|
192
245
|
background: ${props =>
|
|
193
246
|
props.isInverse
|
|
194
|
-
? props.theme.colors.
|
|
247
|
+
? props.theme.colors.indigo700
|
|
195
248
|
: props.theme.colors.neutral100};
|
|
196
249
|
|
|
197
250
|
.cds--chart-holder {
|
|
@@ -199,13 +252,24 @@ const CarbonChartWrapper = styled.div<{
|
|
|
199
252
|
}
|
|
200
253
|
}
|
|
201
254
|
|
|
255
|
+
.cds--chart-holder.filled,
|
|
256
|
+
.cds--chart-holder.filled .cds--cc--chart-wrapper {
|
|
257
|
+
background-color: ${props =>
|
|
258
|
+
props.isInverse
|
|
259
|
+
? props.theme.colors.indigo600
|
|
260
|
+
: props.theme.colors.neutral100};
|
|
261
|
+
}
|
|
262
|
+
|
|
202
263
|
.cds--data-table thead tr th {
|
|
203
264
|
background: ${props =>
|
|
204
|
-
props.isInverse ? props.theme.colors.
|
|
265
|
+
props.isInverse ? props.theme.colors.indigo700 : ''} !important;
|
|
205
266
|
}
|
|
206
267
|
.cds--data-table td,
|
|
207
|
-
.cds--data-table
|
|
208
|
-
color: ${props =>
|
|
268
|
+
.cds--data-table th {
|
|
269
|
+
color: ${props =>
|
|
270
|
+
props.isInverse
|
|
271
|
+
? props.theme.colors.neutral100
|
|
272
|
+
: props.theme.colors.brand.navy};
|
|
209
273
|
}
|
|
210
274
|
.cds--data-table tbody tr,
|
|
211
275
|
.cds--data-table tbody tr td,
|
|
@@ -222,7 +286,7 @@ const CarbonChartWrapper = styled.div<{
|
|
|
222
286
|
color: ${props =>
|
|
223
287
|
props.isInverse
|
|
224
288
|
? props.theme.colors.neutral100
|
|
225
|
-
: props.theme.colors.
|
|
289
|
+
: props.theme.colors.brand.navy};
|
|
226
290
|
max-width: 142px;
|
|
227
291
|
white-space: normal;
|
|
228
292
|
}
|
|
@@ -230,10 +294,10 @@ const CarbonChartWrapper = styled.div<{
|
|
|
230
294
|
.cds--modal-container {
|
|
231
295
|
clip-path: inset(0% 0% 0% 0% round ${props => props.theme.borderRadius});
|
|
232
296
|
background: ${props =>
|
|
233
|
-
props.isInverse ? props.theme.colors.
|
|
297
|
+
props.isInverse ? props.theme.colors.indigo700 : ''};
|
|
234
298
|
.cds--data-table th {
|
|
235
299
|
background: ${props =>
|
|
236
|
-
props.isInverse ? props.theme.colors.
|
|
300
|
+
props.isInverse ? props.theme.colors.indigo600 : ''};
|
|
237
301
|
}
|
|
238
302
|
.cds--data-table td {
|
|
239
303
|
border-top: 1px solid
|
|
@@ -250,7 +314,7 @@ const CarbonChartWrapper = styled.div<{
|
|
|
250
314
|
}
|
|
251
315
|
.cds--data-table tr:hover td {
|
|
252
316
|
background: ${props =>
|
|
253
|
-
props.isInverse ? props.theme.colors.
|
|
317
|
+
props.isInverse ? props.theme.colors.indigo600 : ''};
|
|
254
318
|
}
|
|
255
319
|
}
|
|
256
320
|
|
|
@@ -258,13 +322,28 @@ const CarbonChartWrapper = styled.div<{
|
|
|
258
322
|
.chart-holder div,
|
|
259
323
|
.chart-holder text,
|
|
260
324
|
.cds--cc--axes g.axis .axis-title,
|
|
261
|
-
.cds--cc--title p.title,
|
|
262
325
|
.cds--cc--axes g.axis g.tick text {
|
|
263
326
|
font-family: ${props => props.theme.bodyFont} !important;
|
|
264
327
|
color: ${props =>
|
|
265
328
|
props.isInverse
|
|
266
329
|
? props.theme.colors.neutral100
|
|
267
|
-
: props.theme.colors.
|
|
330
|
+
: props.theme.colors.brand.navy};
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
.chart-holder text,
|
|
334
|
+
.cds--cc--axes g.axis .axis-title,
|
|
335
|
+
.cds--cc--axes g.axis g.tick text {
|
|
336
|
+
fill: ${props =>
|
|
337
|
+
props.isInverse
|
|
338
|
+
? props.theme.colors.neutral100
|
|
339
|
+
: props.theme.colors.brand.navy} !important;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
.cds--cc--title p.title {
|
|
343
|
+
color: ${props =>
|
|
344
|
+
props.isInverse
|
|
345
|
+
? props.theme.colors.neutral100
|
|
346
|
+
: props.theme.colors.brand.navy} !important;
|
|
268
347
|
}
|
|
269
348
|
|
|
270
349
|
.cds--cc--axes {
|
|
@@ -351,28 +430,28 @@ const CarbonChartWrapper = styled.div<{
|
|
|
351
430
|
1px 0px 0px
|
|
352
431
|
${props =>
|
|
353
432
|
props.isInverse
|
|
354
|
-
? props.theme.colors.
|
|
433
|
+
? props.theme.colors.indigo600
|
|
355
434
|
: props.theme.colors.neutral100}
|
|
356
435
|
)
|
|
357
436
|
drop-shadow(
|
|
358
437
|
-1px 0px 0px
|
|
359
438
|
${props =>
|
|
360
439
|
props.isInverse
|
|
361
|
-
? props.theme.colors.
|
|
440
|
+
? props.theme.colors.indigo600
|
|
362
441
|
: props.theme.colors.neutral100}
|
|
363
442
|
)
|
|
364
443
|
drop-shadow(
|
|
365
444
|
0px 1px 0px
|
|
366
445
|
${props =>
|
|
367
446
|
props.isInverse
|
|
368
|
-
? props.theme.colors.
|
|
447
|
+
? props.theme.colors.indigo600
|
|
369
448
|
: props.theme.colors.neutral100}
|
|
370
449
|
)
|
|
371
450
|
drop-shadow(
|
|
372
451
|
0px -1px 0px
|
|
373
452
|
${props =>
|
|
374
453
|
props.isInverse
|
|
375
|
-
? props.theme.colors.
|
|
454
|
+
? props.theme.colors.indigo600
|
|
376
455
|
: props.theme.colors.neutral100}
|
|
377
456
|
);
|
|
378
457
|
}
|
|
@@ -383,28 +462,28 @@ const CarbonChartWrapper = styled.div<{
|
|
|
383
462
|
1px 0px 0px
|
|
384
463
|
${props =>
|
|
385
464
|
props.isInverse
|
|
386
|
-
? props.theme.colors.
|
|
465
|
+
? props.theme.colors.indigo600
|
|
387
466
|
: props.theme.colors.neutral100}
|
|
388
467
|
)
|
|
389
468
|
drop-shadow(
|
|
390
469
|
-1px 0px 0px
|
|
391
470
|
${props =>
|
|
392
471
|
props.isInverse
|
|
393
|
-
? props.theme.colors.
|
|
472
|
+
? props.theme.colors.indigo600
|
|
394
473
|
: props.theme.colors.neutral100}
|
|
395
474
|
)
|
|
396
475
|
drop-shadow(
|
|
397
476
|
0px 1px 0px
|
|
398
477
|
${props =>
|
|
399
478
|
props.isInverse
|
|
400
|
-
? props.theme.colors.
|
|
479
|
+
? props.theme.colors.indigo600
|
|
401
480
|
: props.theme.colors.neutral100}
|
|
402
481
|
)
|
|
403
482
|
drop-shadow(
|
|
404
483
|
0px -1px 0px
|
|
405
484
|
${props =>
|
|
406
485
|
props.isInverse
|
|
407
|
-
? props.theme.colors.
|
|
486
|
+
? props.theme.colors.indigo600
|
|
408
487
|
: props.theme.colors.neutral100}
|
|
409
488
|
);
|
|
410
489
|
}
|
|
@@ -425,28 +504,28 @@ const CarbonChartWrapper = styled.div<{
|
|
|
425
504
|
1px 0px 0px
|
|
426
505
|
${props =>
|
|
427
506
|
props.isInverse
|
|
428
|
-
? props.theme.colors.
|
|
507
|
+
? props.theme.colors.indigo600
|
|
429
508
|
: props.theme.colors.neutral100}
|
|
430
509
|
)
|
|
431
510
|
drop-shadow(
|
|
432
511
|
-1px 0px 0px
|
|
433
512
|
${props =>
|
|
434
513
|
props.isInverse
|
|
435
|
-
? props.theme.colors.
|
|
514
|
+
? props.theme.colors.indigo600
|
|
436
515
|
: props.theme.colors.neutral100}
|
|
437
516
|
)
|
|
438
517
|
drop-shadow(
|
|
439
518
|
0px 1px 0px
|
|
440
519
|
${props =>
|
|
441
520
|
props.isInverse
|
|
442
|
-
? props.theme.colors.
|
|
521
|
+
? props.theme.colors.indigo600
|
|
443
522
|
: props.theme.colors.neutral100}
|
|
444
523
|
)
|
|
445
524
|
drop-shadow(
|
|
446
525
|
0px -1px 0px
|
|
447
526
|
${props =>
|
|
448
527
|
props.isInverse
|
|
449
|
-
? props.theme.colors.
|
|
528
|
+
? props.theme.colors.indigo600
|
|
450
529
|
: props.theme.colors.neutral100}
|
|
451
530
|
);
|
|
452
531
|
}
|
|
@@ -503,7 +582,7 @@ const CarbonChartWrapper = styled.div<{
|
|
|
503
582
|
.cds--btn--primary {
|
|
504
583
|
background: ${props =>
|
|
505
584
|
props.isInverse
|
|
506
|
-
? props.theme.colors.
|
|
585
|
+
? props.theme.colors.cyan500
|
|
507
586
|
: props.theme.colors.primary};
|
|
508
587
|
color: ${props => (props.isInverse ? props.theme.colors.neutral900 : '')};
|
|
509
588
|
}
|
|
@@ -516,6 +595,9 @@ const CarbonChartWrapper = styled.div<{
|
|
|
516
595
|
: props.theme.colors.focus} !important;
|
|
517
596
|
outline-offset: 0;
|
|
518
597
|
}
|
|
598
|
+
circle.dot:focus {
|
|
599
|
+
outline: none !important;
|
|
600
|
+
}
|
|
519
601
|
.cds--overflow-menu-options__btn:focus,
|
|
520
602
|
.cds--overflow-menu:focus,
|
|
521
603
|
.cds--overflow-menu__trigger:focus,
|
|
@@ -560,7 +642,7 @@ const CarbonChartWrapper = styled.div<{
|
|
|
560
642
|
.cds--modal-header {
|
|
561
643
|
background: ${props =>
|
|
562
644
|
props.isInverse
|
|
563
|
-
? props.theme.colors.
|
|
645
|
+
? props.theme.colors.indigo600
|
|
564
646
|
: props.theme.colors.neutral100};
|
|
565
647
|
margin-bottom: 0;
|
|
566
648
|
border-bottom: 1px solid
|
|
@@ -600,7 +682,7 @@ const CarbonChartWrapper = styled.div<{
|
|
|
600
682
|
: props.theme.colors.neutral300};
|
|
601
683
|
background: ${props =>
|
|
602
684
|
props.isInverse
|
|
603
|
-
? props.theme.colors.
|
|
685
|
+
? props.theme.colors.indigo600
|
|
604
686
|
: props.theme.colors.neutral100} !important;
|
|
605
687
|
}
|
|
606
688
|
.layout-child.header {
|
|
@@ -620,13 +702,27 @@ const CarbonChartWrapper = styled.div<{
|
|
|
620
702
|
overflow: visible;
|
|
621
703
|
}
|
|
622
704
|
|
|
705
|
+
circle.dot:focus {
|
|
706
|
+
outline: none;
|
|
707
|
+
stroke: ${props =>
|
|
708
|
+
props.isInverse
|
|
709
|
+
? props.theme.colors.focusInverse
|
|
710
|
+
: props.theme.colors.focus} !important;
|
|
711
|
+
stroke-width: 6px !important;
|
|
712
|
+
stroke-opacity: 1 !important;
|
|
713
|
+
paint-order: stroke fill;
|
|
714
|
+
}
|
|
715
|
+
|
|
623
716
|
.cds--cc--chart-wrapper text {
|
|
624
717
|
font-size: ${props => props.theme.typeScale.size02.fontSize};
|
|
625
718
|
}
|
|
626
719
|
|
|
627
720
|
g.center text,
|
|
628
721
|
.pie-label {
|
|
629
|
-
fill: ${props =>
|
|
722
|
+
fill: ${props =>
|
|
723
|
+
props.isInverse
|
|
724
|
+
? props.theme.colors.neutral100
|
|
725
|
+
: props.theme.colors.brand.navy};
|
|
630
726
|
}
|
|
631
727
|
|
|
632
728
|
// Zoom responsive tweaks
|
|
@@ -663,7 +759,13 @@ interface ColorsObject {
|
|
|
663
759
|
[key: string]: string;
|
|
664
760
|
}
|
|
665
761
|
|
|
762
|
+
type ExtendedChartOptions = ChartOptions & {
|
|
763
|
+
title?: string;
|
|
764
|
+
colors?: string[];
|
|
765
|
+
};
|
|
766
|
+
|
|
666
767
|
const ToolbarWrapper = styled.div<{
|
|
768
|
+
isFlowLayout?: boolean;
|
|
667
769
|
isFullscreen?: boolean;
|
|
668
770
|
isInverse?: boolean;
|
|
669
771
|
theme: ThemeInterface;
|
|
@@ -671,27 +773,19 @@ const ToolbarWrapper = styled.div<{
|
|
|
671
773
|
align-items: center;
|
|
672
774
|
display: flex;
|
|
673
775
|
justify-content: space-between;
|
|
674
|
-
left: ${props => (props.isFullscreen ? '2em' : '0')};
|
|
675
|
-
position: absolute;
|
|
676
|
-
right: ${props => (props.isFullscreen ? '2em' : '0')};
|
|
677
|
-
top: ${props => (props.isFullscreen ? '2em' : '0')};
|
|
678
776
|
z-index: 2;
|
|
679
777
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
: props.theme.colors.focus};
|
|
692
|
-
outline-offset: 0;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
778
|
+
${props =>
|
|
779
|
+
props.isFlowLayout
|
|
780
|
+
? `
|
|
781
|
+
position: relative;
|
|
782
|
+
`
|
|
783
|
+
: `
|
|
784
|
+
left: ${props.isFullscreen ? '2em' : '0'};
|
|
785
|
+
position: absolute;
|
|
786
|
+
right: ${props.isFullscreen ? '2em' : '0'};
|
|
787
|
+
top: ${props.isFullscreen ? '2em' : '0'};
|
|
788
|
+
`}
|
|
695
789
|
`;
|
|
696
790
|
|
|
697
791
|
const ChartTitle = styled.h2<{
|
|
@@ -707,7 +801,23 @@ const ChartTitle = styled.h2<{
|
|
|
707
801
|
color: ${props =>
|
|
708
802
|
props.isInverse
|
|
709
803
|
? props.theme.colors.neutral100
|
|
710
|
-
: props.theme.colors.
|
|
804
|
+
: props.theme.colors.brand.navy} !important;
|
|
805
|
+
`;
|
|
806
|
+
|
|
807
|
+
const TitleGroup = styled.div<{ theme: ThemeInterface }>`
|
|
808
|
+
align-items: center;
|
|
809
|
+
display: flex;
|
|
810
|
+
gap: ${props => props.theme.spaceScale.spacing02};
|
|
811
|
+
min-width: 0;
|
|
812
|
+
`;
|
|
813
|
+
|
|
814
|
+
const TitleSlot = styled.div`
|
|
815
|
+
align-items: center;
|
|
816
|
+
display: flex;
|
|
817
|
+
`;
|
|
818
|
+
|
|
819
|
+
const ChartSlot = styled.div<{ theme: ThemeInterface }>`
|
|
820
|
+
margin: ${props => props.theme.spaceScale.spacing05} 0 0;
|
|
711
821
|
`;
|
|
712
822
|
|
|
713
823
|
const ToolbarActions = styled.div<{ theme: ThemeInterface }>`
|
|
@@ -779,192 +889,83 @@ function downloadCsv(dataSet: Array<Record<string, unknown>>, title: string) {
|
|
|
779
889
|
URL.revokeObjectURL(url);
|
|
780
890
|
}
|
|
781
891
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
target.setAttribute(
|
|
787
|
-
'style',
|
|
788
|
-
Array.from(computed)
|
|
789
|
-
.map(prop => `${prop}:${computed.getPropertyValue(prop)}`)
|
|
790
|
-
.join(';')
|
|
791
|
-
);
|
|
792
|
-
}
|
|
793
|
-
for (let i = 0; i < source.children.length; i++) {
|
|
794
|
-
if (target.children[i]) {
|
|
795
|
-
inlineStyles(source.children[i], target.children[i]);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
interface LegendItem {
|
|
801
|
-
label: string;
|
|
802
|
-
color: string;
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
function readLegendItems(wrapper: HTMLElement): LegendItem[] {
|
|
806
|
-
const items: LegendItem[] = [];
|
|
807
|
-
|
|
808
|
-
wrapper.querySelectorAll('.legend-item').forEach(item => {
|
|
809
|
-
const checkbox = item.querySelector<HTMLElement>('.checkbox');
|
|
810
|
-
const label = item.querySelector('p');
|
|
811
|
-
|
|
812
|
-
if (checkbox && label) {
|
|
813
|
-
items.push({
|
|
814
|
-
color: checkbox.style.background || checkbox.style.backgroundColor,
|
|
815
|
-
label: label.textContent || '',
|
|
816
|
-
});
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
|
|
820
|
-
return items;
|
|
892
|
+
interface CarbonChartCore {
|
|
893
|
+
services?: {
|
|
894
|
+
domUtils?: { exportToPNG: () => void; exportToJPG: () => void };
|
|
895
|
+
};
|
|
821
896
|
}
|
|
822
897
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
items: LegendItem[],
|
|
826
|
-
startY: number,
|
|
827
|
-
canvasWidth: number,
|
|
828
|
-
scale: number
|
|
829
|
-
) {
|
|
830
|
-
const fontSize = 13 * scale;
|
|
831
|
-
const swatchSize = 12 * scale;
|
|
832
|
-
const gap = 8 * scale;
|
|
833
|
-
const itemGap = 16 * scale;
|
|
834
|
-
const paddingX = 16 * scale;
|
|
835
|
-
|
|
836
|
-
ctx.font = `${fontSize}px sans-serif`;
|
|
837
|
-
ctx.textBaseline = 'middle';
|
|
838
|
-
|
|
839
|
-
let x = paddingX;
|
|
840
|
-
let y = startY;
|
|
841
|
-
|
|
842
|
-
for (const item of items) {
|
|
843
|
-
const textWidth = ctx.measureText(item.label).width;
|
|
844
|
-
const itemWidth = swatchSize + gap + textWidth + itemGap;
|
|
845
|
-
|
|
846
|
-
if (x + itemWidth > canvasWidth - paddingX && x > paddingX) {
|
|
847
|
-
x = paddingX;
|
|
848
|
-
y += fontSize + gap;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
ctx.fillStyle = item.color;
|
|
852
|
-
ctx.fillRect(x, y - swatchSize / 2, swatchSize, swatchSize);
|
|
853
|
-
|
|
854
|
-
ctx.fillStyle = '#161616';
|
|
855
|
-
ctx.fillText(item.label, x + swatchSize + gap, y);
|
|
856
|
-
|
|
857
|
-
x += itemWidth;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
return y + fontSize + gap;
|
|
898
|
+
interface CarbonChartComponent {
|
|
899
|
+
chart?: CarbonChartCore;
|
|
861
900
|
}
|
|
862
901
|
|
|
863
|
-
function
|
|
864
|
-
|
|
865
|
-
|
|
902
|
+
function exportCarbonChartImage(
|
|
903
|
+
chart: CarbonChartCore | null | undefined,
|
|
904
|
+
toolbarWrapper: Element | null | undefined,
|
|
866
905
|
format: 'png' | 'jpg'
|
|
867
906
|
) {
|
|
868
|
-
const
|
|
869
|
-
|
|
870
|
-
if (!wrapper) return;
|
|
871
|
-
const svg = wrapper.querySelector('svg.layout-svg-wrapper');
|
|
872
|
-
|
|
873
|
-
if (!svg) return;
|
|
907
|
+
const domUtils = chart?.services?.domUtils;
|
|
874
908
|
|
|
875
|
-
|
|
876
|
-
const legendItems = readLegendItems(wrapper);
|
|
877
|
-
const scale = 2;
|
|
909
|
+
if (!domUtils) return;
|
|
878
910
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
const fontSize = 13 * scale;
|
|
883
|
-
const swatchSize = 12 * scale;
|
|
884
|
-
const gap = 8 * scale;
|
|
885
|
-
const itemGap = 16 * scale;
|
|
886
|
-
const paddingX = 16 * scale;
|
|
887
|
-
const canvasWidth = svgRect.width * scale;
|
|
911
|
+
const magmaWrapper = toolbarWrapper?.classList.contains('has-magma-toolbar')
|
|
912
|
+
? toolbarWrapper
|
|
913
|
+
: null;
|
|
888
914
|
|
|
889
|
-
|
|
915
|
+
magmaWrapper?.classList.remove('has-magma-toolbar');
|
|
890
916
|
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
const textWidth = tempCtx.measureText(item.label).width;
|
|
898
|
-
const itemWidth = swatchSize + gap + textWidth + itemGap;
|
|
917
|
+
let restored = false;
|
|
918
|
+
const restore = () => {
|
|
919
|
+
if (restored) return;
|
|
920
|
+
restored = true;
|
|
921
|
+
magmaWrapper?.classList.add('has-magma-toolbar');
|
|
922
|
+
};
|
|
899
923
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
924
|
+
try {
|
|
925
|
+
if (format === 'jpg') {
|
|
926
|
+
domUtils.exportToJPG();
|
|
927
|
+
} else {
|
|
928
|
+
domUtils.exportToPNG();
|
|
905
929
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
clone.setAttribute('width', String(svgRect.width));
|
|
915
|
-
clone.setAttribute('height', String(svgRect.height));
|
|
916
|
-
clone.setAttribute('viewBox', `0 0 ${svgRect.width} ${svgRect.height}`);
|
|
917
|
-
clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
918
|
-
|
|
919
|
-
inlineStyles(svg, clone);
|
|
920
|
-
|
|
921
|
-
const serializer = new XMLSerializer();
|
|
922
|
-
const svgString = serializer.serializeToString(clone);
|
|
923
|
-
const svgBlob = new Blob([svgString], {
|
|
924
|
-
type: 'image/svg+xml;charset=utf-8',
|
|
925
|
-
});
|
|
926
|
-
const url = URL.createObjectURL(svgBlob);
|
|
927
|
-
|
|
928
|
-
const mimeType = format === 'jpg' ? 'image/jpeg' : 'image/png';
|
|
929
|
-
const ext = format === 'jpg' ? 'jpg' : 'png';
|
|
930
|
-
|
|
931
|
-
const img = new Image();
|
|
932
|
-
|
|
933
|
-
img.onload = () => {
|
|
934
|
-
const canvas = document.createElement('canvas');
|
|
935
|
-
|
|
936
|
-
canvas.width = width;
|
|
937
|
-
canvas.height = height;
|
|
938
|
-
const ctx = canvas.getContext('2d');
|
|
939
|
-
|
|
940
|
-
if (!ctx) return;
|
|
941
|
-
|
|
942
|
-
ctx.fillStyle = '#ffffff';
|
|
943
|
-
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
944
|
-
ctx.drawImage(img, 0, 0, svgRect.width * scale, svgRect.height * scale);
|
|
945
|
-
URL.revokeObjectURL(url);
|
|
946
|
-
|
|
947
|
-
if (legendItems.length > 0) {
|
|
948
|
-
drawLegend(ctx, legendItems, svgRect.height * scale + gap, width, scale);
|
|
930
|
+
} catch (error) {
|
|
931
|
+
console.warn('Carbon chart image export failed', error);
|
|
932
|
+
} finally {
|
|
933
|
+
// Re-add before the next paint so the title swap is never visible on
|
|
934
|
+
// screen; the timeout is only a fallback for when requestAnimationFrame is
|
|
935
|
+
// paused (e.g. the tab is in the background).
|
|
936
|
+
if (typeof requestAnimationFrame === 'function') {
|
|
937
|
+
requestAnimationFrame(restore);
|
|
949
938
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
if (!blob) return;
|
|
953
|
-
const imgUrl = URL.createObjectURL(blob);
|
|
954
|
-
const a = document.createElement('a');
|
|
955
|
-
|
|
956
|
-
a.href = imgUrl;
|
|
957
|
-
a.download = `${title || 'chart'}.${ext}`;
|
|
958
|
-
a.click();
|
|
959
|
-
URL.revokeObjectURL(imgUrl);
|
|
960
|
-
}, mimeType);
|
|
961
|
-
};
|
|
962
|
-
img.src = url;
|
|
939
|
+
setTimeout(restore, 1000);
|
|
940
|
+
}
|
|
963
941
|
}
|
|
964
942
|
|
|
943
|
+
const ALL_CHARTS: Record<CarbonChartType, React.ComponentType<any>> = {
|
|
944
|
+
area: AreaChart,
|
|
945
|
+
areaStacked: StackedAreaChart,
|
|
946
|
+
bar: SimpleBarChart,
|
|
947
|
+
barGrouped: GroupedBarChart,
|
|
948
|
+
barStacked: StackedBarChart,
|
|
949
|
+
donut: DonutChart,
|
|
950
|
+
line: LineChart,
|
|
951
|
+
lollipop: LollipopChart,
|
|
952
|
+
pie: PieChart,
|
|
953
|
+
radar: RadarChart,
|
|
954
|
+
boxplot: BoxplotChart,
|
|
955
|
+
bubble: BubbleChart,
|
|
956
|
+
bullet: BulletChart,
|
|
957
|
+
gauge: GaugeChart,
|
|
958
|
+
histogram: HistogramChart,
|
|
959
|
+
meter: MeterChart,
|
|
960
|
+
scatter: ScatterChart,
|
|
961
|
+
combo: ComboChart,
|
|
962
|
+
};
|
|
963
|
+
|
|
965
964
|
interface InternalToolbarProps {
|
|
965
|
+
chartRef: React.MutableRefObject<CarbonChartComponent | null>;
|
|
966
966
|
config: ChartToolbarConfig;
|
|
967
967
|
dataSet: Array<Record<string, unknown>>;
|
|
968
|
+
isFlowLayout: boolean;
|
|
968
969
|
isInverse: boolean;
|
|
969
970
|
isTableOpen: boolean;
|
|
970
971
|
isFullscreen: boolean;
|
|
@@ -976,8 +977,10 @@ interface InternalToolbarProps {
|
|
|
976
977
|
}
|
|
977
978
|
|
|
978
979
|
function CarbonChartToolbar({
|
|
980
|
+
chartRef,
|
|
979
981
|
config,
|
|
980
982
|
dataSet,
|
|
983
|
+
isFlowLayout,
|
|
981
984
|
isInverse,
|
|
982
985
|
isTableOpen,
|
|
983
986
|
isFullscreen,
|
|
@@ -992,17 +995,28 @@ function CarbonChartToolbar({
|
|
|
992
995
|
const showFullscreen = config.fullscreen !== false;
|
|
993
996
|
const resolvedTitle = title || t.defaultTitle;
|
|
994
997
|
|
|
998
|
+
const exportImage = React.useCallback(
|
|
999
|
+
(format: 'png' | 'jpg') => {
|
|
1000
|
+
exportCarbonChartImage(
|
|
1001
|
+
chartRef.current?.chart,
|
|
1002
|
+
wrapperRef.current?.querySelector('.carbon-chart-wrapper'),
|
|
1003
|
+
format
|
|
1004
|
+
);
|
|
1005
|
+
},
|
|
1006
|
+
[chartRef, wrapperRef]
|
|
1007
|
+
);
|
|
1008
|
+
|
|
995
1009
|
const handleDownloadCsv = React.useCallback(() => {
|
|
996
1010
|
downloadCsv(dataSet, title);
|
|
997
1011
|
}, [dataSet, title]);
|
|
998
1012
|
|
|
999
1013
|
const handleDownloadPng = React.useCallback(() => {
|
|
1000
|
-
|
|
1001
|
-
}, [
|
|
1014
|
+
exportImage('png');
|
|
1015
|
+
}, [exportImage]);
|
|
1002
1016
|
|
|
1003
1017
|
const handleDownloadJpg = React.useCallback(() => {
|
|
1004
|
-
|
|
1005
|
-
}, [
|
|
1018
|
+
exportImage('jpg');
|
|
1019
|
+
}, [exportImage]);
|
|
1006
1020
|
|
|
1007
1021
|
const moreOptionsContent = (
|
|
1008
1022
|
<>
|
|
@@ -1026,17 +1040,26 @@ function CarbonChartToolbar({
|
|
|
1026
1040
|
|
|
1027
1041
|
return (
|
|
1028
1042
|
<ToolbarWrapper
|
|
1043
|
+
isFlowLayout={isFlowLayout}
|
|
1029
1044
|
isFullscreen={isFullscreen}
|
|
1030
1045
|
isInverse={isInverse}
|
|
1031
1046
|
theme={theme}
|
|
1032
1047
|
>
|
|
1033
|
-
<
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1048
|
+
<TitleGroup theme={theme}>
|
|
1049
|
+
{config.titlePrefix ? (
|
|
1050
|
+
<TitleSlot>{config.titlePrefix}</TitleSlot>
|
|
1051
|
+
) : null}
|
|
1052
|
+
<ChartTitle
|
|
1053
|
+
as={`h${config.titleLevel ?? 2}` as keyof JSX.IntrinsicElements}
|
|
1054
|
+
isInverse={isInverse}
|
|
1055
|
+
theme={theme}
|
|
1056
|
+
>
|
|
1057
|
+
{resolvedTitle}
|
|
1058
|
+
</ChartTitle>
|
|
1059
|
+
{config.titleSuffix ? (
|
|
1060
|
+
<TitleSlot>{config.titleSuffix}</TitleSlot>
|
|
1061
|
+
) : null}
|
|
1062
|
+
</TitleGroup>
|
|
1040
1063
|
<ToolbarActions theme={theme}>
|
|
1041
1064
|
{showTable && (
|
|
1042
1065
|
<ChartTableButton
|
|
@@ -1076,6 +1099,7 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1076
1099
|
type,
|
|
1077
1100
|
dataSet,
|
|
1078
1101
|
options,
|
|
1102
|
+
additionalContent,
|
|
1079
1103
|
ariaLabel,
|
|
1080
1104
|
chartToolbar,
|
|
1081
1105
|
...rest
|
|
@@ -1084,6 +1108,7 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1084
1108
|
const isInverse = useIsInverse(isInverseProp);
|
|
1085
1109
|
const toolbarI18n = useChartToolbarI18n();
|
|
1086
1110
|
const internalRef = React.useRef<HTMLDivElement | null>(null);
|
|
1111
|
+
const chartComponentRef = React.useRef<CarbonChartComponent | null>(null);
|
|
1087
1112
|
|
|
1088
1113
|
const [isTableOpen, setIsTableOpen] = React.useState(false);
|
|
1089
1114
|
const [isFullscreen, setIsFullscreen] = React.useState(false);
|
|
@@ -1110,6 +1135,8 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1110
1135
|
? chartToolbar.fullscreen !== false
|
|
1111
1136
|
: false;
|
|
1112
1137
|
|
|
1138
|
+
const isFlowLayout = Boolean(chartToolbar && additionalContent);
|
|
1139
|
+
|
|
1113
1140
|
const savedHeightRef = React.useRef<string>('');
|
|
1114
1141
|
|
|
1115
1142
|
React.useEffect(() => {
|
|
@@ -1123,7 +1150,7 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1123
1150
|
const chartHolder =
|
|
1124
1151
|
internalRef.current?.querySelector<HTMLElement>('.cds--chart-holder');
|
|
1125
1152
|
|
|
1126
|
-
if (chartHolder) {
|
|
1153
|
+
if (chartHolder && !isFlowLayout) {
|
|
1127
1154
|
if (isFs) {
|
|
1128
1155
|
savedHeightRef.current = chartHolder.style.height;
|
|
1129
1156
|
chartHolder.style.height = '100vh';
|
|
@@ -1135,9 +1162,17 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1135
1162
|
|
|
1136
1163
|
document.addEventListener('fullscreenchange', onFullscreenChange);
|
|
1137
1164
|
|
|
1138
|
-
return () =>
|
|
1165
|
+
return () => {
|
|
1139
1166
|
document.removeEventListener('fullscreenchange', onFullscreenChange);
|
|
1140
|
-
|
|
1167
|
+
// Restore height if the component unmounts while in fullscreen.
|
|
1168
|
+
const chartHolder =
|
|
1169
|
+
internalRef.current?.querySelector<HTMLElement>('.cds--chart-holder');
|
|
1170
|
+
|
|
1171
|
+
if (chartHolder && document.fullscreenElement) {
|
|
1172
|
+
chartHolder.style.height = savedHeightRef.current;
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1175
|
+
}, [fullscreenEnabled, isFlowLayout]);
|
|
1141
1176
|
|
|
1142
1177
|
const openTableModal = React.useCallback(
|
|
1143
1178
|
(event: React.MouseEvent<HTMLButtonElement>) => {
|
|
@@ -1149,9 +1184,9 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1149
1184
|
|
|
1150
1185
|
const closeTableModal = React.useCallback(() => {
|
|
1151
1186
|
setIsTableOpen(false);
|
|
1152
|
-
|
|
1187
|
+
requestAnimationFrame(() => {
|
|
1153
1188
|
lastTableTriggerRef.current?.focus();
|
|
1154
|
-
}
|
|
1189
|
+
});
|
|
1155
1190
|
}, []);
|
|
1156
1191
|
|
|
1157
1192
|
const toggleFullscreen = React.useCallback(() => {
|
|
@@ -1167,7 +1202,7 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1167
1202
|
}, []);
|
|
1168
1203
|
|
|
1169
1204
|
const chartTitle: string =
|
|
1170
|
-
(options as
|
|
1205
|
+
(options as ExtendedChartOptions).title || toolbarI18n.defaultTitle;
|
|
1171
1206
|
|
|
1172
1207
|
const legendLabel = `${ariaLabel || chartTitle}. ${toolbarI18n.legendInstructions}`;
|
|
1173
1208
|
|
|
@@ -1322,58 +1357,41 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1322
1357
|
}, [dataSet, chartTitle]);
|
|
1323
1358
|
|
|
1324
1359
|
useCarbonModalFocusManagement(internalRef);
|
|
1325
|
-
const allCharts = {
|
|
1326
|
-
area: AreaChart,
|
|
1327
|
-
areaStacked: StackedAreaChart,
|
|
1328
|
-
bar: SimpleBarChart,
|
|
1329
|
-
barGrouped: GroupedBarChart,
|
|
1330
|
-
barStacked: StackedBarChart,
|
|
1331
|
-
donut: DonutChart,
|
|
1332
|
-
line: LineChart,
|
|
1333
|
-
lollipop: LollipopChart,
|
|
1334
|
-
pie: PieChart,
|
|
1335
|
-
radar: RadarChart,
|
|
1336
|
-
boxplot: BoxplotChart,
|
|
1337
|
-
bubble: BubbleChart,
|
|
1338
|
-
bullet: BulletChart,
|
|
1339
|
-
gauge: GaugeChart,
|
|
1340
|
-
histogram: HistogramChart,
|
|
1341
|
-
meter: MeterChart,
|
|
1342
|
-
scatter: ScatterChart,
|
|
1343
|
-
combo: ComboChart,
|
|
1344
|
-
};
|
|
1345
1360
|
|
|
1346
|
-
|
|
1361
|
+
const colorScale = React.useMemo(() => {
|
|
1347
1362
|
const scaleColorsObj: ColorsObject = {};
|
|
1348
|
-
|
|
1349
|
-
const allGroups = dataSet.map(item => {
|
|
1350
|
-
return 'group' in item ? item['group'] : null;
|
|
1351
|
-
});
|
|
1352
|
-
const uniqueGroups = allGroups.filter(
|
|
1353
|
-
(g, index) => allGroups.indexOf(g) === index
|
|
1354
|
-
);
|
|
1355
|
-
const customColors = ((options as any).colors as string[]) || [];
|
|
1363
|
+
const customColors = (options as ExtendedChartOptions).colors || [];
|
|
1356
1364
|
const allColors = [...customColors, ...theme.chartColors];
|
|
1357
1365
|
const allInverseColors = [...customColors, ...theme.chartColorsInverse];
|
|
1366
|
+
const allGroups = dataSet.map(item =>
|
|
1367
|
+
'group' in item ? (item as Record<string, unknown>)['group'] : null
|
|
1368
|
+
);
|
|
1369
|
+
const uniqueGroups = Array.from(new Set(allGroups));
|
|
1370
|
+
|
|
1371
|
+
if (uniqueGroups.length <= allColors.length) {
|
|
1372
|
+
for (let i = 0; i < uniqueGroups.length; i++) {
|
|
1373
|
+
const group = uniqueGroups[i];
|
|
1358
1374
|
|
|
1359
|
-
|
|
1360
|
-
if (uniqueGroups.length <= allColors.length) {
|
|
1361
|
-
return (scaleColorsObj[group || ('null' as any)] = isInverse
|
|
1375
|
+
scaleColorsObj[String(group ?? 'null')] = isInverse
|
|
1362
1376
|
? allInverseColors[i]
|
|
1363
|
-
: allColors[i]
|
|
1377
|
+
: allColors[i];
|
|
1364
1378
|
}
|
|
1365
|
-
|
|
1366
|
-
return {};
|
|
1367
|
-
});
|
|
1379
|
+
}
|
|
1368
1380
|
|
|
1369
1381
|
return scaleColorsObj;
|
|
1370
|
-
}
|
|
1382
|
+
}, [
|
|
1383
|
+
dataSet,
|
|
1384
|
+
options,
|
|
1385
|
+
theme.chartColors,
|
|
1386
|
+
theme.chartColorsInverse,
|
|
1387
|
+
isInverse,
|
|
1388
|
+
]);
|
|
1371
1389
|
|
|
1372
1390
|
const newOptions = {
|
|
1373
1391
|
...options,
|
|
1374
1392
|
theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE,
|
|
1375
1393
|
color: {
|
|
1376
|
-
scale:
|
|
1394
|
+
scale: colorScale,
|
|
1377
1395
|
},
|
|
1378
1396
|
tooltip: {
|
|
1379
1397
|
...(options?.tooltip || {}),
|
|
@@ -1381,16 +1399,30 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1381
1399
|
type: 'none',
|
|
1382
1400
|
},
|
|
1383
1401
|
},
|
|
1384
|
-
...(chartToolbar
|
|
1402
|
+
...(chartToolbar
|
|
1403
|
+
? {
|
|
1404
|
+
toolbar: { enabled: false },
|
|
1405
|
+
title: chartTitle,
|
|
1406
|
+
...(options.fileDownload
|
|
1407
|
+
? {}
|
|
1408
|
+
: { fileDownload: { fileName: chartTitle } }),
|
|
1409
|
+
}
|
|
1410
|
+
: {}),
|
|
1385
1411
|
};
|
|
1386
1412
|
|
|
1387
|
-
const ChartType =
|
|
1413
|
+
const ChartType = ALL_CHARTS[type];
|
|
1388
1414
|
|
|
1389
1415
|
React.useEffect(() => {
|
|
1390
1416
|
const timer = setTimeout(() => {
|
|
1391
1417
|
if (internalRef.current) {
|
|
1392
1418
|
internalRef.current
|
|
1393
|
-
.querySelectorAll<SVGGElement>('g[aria-label]')
|
|
1419
|
+
.querySelectorAll<SVGGElement>('g.ruler[aria-label]')
|
|
1420
|
+
.forEach(g => {
|
|
1421
|
+
g.setAttribute('aria-hidden', 'true');
|
|
1422
|
+
});
|
|
1423
|
+
|
|
1424
|
+
internalRef.current
|
|
1425
|
+
.querySelectorAll<SVGGElement>('g[aria-label]:not(.ruler)')
|
|
1394
1426
|
.forEach(g => {
|
|
1395
1427
|
const role = g.getAttribute('role');
|
|
1396
1428
|
|
|
@@ -1406,6 +1438,30 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1406
1438
|
return () => clearTimeout(timer);
|
|
1407
1439
|
}, [type, dataSet]);
|
|
1408
1440
|
|
|
1441
|
+
React.useEffect(() => {
|
|
1442
|
+
const container = internalRef.current;
|
|
1443
|
+
|
|
1444
|
+
if (!container) return;
|
|
1445
|
+
|
|
1446
|
+
const hideRulerFromAT = () => {
|
|
1447
|
+
container
|
|
1448
|
+
.querySelectorAll<SVGGElement>('g.ruler[aria-label]')
|
|
1449
|
+
.forEach(g => {
|
|
1450
|
+
if (!g.hasAttribute('aria-hidden')) {
|
|
1451
|
+
g.setAttribute('aria-hidden', 'true');
|
|
1452
|
+
}
|
|
1453
|
+
});
|
|
1454
|
+
};
|
|
1455
|
+
|
|
1456
|
+
hideRulerFromAT();
|
|
1457
|
+
|
|
1458
|
+
const observer = new MutationObserver(hideRulerFromAT);
|
|
1459
|
+
|
|
1460
|
+
observer.observe(container, { childList: true, subtree: true });
|
|
1461
|
+
|
|
1462
|
+
return () => observer.disconnect();
|
|
1463
|
+
}, [type, dataSet]);
|
|
1464
|
+
|
|
1409
1465
|
React.useEffect(() => {
|
|
1410
1466
|
const wrapper = internalRef.current;
|
|
1411
1467
|
|
|
@@ -1467,12 +1523,126 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1467
1523
|
return () => observer.disconnect();
|
|
1468
1524
|
}, [type, dataSet]);
|
|
1469
1525
|
|
|
1470
|
-
|
|
1526
|
+
// Make Carbon Charts data points keyboard-focusable.
|
|
1527
|
+
React.useEffect(() => {
|
|
1528
|
+
const wrapper = internalRef.current;
|
|
1529
|
+
|
|
1530
|
+
if (!wrapper) return;
|
|
1531
|
+
|
|
1532
|
+
const stampDotTabIndex = () => {
|
|
1533
|
+
wrapper
|
|
1534
|
+
.querySelectorAll<SVGCircleElement>('circle.dot')
|
|
1535
|
+
.forEach(dot => {
|
|
1536
|
+
if (!dot.hasAttribute('tabindex')) {
|
|
1537
|
+
dot.setAttribute('tabindex', '0');
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1542
|
+
const isDot = (el: EventTarget | null): el is SVGCircleElement =>
|
|
1543
|
+
el instanceof Element &&
|
|
1544
|
+
el.nodeName.toLowerCase() === 'circle' &&
|
|
1545
|
+
el.classList.contains('dot');
|
|
1546
|
+
|
|
1547
|
+
const onFocusIn = (e: FocusEvent) => {
|
|
1548
|
+
if (!isDot(e.target)) return;
|
|
1549
|
+
const dot = e.target as SVGCircleElement;
|
|
1550
|
+
|
|
1551
|
+
const { left, top, width, height } = dot.getBoundingClientRect();
|
|
1552
|
+
const cx = left + width / 2;
|
|
1553
|
+
const cy = top + height / 2;
|
|
1554
|
+
|
|
1555
|
+
dot.dispatchEvent(
|
|
1556
|
+
new MouseEvent('mouseover', {
|
|
1557
|
+
bubbles: true,
|
|
1558
|
+
clientX: cx,
|
|
1559
|
+
clientY: cy,
|
|
1560
|
+
screenX: cx,
|
|
1561
|
+
screenY: cy,
|
|
1562
|
+
})
|
|
1563
|
+
);
|
|
1564
|
+
dot.dispatchEvent(
|
|
1565
|
+
new MouseEvent('mousemove', {
|
|
1566
|
+
bubbles: true,
|
|
1567
|
+
clientX: cx,
|
|
1568
|
+
clientY: cy,
|
|
1569
|
+
screenX: cx,
|
|
1570
|
+
screenY: cy,
|
|
1571
|
+
})
|
|
1572
|
+
);
|
|
1573
|
+
};
|
|
1574
|
+
|
|
1575
|
+
const onFocusOut = (e: FocusEvent) => {
|
|
1576
|
+
if (!isDot(e.target)) return;
|
|
1577
|
+
const dot = e.target;
|
|
1578
|
+
|
|
1579
|
+
// Keep tooltip context while Tab focus moves between chart points.
|
|
1580
|
+
if (isDot(e.relatedTarget)) {
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
dot.dispatchEvent(new MouseEvent('mouseout', { bubbles: true }));
|
|
1585
|
+
};
|
|
1586
|
+
|
|
1587
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
1588
|
+
if (!isDot(e.target)) return;
|
|
1589
|
+
if (e.key !== 'Enter' && e.key !== ' ') return;
|
|
1590
|
+
e.preventDefault();
|
|
1591
|
+
const dot = e.target;
|
|
1592
|
+
const { left, top, width, height } = dot.getBoundingClientRect();
|
|
1593
|
+
const cx = left + width / 2;
|
|
1594
|
+
const cy = top + height / 2;
|
|
1595
|
+
|
|
1596
|
+
dot.dispatchEvent(
|
|
1597
|
+
new MouseEvent('click', {
|
|
1598
|
+
bubbles: true,
|
|
1599
|
+
clientX: cx,
|
|
1600
|
+
clientY: cy,
|
|
1601
|
+
})
|
|
1602
|
+
);
|
|
1603
|
+
};
|
|
1604
|
+
|
|
1605
|
+
const rafId = requestAnimationFrame(() => {
|
|
1606
|
+
stampDotTabIndex();
|
|
1607
|
+
});
|
|
1608
|
+
|
|
1609
|
+
const dotObserver = new MutationObserver(() => {
|
|
1610
|
+
stampDotTabIndex();
|
|
1611
|
+
});
|
|
1612
|
+
|
|
1613
|
+
dotObserver.observe(wrapper, {
|
|
1614
|
+
childList: true,
|
|
1615
|
+
subtree: true,
|
|
1616
|
+
attributes: true,
|
|
1617
|
+
attributeFilter: ['class', 'style', 'tabindex'],
|
|
1618
|
+
});
|
|
1619
|
+
|
|
1620
|
+
wrapper.addEventListener('focusin', onFocusIn);
|
|
1621
|
+
wrapper.addEventListener('focusout', onFocusOut);
|
|
1622
|
+
wrapper.addEventListener('keydown', onKeyDown);
|
|
1623
|
+
|
|
1624
|
+
return () => {
|
|
1625
|
+
cancelAnimationFrame(rafId);
|
|
1626
|
+
dotObserver.disconnect();
|
|
1627
|
+
wrapper.removeEventListener('focusin', onFocusIn);
|
|
1628
|
+
wrapper.removeEventListener('focusout', onFocusOut);
|
|
1629
|
+
wrapper.removeEventListener('keydown', onKeyDown);
|
|
1630
|
+
};
|
|
1631
|
+
}, [type, dataSet]);
|
|
1632
|
+
|
|
1633
|
+
const groupsLength = Object.keys(colorScale).length;
|
|
1471
1634
|
|
|
1472
1635
|
const showTable = chartToolbar?.showAsTable !== false;
|
|
1473
1636
|
|
|
1637
|
+
if (!ChartType) return null;
|
|
1638
|
+
|
|
1474
1639
|
return (
|
|
1475
|
-
<FullscreenRoot
|
|
1640
|
+
<FullscreenRoot
|
|
1641
|
+
ref={mergedRef}
|
|
1642
|
+
isFlowLayout={isFlowLayout}
|
|
1643
|
+
isInverse={isInverse}
|
|
1644
|
+
theme={theme}
|
|
1645
|
+
>
|
|
1476
1646
|
<VisuallyHidden>
|
|
1477
1647
|
<Announce>{legendAnnouncement}</Announce>
|
|
1478
1648
|
</VisuallyHidden>
|
|
@@ -1483,29 +1653,48 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1483
1653
|
data-testid={testId}
|
|
1484
1654
|
isInverse={isInverse}
|
|
1485
1655
|
theme={theme}
|
|
1486
|
-
className={`carbon-chart-wrapper${
|
|
1656
|
+
className={`carbon-chart-wrapper${
|
|
1657
|
+
chartToolbar ? ' has-magma-toolbar' : ''
|
|
1658
|
+
}`}
|
|
1487
1659
|
groupsLength={groupsLength < 6 ? groupsLength : 14}
|
|
1488
1660
|
role="region"
|
|
1489
1661
|
aria-label={ariaLabel || chartTitle}
|
|
1490
1662
|
aria-roledescription="chart"
|
|
1491
1663
|
{...rest}
|
|
1492
1664
|
>
|
|
1493
|
-
<ChartContentWrapper>
|
|
1665
|
+
<ChartContentWrapper className="carbon-chart-content">
|
|
1494
1666
|
{chartToolbar && (
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1667
|
+
/*
|
|
1668
|
+
* Slot content comes from the adopter, so it resolves
|
|
1669
|
+
* `isInverse` from context rather than from our prop. Without
|
|
1670
|
+
* this provider a Magma component in a title slot would stay
|
|
1671
|
+
* light on an inverse chart.
|
|
1672
|
+
*/
|
|
1673
|
+
<InverseContext.Provider value={{ isInverse }}>
|
|
1674
|
+
<CarbonChartToolbar
|
|
1675
|
+
chartRef={chartComponentRef}
|
|
1676
|
+
config={chartToolbar}
|
|
1677
|
+
dataSet={dataSet as Array<Record<string, unknown>>}
|
|
1678
|
+
isFlowLayout={isFlowLayout}
|
|
1679
|
+
isInverse={isInverse}
|
|
1680
|
+
isTableOpen={isTableOpen}
|
|
1681
|
+
isFullscreen={isFullscreen}
|
|
1682
|
+
onOpenTable={openTableModal}
|
|
1683
|
+
onToggleFullscreen={toggleFullscreen}
|
|
1684
|
+
theme={theme}
|
|
1685
|
+
title={chartTitle}
|
|
1686
|
+
wrapperRef={internalRef}
|
|
1687
|
+
/>
|
|
1688
|
+
{isFlowLayout && (
|
|
1689
|
+
<ChartSlot theme={theme}>{additionalContent}</ChartSlot>
|
|
1690
|
+
)}
|
|
1691
|
+
</InverseContext.Provider>
|
|
1507
1692
|
)}
|
|
1508
|
-
<ChartType
|
|
1693
|
+
<ChartType
|
|
1694
|
+
ref={chartComponentRef}
|
|
1695
|
+
data={dataSet}
|
|
1696
|
+
options={newOptions}
|
|
1697
|
+
/>
|
|
1509
1698
|
</ChartContentWrapper>
|
|
1510
1699
|
</CarbonChartWrapper>
|
|
1511
1700
|
{chartToolbar && showTable && (
|