@react-magma/charts 13.2.0-next.1 → 13.2.1-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 +202 -7
- package/dist/charts.js.map +1 -1
- package/dist/charts.modern.module.js +203 -8
- package/dist/charts.modern.module.js.map +1 -1
- package/dist/charts.umd.js +407 -35
- package/dist/charts.umd.js.map +1 -1
- package/dist/components/ChartTable/chartToolbarI18n.d.ts +1 -0
- package/package.json +3 -3
- package/src/components/CarbonChart/CarbonChart.test.js +214 -4
- package/src/components/CarbonChart/CarbonChart.tsx +264 -0
- package/src/components/ChartTable/chartToolbarI18n.ts +4 -0
package/dist/charts.js
CHANGED
|
@@ -2344,6 +2344,7 @@ var defaults = {
|
|
|
2344
2344
|
downloadAsJpg: 'Download as JPG',
|
|
2345
2345
|
downloadAsPng: 'Download as PNG',
|
|
2346
2346
|
exitFullScreen: 'Exit full screen',
|
|
2347
|
+
legendInstructions: 'Checking these checkboxes will update the chart.',
|
|
2347
2348
|
makeFullScreen: 'Make full screen',
|
|
2348
2349
|
moreOptionsAriaLabel: 'More options',
|
|
2349
2350
|
showAsTableTooltip: 'Show as table',
|
|
@@ -2355,7 +2356,7 @@ var defaults = {
|
|
|
2355
2356
|
*/
|
|
2356
2357
|
// eslint-disable-next-line complexity
|
|
2357
2358
|
function useChartToolbarI18n() {
|
|
2358
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2359
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
2359
2360
|
var i18n = React__namespace.useContext(reactMagmaDom.I18nContext);
|
|
2360
2361
|
var toolbar = (_a = i18n.charts) === null || _a === void 0 ? void 0 : _a.toolbar;
|
|
2361
2362
|
if (!toolbar)
|
|
@@ -2366,10 +2367,11 @@ function useChartToolbarI18n() {
|
|
|
2366
2367
|
downloadAsJpg: (_d = toolbar.downloadAsJpg) !== null && _d !== void 0 ? _d : defaults.downloadAsJpg,
|
|
2367
2368
|
downloadAsPng: (_e = toolbar.downloadAsPng) !== null && _e !== void 0 ? _e : defaults.downloadAsPng,
|
|
2368
2369
|
exitFullScreen: (_f = toolbar.exitFullScreen) !== null && _f !== void 0 ? _f : defaults.exitFullScreen,
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2370
|
+
legendInstructions: (_g = toolbar.legendInstructions) !== null && _g !== void 0 ? _g : defaults.legendInstructions,
|
|
2371
|
+
makeFullScreen: (_h = toolbar.makeFullScreen) !== null && _h !== void 0 ? _h : defaults.makeFullScreen,
|
|
2372
|
+
moreOptionsAriaLabel: (_j = toolbar.moreOptionsAriaLabel) !== null && _j !== void 0 ? _j : defaults.moreOptionsAriaLabel,
|
|
2373
|
+
showAsTableTooltip: (_k = toolbar.showAsTableTooltip) !== null && _k !== void 0 ? _k : defaults.showAsTableTooltip,
|
|
2374
|
+
tabularRepresentationLabel: (_l = toolbar.tabularRepresentationLabel) !== null && _l !== void 0 ? _l : defaults.tabularRepresentationLabel,
|
|
2373
2375
|
};
|
|
2374
2376
|
}
|
|
2375
2377
|
|
|
@@ -2470,7 +2472,7 @@ var FullscreenRoot = styled.div(templateObject_2 || (templateObject_2 = __makeTe
|
|
|
2470
2472
|
? props.theme.colors.primary700
|
|
2471
2473
|
: props.theme.colors.neutral100;
|
|
2472
2474
|
});
|
|
2473
|
-
var CarbonChartWrapper = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n &:fullscreen,\n &:-webkit-full-screen {\n background: ", ";\n\n .cds--chart-holder {\n height: 100vh !important;\n }\n }\n\n .cds--data-table thead tr th {\n background: ", " !important;\n }\n .cds--data-table td,\n .cds--data-table tbody th {\n color: ", ";\n }\n .cds--data-table tbody tr,\n .cds--data-table tbody tr td,\n .cds--data-table tbody tr th {\n color: ", ";\n }\n .cds--data-table tr {\n block-size: 2.5rem;\n }\n\n .cds--cc--tooltip .content-box .datapoint-tooltip p {\n font-size: ", ";\n padding: ", ";\n color: ", ";\n max-width: 142px;\n white-space: normal;\n }\n\n .cds--modal-container {\n clip-path: inset(0% 0% 0% 0% round ", ");\n background: ", ";\n .cds--data-table th {\n background: ", ";\n }\n .cds--data-table td {\n border-top: 1px solid\n ", ";\n border-bottom: 1px solid\n ", ";\n background: ", ";\n }\n .cds--data-table tr:hover td {\n background: ", ";\n }\n }\n\n .chart-holder p,\n .chart-holder div,\n .chart-holder text,\n .cds--cc--axes g.axis .axis-title,\n .cds--cc--title p.title,\n .cds--cc--axes g.axis g.tick text {\n font-family: ", " !important;\n color: ", ";\n }\n\n .cds--cc--axes {\n overflow: visible;\n }\n\n div.cds--cc--legend {\n div.legend-item {\n div.checkbox {\n background: ", ";\n border: none;\n width: ", ";\n height: ", ";\n svg {\n left: 2px;\n position: relative;\n }\n }\n p {\n font-size: ", ";\n margin: 0 ", " 0 0;\n }\n }\n }\n div.cds--cc--legend.has-deactivated-items {\n div.legend-item {\n div.checkbox {\n border: 1px solid\n ", ";\n }\n div.checkbox.active {\n border: 1px solid transparent;\n }\n }\n }\n .chart-holder {\n .cds--cc--axes g.axis g.tick text {\n fill: ", ";\n }\n .cds--cc--axes g.axis path.domain {\n stroke: ", ";\n }\n .cds--cc--grid g.x.grid g.tick line,\n .cds--cc--grid g.y.grid g.tick line {\n stroke: ", ";\n }\n .cds--cc--grid rect.chart-grid-backdrop.stroked {\n stroke: ", ";\n }\n .cds--cc--skeleton .shimmer-effect-lines {\n filter: ", ";\n }\n /* .chart-holder.cds--chart-holder.filled,\n .cds--cc--skeleton rect.chart-skeleton-backdrop,\n .cds--cc--grid rect.chart-grid-backdrop {\n } */\n\n .cds--cc--grid rect.chart-grid-backdrop {\n fill: transparent;\n }\n .cds--cc--scatter circle.dot,\n .cds--cc--scatter circle.dot.hovered {\n padding: 10px;\n }\n .cds--cc--scatter-stacked circle.dot.hovered,\n .cds--cc--scatter-stacked circle.dot.unfilled,\n .cds--cc--scatter circle.dot.unfilled {\n stroke-width: 6px;\n transition: 0.1s all linear;\n }\n .cds--cc--scatter circle.dot {\n filter: drop-shadow(\n 1px 0px 0px\n ", "\n )\n drop-shadow(\n -1px 0px 0px\n ", "\n )\n drop-shadow(\n 0px 1px 0px\n ", "\n )\n drop-shadow(\n 0px -1px 0px\n ", "\n );\n }\n .cds--cc--scatter circle.dot.hovered {\n stroke-width: 0.5em;\n transition: 0.1s all linear;\n filter: drop-shadow(\n 1px 0px 0px\n ", "\n )\n drop-shadow(\n -1px 0px 0px\n ", "\n )\n drop-shadow(\n 0px 1px 0px\n ", "\n )\n drop-shadow(\n 0px -1px 0px\n ", "\n );\n }\n .cds--cc--lollipop circle.dot,\n .cds--cc--lollipop circle.dot.filled,\n .cds--cc--lollipop circle.dot.hovered {\n stroke-width: 15px;\n }\n .cds--cc--scatter-stacked circle.dot,\n .cds--cc--scatter-stacked circle.dot.hovered,\n .cds--cc--scatter-stacked circle.dot.unfilled,\n .cds--cc--scatter circle.dot.unfilled,\n .cds--cc--lollipop circle.dot.filled,\n .cds--cc--lollipop circle.dot,\n .cds--cc--lollipop circle.dot.hovered {\n transition: 0.1s all linear;\n filter: drop-shadow(\n 1px 0px 0px\n ", "\n )\n drop-shadow(\n -1px 0px 0px\n ", "\n )\n drop-shadow(\n 0px 1px 0px\n ", "\n )\n drop-shadow(\n 0px -1px 0px\n ", "\n );\n }\n .cds--cc--lollipop .cds--cc--scatter circle.dot.hovered {\n transition: 0.1s all linear;\n stroke-width: 1.1em;\n }\n\n .cds--cc--tooltip {\n ", "\n }\n\n .cds--overflow-menu-options__btn:focus {\n outline-color: ", ";\n }\n\n .cds--btn {\n min-height: auto;\n display: flex;\n flex: 0 auto;\n align-items: center;\n text-align: center;\n padding: 20px;\n margin: 0;\n line-height: ", ";\n margin: 0;\n min-width: ", ";\n overflow: hidden;\n position: relative;\n right: ", ";\n text-align: center;\n height: 40px;\n font-family: ", ";\n font-size: ", ";\n border-radius: ", ";\n font-weight: 500;\n }\n\n .cds--btn--primary {\n background: ", ";\n color: ", ";\n }\n\n *:focus {\n outline: 2px solid\n ", " !important;\n outline-offset: 0;\n }\n circle.dot:focus {\n outline: none !important;\n }\n .cds--overflow-menu-options__btn:focus,\n .cds--overflow-menu:focus,\n .cds--overflow-menu__trigger:focus,\n .toolbar-control:focus {\n outline: 2px solid\n ", " !important;\n }\n div.cds--cc--legend.clickable\n div.legend-item:not(.additional):focus\n div.checkbox,\n div.cds--cc--legend.clickable\n div.legend-item:not(.additional):hover\n div.checkbox {\n border: ", ";\n }\n div.cds--cc--legend.clickable\n div.legend-item:not(.additional):hover\n div.checkbox {\n box-shadow: 0 0 0 2px\n ", " !important;\n }\n\n .cds--btn--primary {\n &:focus {\n outline: 2px solid\n ", ";\n }\n outline-offset: 2px;\n border: none;\n box-shadow: none;\n }\n .cds--modal-header {\n background: ", ";\n margin-bottom: 0;\n border-bottom: 1px solid\n ", ";\n }\n .cds--modal-header__heading {\n font-weight: 600;\n }\n\n .cds--modal-close {\n position: absolute;\n top: 0;\n right: 0;\n &:focus {\n outline: 2px solid\n ", ";\n border-color: none;\n }\n outline-offset: 0;\n border: none;\n }\n }\n\n .cds--modal-footer.cds--modal-footer {\n display: flex;\n align-items: center;\n border-top: 1px solid\n ", ";\n background: ", " !important;\n }\n .layout-child.header {\n height: auto !important;\n p {\n text-overflow: inherit;\n overflow: auto;\n white-space: normal;\n }\n }\n\n &.has-magma-toolbar .cds--cc--title p.title {\n visibility: hidden;\n }\n\n svg:not(:root) {\n overflow: visible;\n }\n\n circle.dot:focus {\n outline: none;\n stroke: ", " !important;\n stroke-width: 6px !important;\n stroke-opacity: 1 !important;\n paint-order: stroke fill;\n }\n\n .cds--cc--chart-wrapper text {\n font-size: ", ";\n }\n\n g.center text,\n .pie-label {\n fill: ", ";\n }\n\n // Zoom responsive tweaks\n\n @media screen and (max-width: 760px) {\n .cds--modal-container {\n overflow-y: auto;\n }\n .cds--chart-holder .cds--modal .cds--modal-container .cds--modal-content {\n overflow: visible;\n }\n .cds--chart-holder\n .cds--modal\n .cds--modal-container\n .cds--modal-content\n table\n th {\n position: relative;\n }\n }\n"], ["\n &:fullscreen,\n &:-webkit-full-screen {\n background: ",
|
|
2475
|
+
var CarbonChartWrapper = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n .cds--cc--legend-fieldset {\n border: 0;\n margin: 0;\n min-inline-size: 0;\n padding: 0;\n }\n\n .cds--cc--legend-fieldset > legend {\n clip: rect(1px, 1px, 1px, 1px);\n height: 1px;\n overflow: hidden;\n position: absolute;\n top: auto;\n white-space: nowrap;\n width: 1px;\n }\n\n &:fullscreen,\n &:-webkit-full-screen {\n background: ", ";\n\n .cds--chart-holder {\n height: 100vh !important;\n }\n }\n\n .cds--data-table thead tr th {\n background: ", " !important;\n }\n .cds--data-table td,\n .cds--data-table tbody th {\n color: ", ";\n }\n .cds--data-table tbody tr,\n .cds--data-table tbody tr td,\n .cds--data-table tbody tr th {\n color: ", ";\n }\n .cds--data-table tr {\n block-size: 2.5rem;\n }\n\n .cds--cc--tooltip .content-box .datapoint-tooltip p {\n font-size: ", ";\n padding: ", ";\n color: ", ";\n max-width: 142px;\n white-space: normal;\n }\n\n .cds--modal-container {\n clip-path: inset(0% 0% 0% 0% round ", ");\n background: ", ";\n .cds--data-table th {\n background: ", ";\n }\n .cds--data-table td {\n border-top: 1px solid\n ", ";\n border-bottom: 1px solid\n ", ";\n background: ", ";\n }\n .cds--data-table tr:hover td {\n background: ", ";\n }\n }\n\n .chart-holder p,\n .chart-holder div,\n .chart-holder text,\n .cds--cc--axes g.axis .axis-title,\n .cds--cc--title p.title,\n .cds--cc--axes g.axis g.tick text {\n font-family: ", " !important;\n color: ", ";\n }\n\n .cds--cc--axes {\n overflow: visible;\n }\n\n div.cds--cc--legend {\n div.legend-item {\n div.checkbox {\n background: ", ";\n border: none;\n width: ", ";\n height: ", ";\n svg {\n left: 2px;\n position: relative;\n }\n }\n p {\n font-size: ", ";\n margin: 0 ", " 0 0;\n }\n }\n }\n div.cds--cc--legend.has-deactivated-items {\n div.legend-item {\n div.checkbox {\n border: 1px solid\n ", ";\n }\n div.checkbox.active {\n border: 1px solid transparent;\n }\n }\n }\n .chart-holder {\n .cds--cc--axes g.axis g.tick text {\n fill: ", ";\n }\n .cds--cc--axes g.axis path.domain {\n stroke: ", ";\n }\n .cds--cc--grid g.x.grid g.tick line,\n .cds--cc--grid g.y.grid g.tick line {\n stroke: ", ";\n }\n .cds--cc--grid rect.chart-grid-backdrop.stroked {\n stroke: ", ";\n }\n .cds--cc--skeleton .shimmer-effect-lines {\n filter: ", ";\n }\n /* .chart-holder.cds--chart-holder.filled,\n .cds--cc--skeleton rect.chart-skeleton-backdrop,\n .cds--cc--grid rect.chart-grid-backdrop {\n } */\n\n .cds--cc--grid rect.chart-grid-backdrop {\n fill: transparent;\n }\n .cds--cc--scatter circle.dot,\n .cds--cc--scatter circle.dot.hovered {\n padding: 10px;\n }\n .cds--cc--scatter-stacked circle.dot.hovered,\n .cds--cc--scatter-stacked circle.dot.unfilled,\n .cds--cc--scatter circle.dot.unfilled {\n stroke-width: 6px;\n transition: 0.1s all linear;\n }\n .cds--cc--scatter circle.dot {\n filter: drop-shadow(\n 1px 0px 0px\n ", "\n )\n drop-shadow(\n -1px 0px 0px\n ", "\n )\n drop-shadow(\n 0px 1px 0px\n ", "\n )\n drop-shadow(\n 0px -1px 0px\n ", "\n );\n }\n .cds--cc--scatter circle.dot.hovered {\n stroke-width: 0.5em;\n transition: 0.1s all linear;\n filter: drop-shadow(\n 1px 0px 0px\n ", "\n )\n drop-shadow(\n -1px 0px 0px\n ", "\n )\n drop-shadow(\n 0px 1px 0px\n ", "\n )\n drop-shadow(\n 0px -1px 0px\n ", "\n );\n }\n .cds--cc--lollipop circle.dot,\n .cds--cc--lollipop circle.dot.filled,\n .cds--cc--lollipop circle.dot.hovered {\n stroke-width: 15px;\n }\n .cds--cc--scatter-stacked circle.dot,\n .cds--cc--scatter-stacked circle.dot.hovered,\n .cds--cc--scatter-stacked circle.dot.unfilled,\n .cds--cc--scatter circle.dot.unfilled,\n .cds--cc--lollipop circle.dot.filled,\n .cds--cc--lollipop circle.dot,\n .cds--cc--lollipop circle.dot.hovered {\n transition: 0.1s all linear;\n filter: drop-shadow(\n 1px 0px 0px\n ", "\n )\n drop-shadow(\n -1px 0px 0px\n ", "\n )\n drop-shadow(\n 0px 1px 0px\n ", "\n )\n drop-shadow(\n 0px -1px 0px\n ", "\n );\n }\n .cds--cc--lollipop .cds--cc--scatter circle.dot.hovered {\n transition: 0.1s all linear;\n stroke-width: 1.1em;\n }\n\n .cds--cc--tooltip {\n ", "\n }\n\n .cds--overflow-menu-options__btn:focus {\n outline-color: ", ";\n }\n\n .cds--btn {\n min-height: auto;\n display: flex;\n flex: 0 auto;\n align-items: center;\n text-align: center;\n padding: 20px;\n margin: 0;\n line-height: ", ";\n margin: 0;\n min-width: ", ";\n overflow: hidden;\n position: relative;\n right: ", ";\n text-align: center;\n height: 40px;\n font-family: ", ";\n font-size: ", ";\n border-radius: ", ";\n font-weight: 500;\n }\n\n .cds--btn--primary {\n background: ", ";\n color: ", ";\n }\n\n *:focus {\n outline: 2px solid\n ", " !important;\n outline-offset: 0;\n }\n circle.dot:focus {\n outline: none !important;\n }\n .cds--overflow-menu-options__btn:focus,\n .cds--overflow-menu:focus,\n .cds--overflow-menu__trigger:focus,\n .toolbar-control:focus {\n outline: 2px solid\n ", " !important;\n }\n div.cds--cc--legend.clickable\n div.legend-item:not(.additional):focus\n div.checkbox,\n div.cds--cc--legend.clickable\n div.legend-item:not(.additional):hover\n div.checkbox {\n border: ", ";\n }\n div.cds--cc--legend.clickable\n div.legend-item:not(.additional):hover\n div.checkbox {\n box-shadow: 0 0 0 2px\n ", " !important;\n }\n\n .cds--btn--primary {\n &:focus {\n outline: 2px solid\n ", ";\n }\n outline-offset: 2px;\n border: none;\n box-shadow: none;\n }\n .cds--modal-header {\n background: ", ";\n margin-bottom: 0;\n border-bottom: 1px solid\n ", ";\n }\n .cds--modal-header__heading {\n font-weight: 600;\n }\n\n .cds--modal-close {\n position: absolute;\n top: 0;\n right: 0;\n &:focus {\n outline: 2px solid\n ", ";\n border-color: none;\n }\n outline-offset: 0;\n border: none;\n }\n }\n\n .cds--modal-footer.cds--modal-footer {\n display: flex;\n align-items: center;\n border-top: 1px solid\n ", ";\n background: ", " !important;\n }\n .layout-child.header {\n height: auto !important;\n p {\n text-overflow: inherit;\n overflow: auto;\n white-space: normal;\n }\n }\n\n &.has-magma-toolbar .cds--cc--title p.title {\n visibility: hidden;\n }\n\n svg:not(:root) {\n overflow: visible;\n }\n\n circle.dot:focus {\n outline: none;\n stroke: ", " !important;\n stroke-width: 6px !important;\n stroke-opacity: 1 !important;\n paint-order: stroke fill;\n }\n\n .cds--cc--chart-wrapper text {\n font-size: ", ";\n }\n\n g.center text,\n .pie-label {\n fill: ", ";\n }\n\n // Zoom responsive tweaks\n\n @media screen and (max-width: 760px) {\n .cds--modal-container {\n overflow-y: auto;\n }\n .cds--chart-holder .cds--modal .cds--modal-container .cds--modal-content {\n overflow: visible;\n }\n .cds--chart-holder\n .cds--modal\n .cds--modal-container\n .cds--modal-content\n table\n th {\n position: relative;\n }\n }\n"], ["\n .cds--cc--legend-fieldset {\n border: 0;\n margin: 0;\n min-inline-size: 0;\n padding: 0;\n }\n\n .cds--cc--legend-fieldset > legend {\n clip: rect(1px, 1px, 1px, 1px);\n height: 1px;\n overflow: hidden;\n position: absolute;\n top: auto;\n white-space: nowrap;\n width: 1px;\n }\n\n &:fullscreen,\n &:-webkit-full-screen {\n background: ",
|
|
2474
2476
|
";\n\n .cds--chart-holder {\n height: 100vh !important;\n }\n }\n\n .cds--data-table thead tr th {\n background: ",
|
|
2475
2477
|
" !important;\n }\n .cds--data-table td,\n .cds--data-table tbody th {\n color: ", ";\n }\n .cds--data-table tbody tr,\n .cds--data-table tbody tr td,\n .cds--data-table tbody tr th {\n color: ", ";\n }\n .cds--data-table tr {\n block-size: 2.5rem;\n }\n\n .cds--cc--tooltip .content-box .datapoint-tooltip p {\n font-size: ", ";\n padding: ", ";\n color: ",
|
|
2476
2478
|
";\n max-width: 142px;\n white-space: normal;\n }\n\n .cds--modal-container {\n clip-path: inset(0% 0% 0% 0% round ", ");\n background: ",
|
|
@@ -2921,7 +2923,12 @@ var CarbonChart = React__namespace.forwardRef(function (props, ref) {
|
|
|
2921
2923
|
var internalRef = React__namespace.useRef(null);
|
|
2922
2924
|
var _a = React__namespace.useState(false), isTableOpen = _a[0], setIsTableOpen = _a[1];
|
|
2923
2925
|
var _b = React__namespace.useState(false), isFullscreen = _b[0], setIsFullscreen = _b[1];
|
|
2926
|
+
var _c = React__namespace.useState(''), legendAnnouncement = _c[0], setLegendAnnouncement = _c[1];
|
|
2927
|
+
var legendGroupAnnounceRef = React__namespace.useRef(null);
|
|
2924
2928
|
var lastTableTriggerRef = React__namespace.useRef(null);
|
|
2929
|
+
var legendAnnouncedRef = React__namespace.useRef(false);
|
|
2930
|
+
var selectionSignatureRef = React__namespace.useRef(undefined);
|
|
2931
|
+
var _d = reactMagmaDom.useDeviceDetect(), isMacOS = _d.isMacOS, isChrome = _d.isChrome;
|
|
2925
2932
|
var mergedRef = React__namespace.useCallback(function (node) {
|
|
2926
2933
|
internalRef.current = node;
|
|
2927
2934
|
if (typeof ref === 'function') {
|
|
@@ -2988,6 +2995,121 @@ var CarbonChart = React__namespace.forwardRef(function (props, ref) {
|
|
|
2988
2995
|
}
|
|
2989
2996
|
}, []);
|
|
2990
2997
|
var chartTitle = options.title || toolbarI18n.defaultTitle;
|
|
2998
|
+
var legendLabel = (ariaLabel || chartTitle) + ". " + toolbarI18n.legendInstructions;
|
|
2999
|
+
React__namespace.useEffect(function () {
|
|
3000
|
+
var container = internalRef.current;
|
|
3001
|
+
if (!container)
|
|
3002
|
+
return;
|
|
3003
|
+
var applyListSemantics = function (legend) {
|
|
3004
|
+
var itemsHost = legend.matches('[data-name="legend-items"]')
|
|
3005
|
+
? legend
|
|
3006
|
+
: legend.querySelector('[data-name="legend-items"]') || legend;
|
|
3007
|
+
itemsHost.removeAttribute('aria-label');
|
|
3008
|
+
if (itemsHost.getAttribute('role') !== 'list') {
|
|
3009
|
+
itemsHost.setAttribute('role', 'list');
|
|
3010
|
+
}
|
|
3011
|
+
legend.querySelectorAll('.legend-item').forEach(function (item) {
|
|
3012
|
+
if (item.getAttribute('role') !== 'listitem') {
|
|
3013
|
+
item.setAttribute('role', 'listitem');
|
|
3014
|
+
}
|
|
3015
|
+
});
|
|
3016
|
+
container.querySelectorAll('[role="list"]').forEach(function (el) {
|
|
3017
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
3018
|
+
el.removeAttribute('role');
|
|
3019
|
+
}
|
|
3020
|
+
});
|
|
3021
|
+
container.querySelectorAll('[aria-label="Data groups"]').forEach(function (el) {
|
|
3022
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
3023
|
+
el.removeAttribute('aria-label');
|
|
3024
|
+
}
|
|
3025
|
+
});
|
|
3026
|
+
};
|
|
3027
|
+
var unwrapFieldset = function (fieldset) {
|
|
3028
|
+
var _a;
|
|
3029
|
+
(_a = fieldset.querySelector(':scope > legend')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
3030
|
+
fieldset.replaceWith.apply(fieldset, Array.from(fieldset.childNodes));
|
|
3031
|
+
};
|
|
3032
|
+
var wrapLegend = function () {
|
|
3033
|
+
var legend = container.querySelector('.cds--cc--legend');
|
|
3034
|
+
if (!legend)
|
|
3035
|
+
return;
|
|
3036
|
+
applyListSemantics(legend);
|
|
3037
|
+
var closestFieldset = legend.closest('fieldset.cds--cc--legend-fieldset');
|
|
3038
|
+
container
|
|
3039
|
+
.querySelectorAll('fieldset.cds--cc--legend-fieldset')
|
|
3040
|
+
.forEach(function (fieldset) {
|
|
3041
|
+
if (fieldset !== closestFieldset) {
|
|
3042
|
+
unwrapFieldset(fieldset);
|
|
3043
|
+
}
|
|
3044
|
+
});
|
|
3045
|
+
if (closestFieldset) {
|
|
3046
|
+
var existingCaption = closestFieldset.querySelector(':scope > legend');
|
|
3047
|
+
if (existingCaption && existingCaption.textContent !== legendLabel) {
|
|
3048
|
+
existingCaption.textContent = legendLabel;
|
|
3049
|
+
}
|
|
3050
|
+
return;
|
|
3051
|
+
}
|
|
3052
|
+
var fieldset = document.createElement('fieldset');
|
|
3053
|
+
var caption = document.createElement('legend');
|
|
3054
|
+
fieldset.className = 'cds--cc--legend-fieldset';
|
|
3055
|
+
caption.textContent = legendLabel;
|
|
3056
|
+
legend.before(fieldset);
|
|
3057
|
+
fieldset.append(caption, legend);
|
|
3058
|
+
};
|
|
3059
|
+
wrapLegend();
|
|
3060
|
+
var observer = new MutationObserver(wrapLegend);
|
|
3061
|
+
observer.observe(container, {
|
|
3062
|
+
childList: true,
|
|
3063
|
+
subtree: true,
|
|
3064
|
+
attributes: true,
|
|
3065
|
+
attributeFilter: ['role', 'aria-label'],
|
|
3066
|
+
});
|
|
3067
|
+
return function () { return observer.disconnect(); };
|
|
3068
|
+
}, [legendLabel]);
|
|
3069
|
+
React__namespace.useEffect(function () {
|
|
3070
|
+
var container = internalRef.current;
|
|
3071
|
+
if (!container || !isMacOS || !isChrome)
|
|
3072
|
+
return;
|
|
3073
|
+
var announceTimer;
|
|
3074
|
+
var alternateSuffix = false;
|
|
3075
|
+
var closestLegend = function (node) {
|
|
3076
|
+
return node instanceof Element ? node.closest('.cds--cc--legend') : null;
|
|
3077
|
+
};
|
|
3078
|
+
var handleFocusIn = function (event) {
|
|
3079
|
+
var enteredLegend = closestLegend(event.target);
|
|
3080
|
+
var cameFromLegend = closestLegend(event.relatedTarget);
|
|
3081
|
+
if (enteredLegend && !cameFromLegend) {
|
|
3082
|
+
if (legendGroupAnnounceRef.current) {
|
|
3083
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
3084
|
+
}
|
|
3085
|
+
clearTimeout(announceTimer);
|
|
3086
|
+
announceTimer = setTimeout(function () {
|
|
3087
|
+
if (legendGroupAnnounceRef.current) {
|
|
3088
|
+
alternateSuffix = !alternateSuffix;
|
|
3089
|
+
legendGroupAnnounceRef.current.textContent =
|
|
3090
|
+
legendLabel + (alternateSuffix ? ' ' : '');
|
|
3091
|
+
}
|
|
3092
|
+
}, 250);
|
|
3093
|
+
}
|
|
3094
|
+
};
|
|
3095
|
+
var handleFocusOut = function (event) {
|
|
3096
|
+
var leftLegend = closestLegend(event.target) && !closestLegend(event.relatedTarget);
|
|
3097
|
+
// Reset once focus leaves the legend so re-entering announces again.
|
|
3098
|
+
if (leftLegend) {
|
|
3099
|
+
clearTimeout(announceTimer);
|
|
3100
|
+
if (legendGroupAnnounceRef.current) {
|
|
3101
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
3102
|
+
}
|
|
3103
|
+
}
|
|
3104
|
+
};
|
|
3105
|
+
container.addEventListener('focusin', handleFocusIn);
|
|
3106
|
+
container.addEventListener('focusout', handleFocusOut);
|
|
3107
|
+
return function () {
|
|
3108
|
+
clearTimeout(announceTimer);
|
|
3109
|
+
container.removeEventListener('focusin', handleFocusIn);
|
|
3110
|
+
container.removeEventListener('focusout', handleFocusOut);
|
|
3111
|
+
};
|
|
3112
|
+
}, [isMacOS, isChrome, legendLabel]);
|
|
2991
3113
|
var handleModalDownloadCsv = React__namespace.useCallback(function () {
|
|
2992
3114
|
downloadCsv(dataSet, chartTitle);
|
|
2993
3115
|
}, [dataSet, chartTitle]);
|
|
@@ -3110,12 +3232,85 @@ var CarbonChart = React__namespace.forwardRef(function (props, ref) {
|
|
|
3110
3232
|
wrapper.removeEventListener('keydown', onKeyDown);
|
|
3111
3233
|
};
|
|
3112
3234
|
}, [type]);
|
|
3235
|
+
React__namespace.useEffect(function () {
|
|
3236
|
+
var timer = setTimeout(function () {
|
|
3237
|
+
if (internalRef.current) {
|
|
3238
|
+
internalRef.current
|
|
3239
|
+
.querySelectorAll('g[aria-label]')
|
|
3240
|
+
.forEach(function (g) {
|
|
3241
|
+
var role = g.getAttribute('role');
|
|
3242
|
+
if (!role) {
|
|
3243
|
+
g.setAttribute('role', 'img');
|
|
3244
|
+
}
|
|
3245
|
+
else if (role === 'graphics-object group') {
|
|
3246
|
+
g.setAttribute('role', 'graphics-object');
|
|
3247
|
+
}
|
|
3248
|
+
});
|
|
3249
|
+
}
|
|
3250
|
+
}, 0);
|
|
3251
|
+
return function () { return clearTimeout(timer); };
|
|
3252
|
+
}, [type, dataSet]);
|
|
3253
|
+
React__namespace.useEffect(function () {
|
|
3254
|
+
var wrapper = internalRef.current;
|
|
3255
|
+
if (!wrapper)
|
|
3256
|
+
return;
|
|
3257
|
+
var observer = new MutationObserver(function () {
|
|
3258
|
+
var allItems = wrapper.querySelectorAll('.legend-item:not(.additional)');
|
|
3259
|
+
if (allItems.length <= 1)
|
|
3260
|
+
return;
|
|
3261
|
+
var activeLabels = [];
|
|
3262
|
+
allItems.forEach(function (el) {
|
|
3263
|
+
var _a;
|
|
3264
|
+
var checkbox = el.querySelector('.checkbox');
|
|
3265
|
+
var label = el.querySelector('p');
|
|
3266
|
+
if ((checkbox === null || checkbox === void 0 ? void 0 : checkbox.getAttribute('aria-checked')) === 'true' && label) {
|
|
3267
|
+
activeLabels.push(((_a = label.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
|
|
3268
|
+
}
|
|
3269
|
+
});
|
|
3270
|
+
// Carbon re-applies aria-checked (with the same values) on every
|
|
3271
|
+
// render, which still triggers this observer. Only announce when the
|
|
3272
|
+
// selection actually changed, otherwise unrelated re-renders (e.g.
|
|
3273
|
+
// the legend group announcement) cause phantom announcements.
|
|
3274
|
+
var selectionSignature = activeLabels.join('|') + "::" + allItems.length;
|
|
3275
|
+
if (selectionSignatureRef.current === selectionSignature)
|
|
3276
|
+
return;
|
|
3277
|
+
var isFirstRun = selectionSignatureRef.current === undefined;
|
|
3278
|
+
selectionSignatureRef.current = selectionSignature;
|
|
3279
|
+
if (isFirstRun)
|
|
3280
|
+
return;
|
|
3281
|
+
if (activeLabels.length === 1) {
|
|
3282
|
+
if (!legendAnnouncedRef.current) {
|
|
3283
|
+
legendAnnouncedRef.current = true;
|
|
3284
|
+
setLegendAnnouncement("Only " + activeLabels[0] + " is selected");
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
else if (activeLabels.length === allItems.length) {
|
|
3288
|
+
legendAnnouncedRef.current = false;
|
|
3289
|
+
setLegendAnnouncement('All items selected');
|
|
3290
|
+
}
|
|
3291
|
+
else {
|
|
3292
|
+
legendAnnouncedRef.current = false;
|
|
3293
|
+
setLegendAnnouncement('');
|
|
3294
|
+
}
|
|
3295
|
+
});
|
|
3296
|
+
observer.observe(wrapper, {
|
|
3297
|
+
childList: true,
|
|
3298
|
+
subtree: true,
|
|
3299
|
+
attributes: true,
|
|
3300
|
+
attributeFilter: ['aria-checked'],
|
|
3301
|
+
});
|
|
3302
|
+
return function () { return observer.disconnect(); };
|
|
3303
|
+
}, [type, dataSet]);
|
|
3113
3304
|
var groupsLength = Object.keys(colorScale).length;
|
|
3114
3305
|
var showTable = (chartToolbar === null || chartToolbar === void 0 ? void 0 : chartToolbar.showAsTable) !== false;
|
|
3115
3306
|
if (!ChartType)
|
|
3116
3307
|
return null;
|
|
3117
3308
|
return (React__namespace.createElement(FullscreenRoot, { ref: mergedRef, isInverse: isInverse, theme: theme },
|
|
3118
|
-
React__namespace.createElement(
|
|
3309
|
+
React__namespace.createElement(reactMagmaDom.VisuallyHidden, null,
|
|
3310
|
+
React__namespace.createElement(reactMagmaDom.Announce, null, legendAnnouncement)),
|
|
3311
|
+
React__namespace.createElement(reactMagmaDom.VisuallyHidden, null,
|
|
3312
|
+
React__namespace.createElement("div", { "aria-live": "polite", ref: legendGroupAnnounceRef })),
|
|
3313
|
+
React__namespace.createElement(CarbonChartWrapper, __assign({ "data-testid": testId, isInverse: isInverse, theme: theme, className: "carbon-chart-wrapper" + (chartToolbar ? ' has-magma-toolbar' : ''), groupsLength: groupsLength < 6 ? groupsLength : 14, role: "region", "aria-label": ariaLabel || chartTitle, "aria-roledescription": "chart" }, rest),
|
|
3119
3314
|
React__namespace.createElement(ChartContentWrapper, null,
|
|
3120
3315
|
chartToolbar && (React__namespace.createElement(CarbonChartToolbar, { config: chartToolbar, dataSet: dataSet, isInverse: isInverse, isTableOpen: isTableOpen, isFullscreen: isFullscreen, onOpenTable: openTableModal, onToggleFullscreen: toggleFullscreen, theme: theme, title: chartTitle, wrapperRef: internalRef })),
|
|
3121
3316
|
React__namespace.createElement(ChartType, { data: dataSet, options: newOptions }))),
|