@react-magma/charts 13.3.0 → 13.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/charts.js +114 -76
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +114 -76
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +278 -105
- package/dist/charts.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/components/CarbonChart/CarbonChart.test.js +27 -19
- package/src/components/CarbonChart/CarbonChart.tsx +138 -84
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-magma/charts",
|
|
3
|
-
"version": "13.3.
|
|
3
|
+
"version": "13.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"identity-obj-proxy": "^3.0.0",
|
|
48
48
|
"react": "^17.0.2",
|
|
49
49
|
"react-dom": "^17.0.2",
|
|
50
|
-
"react-magma-dom": "^4.
|
|
50
|
+
"react-magma-dom": "^4.17.0",
|
|
51
51
|
"react-magma-icons": "^3.2.5",
|
|
52
52
|
"rollup": "^4.52.4",
|
|
53
53
|
"rollup-plugin-postcss": "^4.0.2"
|
|
@@ -1144,15 +1144,6 @@ describe('CarbonChart', () => {
|
|
|
1144
1144
|
});
|
|
1145
1145
|
|
|
1146
1146
|
describe('focus on dot content', () => {
|
|
1147
|
-
it('should set opacity to 1 when a dot receives focus', () => {
|
|
1148
|
-
const wrapper = renderChart();
|
|
1149
|
-
const dot = addDot(wrapper);
|
|
1150
|
-
|
|
1151
|
-
fireEvent.focusIn(dot);
|
|
1152
|
-
|
|
1153
|
-
expect(dot.style.opacity).toBe('1');
|
|
1154
|
-
});
|
|
1155
|
-
|
|
1156
1147
|
it('should dispatch mouseover on dot focusin to reveal tooltip data', () => {
|
|
1157
1148
|
const wrapper = renderChart();
|
|
1158
1149
|
const dot = addDot(wrapper);
|
|
@@ -1192,28 +1183,45 @@ describe('CarbonChart', () => {
|
|
|
1192
1183
|
});
|
|
1193
1184
|
|
|
1194
1185
|
describe('data visibility', () => {
|
|
1195
|
-
it('should
|
|
1186
|
+
it('should dispatch mouseout on dot focusout to hide tooltip', () => {
|
|
1196
1187
|
const wrapper = renderChart();
|
|
1197
1188
|
const dot = addDot(wrapper);
|
|
1198
1189
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1190
|
+
const mouseoutSpy = jest.fn();
|
|
1191
|
+
dot.addEventListener('mouseout', mouseoutSpy);
|
|
1201
1192
|
|
|
1193
|
+
fireEvent.focusIn(dot);
|
|
1202
1194
|
fireEvent.focusOut(dot);
|
|
1203
|
-
|
|
1195
|
+
|
|
1196
|
+
expect(mouseoutSpy).toHaveBeenCalledTimes(1);
|
|
1204
1197
|
});
|
|
1205
1198
|
|
|
1206
|
-
it('should dispatch mouseout
|
|
1199
|
+
it('should not dispatch mouseout when focus moves from one dot to another', () => {
|
|
1207
1200
|
const wrapper = renderChart();
|
|
1208
|
-
const
|
|
1201
|
+
const firstDot = addDot(wrapper);
|
|
1202
|
+
const secondDot = addDot(wrapper);
|
|
1209
1203
|
|
|
1210
1204
|
const mouseoutSpy = jest.fn();
|
|
1211
|
-
|
|
1205
|
+
firstDot.addEventListener('mouseout', mouseoutSpy);
|
|
1212
1206
|
|
|
1213
|
-
fireEvent.
|
|
1214
|
-
fireEvent.focusOut(dot);
|
|
1207
|
+
fireEvent.focusOut(firstDot, { relatedTarget: secondDot });
|
|
1215
1208
|
|
|
1216
|
-
expect(mouseoutSpy).
|
|
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');
|
|
1217
1225
|
});
|
|
1218
1226
|
});
|
|
1219
1227
|
});
|
|
@@ -1408,94 +1408,17 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1408
1408
|
return () => cancelAnimationFrame(rafId);
|
|
1409
1409
|
}, [ariaLabel]);
|
|
1410
1410
|
|
|
1411
|
-
// Make Carbon Charts data points keyboard-focusable.
|
|
1412
|
-
React.useEffect(() => {
|
|
1413
|
-
const wrapper = internalRef.current;
|
|
1414
|
-
if (!wrapper) return;
|
|
1415
|
-
|
|
1416
|
-
const isDot = (el: EventTarget | null): el is SVGCircleElement =>
|
|
1417
|
-
el instanceof Element &&
|
|
1418
|
-
el.nodeName.toLowerCase() === 'circle' &&
|
|
1419
|
-
el.classList.contains('dot');
|
|
1420
|
-
|
|
1421
|
-
const onFocusIn = (e: FocusEvent) => {
|
|
1422
|
-
if (!isDot(e.target)) return;
|
|
1423
|
-
const dot = e.target as SVGCircleElement;
|
|
1424
|
-
dot.style.opacity = '1';
|
|
1425
|
-
const { left, top, width, height } = dot.getBoundingClientRect();
|
|
1426
|
-
const cx = left + width / 2;
|
|
1427
|
-
const cy = top + height / 2;
|
|
1428
|
-
dot.dispatchEvent(
|
|
1429
|
-
new MouseEvent('mouseover', {
|
|
1430
|
-
bubbles: true,
|
|
1431
|
-
clientX: cx,
|
|
1432
|
-
clientY: cy,
|
|
1433
|
-
screenX: cx,
|
|
1434
|
-
screenY: cy,
|
|
1435
|
-
})
|
|
1436
|
-
);
|
|
1437
|
-
dot.dispatchEvent(
|
|
1438
|
-
new MouseEvent('mousemove', {
|
|
1439
|
-
bubbles: true,
|
|
1440
|
-
clientX: cx,
|
|
1441
|
-
clientY: cy,
|
|
1442
|
-
screenX: cx,
|
|
1443
|
-
screenY: cy,
|
|
1444
|
-
})
|
|
1445
|
-
);
|
|
1446
|
-
};
|
|
1447
|
-
|
|
1448
|
-
const onFocusOut = (e: FocusEvent) => {
|
|
1449
|
-
if (!isDot(e.target)) return;
|
|
1450
|
-
const dot = e.target;
|
|
1451
|
-
dot.style.opacity = '';
|
|
1452
|
-
dot.dispatchEvent(new MouseEvent('mouseout', { bubbles: true }));
|
|
1453
|
-
};
|
|
1454
|
-
|
|
1455
|
-
const onKeyDown = (e: KeyboardEvent) => {
|
|
1456
|
-
if (!isDot(e.target)) return;
|
|
1457
|
-
if (e.key !== 'Enter' && e.key !== ' ') return;
|
|
1458
|
-
e.preventDefault();
|
|
1459
|
-
const dot = e.target;
|
|
1460
|
-
const { left, top, width, height } = dot.getBoundingClientRect();
|
|
1461
|
-
const cx = left + width / 2;
|
|
1462
|
-
const cy = top + height / 2;
|
|
1463
|
-
dot.dispatchEvent(
|
|
1464
|
-
new MouseEvent('click', {
|
|
1465
|
-
bubbles: true,
|
|
1466
|
-
clientX: cx,
|
|
1467
|
-
clientY: cy,
|
|
1468
|
-
})
|
|
1469
|
-
);
|
|
1470
|
-
};
|
|
1471
|
-
|
|
1472
|
-
const rafId = requestAnimationFrame(() => {
|
|
1473
|
-
wrapper
|
|
1474
|
-
.querySelectorAll<SVGCircleElement>('circle.dot')
|
|
1475
|
-
.forEach(dot => {
|
|
1476
|
-
if (!dot.hasAttribute('tabindex')) {
|
|
1477
|
-
dot.setAttribute('tabindex', '0');
|
|
1478
|
-
}
|
|
1479
|
-
});
|
|
1480
|
-
});
|
|
1481
|
-
|
|
1482
|
-
wrapper.addEventListener('focusin', onFocusIn);
|
|
1483
|
-
wrapper.addEventListener('focusout', onFocusOut);
|
|
1484
|
-
wrapper.addEventListener('keydown', onKeyDown);
|
|
1485
|
-
|
|
1486
|
-
return () => {
|
|
1487
|
-
cancelAnimationFrame(rafId);
|
|
1488
|
-
wrapper.removeEventListener('focusin', onFocusIn);
|
|
1489
|
-
wrapper.removeEventListener('focusout', onFocusOut);
|
|
1490
|
-
wrapper.removeEventListener('keydown', onKeyDown);
|
|
1491
|
-
};
|
|
1492
|
-
}, [type]);
|
|
1493
|
-
|
|
1494
1411
|
React.useEffect(() => {
|
|
1495
1412
|
const timer = setTimeout(() => {
|
|
1496
1413
|
if (internalRef.current) {
|
|
1497
1414
|
internalRef.current
|
|
1498
|
-
.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)')
|
|
1499
1422
|
.forEach(g => {
|
|
1500
1423
|
const role = g.getAttribute('role');
|
|
1501
1424
|
|
|
@@ -1511,6 +1434,30 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1511
1434
|
return () => clearTimeout(timer);
|
|
1512
1435
|
}, [type, dataSet]);
|
|
1513
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
|
+
|
|
1514
1461
|
React.useEffect(() => {
|
|
1515
1462
|
const wrapper = internalRef.current;
|
|
1516
1463
|
|
|
@@ -1572,6 +1519,113 @@ export const CarbonChart = React.forwardRef<HTMLDivElement, CarbonChartProps>(
|
|
|
1572
1519
|
return () => observer.disconnect();
|
|
1573
1520
|
}, [type, dataSet]);
|
|
1574
1521
|
|
|
1522
|
+
// Make Carbon Charts data points keyboard-focusable.
|
|
1523
|
+
React.useEffect(() => {
|
|
1524
|
+
const wrapper = internalRef.current;
|
|
1525
|
+
|
|
1526
|
+
if (!wrapper) return;
|
|
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
|
+
|
|
1538
|
+
const isDot = (el: EventTarget | null): el is SVGCircleElement =>
|
|
1539
|
+
el instanceof Element &&
|
|
1540
|
+
el.nodeName.toLowerCase() === 'circle' &&
|
|
1541
|
+
el.classList.contains('dot');
|
|
1542
|
+
|
|
1543
|
+
const onFocusIn = (e: FocusEvent) => {
|
|
1544
|
+
if (!isDot(e.target)) return;
|
|
1545
|
+
const dot = e.target as SVGCircleElement;
|
|
1546
|
+
|
|
1547
|
+
const { left, top, width, height } = dot.getBoundingClientRect();
|
|
1548
|
+
const cx = left + width / 2;
|
|
1549
|
+
const cy = top + height / 2;
|
|
1550
|
+
|
|
1551
|
+
dot.dispatchEvent(
|
|
1552
|
+
new MouseEvent('mouseover', {
|
|
1553
|
+
bubbles: true,
|
|
1554
|
+
clientX: cx,
|
|
1555
|
+
clientY: cy,
|
|
1556
|
+
screenX: cx,
|
|
1557
|
+
screenY: cy,
|
|
1558
|
+
})
|
|
1559
|
+
);
|
|
1560
|
+
dot.dispatchEvent(
|
|
1561
|
+
new MouseEvent('mousemove', {
|
|
1562
|
+
bubbles: true,
|
|
1563
|
+
clientX: cx,
|
|
1564
|
+
clientY: cy,
|
|
1565
|
+
screenX: cx,
|
|
1566
|
+
screenY: cy,
|
|
1567
|
+
})
|
|
1568
|
+
);
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
const onFocusOut = (e: FocusEvent) => {
|
|
1572
|
+
if (!isDot(e.target)) return;
|
|
1573
|
+
const dot = e.target;
|
|
1574
|
+
|
|
1575
|
+
// Keep tooltip context while Tab focus moves between chart points.
|
|
1576
|
+
if (isDot(e.relatedTarget)) {
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
dot.dispatchEvent(new MouseEvent('mouseout', { bubbles: true }));
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1583
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
1584
|
+
if (!isDot(e.target)) return;
|
|
1585
|
+
if (e.key !== 'Enter' && e.key !== ' ') return;
|
|
1586
|
+
e.preventDefault();
|
|
1587
|
+
const dot = e.target;
|
|
1588
|
+
const { left, top, width, height } = dot.getBoundingClientRect();
|
|
1589
|
+
const cx = left + width / 2;
|
|
1590
|
+
const cy = top + height / 2;
|
|
1591
|
+
|
|
1592
|
+
dot.dispatchEvent(
|
|
1593
|
+
new MouseEvent('click', {
|
|
1594
|
+
bubbles: true,
|
|
1595
|
+
clientX: cx,
|
|
1596
|
+
clientY: cy,
|
|
1597
|
+
})
|
|
1598
|
+
);
|
|
1599
|
+
};
|
|
1600
|
+
|
|
1601
|
+
const rafId = requestAnimationFrame(() => {
|
|
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'],
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
wrapper.addEventListener('focusin', onFocusIn);
|
|
1617
|
+
wrapper.addEventListener('focusout', onFocusOut);
|
|
1618
|
+
wrapper.addEventListener('keydown', onKeyDown);
|
|
1619
|
+
|
|
1620
|
+
return () => {
|
|
1621
|
+
cancelAnimationFrame(rafId);
|
|
1622
|
+
dotObserver.disconnect();
|
|
1623
|
+
wrapper.removeEventListener('focusin', onFocusIn);
|
|
1624
|
+
wrapper.removeEventListener('focusout', onFocusOut);
|
|
1625
|
+
wrapper.removeEventListener('keydown', onKeyDown);
|
|
1626
|
+
};
|
|
1627
|
+
}, [type, dataSet]);
|
|
1628
|
+
|
|
1575
1629
|
const groupsLength = Object.keys(colorScale).length;
|
|
1576
1630
|
|
|
1577
1631
|
const showTable = chartToolbar?.showAsTable !== false;
|