@react-magma/charts 16.0.0-next.1 → 16.0.0-v6-next.2

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 (87) hide show
  1. package/dist/charts.js +1517 -114
  2. package/dist/charts.js.map +1 -1
  3. package/dist/charts.modern.module.js +1519 -117
  4. package/dist/charts.modern.module.js.map +1 -1
  5. package/dist/charts.umd.js +49696 -28876
  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 +21 -24
  43. package/src/components/CarbonChart/CarbonChart.test.js +256 -172
  44. package/src/components/CarbonChart/CarbonChart.tsx +44 -39
  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
@@ -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,
@@ -666,6 +667,32 @@ describe('CarbonChart', () => {
666
667
  }
667
668
  );
668
669
  });
670
+
671
+ it('should move focus back after closing the More options dropdown and chart toolbar', () => {
672
+ const testId = 'modal-footer-border-test';
673
+ const { getByTestId, getByText } = render(
674
+ <ThemeContext.Provider value={magma}>
675
+ <CarbonChart
676
+ testId={testId}
677
+ dataSet={dataSet}
678
+ options={chartOptions}
679
+ type={CarbonChartType.bar}
680
+ isInverse={false}
681
+ chartToolbar={{}}
682
+ />
683
+ </ThemeContext.Provider>
684
+ );
685
+
686
+ const moreOptionsButton = getByTestId('chart-more-options-button');
687
+ userEvent.click(moreOptionsButton);
688
+
689
+ expect(getByText('Download as CSV')).toBeVisible();
690
+ expect(getByText('Download as PNG')).toBeVisible();
691
+ expect(getByText('Download as JPG')).toBeVisible();
692
+
693
+ userEvent.keyboard('{esc}');
694
+ expect(moreOptionsButton).toHaveFocus();
695
+ });
669
696
  });
670
697
 
671
698
  describe('Modal Focus Management', () => {
@@ -996,6 +1023,77 @@ describe('CarbonChart', () => {
996
1023
  });
997
1024
  });
998
1025
 
1026
+ describe('fullscreen', () => {
1027
+ const toolbarProps = {
1028
+ dataSet,
1029
+ options: chartOptions,
1030
+ type: CarbonChartType.bar,
1031
+ chartToolbar: {},
1032
+ };
1033
+
1034
+ let setOptions;
1035
+ let createChartSpy;
1036
+
1037
+ const setFullscreenElement = element => {
1038
+ Object.defineProperty(document, 'fullscreenElement', {
1039
+ configurable: true,
1040
+ value: element,
1041
+ });
1042
+ act(() => {
1043
+ document.dispatchEvent(new Event('fullscreenchange'));
1044
+ });
1045
+ };
1046
+
1047
+ beforeEach(() => {
1048
+ setOptions = jest.fn();
1049
+ createChartSpy = jest
1050
+ .spyOn(SimpleBarChart.prototype, 'createChart')
1051
+ .mockImplementation(holder => {
1052
+ holder.classList.add('cds--chart-holder');
1053
+ holder.style.height = chartOptions.height;
1054
+
1055
+ return { model: { setOptions, setData: jest.fn() } };
1056
+ });
1057
+ });
1058
+
1059
+ afterEach(() => {
1060
+ createChartSpy.mockRestore();
1061
+ delete document.fullscreenElement;
1062
+ });
1063
+
1064
+ it('does not update chart options when entering and exiting fullscreen', () => {
1065
+ const { container } = render(<CarbonChart {...toolbarProps} />);
1066
+ const holder = container.querySelector('.cds--chart-holder');
1067
+
1068
+ setFullscreenElement(container.firstChild);
1069
+
1070
+ expect(
1071
+ screen.getByRole('button', {
1072
+ name: `Exit ${chartOptions.title} full screen`,
1073
+ })
1074
+ ).toBeInTheDocument();
1075
+ expect(holder.style.height).toBe('100vh');
1076
+
1077
+ setFullscreenElement(null);
1078
+
1079
+ expect(
1080
+ screen.getByRole('button', {
1081
+ name: `View ${chartOptions.title} full screen`,
1082
+ })
1083
+ ).toBeInTheDocument();
1084
+ expect(holder.style.height).toBe(chartOptions.height);
1085
+ expect(setOptions).not.toHaveBeenCalled();
1086
+ });
1087
+
1088
+ it('does not update chart options on re-render with the same props', () => {
1089
+ const { rerender } = render(<CarbonChart {...toolbarProps} />);
1090
+
1091
+ rerender(<CarbonChart {...toolbarProps} chartToolbar={{}} />);
1092
+
1093
+ expect(setOptions).not.toHaveBeenCalled();
1094
+ });
1095
+ });
1096
+
999
1097
  describe('image export', () => {
1000
1098
  const toolbarProps = {
1001
1099
  dataSet,
@@ -1098,6 +1196,151 @@ describe('CarbonChart', () => {
1098
1196
  });
1099
1197
  });
1100
1198
 
1199
+ describe('dot keyboard accessibility', () => {
1200
+ let rafCallbacks;
1201
+
1202
+ beforeEach(() => {
1203
+ rafCallbacks = [];
1204
+ jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => {
1205
+ rafCallbacks.push(cb);
1206
+ return rafCallbacks.length - 1;
1207
+ });
1208
+ });
1209
+
1210
+ afterEach(() => {
1211
+ window.requestAnimationFrame.mockRestore();
1212
+ rafCallbacks = [];
1213
+ });
1214
+
1215
+ function renderChart() {
1216
+ const { getByTestId } = render(
1217
+ <CarbonChart
1218
+ testId="dot-tab-test"
1219
+ dataSet={dataSet}
1220
+ options={chartOptions}
1221
+ type={CarbonChartType.scatter}
1222
+ />
1223
+ );
1224
+ return getByTestId('dot-tab-test');
1225
+ }
1226
+
1227
+ function addDot(wrapper) {
1228
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1229
+ const dot = document.createElementNS(
1230
+ 'http://www.w3.org/2000/svg',
1231
+ 'circle'
1232
+ );
1233
+ dot.classList.add('dot');
1234
+ svg.appendChild(dot);
1235
+ wrapper.appendChild(svg);
1236
+ return dot;
1237
+ }
1238
+
1239
+ describe('tabbing', () => {
1240
+ it('should stamp tabindex="0" on circle.dot elements so they are reachable by Tab', () => {
1241
+ const wrapper = renderChart();
1242
+ const dot = addDot(wrapper);
1243
+
1244
+ // The last captured RAF is the dots-stamping callback (no ariaLabel provided)
1245
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1246
+
1247
+ expect(dot).toHaveAttribute('tabindex', '0');
1248
+ });
1249
+
1250
+ it('should not overwrite an existing tabindex on circle.dot', () => {
1251
+ const wrapper = renderChart();
1252
+ const dot = addDot(wrapper);
1253
+ dot.setAttribute('tabindex', '-1');
1254
+
1255
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1256
+
1257
+ expect(dot).toHaveAttribute('tabindex', '-1');
1258
+ });
1259
+ });
1260
+
1261
+ describe('focus on dot content', () => {
1262
+ it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
1263
+ const wrapper = renderChart();
1264
+ const dot = addDot(wrapper);
1265
+
1266
+ const mouseoverSpy = jest.fn();
1267
+ dot.addEventListener('mouseover', mouseoverSpy);
1268
+
1269
+ fireEvent.focusIn(dot);
1270
+
1271
+ expect(mouseoverSpy).toHaveBeenCalledTimes(1);
1272
+ });
1273
+
1274
+ it('should dispatch mousemove on dot focusin', () => {
1275
+ const wrapper = renderChart();
1276
+ const dot = addDot(wrapper);
1277
+
1278
+ const mousemoveSpy = jest.fn();
1279
+ dot.addEventListener('mousemove', mousemoveSpy);
1280
+
1281
+ fireEvent.focusIn(dot);
1282
+
1283
+ expect(mousemoveSpy).toHaveBeenCalledTimes(1);
1284
+ });
1285
+
1286
+ it('should not change opacity for non-dot circle elements on focusin', () => {
1287
+ const wrapper = renderChart();
1288
+ const nonDot = document.createElementNS(
1289
+ 'http://www.w3.org/2000/svg',
1290
+ 'circle'
1291
+ );
1292
+ wrapper.appendChild(nonDot);
1293
+
1294
+ fireEvent.focusIn(nonDot);
1295
+
1296
+ expect(nonDot.style.opacity).toBe('');
1297
+ });
1298
+ });
1299
+
1300
+ describe('data visibility', () => {
1301
+ it('should dispatch mouseout on dot focusout to hide tooltip', () => {
1302
+ const wrapper = renderChart();
1303
+ const dot = addDot(wrapper);
1304
+
1305
+ const mouseoutSpy = jest.fn();
1306
+ dot.addEventListener('mouseout', mouseoutSpy);
1307
+
1308
+ fireEvent.focusIn(dot);
1309
+ fireEvent.focusOut(dot);
1310
+
1311
+ expect(mouseoutSpy).toHaveBeenCalledTimes(1);
1312
+ });
1313
+
1314
+ it('should not dispatch mouseout when focus moves from one dot to another', () => {
1315
+ const wrapper = renderChart();
1316
+ const firstDot = addDot(wrapper);
1317
+ const secondDot = addDot(wrapper);
1318
+
1319
+ const mouseoutSpy = jest.fn();
1320
+ firstDot.addEventListener('mouseout', mouseoutSpy);
1321
+
1322
+ fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
1323
+
1324
+ expect(mouseoutSpy).not.toHaveBeenCalled();
1325
+ });
1326
+ });
1327
+
1328
+ describe('dynamic dot rendering', () => {
1329
+ it('should stamp tabindex="0" on dots added after initial raf pass', () => {
1330
+ const wrapper = renderChart();
1331
+
1332
+ // Run initial pass before adding a dot so the observer must handle it.
1333
+ act(() => rafCallbacks[rafCallbacks.length - 1](0));
1334
+
1335
+ const lateDot = addDot(wrapper);
1336
+
1337
+ act(() => mutationObserverCallback([]));
1338
+
1339
+ expect(lateDot).toHaveAttribute('tabindex', '0');
1340
+ });
1341
+ });
1342
+ });
1343
+
1101
1344
  describe('custom content slots', () => {
1102
1345
  const toolbarProps = {
1103
1346
  dataSet,
@@ -1225,32 +1468,14 @@ describe('CarbonChart', () => {
1225
1468
  />
1226
1469
  );
1227
1470
 
1228
- // aria-prohibited-attr and aria-tooltip-name come from Carbon's own SVG
1229
- // output and are present on a chart with no slots at all, so they are
1230
- // excluded here rather than being attributed to the slots.
1231
- const results = await axe(container, {
1232
- rules: {
1233
- 'aria-prohibited-attr': { enabled: false },
1234
- 'aria-tooltip-name': { enabled: false },
1235
- },
1236
- });
1237
-
1238
- expect(results).toHaveNoViolations();
1239
- });
1240
-
1241
- it('keeps a single semantic heading and no a11y violations in the flow layout', async () => {
1242
- const { container } = render(
1243
- <CarbonChart {...toolbarProps} additionalContent={<div>Filter</div>} />
1244
- );
1245
-
1246
- expect(
1247
- screen.getAllByRole('heading', { name: chartOptions.title })
1248
- ).toHaveLength(1);
1249
-
1471
+ // aria-tooltip-name, aria-allowed-attr, and aria-roles come from
1472
+ // Carbon's own SVG output and are present on a chart with no slots at all,
1473
+ // so they are excluded here rather than being attributed to the slots.
1250
1474
  const results = await axe(container, {
1251
1475
  rules: {
1252
- 'aria-prohibited-attr': { enabled: false },
1253
1476
  'aria-tooltip-name': { enabled: false },
1477
+ 'aria-allowed-attr': { enabled: false },
1478
+ 'aria-roles': { enabled: false },
1254
1479
  },
1255
1480
  });
1256
1481
 
@@ -1261,6 +1486,10 @@ describe('CarbonChart', () => {
1261
1486
  describe('Legend accessibility wrap', () => {
1262
1487
  const testId = 'legend-a11y';
1263
1488
 
1489
+ beforeEach(() => {
1490
+ mutationObserverCallbacks = [];
1491
+ });
1492
+
1264
1493
  it('wraps the Carbon legend in a fieldset with a legend caption derived from the chart title', () => {
1265
1494
  const { getByTestId } = render(
1266
1495
  <CarbonChart
@@ -1381,10 +1610,10 @@ describe('CarbonChart', () => {
1381
1610
  expect(itemsHost.getAttribute('aria-label')).toBeNull();
1382
1611
  expect(itemsHost.getAttribute('role')).toBe('list');
1383
1612
 
1384
- if (itemsHost !== legend) {
1385
- expect(legend.getAttribute('role')).toBeNull();
1386
- expect(legend.getAttribute('aria-label')).toBeNull();
1387
- }
1613
+ expect(legend.getAttribute('role')).toBe(
1614
+ itemsHost === legend ? 'list' : null
1615
+ );
1616
+ expect(legend.getAttribute('aria-label')).toBeNull();
1388
1617
 
1389
1618
  const items = itemsHost.querySelectorAll('.legend-item');
1390
1619
  expect(items.length).toBeGreaterThan(0);
@@ -1452,149 +1681,4 @@ describe('CarbonChart', () => {
1452
1681
  );
1453
1682
  });
1454
1683
  });
1455
-
1456
- describe('dot keyboard accessibility', () => {
1457
- let rafCallbacks;
1458
-
1459
- beforeEach(() => {
1460
- rafCallbacks = [];
1461
- jest.spyOn(window, 'requestAnimationFrame').mockImplementation(cb => {
1462
- rafCallbacks.push(cb);
1463
- return rafCallbacks.length - 1;
1464
- });
1465
- });
1466
-
1467
- afterEach(() => {
1468
- window.requestAnimationFrame.mockRestore();
1469
- rafCallbacks = [];
1470
- });
1471
-
1472
- function renderChart() {
1473
- const { getByTestId } = render(
1474
- <CarbonChart
1475
- testId="dot-tab-test"
1476
- dataSet={dataSet}
1477
- options={chartOptions}
1478
- type={CarbonChartType.scatter}
1479
- />
1480
- );
1481
- return getByTestId('dot-tab-test');
1482
- }
1483
-
1484
- function addDot(wrapper) {
1485
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
1486
- const dot = document.createElementNS(
1487
- 'http://www.w3.org/2000/svg',
1488
- 'circle'
1489
- );
1490
- dot.classList.add('dot');
1491
- svg.appendChild(dot);
1492
- wrapper.appendChild(svg);
1493
- return dot;
1494
- }
1495
-
1496
- describe('tabbing', () => {
1497
- it('should stamp tabindex="0" on circle.dot elements so they are reachable by Tab', () => {
1498
- const wrapper = renderChart();
1499
- const dot = addDot(wrapper);
1500
-
1501
- // The last captured RAF is the dots-stamping callback (no ariaLabel provided)
1502
- act(() => rafCallbacks[rafCallbacks.length - 1](0));
1503
-
1504
- expect(dot).toHaveAttribute('tabindex', '0');
1505
- });
1506
-
1507
- it('should not overwrite an existing tabindex on circle.dot', () => {
1508
- const wrapper = renderChart();
1509
- const dot = addDot(wrapper);
1510
- dot.setAttribute('tabindex', '-1');
1511
-
1512
- act(() => rafCallbacks[rafCallbacks.length - 1](0));
1513
-
1514
- expect(dot).toHaveAttribute('tabindex', '-1');
1515
- });
1516
- });
1517
-
1518
- describe('focus on dot content', () => {
1519
- it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
1520
- const wrapper = renderChart();
1521
- const dot = addDot(wrapper);
1522
-
1523
- const mouseoverSpy = jest.fn();
1524
- dot.addEventListener('mouseover', mouseoverSpy);
1525
-
1526
- fireEvent.focusIn(dot);
1527
-
1528
- expect(mouseoverSpy).toHaveBeenCalledTimes(1);
1529
- });
1530
-
1531
- it('should dispatch mousemove on dot focusin', () => {
1532
- const wrapper = renderChart();
1533
- const dot = addDot(wrapper);
1534
-
1535
- const mousemoveSpy = jest.fn();
1536
- dot.addEventListener('mousemove', mousemoveSpy);
1537
-
1538
- fireEvent.focusIn(dot);
1539
-
1540
- expect(mousemoveSpy).toHaveBeenCalledTimes(1);
1541
- });
1542
-
1543
- it('should not change opacity for non-dot circle elements on focusin', () => {
1544
- const wrapper = renderChart();
1545
- const nonDot = document.createElementNS(
1546
- 'http://www.w3.org/2000/svg',
1547
- 'circle'
1548
- );
1549
- wrapper.appendChild(nonDot);
1550
-
1551
- fireEvent.focusIn(nonDot);
1552
-
1553
- expect(nonDot.style.opacity).toBe('');
1554
- });
1555
- });
1556
-
1557
- describe('data visibility', () => {
1558
- it('should dispatch mouseout on dot focusout to hide tooltip', () => {
1559
- const wrapper = renderChart();
1560
- const dot = addDot(wrapper);
1561
-
1562
- const mouseoutSpy = jest.fn();
1563
- dot.addEventListener('mouseout', mouseoutSpy);
1564
-
1565
- fireEvent.focusIn(dot);
1566
- fireEvent.focusOut(dot);
1567
-
1568
- expect(mouseoutSpy).toHaveBeenCalledTimes(1);
1569
- });
1570
-
1571
- it('should not dispatch mouseout when focus moves from one dot to another', () => {
1572
- const wrapper = renderChart();
1573
- const firstDot = addDot(wrapper);
1574
- const secondDot = addDot(wrapper);
1575
-
1576
- const mouseoutSpy = jest.fn();
1577
- firstDot.addEventListener('mouseout', mouseoutSpy);
1578
-
1579
- fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
1580
-
1581
- expect(mouseoutSpy).not.toHaveBeenCalled();
1582
- });
1583
- });
1584
-
1585
- describe('dynamic dot rendering', () => {
1586
- it('should stamp tabindex="0" on dots added after initial raf pass', () => {
1587
- const wrapper = renderChart();
1588
-
1589
- // Run initial pass before adding a dot so the observer must handle it.
1590
- act(() => rafCallbacks[rafCallbacks.length - 1](0));
1591
-
1592
- const lateDot = addDot(wrapper);
1593
-
1594
- act(() => mutationObserverCallback([]));
1595
-
1596
- expect(lateDot).toHaveAttribute('tabindex', '0');
1597
- });
1598
- });
1599
- });
1600
1684
  });
@@ -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
@@ -543,11 +544,10 @@ const CarbonChartWrapper = styled.div<{
543
544
 
544
545
  return chartColors.reduce((result, color, index) => {
545
546
  const indexNum = index + 1;
546
- const newResult =
547
- result +
548
- `.tooltip-${props.groupsLength}-1-${indexNum} { background-color: ${color}; }`;
549
547
 
550
- return newResult;
548
+ result += `.tooltip-${props.groupsLength}-1-${indexNum} { background-color: ${color}; }`;
549
+
550
+ return result;
551
551
  }, '');
552
552
  }}
553
553
  }
@@ -759,10 +759,10 @@ interface ColorsObject {
759
759
  [key: string]: string;
760
760
  }
761
761
 
762
- type ExtendedChartOptions = ChartOptions & {
762
+ interface ExtendedChartOptions extends ChartOptions {
763
763
  title?: string;
764
764
  colors?: string[];
765
- };
765
+ }
766
766
 
767
767
  const ToolbarWrapper = styled.div<{
768
768
  isFlowLayout?: boolean;
@@ -854,11 +854,9 @@ const ToolbarActions = styled.div<{ theme: ThemeInterface }>`
854
854
 
855
855
  function sanitizeCsvValue(value: string): string {
856
856
  const trimmed = value.trimStart();
857
-
858
857
  if (/^[=+\-@\t\r]/.test(trimmed)) {
859
858
  return `'${value}`;
860
859
  }
861
-
862
860
  return value;
863
861
  }
864
862
 
@@ -871,7 +869,6 @@ function downloadCsv(dataSet: Array<Record<string, unknown>>, title: string) {
871
869
  .map(k => {
872
870
  const v = row[k];
873
871
  const s = sanitizeCsvValue(String(v ?? ''));
874
-
875
872
  return s.includes(',') || s.includes('"') || s.includes('\n')
876
873
  ? `"${s.replace(/"/g, '""')}"`
877
874
  : s;
@@ -882,7 +879,6 @@ function downloadCsv(dataSet: Array<Record<string, unknown>>, title: string) {
882
879
  const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
883
880
  const url = URL.createObjectURL(blob);
884
881
  const a = document.createElement('a');
885
-
886
882
  a.href = url;
887
883
  a.download = `${title || 'chart-data'}.csv`;
888
884
  a.click();
@@ -1104,7 +1100,7 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1104
1100
  chartToolbar,
1105
1101
  ...rest
1106
1102
  } = props;
1107
- const theme = React.useContext(ThemeContext) as ThemeInterface;
1103
+ const theme = React.useContext(ThemeContext);
1108
1104
  const isInverse = useIsInverse(isInverseProp);
1109
1105
  const toolbarI18n = useChartToolbarI18n();
1110
1106
  const internalRef = React.useRef<HTMLDivElement | null>(null);
@@ -1144,7 +1140,6 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1144
1140
 
1145
1141
  const onFullscreenChange = () => {
1146
1142
  const isFs = !!document.fullscreenElement;
1147
-
1148
1143
  setIsFullscreen(isFs);
1149
1144
 
1150
1145
  const chartHolder =
@@ -1159,16 +1154,13 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1159
1154
  }
1160
1155
  }
1161
1156
  };
1162
-
1163
1157
  document.addEventListener('fullscreenchange', onFullscreenChange);
1164
-
1165
1158
  return () => {
1166
1159
  document.removeEventListener('fullscreenchange', onFullscreenChange);
1167
1160
  // Restore height if the component unmounts while in fullscreen.
1168
1161
  const chartHolder =
1169
1162
  internalRef.current?.querySelector<HTMLElement>('.cds--chart-holder');
1170
-
1171
- if (chartHolder && document.fullscreenElement) {
1163
+ if (chartHolder && document.fullscreenElement && !isFlowLayout) {
1172
1164
  chartHolder.style.height = savedHeightRef.current;
1173
1165
  }
1174
1166
  };
@@ -1371,7 +1363,6 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1371
1363
  if (uniqueGroups.length <= allColors.length) {
1372
1364
  for (let i = 0; i < uniqueGroups.length; i++) {
1373
1365
  const group = uniqueGroups[i];
1374
-
1375
1366
  scaleColorsObj[String(group ?? 'null')] = isInverse
1376
1367
  ? allInverseColors[i]
1377
1368
  : allColors[i];
@@ -1387,31 +1378,45 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
1387
1378
  isInverse,
1388
1379
  ]);
1389
1380
 
1390
- const newOptions = {
1391
- ...options,
1392
- theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE,
1393
- color: {
1394
- scale: colorScale,
1395
- },
1396
- tooltip: {
1397
- ...(options?.tooltip || {}),
1398
- truncation: {
1399
- type: 'none',
1381
+ const hasChartToolbar = Boolean(chartToolbar);
1382
+ const newOptions = React.useMemo(
1383
+ () => ({
1384
+ ...options,
1385
+ theme: isInverse ? ChartTheme.G100 : ChartTheme.WHITE,
1386
+ color: {
1387
+ scale: colorScale,
1400
1388
  },
1401
- },
1402
- ...(chartToolbar
1403
- ? {
1404
- toolbar: { enabled: false },
1405
- title: chartTitle,
1406
- ...(options.fileDownload
1407
- ? {}
1408
- : { fileDownload: { fileName: chartTitle } }),
1409
- }
1410
- : {}),
1411
- };
1389
+ tooltip: {
1390
+ ...(options?.tooltip || {}),
1391
+ truncation: {
1392
+ type: 'none',
1393
+ },
1394
+ },
1395
+ ...(hasChartToolbar
1396
+ ? {
1397
+ toolbar: { enabled: false },
1398
+ title: chartTitle,
1399
+ ...(options.fileDownload
1400
+ ? {}
1401
+ : { fileDownload: { fileName: chartTitle } }),
1402
+ }
1403
+ : {}),
1404
+ }),
1405
+ [options, isInverse, colorScale, hasChartToolbar, chartTitle]
1406
+ );
1412
1407
 
1413
1408
  const ChartType = ALL_CHARTS[type];
1414
1409
 
1410
+ React.useEffect(() => {
1411
+ if (!ariaLabel) return;
1412
+ const rafId = requestAnimationFrame(() => {
1413
+ const svgEl = internalRef.current?.querySelector('.graph-frame');
1414
+ if (!svgEl) return;
1415
+ svgEl.setAttribute('aria-label', ariaLabel);
1416
+ });
1417
+ return () => cancelAnimationFrame(rafId);
1418
+ }, [ariaLabel]);
1419
+
1415
1420
  React.useEffect(() => {
1416
1421
  const timer = setTimeout(() => {
1417
1422
  if (internalRef.current) {
@@ -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;