@react-magma/charts 14.2.0 → 15.0.0-next.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.
Files changed (89) hide show
  1. package/dist/charts.js +1625 -187
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +1627 -190
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +49219 -28201
  6. package/dist/charts.umd.js.map +1 -1
  7. package/dist/components/CarbonChart/CarbonChart.d.ts +1 -1
  8. package/dist/components/CarbonChart/CarbonChartArea.stories.d.ts +310 -0
  9. package/dist/components/CarbonChart/CarbonChartAreaStacked.stories.d.ts +136 -0
  10. package/dist/components/CarbonChart/CarbonChartBar.stories.d.ts +232 -0
  11. package/dist/components/CarbonChart/CarbonChartBarFloating.stories.d.ts +82 -0
  12. package/dist/components/CarbonChart/CarbonChartBarGrouped.stories.d.ts +234 -0
  13. package/dist/components/CarbonChart/CarbonChartBarStacked.stories.d.ts +266 -0
  14. package/dist/components/CarbonChart/CarbonChartBoxplot.stories.d.ts +53 -0
  15. package/dist/components/CarbonChart/CarbonChartBubble.stories.d.ts +196 -0
  16. package/dist/components/CarbonChart/CarbonChartBullet.stories.d.ts +35 -0
  17. package/dist/components/CarbonChart/CarbonChartCombo.stories.d.ts +580 -0
  18. package/dist/components/CarbonChart/CarbonChartDonut.stories.d.ts +120 -0
  19. package/dist/components/CarbonChart/CarbonChartGauge.stories.d.ts +43 -0
  20. package/dist/components/CarbonChart/CarbonChartHistogram.stories.d.ts +89 -0
  21. package/dist/components/CarbonChart/CarbonChartLine.stories.d.ts +577 -0
  22. package/dist/components/CarbonChart/CarbonChartLollipop.stories.d.ts +55 -0
  23. package/dist/components/CarbonChart/CarbonChartMeter.stories.d.ts +127 -0
  24. package/dist/components/CarbonChart/CarbonChartPie.stories.d.ts +101 -0
  25. package/dist/components/CarbonChart/CarbonChartRadar.stories.d.ts +98 -0
  26. package/dist/components/CarbonChart/CarbonChartScatter.stories.d.ts +173 -0
  27. package/dist/components/CarbonChart/CarbonChartSparkline.stories.d.ts +51 -0
  28. package/dist/components/CarbonChart/CarbonChartStep.stories.d.ts +38 -0
  29. package/dist/components/ChartTable/ChartTable.stories.d.ts +166 -0
  30. package/dist/components/LineChart/Chart.d.ts +27 -0
  31. package/dist/components/LineChart/ChartDataTable.d.ts +17 -0
  32. package/dist/components/LineChart/CustomAxisComponent.d.ts +3 -0
  33. package/dist/components/LineChart/CustomPointComponent.d.ts +17 -0
  34. package/dist/components/LineChart/DataTable.d.ts +5 -0
  35. package/dist/components/LineChart/GraphTooltip.d.ts +3 -0
  36. package/dist/components/LineChart/LegendButton.d.ts +6 -0
  37. package/dist/components/LineChart/LineChart.d.ts +67 -0
  38. package/dist/components/LineChart/LineChart.stories.d.ts +113 -0
  39. package/dist/components/LineChart/index.d.ts +1 -0
  40. package/dist/components/LineChart/magma-charts.d.ts +1 -0
  41. package/dist/index.d.ts +1 -0
  42. package/package.json +19 -22
  43. package/src/components/CarbonChart/CarbonChart.test.js +185 -164
  44. package/src/components/CarbonChart/CarbonChart.tsx +79 -29
  45. package/src/components/CarbonChart/CarbonChartArea.stories.tsx +5 -3
  46. package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +5 -3
  47. package/src/components/CarbonChart/CarbonChartBar.stories.tsx +5 -3
  48. package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +5 -3
  49. package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +5 -3
  50. package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +5 -3
  51. package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +5 -3
  52. package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +5 -3
  53. package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +5 -3
  54. package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +5 -3
  55. package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +5 -3
  56. package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +5 -3
  57. package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +5 -3
  58. package/src/components/CarbonChart/CarbonChartLine.stories.tsx +5 -3
  59. package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +5 -3
  60. package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +5 -3
  61. package/src/components/CarbonChart/CarbonChartPie.stories.tsx +5 -3
  62. package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +5 -3
  63. package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +5 -3
  64. package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +5 -3
  65. package/src/components/CarbonChart/CarbonChartStep.stories.tsx +5 -3
  66. package/src/components/ChartTable/ChartDataTable.tsx +0 -3
  67. package/src/components/ChartTable/ChartMoreOptionsButton.tsx +0 -1
  68. package/src/components/ChartTable/ChartTable.test.js +0 -8
  69. package/src/components/ChartTable/ChartTableButton.tsx +0 -1
  70. package/src/components/ChartTable/ChartToolbar.tsx +0 -1
  71. package/src/components/ChartTable/chartToolbarI18n.ts +1 -1
  72. package/src/components/LineChart/Chart.tsx +241 -0
  73. package/src/components/LineChart/ChartDataTable.test.js +165 -0
  74. package/src/components/LineChart/ChartDataTable.tsx +135 -0
  75. package/src/components/LineChart/CustomAxisComponent.tsx +30 -0
  76. package/src/components/LineChart/CustomPointComponent.tsx +93 -0
  77. package/src/components/LineChart/DataTable.tsx +57 -0
  78. package/src/components/LineChart/GraphTooltip.tsx +100 -0
  79. package/src/components/LineChart/LegendButton.tsx +77 -0
  80. package/src/components/LineChart/LineChart.stories.tsx +399 -0
  81. package/src/components/LineChart/LineChart.test.js +501 -0
  82. package/src/components/LineChart/LineChart.tsx +669 -0
  83. package/src/components/LineChart/index.ts +1 -0
  84. package/src/components/LineChart/magma-charts.ts +279 -0
  85. package/src/components/LineChart/test/exampleChartData.js +289 -0
  86. package/src/hooks/useCarbonModalFocusManagement.ts +0 -12
  87. package/src/index.ts +1 -0
  88. package/dist/components/ChartTable/ChartTable.test.d.ts +0 -1
  89. package/src/components/ChartTable/ChartTable.test.tsx +0 -452
@@ -2,6 +2,7 @@ import React from 'react';
2
2
 
3
3
  import { SimpleBarChart } from '@carbon/charts-react';
4
4
  import { act, render, screen, fireEvent } from '@testing-library/react';
5
+ import userEvent from '@testing-library/user-event';
5
6
  import { axe } from 'jest-axe';
6
7
  import {
7
8
  ThemeContext,
@@ -622,6 +623,32 @@ describe('CarbonChart', () => {
622
623
  }
623
624
  );
624
625
  });
626
+
627
+ it('should move focus back after closing the More options dropdown and chart toolbar', () => {
628
+ const testId = 'modal-footer-border-test';
629
+ const { getByTestId, getByText } = render(
630
+ <ThemeContext.Provider value={magma}>
631
+ <CarbonChart
632
+ testId={testId}
633
+ dataSet={dataSet}
634
+ options={chartOptions}
635
+ type={CarbonChartType.bar}
636
+ isInverse={false}
637
+ chartToolbar={{}}
638
+ />
639
+ </ThemeContext.Provider>
640
+ );
641
+
642
+ const moreOptionsButton = getByTestId('chart-more-options-button');
643
+ userEvent.click(moreOptionsButton);
644
+
645
+ expect(getByText('Download as CSV')).toBeVisible();
646
+ expect(getByText('Download as PNG')).toBeVisible();
647
+ expect(getByText('Download as JPG')).toBeVisible();
648
+
649
+ userEvent.keyboard('{esc}');
650
+ expect(moreOptionsButton).toHaveFocus();
651
+ });
625
652
  });
626
653
 
627
654
  describe('Modal Focus Management', () => {
@@ -1054,6 +1081,151 @@ describe('CarbonChart', () => {
1054
1081
  });
1055
1082
  });
1056
1083
 
1084
+ describe('dot keyboard accessibility', () => {
1085
+ let rafCallbacks;
1086
+
1087
+ beforeEach(() => {
1088
+ rafCallbacks = [];
1089
+ jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => {
1090
+ rafCallbacks.push(cb);
1091
+ return rafCallbacks.length - 1;
1092
+ });
1093
+ });
1094
+
1095
+ afterEach(() => {
1096
+ window.requestAnimationFrame.mockRestore();
1097
+ rafCallbacks = [];
1098
+ });
1099
+
1100
+ function renderChart() {
1101
+ const { getByTestId } = render(
1102
+ <CarbonChart
1103
+ testId="dot-tab-test"
1104
+ dataSet={dataSet}
1105
+ options={chartOptions}
1106
+ type={CarbonChartType.scatter}
1107
+ />
1108
+ );
1109
+ return getByTestId('dot-tab-test');
1110
+ }
1111
+
1112
+ function addDot(wrapper) {
1113
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1114
+ const dot = document.createElementNS(
1115
+ 'http://www.w3.org/2000/svg',
1116
+ 'circle'
1117
+ );
1118
+ dot.classList.add('dot');
1119
+ svg.appendChild(dot);
1120
+ wrapper.appendChild(svg);
1121
+ return dot;
1122
+ }
1123
+
1124
+ describe('tabbing', () => {
1125
+ it('should stamp tabindex="0" on circle.dot elements so they are reachable by Tab', () => {
1126
+ const wrapper = renderChart();
1127
+ const dot = addDot(wrapper);
1128
+
1129
+ // The last captured RAF is the dots-stamping callback (no ariaLabel provided)
1130
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1131
+
1132
+ expect(dot).toHaveAttribute('tabindex', '0');
1133
+ });
1134
+
1135
+ it('should not overwrite an existing tabindex on circle.dot', () => {
1136
+ const wrapper = renderChart();
1137
+ const dot = addDot(wrapper);
1138
+ dot.setAttribute('tabindex', '-1');
1139
+
1140
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1141
+
1142
+ expect(dot).toHaveAttribute('tabindex', '-1');
1143
+ });
1144
+ });
1145
+
1146
+ describe('focus on dot content', () => {
1147
+ it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
1148
+ const wrapper = renderChart();
1149
+ const dot = addDot(wrapper);
1150
+
1151
+ const mouseoverSpy = jest.fn();
1152
+ dot.addEventListener('mouseover', mouseoverSpy);
1153
+
1154
+ fireEvent.focusIn(dot);
1155
+
1156
+ expect(mouseoverSpy).toHaveBeenCalledTimes(1);
1157
+ });
1158
+
1159
+ it('should dispatch mousemove on dot focusin', () => {
1160
+ const wrapper = renderChart();
1161
+ const dot = addDot(wrapper);
1162
+
1163
+ const mousemoveSpy = jest.fn();
1164
+ dot.addEventListener('mousemove', mousemoveSpy);
1165
+
1166
+ fireEvent.focusIn(dot);
1167
+
1168
+ expect(mousemoveSpy).toHaveBeenCalledTimes(1);
1169
+ });
1170
+
1171
+ it('should not change opacity for non-dot circle elements on focusin', () => {
1172
+ const wrapper = renderChart();
1173
+ const nonDot = document.createElementNS(
1174
+ 'http://www.w3.org/2000/svg',
1175
+ 'circle'
1176
+ );
1177
+ wrapper.appendChild(nonDot);
1178
+
1179
+ fireEvent.focusIn(nonDot);
1180
+
1181
+ expect(nonDot.style.opacity).toBe('');
1182
+ });
1183
+ });
1184
+
1185
+ describe('data visibility', () => {
1186
+ it('should dispatch mouseout on dot focusout to hide tooltip', () => {
1187
+ const wrapper = renderChart();
1188
+ const dot = addDot(wrapper);
1189
+
1190
+ const mouseoutSpy = jest.fn();
1191
+ dot.addEventListener('mouseout', mouseoutSpy);
1192
+
1193
+ fireEvent.focusIn(dot);
1194
+ fireEvent.focusOut(dot);
1195
+
1196
+ expect(mouseoutSpy).toHaveBeenCalledTimes(1);
1197
+ });
1198
+
1199
+ it('should not dispatch mouseout when focus moves from one dot to another', () => {
1200
+ const wrapper = renderChart();
1201
+ const firstDot = addDot(wrapper);
1202
+ const secondDot = addDot(wrapper);
1203
+
1204
+ const mouseoutSpy = jest.fn();
1205
+ firstDot.addEventListener('mouseout', mouseoutSpy);
1206
+
1207
+ fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
1208
+
1209
+ expect(mouseoutSpy).not.toHaveBeenCalled();
1210
+ });
1211
+ });
1212
+
1213
+ describe('dynamic dot rendering', () => {
1214
+ it('should stamp tabindex="0" on dots added after initial raf pass', () => {
1215
+ const wrapper = renderChart();
1216
+
1217
+ // Run initial pass before adding a dot so the observer must handle it.
1218
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1219
+
1220
+ const lateDot = addDot(wrapper);
1221
+
1222
+ act(() => mutationObserverCallback([]));
1223
+
1224
+ expect(lateDot).toHaveAttribute('tabindex', '0');
1225
+ });
1226
+ });
1227
+ });
1228
+
1057
1229
  describe('custom content slots', () => {
1058
1230
  const toolbarProps = {
1059
1231
  dataSet,
@@ -1181,32 +1353,14 @@ describe('CarbonChart', () => {
1181
1353
  />
1182
1354
  );
1183
1355
 
1184
- // aria-prohibited-attr and aria-tooltip-name come from Carbon's own SVG
1185
- // output and are present on a chart with no slots at all, so they are
1186
- // excluded here rather than being attributed to the slots.
1356
+ // aria-tooltip-name, aria-allowed-attr, and aria-roles come from
1357
+ // Carbon's own SVG output and are present on a chart with no slots at all,
1358
+ // so they are excluded here rather than being attributed to the slots.
1187
1359
  const results = await axe(container, {
1188
1360
  rules: {
1189
- 'aria-prohibited-attr': { enabled: false },
1190
- 'aria-tooltip-name': { enabled: false },
1191
- },
1192
- });
1193
-
1194
- expect(results).toHaveNoViolations();
1195
- });
1196
-
1197
- it('keeps a single semantic heading and no a11y violations in the flow layout', async () => {
1198
- const { container } = render(
1199
- <CarbonChart {...toolbarProps} additionalContent={<div>Filter</div>} />
1200
- );
1201
-
1202
- expect(
1203
- screen.getAllByRole('heading', { name: chartOptions.title })
1204
- ).toHaveLength(1);
1205
-
1206
- const results = await axe(container, {
1207
- rules: {
1208
- 'aria-prohibited-attr': { enabled: false },
1209
1361
  'aria-tooltip-name': { enabled: false },
1362
+ 'aria-allowed-attr': { enabled: false },
1363
+ 'aria-roles': { enabled: false },
1210
1364
  },
1211
1365
  });
1212
1366
 
@@ -1217,6 +1371,10 @@ describe('CarbonChart', () => {
1217
1371
  describe('Legend accessibility wrap', () => {
1218
1372
  const testId = 'legend-a11y';
1219
1373
 
1374
+ beforeEach(() => {
1375
+ mutationObserverCallbacks = [];
1376
+ });
1377
+
1220
1378
  it('wraps the Carbon legend in a fieldset with a legend caption derived from the chart title', () => {
1221
1379
  const { getByTestId } = render(
1222
1380
  <CarbonChart
@@ -1337,10 +1495,10 @@ describe('CarbonChart', () => {
1337
1495
  expect(itemsHost.getAttribute('aria-label')).toBeNull();
1338
1496
  expect(itemsHost.getAttribute('role')).toBe('list');
1339
1497
 
1340
- if (itemsHost !== legend) {
1341
- expect(legend.getAttribute('role')).toBeNull();
1342
- expect(legend.getAttribute('aria-label')).toBeNull();
1343
- }
1498
+ expect(legend.getAttribute('role')).toBe(
1499
+ itemsHost === legend ? 'list' : null
1500
+ );
1501
+ expect(legend.getAttribute('aria-label')).toBeNull();
1344
1502
 
1345
1503
  const items = itemsHost.querySelectorAll('.legend-item');
1346
1504
  expect(items.length).toBeGreaterThan(0);
@@ -1408,141 +1566,4 @@ describe('CarbonChart', () => {
1408
1566
  );
1409
1567
  });
1410
1568
  });
1411
-
1412
- describe('dot keyboard accessibility', () => {
1413
- let rafCallbacks;
1414
-
1415
- beforeEach(() => {
1416
- rafCallbacks = [];
1417
- jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => {
1418
- rafCallbacks.push(cb);
1419
- return rafCallbacks.length - 1;
1420
- });
1421
- });
1422
-
1423
- afterEach(() => {
1424
- window.requestAnimationFrame.mockRestore();
1425
- rafCallbacks = [];
1426
- });
1427
-
1428
- function renderChart() {
1429
- const { getByTestId } = render(
1430
- <CarbonChart
1431
- testId="dot-tab-test"
1432
- dataSet={dataSet}
1433
- options={chartOptions}
1434
- type={CarbonChartType.scatter}
1435
- />
1436
- );
1437
- return getByTestId('dot-tab-test');
1438
- }
1439
-
1440
- function addDot(wrapper) {
1441
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1442
- const dot = document.createElementNS(
1443
- 'http://www.w3.org/2000/svg',
1444
- 'circle'
1445
- );
1446
- dot.classList.add('dot');
1447
- svg.appendChild(dot);
1448
- wrapper.appendChild(svg);
1449
- return dot;
1450
- }
1451
-
1452
- describe('tabbing', () => {
1453
- it('should stamp tabindex="0" on circle.dot elements so they are reachable by Tab', () => {
1454
- const wrapper = renderChart();
1455
- const dot = addDot(wrapper);
1456
-
1457
- // The last captured RAF is the dots-stamping callback (no ariaLabel provided)
1458
- act(() => rafCallbacks[rafCallbacks.length - 1](0));
1459
-
1460
- expect(dot).toHaveAttribute('tabindex', '0');
1461
- });
1462
-
1463
- it('should not overwrite an existing tabindex on circle.dot', () => {
1464
- const wrapper = renderChart();
1465
- const dot = addDot(wrapper);
1466
- dot.setAttribute('tabindex', '-1');
1467
-
1468
- act(() => rafCallbacks[rafCallbacks.length - 1](0));
1469
-
1470
- expect(dot).toHaveAttribute('tabindex', '-1');
1471
- });
1472
- });
1473
-
1474
- describe('focus on dot content', () => {
1475
- it('should set opacity to 1 when a dot receives focus', () => {
1476
- const wrapper = renderChart();
1477
- const dot = addDot(wrapper);
1478
-
1479
- fireEvent.focusIn(dot);
1480
-
1481
- expect(dot.style.opacity).toBe('1');
1482
- });
1483
-
1484
- it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
1485
- const wrapper = renderChart();
1486
- const dot = addDot(wrapper);
1487
-
1488
- const mouseoverSpy = jest.fn();
1489
- dot.addEventListener('mouseover', mouseoverSpy);
1490
-
1491
- fireEvent.focusIn(dot);
1492
-
1493
- expect(mouseoverSpy).toHaveBeenCalledTimes(1);
1494
- });
1495
-
1496
- it('should dispatch mousemove on dot focusin', () => {
1497
- const wrapper = renderChart();
1498
- const dot = addDot(wrapper);
1499
-
1500
- const mousemoveSpy = jest.fn();
1501
- dot.addEventListener('mousemove', mousemoveSpy);
1502
-
1503
- fireEvent.focusIn(dot);
1504
-
1505
- expect(mousemoveSpy).toHaveBeenCalledTimes(1);
1506
- });
1507
-
1508
- it('should not change opacity for non-dot circle elements on focusin', () => {
1509
- const wrapper = renderChart();
1510
- const nonDot = document.createElementNS(
1511
- 'http://www.w3.org/2000/svg',
1512
- 'circle'
1513
- );
1514
- wrapper.appendChild(nonDot);
1515
-
1516
- fireEvent.focusIn(nonDot);
1517
-
1518
- expect(nonDot.style.opacity).toBe('');
1519
- });
1520
- });
1521
-
1522
- describe('data visibility', () => {
1523
- it('should reset dot opacity when dot loses focus', () => {
1524
- const wrapper = renderChart();
1525
- const dot = addDot(wrapper);
1526
-
1527
- fireEvent.focusIn(dot);
1528
- expect(dot.style.opacity).toBe('1');
1529
-
1530
- fireEvent.focusOut(dot);
1531
- expect(dot.style.opacity).toBe('');
1532
- });
1533
-
1534
- it('should dispatch mouseout on dot focusout to hide tooltip', () => {
1535
- const wrapper = renderChart();
1536
- const dot = addDot(wrapper);
1537
-
1538
- const mouseoutSpy = jest.fn();
1539
- dot.addEventListener('mouseout', mouseoutSpy);
1540
-
1541
- fireEvent.focusIn(dot);
1542
- fireEvent.focusOut(dot);
1543
-
1544
- expect(mouseoutSpy).toHaveBeenCalledTimes(1);
1545
- });
1546
- });
1547
- });
1548
1569
  });
@@ -1,3 +1,4 @@
1
+ /* eslint-disable complexity */
1
2
  import * as React from 'react';
2
3
 
3
4
  import {
@@ -131,7 +132,7 @@ export interface ChartToolbarConfig {
131
132
  }
132
133
 
133
134
  export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
134
- dataSet: Array<object>;
135
+ dataSet: Array<Object>;
135
136
  isInverse?: boolean;
136
137
  /**
137
138
  * For a complete list of options, see Carbon Charts documentation
@@ -525,11 +526,10 @@ const CarbonChartWrapper = styled.div<{
525
526
 
526
527
  return chartColors.reduce((result, color, index) => {
527
528
  const indexNum = index + 1;
528
- const newResult =
529
- result +
530
- `.tooltip-${props.groupsLength}-1-${indexNum} { background-color: ${color}; }`;
531
529
 
532
- return newResult;
530
+ result += `.tooltip-${props.groupsLength}-1-${indexNum} { background-color: ${color}; }`;
531
+
532
+ return result;
533
533
  }, '');
534
534
  }}
535
535
  }
@@ -738,10 +738,10 @@ interface ColorsObject {
738
738
  [key: string]: string;
739
739
  }
740
740
 
741
- type ExtendedChartOptions = ChartOptions & {
741
+ interface ExtendedChartOptions extends ChartOptions {
742
742
  title?: string;
743
743
  colors?: string[];
744
- };
744
+ }
745
745
 
746
746
  const ToolbarWrapper = styled.div<{
747
747
  isFlowLayout?: boolean;
@@ -849,11 +849,9 @@ const ToolbarActions = styled.div<{ theme: ThemeInterface }>`
849
849
 
850
850
  function sanitizeCsvValue(value: string): string {
851
851
  const trimmed = value.trimStart();
852
-
853
852
  if (/^[=+\-@\t\r]/.test(trimmed)) {
854
853
  return `'${value}`;
855
854
  }
856
-
857
855
  return value;
858
856
  }
859
857
 
@@ -866,7 +864,6 @@ function downloadCsv(dataSet: Array<Record<string, unknown>>, title: string) {
866
864
  .map(k => {
867
865
  const v = row[k];
868
866
  const s = sanitizeCsvValue(String(v ?? ''));
869
-
870
867
  return s.includes(',') || s.includes('"') || s.includes('\n')
871
868
  ? `"${s.replace(/"/g, '""')}"`
872
869
  : s;
@@ -877,7 +874,6 @@ function downloadCsv(dataSet: Array<Record<string, unknown>>, title: string) {
877
874
  const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
878
875
  const url = URL.createObjectURL(blob);
879
876
  const a = document.createElement('a');
880
-
881
877
  a.href = url;
882
878
  a.download = `${title || 'chart-data'}.csv`;
883
879
  a.click();
@@ -1099,7 +1095,7 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1099
1095
  chartToolbar,
1100
1096
  ...rest
1101
1097
  } = props;
1102
- const theme = React.useContext(ThemeContext) as ThemeInterface;
1098
+ const theme = React.useContext(ThemeContext);
1103
1099
  const isInverse = useIsInverse(isInverseProp);
1104
1100
  const toolbarI18n = useChartToolbarI18n();
1105
1101
  const internalRef = React.useRef<HTMLDivElement | null>(null);
@@ -1139,7 +1135,6 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1139
1135
 
1140
1136
  const onFullscreenChange = () => {
1141
1137
  const isFs = !!document.fullscreenElement;
1142
-
1143
1138
  setIsFullscreen(isFs);
1144
1139
 
1145
1140
  const chartHolder =
@@ -1154,16 +1149,13 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1154
1149
  }
1155
1150
  }
1156
1151
  };
1157
-
1158
1152
  document.addEventListener('fullscreenchange', onFullscreenChange);
1159
-
1160
1153
  return () => {
1161
1154
  document.removeEventListener('fullscreenchange', onFullscreenChange);
1162
1155
  // Restore height if the component unmounts while in fullscreen.
1163
1156
  const chartHolder =
1164
1157
  internalRef.current?.querySelector<HTMLElement>('.cds--chart-holder');
1165
-
1166
- if (chartHolder && document.fullscreenElement) {
1158
+ if (chartHolder && document.fullscreenElement && !isFlowLayout) {
1167
1159
  chartHolder.style.height = savedHeightRef.current;
1168
1160
  }
1169
1161
  };
@@ -1366,7 +1358,6 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1366
1358
  if (uniqueGroups.length <= allColors.length) {
1367
1359
  for (let i = 0; i < uniqueGroups.length; i++) {
1368
1360
  const group = uniqueGroups[i];
1369
-
1370
1361
  scaleColorsObj[String(group ?? 'null')] = isInverse
1371
1362
  ? allInverseColors[i]
1372
1363
  : allColors[i];
@@ -1407,11 +1398,27 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1407
1398
 
1408
1399
  const ChartType = ALL_CHARTS[type];
1409
1400
 
1401
+ React.useEffect(() => {
1402
+ if (!ariaLabel) return;
1403
+ const rafId = requestAnimationFrame(() => {
1404
+ const svgEl = internalRef.current?.querySelector('.graph-frame');
1405
+ if (!svgEl) return;
1406
+ svgEl.setAttribute('aria-label', ariaLabel);
1407
+ });
1408
+ return () => cancelAnimationFrame(rafId);
1409
+ }, [ariaLabel]);
1410
+
1410
1411
  React.useEffect(() => {
1411
1412
  const timer = setTimeout(() => {
1412
1413
  if (internalRef.current) {
1413
1414
  internalRef.current
1414
- .querySelectorAll<SVGGElement>('g[aria-label]')
1415
+ .querySelectorAll<SVGGElement>('g.ruler[aria-label]')
1416
+ .forEach(g => {
1417
+ g.setAttribute('aria-hidden', 'true');
1418
+ });
1419
+
1420
+ internalRef.current
1421
+ .querySelectorAll<SVGGElement>('g[aria-label]:not(.ruler)')
1415
1422
  .forEach(g => {
1416
1423
  const role = g.getAttribute('role');
1417
1424
 
@@ -1427,6 +1434,30 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1427
1434
  return () => clearTimeout(timer);
1428
1435
  }, [type, dataSet]);
1429
1436
 
1437
+ React.useEffect(() => {
1438
+ const container = internalRef.current;
1439
+
1440
+ if (!container) return;
1441
+
1442
+ const hideRulerFromAT = () => {
1443
+ container
1444
+ .querySelectorAll<SVGGElement>('g.ruler[aria-label]')
1445
+ .forEach(g => {
1446
+ if (!g.hasAttribute('aria-hidden')) {
1447
+ g.setAttribute('aria-hidden', 'true');
1448
+ }
1449
+ });
1450
+ };
1451
+
1452
+ hideRulerFromAT();
1453
+
1454
+ const observer = new MutationObserver(hideRulerFromAT);
1455
+
1456
+ observer.observe(container, { childList: true, subtree: true });
1457
+
1458
+ return () => observer.disconnect();
1459
+ }, [type, dataSet]);
1460
+
1430
1461
  React.useEffect(() => {
1431
1462
  const wrapper = internalRef.current;
1432
1463
 
@@ -1494,6 +1525,16 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1494
1525
 
1495
1526
  if (!wrapper) return;
1496
1527
 
1528
+ const stampDotTabIndex = () => {
1529
+ wrapper
1530
+ .querySelectorAll<SVGCircleElement>('circle.dot')
1531
+ .forEach(dot => {
1532
+ if (!dot.hasAttribute('tabindex')) {
1533
+ dot.setAttribute('tabindex', '0');
1534
+ }
1535
+ });
1536
+ };
1537
+
1497
1538
  const isDot = (el: EventTarget | null): el is SVGCircleElement =>
1498
1539
  el instanceof Element &&
1499
1540
  el.nodeName.toLowerCase() === 'circle' &&
@@ -1503,7 +1544,6 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1503
1544
  if (!isDot(e.target)) return;
1504
1545
  const dot = e.target as SVGCircleElement;
1505
1546
 
1506
- dot.style.opacity = '1';
1507
1547
  const { left, top, width, height } = dot.getBoundingClientRect();
1508
1548
  const cx = left + width / 2;
1509
1549
  const cy = top + height / 2;
@@ -1532,7 +1572,11 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1532
1572
  if (!isDot(e.target)) return;
1533
1573
  const dot = e.target;
1534
1574
 
1535
- dot.style.opacity = '';
1575
+ // Keep tooltip context while Tab focus moves between chart points.
1576
+ if (isDot(e.relatedTarget)) {
1577
+ return;
1578
+ }
1579
+
1536
1580
  dot.dispatchEvent(new MouseEvent('mouseout', { bubbles: true }));
1537
1581
  };
1538
1582
 
@@ -1555,13 +1599,18 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1555
1599
  };
1556
1600
 
1557
1601
  const rafId = requestAnimationFrame(() => {
1558
- wrapper
1559
- .querySelectorAll<SVGCircleElement>('circle.dot')
1560
- .forEach(dot => {
1561
- if (!dot.hasAttribute('tabindex')) {
1562
- dot.setAttribute('tabindex', '0');
1563
- }
1564
- });
1602
+ stampDotTabIndex();
1603
+ });
1604
+
1605
+ const dotObserver = new MutationObserver(() => {
1606
+ stampDotTabIndex();
1607
+ });
1608
+
1609
+ dotObserver.observe(wrapper, {
1610
+ childList: true,
1611
+ subtree: true,
1612
+ attributes: true,
1613
+ attributeFilter: ['class', 'style', 'tabindex'],
1565
1614
  });
1566
1615
 
1567
1616
  wrapper.addEventListener('focusin', onFocusIn);
@@ -1570,11 +1619,12 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1570
1619
 
1571
1620
  return () => {
1572
1621
  cancelAnimationFrame(rafId);
1622
+ dotObserver.disconnect();
1573
1623
  wrapper.removeEventListener('focusin', onFocusIn);
1574
1624
  wrapper.removeEventListener('focusout', onFocusOut);
1575
1625
  wrapper.removeEventListener('keydown', onKeyDown);
1576
1626
  };
1577
- }, [type]);
1627
+ }, [type, dataSet]);
1578
1628
 
1579
1629
  const groupsLength = Object.keys(colorScale).length;
1580
1630
 
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { StoryFn, Meta } from '@storybook/react-webpack5';
3
+ import { StoryFn, Meta } from '@storybook/react/types-6-0';
4
4
  import { Card } from 'react-magma-dom';
5
5
 
6
6
  import { CarbonChart, CarbonChartProps, CarbonChartType } from '.';
@@ -15,8 +15,10 @@ export default {
15
15
  },
16
16
  },
17
17
  type: {
18
- control: { type: 'select' },
19
- options: Object.values(CarbonChartType),
18
+ control: {
19
+ type: 'select',
20
+ options: CarbonChartType,
21
+ },
20
22
  },
21
23
  },
22
24
  } as Meta;