@j2inn/fin5-ui-utils 3.0.7-beta.0 → 4.0.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/README.md +5 -5
- package/dist/fantomProps/createFin5Props/index.d.ts +12 -12
- package/dist/fantomProps/createFin5Props/index.js +146 -146
- package/dist/fantomProps/createFin5Props/runCreateFin5Props.d.ts +2 -2
- package/dist/fantomProps/createFin5Props/runCreateFin5Props.js +16 -16
- package/dist/fantomProps/fantomPropsToObject.d.ts +8 -8
- package/dist/fantomProps/fantomPropsToObject.js +183 -183
- package/dist/fantomProps/generateJsonFromFantomPropsFile.d.ts +4 -4
- package/dist/fantomProps/generateJsonFromFantomPropsFile.js +41 -41
- package/dist/fantomProps/localePropsToJson.d.ts +1 -1
- package/dist/fantomProps/localePropsToJson.js +50 -50
- package/dist/fantomProps/readFantomPropsFile.d.ts +5 -5
- package/dist/fantomProps/readFantomPropsFile.js +61 -61
- package/dist/fin5Top/fin5FileUpload.d.ts +24 -24
- package/dist/fin5Top/fin5FileUpload.js +51 -51
- package/dist/fin5Top/fin5Top.d.ts +115 -115
- package/dist/fin5Top/fin5Top.js +58 -58
- package/dist/fin5Top/finEdge2Cloud.d.ts +6 -6
- package/dist/fin5Top/finEdge2Cloud.js +15 -15
- package/dist/fin5Top/getFin5BinUrl.d.ts +2 -2
- package/dist/fin5Top/getFin5BinUrl.js +9 -9
- package/dist/fin5Top/openFin5Alarm.d.ts +22 -22
- package/dist/fin5Top/openFin5Alarm.js +23 -23
- package/dist/fin5Top/openFin5Historian.d.ts +3 -3
- package/dist/fin5Top/openFin5Historian.js +19 -19
- package/dist/fin5Top/useFin5AppURLHashParameter.d.ts +18 -18
- package/dist/fin5Top/useFin5AppURLHashParameter.js +128 -128
- package/dist/index.d.ts +30 -30
- package/dist/index.js +64 -64
- package/dist/jobs/jobUtils.d.ts +14 -14
- package/dist/jobs/jobUtils.js +15 -15
- package/dist/react/app/Fin5AppContainer.d.ts +36 -36
- package/dist/react/app/Fin5AppContainer.js +102 -102
- package/dist/react/app/Fin5AppRootStore.d.ts +39 -39
- package/dist/react/app/Fin5AppRootStore.js +69 -69
- package/dist/react/components/ErrorBoundary.d.ts +57 -57
- package/dist/react/components/ErrorBoundary.js +150 -150
- package/dist/react/components/ErrorDisplayer.d.ts +19 -19
- package/dist/react/components/ErrorDisplayer.js +36 -36
- package/dist/react/components/Loader.d.ts +9 -9
- package/dist/react/components/Loader.js +17 -17
- package/dist/react/components/LoadingSpinner.d.ts +2 -2
- package/dist/react/components/LoadingSpinner.js +27 -27
- package/dist/react/components/RecordImage.d.ts +20 -20
- package/dist/react/components/RecordImage.js +51 -51
- package/dist/react/components/charts/QRCode.d.ts +25 -25
- package/dist/react/components/charts/QRCode.js +81 -81
- package/dist/react/components/charts/pie/PieChart.d.ts +93 -93
- package/dist/react/components/charts/pie/PieChart.js +202 -202
- package/dist/react/components/charts/pie/SimplePieChart.d.ts +20 -20
- package/dist/react/components/charts/pie/SimplePieChart.js +55 -55
- package/dist/react/components/graphics/GraphicViewer.d.ts +10 -10
- package/dist/react/components/graphics/GraphicViewer.js +29 -29
- package/dist/react/components/graphics/GraphicsTabViewer.d.ts +17 -17
- package/dist/react/components/graphics/GraphicsTabViewer.js +90 -90
- package/dist/react/components/navigation/BasicLayout.d.ts +41 -41
- package/dist/react/components/navigation/BasicLayout.js +155 -155
- package/dist/react/components/navigation/HeaderSiderLayout.d.ts +13 -13
- package/dist/react/components/navigation/HeaderSiderLayout.js +110 -110
- package/dist/react/components/navigation/MenuPage.d.ts +37 -37
- package/dist/react/components/navigation/MenuPage.js +36 -36
- package/dist/react/components/navigation/MenuTrigger.d.ts +9 -9
- package/dist/react/components/navigation/MenuTrigger.js +33 -33
- package/dist/react/components/navigation/ReactRouterHeaderSiderLayout.d.ts +11 -11
- package/dist/react/components/navigation/ReactRouterHeaderSiderLayout.js +25 -25
- package/dist/react/components/navigation/ReactRouterLayout.d.ts +35 -35
- package/dist/react/components/navigation/ReactRouterLayout.js +113 -117
- package/dist/react/components/navigation/ReactRouterLayout.js.map +1 -1
- package/dist/react/components/navigation/customRouting/Router.d.ts +12 -12
- package/dist/react/components/navigation/customRouting/Router.js +45 -45
- package/dist/react/components/navigation/customRouting/RouterLayout.d.ts +11 -11
- package/dist/react/components/navigation/customRouting/RouterLayout.js +61 -61
- package/dist/react/components/resolvable/configurationForm/ConfigurationForm.d.ts +27 -27
- package/dist/react/components/resolvable/configurationForm/ConfigurationForm.js +95 -95
- package/dist/react/components/resolvable/configurationForm/ConfigurationFormEntry.d.ts +16 -16
- package/dist/react/components/resolvable/configurationForm/ConfigurationFormEntry.js +88 -88
- package/dist/react/components/resolvable/configurationForm/getSectionDefault.d.ts +16 -16
- package/dist/react/components/resolvable/configurationForm/getSectionDefault.js +99 -99
- package/dist/react/hooks/useFin5BinUrl.d.ts +6 -6
- package/dist/react/hooks/useFin5BinUrl.js +15 -15
- package/dist_es/fantomProps/createFin5Props/index.d.ts +12 -12
- package/dist_es/fantomProps/createFin5Props/index.js +140 -140
- package/dist_es/fantomProps/createFin5Props/index.js.map +0 -0
- package/dist_es/fantomProps/createFin5Props/runCreateFin5Props.d.ts +2 -2
- package/dist_es/fantomProps/createFin5Props/runCreateFin5Props.js +11 -11
- package/dist_es/fantomProps/createFin5Props/runCreateFin5Props.js.map +0 -0
- package/dist_es/fantomProps/fantomPropsToObject.d.ts +8 -8
- package/dist_es/fantomProps/fantomPropsToObject.js +178 -178
- package/dist_es/fantomProps/fantomPropsToObject.js.map +0 -0
- package/dist_es/fantomProps/generateJsonFromFantomPropsFile.d.ts +4 -4
- package/dist_es/fantomProps/generateJsonFromFantomPropsFile.js +12 -12
- package/dist_es/fantomProps/generateJsonFromFantomPropsFile.js.map +0 -0
- package/dist_es/fantomProps/localePropsToJson.d.ts +1 -1
- package/dist_es/fantomProps/localePropsToJson.js +21 -21
- package/dist_es/fantomProps/localePropsToJson.js.map +0 -0
- package/dist_es/fantomProps/readFantomPropsFile.d.ts +5 -5
- package/dist_es/fantomProps/readFantomPropsFile.js +35 -35
- package/dist_es/fantomProps/readFantomPropsFile.js.map +0 -0
- package/dist_es/fin5Top/fin5FileUpload.d.ts +24 -24
- package/dist_es/fin5Top/fin5FileUpload.js +47 -47
- package/dist_es/fin5Top/fin5Top.d.ts +115 -115
- package/dist_es/fin5Top/fin5Top.js +54 -54
- package/dist_es/fin5Top/fin5Top.js.map +0 -0
- package/dist_es/fin5Top/finEdge2Cloud.d.ts +6 -6
- package/dist_es/fin5Top/finEdge2Cloud.js +11 -11
- package/dist_es/fin5Top/getFin5BinUrl.d.ts +2 -2
- package/dist_es/fin5Top/getFin5BinUrl.js +5 -5
- package/dist_es/fin5Top/getFin5BinUrl.js.map +0 -0
- package/dist_es/fin5Top/openFin5Alarm.d.ts +22 -22
- package/dist_es/fin5Top/openFin5Alarm.js +19 -19
- package/dist_es/fin5Top/openFin5Alarm.js.map +0 -0
- package/dist_es/fin5Top/openFin5Historian.d.ts +3 -3
- package/dist_es/fin5Top/openFin5Historian.js +15 -15
- package/dist_es/fin5Top/openFin5Historian.js.map +0 -0
- package/dist_es/fin5Top/useFin5AppURLHashParameter.d.ts +18 -18
- package/dist_es/fin5Top/useFin5AppURLHashParameter.js +119 -119
- package/dist_es/fin5Top/useFin5AppURLHashParameter.js.map +0 -0
- package/dist_es/index.d.ts +30 -30
- package/dist_es/index.js +48 -48
- package/dist_es/index.js.map +0 -0
- package/dist_es/jobs/jobUtils.d.ts +14 -14
- package/dist_es/jobs/jobUtils.js +9 -9
- package/dist_es/react/app/Fin5AppContainer.d.ts +36 -36
- package/dist_es/react/app/Fin5AppContainer.js +73 -73
- package/dist_es/react/app/Fin5AppContainer.jsx +0 -0
- package/dist_es/react/app/Fin5AppContainer.jsx.map +0 -0
- package/dist_es/react/app/Fin5AppRootStore.d.ts +39 -39
- package/dist_es/react/app/Fin5AppRootStore.js +65 -65
- package/dist_es/react/app/Fin5AppRootStore.js.map +0 -0
- package/dist_es/react/components/ErrorBoundary.d.ts +57 -57
- package/dist_es/react/components/ErrorBoundary.js +123 -123
- package/dist_es/react/components/ErrorBoundary.jsx +0 -0
- package/dist_es/react/components/ErrorBoundary.jsx.map +0 -0
- package/dist_es/react/components/ErrorDisplayer.d.ts +19 -19
- package/dist_es/react/components/ErrorDisplayer.js +28 -28
- package/dist_es/react/components/ErrorDisplayer.jsx +0 -0
- package/dist_es/react/components/ErrorDisplayer.jsx.map +0 -0
- package/dist_es/react/components/Loader.d.ts +9 -9
- package/dist_es/react/components/Loader.js +12 -12
- package/dist_es/react/components/Loader.jsx +1 -1
- package/dist_es/react/components/Loader.jsx.map +1 -1
- package/dist_es/react/components/LoadingSpinner.d.ts +2 -2
- package/dist_es/react/components/LoadingSpinner.js +20 -20
- package/dist_es/react/components/LoadingSpinner.jsx +4 -3
- package/dist_es/react/components/LoadingSpinner.jsx.map +1 -1
- package/dist_es/react/components/RecordImage.d.ts +20 -20
- package/dist_es/react/components/RecordImage.js +24 -24
- package/dist_es/react/components/charts/QRCode.d.ts +25 -25
- package/dist_es/react/components/charts/QRCode.js +53 -53
- package/dist_es/react/components/charts/pie/PieChart.d.ts +93 -93
- package/dist_es/react/components/charts/pie/PieChart.js +175 -175
- package/dist_es/react/components/charts/pie/SimplePieChart.d.ts +20 -20
- package/dist_es/react/components/charts/pie/SimplePieChart.js +25 -25
- package/dist_es/react/components/graphics/GraphicViewer.d.ts +10 -10
- package/dist_es/react/components/graphics/GraphicViewer.js +22 -22
- package/dist_es/react/components/graphics/GraphicsTabViewer.d.ts +17 -17
- package/dist_es/react/components/graphics/GraphicsTabViewer.js +60 -60
- package/dist_es/react/components/navigation/BasicLayout.d.ts +41 -41
- package/dist_es/react/components/navigation/BasicLayout.js +124 -124
- package/dist_es/react/components/navigation/BasicLayout.jsx +7 -35
- package/dist_es/react/components/navigation/BasicLayout.jsx.map +1 -1
- package/dist_es/react/components/navigation/HeaderSiderLayout.d.ts +13 -13
- package/dist_es/react/components/navigation/HeaderSiderLayout.js +80 -80
- package/dist_es/react/components/navigation/MenuPage.d.ts +37 -37
- package/dist_es/react/components/navigation/MenuPage.js +30 -30
- package/dist_es/react/components/navigation/MenuPage.jsx +0 -0
- package/dist_es/react/components/navigation/MenuPage.jsx.map +1 -1
- package/dist_es/react/components/navigation/MenuTrigger.d.ts +9 -9
- package/dist_es/react/components/navigation/MenuTrigger.js +28 -28
- package/dist_es/react/components/navigation/ReactRouterHeaderSiderLayout.d.ts +11 -11
- package/dist_es/react/components/navigation/ReactRouterHeaderSiderLayout.js +18 -18
- package/dist_es/react/components/navigation/ReactRouterLayout.d.ts +35 -35
- package/dist_es/react/components/navigation/ReactRouterLayout.js +81 -85
- package/dist_es/react/components/navigation/ReactRouterLayout.js.map +1 -1
- package/dist_es/react/components/navigation/Router.d.ts +0 -0
- package/dist_es/react/components/navigation/Router.jsx +1 -1
- package/dist_es/react/components/navigation/Router.jsx.map +1 -1
- package/dist_es/react/components/navigation/customRouting/Router.d.ts +12 -12
- package/dist_es/react/components/navigation/customRouting/Router.js +18 -18
- package/dist_es/react/components/navigation/customRouting/RouterLayout.d.ts +11 -11
- package/dist_es/react/components/navigation/customRouting/RouterLayout.js +34 -34
- package/dist_es/react/components/resolvable/configurationForm/ConfigurationForm.d.ts +27 -27
- package/dist_es/react/components/resolvable/configurationForm/ConfigurationForm.js +64 -64
- package/dist_es/react/components/resolvable/configurationForm/ConfigurationFormEntry.d.ts +16 -16
- package/dist_es/react/components/resolvable/configurationForm/ConfigurationFormEntry.js +58 -58
- package/dist_es/react/components/resolvable/configurationForm/getSectionDefault.d.ts +16 -16
- package/dist_es/react/components/resolvable/configurationForm/getSectionDefault.js +94 -94
- package/dist_es/react/hooks/useFin5BinUrl.d.ts +6 -6
- package/dist_es/react/hooks/useFin5BinUrl.js +11 -11
- package/package.json +13 -13
- package/dist_es/react/components/graphics/GraphicViewer.jsx +0 -23
- package/dist_es/react/components/graphics/GraphicViewer.jsx.map +0 -1
- package/dist_es/react/components/graphics/GraphicsTabViewer.jsx +0 -63
- package/dist_es/react/components/graphics/GraphicsTabViewer.jsx.map +0 -1
- package/dist_es/react/components/navigation/Router.js +0 -19
- package/dist_es/react/components/navigation/Router.js.map +0 -1
- package/dist_es/react/components/navigation/react-router/BasicLayout.d.ts +0 -23
- package/dist_es/react/components/navigation/react-router/BasicLayout.js +0 -82
- package/dist_es/react/components/navigation/react-router/BasicLayout.js.map +0 -1
- package/dist_es/react/components/navigation/react-router/ReactRouterBasicLayout.d.ts +0 -24
- package/dist_es/react/components/navigation/react-router/ReactRouterBasicLayout.js +0 -82
- package/dist_es/react/components/navigation/react-router/ReactRouterBasicLayout.js.map +0 -1
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import { Typography, ant_prefix } from '@j2inn/ui';
|
|
2
|
-
import cn from 'classnames';
|
|
3
|
-
import QRious from 'qrious';
|
|
4
|
-
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState, } from 'react';
|
|
5
|
-
import { createUseStyles } from 'react-jss';
|
|
6
|
-
const useStyles = createUseStyles({
|
|
7
|
-
qrCode: {
|
|
8
|
-
display: 'flex',
|
|
9
|
-
flexDirection: 'column',
|
|
10
|
-
[`& .${ant_prefix}-typography`]: {
|
|
11
|
-
textAlign: 'center',
|
|
12
|
-
paddingBottom: '0.5em',
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
const QRCode = ({ value, size = 350, copyable = true, copyText = 'Copy QR code to clipboard', className, }) => {
|
|
17
|
-
const classes = useStyles();
|
|
18
|
-
const canvasRef = useRef(null);
|
|
19
|
-
const [qrCode, setQrCode] = useState();
|
|
20
|
-
useLayoutEffect(() => {
|
|
21
|
-
if (canvasRef.current) {
|
|
22
|
-
setQrCode(new QRious({
|
|
23
|
-
element: canvasRef.current,
|
|
24
|
-
value,
|
|
25
|
-
size,
|
|
26
|
-
}));
|
|
27
|
-
}
|
|
28
|
-
}, [value, canvasRef.current]);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
if (qrCode && qrCode.size !== size) {
|
|
31
|
-
qrCode.size = size;
|
|
32
|
-
}
|
|
33
|
-
}, [size]);
|
|
34
|
-
const copyQrCodeToClipboard = useCallback(async () => {
|
|
35
|
-
if (canvasRef.current) {
|
|
36
|
-
await canvasRef.current.toBlob((blob) => {
|
|
37
|
-
if (blob) {
|
|
38
|
-
navigator.clipboard.write([
|
|
39
|
-
new ClipboardItem({
|
|
40
|
-
'image/png': blob,
|
|
41
|
-
}),
|
|
42
|
-
]);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}, [canvasRef.current]);
|
|
47
|
-
return (React.createElement("div", { className: cn(className, classes.qrCode) },
|
|
48
|
-
copyable && (React.createElement(Typography.Text, { copyable: {
|
|
49
|
-
onCopy: () => copyQrCodeToClipboard(),
|
|
50
|
-
} }, copyText)),
|
|
51
|
-
React.createElement("canvas", { ref: canvasRef })));
|
|
52
|
-
};
|
|
53
|
-
export default QRCode;
|
|
1
|
+
import { Typography, ant_prefix } from '@j2inn/ui';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import QRious from 'qrious';
|
|
4
|
+
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState, } from 'react';
|
|
5
|
+
import { createUseStyles } from 'react-jss';
|
|
6
|
+
const useStyles = createUseStyles({
|
|
7
|
+
qrCode: {
|
|
8
|
+
display: 'flex',
|
|
9
|
+
flexDirection: 'column',
|
|
10
|
+
[`& .${ant_prefix}-typography`]: {
|
|
11
|
+
textAlign: 'center',
|
|
12
|
+
paddingBottom: '0.5em',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
const QRCode = ({ value, size = 350, copyable = true, copyText = 'Copy QR code to clipboard', className, }) => {
|
|
17
|
+
const classes = useStyles();
|
|
18
|
+
const canvasRef = useRef(null);
|
|
19
|
+
const [qrCode, setQrCode] = useState();
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
if (canvasRef.current) {
|
|
22
|
+
setQrCode(new QRious({
|
|
23
|
+
element: canvasRef.current,
|
|
24
|
+
value,
|
|
25
|
+
size,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
}, [value, canvasRef.current]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (qrCode && qrCode.size !== size) {
|
|
31
|
+
qrCode.size = size;
|
|
32
|
+
}
|
|
33
|
+
}, [size]);
|
|
34
|
+
const copyQrCodeToClipboard = useCallback(async () => {
|
|
35
|
+
if (canvasRef.current) {
|
|
36
|
+
await canvasRef.current.toBlob((blob) => {
|
|
37
|
+
if (blob) {
|
|
38
|
+
navigator.clipboard.write([
|
|
39
|
+
new ClipboardItem({
|
|
40
|
+
'image/png': blob,
|
|
41
|
+
}),
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}, [canvasRef.current]);
|
|
47
|
+
return (React.createElement("div", { className: cn(className, classes.qrCode) },
|
|
48
|
+
copyable && (React.createElement(Typography.Text, { copyable: {
|
|
49
|
+
onCopy: () => copyQrCodeToClipboard(),
|
|
50
|
+
} }, copyText)),
|
|
51
|
+
React.createElement("canvas", { ref: canvasRef })));
|
|
52
|
+
};
|
|
53
|
+
export default QRCode;
|
|
54
54
|
//# sourceMappingURL=QRCode.js.map
|
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
import * as am5 from '@amcharts/amcharts5';
|
|
2
|
-
import * as am5percent from '@amcharts/amcharts5/percent';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
export declare type PieChartInterfaceColors = {
|
|
5
|
-
[Property in keyof am5.IInterfaceColorsSettings]: string;
|
|
6
|
-
};
|
|
7
|
-
export interface PieChartColorPalette {
|
|
8
|
-
interfaceColors?: Partial<PieChartInterfaceColors>;
|
|
9
|
-
series?: string[];
|
|
10
|
-
}
|
|
11
|
-
export interface PieChartSliceData {
|
|
12
|
-
value: number;
|
|
13
|
-
category: string;
|
|
14
|
-
}
|
|
15
|
-
export interface PieChartProps {
|
|
16
|
-
/**
|
|
17
|
-
* Data used to populate the chart
|
|
18
|
-
*/
|
|
19
|
-
data: PieChartSliceData[];
|
|
20
|
-
/**
|
|
21
|
-
* Color palette for the chart slices and interface colors @see https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/#Interface_colors
|
|
22
|
-
*/
|
|
23
|
-
colorPalette?: Partial<PieChartColorPalette>;
|
|
24
|
-
/**
|
|
25
|
-
* Number formatting options @see https://www.amcharts.com/docs/v5/tutorials/formatting-date-time-and-numbers-using-intl-object/#Formatting_numbers
|
|
26
|
-
*/
|
|
27
|
-
numberFormat?: Intl.NumberFormatOptions;
|
|
28
|
-
/**
|
|
29
|
-
* amcharts5 theme classes to be used by the chart @see https://www.amcharts.com/docs/v5/concepts/themes/
|
|
30
|
-
*/
|
|
31
|
-
chartThemes?: typeof am5.Theme[];
|
|
32
|
-
/**
|
|
33
|
-
* Settings for chart customization @see https://www.amcharts.com/docs/v5/reference/piechart/#Settings
|
|
34
|
-
* The function accepts the chart root as a parameter to allow layout configuration.
|
|
35
|
-
*/
|
|
36
|
-
chartSettingsProvider?: (root: am5.Root) => am5percent.IPieChartSettings;
|
|
37
|
-
/**
|
|
38
|
-
* Function to get settings for legend customization @see https://www.amcharts.com/docs/v5/reference/legend/#Settings
|
|
39
|
-
* The function accepts the chart root as a parameter to allow layout configuration.
|
|
40
|
-
*/
|
|
41
|
-
legendSettingsProvider?: (root: am5.Root) => am5.ILegendSettings;
|
|
42
|
-
/**
|
|
43
|
-
* Settings for legend labels customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
|
|
44
|
-
*/
|
|
45
|
-
legendLabelsSettings?: Partial<am5.ILabelSettings>;
|
|
46
|
-
/**
|
|
47
|
-
* Settings for legend value labels customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
|
|
48
|
-
*/
|
|
49
|
-
legendValueLabelsSettings?: Partial<am5.ILabelSettings>;
|
|
50
|
-
/**
|
|
51
|
-
* Settings for legend markers customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
|
|
52
|
-
*/
|
|
53
|
-
legendMarkersSettings?: Partial<am5.ILabelSettings>;
|
|
54
|
-
/**
|
|
55
|
-
* Settings for chart series customization @see https://www.amcharts.com/docs/v5/reference/pieseries/#Settings
|
|
56
|
-
*/
|
|
57
|
-
seriesSettings?: am5percent.IPieSeriesSettings;
|
|
58
|
-
/**
|
|
59
|
-
* Settings for series labels customization @see https://www.amcharts.com/docs/v5/reference/pieseries/#Settings
|
|
60
|
-
*/
|
|
61
|
-
seriesLabelsSettings?: Partial<am5.IRadialLabelSettings>;
|
|
62
|
-
/**
|
|
63
|
-
* Settings for central label customization, useful for donut charts, if not specified no center label will be shown @see https://www.amcharts.com/docs/v5/reference/radiallabel/#Settings
|
|
64
|
-
*/
|
|
65
|
-
centerLabelSettings?: am5.ILabelSettings;
|
|
66
|
-
/**
|
|
67
|
-
* Settings for pie slices customization @see https://www.amcharts.com/docs/v5/reference/slice/#Settings
|
|
68
|
-
*/
|
|
69
|
-
slicesSettings?: Partial<am5.ISliceSettings>;
|
|
70
|
-
/**
|
|
71
|
-
* List of adapters to be applied to the slices @see https://www.amcharts.com/docs/v5/concepts/settings/adapters
|
|
72
|
-
*/
|
|
73
|
-
sliceAdapters?: SliceAdapter[];
|
|
74
|
-
/**
|
|
75
|
-
* Optional DOM id for the chart container, if not specified it will be automatically generated
|
|
76
|
-
*/
|
|
77
|
-
DOMtargetId?: string;
|
|
78
|
-
}
|
|
79
|
-
export declare type SliceAdapter<T extends keyof am5.ISliceSettings = keyof am5.ISliceSettings> = [
|
|
80
|
-
T,
|
|
81
|
-
(context: {
|
|
82
|
-
root: am5.Root;
|
|
83
|
-
chart: am5percent.PieChart;
|
|
84
|
-
series: am5percent.PieSeries;
|
|
85
|
-
}) => (value: am5.ISliceSettings[T], target: am5.Slice, key: T) => am5.ISliceSettings[T]
|
|
86
|
-
];
|
|
87
|
-
/**
|
|
88
|
-
* Highly customizable pie chart component based on amcharts5
|
|
89
|
-
* @see https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/
|
|
90
|
-
*
|
|
91
|
-
* This component wraps some of the chart configuration trying to make it more react-friendly
|
|
92
|
-
*/
|
|
93
|
-
export declare const PieChart: React.FC<PieChartProps>;
|
|
1
|
+
import * as am5 from '@amcharts/amcharts5';
|
|
2
|
+
import * as am5percent from '@amcharts/amcharts5/percent';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export declare type PieChartInterfaceColors = {
|
|
5
|
+
[Property in keyof am5.IInterfaceColorsSettings]: string;
|
|
6
|
+
};
|
|
7
|
+
export interface PieChartColorPalette {
|
|
8
|
+
interfaceColors?: Partial<PieChartInterfaceColors>;
|
|
9
|
+
series?: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface PieChartSliceData {
|
|
12
|
+
value: number;
|
|
13
|
+
category: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PieChartProps {
|
|
16
|
+
/**
|
|
17
|
+
* Data used to populate the chart
|
|
18
|
+
*/
|
|
19
|
+
data: PieChartSliceData[];
|
|
20
|
+
/**
|
|
21
|
+
* Color palette for the chart slices and interface colors @see https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/#Interface_colors
|
|
22
|
+
*/
|
|
23
|
+
colorPalette?: Partial<PieChartColorPalette>;
|
|
24
|
+
/**
|
|
25
|
+
* Number formatting options @see https://www.amcharts.com/docs/v5/tutorials/formatting-date-time-and-numbers-using-intl-object/#Formatting_numbers
|
|
26
|
+
*/
|
|
27
|
+
numberFormat?: Intl.NumberFormatOptions;
|
|
28
|
+
/**
|
|
29
|
+
* amcharts5 theme classes to be used by the chart @see https://www.amcharts.com/docs/v5/concepts/themes/
|
|
30
|
+
*/
|
|
31
|
+
chartThemes?: typeof am5.Theme[];
|
|
32
|
+
/**
|
|
33
|
+
* Settings for chart customization @see https://www.amcharts.com/docs/v5/reference/piechart/#Settings
|
|
34
|
+
* The function accepts the chart root as a parameter to allow layout configuration.
|
|
35
|
+
*/
|
|
36
|
+
chartSettingsProvider?: (root: am5.Root) => am5percent.IPieChartSettings;
|
|
37
|
+
/**
|
|
38
|
+
* Function to get settings for legend customization @see https://www.amcharts.com/docs/v5/reference/legend/#Settings
|
|
39
|
+
* The function accepts the chart root as a parameter to allow layout configuration.
|
|
40
|
+
*/
|
|
41
|
+
legendSettingsProvider?: (root: am5.Root) => am5.ILegendSettings;
|
|
42
|
+
/**
|
|
43
|
+
* Settings for legend labels customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
|
|
44
|
+
*/
|
|
45
|
+
legendLabelsSettings?: Partial<am5.ILabelSettings>;
|
|
46
|
+
/**
|
|
47
|
+
* Settings for legend value labels customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
|
|
48
|
+
*/
|
|
49
|
+
legendValueLabelsSettings?: Partial<am5.ILabelSettings>;
|
|
50
|
+
/**
|
|
51
|
+
* Settings for legend markers customization @see https://www.amcharts.com/docs/v5/reference/label/#Settings
|
|
52
|
+
*/
|
|
53
|
+
legendMarkersSettings?: Partial<am5.ILabelSettings>;
|
|
54
|
+
/**
|
|
55
|
+
* Settings for chart series customization @see https://www.amcharts.com/docs/v5/reference/pieseries/#Settings
|
|
56
|
+
*/
|
|
57
|
+
seriesSettings?: am5percent.IPieSeriesSettings;
|
|
58
|
+
/**
|
|
59
|
+
* Settings for series labels customization @see https://www.amcharts.com/docs/v5/reference/pieseries/#Settings
|
|
60
|
+
*/
|
|
61
|
+
seriesLabelsSettings?: Partial<am5.IRadialLabelSettings>;
|
|
62
|
+
/**
|
|
63
|
+
* Settings for central label customization, useful for donut charts, if not specified no center label will be shown @see https://www.amcharts.com/docs/v5/reference/radiallabel/#Settings
|
|
64
|
+
*/
|
|
65
|
+
centerLabelSettings?: am5.ILabelSettings;
|
|
66
|
+
/**
|
|
67
|
+
* Settings for pie slices customization @see https://www.amcharts.com/docs/v5/reference/slice/#Settings
|
|
68
|
+
*/
|
|
69
|
+
slicesSettings?: Partial<am5.ISliceSettings>;
|
|
70
|
+
/**
|
|
71
|
+
* List of adapters to be applied to the slices @see https://www.amcharts.com/docs/v5/concepts/settings/adapters
|
|
72
|
+
*/
|
|
73
|
+
sliceAdapters?: SliceAdapter[];
|
|
74
|
+
/**
|
|
75
|
+
* Optional DOM id for the chart container, if not specified it will be automatically generated
|
|
76
|
+
*/
|
|
77
|
+
DOMtargetId?: string;
|
|
78
|
+
}
|
|
79
|
+
export declare type SliceAdapter<T extends keyof am5.ISliceSettings = keyof am5.ISliceSettings> = [
|
|
80
|
+
T,
|
|
81
|
+
(context: {
|
|
82
|
+
root: am5.Root;
|
|
83
|
+
chart: am5percent.PieChart;
|
|
84
|
+
series: am5percent.PieSeries;
|
|
85
|
+
}) => (value: am5.ISliceSettings[T], target: am5.Slice, key: T) => am5.ISliceSettings[T]
|
|
86
|
+
];
|
|
87
|
+
/**
|
|
88
|
+
* Highly customizable pie chart component based on amcharts5
|
|
89
|
+
* @see https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/
|
|
90
|
+
*
|
|
91
|
+
* This component wraps some of the chart configuration trying to make it more react-friendly
|
|
92
|
+
*/
|
|
93
|
+
export declare const PieChart: React.FC<PieChartProps>;
|
|
@@ -1,176 +1,176 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023, J2 Innovations. All Rights Reserved
|
|
3
|
-
*/
|
|
4
|
-
import * as am5 from '@amcharts/amcharts5';
|
|
5
|
-
import * as am5percent from '@amcharts/amcharts5/percent';
|
|
6
|
-
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
7
|
-
import { createUseStyles, useTheme } from 'react-jss';
|
|
8
|
-
const useStyles = createUseStyles({
|
|
9
|
-
root: {
|
|
10
|
-
width: '100%',
|
|
11
|
-
height: '100%',
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
/**
|
|
15
|
-
* Returns a color palette selecting some colors from the theme.
|
|
16
|
-
* @param theme The theme
|
|
17
|
-
* @returns An array of colors
|
|
18
|
-
*/
|
|
19
|
-
const getDefaultChartColors = (theme) => {
|
|
20
|
-
return {
|
|
21
|
-
interfaceColors: {
|
|
22
|
-
text: theme.textColor,
|
|
23
|
-
},
|
|
24
|
-
series: [
|
|
25
|
-
theme.palette.lime,
|
|
26
|
-
theme.palette.cyan,
|
|
27
|
-
theme.palette.red,
|
|
28
|
-
theme.palette.volcano,
|
|
29
|
-
theme.palette.orange,
|
|
30
|
-
theme.palette.gold,
|
|
31
|
-
theme.palette.yellow,
|
|
32
|
-
theme.palette.green,
|
|
33
|
-
theme.palette.purple,
|
|
34
|
-
theme.palette.magenta,
|
|
35
|
-
theme.palette.blue,
|
|
36
|
-
theme.palette.grey,
|
|
37
|
-
],
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Highly customizable pie chart component based on amcharts5
|
|
42
|
-
* @see https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/
|
|
43
|
-
*
|
|
44
|
-
* This component wraps some of the chart configuration trying to make it more react-friendly
|
|
45
|
-
*/
|
|
46
|
-
export const PieChart = ({ DOMtargetId, data, colorPalette, numberFormat, chartThemes, chartSettingsProvider, legendSettingsProvider, legendLabelsSettings, legendValueLabelsSettings, legendMarkersSettings, seriesSettings, seriesLabelsSettings, centerLabelSettings, slicesSettings, sliceAdapters, }) => {
|
|
47
|
-
// Colors configuration
|
|
48
|
-
const theme = useTheme();
|
|
49
|
-
const colors = { ...getDefaultChartColors(theme), ...colorPalette };
|
|
50
|
-
// Chart lifecycle
|
|
51
|
-
const [id, setId] = useState(DOMtargetId ?? `amchart-${Math.random()}`);
|
|
52
|
-
const rootRef = useRef(null);
|
|
53
|
-
const chartRef = useRef(null);
|
|
54
|
-
const legendRef = useRef(null);
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (DOMtargetId && DOMtargetId !== id) {
|
|
57
|
-
setId(DOMtargetId);
|
|
58
|
-
}
|
|
59
|
-
}, [DOMtargetId]);
|
|
60
|
-
// Chart setup
|
|
61
|
-
useLayoutEffect(() => {
|
|
62
|
-
const root = am5.Root.new(id);
|
|
63
|
-
// Setup amcharts theme
|
|
64
|
-
if (chartThemes) {
|
|
65
|
-
root.setThemes(chartThemes.map((t) => t.new(root)));
|
|
66
|
-
}
|
|
67
|
-
// Setup interface colors, see https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/#Interface_colors
|
|
68
|
-
if (colors.interfaceColors) {
|
|
69
|
-
// Remap settings to use amcharts Color objects
|
|
70
|
-
for (const setting in colors.interfaceColors) {
|
|
71
|
-
const color = colors.interfaceColors[setting];
|
|
72
|
-
// Apply defined interfaceColor on the chart
|
|
73
|
-
root.interfaceColors.set(setting, am5.color(color));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// Setup chart settings
|
|
77
|
-
const chart = root.container.children.push(am5percent.PieChart.new(root, {
|
|
78
|
-
layout: root.verticalLayout,
|
|
79
|
-
...chartSettingsProvider?.(root),
|
|
80
|
-
}));
|
|
81
|
-
// Setup legend
|
|
82
|
-
const legend = chart.children.push(am5.Legend.new(root, {
|
|
83
|
-
layout: root.horizontalLayout,
|
|
84
|
-
...legendSettingsProvider?.(root),
|
|
85
|
-
}));
|
|
86
|
-
if (legendLabelsSettings) {
|
|
87
|
-
legend.labels.template.setAll(legendLabelsSettings);
|
|
88
|
-
}
|
|
89
|
-
if (legendValueLabelsSettings) {
|
|
90
|
-
legend.valueLabels.template.setAll(legendValueLabelsSettings);
|
|
91
|
-
}
|
|
92
|
-
if (legendMarkersSettings) {
|
|
93
|
-
legend.markers.template.setAll(legendMarkersSettings);
|
|
94
|
-
}
|
|
95
|
-
rootRef.current = root;
|
|
96
|
-
chartRef.current = chart;
|
|
97
|
-
legendRef.current = legend;
|
|
98
|
-
// clean up before component removal from the DOM
|
|
99
|
-
return () => {
|
|
100
|
-
legendRef.current?.dispose();
|
|
101
|
-
legendRef.current = null;
|
|
102
|
-
chartRef.current?.dispose();
|
|
103
|
-
chartRef.current = null;
|
|
104
|
-
root?.dispose();
|
|
105
|
-
rootRef.current = null;
|
|
106
|
-
};
|
|
107
|
-
}, [
|
|
108
|
-
id,
|
|
109
|
-
colors,
|
|
110
|
-
chartThemes,
|
|
111
|
-
chartSettingsProvider,
|
|
112
|
-
legendSettingsProvider,
|
|
113
|
-
legendValueLabelsSettings,
|
|
114
|
-
legendMarkersSettings,
|
|
115
|
-
]);
|
|
116
|
-
// Set data
|
|
117
|
-
useEffect(() => {
|
|
118
|
-
const root = rootRef.current;
|
|
119
|
-
const chart = chartRef.current;
|
|
120
|
-
if (chart && root) {
|
|
121
|
-
chart.series.clear();
|
|
122
|
-
if (data?.length) {
|
|
123
|
-
// Setup series
|
|
124
|
-
const series = chart.series.push(am5percent.PieSeries.new(root, {
|
|
125
|
-
valueField: 'value',
|
|
126
|
-
categoryField: 'category',
|
|
127
|
-
...seriesSettings,
|
|
128
|
-
}));
|
|
129
|
-
// Setup series labels
|
|
130
|
-
if (seriesLabelsSettings) {
|
|
131
|
-
series.labels.template.setAll(seriesLabelsSettings);
|
|
132
|
-
}
|
|
133
|
-
// Setup center label
|
|
134
|
-
if (centerLabelSettings) {
|
|
135
|
-
series.children.push(am5.Label.new(root, {
|
|
136
|
-
...centerLabelSettings,
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
// Setup series slices
|
|
140
|
-
if (slicesSettings) {
|
|
141
|
-
series.slices.template.setAll(slicesSettings);
|
|
142
|
-
}
|
|
143
|
-
// Setup slice adapters
|
|
144
|
-
if (sliceAdapters) {
|
|
145
|
-
sliceAdapters.forEach(([key, callbackMaker]) => series.slices.template.adapters.add(key, callbackMaker({
|
|
146
|
-
root: root,
|
|
147
|
-
chart: chart,
|
|
148
|
-
series,
|
|
149
|
-
})));
|
|
150
|
-
}
|
|
151
|
-
// Setup series colors
|
|
152
|
-
if (colors?.series) {
|
|
153
|
-
series.get('colors')?.set('colors', colors.series.map((c) => am5.color(c)));
|
|
154
|
-
}
|
|
155
|
-
series.data.setAll(data);
|
|
156
|
-
legendRef.current?.data.setAll(series.dataItems);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}, [
|
|
160
|
-
data,
|
|
161
|
-
chartRef.current,
|
|
162
|
-
colors?.series,
|
|
163
|
-
seriesSettings,
|
|
164
|
-
slicesSettings,
|
|
165
|
-
seriesLabelsSettings,
|
|
166
|
-
sliceAdapters,
|
|
167
|
-
]);
|
|
168
|
-
useEffect(() => {
|
|
169
|
-
if (numberFormat) {
|
|
170
|
-
rootRef.current?.numberFormatter.set('numberFormat', numberFormat);
|
|
171
|
-
}
|
|
172
|
-
}, [rootRef.current, numberFormat]);
|
|
173
|
-
const classes = useStyles();
|
|
174
|
-
return React.createElement("div", { id: id, className: classes.root });
|
|
175
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023, J2 Innovations. All Rights Reserved
|
|
3
|
+
*/
|
|
4
|
+
import * as am5 from '@amcharts/amcharts5';
|
|
5
|
+
import * as am5percent from '@amcharts/amcharts5/percent';
|
|
6
|
+
import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
7
|
+
import { createUseStyles, useTheme } from 'react-jss';
|
|
8
|
+
const useStyles = createUseStyles({
|
|
9
|
+
root: {
|
|
10
|
+
width: '100%',
|
|
11
|
+
height: '100%',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Returns a color palette selecting some colors from the theme.
|
|
16
|
+
* @param theme The theme
|
|
17
|
+
* @returns An array of colors
|
|
18
|
+
*/
|
|
19
|
+
const getDefaultChartColors = (theme) => {
|
|
20
|
+
return {
|
|
21
|
+
interfaceColors: {
|
|
22
|
+
text: theme.textColor,
|
|
23
|
+
},
|
|
24
|
+
series: [
|
|
25
|
+
theme.palette.lime,
|
|
26
|
+
theme.palette.cyan,
|
|
27
|
+
theme.palette.red,
|
|
28
|
+
theme.palette.volcano,
|
|
29
|
+
theme.palette.orange,
|
|
30
|
+
theme.palette.gold,
|
|
31
|
+
theme.palette.yellow,
|
|
32
|
+
theme.palette.green,
|
|
33
|
+
theme.palette.purple,
|
|
34
|
+
theme.palette.magenta,
|
|
35
|
+
theme.palette.blue,
|
|
36
|
+
theme.palette.grey,
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Highly customizable pie chart component based on amcharts5
|
|
42
|
+
* @see https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/
|
|
43
|
+
*
|
|
44
|
+
* This component wraps some of the chart configuration trying to make it more react-friendly
|
|
45
|
+
*/
|
|
46
|
+
export const PieChart = ({ DOMtargetId, data, colorPalette, numberFormat, chartThemes, chartSettingsProvider, legendSettingsProvider, legendLabelsSettings, legendValueLabelsSettings, legendMarkersSettings, seriesSettings, seriesLabelsSettings, centerLabelSettings, slicesSettings, sliceAdapters, }) => {
|
|
47
|
+
// Colors configuration
|
|
48
|
+
const theme = useTheme();
|
|
49
|
+
const colors = { ...getDefaultChartColors(theme), ...colorPalette };
|
|
50
|
+
// Chart lifecycle
|
|
51
|
+
const [id, setId] = useState(DOMtargetId ?? `amchart-${Math.random()}`);
|
|
52
|
+
const rootRef = useRef(null);
|
|
53
|
+
const chartRef = useRef(null);
|
|
54
|
+
const legendRef = useRef(null);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (DOMtargetId && DOMtargetId !== id) {
|
|
57
|
+
setId(DOMtargetId);
|
|
58
|
+
}
|
|
59
|
+
}, [DOMtargetId]);
|
|
60
|
+
// Chart setup
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
const root = am5.Root.new(id);
|
|
63
|
+
// Setup amcharts theme
|
|
64
|
+
if (chartThemes) {
|
|
65
|
+
root.setThemes(chartThemes.map((t) => t.new(root)));
|
|
66
|
+
}
|
|
67
|
+
// Setup interface colors, see https://www.amcharts.com/docs/v5/concepts/colors-gradients-and-patterns/#Interface_colors
|
|
68
|
+
if (colors.interfaceColors) {
|
|
69
|
+
// Remap settings to use amcharts Color objects
|
|
70
|
+
for (const setting in colors.interfaceColors) {
|
|
71
|
+
const color = colors.interfaceColors[setting];
|
|
72
|
+
// Apply defined interfaceColor on the chart
|
|
73
|
+
root.interfaceColors.set(setting, am5.color(color));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Setup chart settings
|
|
77
|
+
const chart = root.container.children.push(am5percent.PieChart.new(root, {
|
|
78
|
+
layout: root.verticalLayout,
|
|
79
|
+
...chartSettingsProvider?.(root),
|
|
80
|
+
}));
|
|
81
|
+
// Setup legend
|
|
82
|
+
const legend = chart.children.push(am5.Legend.new(root, {
|
|
83
|
+
layout: root.horizontalLayout,
|
|
84
|
+
...legendSettingsProvider?.(root),
|
|
85
|
+
}));
|
|
86
|
+
if (legendLabelsSettings) {
|
|
87
|
+
legend.labels.template.setAll(legendLabelsSettings);
|
|
88
|
+
}
|
|
89
|
+
if (legendValueLabelsSettings) {
|
|
90
|
+
legend.valueLabels.template.setAll(legendValueLabelsSettings);
|
|
91
|
+
}
|
|
92
|
+
if (legendMarkersSettings) {
|
|
93
|
+
legend.markers.template.setAll(legendMarkersSettings);
|
|
94
|
+
}
|
|
95
|
+
rootRef.current = root;
|
|
96
|
+
chartRef.current = chart;
|
|
97
|
+
legendRef.current = legend;
|
|
98
|
+
// clean up before component removal from the DOM
|
|
99
|
+
return () => {
|
|
100
|
+
legendRef.current?.dispose();
|
|
101
|
+
legendRef.current = null;
|
|
102
|
+
chartRef.current?.dispose();
|
|
103
|
+
chartRef.current = null;
|
|
104
|
+
root?.dispose();
|
|
105
|
+
rootRef.current = null;
|
|
106
|
+
};
|
|
107
|
+
}, [
|
|
108
|
+
id,
|
|
109
|
+
colors,
|
|
110
|
+
chartThemes,
|
|
111
|
+
chartSettingsProvider,
|
|
112
|
+
legendSettingsProvider,
|
|
113
|
+
legendValueLabelsSettings,
|
|
114
|
+
legendMarkersSettings,
|
|
115
|
+
]);
|
|
116
|
+
// Set data
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const root = rootRef.current;
|
|
119
|
+
const chart = chartRef.current;
|
|
120
|
+
if (chart && root) {
|
|
121
|
+
chart.series.clear();
|
|
122
|
+
if (data?.length) {
|
|
123
|
+
// Setup series
|
|
124
|
+
const series = chart.series.push(am5percent.PieSeries.new(root, {
|
|
125
|
+
valueField: 'value',
|
|
126
|
+
categoryField: 'category',
|
|
127
|
+
...seriesSettings,
|
|
128
|
+
}));
|
|
129
|
+
// Setup series labels
|
|
130
|
+
if (seriesLabelsSettings) {
|
|
131
|
+
series.labels.template.setAll(seriesLabelsSettings);
|
|
132
|
+
}
|
|
133
|
+
// Setup center label
|
|
134
|
+
if (centerLabelSettings) {
|
|
135
|
+
series.children.push(am5.Label.new(root, {
|
|
136
|
+
...centerLabelSettings,
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
// Setup series slices
|
|
140
|
+
if (slicesSettings) {
|
|
141
|
+
series.slices.template.setAll(slicesSettings);
|
|
142
|
+
}
|
|
143
|
+
// Setup slice adapters
|
|
144
|
+
if (sliceAdapters) {
|
|
145
|
+
sliceAdapters.forEach(([key, callbackMaker]) => series.slices.template.adapters.add(key, callbackMaker({
|
|
146
|
+
root: root,
|
|
147
|
+
chart: chart,
|
|
148
|
+
series,
|
|
149
|
+
})));
|
|
150
|
+
}
|
|
151
|
+
// Setup series colors
|
|
152
|
+
if (colors?.series) {
|
|
153
|
+
series.get('colors')?.set('colors', colors.series.map((c) => am5.color(c)));
|
|
154
|
+
}
|
|
155
|
+
series.data.setAll(data);
|
|
156
|
+
legendRef.current?.data.setAll(series.dataItems);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}, [
|
|
160
|
+
data,
|
|
161
|
+
chartRef.current,
|
|
162
|
+
colors?.series,
|
|
163
|
+
seriesSettings,
|
|
164
|
+
slicesSettings,
|
|
165
|
+
seriesLabelsSettings,
|
|
166
|
+
sliceAdapters,
|
|
167
|
+
]);
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
if (numberFormat) {
|
|
170
|
+
rootRef.current?.numberFormatter.set('numberFormat', numberFormat);
|
|
171
|
+
}
|
|
172
|
+
}, [rootRef.current, numberFormat]);
|
|
173
|
+
const classes = useStyles();
|
|
174
|
+
return React.createElement("div", { id: id, className: classes.root });
|
|
175
|
+
};
|
|
176
176
|
//# sourceMappingURL=PieChart.js.map
|