@perses-dev/bar-chart-plugin 0.11.1 → 0.13.0-beta.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/__mf/css/async/236.85c2cbf6.css +1 -0
- package/__mf/font/inter-cyrillic-300-normal.432f2b21.woff +0 -0
- package/__mf/font/inter-cyrillic-300-normal.9da91009.woff2 +0 -0
- package/__mf/font/inter-cyrillic-400-normal.372704ff.woff2 +0 -0
- package/__mf/font/inter-cyrillic-400-normal.a6b6ef6f.woff +0 -0
- package/__mf/font/inter-cyrillic-500-normal.7c15bba8.woff2 +0 -0
- package/__mf/font/inter-cyrillic-500-normal.b9f8c929.woff +0 -0
- package/__mf/font/inter-cyrillic-600-normal.2f42892a.woff2 +0 -0
- package/__mf/font/inter-cyrillic-600-normal.c3987adc.woff +0 -0
- package/__mf/font/inter-cyrillic-700-normal.93eba3c3.woff +0 -0
- package/__mf/font/inter-cyrillic-700-normal.e9e5b2dc.woff2 +0 -0
- package/__mf/font/inter-cyrillic-900-normal.f285bd7a.woff2 +0 -0
- package/__mf/font/inter-cyrillic-900-normal.ffbd8a3a.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-300-normal.95bb9038.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-300-normal.cfc143a9.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-400-normal.2a31c04b.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-400-normal.f572b170.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-500-normal.5a6bb1da.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-500-normal.fe0d9b14.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-600-normal.ecbdecad.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-600-normal.f7b3c15b.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-700-normal.4b4022a6.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-700-normal.74b516d2.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-900-normal.9970ddb5.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-900-normal.a0d59adc.woff2 +0 -0
- package/__mf/font/inter-greek-300-normal.0d7be683.woff2 +0 -0
- package/__mf/font/inter-greek-300-normal.8f0b988e.woff +0 -0
- package/__mf/font/inter-greek-400-normal.cc58c11b.woff +0 -0
- package/__mf/font/inter-greek-400-normal.d7020e3c.woff2 +0 -0
- package/__mf/font/inter-greek-500-normal.d9a33207.woff +0 -0
- package/__mf/font/inter-greek-500-normal.f41f43db.woff2 +0 -0
- package/__mf/font/inter-greek-600-normal.4ec0c1c1.woff +0 -0
- package/__mf/font/inter-greek-600-normal.cc532937.woff2 +0 -0
- package/__mf/font/inter-greek-700-normal.5ec6c758.woff +0 -0
- package/__mf/font/inter-greek-700-normal.97f0eeeb.woff2 +0 -0
- package/__mf/font/inter-greek-900-normal.46b66369.woff2 +0 -0
- package/__mf/font/inter-greek-900-normal.9ae3a3c5.woff +0 -0
- package/__mf/font/inter-greek-ext-300-normal.10247a66.woff2 +0 -0
- package/__mf/font/inter-greek-ext-300-normal.4668e5cb.woff +0 -0
- package/__mf/font/inter-greek-ext-400-normal.4ce1df5d.woff2 +0 -0
- package/__mf/font/inter-greek-ext-400-normal.88ede1ea.woff +0 -0
- package/__mf/font/inter-greek-ext-500-normal.7a4aa726.woff +0 -0
- package/__mf/font/inter-greek-ext-500-normal.cbd51e2d.woff2 +0 -0
- package/__mf/font/inter-greek-ext-600-normal.089a95ee.woff +0 -0
- package/__mf/font/inter-greek-ext-600-normal.1f33d317.woff2 +0 -0
- package/__mf/font/inter-greek-ext-700-normal.31f1075d.woff +0 -0
- package/__mf/font/inter-greek-ext-700-normal.827cd618.woff2 +0 -0
- package/__mf/font/inter-greek-ext-900-normal.531bcee7.woff +0 -0
- package/__mf/font/inter-greek-ext-900-normal.8a9b36b9.woff2 +0 -0
- package/__mf/font/inter-latin-300-normal.15fb600d.woff2 +0 -0
- package/__mf/font/inter-latin-300-normal.6f95f590.woff +0 -0
- package/__mf/font/inter-latin-400-normal.2c7a775c.woff +0 -0
- package/__mf/font/inter-latin-400-normal.ef6d3f52.woff2 +0 -0
- package/__mf/font/inter-latin-500-normal.b7b43ace.woff2 +0 -0
- package/__mf/font/inter-latin-500-normal.cb4c8ceb.woff +0 -0
- package/__mf/font/inter-latin-600-normal.8fb1a964.woff2 +0 -0
- package/__mf/font/inter-latin-600-normal.ce0f5f43.woff +0 -0
- package/__mf/font/inter-latin-700-normal.953b7aa5.woff2 +0 -0
- package/__mf/font/inter-latin-700-normal.9c21d4dc.woff +0 -0
- package/__mf/font/inter-latin-900-normal.2a8028ec.woff2 +0 -0
- package/__mf/font/inter-latin-900-normal.fa252135.woff +0 -0
- package/__mf/font/inter-latin-ext-300-normal.167cc8c9.woff2 +0 -0
- package/__mf/font/inter-latin-ext-300-normal.f695be66.woff +0 -0
- package/__mf/font/inter-latin-ext-400-normal.32a25442.woff2 +0 -0
- package/__mf/font/inter-latin-ext-400-normal.4edcaace.woff +0 -0
- package/__mf/font/inter-latin-ext-500-normal.a19a84a6.woff +0 -0
- package/__mf/font/inter-latin-ext-500-normal.d9b491de.woff2 +0 -0
- package/__mf/font/inter-latin-ext-600-normal.38b075d8.woff2 +0 -0
- package/__mf/font/inter-latin-ext-600-normal.49faa47a.woff +0 -0
- package/__mf/font/inter-latin-ext-700-normal.93534b50.woff +0 -0
- package/__mf/font/inter-latin-ext-700-normal.b63daa1a.woff2 +0 -0
- package/__mf/font/inter-latin-ext-900-normal.0efdb307.woff +0 -0
- package/__mf/font/inter-latin-ext-900-normal.9c0fc2c7.woff2 +0 -0
- package/__mf/font/inter-vietnamese-300-normal.aad496d8.woff +0 -0
- package/__mf/font/inter-vietnamese-300-normal.ad9ef503.woff2 +0 -0
- package/__mf/font/inter-vietnamese-400-normal.a9dd2faf.woff +0 -0
- package/__mf/font/inter-vietnamese-400-normal.de4fc44f.woff2 +0 -0
- package/__mf/font/inter-vietnamese-500-normal.7c0a695f.woff2 +0 -0
- package/__mf/font/inter-vietnamese-500-normal.a3a73b95.woff +0 -0
- package/__mf/font/inter-vietnamese-600-normal.9d518599.woff2 +0 -0
- package/__mf/font/inter-vietnamese-600-normal.c5ce3fcb.woff +0 -0
- package/__mf/font/inter-vietnamese-700-normal.bc68b199.woff +0 -0
- package/__mf/font/inter-vietnamese-700-normal.faf12809.woff2 +0 -0
- package/__mf/font/inter-vietnamese-900-normal.2b782045.woff +0 -0
- package/__mf/font/inter-vietnamese-900-normal.e639b65a.woff2 +0 -0
- package/__mf/js/BarChart.684cf4ee.js +7 -0
- package/__mf/js/async/121.697325de.js +2 -0
- package/__mf/js/async/177.83b4a0c7.js +1 -0
- package/__mf/js/async/187.dce780a3.js +24 -0
- package/__mf/js/async/{634.c4642701.js.LICENSE.txt → 187.dce780a3.js.LICENSE.txt} +0 -16
- package/__mf/js/async/192.978ad416.js +1 -0
- package/__mf/js/async/235.dcb2a938.js +1 -0
- package/__mf/js/async/236.1e90c5b6.js +7 -0
- package/__mf/js/async/{901.1c784bfb.js.LICENSE.txt → 236.1e90c5b6.js.LICENSE.txt} +19 -1
- package/__mf/js/async/274.48038fad.js +2 -0
- package/__mf/js/async/356.3310d2e7.js +1 -0
- package/__mf/js/async/377.fbdc975f.js +1 -0
- package/__mf/js/async/392.2095dbb3.js +2 -0
- package/__mf/js/async/435.dc0a9a8a.js +1 -0
- package/__mf/js/async/{77.f584b802.js → 458.8fe7d3e6.js} +1 -1
- package/__mf/js/async/46.f0465d0c.js +101 -0
- package/__mf/js/async/470.306558f6.js +2 -0
- package/__mf/js/async/496.1c041ac9.js +1 -0
- package/__mf/js/async/568.0c8cf5cf.js +1 -0
- package/__mf/js/async/587.f983bd0d.js +1 -0
- package/__mf/js/async/588.c5433cac.js +1 -0
- package/__mf/js/async/616.3805dee7.js +1 -0
- package/__mf/js/async/71.63183692.js +1 -0
- package/__mf/js/async/721.497b5f27.js +1 -0
- package/__mf/js/async/77.317669de.js +1 -0
- package/__mf/js/async/823.d7e96856.js +10 -0
- package/__mf/js/async/{204.9eb9aa47.js.LICENSE.txt → 823.d7e96856.js.LICENSE.txt} +1 -1
- package/__mf/js/async/854.c97a2bb3.js +1 -0
- package/__mf/js/async/873.be346a58.js +1 -0
- package/__mf/js/async/934.ffdb04e7.js +2 -0
- package/__mf/js/async/941.4dad52d6.js +2 -0
- package/__mf/js/async/958.30e78b21.js +39 -0
- package/__mf/js/async/{705.790ed4c5.js.LICENSE.txt → 958.30e78b21.js.LICENSE.txt} +17 -1
- package/__mf/js/async/963.2293b290.js +1 -0
- package/__mf/js/async/968.fc1dd4a5.js +1 -0
- package/__mf/js/async/978.fd94d741.js +1 -0
- package/__mf/js/async/__federation_expose_BarChart.44843c4d.js +1 -0
- package/__mf/js/async/lib-router.354c6b86.js +2 -0
- package/__mf/js/main.2ce2f26b.js +7 -0
- package/lib/BarChartBase.d.ts +12 -2
- package/lib/BarChartBase.d.ts.map +1 -1
- package/lib/BarChartBase.js +104 -12
- package/lib/BarChartBase.js.map +1 -1
- package/lib/BarChartOptionsEditorSettings.d.ts.map +1 -1
- package/lib/BarChartOptionsEditorSettings.js +98 -29
- package/lib/BarChartOptionsEditorSettings.js.map +1 -1
- package/lib/BarChartPanel.d.ts +1 -1
- package/lib/BarChartPanel.d.ts.map +1 -1
- package/lib/BarChartPanel.js +71 -4
- package/lib/BarChartPanel.js.map +1 -1
- package/lib/bar-chart-model.d.ts +9 -3
- package/lib/bar-chart-model.d.ts.map +1 -1
- package/lib/bar-chart-model.js +8 -2
- package/lib/bar-chart-model.js.map +1 -1
- package/lib/cjs/BarChartBase.js +107 -15
- package/lib/cjs/BarChartOptionsEditorSettings.js +95 -26
- package/lib/cjs/BarChartPanel.js +72 -5
- package/lib/cjs/bar-chart-model.js +18 -3
- package/lib/tresholds.d.ts +1 -1
- package/lib/tresholds.d.ts.map +1 -1
- package/lib/tresholds.js.map +1 -1
- package/mf-manifest.json +76 -62
- package/mf-stats.json +92 -64
- package/package.json +4 -4
- package/__mf/css/async/442.d3010b86.css +0 -1
- package/__mf/css/async/61.d3010b86.css +0 -1
- package/__mf/css/async/823.d3010b86.css +0 -1
- package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
- package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
- package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
- package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
- package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
- package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
- package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
- package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
- package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
- package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
- package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
- package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
- package/__mf/js/BarChart.685a17f4.js +0 -6
- package/__mf/js/async/102.b7abdc1f.js +0 -1
- package/__mf/js/async/121.517e00e8.js +0 -2
- package/__mf/js/async/160.edce75b3.js +0 -1
- package/__mf/js/async/177.91621efa.js +0 -1
- package/__mf/js/async/192.73182890.js +0 -1
- package/__mf/js/async/204.9eb9aa47.js +0 -10
- package/__mf/js/async/235.b537858d.js +0 -38
- package/__mf/js/async/255.75982caf.js +0 -1
- package/__mf/js/async/274.9bfff28e.js +0 -2
- package/__mf/js/async/356.6146b01c.js +0 -1
- package/__mf/js/async/377.5b9c90dc.js +0 -1
- package/__mf/js/async/392.63dbc9c4.js +0 -2
- package/__mf/js/async/458.cffba90f.js +0 -1
- package/__mf/js/async/470.82e9b967.js +0 -2
- package/__mf/js/async/473.2df10452.js +0 -1
- package/__mf/js/async/496.b35b3a0a.js +0 -1
- package/__mf/js/async/587.bcc920f1.js +0 -1
- package/__mf/js/async/588.680cfad0.js +0 -1
- package/__mf/js/async/616.302bdae0.js +0 -1
- package/__mf/js/async/634.c4642701.js +0 -24
- package/__mf/js/async/703.16dd2eaa.js +0 -2
- package/__mf/js/async/705.790ed4c5.js +0 -102
- package/__mf/js/async/71.dab9ec76.js +0 -1
- package/__mf/js/async/854.7be16fdf.js +0 -1
- package/__mf/js/async/873.daa0c1ab.js +0 -1
- package/__mf/js/async/901.1c784bfb.js +0 -7
- package/__mf/js/async/941.4efdb193.js +0 -2
- package/__mf/js/async/963.85d5346b.js +0 -1
- package/__mf/js/async/968.d562d0d2.js +0 -1
- package/__mf/js/async/978.458b6e7d.js +0 -1
- package/__mf/js/async/__federation_expose_BarChart.8a38ae5e.js +0 -1
- package/__mf/js/async/lib-router.66821436.js +0 -2
- package/__mf/js/main.0490f6dd.js +0 -6
- /package/__mf/js/async/{121.517e00e8.js.LICENSE.txt → 121.697325de.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{274.9bfff28e.js.LICENSE.txt → 274.48038fad.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{392.63dbc9c4.js.LICENSE.txt → 392.2095dbb3.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{470.82e9b967.js.LICENSE.txt → 470.306558f6.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{703.16dd2eaa.js.LICENSE.txt → 934.ffdb04e7.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{941.4efdb193.js.LICENSE.txt → 941.4dad52d6.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{lib-router.66821436.js.LICENSE.txt → lib-router.354c6b86.js.LICENSE.txt} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
2
3
|
// Copyright The Perses Authors
|
|
3
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
5
|
// you may not use this file except in compliance with the License.
|
|
@@ -11,13 +12,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
11
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
13
|
// See the License for the specific language governing permissions and
|
|
13
14
|
// limitations under the License.
|
|
14
|
-
import { Button } from '@mui/material';
|
|
15
|
-
import { FormatControls, ModeSelector, OptionsEditorColumn, OptionsEditorGrid, OptionsEditorGroup, SortSelector } from '@perses-dev/components';
|
|
16
|
-
import {
|
|
17
|
-
import { CalculationSelector } from '@perses-dev/plugin-system';
|
|
15
|
+
import { Autocomplete, Button, Chip, FormControlLabel, Switch, TextField, ToggleButton, ToggleButtonGroup } from '@mui/material';
|
|
16
|
+
import { FormatControls, isPercentUnit, ModeSelector, OptionsEditorColumn, OptionsEditorGrid, OptionsEditorGroup, SortSelector } from '@perses-dev/components';
|
|
17
|
+
import { CalculationSelector, DEFAULT_CALCULATION } from '@perses-dev/plugin-system';
|
|
18
18
|
import { produce } from 'immer';
|
|
19
19
|
import merge from 'lodash/merge';
|
|
20
|
-
import { DEFAULT_FORMAT, DEFAULT_MODE, DEFAULT_SORT } from './bar-chart-model';
|
|
20
|
+
import { DEFAULT_FORMAT, DEFAULT_MODE, DEFAULT_ORIENTATION, DEFAULT_SORT, DEFAULT_IS_STACKED, DEFAULT_GROUP_BY } from './bar-chart-model';
|
|
21
21
|
export function BarChartOptionsEditorSettings(props) {
|
|
22
22
|
const { onChange, value } = props;
|
|
23
23
|
const handleCalculationChange = (newCalculation)=>{
|
|
@@ -46,36 +46,105 @@ export function BarChartOptionsEditorSettings(props) {
|
|
|
46
46
|
draft.format = DEFAULT_FORMAT;
|
|
47
47
|
draft.sort = DEFAULT_SORT;
|
|
48
48
|
draft.mode = DEFAULT_MODE;
|
|
49
|
+
draft.groupBy = DEFAULT_GROUP_BY;
|
|
50
|
+
draft.isStacked = DEFAULT_IS_STACKED;
|
|
51
|
+
draft.orientation = DEFAULT_ORIENTATION;
|
|
49
52
|
}));
|
|
50
53
|
};
|
|
51
54
|
// ensures decimalPlaces defaults to correct value
|
|
52
55
|
const format = merge({}, DEFAULT_FORMAT, value.format);
|
|
56
|
+
const groupBy = value.groupBy ?? DEFAULT_GROUP_BY;
|
|
57
|
+
const isStacked = value.isStacked ?? DEFAULT_IS_STACKED;
|
|
53
58
|
return /*#__PURE__*/ _jsxs(OptionsEditorGrid, {
|
|
54
59
|
children: [
|
|
55
|
-
/*#__PURE__*/
|
|
56
|
-
children:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
60
|
+
/*#__PURE__*/ _jsxs(OptionsEditorColumn, {
|
|
61
|
+
children: [
|
|
62
|
+
/*#__PURE__*/ _jsxs(OptionsEditorGroup, {
|
|
63
|
+
title: "Misc",
|
|
64
|
+
children: [
|
|
65
|
+
/*#__PURE__*/ _jsx(FormatControls, {
|
|
66
|
+
value: format,
|
|
67
|
+
onChange: handleUnitChange,
|
|
68
|
+
disabled: value.mode === 'percentage'
|
|
69
|
+
}),
|
|
70
|
+
/*#__PURE__*/ _jsx(CalculationSelector, {
|
|
71
|
+
value: value.calculation,
|
|
72
|
+
onChange: handleCalculationChange
|
|
73
|
+
}),
|
|
74
|
+
/*#__PURE__*/ _jsx(SortSelector, {
|
|
75
|
+
value: value.sort,
|
|
76
|
+
onChange: handleSortChange
|
|
77
|
+
}),
|
|
78
|
+
/*#__PURE__*/ _jsx(ModeSelector, {
|
|
79
|
+
value: value.mode,
|
|
80
|
+
onChange: handleModeChange,
|
|
81
|
+
disablePercentageMode: isPercentUnit(format)
|
|
82
|
+
}),
|
|
83
|
+
/*#__PURE__*/ _jsxs(ToggleButtonGroup, {
|
|
84
|
+
exclusive: true,
|
|
85
|
+
size: "small",
|
|
86
|
+
value: value.orientation ?? 'horizontal',
|
|
87
|
+
onChange: (_, v)=>v && onChange(produce(value, (draft)=>{
|
|
88
|
+
draft.orientation = v;
|
|
89
|
+
})),
|
|
90
|
+
children: [
|
|
91
|
+
/*#__PURE__*/ _jsx(ToggleButton, {
|
|
92
|
+
value: "horizontal",
|
|
93
|
+
children: "Horizontal"
|
|
94
|
+
}),
|
|
95
|
+
/*#__PURE__*/ _jsx(ToggleButton, {
|
|
96
|
+
value: "vertical",
|
|
97
|
+
children: "Vertical"
|
|
98
|
+
})
|
|
99
|
+
]
|
|
100
|
+
})
|
|
101
|
+
]
|
|
102
|
+
}),
|
|
103
|
+
/*#__PURE__*/ _jsxs(OptionsEditorGroup, {
|
|
104
|
+
title: "Stacking",
|
|
105
|
+
children: [
|
|
106
|
+
/*#__PURE__*/ _jsx(Autocomplete, {
|
|
107
|
+
multiple: true,
|
|
108
|
+
freeSolo: true,
|
|
109
|
+
value: groupBy,
|
|
110
|
+
onChange: (_, newValue)=>{
|
|
111
|
+
const filtered = newValue.filter((v)=>v.trim() !== '');
|
|
112
|
+
onChange(produce(value, (draft)=>{
|
|
113
|
+
draft.groupBy = filtered;
|
|
114
|
+
if (filtered.length === 0) draft.isStacked = false;
|
|
115
|
+
}));
|
|
116
|
+
},
|
|
117
|
+
options: [],
|
|
118
|
+
renderTags: (tagValues, getTagProps)=>tagValues.map((option, index)=>/*#__PURE__*/ _createElement(Chip, {
|
|
119
|
+
size: "small",
|
|
120
|
+
variant: "outlined",
|
|
121
|
+
label: option,
|
|
122
|
+
...getTagProps({
|
|
123
|
+
index
|
|
124
|
+
}),
|
|
125
|
+
key: option
|
|
126
|
+
})),
|
|
127
|
+
renderInput: (params)=>/*#__PURE__*/ _jsx(TextField, {
|
|
128
|
+
...params,
|
|
129
|
+
size: "small",
|
|
130
|
+
label: "Group By Labels",
|
|
131
|
+
placeholder: "Type label name + Enter"
|
|
132
|
+
})
|
|
133
|
+
}),
|
|
134
|
+
/*#__PURE__*/ _jsx(FormControlLabel, {
|
|
135
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
136
|
+
size: "small",
|
|
137
|
+
checked: isStacked,
|
|
138
|
+
disabled: groupBy.length === 0,
|
|
139
|
+
onChange: (e)=>onChange(produce(value, (draft)=>{
|
|
140
|
+
draft.isStacked = e.target.checked;
|
|
141
|
+
}))
|
|
142
|
+
}),
|
|
143
|
+
label: "Stack bars"
|
|
144
|
+
})
|
|
145
|
+
]
|
|
146
|
+
})
|
|
147
|
+
]
|
|
79
148
|
}),
|
|
80
149
|
/*#__PURE__*/ _jsx(OptionsEditorColumn, {
|
|
81
150
|
children: /*#__PURE__*/ _jsx(OptionsEditorGroup, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/BarChartOptionsEditorSettings.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Button } from '@mui/material';\nimport {\n FormatControls,\n FormatControlsProps,\n ModeOption,\n ModeSelector,\n ModeSelectorProps,\n OptionsEditorColumn,\n OptionsEditorGrid,\n OptionsEditorGroup,\n SortOption,\n SortSelector,\n SortSelectorProps,\n} from '@perses-dev/components';\nimport { CalculationType, DEFAULT_CALCULATION, FormatOptions, isPercentUnit } from '@perses-dev/core';\nimport { CalculationSelector, CalculationSelectorProps } from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport merge from 'lodash/merge';\nimport { MouseEventHandler, ReactElement } from 'react';\nimport {\n BarChartOptions,\n BarChartOptionsEditorProps,\n DEFAULT_FORMAT,\n DEFAULT_MODE,\n DEFAULT_SORT,\n} from './bar-chart-model';\n\nexport function BarChartOptionsEditorSettings(props: BarChartOptionsEditorProps): ReactElement {\n const { onChange, value } = props;\n\n const handleCalculationChange: CalculationSelectorProps['onChange'] = (newCalculation: CalculationType) => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.calculation = newCalculation;\n })\n );\n };\n\n const handleUnitChange: FormatControlsProps['onChange'] = (newFormat: FormatOptions) => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.format = newFormat;\n })\n );\n };\n\n const handleSortChange: SortSelectorProps['onChange'] = (newSort: SortOption) => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.sort = newSort;\n })\n );\n };\n\n const handleModeChange: ModeSelectorProps['onChange'] = (newMode: ModeOption) => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.mode = newMode;\n })\n );\n };\n\n const handleResetSettings: MouseEventHandler<HTMLButtonElement> = () => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.calculation = DEFAULT_CALCULATION;\n draft.format = DEFAULT_FORMAT;\n draft.sort = DEFAULT_SORT;\n draft.mode = DEFAULT_MODE;\n })\n );\n };\n\n // ensures decimalPlaces defaults to correct value\n const format = merge({}, DEFAULT_FORMAT, value.format);\n\n return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\n <OptionsEditorGroup title=\"Misc\">\n <FormatControls value={format} onChange={handleUnitChange} disabled={value.mode === 'percentage'} />\n <CalculationSelector value={value.calculation} onChange={handleCalculationChange} />\n <SortSelector value={value.sort} onChange={handleSortChange} />\n <ModeSelector value={value.mode} onChange={handleModeChange} disablePercentageMode={isPercentUnit(format)} />\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n <OptionsEditorColumn>\n <OptionsEditorGroup title=\"Reset Settings\">\n <Button variant=\"outlined\" color=\"secondary\" onClick={handleResetSettings}>\n Reset To Defaults\n </Button>\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n </OptionsEditorGrid>\n );\n}\n"],"names":["Button","FormatControls","ModeSelector","OptionsEditorColumn","OptionsEditorGrid","OptionsEditorGroup","SortSelector","DEFAULT_CALCULATION","isPercentUnit","CalculationSelector","produce","merge","DEFAULT_FORMAT","DEFAULT_MODE","DEFAULT_SORT","BarChartOptionsEditorSettings","props","onChange","value","handleCalculationChange","newCalculation","draft","calculation","handleUnitChange","newFormat","format","handleSortChange","newSort","sort","handleModeChange","newMode","mode","handleResetSettings","title","disabled","disablePercentageMode","variant","color","onClick"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAQ,gBAAgB;AACvC,SACEC,cAAc,EAGdC,YAAY,EAEZC,mBAAmB,EACnBC,iBAAiB,EACjBC,kBAAkB,EAElBC,YAAY,QAEP,yBAAyB;AAChC,SAA0BC,mBAAmB,EAAiBC,aAAa,QAAQ,mBAAmB;AACtG,SAASC,mBAAmB,QAAkC,4BAA4B;AAC1F,SAASC,OAAO,QAAQ,QAAQ;AAChC,OAAOC,WAAW,eAAe;AAEjC,SAGEC,cAAc,EACdC,YAAY,EACZC,YAAY,QACP,oBAAoB;AAE3B,OAAO,SAASC,8BAA8BC,KAAiC;IAC7E,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,MAAMG,0BAAgE,CAACC;QACrEH,SACEP,QAAQQ,OAAO,CAACG;YACdA,MAAMC,WAAW,GAAGF;QACtB;IAEJ;IAEA,MAAMG,mBAAoD,CAACC;QACzDP,SACEP,QAAQQ,OAAO,CAACG;YACdA,MAAMI,MAAM,GAAGD;QACjB;IAEJ;IAEA,MAAME,mBAAkD,CAACC;QACvDV,SACEP,QAAQQ,OAAO,CAACG;YACdA,MAAMO,IAAI,GAAGD;QACf;IAEJ;IAEA,MAAME,mBAAkD,CAACC;QACvDb,SACEP,QAAQQ,OAAO,CAACG;YACdA,MAAMU,IAAI,GAAGD;QACf;IAEJ;IAEA,MAAME,sBAA4D;QAChEf,SACEP,QAAQQ,OAAO,CAACG;YACdA,MAAMC,WAAW,GAAGf;YACpBc,MAAMI,MAAM,GAAGb;YACfS,MAAMO,IAAI,GAAGd;YACbO,MAAMU,IAAI,GAAGlB;QACf;IAEJ;IAEA,kDAAkD;IAClD,MAAMY,SAASd,MAAM,CAAC,GAAGC,gBAAgBM,MAAMO,MAAM;IAErD,qBACE,MAACrB;;0BACC,KAACD;0BACC,cAAA,MAACE;oBAAmB4B,OAAM;;sCACxB,KAAChC;4BAAeiB,OAAOO;4BAAQR,UAAUM;4BAAkBW,UAAUhB,MAAMa,IAAI,KAAK;;sCACpF,KAACtB;4BAAoBS,OAAOA,MAAMI,WAAW;4BAAEL,UAAUE;;sCACzD,KAACb;4BAAaY,OAAOA,MAAMU,IAAI;4BAAEX,UAAUS;;sCAC3C,KAACxB;4BAAagB,OAAOA,MAAMa,IAAI;4BAAEd,UAAUY;4BAAkBM,uBAAuB3B,cAAciB;;;;;0BAGtG,KAACtB;0BACC,cAAA,KAACE;oBAAmB4B,OAAM;8BACxB,cAAA,KAACjC;wBAAOoC,SAAQ;wBAAWC,OAAM;wBAAYC,SAASN;kCAAqB;;;;;;AAOrF"}
|
|
1
|
+
{"version":3,"sources":["../../src/BarChartOptionsEditorSettings.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n Autocomplete,\n Button,\n Chip,\n FormControlLabel,\n Switch,\n TextField,\n ToggleButton,\n ToggleButtonGroup,\n} from '@mui/material';\nimport {\n FormatControls,\n FormatControlsProps,\n FormatOptions,\n isPercentUnit,\n ModeOption,\n ModeSelector,\n ModeSelectorProps,\n OptionsEditorColumn,\n OptionsEditorGrid,\n OptionsEditorGroup,\n SortOption,\n SortSelector,\n SortSelectorProps,\n} from '@perses-dev/components';\nimport {\n CalculationSelector,\n CalculationSelectorProps,\n CalculationType,\n DEFAULT_CALCULATION,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport merge from 'lodash/merge';\nimport { MouseEventHandler, ReactElement } from 'react';\nimport {\n BarChartOptions,\n BarChartOptionsEditorProps,\n DEFAULT_FORMAT,\n DEFAULT_MODE,\n DEFAULT_ORIENTATION,\n DEFAULT_SORT,\n DEFAULT_IS_STACKED,\n DEFAULT_GROUP_BY,\n} from './bar-chart-model';\n\nexport function BarChartOptionsEditorSettings(props: BarChartOptionsEditorProps): ReactElement {\n const { onChange, value } = props;\n\n const handleCalculationChange: CalculationSelectorProps['onChange'] = (newCalculation: CalculationType) => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.calculation = newCalculation;\n })\n );\n };\n\n const handleUnitChange: FormatControlsProps['onChange'] = (newFormat: FormatOptions) => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.format = newFormat;\n })\n );\n };\n\n const handleSortChange: SortSelectorProps['onChange'] = (newSort: SortOption) => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.sort = newSort;\n })\n );\n };\n\n const handleModeChange: ModeSelectorProps['onChange'] = (newMode: ModeOption) => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.mode = newMode;\n })\n );\n };\n\n const handleResetSettings: MouseEventHandler<HTMLButtonElement> = () => {\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.calculation = DEFAULT_CALCULATION;\n draft.format = DEFAULT_FORMAT;\n draft.sort = DEFAULT_SORT;\n draft.mode = DEFAULT_MODE;\n draft.groupBy = DEFAULT_GROUP_BY;\n draft.isStacked = DEFAULT_IS_STACKED;\n draft.orientation = DEFAULT_ORIENTATION;\n })\n );\n };\n\n // ensures decimalPlaces defaults to correct value\n const format = merge({}, DEFAULT_FORMAT, value.format);\n const groupBy = value.groupBy ?? DEFAULT_GROUP_BY;\n const isStacked = value.isStacked ?? DEFAULT_IS_STACKED;\n\n return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\n <OptionsEditorGroup title=\"Misc\">\n <FormatControls value={format} onChange={handleUnitChange} disabled={value.mode === 'percentage'} />\n <CalculationSelector value={value.calculation} onChange={handleCalculationChange} />\n <SortSelector value={value.sort} onChange={handleSortChange} />\n <ModeSelector value={value.mode} onChange={handleModeChange} disablePercentageMode={isPercentUnit(format)} />\n <ToggleButtonGroup\n exclusive\n size=\"small\"\n value={value.orientation ?? 'horizontal'}\n onChange={(_, v) =>\n v &&\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.orientation = v;\n })\n )\n }\n >\n <ToggleButton value=\"horizontal\">Horizontal</ToggleButton>\n <ToggleButton value=\"vertical\">Vertical</ToggleButton>\n </ToggleButtonGroup>\n </OptionsEditorGroup>\n <OptionsEditorGroup title=\"Stacking\">\n <Autocomplete\n multiple\n freeSolo\n value={groupBy}\n onChange={(_, newValue) => {\n const filtered = (newValue as string[]).filter((v) => v.trim() !== '');\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.groupBy = filtered;\n if (filtered.length === 0) draft.isStacked = false;\n })\n );\n }}\n options={[]}\n renderTags={(tagValues, getTagProps) =>\n tagValues.map((option, index) => (\n <Chip size=\"small\" variant=\"outlined\" label={option} {...getTagProps({ index })} key={option} />\n ))\n }\n renderInput={(params) => (\n <TextField {...params} size=\"small\" label=\"Group By Labels\" placeholder=\"Type label name + Enter\" />\n )}\n />\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={isStacked}\n disabled={groupBy.length === 0}\n onChange={(e) =>\n onChange(\n produce(value, (draft: BarChartOptions) => {\n draft.isStacked = e.target.checked;\n })\n )\n }\n />\n }\n label=\"Stack bars\"\n />\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n <OptionsEditorColumn>\n <OptionsEditorGroup title=\"Reset Settings\">\n <Button variant=\"outlined\" color=\"secondary\" onClick={handleResetSettings}>\n Reset To Defaults\n </Button>\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n </OptionsEditorGrid>\n );\n}\n"],"names":["Autocomplete","Button","Chip","FormControlLabel","Switch","TextField","ToggleButton","ToggleButtonGroup","FormatControls","isPercentUnit","ModeSelector","OptionsEditorColumn","OptionsEditorGrid","OptionsEditorGroup","SortSelector","CalculationSelector","DEFAULT_CALCULATION","produce","merge","DEFAULT_FORMAT","DEFAULT_MODE","DEFAULT_ORIENTATION","DEFAULT_SORT","DEFAULT_IS_STACKED","DEFAULT_GROUP_BY","BarChartOptionsEditorSettings","props","onChange","value","handleCalculationChange","newCalculation","draft","calculation","handleUnitChange","newFormat","format","handleSortChange","newSort","sort","handleModeChange","newMode","mode","handleResetSettings","groupBy","isStacked","orientation","title","disabled","disablePercentageMode","exclusive","size","_","v","multiple","freeSolo","newValue","filtered","filter","trim","length","options","renderTags","tagValues","getTagProps","map","option","index","variant","label","key","renderInput","params","placeholder","control","checked","e","target","color","onClick"],"mappings":";;AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SACEA,YAAY,EACZC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,MAAM,EACNC,SAAS,EACTC,YAAY,EACZC,iBAAiB,QACZ,gBAAgB;AACvB,SACEC,cAAc,EAGdC,aAAa,EAEbC,YAAY,EAEZC,mBAAmB,EACnBC,iBAAiB,EACjBC,kBAAkB,EAElBC,YAAY,QAEP,yBAAyB;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CACLwB,SAAS9B;oCACTG,UAAUJ,QAAQgB,MAAM,KAAK;oCAC7BhC,UAAU,CAACgD,IACThD,SACEV,QAAQW,OAAO,CAACG;4CACdA,MAAMa,SAAS,GAAG+B,EAAEC,MAAM,CAACF,OAAO;wCACpC;;gCAKRN,OAAM;;;;;;0BAIZ,KAACzD;0BACC,cAAA,KAACE;oBAAmBiC,OAAM;8BACxB,cAAA,KAAC7C;wBAAOkE,SAAQ;wBAAWU,OAAM;wBAAYC,SAASpC;kCAAqB;;;;;;AAOrF"}
|
package/lib/BarChartPanel.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { TimeSeriesData } from '@perses-dev/core';
|
|
3
2
|
import { PanelProps } from '@perses-dev/plugin-system';
|
|
3
|
+
import { TimeSeriesData } from '@perses-dev/spec';
|
|
4
4
|
import { BarChartOptions } from './bar-chart-model';
|
|
5
5
|
export type BarChartPanelProps = PanelProps<BarChartOptions, TimeSeriesData>;
|
|
6
6
|
export declare function BarChartPanel(props: BarChartPanelProps): ReactElement | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BarChartPanel.d.ts","sourceRoot":"","sources":["../../src/BarChartPanel.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAoC,
|
|
1
|
+
{"version":3,"file":"BarChartPanel.d.ts","sourceRoot":"","sources":["../../src/BarChartPanel.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAoC,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;AAE7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,YAAY,GAAG,IAAI,CAiH5E"}
|
package/lib/BarChartPanel.js
CHANGED
|
@@ -14,14 +14,15 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
14
14
|
import { useChartsTheme } from '@perses-dev/components';
|
|
15
15
|
import { Box } from '@mui/material';
|
|
16
16
|
import { useMemo } from 'react';
|
|
17
|
-
import { CalculationsMap } from '@perses-dev/
|
|
17
|
+
import { CalculationsMap } from '@perses-dev/plugin-system';
|
|
18
18
|
import { calculatePercentages, sortSeriesData } from './utils';
|
|
19
19
|
import { BarChartBase } from './BarChartBase';
|
|
20
20
|
export function BarChartPanel(props) {
|
|
21
|
-
const { spec: { calculation, format, sort, mode }, contentDimensions, queryResults } = props;
|
|
21
|
+
const { spec: { calculation, format, sort, mode, groupBy = [], isStacked = false, orientation = 'horizontal' }, contentDimensions, queryResults } = props;
|
|
22
22
|
const chartsTheme = useChartsTheme();
|
|
23
23
|
const PADDING = chartsTheme.container.padding.default;
|
|
24
24
|
const barChartData = useMemo(()=>{
|
|
25
|
+
if (groupBy.length > 0) return [];
|
|
25
26
|
const calculate = CalculationsMap[calculation];
|
|
26
27
|
const barChartData = [];
|
|
27
28
|
for (const result of queryResults){
|
|
@@ -43,9 +44,72 @@ export function BarChartPanel(props) {
|
|
|
43
44
|
queryResults,
|
|
44
45
|
sort,
|
|
45
46
|
mode,
|
|
47
|
+
calculation,
|
|
48
|
+
groupBy
|
|
49
|
+
]);
|
|
50
|
+
const stackedBarChartData = useMemo(()=>{
|
|
51
|
+
if (groupBy.length === 0) return null;
|
|
52
|
+
const calculate = CalculationsMap[calculation];
|
|
53
|
+
const groupMap = new Map();
|
|
54
|
+
const segmentNamesOrdered = [];
|
|
55
|
+
const segmentNamesSet = new Set();
|
|
56
|
+
for (const queryResult of queryResults){
|
|
57
|
+
for (const seriesData of queryResult.data.series){
|
|
58
|
+
const labels = seriesData.labels ?? {};
|
|
59
|
+
const groupKey = groupBy.map((k)=>labels[k] ?? '').join(' / ');
|
|
60
|
+
const remainingEntries = Object.entries(labels).filter(([k])=>!groupBy.includes(k));
|
|
61
|
+
const segmentName = remainingEntries.length > 0 ? '{' + remainingEntries.map(([k, v])=>`${k}="${v}"`).join(', ') + '}' : seriesData.formattedName ?? seriesData.name;
|
|
62
|
+
if (!groupMap.has(groupKey)) {
|
|
63
|
+
groupMap.set(groupKey, new Map());
|
|
64
|
+
}
|
|
65
|
+
const segMap = groupMap.get(groupKey);
|
|
66
|
+
if (!segMap) continue;
|
|
67
|
+
const value = calculate(seriesData.values) ?? 0;
|
|
68
|
+
segMap.set(segmentName, (segMap.get(segmentName) ?? 0) + value);
|
|
69
|
+
if (!segmentNamesSet.has(segmentName)) {
|
|
70
|
+
segmentNamesSet.add(segmentName);
|
|
71
|
+
segmentNamesOrdered.push(segmentName);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (groupMap.size === 0) return null;
|
|
76
|
+
const getTotalValue = (cat)=>Array.from(groupMap.get(cat)?.values() ?? []).reduce((a, b)=>a + b, 0);
|
|
77
|
+
let categories = Array.from(groupMap.keys());
|
|
78
|
+
if (sort === 'asc') {
|
|
79
|
+
categories = categories.sort((a, b)=>getTotalValue(a) - getTotalValue(b));
|
|
80
|
+
} else if (sort === 'desc') {
|
|
81
|
+
categories = categories.sort((a, b)=>getTotalValue(b) - getTotalValue(a));
|
|
82
|
+
}
|
|
83
|
+
const series = segmentNamesOrdered.map((segName)=>{
|
|
84
|
+
const values = categories.map((cat)=>{
|
|
85
|
+
const rawVal = groupMap.get(cat)?.get(segName) ?? null;
|
|
86
|
+
if (mode === 'percentage' && rawVal !== null) {
|
|
87
|
+
const total = getTotalValue(cat);
|
|
88
|
+
return total > 0 ? rawVal / total * 100 : 0;
|
|
89
|
+
}
|
|
90
|
+
return rawVal;
|
|
91
|
+
});
|
|
92
|
+
return {
|
|
93
|
+
name: segName,
|
|
94
|
+
values
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
categories,
|
|
99
|
+
series
|
|
100
|
+
};
|
|
101
|
+
}, [
|
|
102
|
+
queryResults,
|
|
103
|
+
groupBy,
|
|
104
|
+
sort,
|
|
105
|
+
mode,
|
|
46
106
|
calculation
|
|
47
107
|
]);
|
|
48
108
|
if (contentDimensions === undefined) return null;
|
|
109
|
+
const effectiveFormat = mode === 'percentage' ? {
|
|
110
|
+
unit: 'percent',
|
|
111
|
+
decimalPlaces: format?.decimalPlaces
|
|
112
|
+
} : format;
|
|
49
113
|
return /*#__PURE__*/ _jsx(Box, {
|
|
50
114
|
sx: {
|
|
51
115
|
padding: `${PADDING}px`
|
|
@@ -54,8 +118,11 @@ export function BarChartPanel(props) {
|
|
|
54
118
|
width: contentDimensions.width - PADDING * 2,
|
|
55
119
|
height: contentDimensions.height - PADDING * 2,
|
|
56
120
|
data: barChartData,
|
|
57
|
-
format: format,
|
|
58
|
-
mode: mode
|
|
121
|
+
format: groupBy.length > 0 ? effectiveFormat : format,
|
|
122
|
+
mode: mode,
|
|
123
|
+
groupedData: stackedBarChartData,
|
|
124
|
+
isStacked: isStacked,
|
|
125
|
+
orientation: orientation
|
|
59
126
|
})
|
|
60
127
|
});
|
|
61
128
|
}
|
package/lib/BarChartPanel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/BarChartPanel.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useChartsTheme } from '@perses-dev/components';\nimport { Box } from '@mui/material';\nimport { ReactElement, useMemo } from 'react';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/BarChartPanel.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useChartsTheme } from '@perses-dev/components';\nimport { Box } from '@mui/material';\nimport { ReactElement, useMemo } from 'react';\nimport { CalculationsMap, CalculationType, PanelProps } from '@perses-dev/plugin-system';\nimport { TimeSeriesData } from '@perses-dev/spec';\nimport { BarChartOptions } from './bar-chart-model';\nimport { calculatePercentages, sortSeriesData } from './utils';\nimport { BarChartBase, BarChartData, StackedBarChartData, StackedBarChartSeries } from './BarChartBase';\n\nexport type BarChartPanelProps = PanelProps<BarChartOptions, TimeSeriesData>;\n\nexport function BarChartPanel(props: BarChartPanelProps): ReactElement | null {\n const {\n spec: { calculation, format, sort, mode, groupBy = [], isStacked = false, orientation = 'horizontal' },\n contentDimensions,\n queryResults,\n } = props;\n\n const chartsTheme = useChartsTheme();\n const PADDING = chartsTheme.container.padding.default;\n\n const barChartData: BarChartData[] = useMemo(() => {\n if (groupBy.length > 0) return [];\n\n const calculate = CalculationsMap[calculation as CalculationType];\n const barChartData: BarChartData[] = [];\n for (const result of queryResults) {\n for (const seriesData of result.data.series) {\n const series = {\n value: calculate(seriesData.values) ?? null,\n label: seriesData.formattedName ?? '',\n };\n barChartData.push(series);\n }\n }\n\n const sortedBarChartData = sortSeriesData(barChartData, sort);\n if (mode === 'percentage') {\n return calculatePercentages(sortedBarChartData);\n } else {\n return sortedBarChartData;\n }\n }, [queryResults, sort, mode, calculation, groupBy]);\n\n const stackedBarChartData: StackedBarChartData | null = useMemo(() => {\n if (groupBy.length === 0) return null;\n\n const calculate = CalculationsMap[calculation as CalculationType];\n const groupMap = new Map<string, Map<string, number>>();\n const segmentNamesOrdered: string[] = [];\n const segmentNamesSet = new Set<string>();\n\n for (const queryResult of queryResults) {\n for (const seriesData of queryResult.data.series) {\n const labels = seriesData.labels ?? {};\n\n const groupKey = groupBy.map((k) => labels[k] ?? '').join(' / ');\n\n const remainingEntries = Object.entries(labels).filter(([k]) => !groupBy.includes(k));\n const segmentName =\n remainingEntries.length > 0\n ? '{' + remainingEntries.map(([k, v]) => `${k}=\"${v}\"`).join(', ') + '}'\n : (seriesData.formattedName ?? seriesData.name);\n\n if (!groupMap.has(groupKey)) {\n groupMap.set(groupKey, new Map());\n }\n const segMap = groupMap.get(groupKey);\n if (!segMap) continue;\n const value = calculate(seriesData.values) ?? 0;\n segMap.set(segmentName, (segMap.get(segmentName) ?? 0) + value);\n\n if (!segmentNamesSet.has(segmentName)) {\n segmentNamesSet.add(segmentName);\n segmentNamesOrdered.push(segmentName);\n }\n }\n }\n\n if (groupMap.size === 0) return null;\n const getTotalValue = (cat: string): number =>\n Array.from(groupMap.get(cat)?.values() ?? []).reduce((a, b) => a + b, 0);\n\n let categories = Array.from(groupMap.keys());\n if (sort === 'asc') {\n categories = categories.sort((a, b) => getTotalValue(a) - getTotalValue(b));\n } else if (sort === 'desc') {\n categories = categories.sort((a, b) => getTotalValue(b) - getTotalValue(a));\n }\n\n const series: StackedBarChartSeries[] = segmentNamesOrdered.map((segName) => {\n const values = categories.map((cat) => {\n const rawVal = groupMap.get(cat)?.get(segName) ?? null;\n if (mode === 'percentage' && rawVal !== null) {\n const total = getTotalValue(cat);\n return total > 0 ? (rawVal / total) * 100 : 0;\n }\n return rawVal;\n });\n return { name: segName, values };\n });\n\n return { categories, series };\n }, [queryResults, groupBy, sort, mode, calculation]);\n\n if (contentDimensions === undefined) return null;\n\n const effectiveFormat =\n mode === 'percentage' ? { unit: 'percent' as const, decimalPlaces: format?.decimalPlaces } : format;\n\n return (\n <Box sx={{ padding: `${PADDING}px` }}>\n <BarChartBase\n width={contentDimensions.width - PADDING * 2}\n height={contentDimensions.height - PADDING * 2}\n data={barChartData}\n format={groupBy.length > 0 ? effectiveFormat : format}\n mode={mode}\n groupedData={stackedBarChartData}\n isStacked={isStacked}\n orientation={orientation}\n />\n </Box>\n );\n}\n"],"names":["useChartsTheme","Box","useMemo","CalculationsMap","calculatePercentages","sortSeriesData","BarChartBase","BarChartPanel","props","spec","calculation","format","sort","mode","groupBy","isStacked","orientation","contentDimensions","queryResults","chartsTheme","PADDING","container","padding","default","barChartData","length","calculate","result","seriesData","data","series","value","values","label","formattedName","push","sortedBarChartData","stackedBarChartData","groupMap","Map","segmentNamesOrdered","segmentNamesSet","Set","queryResult","labels","groupKey","map","k","join","remainingEntries","Object","entries","filter","includes","segmentName","v","name","has","set","segMap","get","add","size","getTotalValue","cat","Array","from","reduce","a","b","categories","keys","segName","rawVal","total","undefined","effectiveFormat","unit","decimalPlaces","sx","width","height","groupedData"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,QAAQ,yBAAyB;AACxD,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAASC,eAAe,QAAqC,4BAA4B;AAGzF,SAASC,oBAAoB,EAAEC,cAAc,QAAQ,UAAU;AAC/D,SAASC,YAAY,QAAkE,iBAAiB;AAIxG,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EACJC,MAAM,EAAEC,WAAW,EAAEC,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,UAAU,EAAE,EAAEC,YAAY,KAAK,EAAEC,cAAc,YAAY,EAAE,EACtGC,iBAAiB,EACjBC,Y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gBAC7B,MAAMS,SAASnC,SAASsB,GAAG,CAACI,MAAMJ,IAAIY,YAAY;gBAClD,IAAI3D,SAAS,gBAAgB4D,WAAW,MAAM;oBAC5C,MAAMC,QAAQX,cAAcC;oBAC5B,OAAOU,QAAQ,IAAI,AAACD,SAASC,QAAS,MAAM;gBAC9C;gBACA,OAAOD;YACT;YACA,OAAO;gBAAEjB,MAAMgB;gBAASxC;YAAO;QACjC;QAEA,OAAO;YAAEsC;YAAYxC;QAAO;IAC9B,GAAG;QAACZ;QAAcJ;QAASF;QAAMC;QAAMH;KAAY;IAEnD,IAAIO,sBAAsB0D,WAAW,OAAO;IAE5C,MAAMC,kBACJ/D,SAAS,eAAe;QAAEgE,MAAM;QAAoBC,eAAenE,QAAQmE;IAAc,IAAInE;IAE/F,qBACE,KAACV;QAAI8E,IAAI;YAAEzD,SAAS,GAAGF,QAAQ,EAAE,CAAC;QAAC;kBACjC,cAAA,KAACd;YACC0E,OAAO/D,kBAAkB+D,KAAK,GAAG5D,UAAU;YAC3C6D,QAAQhE,kBAAkBgE,MAAM,GAAG7D,UAAU;YAC7CS,MAAML;YACNb,QAAQG,QAAQW,MAAM,GAAG,IAAImD,kBAAkBjE;YAC/CE,MAAMA;YACNqE,aAAa7C;YACbtB,WAAWA;YACXC,aAAaA;;;AAIrB"}
|
package/lib/bar-chart-model.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { ModeOption, SortOption } from '@perses-dev/components';
|
|
2
|
-
import { CalculationType,
|
|
3
|
-
import {
|
|
1
|
+
import { FormatOptions, ModeOption, SortOption } from '@perses-dev/components';
|
|
2
|
+
import { CalculationType, OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
3
|
+
import { Definition } from '@perses-dev/spec';
|
|
4
4
|
export declare const DEFAULT_FORMAT: FormatOptions;
|
|
5
5
|
export declare const DEFAULT_SORT: SortOption;
|
|
6
6
|
export declare const DEFAULT_MODE: ModeOption;
|
|
7
|
+
export declare const DEFAULT_ORIENTATION: 'horizontal' | 'vertical';
|
|
8
|
+
export declare const DEFAULT_GROUP_BY: string[];
|
|
9
|
+
export declare const DEFAULT_IS_STACKED = false;
|
|
7
10
|
/**
|
|
8
11
|
* The schema for a BarChart panel.
|
|
9
12
|
*/
|
|
@@ -18,6 +21,9 @@ export interface BarChartOptions {
|
|
|
18
21
|
format?: FormatOptions;
|
|
19
22
|
sort?: SortOption;
|
|
20
23
|
mode?: ModeOption;
|
|
24
|
+
orientation?: 'horizontal' | 'vertical';
|
|
25
|
+
groupBy?: string[];
|
|
26
|
+
isStacked?: boolean;
|
|
21
27
|
}
|
|
22
28
|
export type BarChartOptionsEditorProps = OptionsEditorProps<BarChartOptions>;
|
|
23
29
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bar-chart-model.d.ts","sourceRoot":"","sources":["../../src/bar-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"bar-chart-model.d.ts","sourceRoot":"","sources":["../../src/bar-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAuB,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,eAAO,MAAM,cAAc,EAAE,aAAsD,CAAC;AACpF,eAAO,MAAM,YAAY,EAAE,UAAmB,CAAC;AAC/C,eAAO,MAAM,YAAY,EAAE,UAAoB,CAAC;AAChD,eAAO,MAAM,mBAAmB,EAAE,YAAY,GAAG,UAAyB,CAAC;AAC3E,eAAO,MAAM,gBAAgB,EAAE,MAAM,EAAO,CAAC;AAC7C,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,UAAU,CAAC,eAAe,CAAC;IACrE,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,MAAM,0BAA0B,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAE7E;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,eAAe,CAU9D"}
|
package/lib/bar-chart-model.js
CHANGED
|
@@ -10,13 +10,16 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { DEFAULT_CALCULATION } from '@perses-dev/
|
|
13
|
+
import { DEFAULT_CALCULATION } from '@perses-dev/plugin-system';
|
|
14
14
|
export const DEFAULT_FORMAT = {
|
|
15
15
|
unit: 'decimal',
|
|
16
16
|
shortValues: true
|
|
17
17
|
};
|
|
18
18
|
export const DEFAULT_SORT = 'desc';
|
|
19
19
|
export const DEFAULT_MODE = 'value';
|
|
20
|
+
export const DEFAULT_ORIENTATION = 'horizontal';
|
|
21
|
+
export const DEFAULT_GROUP_BY = [];
|
|
22
|
+
export const DEFAULT_IS_STACKED = false;
|
|
20
23
|
/**
|
|
21
24
|
* Creates the initial/empty options for a BarChart panel.
|
|
22
25
|
*/ export function createInitialBarChartOptions() {
|
|
@@ -24,7 +27,10 @@ export const DEFAULT_MODE = 'value';
|
|
|
24
27
|
calculation: DEFAULT_CALCULATION,
|
|
25
28
|
format: DEFAULT_FORMAT,
|
|
26
29
|
sort: DEFAULT_SORT,
|
|
27
|
-
mode: DEFAULT_MODE
|
|
30
|
+
mode: DEFAULT_MODE,
|
|
31
|
+
orientation: DEFAULT_ORIENTATION,
|
|
32
|
+
groupBy: DEFAULT_GROUP_BY,
|
|
33
|
+
isStacked: DEFAULT_IS_STACKED
|
|
28
34
|
};
|
|
29
35
|
}
|
|
30
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bar-chart-model.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ModeOption, SortOption } from '@perses-dev/components';\nimport { CalculationType, DEFAULT_CALCULATION,
|
|
1
|
+
{"version":3,"sources":["../../src/bar-chart-model.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FormatOptions, ModeOption, SortOption } from '@perses-dev/components';\nimport { CalculationType, DEFAULT_CALCULATION, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Definition } from '@perses-dev/spec';\n\nexport const DEFAULT_FORMAT: FormatOptions = { unit: 'decimal', shortValues: true };\nexport const DEFAULT_SORT: SortOption = 'desc';\nexport const DEFAULT_MODE: ModeOption = 'value';\nexport const DEFAULT_ORIENTATION: 'horizontal' | 'vertical' = 'horizontal';\nexport const DEFAULT_GROUP_BY: string[] = [];\nexport const DEFAULT_IS_STACKED = false;\n\n/**\n * The schema for a BarChart panel.\n */\nexport interface BarChartDefinition extends Definition<BarChartOptions> {\n kind: 'BarChart';\n}\n\n/**\n * The Options object type supported by the BarChart panel plugin.\n */\nexport interface BarChartOptions {\n calculation: CalculationType;\n format?: FormatOptions;\n sort?: SortOption;\n mode?: ModeOption;\n orientation?: 'horizontal' | 'vertical';\n groupBy?: string[];\n isStacked?: boolean;\n}\n\nexport type BarChartOptionsEditorProps = OptionsEditorProps<BarChartOptions>;\n\n/**\n * Creates the initial/empty options for a BarChart panel.\n */\nexport function createInitialBarChartOptions(): BarChartOptions {\n return {\n calculation: DEFAULT_CALCULATION,\n format: DEFAULT_FORMAT,\n sort: DEFAULT_SORT,\n mode: DEFAULT_MODE,\n orientation: DEFAULT_ORIENTATION,\n groupBy: DEFAULT_GROUP_BY,\n isStacked: DEFAULT_IS_STACKED,\n };\n}\n"],"names":["DEFAULT_CALCULATION","DEFAULT_FORMAT","unit","shortValues","DEFAULT_SORT","DEFAULT_MODE","DEFAULT_ORIENTATION","DEFAULT_GROUP_BY","DEFAULT_IS_STACKED","createInitialBarChartOptions","calculation","format","sort","mode","orientation","groupBy","isStacked"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAA0BA,mBAAmB,QAA4B,4BAA4B;AAGrG,OAAO,MAAMC,iBAAgC;IAAEC,MAAM;IAAWC,aAAa;AAAK,EAAE;AACpF,OAAO,MAAMC,eAA2B,OAAO;AAC/C,OAAO,MAAMC,eAA2B,QAAQ;AAChD,OAAO,MAAMC,sBAAiD,aAAa;AAC3E,OAAO,MAAMC,mBAA6B,EAAE,CAAC;AAC7C,OAAO,MAAMC,qBAAqB,MAAM;AAwBxC;;CAEC,GACD,OAAO,SAASC;IACd,OAAO;QACLC,aAAaV;QACbW,QAAQV;QACRW,MAAMR;QACNS,MAAMR;QACNS,aAAaR;QACbS,SAASR;QACTS,WAAWR;IACb;AACF"}
|
package/lib/cjs/BarChartBase.js
CHANGED
|
@@ -23,28 +23,97 @@ Object.defineProperty(exports, "BarChartBase", {
|
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _react = require("react");
|
|
25
25
|
const _components = require("@perses-dev/components");
|
|
26
|
-
const _core = require("
|
|
27
|
-
const _core1 = require("echarts/core");
|
|
26
|
+
const _core = require("echarts/core");
|
|
28
27
|
const _charts = require("echarts/charts");
|
|
29
28
|
const _components1 = require("echarts/components");
|
|
30
29
|
const _renderers = require("echarts/renderers");
|
|
31
30
|
const _material = require("@mui/material");
|
|
32
|
-
(0,
|
|
31
|
+
(0, _core.use)([
|
|
33
32
|
_charts.BarChart,
|
|
34
33
|
_components1.GridComponent,
|
|
35
34
|
_components1.DatasetComponent,
|
|
36
35
|
_components1.TitleComponent,
|
|
37
36
|
_components1.TooltipComponent,
|
|
37
|
+
_components1.LegendComponent,
|
|
38
38
|
_renderers.CanvasRenderer
|
|
39
39
|
]);
|
|
40
40
|
const BAR_WIN_WIDTH = 14;
|
|
41
41
|
const BAR_GAP = 6;
|
|
42
|
+
const LEGEND_HEIGHT = 20;
|
|
42
43
|
function BarChartBase(props) {
|
|
43
44
|
const { width, height, data, format = {
|
|
44
45
|
unit: 'decimal'
|
|
45
|
-
}, mode = 'value' } = props;
|
|
46
|
+
}, mode = 'value', groupedData, isStacked = false, orientation = 'horizontal' } = props;
|
|
46
47
|
const chartsTheme = (0, _components.useChartsTheme)();
|
|
48
|
+
const isHorizontal = orientation === 'horizontal';
|
|
47
49
|
const option = (0, _react.useMemo)(()=>{
|
|
50
|
+
if (groupedData) {
|
|
51
|
+
if (!groupedData.series.length || !groupedData.categories.length) return chartsTheme.noDataOption;
|
|
52
|
+
const { categories, series } = groupedData;
|
|
53
|
+
return {
|
|
54
|
+
title: {
|
|
55
|
+
show: false
|
|
56
|
+
},
|
|
57
|
+
legend: {
|
|
58
|
+
type: 'scroll',
|
|
59
|
+
show: true,
|
|
60
|
+
bottom: 0
|
|
61
|
+
},
|
|
62
|
+
xAxis: isHorizontal ? (0, _components.getFormattedAxis)({}, format) : {
|
|
63
|
+
type: 'category',
|
|
64
|
+
data: categories,
|
|
65
|
+
splitLine: {
|
|
66
|
+
show: false
|
|
67
|
+
},
|
|
68
|
+
axisLabel: {
|
|
69
|
+
overflow: 'truncate',
|
|
70
|
+
width: width / 3
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
yAxis: isHorizontal ? {
|
|
74
|
+
type: 'category',
|
|
75
|
+
data: categories,
|
|
76
|
+
splitLine: {
|
|
77
|
+
show: false
|
|
78
|
+
},
|
|
79
|
+
axisLabel: {
|
|
80
|
+
overflow: 'truncate',
|
|
81
|
+
width: width / 3
|
|
82
|
+
}
|
|
83
|
+
} : (0, _components.getFormattedAxis)({}, format),
|
|
84
|
+
series: series.map((s)=>({
|
|
85
|
+
name: s.name,
|
|
86
|
+
type: 'bar',
|
|
87
|
+
stack: isStacked ? 'total' : undefined,
|
|
88
|
+
data: s.values,
|
|
89
|
+
label: {
|
|
90
|
+
show: false
|
|
91
|
+
},
|
|
92
|
+
itemStyle: {
|
|
93
|
+
borderRadius: isStacked ? 0 : 4
|
|
94
|
+
}
|
|
95
|
+
})),
|
|
96
|
+
tooltip: {
|
|
97
|
+
trigger: 'axis',
|
|
98
|
+
axisPointer: {
|
|
99
|
+
type: 'shadow'
|
|
100
|
+
},
|
|
101
|
+
appendToBody: true,
|
|
102
|
+
confine: true,
|
|
103
|
+
formatter: (params)=>{
|
|
104
|
+
if (!params.length) return '';
|
|
105
|
+
const header = `<b>${params[0]?.name}</b><br/>`;
|
|
106
|
+
const rows = params.filter((p)=>p.data !== null).map((p)=>`<span style="display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;background-color:${p.color}"></span>` + `${p.seriesName}: <b>${(0, _components.formatValue)(p.data, format)}</b>`).join('<br/>');
|
|
107
|
+
return header + rows;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
grid: {
|
|
111
|
+
left: '5%',
|
|
112
|
+
right: '5%',
|
|
113
|
+
bottom: LEGEND_HEIGHT * 2
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
48
117
|
if (!data || !data.length) return chartsTheme.noDataOption;
|
|
49
118
|
const source = [];
|
|
50
119
|
data.map((d)=>{
|
|
@@ -66,8 +135,7 @@ function BarChartBase(props) {
|
|
|
66
135
|
source: source
|
|
67
136
|
}
|
|
68
137
|
],
|
|
69
|
-
xAxis: (0, _components.getFormattedAxis)({}, format)
|
|
70
|
-
yAxis: {
|
|
138
|
+
xAxis: isHorizontal ? (0, _components.getFormattedAxis)({}, format) : {
|
|
71
139
|
type: 'category',
|
|
72
140
|
splitLine: {
|
|
73
141
|
show: false
|
|
@@ -77,25 +145,35 @@ function BarChartBase(props) {
|
|
|
77
145
|
width: width / 3
|
|
78
146
|
}
|
|
79
147
|
},
|
|
148
|
+
yAxis: isHorizontal ? {
|
|
149
|
+
type: 'category',
|
|
150
|
+
splitLine: {
|
|
151
|
+
show: false
|
|
152
|
+
},
|
|
153
|
+
axisLabel: {
|
|
154
|
+
overflow: 'truncate',
|
|
155
|
+
width: width / 3
|
|
156
|
+
}
|
|
157
|
+
} : (0, _components.getFormattedAxis)({}, format),
|
|
80
158
|
series: {
|
|
81
159
|
type: 'bar',
|
|
160
|
+
barMinWidth: BAR_WIN_WIDTH,
|
|
161
|
+
barCategoryGap: BAR_GAP,
|
|
82
162
|
label: {
|
|
83
163
|
show: true,
|
|
84
|
-
position: 'right',
|
|
164
|
+
position: isHorizontal ? 'right' : 'top',
|
|
85
165
|
formatter: (params)=>{
|
|
86
166
|
if (!params.data[1]) {
|
|
87
167
|
return undefined;
|
|
88
168
|
}
|
|
89
169
|
if (mode === 'percentage') {
|
|
90
|
-
return (0,
|
|
170
|
+
return (0, _components.formatValue)(params.data[1], {
|
|
91
171
|
unit: 'percent',
|
|
92
172
|
decimalPlaces: format.decimalPlaces
|
|
93
173
|
});
|
|
94
174
|
}
|
|
95
|
-
return (0,
|
|
96
|
-
}
|
|
97
|
-
barMinWidth: BAR_WIN_WIDTH,
|
|
98
|
-
barCategoryGap: BAR_GAP
|
|
175
|
+
return (0, _components.formatValue)(params.data[1], format);
|
|
176
|
+
}
|
|
99
177
|
},
|
|
100
178
|
itemStyle: {
|
|
101
179
|
borderRadius: 4,
|
|
@@ -105,7 +183,7 @@ function BarChartBase(props) {
|
|
|
105
183
|
tooltip: {
|
|
106
184
|
appendToBody: true,
|
|
107
185
|
confine: true,
|
|
108
|
-
formatter: (params)=>params.data[1] && `<b>${params.name}</b>   ${(0,
|
|
186
|
+
formatter: (params)=>params.data[1] && `<b>${params.name}</b>   ${(0, _components.formatValue)(params.data[1], format)}`
|
|
109
187
|
},
|
|
110
188
|
// increase distance between grid and container to prevent y axis labels from getting cut off
|
|
111
189
|
grid: {
|
|
@@ -115,11 +193,25 @@ function BarChartBase(props) {
|
|
|
115
193
|
};
|
|
116
194
|
}, [
|
|
117
195
|
data,
|
|
196
|
+
groupedData,
|
|
197
|
+
isStacked,
|
|
118
198
|
chartsTheme,
|
|
119
199
|
width,
|
|
120
200
|
mode,
|
|
121
|
-
format
|
|
201
|
+
format,
|
|
202
|
+
isHorizontal
|
|
122
203
|
]);
|
|
204
|
+
const numGroupedRows = groupedData ? isStacked ? groupedData.categories.length : groupedData.categories.length * groupedData.series.length : 0;
|
|
205
|
+
function getChartHeight() {
|
|
206
|
+
if (groupedData) {
|
|
207
|
+
if (!isHorizontal) return height;
|
|
208
|
+
return Math.max(height, numGroupedRows * (BAR_WIN_WIDTH + BAR_GAP) + LEGEND_HEIGHT * 2 + 20);
|
|
209
|
+
}
|
|
210
|
+
if (data) {
|
|
211
|
+
return data.length * (BAR_WIN_WIDTH + BAR_GAP);
|
|
212
|
+
}
|
|
213
|
+
return '100%';
|
|
214
|
+
}
|
|
123
215
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
124
216
|
style: {
|
|
125
217
|
width: width,
|
|
@@ -131,7 +223,7 @@ function BarChartBase(props) {
|
|
|
131
223
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.EChart, {
|
|
132
224
|
style: {
|
|
133
225
|
minHeight: height,
|
|
134
|
-
height:
|
|
226
|
+
height: getChartHeight()
|
|
135
227
|
},
|
|
136
228
|
option: option,
|
|
137
229
|
theme: chartsTheme.echartsTheme
|