@cashub/ui-elv 1.0.2 → 1.0.4
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/datetimePicker/index.js +2 -37
- package/esm/Tab/Tab.js +21 -0
- package/esm/Tab/TabList.js +160 -0
- package/esm/Tab/TabPanel.js +42 -0
- package/esm/Tab/TabTab.js +98 -0
- package/esm/Tab/index.js +23 -0
- package/esm/Tab/subComponent/TabContext.js +3 -0
- package/esm/Tab/subComponent/TabListV2.js +18 -0
- package/esm/Tab/subComponent/TabPanelV2.js +45 -0
- package/esm/Tab/subComponent/TabTabV2.js +56 -0
- package/esm/VerticalTab/TabList.js +20 -0
- package/esm/VerticalTab/TabPanel.js +45 -0
- package/esm/VerticalTab/TabTab.js +63 -0
- package/esm/VerticalTab/VerticalTab.js +34 -0
- package/esm/VerticalTab/index.js +9 -0
- package/esm/VerticalTab/subComponent/TabContext.js +3 -0
- package/esm/alert/Alert.js +22 -0
- package/esm/alert/index.js +1 -0
- package/esm/animate/Collapse.js +65 -0
- package/esm/animate/Loader.js +51 -0
- package/esm/animate/NumberCounter.js +45 -0
- package/esm/animate/PulseRing.js +26 -0
- package/esm/animate/Spinner.js +11 -0
- package/esm/animate/index.js +5 -0
- package/esm/assets/css/autocomplete.css +16 -0
- package/esm/assets/css/font.css +4 -0
- package/esm/assets/css/global.css +2 -0
- package/esm/assets/font/helvetica/Helvetica.ttf +0 -0
- package/esm/assets/font/nanumGothic/NanumGothic-Bold.ttf +0 -0
- package/esm/assets/font/nanumGothic/NanumGothic-ExtraBold.ttf +0 -0
- package/esm/assets/font/nanumGothic/NanumGothic-Regular.ttf +0 -0
- package/esm/assets/icons/app-management.png +0 -0
- package/esm/assets/icons/burger-black.png +0 -0
- package/esm/assets/icons/burger-white.png +0 -0
- package/esm/assets/icons/burger.png +0 -0
- package/esm/assets/icons/file.svg +1 -0
- package/esm/assets/icons/map_icon1.png +0 -0
- package/esm/assets/icons/map_icon4.png +0 -0
- package/esm/assets/images/bg-aside.png +0 -0
- package/esm/assets/images/bg-chart-circle.png +0 -0
- package/esm/assets/images/bg-chart-triangle.png +0 -0
- package/esm/assets/images/cashub-logo-only.png +0 -0
- package/esm/assets/images/default-user.jpg +0 -0
- package/esm/assets/images/logo-cashub.png +0 -0
- package/esm/assets/images/map.png +0 -0
- package/esm/assets/images/qrcode.png +0 -0
- package/esm/backdrop/BaseBackdrop.js +11 -0
- package/esm/backdrop/LoadingBackdrop.js +10 -0
- package/esm/backdrop/ModalBackdrop.js +8 -0
- package/esm/backdrop/index.js +3 -0
- package/esm/badge/Badge.js +19 -0
- package/esm/badge/BadgeDot.js +11 -0
- package/esm/badge/BadgeFill.js +42 -0
- package/esm/badge/BadgeFillTriangle.js +138 -0
- package/esm/badge/BadgeWithText.js +24 -0
- package/esm/badge/index.js +5 -0
- package/esm/billing/BarChart.js +45 -0
- package/esm/billing/Grid.js +38 -0
- package/esm/billing/Header2.js +19 -0
- package/esm/billing/Header3.js +31 -0
- package/esm/billing/Paragraph.js +27 -0
- package/esm/billing/ParagraphGroup.js +16 -0
- package/esm/billing/ParagraphText.js +20 -0
- package/esm/billing/Section.js +44 -0
- package/esm/billing/SectionBody.js +11 -0
- package/esm/billing/SectionHeader.js +20 -0
- package/esm/billing/__stories__/BarChart.stories.js_bak +46 -0
- package/esm/billing/__stories__/Grid.stories.js_bak +57 -0
- package/esm/billing/__stories__/Header2.stories.js_bak +62 -0
- package/esm/billing/__stories__/Header3.stories.js_bak +69 -0
- package/esm/billing/__stories__/Paragraph.stories.js_bak +84 -0
- package/esm/billing/__stories__/ParagraphGroup.stories.js_bak +68 -0
- package/esm/billing/__stories__/ParagraphText.stories.js_bak +64 -0
- package/esm/billing/__stories__/Section.stories.js_bak +115 -0
- package/esm/billing/__stories__/SectionBody.stories.js_bak +62 -0
- package/esm/billing/__stories__/SectionHeader.stories.js-bak +68 -0
- package/esm/breadcrumb/Breadcrumb.js +71 -0
- package/esm/breadcrumb/index.js +1 -0
- package/esm/button/Button.js +145 -0
- package/esm/button/ButtonGroup.js +54 -0
- package/esm/button/IconButton.js +64 -0
- package/esm/button/ScrollToTopButton.js +47 -0
- package/esm/button/index.js +4 -0
- package/esm/callout/Callout.js +45 -0
- package/esm/callout/index.js +1 -0
- package/esm/chart/BarChart.js +147 -0
- package/esm/chart/DoughnutChart.js +110 -0
- package/esm/chart/LineChart.js +140 -0
- package/esm/chart/SingleBarChart.js +35 -0
- package/esm/chart/index.js +5 -0
- package/esm/chart/utils/centerTextPlugin.js +56 -0
- package/esm/chart/utils/customTooltip.js +84 -0
- package/esm/chart/utils/customTooltipLifecyclePlugin.js +16 -0
- package/esm/chart/utils/htmlLegendPlugin.js +83 -0
- package/esm/chart/utils/index.js +3 -0
- package/esm/chart/utils/padEmptyChartBar.js +47 -0
- package/esm/chart/utils/tooltipElement.js +17 -0
- package/esm/chart/utils/xAxisLabelTooltipPlugin.js +101 -0
- package/esm/chart/utils/yAxisTopTitlePlugin.js +43 -0
- package/esm/container/FlexContainer.js +33 -0
- package/esm/container/index.js +1 -0
- package/esm/cropper/Cropper.js +47 -0
- package/esm/cropper/CropperModalHandler.js +34 -0
- package/esm/cropper/index.js +2 -0
- package/esm/cropper/subComponent/CropImageModal.js +72 -0
- package/{datetimePicker/DatetimePicker.js → esm/datetimePicker/DatetimePickerV3.js} +63 -31
- package/esm/datetimePicker/TimeInput.js +49 -0
- package/esm/datetimePicker/TimePickerStyle.js +58 -0
- package/esm/datetimePicker/TimePickerV2.js +199 -0
- package/esm/datetimePicker/accordion/Month.js +245 -0
- package/esm/datetimePicker/accordion/Year.js +275 -0
- package/esm/datetimePicker/index.js +4 -0
- package/esm/datetimePicker/provider/constant.js +38 -0
- package/esm/datetimePicker/subComponent/DateTimePickerContext.js +3 -0
- package/esm/datetimePicker/utils/GMTDate.js +9 -0
- package/esm/datetimePicker/utils/pad.js +7 -0
- package/esm/datetimePicker/utils/toUTC0.js +7 -0
- package/esm/descriptionList/DescriptionDetail.js +21 -0
- package/esm/descriptionList/DescriptionList.js +18 -0
- package/esm/descriptionList/DescriptionTerm.js +7 -0
- package/esm/descriptionList/index.js +3 -0
- package/esm/divider/Divider.js +24 -0
- package/esm/divider/index.js +1 -0
- package/esm/dropdown/Dropdown.js +48 -0
- package/esm/dropdown/DropdownButtonOption.js +36 -0
- package/esm/dropdown/DropdownContent.js +83 -0
- package/esm/dropdown/DropdownDivOption.js +19 -0
- package/esm/dropdown/DropdownItem.js +19 -0
- package/esm/dropdown/DropdownLinkOption.js +17 -0
- package/esm/dropdown/DropdownToggle.js +31 -0
- package/esm/dropdown/index.js +11 -0
- package/esm/dropdown/subComponent/DropdownContext.js +3 -0
- package/esm/dropzone/FileDropzone.js +472 -0
- package/esm/dropzone/ImageDropzone.js +327 -0
- package/esm/dropzone/index.js +2 -0
- package/esm/dropzone/subComponent/Message.js +19 -0
- package/esm/figure/IconFigure.js +35 -0
- package/esm/figure/ImageFigure.js +31 -0
- package/esm/figure/index.js +2 -0
- package/esm/file/HiddenFileInput.js +8 -0
- package/esm/file/index.js +1 -0
- package/esm/form/Checkbox.js +157 -0
- package/esm/form/Fieldset.js +11 -0
- package/esm/form/FormItem.js +15 -0
- package/esm/form/Input.js +59 -0
- package/esm/form/Label.js +54 -0
- package/esm/form/MutedText.js +14 -0
- package/esm/form/PasswordInput.js +40 -0
- package/esm/form/RadioButton.js +94 -0
- package/esm/form/SearchSelect.js +174 -0
- package/esm/form/Searchbox.js +91 -0
- package/esm/form/Slider.js +39 -0
- package/esm/form/SwitchButton.js +97 -0
- package/esm/form/Textarea.js +34 -0
- package/esm/form/TreeView.js +66 -0
- package/esm/form/index.js +14 -0
- package/esm/grid/Column.js +39 -0
- package/esm/grid/Grid.js +28 -0
- package/esm/grid/index.js +2 -0
- package/esm/heading/Heading1.js +14 -0
- package/esm/heading/Heading2.js +21 -0
- package/esm/heading/Heading3.js +42 -0
- package/esm/heading/index.js +3 -0
- package/esm/helmet/Helmet.js +17 -0
- package/esm/helmet/index.js +3 -0
- package/esm/iconbox/ApplicationIconBox.js +74 -0
- package/esm/iconbox/IconBox.js +60 -0
- package/esm/iconbox/IconBoxV2.js +63 -0
- package/esm/iconbox/index.js +3 -0
- package/esm/iconbox/subComponent/IconBoxFigure.js +43 -0
- package/esm/iconbox/subComponent/IconBoxImage.js +35 -0
- package/esm/image/ImageFluid.js +10 -0
- package/esm/image/UploadImage.js +243 -0
- package/esm/image/index.js +2 -0
- package/esm/index.js +47 -0
- package/esm/keyframe/Pulse.js +15 -0
- package/esm/keyframe/Spin.js +7 -0
- package/esm/layout/Aside.js +39 -0
- package/esm/layout/AsideHeader.jsx +27 -0
- package/esm/layout/Backdrop.js +16 -0
- package/esm/layout/Container.js +30 -0
- package/esm/layout/Footer.js +36 -0
- package/esm/layout/Header.jsx +55 -0
- package/esm/layout/Layout.jsx +84 -0
- package/esm/layout/Logo.jsx +17 -0
- package/esm/layout/MenuIcon.jsx +27 -0
- package/esm/layout/Sidebar.jsx +271 -0
- package/esm/layout/index.js +1 -0
- package/esm/link/LinkSpan.js +62 -0
- package/esm/link/index.js +1 -0
- package/esm/map/GoogleMap.js +439 -0
- package/esm/map/GoogleReverseGeolocation.js +193 -0
- package/esm/map/LeafletMap.js +224 -0
- package/esm/map/LeafletReverseGeolocation.js +94 -0
- package/esm/map/index.js +4 -0
- package/esm/map/subComponent/BasicLeafletMap.js +27 -0
- package/esm/map/subComponent/GoogleMapContainer.js +22 -0
- package/esm/map/subComponent/GoogleMapPopup.js +103 -0
- package/esm/map/subComponent/GoogleMapWrapper.js +34 -0
- package/esm/map/subComponent/LeafletDrawControl.js +116 -0
- package/esm/map/subComponent/LeafletMapContainer.js +166 -0
- package/esm/map/subComponent/MapSearchBoxControl.js +47 -0
- package/esm/modal/StateModal.js +169 -0
- package/esm/modal/TitleModal.js +241 -0
- package/esm/modal/index.js +2 -0
- package/esm/page/Disclaimer.js +121 -0
- package/esm/page/index.js +1 -0
- package/esm/paginate/Paginate.js +129 -0
- package/esm/paginate/index.js +1 -0
- package/esm/popover/Popover.js +82 -0
- package/esm/popover/index.js +1 -0
- package/esm/qrcode/QRCode.js +51 -0
- package/esm/qrcode/QRCodeContainter.js +27 -0
- package/esm/qrcode/index.js +2 -0
- package/esm/ribbon/Ribbon.js +35 -0
- package/esm/ribbon/index.js +1 -0
- package/esm/section/Section.js +126 -0
- package/esm/section/SectionBody.js +43 -0
- package/esm/section/SectionHeader.js +61 -0
- package/esm/section/SectionToolbar.js +11 -0
- package/esm/section/SectionToolbarItem.js +10 -0
- package/esm/section/index.js +5 -0
- package/esm/select/InputSelect.js +263 -0
- package/esm/select/Select.js +811 -0
- package/esm/select/index.js +2 -0
- package/esm/select/subComponent/Checkbox.js +40 -0
- package/esm/select/subComponent/Footer.js +6 -0
- package/esm/select/subComponent/ListBox.js +23 -0
- package/esm/select/subComponent/Option.js +37 -0
- package/esm/select/subComponent/OptionGroup.js +16 -0
- package/esm/select/subComponent/Options.js +25 -0
- package/esm/select/subComponent/SearchBox.js +51 -0
- package/esm/select/subComponent/SelectedMultipleCount.js +32 -0
- package/esm/select/subComponent/SelectedMultipleTags.js +47 -0
- package/esm/select/subComponent/SelectedMultipleText.js +63 -0
- package/esm/select/subComponent/SelectedSingle.js +10 -0
- package/esm/styles/GlobalStyle.js +328 -0
- package/esm/styles/config/breakpoint.style.js +7 -0
- package/esm/styles/config/header.style.js +4 -0
- package/esm/styles/config/sidebar.style.js +11 -0
- package/esm/styles/index.js +2 -0
- package/esm/styles/mixin/backgroundColor.js +38 -0
- package/esm/styles/mixin/borderColor.js +31 -0
- package/esm/styles/mixin/color.js +31 -0
- package/esm/styles/mixin/colorOnBackground.js +31 -0
- package/esm/styles/mixin/inputPlaceholder.js +24 -0
- package/esm/styles/mixin/media.js +15 -0
- package/esm/styles/mixin/rounded.js +24 -0
- package/esm/styles/mixin/scrollbar.js +26 -0
- package/esm/styles/theme/dark.theme.js +91 -0
- package/esm/styles/theme/light.theme.js +91 -0
- package/esm/styles/theme/white.theme.js +91 -0
- package/esm/styles/themes.js +9 -0
- package/esm/table/GridTable.js +329 -0
- package/esm/table/ImageBox.js +38 -0
- package/esm/table/InfiniteGridTable.js +396 -0
- package/esm/table/PermissionTable.js +57 -0
- package/esm/table/SimpleGridTable.js +136 -0
- package/esm/table/Table.js +559 -0
- package/esm/table/__mock__/columns.js +64 -0
- package/esm/table/__mock__/data.js +530 -0
- package/esm/table/hooks/index.js +2 -0
- package/esm/table/hooks/useCalculateDataRange.js +22 -0
- package/esm/table/hooks/useGenerateSort.js +32 -0
- package/esm/table/index.js +6 -0
- package/esm/table/subComponent/BaseTableHeadCell.js +54 -0
- package/esm/table/subComponent/GridTableFooter.js +17 -0
- package/esm/table/subComponent/GridTableHeadCell.js +13 -0
- package/esm/table/subComponent/Resizer.js +70 -0
- package/esm/table/subComponent/TableFooter.js +24 -0
- package/esm/table/subComponent/TableFooterInfo.js +6 -0
- package/esm/table/subComponent/TableFooterPager.js +26 -0
- package/esm/table/subComponent/TableHeadCell.js +12 -0
- package/esm/table/subComponent/TableSort.js +31 -0
- package/esm/tagify/TagifyStyle.js +54 -0
- package/esm/tagify/Tags.js +49 -0
- package/esm/tagify/index.js +3 -0
- package/esm/tagify/templates/getCreateButtonTemplate.js +12 -0
- package/esm/text/Paragraph.js +79 -0
- package/esm/text/index.js +1 -0
- package/esm/timeline/Timeline.js +132 -0
- package/esm/timeline/index.js +1 -0
- package/esm/toast/CustomToastContainer.js +38 -0
- package/esm/toast/MessageContainer.js +44 -0
- package/esm/toast/index.js +3 -0
- package/esm/toast/show.js +29 -0
- package/esm/toast/style.css +1 -0
- package/esm/tooltip/Tooltip.js +133 -0
- package/esm/tooltip/index.js +1 -0
- package/esm/treeView/TreeViewV2.js +32 -0
- package/esm/treeView/TreeflexStyle.js +43 -0
- package/esm/treeView/index.js +2 -0
- package/esm/wizard/Wizard.js +244 -0
- package/esm/wizard/index.js +1 -0
- package/helmet/index.js +3 -7
- package/index.js +0 -12
- package/layout/Sidebar.jsx +1 -1
- package/package.json +5 -4
- package/datetimePicker/DatePicker.js +0 -363
- package/datetimePicker/DatePickerV2.js +0 -407
- package/datetimePicker/DatetimePickerV2.js +0 -395
- package/datetimePicker/TimePicker.js +0 -317
- package/datetimePicker/hooks/index.js +0 -27
- package/datetimePicker/hooks/useChangeNumber.js +0 -42
- package/datetimePicker/hooks/useDecrease.js +0 -38
- package/datetimePicker/hooks/useIncrease.js +0 -38
- package/datetimePicker/subComponent/Accordion.js +0 -373
- package/datetimePicker/subComponent/CustomTimeInput.js +0 -47
- package/jsoneditor/JsonEditor.js +0 -142
- package/jsoneditor/index.js +0 -13
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { ThemeContext } from 'styled-components';
|
|
3
|
+
import { Bar, defaults } from 'react-chartjs-2';
|
|
4
|
+
import customTooltip from './utils/customTooltip';
|
|
5
|
+
import customTooltipLifecyclePlugin from './utils/customTooltipLifecyclePlugin';
|
|
6
|
+
import padEmptyChartBar from './utils/padEmptyChartBar';
|
|
7
|
+
import yAxisTopTitlePlugin from './utils/yAxisTopTitlePlugin';
|
|
8
|
+
import xAxisLabelTooltipPlugin from './utils/xAxisLabelTooltipPlugin';
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
const BarChart = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
height = 300,
|
|
13
|
+
data,
|
|
14
|
+
options = {},
|
|
15
|
+
...props
|
|
16
|
+
} = _ref;
|
|
17
|
+
const theme = useContext(ThemeContext);
|
|
18
|
+
|
|
19
|
+
// fix: read value from theme
|
|
20
|
+
defaults.font.family = theme.fontFamily;
|
|
21
|
+
defaults.font.size = 16;
|
|
22
|
+
defaults.color = theme.fontOnBg;
|
|
23
|
+
defaults.plugins.tooltip.external = customTooltip(theme);
|
|
24
|
+
const customOptions = useMemo(() => {
|
|
25
|
+
const {
|
|
26
|
+
yAxisTopTitle,
|
|
27
|
+
tooltips = {}
|
|
28
|
+
} = options;
|
|
29
|
+
return {
|
|
30
|
+
onlyFirstTooltips: options.onlyFirstTooltips === undefined ? true : options.onlyFirstTooltips,
|
|
31
|
+
maxBarNumber: options.maxBarNumber === undefined ? 5 : options.maxBarNumber,
|
|
32
|
+
stacked: options.stacked === undefined ? true : options.stacked,
|
|
33
|
+
suggestedMax: options.suggestedMax === undefined ? 10 : options.suggestedMax,
|
|
34
|
+
showLegend: options.showLegend === undefined ? false : options.showLegend,
|
|
35
|
+
rotateLabel: options.rotateLabel === undefined ? true : options.rotateLabel,
|
|
36
|
+
yAxisTopTitle: yAxisTopTitle ? yAxisTopTitle : '',
|
|
37
|
+
tooltipLabelPostfix: tooltips.labelPostfix || '',
|
|
38
|
+
showFullLabelOnHover: options.showFullLabelOnHover === undefined ? false : options.showFullLabelOnHover
|
|
39
|
+
};
|
|
40
|
+
}, [options]);
|
|
41
|
+
const defaultOptions = useMemo(() => {
|
|
42
|
+
return {
|
|
43
|
+
responsive: true,
|
|
44
|
+
maintainAspectRatio: false,
|
|
45
|
+
aspectRatio: 1,
|
|
46
|
+
interaction: {
|
|
47
|
+
mode: 'nearest',
|
|
48
|
+
intersect: false
|
|
49
|
+
},
|
|
50
|
+
plugins: {
|
|
51
|
+
padEmptyChartBar: {
|
|
52
|
+
maxBarNumber: customOptions.maxBarNumber
|
|
53
|
+
},
|
|
54
|
+
legend: {
|
|
55
|
+
position: 'bottom',
|
|
56
|
+
display: customOptions.showLegend
|
|
57
|
+
},
|
|
58
|
+
tooltip: {
|
|
59
|
+
enabled: false,
|
|
60
|
+
intersect: false,
|
|
61
|
+
filter(context) {
|
|
62
|
+
return !customOptions.onlyFirstTooltips || context.datasetIndex === 0 && context.label !== 'null';
|
|
63
|
+
},
|
|
64
|
+
callbacks: {
|
|
65
|
+
title(context) {
|
|
66
|
+
return context[0] ? context[0].label.match(/(.{1,20})/g) : '';
|
|
67
|
+
},
|
|
68
|
+
label(context) {
|
|
69
|
+
const tooltipLabel = context.dataset.tooltipLabels?.[context.dataIndex];
|
|
70
|
+
if (tooltipLabel !== undefined) {
|
|
71
|
+
return `${context.dataset.label}: ${tooltipLabel}`;
|
|
72
|
+
}
|
|
73
|
+
const label = context.dataset.data[context.dataIndex];
|
|
74
|
+
if (context.dataset.customLabel) {
|
|
75
|
+
return context.dataset.customLabel[context.dataIndex].toString();
|
|
76
|
+
}
|
|
77
|
+
return `${context.dataset.label}: ${label.toString()}${customOptions.tooltipLabelPostfix}`;
|
|
78
|
+
},
|
|
79
|
+
labelTextColor(context) {
|
|
80
|
+
const {
|
|
81
|
+
color
|
|
82
|
+
} = context.dataset;
|
|
83
|
+
if (!color) {
|
|
84
|
+
return theme.fontOnPrimary;
|
|
85
|
+
}
|
|
86
|
+
if (color && Array.isArray(color)) {
|
|
87
|
+
return color[context.dataIndex % color.length];
|
|
88
|
+
}
|
|
89
|
+
return color;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
yAxisTopTitle: {
|
|
94
|
+
title: customOptions.yAxisTopTitle
|
|
95
|
+
},
|
|
96
|
+
xAxisLabelTooltip: {
|
|
97
|
+
enabled: customOptions.showFullLabelOnHover
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
scales: {
|
|
101
|
+
x: {
|
|
102
|
+
stacked: customOptions.stacked,
|
|
103
|
+
grid: {
|
|
104
|
+
display: false,
|
|
105
|
+
drawBorder: false
|
|
106
|
+
},
|
|
107
|
+
ticks: {
|
|
108
|
+
minRotation: customOptions.rotateLabel ? 15 : 0,
|
|
109
|
+
callback(value) {
|
|
110
|
+
const label = this.getLabelForValue(value);
|
|
111
|
+
return label && label.length > 11 ? `${label.substr(0, 11)}...` : label;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
y: {
|
|
116
|
+
beginAtZero: true,
|
|
117
|
+
suggestedMax: customOptions.suggestedMax,
|
|
118
|
+
grid: {
|
|
119
|
+
display: false,
|
|
120
|
+
drawBorder: false
|
|
121
|
+
},
|
|
122
|
+
ticks: {
|
|
123
|
+
callback(value) {
|
|
124
|
+
if (value % 1 === 0) {
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
layout: {
|
|
133
|
+
padding: {
|
|
134
|
+
top: 32
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}, [customOptions, theme.fontOnPrimary]);
|
|
139
|
+
return /*#__PURE__*/_jsx(Bar, {
|
|
140
|
+
height: height,
|
|
141
|
+
data: data,
|
|
142
|
+
options: defaultOptions,
|
|
143
|
+
plugins: [padEmptyChartBar, yAxisTopTitlePlugin, xAxisLabelTooltipPlugin, customTooltipLifecyclePlugin],
|
|
144
|
+
...props
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
export default BarChart;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { useContext, useMemo, useState } from 'react';
|
|
2
|
+
import styled, { ThemeContext } from 'styled-components';
|
|
3
|
+
import { Doughnut, defaults } from 'react-chartjs-2';
|
|
4
|
+
import uniqueId from 'lodash.uniqueid';
|
|
5
|
+
import htmlLegendPlugin from './utils/htmlLegendPlugin';
|
|
6
|
+
import customTooltip from './utils/customTooltip';
|
|
7
|
+
import customTooltipLifecyclePlugin from './utils/customTooltipLifecyclePlugin';
|
|
8
|
+
import centerTextPlugin from './utils/centerTextPlugin';
|
|
9
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
const DoughnutChart = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
height = 300,
|
|
13
|
+
data,
|
|
14
|
+
showCenterText = false,
|
|
15
|
+
centerTextTitle,
|
|
16
|
+
...props
|
|
17
|
+
} = _ref;
|
|
18
|
+
const [legendContainerId] = useState(uniqueId('legend-container-'));
|
|
19
|
+
const theme = useContext(ThemeContext);
|
|
20
|
+
|
|
21
|
+
// fix: read value from theme
|
|
22
|
+
defaults.font.family = theme.fontFamily;
|
|
23
|
+
defaults.font.size = 16;
|
|
24
|
+
defaults.color = theme.fontOnBg;
|
|
25
|
+
defaults.plugins.tooltip.external = customTooltip(theme);
|
|
26
|
+
const defaultOptions = useMemo(() => {
|
|
27
|
+
return {
|
|
28
|
+
responsive: true,
|
|
29
|
+
maintainAspectRatio: false,
|
|
30
|
+
aspectRatio: 1,
|
|
31
|
+
plugins: {
|
|
32
|
+
htmlLegend: {
|
|
33
|
+
containerID: legendContainerId
|
|
34
|
+
},
|
|
35
|
+
legend: {
|
|
36
|
+
display: false
|
|
37
|
+
},
|
|
38
|
+
tooltip: {
|
|
39
|
+
enabled: false,
|
|
40
|
+
callbacks: {
|
|
41
|
+
title(context) {
|
|
42
|
+
return context[0] ? context[0].label.match(/(.{1,20})/g) : '';
|
|
43
|
+
},
|
|
44
|
+
label(context) {
|
|
45
|
+
const label = context.dataset.data[context.dataIndex];
|
|
46
|
+
if (context.dataset.customLabel) {
|
|
47
|
+
return context.dataset.customLabel[context.dataIndex].toString();
|
|
48
|
+
}
|
|
49
|
+
return label.toString();
|
|
50
|
+
},
|
|
51
|
+
labelTextColor(context) {
|
|
52
|
+
const {
|
|
53
|
+
color
|
|
54
|
+
} = context.dataset;
|
|
55
|
+
if (!color) {
|
|
56
|
+
return theme.fontOnPrimary;
|
|
57
|
+
}
|
|
58
|
+
if (color && Array.isArray(color)) {
|
|
59
|
+
return color[context.dataIndex % color.length];
|
|
60
|
+
}
|
|
61
|
+
return color;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
centerText: {
|
|
66
|
+
display: showCenterText,
|
|
67
|
+
title: centerTextTitle
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}, [legendContainerId, theme.fontOnPrimary, showCenterText, centerTextTitle]);
|
|
72
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
73
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
74
|
+
children: /*#__PURE__*/_jsx(Doughnut, {
|
|
75
|
+
height: height,
|
|
76
|
+
data: data,
|
|
77
|
+
options: defaultOptions,
|
|
78
|
+
plugins: [htmlLegendPlugin, centerTextPlugin, customTooltipLifecyclePlugin],
|
|
79
|
+
...props
|
|
80
|
+
})
|
|
81
|
+
}), /*#__PURE__*/_jsx(LegendWrapper, {
|
|
82
|
+
id: legendContainerId
|
|
83
|
+
})]
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const LegendWrapper = styled.div`
|
|
87
|
+
.custom-legend-tooltip {
|
|
88
|
+
position: relative;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.custom-legend-tooltip:hover::after {
|
|
92
|
+
content: attr(data-tooltip);
|
|
93
|
+
position: absolute;
|
|
94
|
+
top: calc(1rem + var(--spacing-xs));
|
|
95
|
+
left: 50%;
|
|
96
|
+
transform: translateX(-50%);
|
|
97
|
+
border: 1px solid var(--border-color);
|
|
98
|
+
color: var(--font-on-background);
|
|
99
|
+
background: var(--color-background2);
|
|
100
|
+
box-shadow: var(--box-shadow);
|
|
101
|
+
border-radius: calc(var(--border-radius) / 2);
|
|
102
|
+
padding: var(--spacing-xs);
|
|
103
|
+
font-size: var(--font-body1);
|
|
104
|
+
font-weight: var(--font-normal);
|
|
105
|
+
text-align: center;
|
|
106
|
+
width: max-content;
|
|
107
|
+
max-width: 50vw;
|
|
108
|
+
}
|
|
109
|
+
`;
|
|
110
|
+
export default DoughnutChart;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { ThemeContext } from 'styled-components';
|
|
3
|
+
import { Line, defaults } from 'react-chartjs-2';
|
|
4
|
+
import customTooltip from './utils/customTooltip';
|
|
5
|
+
import customTooltipLifecyclePlugin from './utils/customTooltipLifecyclePlugin';
|
|
6
|
+
import yAxisTopTitlePlugin from './utils/yAxisTopTitlePlugin';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const LineChart = _ref => {
|
|
9
|
+
let {
|
|
10
|
+
height = 300,
|
|
11
|
+
data,
|
|
12
|
+
options = {},
|
|
13
|
+
...props
|
|
14
|
+
} = _ref;
|
|
15
|
+
const theme = useContext(ThemeContext);
|
|
16
|
+
|
|
17
|
+
// fix: read value from theme
|
|
18
|
+
defaults.font.family = theme.fontFamily;
|
|
19
|
+
defaults.font.size = 16;
|
|
20
|
+
defaults.color = theme.fontOnBg;
|
|
21
|
+
defaults.plugins.tooltip.external = customTooltip(theme);
|
|
22
|
+
const customOptions = useMemo(() => {
|
|
23
|
+
const {
|
|
24
|
+
yAxisTopTitle
|
|
25
|
+
} = options;
|
|
26
|
+
return {
|
|
27
|
+
suggestedMax: options.suggestedMax ? options.suggestedMax : 10,
|
|
28
|
+
tooltipTitlePrefix: '',
|
|
29
|
+
tooltipLabelPrefix: '',
|
|
30
|
+
tooltipLabelPostfix: '',
|
|
31
|
+
showLegend: options.showLegend === undefined ? false : options.showLegend,
|
|
32
|
+
yAxisTopTitle: yAxisTopTitle ? yAxisTopTitle : ''
|
|
33
|
+
};
|
|
34
|
+
}, [options]);
|
|
35
|
+
if (options.tooltips) {
|
|
36
|
+
const tooltipsOptions = options.tooltips;
|
|
37
|
+
customOptions.tooltipTitlePrefix = tooltipsOptions.titlePrefix || '';
|
|
38
|
+
customOptions.tooltipLabelPrefix = tooltipsOptions.labelPrefix || '';
|
|
39
|
+
customOptions.tooltipLabelPostfix = tooltipsOptions.labelPostfix || '';
|
|
40
|
+
}
|
|
41
|
+
const defaultOptions = useMemo(() => {
|
|
42
|
+
return {
|
|
43
|
+
responsive: true,
|
|
44
|
+
maintainAspectRatio: false,
|
|
45
|
+
aspectRatio: 1,
|
|
46
|
+
interaction: {
|
|
47
|
+
mode: 'nearest',
|
|
48
|
+
intersect: false
|
|
49
|
+
},
|
|
50
|
+
plugins: {
|
|
51
|
+
legend: {
|
|
52
|
+
display: customOptions.showLegend
|
|
53
|
+
},
|
|
54
|
+
tooltip: {
|
|
55
|
+
enabled: false,
|
|
56
|
+
intersect: false,
|
|
57
|
+
filter(context) {
|
|
58
|
+
return context.label !== 'null';
|
|
59
|
+
},
|
|
60
|
+
callbacks: {
|
|
61
|
+
title(context) {
|
|
62
|
+
const content = context[0] ? context[0].label.match(/(.{1,20})/g) : '';
|
|
63
|
+
return `${customOptions.tooltipTitlePrefix}${content}`;
|
|
64
|
+
},
|
|
65
|
+
label(context) {
|
|
66
|
+
const datasetLabel = context.dataset.label || '';
|
|
67
|
+
const tooltipLabel = context.dataset.tooltipLabels?.[context.dataIndex];
|
|
68
|
+
if (tooltipLabel !== undefined) {
|
|
69
|
+
return datasetLabel ? `${datasetLabel}: ${tooltipLabel}` : `${tooltipLabel}`;
|
|
70
|
+
}
|
|
71
|
+
const content = context.dataset.data[context.dataIndex].toString();
|
|
72
|
+
return datasetLabel ? `${datasetLabel}: ${customOptions.tooltipLabelPrefix}${content}${customOptions.tooltipLabelPostfix}` : `${customOptions.tooltipLabelPrefix}${content}${customOptions.tooltipLabelPostfix}`;
|
|
73
|
+
},
|
|
74
|
+
labelColor(context) {
|
|
75
|
+
const {
|
|
76
|
+
borderColor
|
|
77
|
+
} = context.dataset;
|
|
78
|
+
return {
|
|
79
|
+
borderColor,
|
|
80
|
+
backgroundColor: borderColor
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
labelTextColor(context) {
|
|
84
|
+
const {
|
|
85
|
+
color
|
|
86
|
+
} = context.dataset;
|
|
87
|
+
if (!color) {
|
|
88
|
+
return theme.fontOnPrimary;
|
|
89
|
+
}
|
|
90
|
+
if (color && Array.isArray(color)) {
|
|
91
|
+
return color[context.dataIndex % color.length];
|
|
92
|
+
}
|
|
93
|
+
return color;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
yAxisTopTitle: {
|
|
98
|
+
title: customOptions.yAxisTopTitle
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
scales: {
|
|
102
|
+
x: {
|
|
103
|
+
grid: {
|
|
104
|
+
display: false,
|
|
105
|
+
drawBorder: false
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
y: {
|
|
109
|
+
beginAtZero: true,
|
|
110
|
+
suggestedMax: customOptions.suggestedMax,
|
|
111
|
+
grid: {
|
|
112
|
+
display: false,
|
|
113
|
+
drawBorder: false
|
|
114
|
+
},
|
|
115
|
+
ticks: {
|
|
116
|
+
callback(value) {
|
|
117
|
+
if (value % 1 === 0) {
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
layout: {
|
|
126
|
+
padding: {
|
|
127
|
+
top: 32
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}, [customOptions, theme.fontOnPrimary]);
|
|
132
|
+
return /*#__PURE__*/_jsx(Line, {
|
|
133
|
+
height: height,
|
|
134
|
+
data: data,
|
|
135
|
+
options: defaultOptions,
|
|
136
|
+
plugins: [yAxisTopTitlePlugin, customTooltipLifecyclePlugin],
|
|
137
|
+
...props
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
export default LineChart;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import backgroundColor from '../styles/mixin/backgroundColor';
|
|
3
|
+
const SingleBarChart = styled.div.attrs(() => ({
|
|
4
|
+
primary: true
|
|
5
|
+
}))`
|
|
6
|
+
position: relative;
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 1rem;
|
|
9
|
+
border-radius: var(--border-radius);
|
|
10
|
+
background: var(--color-background3);
|
|
11
|
+
|
|
12
|
+
&::before {
|
|
13
|
+
position: absolute;
|
|
14
|
+
content: '';
|
|
15
|
+
width: ${_ref => {
|
|
16
|
+
let {
|
|
17
|
+
percentage
|
|
18
|
+
} = _ref;
|
|
19
|
+
return percentage;
|
|
20
|
+
}}%;
|
|
21
|
+
border-radius: var(--border-radius);
|
|
22
|
+
top: 0;
|
|
23
|
+
bottom: 0;
|
|
24
|
+
|
|
25
|
+
${backgroundColor}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
${_ref2 => {
|
|
29
|
+
let {
|
|
30
|
+
marginTop
|
|
31
|
+
} = _ref2;
|
|
32
|
+
return marginTop && 'margin-top: var(--spacing-s)';
|
|
33
|
+
}}
|
|
34
|
+
`;
|
|
35
|
+
export default SingleBarChart;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { defaults } from 'react-chartjs-2';
|
|
2
|
+
const centerTextPlugin = {
|
|
3
|
+
id: 'centerText',
|
|
4
|
+
beforeDraw: chart => {
|
|
5
|
+
const {
|
|
6
|
+
options,
|
|
7
|
+
data
|
|
8
|
+
} = chart.config;
|
|
9
|
+
const config = options.plugins.centerText;
|
|
10
|
+
if (!config || !config.display) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const {
|
|
14
|
+
ctx,
|
|
15
|
+
chartArea: {
|
|
16
|
+
top,
|
|
17
|
+
width,
|
|
18
|
+
height
|
|
19
|
+
}
|
|
20
|
+
} = chart;
|
|
21
|
+
ctx.save();
|
|
22
|
+
|
|
23
|
+
// calculate center position
|
|
24
|
+
const centerX = width / 2;
|
|
25
|
+
const centerY = height / 2 + top;
|
|
26
|
+
|
|
27
|
+
// font settings
|
|
28
|
+
const {
|
|
29
|
+
font,
|
|
30
|
+
color
|
|
31
|
+
} = defaults;
|
|
32
|
+
const {
|
|
33
|
+
family,
|
|
34
|
+
size,
|
|
35
|
+
lineHeight
|
|
36
|
+
} = font;
|
|
37
|
+
const offset = size * lineHeight / 2;
|
|
38
|
+
ctx.textAlign = 'center';
|
|
39
|
+
ctx.textBaseline = 'middle';
|
|
40
|
+
ctx.fillStyle = color;
|
|
41
|
+
const {
|
|
42
|
+
title
|
|
43
|
+
} = config;
|
|
44
|
+
if (title) {
|
|
45
|
+
ctx.font = `bold ${size}px ${family}`;
|
|
46
|
+
ctx.fillText(title, centerX, centerY - offset);
|
|
47
|
+
}
|
|
48
|
+
const total = data.datasets[0].data.reduce((total, current) => {
|
|
49
|
+
return total + current;
|
|
50
|
+
}, 0);
|
|
51
|
+
ctx.font = `${size}px ${family}`;
|
|
52
|
+
ctx.fillText(total.toLocaleString(), centerX, centerY + (title ? offset : 0));
|
|
53
|
+
ctx.restore();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
export default centerTextPlugin;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { CUSTOM_TOOLTIP_ID, getOrCreateTooltipEl } from './tooltipElement';
|
|
2
|
+
const customTooltip = theme => {
|
|
3
|
+
// optimize: render in react way
|
|
4
|
+
return function (context) {
|
|
5
|
+
// Tooltip Element
|
|
6
|
+
const tooltipEl = getOrCreateTooltipEl(CUSTOM_TOOLTIP_ID);
|
|
7
|
+
if (!tooltipEl.querySelector('table')) {
|
|
8
|
+
tooltipEl.innerHTML = '<table></table>';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Hide tooltip, if no tooltip or no data
|
|
12
|
+
const tooltipModel = context.tooltip;
|
|
13
|
+
if (!tooltipModel || !tooltipModel.dataPoints || !tooltipModel.dataPoints[0] || tooltipModel.opacity === 0) {
|
|
14
|
+
tooltipEl.style.display = 'none';
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Set caret Position
|
|
19
|
+
tooltipEl.classList.remove('above', 'below', 'no-transform');
|
|
20
|
+
if (tooltipModel.yAlign) {
|
|
21
|
+
tooltipEl.classList.add(tooltipModel.yAlign);
|
|
22
|
+
} else {
|
|
23
|
+
tooltipEl.classList.add('no-transform');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Set Text
|
|
27
|
+
if (tooltipModel.body) {
|
|
28
|
+
const titleLines = tooltipModel.title || [];
|
|
29
|
+
const bodyLines = tooltipModel.body.map(bodyItem => {
|
|
30
|
+
return bodyItem.lines || [];
|
|
31
|
+
});
|
|
32
|
+
let innerHtml = '<thead>';
|
|
33
|
+
titleLines.forEach(title => {
|
|
34
|
+
innerHtml += `<tr><th>${title}</th></tr>`;
|
|
35
|
+
});
|
|
36
|
+
innerHtml += '</thead><tbody>';
|
|
37
|
+
bodyLines.forEach(body => {
|
|
38
|
+
if (Array.isArray(body)) {
|
|
39
|
+
body.forEach(line => {
|
|
40
|
+
innerHtml += `<tr><td>${line}</td></tr>`;
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
innerHtml += `<tr><td>${body}</td></tr>`;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
innerHtml += '</tbody>';
|
|
47
|
+
const tableRoot = tooltipEl.querySelector('table');
|
|
48
|
+
tableRoot.innerHTML = innerHtml;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// `this` will be the overall tooltip
|
|
52
|
+
const position = context.chart.canvas.getBoundingClientRect();
|
|
53
|
+
|
|
54
|
+
// Display, position, and set styles for font
|
|
55
|
+
tooltipEl.style.fontFamily = theme.fontFamily;
|
|
56
|
+
tooltipEl.style.fontSize = theme.fontBody1;
|
|
57
|
+
tooltipEl.style.display = 'block';
|
|
58
|
+
tooltipEl.style.position = 'absolute';
|
|
59
|
+
tooltipEl.style.boxShadow = theme.boxShadow;
|
|
60
|
+
[tooltipEl.style.color] = tooltipModel.labelTextColors;
|
|
61
|
+
tooltipEl.style.background = tooltipModel.labelColors[0].backgroundColor;
|
|
62
|
+
tooltipEl.style.borderRadius = theme.borderRadius;
|
|
63
|
+
tooltipEl.style.textAlign = 'center';
|
|
64
|
+
tooltipEl.style.padding = `${theme.spacerXS} ${theme.spacerS}`;
|
|
65
|
+
tooltipEl.style.pointerEvents = 'none';
|
|
66
|
+
|
|
67
|
+
// determine position is left or right
|
|
68
|
+
if (tooltipModel.caretX + tooltipEl.offsetWidth <= this._chart.width) {
|
|
69
|
+
tooltipEl.style.borderTopLeftRadius = 0;
|
|
70
|
+
tooltipEl.style.left = `${position.left + window.pageXOffset + tooltipModel.caretX + 8}px`;
|
|
71
|
+
} else {
|
|
72
|
+
tooltipEl.style.borderTopRightRadius = 0;
|
|
73
|
+
tooltipEl.style.left = `${position.left + window.pageXOffset + tooltipModel.caretX - tooltipModel.width - 16 * 2}px`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// determine position is top or bottom
|
|
77
|
+
if (tooltipModel.caretY + tooltipEl.offsetHeight <= this._chart.height) {
|
|
78
|
+
tooltipEl.style.top = `${position.top + window.pageYOffset + tooltipModel.caretY + 8}px`;
|
|
79
|
+
} else {
|
|
80
|
+
tooltipEl.style.top = `${position.top + window.pageYOffset + tooltipModel.caretY - tooltipModel.width - 16 * 2}px`;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export default customTooltip;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CUSTOM_TOOLTIP_ID, hideTooltipEl } from './tooltipElement';
|
|
2
|
+
|
|
3
|
+
// customTooltip.js renders #chartjs-tooltip outside React's tree (appended to
|
|
4
|
+
// document.body), so it needs an explicit hook to hide it when the chart's
|
|
5
|
+
// container resizes or the chart instance is destroyed - otherwise the last
|
|
6
|
+
// rendered tooltip is left floating, detached from the (moved/gone) chart.
|
|
7
|
+
const customTooltipLifecyclePlugin = {
|
|
8
|
+
id: 'customTooltipLifecycle',
|
|
9
|
+
resize() {
|
|
10
|
+
hideTooltipEl(CUSTOM_TOOLTIP_ID);
|
|
11
|
+
},
|
|
12
|
+
afterDestroy() {
|
|
13
|
+
hideTooltipEl(CUSTOM_TOOLTIP_ID);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export default customTooltipLifecyclePlugin;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { defaults } from 'react-chartjs-2';
|
|
2
|
+
const htmlLegendPlugin = {
|
|
3
|
+
id: 'htmlLegend',
|
|
4
|
+
afterUpdate(chart, args, options) {
|
|
5
|
+
const ul = getOrCreateLegendList(chart, options.containerID);
|
|
6
|
+
|
|
7
|
+
// Remove old legend items
|
|
8
|
+
while (ul.firstChild) {
|
|
9
|
+
ul.firstChild.remove();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Reuse the built-in legendItems generator
|
|
13
|
+
const items = chart.options.plugins.legend.labels.generateLabels(chart);
|
|
14
|
+
items.forEach(item => {
|
|
15
|
+
const li = document.createElement('li');
|
|
16
|
+
li.style.alignItems = 'center';
|
|
17
|
+
li.style.cursor = 'pointer';
|
|
18
|
+
li.style.display = 'flex';
|
|
19
|
+
li.style.flexDirection = 'row';
|
|
20
|
+
li.style.marginLeft = '16px';
|
|
21
|
+
li.style.marginTop = '16px';
|
|
22
|
+
li.style.color = defaults.color;
|
|
23
|
+
const [dataset] = chart.data.datasets;
|
|
24
|
+
const description = dataset.descriptions ? dataset.descriptions[item.index] : '';
|
|
25
|
+
if (description) {
|
|
26
|
+
li.setAttribute('data-tooltip', description);
|
|
27
|
+
li.classList.add('custom-legend-tooltip');
|
|
28
|
+
}
|
|
29
|
+
li.onclick = () => {
|
|
30
|
+
const {
|
|
31
|
+
type
|
|
32
|
+
} = chart.config;
|
|
33
|
+
if (type === 'pie' || type === 'doughnut') {
|
|
34
|
+
// Pie and doughnut charts only have a single dataset and visibility is per item
|
|
35
|
+
chart.toggleDataVisibility(item.index);
|
|
36
|
+
} else {
|
|
37
|
+
chart.setDatasetVisibility(item.datasetIndex, !chart.isDatasetVisible(item.datasetIndex));
|
|
38
|
+
}
|
|
39
|
+
chart.update();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Color box
|
|
43
|
+
const boxSpan = document.createElement('span');
|
|
44
|
+
boxSpan.style.background = item.fillStyle;
|
|
45
|
+
boxSpan.style.borderColor = item.strokeStyle;
|
|
46
|
+
boxSpan.style.borderWidth = `${item.lineWidth}px`;
|
|
47
|
+
boxSpan.style.borderStyle = 'solid';
|
|
48
|
+
boxSpan.style.display = 'inline-block';
|
|
49
|
+
boxSpan.style.height = '16px';
|
|
50
|
+
boxSpan.style.marginRight = '8px';
|
|
51
|
+
boxSpan.style.width = '32px';
|
|
52
|
+
|
|
53
|
+
// Text
|
|
54
|
+
const textContainer = document.createElement('p');
|
|
55
|
+
textContainer.style.color = item.fontColor;
|
|
56
|
+
textContainer.style.margin = 0;
|
|
57
|
+
textContainer.style.padding = 0;
|
|
58
|
+
textContainer.style.wordBreak = 'break-all';
|
|
59
|
+
textContainer.style.textDecoration = item.hidden ? 'line-through' : '';
|
|
60
|
+
const text = document.createTextNode(item.text);
|
|
61
|
+
textContainer.appendChild(text);
|
|
62
|
+
li.appendChild(boxSpan);
|
|
63
|
+
li.appendChild(textContainer);
|
|
64
|
+
ul.appendChild(li);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const getOrCreateLegendList = (chart, id) => {
|
|
69
|
+
const legendContainer = document.getElementById(id);
|
|
70
|
+
let listContainer = legendContainer.querySelector('ul');
|
|
71
|
+
if (!listContainer) {
|
|
72
|
+
listContainer = document.createElement('ul');
|
|
73
|
+
listContainer.style.display = 'flex';
|
|
74
|
+
listContainer.style.flexDirection = 'row';
|
|
75
|
+
listContainer.style.flexWrap = 'wrap';
|
|
76
|
+
listContainer.style.justifyContent = 'center';
|
|
77
|
+
listContainer.style.margin = 0;
|
|
78
|
+
listContainer.style.padding = 0;
|
|
79
|
+
legendContainer.appendChild(listContainer);
|
|
80
|
+
}
|
|
81
|
+
return listContainer;
|
|
82
|
+
};
|
|
83
|
+
export default htmlLegendPlugin;
|