@react-magma/charts 13.2.0-next.0 → 13.2.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 +392 -32
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { css } from '@emotion/react';
|
|
3
|
-
import { Card, Datagrid, Spinner, useForceUpdate, StyledTooltip, ThemeContext, TooltipPosition, TooltipArrow, Checkbox, I18nContext, styled as styled$1, Paragraph, TabsContainer, TabPanel, useDescendants, TypographyVisualStyle, Tabs, Tab, Tooltip, IconButton, ButtonVariant, Announce, TabPanelsContainer, Table, TableHead, TableRow, TableHeaderCell, TableBody, TableCell, Dropdown, DropdownButton, DropdownContent, ModalSize, Modal, Button, Heading, useIsInverse, DropdownMenuItem, DropdownDivider } from 'react-magma-dom';
|
|
3
|
+
import { Card, Datagrid, Spinner, useForceUpdate, StyledTooltip, ThemeContext, TooltipPosition, TooltipArrow, Checkbox, I18nContext, styled as styled$1, Paragraph, TabsContainer, TabPanel, useDescendants, TypographyVisualStyle, Tabs, Tab, Tooltip, IconButton, ButtonVariant, Announce, TabPanelsContainer, Table, TableHead, TableRow, TableHeaderCell, TableBody, TableCell, Dropdown, DropdownButton, DropdownContent, ModalSize, Modal, Button, Heading, useIsInverse, useDeviceDetect, VisuallyHidden, DropdownMenuItem, DropdownDivider } from 'react-magma-dom';
|
|
4
4
|
import { KeyboardIcon, TableIcon, FullscreenExitIcon, FullscreenIcon, MoreVertIcon } from 'react-magma-icons';
|
|
5
5
|
import styled from '@emotion/styled';
|
|
6
6
|
import { LineSegment, Point, VictoryChart, VictoryVoronoiContainer, VictoryTooltip, VictoryAxis, VictoryLine, VictoryScatter } from 'victory';
|
|
@@ -2323,6 +2323,7 @@ var defaults = {
|
|
|
2323
2323
|
downloadAsJpg: 'Download as JPG',
|
|
2324
2324
|
downloadAsPng: 'Download as PNG',
|
|
2325
2325
|
exitFullScreen: 'Exit full screen',
|
|
2326
|
+
legendInstructions: 'Checking these checkboxes will update the chart.',
|
|
2326
2327
|
makeFullScreen: 'Make full screen',
|
|
2327
2328
|
moreOptionsAriaLabel: 'More options',
|
|
2328
2329
|
showAsTableTooltip: 'Show as table',
|
|
@@ -2334,7 +2335,7 @@ var defaults = {
|
|
|
2334
2335
|
*/
|
|
2335
2336
|
// eslint-disable-next-line complexity
|
|
2336
2337
|
function useChartToolbarI18n() {
|
|
2337
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
2338
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
2338
2339
|
var i18n = React.useContext(I18nContext);
|
|
2339
2340
|
var toolbar = (_a = i18n.charts) === null || _a === void 0 ? void 0 : _a.toolbar;
|
|
2340
2341
|
if (!toolbar)
|
|
@@ -2345,10 +2346,11 @@ function useChartToolbarI18n() {
|
|
|
2345
2346
|
downloadAsJpg: (_d = toolbar.downloadAsJpg) !== null && _d !== void 0 ? _d : defaults.downloadAsJpg,
|
|
2346
2347
|
downloadAsPng: (_e = toolbar.downloadAsPng) !== null && _e !== void 0 ? _e : defaults.downloadAsPng,
|
|
2347
2348
|
exitFullScreen: (_f = toolbar.exitFullScreen) !== null && _f !== void 0 ? _f : defaults.exitFullScreen,
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2349
|
+
legendInstructions: (_g = toolbar.legendInstructions) !== null && _g !== void 0 ? _g : defaults.legendInstructions,
|
|
2350
|
+
makeFullScreen: (_h = toolbar.makeFullScreen) !== null && _h !== void 0 ? _h : defaults.makeFullScreen,
|
|
2351
|
+
moreOptionsAriaLabel: (_j = toolbar.moreOptionsAriaLabel) !== null && _j !== void 0 ? _j : defaults.moreOptionsAriaLabel,
|
|
2352
|
+
showAsTableTooltip: (_k = toolbar.showAsTableTooltip) !== null && _k !== void 0 ? _k : defaults.showAsTableTooltip,
|
|
2353
|
+
tabularRepresentationLabel: (_l = toolbar.tabularRepresentationLabel) !== null && _l !== void 0 ? _l : defaults.tabularRepresentationLabel,
|
|
2352
2354
|
};
|
|
2353
2355
|
}
|
|
2354
2356
|
|
|
@@ -2449,7 +2451,7 @@ var FullscreenRoot = styled.div(templateObject_2 || (templateObject_2 = __makeTe
|
|
|
2449
2451
|
? props.theme.colors.primary700
|
|
2450
2452
|
: props.theme.colors.neutral100;
|
|
2451
2453
|
});
|
|
2452
|
-
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: ",
|
|
2454
|
+
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: ",
|
|
2453
2455
|
";\n\n .cds--chart-holder {\n height: 100vh !important;\n }\n }\n\n .cds--data-table thead tr th {\n background: ",
|
|
2454
2456
|
" !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: ",
|
|
2455
2457
|
";\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: ",
|
|
@@ -2900,7 +2902,12 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
2900
2902
|
var internalRef = React.useRef(null);
|
|
2901
2903
|
var _a = React.useState(false), isTableOpen = _a[0], setIsTableOpen = _a[1];
|
|
2902
2904
|
var _b = React.useState(false), isFullscreen = _b[0], setIsFullscreen = _b[1];
|
|
2905
|
+
var _c = React.useState(''), legendAnnouncement = _c[0], setLegendAnnouncement = _c[1];
|
|
2906
|
+
var legendGroupAnnounceRef = React.useRef(null);
|
|
2903
2907
|
var lastTableTriggerRef = React.useRef(null);
|
|
2908
|
+
var legendAnnouncedRef = React.useRef(false);
|
|
2909
|
+
var selectionSignatureRef = React.useRef(undefined);
|
|
2910
|
+
var _d = useDeviceDetect(), isMacOS = _d.isMacOS, isChrome = _d.isChrome;
|
|
2904
2911
|
var mergedRef = React.useCallback(function (node) {
|
|
2905
2912
|
internalRef.current = node;
|
|
2906
2913
|
if (typeof ref === 'function') {
|
|
@@ -2967,6 +2974,121 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
2967
2974
|
}
|
|
2968
2975
|
}, []);
|
|
2969
2976
|
var chartTitle = options.title || toolbarI18n.defaultTitle;
|
|
2977
|
+
var legendLabel = (ariaLabel || chartTitle) + ". " + toolbarI18n.legendInstructions;
|
|
2978
|
+
React.useEffect(function () {
|
|
2979
|
+
var container = internalRef.current;
|
|
2980
|
+
if (!container)
|
|
2981
|
+
return;
|
|
2982
|
+
var applyListSemantics = function (legend) {
|
|
2983
|
+
var itemsHost = legend.matches('[data-name="legend-items"]')
|
|
2984
|
+
? legend
|
|
2985
|
+
: legend.querySelector('[data-name="legend-items"]') || legend;
|
|
2986
|
+
itemsHost.removeAttribute('aria-label');
|
|
2987
|
+
if (itemsHost.getAttribute('role') !== 'list') {
|
|
2988
|
+
itemsHost.setAttribute('role', 'list');
|
|
2989
|
+
}
|
|
2990
|
+
legend.querySelectorAll('.legend-item').forEach(function (item) {
|
|
2991
|
+
if (item.getAttribute('role') !== 'listitem') {
|
|
2992
|
+
item.setAttribute('role', 'listitem');
|
|
2993
|
+
}
|
|
2994
|
+
});
|
|
2995
|
+
container.querySelectorAll('[role="list"]').forEach(function (el) {
|
|
2996
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
2997
|
+
el.removeAttribute('role');
|
|
2998
|
+
}
|
|
2999
|
+
});
|
|
3000
|
+
container.querySelectorAll('[aria-label="Data groups"]').forEach(function (el) {
|
|
3001
|
+
if (el !== itemsHost && el.contains(itemsHost)) {
|
|
3002
|
+
el.removeAttribute('aria-label');
|
|
3003
|
+
}
|
|
3004
|
+
});
|
|
3005
|
+
};
|
|
3006
|
+
var unwrapFieldset = function (fieldset) {
|
|
3007
|
+
var _a;
|
|
3008
|
+
(_a = fieldset.querySelector(':scope > legend')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
3009
|
+
fieldset.replaceWith.apply(fieldset, Array.from(fieldset.childNodes));
|
|
3010
|
+
};
|
|
3011
|
+
var wrapLegend = function () {
|
|
3012
|
+
var legend = container.querySelector('.cds--cc--legend');
|
|
3013
|
+
if (!legend)
|
|
3014
|
+
return;
|
|
3015
|
+
applyListSemantics(legend);
|
|
3016
|
+
var closestFieldset = legend.closest('fieldset.cds--cc--legend-fieldset');
|
|
3017
|
+
container
|
|
3018
|
+
.querySelectorAll('fieldset.cds--cc--legend-fieldset')
|
|
3019
|
+
.forEach(function (fieldset) {
|
|
3020
|
+
if (fieldset !== closestFieldset) {
|
|
3021
|
+
unwrapFieldset(fieldset);
|
|
3022
|
+
}
|
|
3023
|
+
});
|
|
3024
|
+
if (closestFieldset) {
|
|
3025
|
+
var existingCaption = closestFieldset.querySelector(':scope > legend');
|
|
3026
|
+
if (existingCaption && existingCaption.textContent !== legendLabel) {
|
|
3027
|
+
existingCaption.textContent = legendLabel;
|
|
3028
|
+
}
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
var fieldset = document.createElement('fieldset');
|
|
3032
|
+
var caption = document.createElement('legend');
|
|
3033
|
+
fieldset.className = 'cds--cc--legend-fieldset';
|
|
3034
|
+
caption.textContent = legendLabel;
|
|
3035
|
+
legend.before(fieldset);
|
|
3036
|
+
fieldset.append(caption, legend);
|
|
3037
|
+
};
|
|
3038
|
+
wrapLegend();
|
|
3039
|
+
var observer = new MutationObserver(wrapLegend);
|
|
3040
|
+
observer.observe(container, {
|
|
3041
|
+
childList: true,
|
|
3042
|
+
subtree: true,
|
|
3043
|
+
attributes: true,
|
|
3044
|
+
attributeFilter: ['role', 'aria-label'],
|
|
3045
|
+
});
|
|
3046
|
+
return function () { return observer.disconnect(); };
|
|
3047
|
+
}, [legendLabel]);
|
|
3048
|
+
React.useEffect(function () {
|
|
3049
|
+
var container = internalRef.current;
|
|
3050
|
+
if (!container || !isMacOS || !isChrome)
|
|
3051
|
+
return;
|
|
3052
|
+
var announceTimer;
|
|
3053
|
+
var alternateSuffix = false;
|
|
3054
|
+
var closestLegend = function (node) {
|
|
3055
|
+
return node instanceof Element ? node.closest('.cds--cc--legend') : null;
|
|
3056
|
+
};
|
|
3057
|
+
var handleFocusIn = function (event) {
|
|
3058
|
+
var enteredLegend = closestLegend(event.target);
|
|
3059
|
+
var cameFromLegend = closestLegend(event.relatedTarget);
|
|
3060
|
+
if (enteredLegend && !cameFromLegend) {
|
|
3061
|
+
if (legendGroupAnnounceRef.current) {
|
|
3062
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
3063
|
+
}
|
|
3064
|
+
clearTimeout(announceTimer);
|
|
3065
|
+
announceTimer = setTimeout(function () {
|
|
3066
|
+
if (legendGroupAnnounceRef.current) {
|
|
3067
|
+
alternateSuffix = !alternateSuffix;
|
|
3068
|
+
legendGroupAnnounceRef.current.textContent =
|
|
3069
|
+
legendLabel + (alternateSuffix ? ' ' : '');
|
|
3070
|
+
}
|
|
3071
|
+
}, 250);
|
|
3072
|
+
}
|
|
3073
|
+
};
|
|
3074
|
+
var handleFocusOut = function (event) {
|
|
3075
|
+
var leftLegend = closestLegend(event.target) && !closestLegend(event.relatedTarget);
|
|
3076
|
+
// Reset once focus leaves the legend so re-entering announces again.
|
|
3077
|
+
if (leftLegend) {
|
|
3078
|
+
clearTimeout(announceTimer);
|
|
3079
|
+
if (legendGroupAnnounceRef.current) {
|
|
3080
|
+
legendGroupAnnounceRef.current.textContent = '';
|
|
3081
|
+
}
|
|
3082
|
+
}
|
|
3083
|
+
};
|
|
3084
|
+
container.addEventListener('focusin', handleFocusIn);
|
|
3085
|
+
container.addEventListener('focusout', handleFocusOut);
|
|
3086
|
+
return function () {
|
|
3087
|
+
clearTimeout(announceTimer);
|
|
3088
|
+
container.removeEventListener('focusin', handleFocusIn);
|
|
3089
|
+
container.removeEventListener('focusout', handleFocusOut);
|
|
3090
|
+
};
|
|
3091
|
+
}, [isMacOS, isChrome, legendLabel]);
|
|
2970
3092
|
var handleModalDownloadCsv = React.useCallback(function () {
|
|
2971
3093
|
downloadCsv(dataSet, chartTitle);
|
|
2972
3094
|
}, [dataSet, chartTitle]);
|
|
@@ -3089,12 +3211,85 @@ var CarbonChart = React.forwardRef(function (props, ref) {
|
|
|
3089
3211
|
wrapper.removeEventListener('keydown', onKeyDown);
|
|
3090
3212
|
};
|
|
3091
3213
|
}, [type]);
|
|
3214
|
+
React.useEffect(function () {
|
|
3215
|
+
var timer = setTimeout(function () {
|
|
3216
|
+
if (internalRef.current) {
|
|
3217
|
+
internalRef.current
|
|
3218
|
+
.querySelectorAll('g[aria-label]')
|
|
3219
|
+
.forEach(function (g) {
|
|
3220
|
+
var role = g.getAttribute('role');
|
|
3221
|
+
if (!role) {
|
|
3222
|
+
g.setAttribute('role', 'img');
|
|
3223
|
+
}
|
|
3224
|
+
else if (role === 'graphics-object group') {
|
|
3225
|
+
g.setAttribute('role', 'graphics-object');
|
|
3226
|
+
}
|
|
3227
|
+
});
|
|
3228
|
+
}
|
|
3229
|
+
}, 0);
|
|
3230
|
+
return function () { return clearTimeout(timer); };
|
|
3231
|
+
}, [type, dataSet]);
|
|
3232
|
+
React.useEffect(function () {
|
|
3233
|
+
var wrapper = internalRef.current;
|
|
3234
|
+
if (!wrapper)
|
|
3235
|
+
return;
|
|
3236
|
+
var observer = new MutationObserver(function () {
|
|
3237
|
+
var allItems = wrapper.querySelectorAll('.legend-item:not(.additional)');
|
|
3238
|
+
if (allItems.length <= 1)
|
|
3239
|
+
return;
|
|
3240
|
+
var activeLabels = [];
|
|
3241
|
+
allItems.forEach(function (el) {
|
|
3242
|
+
var _a;
|
|
3243
|
+
var checkbox = el.querySelector('.checkbox');
|
|
3244
|
+
var label = el.querySelector('p');
|
|
3245
|
+
if ((checkbox === null || checkbox === void 0 ? void 0 : checkbox.getAttribute('aria-checked')) === 'true' && label) {
|
|
3246
|
+
activeLabels.push(((_a = label.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '');
|
|
3247
|
+
}
|
|
3248
|
+
});
|
|
3249
|
+
// Carbon re-applies aria-checked (with the same values) on every
|
|
3250
|
+
// render, which still triggers this observer. Only announce when the
|
|
3251
|
+
// selection actually changed, otherwise unrelated re-renders (e.g.
|
|
3252
|
+
// the legend group announcement) cause phantom announcements.
|
|
3253
|
+
var selectionSignature = activeLabels.join('|') + "::" + allItems.length;
|
|
3254
|
+
if (selectionSignatureRef.current === selectionSignature)
|
|
3255
|
+
return;
|
|
3256
|
+
var isFirstRun = selectionSignatureRef.current === undefined;
|
|
3257
|
+
selectionSignatureRef.current = selectionSignature;
|
|
3258
|
+
if (isFirstRun)
|
|
3259
|
+
return;
|
|
3260
|
+
if (activeLabels.length === 1) {
|
|
3261
|
+
if (!legendAnnouncedRef.current) {
|
|
3262
|
+
legendAnnouncedRef.current = true;
|
|
3263
|
+
setLegendAnnouncement("Only " + activeLabels[0] + " is selected");
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
else if (activeLabels.length === allItems.length) {
|
|
3267
|
+
legendAnnouncedRef.current = false;
|
|
3268
|
+
setLegendAnnouncement('All items selected');
|
|
3269
|
+
}
|
|
3270
|
+
else {
|
|
3271
|
+
legendAnnouncedRef.current = false;
|
|
3272
|
+
setLegendAnnouncement('');
|
|
3273
|
+
}
|
|
3274
|
+
});
|
|
3275
|
+
observer.observe(wrapper, {
|
|
3276
|
+
childList: true,
|
|
3277
|
+
subtree: true,
|
|
3278
|
+
attributes: true,
|
|
3279
|
+
attributeFilter: ['aria-checked'],
|
|
3280
|
+
});
|
|
3281
|
+
return function () { return observer.disconnect(); };
|
|
3282
|
+
}, [type, dataSet]);
|
|
3092
3283
|
var groupsLength = Object.keys(colorScale).length;
|
|
3093
3284
|
var showTable = (chartToolbar === null || chartToolbar === void 0 ? void 0 : chartToolbar.showAsTable) !== false;
|
|
3094
3285
|
if (!ChartType)
|
|
3095
3286
|
return null;
|
|
3096
3287
|
return (React.createElement(FullscreenRoot, { ref: mergedRef, isInverse: isInverse, theme: theme },
|
|
3097
|
-
React.createElement(
|
|
3288
|
+
React.createElement(VisuallyHidden, null,
|
|
3289
|
+
React.createElement(Announce, null, legendAnnouncement)),
|
|
3290
|
+
React.createElement(VisuallyHidden, null,
|
|
3291
|
+
React.createElement("div", { "aria-live": "polite", ref: legendGroupAnnounceRef })),
|
|
3292
|
+
React.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),
|
|
3098
3293
|
React.createElement(ChartContentWrapper, null,
|
|
3099
3294
|
chartToolbar && (React.createElement(CarbonChartToolbar, { config: chartToolbar, dataSet: dataSet, isInverse: isInverse, isTableOpen: isTableOpen, isFullscreen: isFullscreen, onOpenTable: openTableModal, onToggleFullscreen: toggleFullscreen, theme: theme, title: chartTitle, wrapperRef: internalRef })),
|
|
3100
3295
|
React.createElement(ChartType, { data: dataSet, options: newOptions }))),
|