@react-magma/charts 14.2.0-rc.1 → 15.0.0-rc.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 +208 -193
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +208 -193
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +656 -313
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/CarbonChart/CarbonChart.d.ts +10 -0
- package/package.json +3 -3
- package/src/components/CarbonChart/CarbonChart.test.js +280 -0
- package/src/components/CarbonChart/CarbonChart.tsx +319 -238
- 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/ChartMoreOptionsButton.tsx +1 -0
- package/src/components/ChartTable/ChartTable.stories.tsx +54 -0
- package/dist/components/ChartTable/ChartTable.test.d.ts +0 -1
- /package/src/components/ChartTable/{ChartTable.test.tsx → ChartTable.test.js} +0 -0
|
@@ -103,5 +103,15 @@ export interface CarbonChartProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
103
103
|
* toolbar is automatically disabled.
|
|
104
104
|
*/
|
|
105
105
|
chartToolbar?: ChartToolbarConfig;
|
|
106
|
+
/**
|
|
107
|
+
* Custom content rendered below the toolbar row and above the chart itself,
|
|
108
|
+
* for example a filter. Requires `chartToolbar`; ignored without it.
|
|
109
|
+
*
|
|
110
|
+
* Providing this lays the toolbar out in normal flow instead of overlaying
|
|
111
|
+
* the single row Carbon reserves for its title, so the rendered height
|
|
112
|
+
* becomes toolbar + content + chart rather than the chart box alone. Set
|
|
113
|
+
* `options.height` so the chart still has a definite height of its own.
|
|
114
|
+
*/
|
|
115
|
+
additionalContent?: React.ReactNode;
|
|
106
116
|
}
|
|
107
117
|
export declare const CarbonChart: React.ForwardRefExoticComponent<CarbonChartProps & React.RefAttributes<HTMLDivElement>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-magma/charts",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "15.0.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"identity-obj-proxy": "3.0.0",
|
|
51
51
|
"react": "18.3.1",
|
|
52
52
|
"react-dom": "18.3.1",
|
|
53
|
-
"react-magma-dom": "^5.
|
|
53
|
+
"react-magma-dom": "^5.3.0-rc.0",
|
|
54
54
|
"react-magma-icons": "^3.2.5",
|
|
55
55
|
"rollup": "^4.52.4",
|
|
56
56
|
"rollup-plugin-postcss": "^4.0.2"
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@emotion/styled": "^11.14.0",
|
|
61
61
|
"react": "^18.3.1",
|
|
62
62
|
"react-dom": "^18.3.1",
|
|
63
|
-
"react-magma-dom": "^5.
|
|
63
|
+
"react-magma-dom": "^5.3.0-rc.0",
|
|
64
64
|
"react-magma-icons": "^3.2.5"
|
|
65
65
|
},
|
|
66
66
|
"engines": {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import { SimpleBarChart } from '@carbon/charts-react';
|
|
3
4
|
import { act, render, screen, fireEvent } from '@testing-library/react';
|
|
4
5
|
import { axe } from 'jest-axe';
|
|
5
6
|
import {
|
|
@@ -189,6 +190,27 @@ describe('CarbonChart', () => {
|
|
|
189
190
|
);
|
|
190
191
|
});
|
|
191
192
|
|
|
193
|
+
it("pins Carbon's export `.filled` background to the inverse surface color", () => {
|
|
194
|
+
const testId = 'filled-bg-inverse';
|
|
195
|
+
const { getByTestId } = render(
|
|
196
|
+
<ThemeContext.Provider value={magma}>
|
|
197
|
+
<CarbonChart
|
|
198
|
+
testId={testId}
|
|
199
|
+
dataSet={dataSet}
|
|
200
|
+
options={chartOptions}
|
|
201
|
+
type={CarbonChartType.bar}
|
|
202
|
+
isInverse
|
|
203
|
+
/>
|
|
204
|
+
</ThemeContext.Provider>
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
expect(getByTestId(testId)).toHaveStyleRule(
|
|
208
|
+
'background-color',
|
|
209
|
+
magma.colors.primary600,
|
|
210
|
+
{ target: '.cds--chart-holder.filled' }
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
|
|
192
214
|
it('should apply theme.colors.neutral100 for inverse text color', () => {
|
|
193
215
|
const testId = 'text-inverse-test';
|
|
194
216
|
const { getByTestId } = render(
|
|
@@ -930,6 +952,108 @@ describe('CarbonChart', () => {
|
|
|
930
952
|
});
|
|
931
953
|
});
|
|
932
954
|
|
|
955
|
+
describe('image export', () => {
|
|
956
|
+
const toolbarProps = {
|
|
957
|
+
dataSet,
|
|
958
|
+
options: chartOptions,
|
|
959
|
+
type: CarbonChartType.bar,
|
|
960
|
+
chartToolbar: {},
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
let exportToPNG;
|
|
964
|
+
let exportToJPG;
|
|
965
|
+
let createChartSpy;
|
|
966
|
+
|
|
967
|
+
beforeEach(() => {
|
|
968
|
+
exportToPNG = jest.fn();
|
|
969
|
+
exportToJPG = jest.fn();
|
|
970
|
+
createChartSpy = jest
|
|
971
|
+
.spyOn(SimpleBarChart.prototype, 'createChart')
|
|
972
|
+
.mockImplementation(() => ({
|
|
973
|
+
services: { domUtils: { exportToPNG, exportToJPG } },
|
|
974
|
+
}));
|
|
975
|
+
});
|
|
976
|
+
|
|
977
|
+
afterEach(() => {
|
|
978
|
+
createChartSpy.mockRestore();
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
it("runs Carbon's own PNG export from the More options menu", () => {
|
|
982
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
983
|
+
|
|
984
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
985
|
+
fireEvent.click(screen.getByText('Download as PNG'));
|
|
986
|
+
|
|
987
|
+
expect(exportToPNG).toHaveBeenCalledTimes(1);
|
|
988
|
+
expect(exportToJPG).not.toHaveBeenCalled();
|
|
989
|
+
});
|
|
990
|
+
|
|
991
|
+
it("runs Carbon's own JPG export from the More options menu", () => {
|
|
992
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
993
|
+
|
|
994
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
995
|
+
fireEvent.click(screen.getByText('Download as JPG'));
|
|
996
|
+
|
|
997
|
+
expect(exportToJPG).toHaveBeenCalledTimes(1);
|
|
998
|
+
expect(exportToPNG).not.toHaveBeenCalled();
|
|
999
|
+
});
|
|
1000
|
+
|
|
1001
|
+
it("keeps Carbon's own title alive and uses it as the export file name", () => {
|
|
1002
|
+
render(<CarbonChart {...toolbarProps} />);
|
|
1003
|
+
|
|
1004
|
+
const options = createChartSpy.mock.calls[0][2];
|
|
1005
|
+
expect(options.title).toBe(chartOptions.title);
|
|
1006
|
+
expect(options.fileDownload.fileName).toBe(chartOptions.title);
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
it("reveals Carbon's hidden title for the capture and restores it afterwards", () => {
|
|
1010
|
+
jest.useFakeTimers();
|
|
1011
|
+
try {
|
|
1012
|
+
const { container } = render(<CarbonChart {...toolbarProps} />);
|
|
1013
|
+
const wrapper = container.querySelector('.carbon-chart-wrapper');
|
|
1014
|
+
|
|
1015
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1016
|
+
|
|
1017
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
1018
|
+
fireEvent.click(screen.getByText('Download as PNG'));
|
|
1019
|
+
|
|
1020
|
+
expect(wrapper).not.toHaveClass('has-magma-toolbar');
|
|
1021
|
+
|
|
1022
|
+
jest.runOnlyPendingTimers();
|
|
1023
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1024
|
+
} finally {
|
|
1025
|
+
jest.useRealTimers();
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
it('reveals the title for the flow layout (additionalContent) export too', () => {
|
|
1030
|
+
jest.useFakeTimers();
|
|
1031
|
+
try {
|
|
1032
|
+
const { container } = render(
|
|
1033
|
+
<CarbonChart
|
|
1034
|
+
{...toolbarProps}
|
|
1035
|
+
additionalContent={<div>Filter</div>}
|
|
1036
|
+
/>
|
|
1037
|
+
);
|
|
1038
|
+
const wrapper = container.querySelector('.carbon-chart-wrapper');
|
|
1039
|
+
|
|
1040
|
+
expect(createChartSpy.mock.calls[0][2].title).toBe(chartOptions.title);
|
|
1041
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1042
|
+
|
|
1043
|
+
fireEvent.click(screen.getByRole('button', { name: 'More options' }));
|
|
1044
|
+
fireEvent.click(screen.getByText('Download as JPG'));
|
|
1045
|
+
|
|
1046
|
+
expect(exportToJPG).toHaveBeenCalledTimes(1);
|
|
1047
|
+
expect(wrapper).not.toHaveClass('has-magma-toolbar');
|
|
1048
|
+
|
|
1049
|
+
jest.runOnlyPendingTimers();
|
|
1050
|
+
expect(wrapper).toHaveClass('has-magma-toolbar');
|
|
1051
|
+
} finally {
|
|
1052
|
+
jest.useRealTimers();
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
});
|
|
1056
|
+
|
|
933
1057
|
describe('custom content slots', () => {
|
|
934
1058
|
const toolbarProps = {
|
|
935
1059
|
dataSet,
|
|
@@ -1069,6 +1193,25 @@ describe('CarbonChart', () => {
|
|
|
1069
1193
|
|
|
1070
1194
|
expect(results).toHaveNoViolations();
|
|
1071
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
|
+
'aria-tooltip-name': { enabled: false },
|
|
1210
|
+
},
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
expect(results).toHaveNoViolations();
|
|
1214
|
+
});
|
|
1072
1215
|
});
|
|
1073
1216
|
|
|
1074
1217
|
describe('Legend accessibility wrap', () => {
|
|
@@ -1265,4 +1408,141 @@ describe('CarbonChart', () => {
|
|
|
1265
1408
|
);
|
|
1266
1409
|
});
|
|
1267
1410
|
});
|
|
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
|
+
});
|
|
1268
1548
|
});
|