@react-magma/charts 15.0.0-rc.4 → 15.0.0-rc.5
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 +104 -9
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +105 -10
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +104 -9
- package/dist/charts.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/CarbonChart/CarbonChart.test.js +71 -3
- package/src/components/CarbonChart/CarbonChart.tsx +128 -9
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ComboChart, ScatterChart, MeterChart, HistogramChart, GaugeChart, BulletChart, BubbleChart, BoxplotChart, RadarChart, PieChart, LollipopChart, LineChart, DonutChart, StackedBarChart, GroupedBarChart, SimpleBarChart, StackedAreaChart, AreaChart } from '@carbon/charts-react';
|
|
3
3
|
import styled from '@emotion/styled';
|
|
4
|
-
import { Table, TableHead, TableRow, TableHeaderCell, TableBody, TableCell, I18nContext, Tooltip, IconButton, ButtonVariant, Dropdown, DropdownButton, DropdownContent, ModalSize, ThemeContext, Modal, Button, TypographyVisualStyle, Heading, useIsInverse, VisuallyHidden, Announce, DropdownMenuItem, DropdownDivider } from 'react-magma-dom';
|
|
4
|
+
import { Table, TableHead, TableRow, TableHeaderCell, TableBody, TableCell, I18nContext, Tooltip, IconButton, ButtonVariant, Dropdown, DropdownButton, DropdownContent, ModalSize, ThemeContext, Modal, Button, TypographyVisualStyle, Heading, useIsInverse, useDeviceDetect, VisuallyHidden, Announce, DropdownMenuItem, DropdownDivider } from 'react-magma-dom';
|
|
5
5
|
import { TableIcon, FullscreenExitIcon, FullscreenIcon, MoreVertIcon } from 'react-magma-icons';
|
|
6
6
|
|
|
7
7
|
/******************************************************************************
|
|
@@ -1484,8 +1484,11 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
1484
1484
|
var _a = React.useState(false), isTableOpen = _a[0], setIsTableOpen = _a[1];
|
|
1485
1485
|
var _b = React.useState(false), isFullscreen = _b[0], setIsFullscreen = _b[1];
|
|
1486
1486
|
var _c = React.useState(''), legendAnnouncement = _c[0], setLegendAnnouncement = _c[1];
|
|
1487
|
+
var legendGroupAnnounceRef = React.useRef(null);
|
|
1487
1488
|
var lastTableTriggerRef = React.useRef(null);
|
|
1488
1489
|
var legendAnnouncedRef = React.useRef(false);
|
|
1490
|
+
var selectionSignatureRef = React.useRef(undefined);
|
|
1491
|
+
var _d = useDeviceDetect(), isMacOS = _d.isMacOS, isChrome = _d.isChrome;
|
|
1489
1492
|
var mergedRef = React.useCallback(function (node) {
|
|
1490
1493
|
internalRef.current = node;
|
|
1491
1494
|
if (typeof ref === 'function') {
|
|
@@ -1552,20 +1555,49 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
1552
1555
|
if (!container)
|
|
1553
1556
|
return;
|
|
1554
1557
|
var applyListSemantics = function (legend) {
|
|
1555
|
-
legend.
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1558
|
+
var itemsHost = legend.matches('[data-name="legend-items"]')
|
|
1559
|
+
? legend
|
|
1560
|
+
: legend.querySelector('[data-name="legend-items"]') || legend;
|
|
1561
|
+
itemsHost.removeAttribute('aria-label');
|
|
1562
|
+
if (itemsHost.getAttribute('role') !== 'list') {
|
|
1563
|
+
itemsHost.setAttribute('role', 'list');
|
|
1564
|
+
}
|
|
1565
|
+
legend.querySelectorAll('.legend-item').forEach(function (item) {
|
|
1566
|
+
if (item.getAttribute('role') !== 'listitem') {
|
|
1567
|
+
item.setAttribute('role', 'listitem');
|
|
1568
|
+
}
|
|
1569
|
+
});
|
|
1570
|
+
container.querySelectorAll('[role="list"]').forEach(function (el) {
|
|
1571
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
1572
|
+
el.removeAttribute('role');
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
container.querySelectorAll('[aria-label="Data groups"]').forEach(function (el) {
|
|
1576
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
1577
|
+
el.removeAttribute('aria-label');
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
};
|
|
1581
|
+
var unwrapFieldset = function (fieldset) {
|
|
1582
|
+
var _a;
|
|
1583
|
+
(_a = fieldset.querySelector(':scope > legend')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
1584
|
+
fieldset.replaceWith.apply(fieldset, Array.from(fieldset.childNodes));
|
|
1560
1585
|
};
|
|
1561
1586
|
var wrapLegend = function () {
|
|
1562
1587
|
var legend = container.querySelector('.cds--cc--legend');
|
|
1563
1588
|
if (!legend)
|
|
1564
1589
|
return;
|
|
1565
1590
|
applyListSemantics(legend);
|
|
1566
|
-
var
|
|
1567
|
-
|
|
1568
|
-
|
|
1591
|
+
var closestFieldset = legend.closest('fieldset.cds--cc--legend-fieldset');
|
|
1592
|
+
container
|
|
1593
|
+
.querySelectorAll('fieldset.cds--cc--legend-fieldset')
|
|
1594
|
+
.forEach(function (fieldset) {
|
|
1595
|
+
if (fieldset !== closestFieldset) {
|
|
1596
|
+
unwrapFieldset(fieldset);
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
if (closestFieldset) {
|
|
1600
|
+
var existingCaption = closestFieldset.querySelector(':scope > legend');
|
|
1569
1601
|
if (existingCaption && existingCaption.textContent !== legendLabel) {
|
|
1570
1602
|
existingCaption.textContent = legendLabel;
|
|
1571
1603
|
}
|
|
@@ -1580,9 +1612,58 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
1580
1612
|
};
|
|
1581
1613
|
wrapLegend();
|
|
1582
1614
|
var observer = new MutationObserver(wrapLegend);
|
|
1583
|
-
observer.observe(container, {
|
|
1615
|
+
observer.observe(container, {
|
|
1616
|
+
childList: true,
|
|
1617
|
+
subtree: true,
|
|
1618
|
+
attributes: true,
|
|
1619
|
+
attributeFilter: ['role', 'aria-label'],
|
|
1620
|
+
});
|
|
1584
1621
|
return function () { return observer.disconnect(); };
|
|
1585
1622
|
}, [legendLabel]);
|
|
1623
|
+
React.useEffect(function () {
|
|
1624
|
+
var container = internalRef.current;
|
|
1625
|
+
if (!container || !isMacOS || !isChrome)
|
|
1626
|
+
return;
|
|
1627
|
+
var announceTimer;
|
|
1628
|
+
var alternateSuffix = false;
|
|
1629
|
+
var closestLegend = function (node) {
|
|
1630
|
+
return node instanceof Element ? node.closest('.cds--cc--legend') : null;
|
|
1631
|
+
};
|
|
1632
|
+
var handleFocusIn = function (event) {
|
|
1633
|
+
var enteredLegend = closestLegend(event.target);
|
|
1634
|
+
var cameFromLegend = closestLegend(event.relatedTarget);
|
|
1635
|
+
if (enteredLegend && !cameFromLegend) {
|
|
1636
|
+
if (legendGroupAnnounceRef.current) {
|
|
1637
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
1638
|
+
}
|
|
1639
|
+
clearTimeout(announceTimer);
|
|
1640
|
+
announceTimer = setTimeout(function () {
|
|
1641
|
+
if (legendGroupAnnounceRef.current) {
|
|
1642
|
+
alternateSuffix = !alternateSuffix;
|
|
1643
|
+
legendGroupAnnounceRef.current.textContent =
|
|
1644
|
+
legendLabel + (alternateSuffix ? ' ' : '');
|
|
1645
|
+
}
|
|
1646
|
+
}, 250);
|
|
1647
|
+
}
|
|
1648
|
+
};
|
|
1649
|
+
var handleFocusOut = function (event) {
|
|
1650
|
+
var leftLegend = closestLegend(event.target) && !closestLegend(event.relatedTarget);
|
|
1651
|
+
// Reset once focus leaves the legend so re-entering announces again.
|
|
1652
|
+
if (leftLegend) {
|
|
1653
|
+
clearTimeout(announceTimer);
|
|
1654
|
+
if (legendGroupAnnounceRef.current) {
|
|
1655
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
container.addEventListener('focusin', handleFocusIn);
|
|
1660
|
+
container.addEventListener('focusout', handleFocusOut);
|
|
1661
|
+
return function () {
|
|
1662
|
+
clearTimeout(announceTimer);
|
|
1663
|
+
container.removeEventListener('focusin', handleFocusIn);
|
|
1664
|
+
container.removeEventListener('focusout', handleFocusOut);
|
|
1665
|
+
};
|
|
1666
|
+
}, [isMacOS, isChrome, legendLabel]);
|
|
1586
1667
|
var handleModalDownloadCsv = React.useCallback(function () {
|
|
1587
1668
|
downloadCsv(dataSet, chartTitle);
|
|
1588
1669
|
}, [dataSet, chartTitle]);
|
|
@@ -1667,6 +1748,17 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
1667
1748
|
activeLabels.push(((_a = label.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
|
|
1668
1749
|
}
|
|
1669
1750
|
});
|
|
1751
|
+
// Carbon re-applies aria-checked (with the same values) on every
|
|
1752
|
+
// render, which still triggers this observer. Only announce when the
|
|
1753
|
+
// selection actually changed, otherwise unrelated re-renders (e.g.
|
|
1754
|
+
// the legend group announcement) cause phantom announcements.
|
|
1755
|
+
var selectionSignature = "".concat(activeLabels.join('|'), "::").concat(allItems.length);
|
|
1756
|
+
if (selectionSignatureRef.current === selectionSignature)
|
|
1757
|
+
return;
|
|
1758
|
+
var isFirstRun = selectionSignatureRef.current === undefined;
|
|
1759
|
+
selectionSignatureRef.current = selectionSignature;
|
|
1760
|
+
if (isFirstRun)
|
|
1761
|
+
return;
|
|
1670
1762
|
if (activeLabels.length === 1) {
|
|
1671
1763
|
if (!legendAnnouncedRef.current) {
|
|
1672
1764
|
legendAnnouncedRef.current = true;
|
|
@@ -1683,6 +1775,7 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
1683
1775
|
}
|
|
1684
1776
|
});
|
|
1685
1777
|
observer.observe(wrapper, {
|
|
1778
|
+
childList: true,
|
|
1686
1779
|
subtree: true,
|
|
1687
1780
|
attributes: true,
|
|
1688
1781
|
attributeFilter: ['aria-checked'],
|
|
@@ -1694,6 +1787,8 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
1694
1787
|
return (React.createElement(FullscreenRoot, { ref: mergedRef, isInverse: isInverse, theme: theme },
|
|
1695
1788
|
React.createElement(VisuallyHidden, null,
|
|
1696
1789
|
React.createElement(Announce, null, legendAnnouncement)),
|
|
1790
|
+
React.createElement(VisuallyHidden, null,
|
|
1791
|
+
React.createElement("div", { "aria-live": "polite", ref: legendGroupAnnounceRef })),
|
|
1697
1792
|
React.createElement(CarbonChartWrapper, __assign({ "data-testid": testId, isInverse: isInverse, theme: theme, className: "carbon-chart-wrapper".concat(chartToolbar ? ' has-magma-toolbar' : ''), groupsLength: groupsLength < 6 ? groupsLength : 14, role: "region", "aria-label": ariaLabel || chartTitle, "aria-roledescription": "chart" }, rest),
|
|
1698
1793
|
React.createElement(ChartContentWrapper, null,
|
|
1699
1794
|
chartToolbar && (React.createElement(CarbonChartToolbar, { config: chartToolbar, dataSet: dataSet, isInverse: isInverse, isTableOpen: isTableOpen, isFullscreen: isFullscreen, onOpenTable: openTableModal, onToggleFullscreen: toggleFullscreen, theme: theme, title: chartTitle, wrapperRef: internalRef })),
|