@perses-dev/pie-chart-plugin 0.13.0 → 0.14.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/PieChart.4874b5a3.js +7 -0
- package/__mf/js/async/121.77d8ca8d.js +2 -0
- package/__mf/js/async/177.5b05acb8.js +1 -0
- package/__mf/js/async/192.8567667d.js +1 -0
- package/__mf/js/async/2.1fd70a85.js +1 -0
- package/__mf/js/async/204.0b9b3971.js +1 -0
- package/__mf/js/async/235.47f639e4.js +1 -0
- package/__mf/js/async/236.93daa9e1.js +7 -0
- package/__mf/js/async/{390.99d822cd.js.LICENSE.txt → 236.93daa9e1.js.LICENSE.txt} +19 -1
- package/__mf/js/async/274.a688b81f.js +2 -0
- package/__mf/js/async/356.f9173bd6.js +1 -0
- package/__mf/js/async/376.9566e7f3.js +110 -0
- package/__mf/js/async/376.9566e7f3.js.LICENSE.txt +27 -0
- package/__mf/js/async/392.fd732e61.js +2 -0
- package/__mf/js/async/469.3c02be86.js +1 -0
- package/__mf/js/async/47.58c2f69b.js +39 -0
- package/__mf/js/async/{67.5bf7fff1.js.LICENSE.txt → 47.58c2f69b.js.LICENSE.txt} +11 -23
- package/__mf/js/async/470.f4861d15.js +2 -0
- package/__mf/js/async/554.97159342.js +2 -0
- package/__mf/js/async/558.38ed78e0.js +1 -0
- package/__mf/js/async/568.21c3aaad.js +24 -0
- package/__mf/js/async/{648.924b8cfc.js.LICENSE.txt → 568.21c3aaad.js.LICENSE.txt} +0 -16
- package/__mf/js/async/587.cb45262d.js +1 -0
- package/__mf/js/async/616.b87a9b8b.js +1 -0
- package/__mf/js/async/663.69a57e79.js +1 -0
- package/__mf/js/async/721.6e66d127.js +1 -0
- package/__mf/js/async/873.10a8cf00.js +1 -0
- package/__mf/js/async/941.8d9ea74e.js +2 -0
- package/__mf/js/async/968.1b0e9683.js +1 -0
- package/__mf/js/async/__federation_expose_PieChart.944f7c8e.js +4 -0
- package/__mf/js/async/lib-router.6ba1ce34.js +2 -0
- package/__mf/js/main.641ea30c.js +7 -0
- package/lib/PieChartBase.d.ts +6 -0
- package/lib/PieChartBase.d.ts.map +1 -1
- package/lib/PieChartBase.js +5 -4
- package/lib/PieChartBase.js.map +1 -1
- package/lib/PieChartOptionsEditorSettings.d.ts.map +1 -1
- package/lib/PieChartOptionsEditorSettings.js +1 -2
- package/lib/PieChartOptionsEditorSettings.js.map +1 -1
- package/lib/PieChartPanel.d.ts +1 -1
- package/lib/PieChartPanel.d.ts.map +1 -1
- package/lib/PieChartPanel.js +25 -70
- package/lib/PieChartPanel.js.map +1 -1
- package/lib/cjs/PieChartBase.js +4 -3
- package/lib/cjs/PieChartOptionsEditorSettings.js +1 -2
- package/lib/cjs/PieChartPanel.js +24 -69
- package/lib/cjs/pie-chart-model.js +2 -2
- package/lib/cjs/utils.js +123 -12
- package/lib/pie-chart-model.d.ts +3 -3
- package/lib/pie-chart-model.d.ts.map +1 -1
- package/lib/pie-chart-model.js +1 -1
- package/lib/pie-chart-model.js.map +1 -1
- package/lib/utils.d.ts +22 -6
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +112 -10
- package/lib/utils.js.map +1 -1
- package/mf-manifest.json +56 -46
- package/mf-stats.json +70 -47
- 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/PieChart.cf3c31fc.js +0 -6
- package/__mf/js/async/121.281eb287.js +0 -2
- package/__mf/js/async/177.c83badab.js +0 -1
- package/__mf/js/async/192.b0eb01c2.js +0 -1
- package/__mf/js/async/2.ba8aa6eb.js +0 -1
- package/__mf/js/async/235.88141957.js +0 -1
- package/__mf/js/async/274.78035147.js +0 -2
- package/__mf/js/async/337.13482c5c.js +0 -1
- package/__mf/js/async/350.7f227cc5.js +0 -1
- package/__mf/js/async/356.75a8af4c.js +0 -1
- package/__mf/js/async/390.99d822cd.js +0 -7
- package/__mf/js/async/392.2780a75e.js +0 -2
- package/__mf/js/async/469.e52e96c4.js +0 -1
- package/__mf/js/async/470.844ea64f.js +0 -2
- package/__mf/js/async/554.2692322c.js +0 -2
- package/__mf/js/async/587.6f746ff5.js +0 -1
- package/__mf/js/async/616.b6650249.js +0 -1
- package/__mf/js/async/634.282182cd.js +0 -38
- package/__mf/js/async/648.924b8cfc.js +0 -22
- package/__mf/js/async/663.c0629798.js +0 -1
- package/__mf/js/async/67.5bf7fff1.js +0 -110
- package/__mf/js/async/721.8dc45583.js +0 -1
- package/__mf/js/async/873.8b5831f0.js +0 -1
- package/__mf/js/async/941.4ea66ef3.js +0 -2
- package/__mf/js/async/968.a62ee0f7.js +0 -1
- package/__mf/js/async/__federation_expose_PieChart.329ca150.js +0 -1
- package/__mf/js/async/lib-router.48213c49.js +0 -2
- package/__mf/js/main.2fa79bb4.js +0 -6
- /package/__mf/js/async/{121.281eb287.js.LICENSE.txt → 121.77d8ca8d.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{274.78035147.js.LICENSE.txt → 274.a688b81f.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{392.2780a75e.js.LICENSE.txt → 392.fd732e61.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{470.844ea64f.js.LICENSE.txt → 470.f4861d15.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{554.2692322c.js.LICENSE.txt → 554.97159342.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{941.4ea66ef3.js.LICENSE.txt → 941.8d9ea74e.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{lib-router.48213c49.js.LICENSE.txt → lib-router.6ba1ce34.js.LICENSE.txt} +0 -0
package/lib/cjs/utils.js
CHANGED
|
@@ -21,24 +21,26 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
get
|
|
25
|
-
return
|
|
24
|
+
get PieChartListLegendMapper () {
|
|
25
|
+
return PieChartListLegendMapper;
|
|
26
|
+
},
|
|
27
|
+
get PieChartTableLegendMapper () {
|
|
28
|
+
return PieChartTableLegendMapper;
|
|
29
|
+
},
|
|
30
|
+
get getLabelFormatter () {
|
|
31
|
+
return getLabelFormatter;
|
|
32
|
+
},
|
|
33
|
+
get getTooltipFormatter () {
|
|
34
|
+
return getTooltipFormatter;
|
|
26
35
|
},
|
|
27
36
|
get sortSeriesData () {
|
|
28
37
|
return sortSeriesData;
|
|
29
38
|
}
|
|
30
39
|
});
|
|
40
|
+
const _components = require("@perses-dev/components");
|
|
41
|
+
const _echarts = require("echarts");
|
|
42
|
+
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
31
43
|
const _piechartmodel = require("./pie-chart-model");
|
|
32
|
-
function calculatePercentages(data) {
|
|
33
|
-
const sum = data.reduce((accumulator, { value })=>accumulator + (value ?? 0), 0);
|
|
34
|
-
return data.map((seriesData)=>{
|
|
35
|
-
const percentage = (seriesData.value ?? 0) / sum * 100;
|
|
36
|
-
return {
|
|
37
|
-
...seriesData,
|
|
38
|
-
value: Number(percentage.toFixed(2))
|
|
39
|
-
};
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
44
|
function sortSeriesData(data, sortOrder = _piechartmodel.DEFAULT_SORT) {
|
|
43
45
|
return data.sort((a, b)=>{
|
|
44
46
|
// Handle null values - push them to the end regardless of sort order
|
|
@@ -50,3 +52,112 @@ function sortSeriesData(data, sortOrder = _piechartmodel.DEFAULT_SORT) {
|
|
|
50
52
|
return sortOrder === 'asc' ? diff : -diff;
|
|
51
53
|
});
|
|
52
54
|
}
|
|
55
|
+
const getTooltipFormatter = (formatOptions)=>{
|
|
56
|
+
const relativeFormatOptions = {
|
|
57
|
+
unit: 'percent',
|
|
58
|
+
decimalPlaces: formatOptions?.decimalPlaces
|
|
59
|
+
};
|
|
60
|
+
return ({ name, value, percent })=>{
|
|
61
|
+
if (typeof value === 'number') {
|
|
62
|
+
return `${_echarts.format.encodeHTML(name)}: ${(0, _components.formatValue)(value, formatOptions)} (${(0, _components.formatValue)(percent, relativeFormatOptions)})`;
|
|
63
|
+
}
|
|
64
|
+
return `${_echarts.format.encodeHTML(name)}: ${_echarts.format.encodeHTML(value.toString())}`;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const getLabelFormatter = (mode, formatOptions)=>{
|
|
68
|
+
if (mode === 'percentage') {
|
|
69
|
+
return percentageLabelFormatter(formatOptions);
|
|
70
|
+
}
|
|
71
|
+
return labelFormatter(formatOptions);
|
|
72
|
+
};
|
|
73
|
+
const labelFormatter = (formatOptions)=>{
|
|
74
|
+
return ({ name, value })=>{
|
|
75
|
+
if (typeof value === 'number') {
|
|
76
|
+
return `${name}:\n${(0, _components.formatValue)(value, formatOptions)}`;
|
|
77
|
+
}
|
|
78
|
+
return `${name}:\n${_echarts.format.encodeHTML(value.toString())}`;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const percentageLabelFormatter = (formatOptions)=>{
|
|
82
|
+
const relativeFormatOptions = {
|
|
83
|
+
unit: 'percent',
|
|
84
|
+
decimalPlaces: formatOptions?.decimalPlaces
|
|
85
|
+
};
|
|
86
|
+
return ({ name, percent })=>{
|
|
87
|
+
return `${name}:\n${(0, _components.formatValue)(percent, relativeFormatOptions)}`;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
class PieChartListLegendMapper {
|
|
91
|
+
mapToLegendItems(pieChartData) {
|
|
92
|
+
return pieChartData.map(({ id, name, itemStyle })=>({
|
|
93
|
+
id: id,
|
|
94
|
+
label: name,
|
|
95
|
+
color: itemStyle.color,
|
|
96
|
+
data: {}
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
mapToLegendColumns() {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
class PieChartTableLegendMapper {
|
|
104
|
+
mapToLegendItems(pieChartData, selectedValues) {
|
|
105
|
+
const relativePieChartData = calculatePercentages(pieChartData);
|
|
106
|
+
const absoluteValueSelected = selectedValues?.includes('abs');
|
|
107
|
+
const relativeValueSelected = selectedValues?.includes('relative');
|
|
108
|
+
return pieChartData.map(({ id, name, itemStyle, value })=>{
|
|
109
|
+
const data = {};
|
|
110
|
+
if (absoluteValueSelected && typeof value === 'number') {
|
|
111
|
+
data['abs'] = value;
|
|
112
|
+
}
|
|
113
|
+
if (relativeValueSelected) {
|
|
114
|
+
const itemPercentageValue = relativePieChartData.find((rpd)=>rpd.id === id)?.value;
|
|
115
|
+
if (typeof itemPercentageValue === 'number') {
|
|
116
|
+
data['relative'] = itemPercentageValue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
id: id,
|
|
121
|
+
label: name,
|
|
122
|
+
color: itemStyle.color,
|
|
123
|
+
data: data
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
mapToLegendColumns(selectedValues, formatOptions) {
|
|
128
|
+
const relativeFormatOptions = {
|
|
129
|
+
unit: 'percent',
|
|
130
|
+
decimalPlaces: formatOptions?.decimalPlaces
|
|
131
|
+
};
|
|
132
|
+
return selectedValues?.toSorted().map((v)=>{
|
|
133
|
+
const comparisonValue = isComparisonValue(v);
|
|
134
|
+
return {
|
|
135
|
+
accessorKey: `data.${v}`,
|
|
136
|
+
header: comparisonValue ? _pluginsystem.comparisonLegends[v].label : v,
|
|
137
|
+
headerDescription: comparisonValue ? _pluginsystem.comparisonLegends[v].description : undefined,
|
|
138
|
+
width: 90,
|
|
139
|
+
align: 'right',
|
|
140
|
+
cellDescription: true,
|
|
141
|
+
enableSorting: true,
|
|
142
|
+
cell: ({ getValue })=>{
|
|
143
|
+
const cellValue = getValue();
|
|
144
|
+
return typeof cellValue === 'number' && formatOptions ? (0, _components.formatValue)(cellValue, v === 'relative' ? relativeFormatOptions : formatOptions) : cellValue;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}) ?? [];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function calculatePercentages(data) {
|
|
151
|
+
const sum = data.reduce((accumulator, { value })=>accumulator + (value ?? 0), 0);
|
|
152
|
+
return data.map((seriesData)=>{
|
|
153
|
+
const percentage = (seriesData.value ?? 0) / sum * 100;
|
|
154
|
+
return {
|
|
155
|
+
...seriesData,
|
|
156
|
+
value: Number(percentage.toFixed(4))
|
|
157
|
+
};
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const comparisonValuesArray = Object.keys(_pluginsystem.comparisonLegends);
|
|
161
|
+
function isComparisonValue(value) {
|
|
162
|
+
return typeof value === 'string' && comparisonValuesArray.includes(value);
|
|
163
|
+
}
|
package/lib/pie-chart-model.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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, LegendSpecOptions, 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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pie-chart-model.d.ts","sourceRoot":"","sources":["../../src/pie-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"pie-chart-model.d.ts","sourceRoot":"","sources":["../../src/pie-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAuB,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACxH,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;AAEhD,MAAM,WAAW,kBAAmB,SAAQ,UAAU,CAAC,eAAe,CAAC;IACrE,IAAI,EAAE,UAAU,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,MAAM,MAAM,0BAA0B,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAE7E,wBAAgB,4BAA4B,IAAI,eAAe,CAS9D"}
|
package/lib/pie-chart-model.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/pie-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/pie-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, LegendSpecOptions, 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';\n\nexport interface BarChartDefinition extends Definition<PieChartOptions> {\n kind: 'PieChart';\n}\n\nexport interface PieChartOptions {\n calculation: CalculationType;\n format?: FormatOptions;\n colorPalette?: string[];\n legend?: LegendSpecOptions;\n mode?: ModeOption;\n radius: number;\n showLabels?: boolean;\n sort?: SortOption;\n}\n\nexport type PieChartOptionsEditorProps = OptionsEditorProps<PieChartOptions>;\n\nexport function createInitialPieChartOptions(): PieChartOptions {\n return {\n calculation: DEFAULT_CALCULATION,\n format: DEFAULT_FORMAT,\n mode: DEFAULT_MODE,\n radius: 50,\n showLabels: false,\n sort: DEFAULT_SORT,\n };\n}\n"],"names":["DEFAULT_CALCULATION","DEFAULT_FORMAT","unit","shortValues","DEFAULT_SORT","DEFAULT_MODE","createInitialPieChartOptions","calculation","format","mode","radius","showLabels","sort"],"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,QAA+C,4BAA4B;AAGxH,OAAO,MAAMC,iBAAgC;IAAEC,MAAM;IAAWC,aAAa;AAAK,EAAE;AACpF,OAAO,MAAMC,eAA2B,OAAO;AAC/C,OAAO,MAAMC,eAA2B,QAAQ;AAmBhD,OAAO,SAASC;IACd,OAAO;QACLC,aAAaP;QACbQ,QAAQP;QACRQ,MAAMJ;QACNK,QAAQ;QACRC,YAAY;QACZC,MAAMR;IACR;AACF"}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
import { SortOption } from '@perses-dev/components';
|
|
1
|
+
import { FormatOptions, LegendItem, ModeOption, SortOption, TableColumnConfig } from '@perses-dev/components';
|
|
2
|
+
import { ComparisonValues, LegendValue } from '@perses-dev/plugin-system';
|
|
2
3
|
import { PieChartData } from './PieChartBase';
|
|
3
|
-
export declare function
|
|
4
|
-
|
|
4
|
+
export declare function sortSeriesData<T extends PieChartData>(data: T[], sortOrder?: SortOption): T[];
|
|
5
|
+
type formatterProps = {
|
|
5
6
|
name: string;
|
|
6
|
-
value: number;
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
value: number | unknown[] | object;
|
|
8
|
+
percent: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const getTooltipFormatter: (formatOptions?: FormatOptions) => ((props: formatterProps) => string);
|
|
11
|
+
export declare const getLabelFormatter: (mode?: ModeOption, formatOptions?: FormatOptions) => ((props: formatterProps) => string);
|
|
12
|
+
export interface PieChartLegendMapper {
|
|
13
|
+
mapToLegendItems: (pieChartData: Array<Required<PieChartData>>, selectedValues?: Array<LegendValue | ComparisonValues>) => LegendItem[];
|
|
14
|
+
mapToLegendColumns: (selectedValues?: Array<LegendValue | ComparisonValues>, formatOptions?: FormatOptions) => Array<TableColumnConfig<LegendItem>>;
|
|
15
|
+
}
|
|
16
|
+
export declare class PieChartListLegendMapper implements PieChartLegendMapper {
|
|
17
|
+
mapToLegendItems(pieChartData: Array<Required<PieChartData>>): LegendItem[];
|
|
18
|
+
mapToLegendColumns(): Array<TableColumnConfig<LegendItem>>;
|
|
19
|
+
}
|
|
20
|
+
export declare class PieChartTableLegendMapper implements PieChartLegendMapper {
|
|
21
|
+
mapToLegendItems(pieChartData: Array<Required<PieChartData>>, selectedValues?: Array<LegendValue | ComparisonValues>): LegendItem[];
|
|
22
|
+
mapToLegendColumns(selectedValues?: Array<LegendValue | ComparisonValues>, formatOptions?: FormatOptions): Array<TableColumnConfig<LegendItem>>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
9
25
|
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,UAAU,EACV,UAAU,EACV,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAqB,gBAAgB,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,wBAAgB,cAAc,CAAC,CAAC,SAAS,YAAY,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,SAAS,GAAE,UAAyB,GAAG,CAAC,EAAE,CAW3G;AAED,KAAK,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAC5F,eAAO,MAAM,mBAAmB,GAAI,gBAAgB,aAAa,KAAG,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAQrG,CAAC;AACF,eAAO,MAAM,iBAAiB,GAC5B,OAAO,UAAU,EACjB,gBAAgB,aAAa,KAC5B,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAKpC,CAAC;AAkBF,MAAM,WAAW,oBAAoB;IACnC,gBAAgB,EAAE,CAChB,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,EAC3C,cAAc,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,gBAAgB,CAAC,KACnD,UAAU,EAAE,CAAC;IAClB,kBAAkB,EAAE,CAClB,cAAc,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,gBAAgB,CAAC,EACtD,aAAa,CAAC,EAAE,aAAa,KAC1B,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC;CAC3C;AAED,qBAAa,wBAAyB,YAAW,oBAAoB;IACnE,gBAAgB,CAAC,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,GAAG,UAAU,EAAE;IAG3E,kBAAkB,IAAI,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;CAG3D;AAED,qBAAa,yBAA0B,YAAW,oBAAoB;IACpE,gBAAgB,CACd,YAAY,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,EAC3C,cAAc,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,gBAAgB,CAAC,GACrD,UAAU,EAAE;IAwBf,kBAAkB,CAChB,cAAc,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,gBAAgB,CAAC,EACtD,aAAa,CAAC,EAAE,aAAa,GAC5B,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;CAuBxC"}
|
package/lib/utils.js
CHANGED
|
@@ -10,17 +10,10 @@
|
|
|
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 { formatValue } from '@perses-dev/components';
|
|
14
|
+
import { format } from 'echarts';
|
|
15
|
+
import { comparisonLegends } from '@perses-dev/plugin-system';
|
|
13
16
|
import { DEFAULT_SORT } from './pie-chart-model';
|
|
14
|
-
export function calculatePercentages(data) {
|
|
15
|
-
const sum = data.reduce((accumulator, { value })=>accumulator + (value ?? 0), 0);
|
|
16
|
-
return data.map((seriesData)=>{
|
|
17
|
-
const percentage = (seriesData.value ?? 0) / sum * 100;
|
|
18
|
-
return {
|
|
19
|
-
...seriesData,
|
|
20
|
-
value: Number(percentage.toFixed(2))
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
17
|
export function sortSeriesData(data, sortOrder = DEFAULT_SORT) {
|
|
25
18
|
return data.sort((a, b)=>{
|
|
26
19
|
// Handle null values - push them to the end regardless of sort order
|
|
@@ -32,5 +25,114 @@ export function sortSeriesData(data, sortOrder = DEFAULT_SORT) {
|
|
|
32
25
|
return sortOrder === 'asc' ? diff : -diff;
|
|
33
26
|
});
|
|
34
27
|
}
|
|
28
|
+
export const getTooltipFormatter = (formatOptions)=>{
|
|
29
|
+
const relativeFormatOptions = {
|
|
30
|
+
unit: 'percent',
|
|
31
|
+
decimalPlaces: formatOptions?.decimalPlaces
|
|
32
|
+
};
|
|
33
|
+
return ({ name, value, percent })=>{
|
|
34
|
+
if (typeof value === 'number') {
|
|
35
|
+
return `${format.encodeHTML(name)}: ${formatValue(value, formatOptions)} (${formatValue(percent, relativeFormatOptions)})`;
|
|
36
|
+
}
|
|
37
|
+
return `${format.encodeHTML(name)}: ${format.encodeHTML(value.toString())}`;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const getLabelFormatter = (mode, formatOptions)=>{
|
|
41
|
+
if (mode === 'percentage') {
|
|
42
|
+
return percentageLabelFormatter(formatOptions);
|
|
43
|
+
}
|
|
44
|
+
return labelFormatter(formatOptions);
|
|
45
|
+
};
|
|
46
|
+
const labelFormatter = (formatOptions)=>{
|
|
47
|
+
return ({ name, value })=>{
|
|
48
|
+
if (typeof value === 'number') {
|
|
49
|
+
return `${name}:\n${formatValue(value, formatOptions)}`;
|
|
50
|
+
}
|
|
51
|
+
return `${name}:\n${format.encodeHTML(value.toString())}`;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const percentageLabelFormatter = (formatOptions)=>{
|
|
55
|
+
const relativeFormatOptions = {
|
|
56
|
+
unit: 'percent',
|
|
57
|
+
decimalPlaces: formatOptions?.decimalPlaces
|
|
58
|
+
};
|
|
59
|
+
return ({ name, percent })=>{
|
|
60
|
+
return `${name}:\n${formatValue(percent, relativeFormatOptions)}`;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export class PieChartListLegendMapper {
|
|
64
|
+
mapToLegendItems(pieChartData) {
|
|
65
|
+
return pieChartData.map(({ id, name, itemStyle })=>({
|
|
66
|
+
id: id,
|
|
67
|
+
label: name,
|
|
68
|
+
color: itemStyle.color,
|
|
69
|
+
data: {}
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
mapToLegendColumns() {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export class PieChartTableLegendMapper {
|
|
77
|
+
mapToLegendItems(pieChartData, selectedValues) {
|
|
78
|
+
const relativePieChartData = calculatePercentages(pieChartData);
|
|
79
|
+
const absoluteValueSelected = selectedValues?.includes('abs');
|
|
80
|
+
const relativeValueSelected = selectedValues?.includes('relative');
|
|
81
|
+
return pieChartData.map(({ id, name, itemStyle, value })=>{
|
|
82
|
+
const data = {};
|
|
83
|
+
if (absoluteValueSelected && typeof value === 'number') {
|
|
84
|
+
data['abs'] = value;
|
|
85
|
+
}
|
|
86
|
+
if (relativeValueSelected) {
|
|
87
|
+
const itemPercentageValue = relativePieChartData.find((rpd)=>rpd.id === id)?.value;
|
|
88
|
+
if (typeof itemPercentageValue === 'number') {
|
|
89
|
+
data['relative'] = itemPercentageValue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
id: id,
|
|
94
|
+
label: name,
|
|
95
|
+
color: itemStyle.color,
|
|
96
|
+
data: data
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
mapToLegendColumns(selectedValues, formatOptions) {
|
|
101
|
+
const relativeFormatOptions = {
|
|
102
|
+
unit: 'percent',
|
|
103
|
+
decimalPlaces: formatOptions?.decimalPlaces
|
|
104
|
+
};
|
|
105
|
+
return selectedValues?.toSorted().map((v)=>{
|
|
106
|
+
const comparisonValue = isComparisonValue(v);
|
|
107
|
+
return {
|
|
108
|
+
accessorKey: `data.${v}`,
|
|
109
|
+
header: comparisonValue ? comparisonLegends[v].label : v,
|
|
110
|
+
headerDescription: comparisonValue ? comparisonLegends[v].description : undefined,
|
|
111
|
+
width: 90,
|
|
112
|
+
align: 'right',
|
|
113
|
+
cellDescription: true,
|
|
114
|
+
enableSorting: true,
|
|
115
|
+
cell: ({ getValue })=>{
|
|
116
|
+
const cellValue = getValue();
|
|
117
|
+
return typeof cellValue === 'number' && formatOptions ? formatValue(cellValue, v === 'relative' ? relativeFormatOptions : formatOptions) : cellValue;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}) ?? [];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function calculatePercentages(data) {
|
|
124
|
+
const sum = data.reduce((accumulator, { value })=>accumulator + (value ?? 0), 0);
|
|
125
|
+
return data.map((seriesData)=>{
|
|
126
|
+
const percentage = (seriesData.value ?? 0) / sum * 100;
|
|
127
|
+
return {
|
|
128
|
+
...seriesData,
|
|
129
|
+
value: Number(percentage.toFixed(4))
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
const comparisonValuesArray = Object.keys(comparisonLegends);
|
|
134
|
+
function isComparisonValue(value) {
|
|
135
|
+
return typeof value === 'string' && comparisonValuesArray.includes(value);
|
|
136
|
+
}
|
|
35
137
|
|
|
36
138
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.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 { SortOption } from '@perses-dev/components';\nimport { DEFAULT_SORT } from './pie-chart-model';\nimport { PieChartData } from './PieChartBase';\n\nexport function calculatePercentages(data: PieChartData[]): Array<{ id?: string; name: string; value: number }> {\n const sum = data.reduce((accumulator, { value }) => accumulator + (value ?? 0), 0);\n return data.map((seriesData) => {\n const percentage = ((seriesData.value ?? 0) / sum) * 100;\n return {\n ...seriesData,\n value: Number(percentage.toFixed(2)),\n };\n });\n}\n\nexport function sortSeriesData(data: PieChartData[], sortOrder: SortOption = DEFAULT_SORT): PieChartData[] {\n return data.sort((a, b) => {\n // Handle null values - push them to the end regardless of sort order\n if (a.value === null && b.value === null) return 0;\n if (a.value === null) return 1;\n if (b.value === null) return -1;\n\n // Sort by value\n const diff = (a.value ?? 0) - (b.value ?? 0);\n return sortOrder === 'asc' ? diff : -diff;\n });\n}\n"],"names":["DEFAULT_SORT","calculatePercentages","data","sum","reduce","accumulator","value","map","seriesData","percentage","Number","toFixed","sortSeriesData","sortOrder","sort","a","b","diff"],"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,SAASA,YAAY,QAAQ,oBAAoB;AAGjD,OAAO,SAASC,qBAAqBC,IAAoB;IACvD,MAAMC,MAAMD,KAAKE,MAAM,CAAC,CAACC,aAAa,EAAEC,KAAK,EAAE,GAAKD,cAAeC,CAAAA,SAAS,CAAA,GAAI;IAChF,OAAOJ,KAAKK,GAAG,CAAC,CAACC;QACf,MAAMC,aAAa,AAAED,CAAAA,WAAWF,KAAK,IAAI,CAAA,IAAKH,MAAO;QACrD,OAAO;YACL,GAAGK,UAAU;YACbF,OAAOI,OAAOD,WAAWE,OAAO,CAAC;QACnC;IACF;AACF;AAEA,OAAO,SAASC,eAAeV,IAAoB,EAAEW,YAAwBb,YAAY;IACvF,OAAOE,KAAKY,IAAI,CAAC,CAACC,GAAGC;QACnB,qEAAqE;QACrE,IAAID,EAAET,KAAK,KAAK,QAAQU,EAAEV,KAAK,KAAK,MAAM,OAAO;QACjD,IAAIS,EAAET,KAAK,KAAK,MAAM,OAAO;QAC7B,IAAIU,EAAEV,KAAK,KAAK,MAAM,OAAO,CAAC;QAE9B,gBAAgB;QAChB,MAAMW,OAAO,AAACF,CAAAA,EAAET,KAAK,IAAI,CAAA,IAAMU,CAAAA,EAAEV,KAAK,IAAI,CAAA;QAC1C,OAAOO,cAAc,QAAQI,OAAO,CAACA;IACvC;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils.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 {\n FormatOptions,\n formatValue,\n LegendItem,\n ModeOption,\n SortOption,\n TableColumnConfig,\n} from '@perses-dev/components';\nimport { format } from 'echarts';\nimport { comparisonLegends, ComparisonValues, LegendValue } from '@perses-dev/plugin-system';\nimport { PieChartData } from './PieChartBase';\nimport { DEFAULT_SORT } from './pie-chart-model';\n\nexport function sortSeriesData<T extends PieChartData>(data: T[], sortOrder: SortOption = DEFAULT_SORT): T[] {\n return data.sort((a, b) => {\n // Handle null values - push them to the end regardless of sort order\n if (a.value === null && b.value === null) return 0;\n if (a.value === null) return 1;\n if (b.value === null) return -1;\n\n // Sort by value\n const diff = (a.value ?? 0) - (b.value ?? 0);\n return sortOrder === 'asc' ? diff : -diff;\n });\n}\n\ntype formatterProps = { name: string; value: number | unknown[] | object; percent: number };\nexport const getTooltipFormatter = (formatOptions?: FormatOptions): ((props: formatterProps) => string) => {\n const relativeFormatOptions = { unit: 'percent', decimalPlaces: formatOptions?.decimalPlaces } as const;\n return ({ name, value, percent }: formatterProps): string => {\n if (typeof value === 'number') {\n return `${format.encodeHTML(name)}: ${formatValue(value, formatOptions)} (${formatValue(percent, relativeFormatOptions)})`;\n }\n return `${format.encodeHTML(name)}: ${format.encodeHTML(value.toString())}`;\n };\n};\nexport const getLabelFormatter = (\n mode?: ModeOption,\n formatOptions?: FormatOptions\n): ((props: formatterProps) => string) => {\n if (mode === 'percentage') {\n return percentageLabelFormatter(formatOptions);\n }\n return labelFormatter(formatOptions);\n};\n\nconst labelFormatter = (formatOptions?: FormatOptions) => {\n return ({ name, value }: formatterProps): string => {\n if (typeof value === 'number') {\n return `${name}:\\n${formatValue(value, formatOptions)}`;\n }\n return `${name}:\\n${format.encodeHTML(value.toString())}`;\n };\n};\n\nconst percentageLabelFormatter = (formatOptions?: FormatOptions) => {\n const relativeFormatOptions = { unit: 'percent', decimalPlaces: formatOptions?.decimalPlaces } as const;\n return ({ name, percent }: formatterProps): string => {\n return `${name}:\\n${formatValue(percent, relativeFormatOptions)}`;\n };\n};\n\nexport interface PieChartLegendMapper {\n mapToLegendItems: (\n pieChartData: Array<Required<PieChartData>>,\n selectedValues?: Array<LegendValue | ComparisonValues>\n ) => LegendItem[];\n mapToLegendColumns: (\n selectedValues?: Array<LegendValue | ComparisonValues>,\n formatOptions?: FormatOptions\n ) => Array<TableColumnConfig<LegendItem>>;\n}\n\nexport class PieChartListLegendMapper implements PieChartLegendMapper {\n mapToLegendItems(pieChartData: Array<Required<PieChartData>>): LegendItem[] {\n return pieChartData.map(({ id, name, itemStyle }) => ({ id: id, label: name, color: itemStyle.color, data: {} }));\n }\n mapToLegendColumns(): Array<TableColumnConfig<LegendItem>> {\n return [];\n }\n}\n\nexport class PieChartTableLegendMapper implements PieChartLegendMapper {\n mapToLegendItems(\n pieChartData: Array<Required<PieChartData>>,\n selectedValues?: Array<LegendValue | ComparisonValues>\n ): LegendItem[] {\n const relativePieChartData = calculatePercentages(pieChartData);\n const absoluteValueSelected = selectedValues?.includes('abs');\n const relativeValueSelected = selectedValues?.includes('relative');\n return pieChartData.map(({ id, name, itemStyle, value }) => {\n const data: { [k in ComparisonValues]?: number } = {};\n if (absoluteValueSelected && typeof value === 'number') {\n data['abs'] = value;\n }\n if (relativeValueSelected) {\n const itemPercentageValue = relativePieChartData.find((rpd) => rpd.id === id)?.value;\n if (typeof itemPercentageValue === 'number') {\n data['relative'] = itemPercentageValue;\n }\n }\n return {\n id: id,\n label: name,\n color: itemStyle.color,\n data: data,\n };\n });\n }\n\n mapToLegendColumns(\n selectedValues?: Array<LegendValue | ComparisonValues>,\n formatOptions?: FormatOptions\n ): Array<TableColumnConfig<LegendItem>> {\n const relativeFormatOptions = { unit: 'percent', decimalPlaces: formatOptions?.decimalPlaces } as const;\n return (\n selectedValues?.toSorted().map((v) => {\n const comparisonValue = isComparisonValue(v);\n return {\n accessorKey: `data.${v}`,\n header: comparisonValue ? comparisonLegends[v].label : v,\n headerDescription: comparisonValue ? comparisonLegends[v].description : undefined,\n width: 90,\n align: 'right',\n cellDescription: true,\n enableSorting: true,\n cell: ({ getValue }): string => {\n const cellValue = getValue();\n return typeof cellValue === 'number' && formatOptions\n ? formatValue(cellValue, v === 'relative' ? relativeFormatOptions : formatOptions)\n : cellValue;\n },\n };\n }) ?? []\n );\n }\n}\n\nfunction calculatePercentages<T extends PieChartData>(data: T[]): T[] {\n const sum = data.reduce((accumulator, { value }) => accumulator + (value ?? 0), 0);\n return data.map((seriesData) => {\n const percentage = ((seriesData.value ?? 0) / sum) * 100;\n return {\n ...seriesData,\n value: Number(percentage.toFixed(4)),\n };\n });\n}\n\nconst comparisonValuesArray = Object.keys(comparisonLegends);\nfunction isComparisonValue(value: string | undefined): value is ComparisonValues {\n return typeof value === 'string' && comparisonValuesArray.includes(value);\n}\n"],"names":["formatValue","format","comparisonLegends","DEFAULT_SORT","sortSeriesData","data","sortOrder","sort","a","b","value","diff","getTooltipFormatter","formatOptions","relativeFormatOptions","unit","decimalPlaces","name","percent","encodeHTML","toString","getLabelFormatter","mode","percentageLabelFormatter","labelFormatter","PieChartListLegendMapper","mapToLegendItems","pieChartData","map","id","itemStyle","label","color","mapToLegendColumns","PieChartTableLegendMapper","selectedValues","relativePieChartData","calculatePercentages","absoluteValueSelected","includes","relativeValueSelected","itemPercentageValue","find","rpd","toSorted","v","comparisonValue","isComparisonValue","accessorKey","header","headerDescription","description","undefined","width","align","cellDescription","enableSorting","cell","getValue","cellValue","sum","reduce","accumulator","seriesData","percentage","Number","toFixed","comparisonValuesArray","Object","keys"],"mappings":"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"}
|