@react-magma/charts 14.2.1 → 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.
- package/dist/charts.js +1511 -111
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +1513 -114
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +48975 -28130
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +1 -1
- package/dist/components/CarbonChart/CarbonChartArea.stories.d.ts +310 -0
- package/dist/components/CarbonChart/CarbonChartAreaStacked.stories.d.ts +136 -0
- package/dist/components/CarbonChart/CarbonChartBar.stories.d.ts +232 -0
- package/dist/components/CarbonChart/CarbonChartBarFloating.stories.d.ts +82 -0
- package/dist/components/CarbonChart/CarbonChartBarGrouped.stories.d.ts +234 -0
- package/dist/components/CarbonChart/CarbonChartBarStacked.stories.d.ts +266 -0
- package/dist/components/CarbonChart/CarbonChartBoxplot.stories.d.ts +53 -0
- package/dist/components/CarbonChart/CarbonChartBubble.stories.d.ts +196 -0
- package/dist/components/CarbonChart/CarbonChartBullet.stories.d.ts +35 -0
- package/dist/components/CarbonChart/CarbonChartCombo.stories.d.ts +580 -0
- package/dist/components/CarbonChart/CarbonChartDonut.stories.d.ts +120 -0
- package/dist/components/CarbonChart/CarbonChartGauge.stories.d.ts +43 -0
- package/dist/components/CarbonChart/CarbonChartHistogram.stories.d.ts +89 -0
- package/dist/components/CarbonChart/CarbonChartLine.stories.d.ts +577 -0
- package/dist/components/CarbonChart/CarbonChartLollipop.stories.d.ts +55 -0
- package/dist/components/CarbonChart/CarbonChartMeter.stories.d.ts +127 -0
- package/dist/components/CarbonChart/CarbonChartPie.stories.d.ts +101 -0
- package/dist/components/CarbonChart/CarbonChartRadar.stories.d.ts +98 -0
- package/dist/components/CarbonChart/CarbonChartScatter.stories.d.ts +173 -0
- package/dist/components/CarbonChart/CarbonChartSparkline.stories.d.ts +51 -0
- package/dist/components/CarbonChart/CarbonChartStep.stories.d.ts +38 -0
- package/dist/components/ChartTable/ChartTable.stories.d.ts +166 -0
- package/dist/components/LineChart/Chart.d.ts +27 -0
- package/dist/components/LineChart/ChartDataTable.d.ts +17 -0
- package/dist/components/LineChart/CustomAxisComponent.d.ts +3 -0
- package/dist/components/LineChart/CustomPointComponent.d.ts +17 -0
- package/dist/components/LineChart/DataTable.d.ts +5 -0
- package/dist/components/LineChart/GraphTooltip.d.ts +3 -0
- package/dist/components/LineChart/LegendButton.d.ts +6 -0
- package/dist/components/LineChart/LineChart.d.ts +67 -0
- package/dist/components/LineChart/LineChart.stories.d.ts +113 -0
- package/dist/components/LineChart/index.d.ts +1 -0
- package/dist/components/LineChart/magma-charts.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +19 -22
- package/src/components/CarbonChart/CarbonChart.test.js +185 -172
- package/src/components/CarbonChart/CarbonChart.tsx +19 -18
- package/src/components/CarbonChart/CarbonChartArea.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartAreaStacked.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBar.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBarFloating.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBarGrouped.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBarStacked.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBoxplot.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBubble.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartBullet.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartCombo.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartDonut.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartGauge.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartHistogram.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartLine.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartLollipop.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartMeter.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartPie.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartRadar.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartScatter.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartSparkline.stories.tsx +5 -3
- package/src/components/CarbonChart/CarbonChartStep.stories.tsx +5 -3
- package/src/components/ChartTable/ChartDataTable.tsx +0 -3
- package/src/components/ChartTable/ChartMoreOptionsButton.tsx +0 -1
- package/src/components/ChartTable/ChartTable.test.js +0 -8
- package/src/components/ChartTable/ChartTableButton.tsx +0 -1
- package/src/components/ChartTable/ChartToolbar.tsx +0 -1
- package/src/components/ChartTable/chartToolbarI18n.ts +1 -1
- package/src/components/LineChart/Chart.tsx +241 -0
- package/src/components/LineChart/ChartDataTable.test.js +165 -0
- package/src/components/LineChart/ChartDataTable.tsx +135 -0
- package/src/components/LineChart/CustomAxisComponent.tsx +30 -0
- package/src/components/LineChart/CustomPointComponent.tsx +93 -0
- package/src/components/LineChart/DataTable.tsx +57 -0
- package/src/components/LineChart/GraphTooltip.tsx +100 -0
- package/src/components/LineChart/LegendButton.tsx +77 -0
- package/src/components/LineChart/LineChart.stories.tsx +399 -0
- package/src/components/LineChart/LineChart.test.js +501 -0
- package/src/components/LineChart/LineChart.tsx +669 -0
- package/src/components/LineChart/index.ts +1 -0
- package/src/components/LineChart/magma-charts.ts +279 -0
- package/src/components/LineChart/test/exampleChartData.js +289 -0
- package/src/hooks/useCarbonModalFocusManagement.ts +0 -12
- 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,
|
|
@@ -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-
|
|
1185
|
-
// output and are present on a chart with no slots at all,
|
|
1186
|
-
// excluded here rather than being attributed to the slots.
|
|
1187
|
-
const results = await axe(container, {
|
|
1188
|
-
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
|
-
|
|
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.
|
|
1206
1359
|
const results = await axe(container, {
|
|
1207
1360
|
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
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
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,149 +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 dispatch mouseover on dot focusin to reveal tooltip data', () => {
|
|
1476
|
-
const wrapper = renderChart();
|
|
1477
|
-
const dot = addDot(wrapper);
|
|
1478
|
-
|
|
1479
|
-
const mouseoverSpy = jest.fn();
|
|
1480
|
-
dot.addEventListener('mouseover', mouseoverSpy);
|
|
1481
|
-
|
|
1482
|
-
fireEvent.focusIn(dot);
|
|
1483
|
-
|
|
1484
|
-
expect(mouseoverSpy).toHaveBeenCalledTimes(1);
|
|
1485
|
-
});
|
|
1486
|
-
|
|
1487
|
-
it('should dispatch mousemove on dot focusin', () => {
|
|
1488
|
-
const wrapper = renderChart();
|
|
1489
|
-
const dot = addDot(wrapper);
|
|
1490
|
-
|
|
1491
|
-
const mousemoveSpy = jest.fn();
|
|
1492
|
-
dot.addEventListener('mousemove', mousemoveSpy);
|
|
1493
|
-
|
|
1494
|
-
fireEvent.focusIn(dot);
|
|
1495
|
-
|
|
1496
|
-
expect(mousemoveSpy).toHaveBeenCalledTimes(1);
|
|
1497
|
-
});
|
|
1498
|
-
|
|
1499
|
-
it('should not change opacity for non-dot circle elements on focusin', () => {
|
|
1500
|
-
const wrapper = renderChart();
|
|
1501
|
-
const nonDot = document.createElementNS(
|
|
1502
|
-
'http://www.w3.org/2000/svg',
|
|
1503
|
-
'circle'
|
|
1504
|
-
);
|
|
1505
|
-
wrapper.appendChild(nonDot);
|
|
1506
|
-
|
|
1507
|
-
fireEvent.focusIn(nonDot);
|
|
1508
|
-
|
|
1509
|
-
expect(nonDot.style.opacity).toBe('');
|
|
1510
|
-
});
|
|
1511
|
-
});
|
|
1512
|
-
|
|
1513
|
-
describe('data visibility', () => {
|
|
1514
|
-
it('should dispatch mouseout on dot focusout to hide tooltip', () => {
|
|
1515
|
-
const wrapper = renderChart();
|
|
1516
|
-
const dot = addDot(wrapper);
|
|
1517
|
-
|
|
1518
|
-
const mouseoutSpy = jest.fn();
|
|
1519
|
-
dot.addEventListener('mouseout', mouseoutSpy);
|
|
1520
|
-
|
|
1521
|
-
fireEvent.focusIn(dot);
|
|
1522
|
-
fireEvent.focusOut(dot);
|
|
1523
|
-
|
|
1524
|
-
expect(mouseoutSpy).toHaveBeenCalledTimes(1);
|
|
1525
|
-
});
|
|
1526
|
-
|
|
1527
|
-
it('should not dispatch mouseout when focus moves from one dot to another', () => {
|
|
1528
|
-
const wrapper = renderChart();
|
|
1529
|
-
const firstDot = addDot(wrapper);
|
|
1530
|
-
const secondDot = addDot(wrapper);
|
|
1531
|
-
|
|
1532
|
-
const mouseoutSpy = jest.fn();
|
|
1533
|
-
firstDot.addEventListener('mouseout', mouseoutSpy);
|
|
1534
|
-
|
|
1535
|
-
fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
|
|
1536
|
-
|
|
1537
|
-
expect(mouseoutSpy).not.toHaveBeenCalled();
|
|
1538
|
-
});
|
|
1539
|
-
});
|
|
1540
|
-
|
|
1541
|
-
describe('dynamic dot rendering', () => {
|
|
1542
|
-
it('should stamp tabindex="0" on dots added after initial raf pass', () => {
|
|
1543
|
-
const wrapper = renderChart();
|
|
1544
|
-
|
|
1545
|
-
// Run initial pass before adding a dot so the observer must handle it.
|
|
1546
|
-
act(() => rafCallbacks[rafCallbacks.length - 1](0));
|
|
1547
|
-
|
|
1548
|
-
const lateDot = addDot(wrapper);
|
|
1549
|
-
|
|
1550
|
-
act(() => mutationObserverCallback([]));
|
|
1551
|
-
|
|
1552
|
-
expect(lateDot).toHaveAttribute('tabindex', '0');
|
|
1553
|
-
});
|
|
1554
|
-
});
|
|
1555
|
-
});
|
|
1556
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<
|
|
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
|
-
|
|
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
|
-
|
|
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)
|
|
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,6 +1398,16 @@ 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) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
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: {
|
|
19
|
-
|
|
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-
|
|
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: {
|
|
19
|
-
|
|
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-
|
|
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: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
titleLevel: {
|
|
22
24
|
control: { type: 'select' },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { StoryFn, Meta } from '@storybook/react-
|
|
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: {
|
|
19
|
-
|
|
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-
|
|
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: {
|
|
19
|
-
|
|
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-
|
|
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: {
|
|
19
|
-
|
|
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-
|
|
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: {
|
|
19
|
-
|
|
18
|
+
control: {
|
|
19
|
+
type: 'select',
|
|
20
|
+
options: CarbonChartType,
|
|
21
|
+
},
|
|
20
22
|
},
|
|
21
23
|
},
|
|
22
24
|
} as Meta;
|