@perses-dev/pie-chart-plugin 0.13.1 → 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/{901.b80f4764.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/{253.4239fca0.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 +1 -2
- package/lib/PieChartBase.d.ts.map +1 -1
- 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 +2 -3
- package/lib/PieChartPanel.js.map +1 -1
- package/lib/cjs/PieChartOptionsEditorSettings.js +1 -2
- package/lib/cjs/PieChartPanel.js +2 -3
- package/lib/cjs/pie-chart-model.js +2 -2
- package/lib/cjs/utils.js +5 -5
- 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 +1 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/mf-manifest.json +56 -46
- package/mf-stats.json +66 -46
- 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.1d9ff92c.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/253.4239fca0.js +0 -24
- 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/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/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/901.b80f4764.js +0 -7
- 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.d3aa3268.js +0 -4
- package/__mf/js/async/lib-router.48213c49.js +0 -2
- package/__mf/js/main.09fdb510.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/PieChartBase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/PieChartBase.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 { use } from 'echarts/core';\nimport { PieChart as EChartsPieChart } from 'echarts/charts';\nimport { DatasetComponent, GridComponent, LegendComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { Box, useTheme } from '@mui/material';\nimport { ReactElement } from 'react';\nimport { EChart, ModeOption, useChartsTheme } from '@perses-dev/components';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/PieChartBase.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 { use } from 'echarts/core';\nimport { PieChart as EChartsPieChart } from 'echarts/charts';\nimport { DatasetComponent, GridComponent, LegendComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { Box, useTheme } from '@mui/material';\nimport { ReactElement } from 'react';\nimport { EChart, FormatOptions, ModeOption, useChartsTheme } from '@perses-dev/components';\nimport { getLabelFormatter, getTooltipFormatter } from './utils';\n\nuse([\n EChartsPieChart,\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n LegendComponent,\n CanvasRenderer,\n]);\nexport interface PieChartData {\n id?: string;\n name: string;\n value: number | null;\n itemStyle?: {\n color: string;\n };\n}\n\nexport interface PieChartBaseProps {\n width: number;\n height: number;\n data: PieChartData[] | null;\n mode?: ModeOption;\n showLabels?: boolean;\n formatOptions?: FormatOptions;\n}\n\nexport function PieChartBase(props: PieChartBaseProps): ReactElement {\n const { width, height, data, mode, formatOptions, showLabels } = props;\n const chartsTheme = useChartsTheme();\n const muiTheme = useTheme();\n\n const option = {\n tooltip: {\n trigger: 'item',\n formatter: getTooltipFormatter(formatOptions),\n appendTo: document.body,\n confine: false,\n },\n series: [\n {\n type: 'pie',\n radius: '90%',\n label: {\n show: Boolean(showLabels),\n position: 'inner',\n fontSize: 14,\n formatter: getLabelFormatter(mode, formatOptions),\n overflow: 'truncate',\n fontWeight: 'bold',\n },\n center: ['50%', '50%'],\n data: data,\n emphasis: {\n itemStyle: {\n shadowBlur: 10,\n shadowOffsetX: 0,\n shadowColor: 'rgba(0, 0, 0, 0.5)',\n },\n },\n itemStyle: {\n borderRadius: 5,\n borderColor: muiTheme.palette.background.default,\n borderWidth: 2,\n },\n },\n ],\n };\n\n return (\n <Box\n style={{\n width: width,\n height: height,\n }}\n sx={{ overflow: 'auto' }}\n >\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n />\n </Box>\n );\n}\n"],"names":["use","PieChart","EChartsPieChart","DatasetComponent","GridComponent","LegendComponent","TitleComponent","TooltipComponent","CanvasRenderer","Box","useTheme","EChart","useChartsTheme","getLabelFormatter","getTooltipFormatter","PieChartBase","props","width","height","data","mode","formatOptions","showLabels","chartsTheme","muiTheme","option","tooltip","trigger","formatter","appendTo","document","body","confine","series","type","radius","label","show","Boolean","position","fontSize","overflow","fontWeight","center","emphasis","itemStyle","shadowBlur","shadowOffsetX","shadowColor","borderRadius","borderColor","palette","background","default","borderWidth","style","sx","theme","echartsTheme"],"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,GAAG,QAAQ,eAAe;AACnC,SAASC,YAAYC,eAAe,QAAQ,iBAAiB;AAC7D,SAASC,gBAAgB,EAAEC,aAAa,EAAEC,eAAe,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,qBAAqB;AACxH,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,GAAG,EAAEC,QAAQ,QAAQ,gBAAgB;AAE9C,SAASC,MAAM,EAA6BC,cAAc,QAAQ,yBAAyB;AAC3F,SAASC,iBAAiB,EAAEC,mBAAmB,QAAQ,UAAU;AAEjEd,IAAI;IACFE;IACAE;IACAD;IACAG;IACAC;IACAF;IACAG;CACD;AAmBD,OAAO,SAASO,aAAaC,KAAwB;IACnD,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,aAAa,EAAEC,UAAU,EAAE,GAAGN;IACjE,MAAMO,cAAcX;IACpB,MAAMY,WAAWd;IAEjB,MAAMe,SAAS;QACbC,SAAS;YACPC,SAAS;YACTC,WAAWd,oBAAoBO;YAC/BQ,UAAUC,SAASC,IAAI;YACvBC,SAAS;QACX;QACAC,QAAQ;YACN;gBACEC,MAAM;gBACNC,QAAQ;gBACRC,OAAO;oBACLC,MAAMC,QAAQhB;oBACdiB,UAAU;oBACVC,UAAU;oBACVZ,WAAWf,kBAAkBO,MAAMC;oBACnCoB,UAAU;oBACVC,YAAY;gBACd;gBACAC,QAAQ;oBAAC;oBAAO;iBAAM;gBACtBxB,MAAMA;gBACNyB,UAAU;oBACRC,WAAW;wBACTC,YAAY;wBACZC,eAAe;wBACfC,aAAa;oBACf;gBACF;gBACAH,WAAW;oBACTI,cAAc;oBACdC,aAAa1B,SAAS2B,OAAO,CAACC,UAAU,CAACC,OAAO;oBAChDC,aAAa;gBACf;YACF;SACD;IACH;IAEA,qBACE,KAAC7C;QACC8C,OAAO;YACLtC,OAAOA;YACPC,QAAQA;QACV;QACAsC,IAAI;YAAEf,UAAU;QAAO;kBAEvB,cAAA,KAAC9B;YACC6C,IAAI;gBACFvC,OAAO;gBACPC,QAAQ;YACV;YACAO,QAAQA;YACRgC,OAAOlC,YAAYmC,YAAY;;;AAIvC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PieChartOptionsEditorSettings.d.ts","sourceRoot":"","sources":["../../src/PieChartOptionsEditorSettings.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PieChartOptionsEditorSettings.d.ts","sourceRoot":"","sources":["../../src/PieChartOptionsEditorSettings.tsx"],"names":[],"mappings":"AAmDA,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAmB,0BAA0B,EAAkB,MAAM,mBAAmB,CAAC;AAEhG,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,0BAA0B,GAAG,YAAY,CA+K7F"}
|
|
@@ -14,8 +14,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
import merge from 'lodash/merge';
|
|
15
15
|
import { CalculationSelector, LegendOptionsEditor } from '@perses-dev/plugin-system';
|
|
16
16
|
import { produce } from 'immer';
|
|
17
|
-
import { FormatControls, OptionsColorPicker, OptionsEditorGroup, OptionsEditorGrid, OptionsEditorColumn, SortSelector, ModeSelector, OptionsEditorControl, useChartsTheme } from '@perses-dev/components';
|
|
18
|
-
import { isPercentUnit } from '@perses-dev/core';
|
|
17
|
+
import { FormatControls, OptionsColorPicker, OptionsEditorGroup, OptionsEditorGrid, OptionsEditorColumn, SortSelector, ModeSelector, OptionsEditorControl, useChartsTheme, isPercentUnit } from '@perses-dev/components';
|
|
19
18
|
import { Button, FormControl, InputLabel, MenuItem, Select, Stack, Switch, Typography } from '@mui/material';
|
|
20
19
|
import { useMemo } from 'react';
|
|
21
20
|
import { DEFAULT_FORMAT } from './pie-chart-model';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/PieChartOptionsEditorSettings.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 merge from 'lodash/merge';\nimport {\n CalculationSelector,\n CalculationSelectorProps,\n LegendOptionsEditor,\n LegendOptionsEditorProps,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport {\n FormatControls,\n FormatControlsProps,\n OptionsColorPicker,\n OptionsEditorGroup,\n OptionsEditorGrid,\n OptionsEditorColumn,\n SortSelector,\n SortSelectorProps,\n ModeSelector,\n ModeSelectorProps,\n ModeOption,\n SortOption,\n OptionsEditorControl,\n useChartsTheme,\n} from '@perses-dev/components';\nimport { CalculationType, isPercentUnit, FormatOptions } from '@perses-dev/core';\nimport {\n Button,\n FormControl,\n InputLabel,\n MenuItem,\n Select,\n Stack,\n Switch,\n SwitchProps,\n Typography,\n} from '@mui/material';\nimport { ReactElement, useMemo } from 'react';\nimport { PieChartOptions, PieChartOptionsEditorProps, DEFAULT_FORMAT } from './pie-chart-model';\n\nexport function PieChartOptionsEditorSettings(props: PieChartOptionsEditorProps): ReactElement {\n const { onChange, value } = props;\n\n const handleCalculationChange: CalculationSelectorProps['onChange'] = (newCalculation: CalculationType) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.calculation = newCalculation;\n })\n );\n };\n\n const handleLegendChange: LegendOptionsEditorProps['onChange'] = (newLegend) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.legend = newLegend;\n })\n );\n };\n\n const handleUnitChange: FormatControlsProps['onChange'] = (newFormat: FormatOptions) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.format = newFormat;\n })\n );\n };\n\n const handleSortChange: SortSelectorProps['onChange'] = (newSort: SortOption) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.sort = newSort;\n })\n );\n };\n\n const handleModeChange: ModeSelectorProps['onChange'] = (newMode: ModeOption) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.mode = newMode;\n })\n );\n };\n\n const handleShowLabelsChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.showLabels = checked;\n })\n );\n };\n\n const chartsTheme = useChartsTheme();\n const themePalette = chartsTheme.echartsTheme.color;\n\n const colorPalette: string[] | undefined = useMemo(() => {\n return value.colorPalette || undefined;\n }, [value.colorPalette]);\n\n const handleColorChange = (color?: string[]): void => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n if (Array.isArray(color)) {\n draft.colorPalette = color;\n } else if (typeof color === 'string') {\n draft.colorPalette = [color];\n } else {\n draft.colorPalette = undefined;\n }\n })\n );\n };\n\n // ensures decimalPlaces defaults to correct value\n const format = merge({}, DEFAULT_FORMAT, value.format);\n\n type ColorScheme = 'default' | 'theme' | 'gradient';\n\n const colorScheme: ColorScheme = useMemo(() => {\n return Array.isArray(colorPalette) ? (colorPalette.length === 1 ? 'gradient' : 'theme') : 'default';\n }, [colorPalette]);\n\n const handleColorSchemeChange = (scheme: ColorScheme): void => {\n if (scheme === 'theme') {\n handleColorChange(themePalette as string[]);\n } else if (scheme === 'default') {\n handleColorChange();\n } else {\n // gradient: keep existing single color if present (user-chosen via OptionsColorPicker)\n if (Array.isArray(colorPalette) && colorPalette.length === 1) {\n return;\n }\n // initialize with a sensible default so the color picker shows a color\n handleColorChange(['#ff0000']);\n }\n };\n\n const colorHelpText = useMemo(() => {\n if (colorPalette === undefined) {\n return 'Colors will be automatically assigned using metrics name hash.';\n }\n if (Array.isArray(colorPalette) && colorPalette.length > 1) {\n return 'Colors will be automatically assigned using the current theme color palette.';\n }\n if (Array.isArray(colorPalette) && colorPalette.length === 1) {\n return 'All series will use a gradient based on the selected color.';\n }\n return undefined;\n }, [colorPalette]);\n\n return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\n <LegendOptionsEditor calculation=\"comparison\" value={value.legend} onChange={handleLegendChange} />\n <OptionsEditorGroup title=\"Misc\">\n <OptionsEditorControl\n label=\"Show Labels\"\n control={<Switch checked={Boolean(value.showLabels)} onChange={handleShowLabelsChange} />}\n />\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=\"Colors\">\n <Stack spacing={2}>\n <Stack direction=\"row\" spacing={2} alignItems=\"center\">\n <FormControl size=\"small\" sx={{ minWidth: 150 }}>\n <InputLabel>Color Scheme</InputLabel>\n <Select\n value={colorScheme}\n label=\"Color Scheme\"\n onChange={(e) => handleColorSchemeChange(e.target.value as ColorScheme)}\n >\n <MenuItem value=\"default\">Default</MenuItem>\n <MenuItem value=\"theme\">Theme</MenuItem>\n <MenuItem value=\"gradient\">Gradient</MenuItem>\n </Select>\n </FormControl>\n {Array.isArray(colorPalette) && colorPalette.length === 1 && (\n <OptionsColorPicker\n label=\"Color\"\n color={colorPalette?.[0] ?? (themePalette as string[])[0] ?? '#ff0000'}\n onColorChange={(c: string) => handleColorChange([c])}\n />\n )}\n </Stack>\n {colorHelpText && (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {colorHelpText}\n </Typography>\n )}\n </Stack>\n </OptionsEditorGroup>\n <OptionsEditorGroup title=\"Reset Settings\">\n <Button\n variant=\"outlined\"\n color=\"secondary\"\n onClick={() => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n // reset button removes all optional panel options\n draft.legend = undefined;\n draft.colorPalette = undefined;\n })\n );\n }}\n >\n Reset To Defaults\n </Button>\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n </OptionsEditorGrid>\n );\n}\n"],"names":["merge","CalculationSelector","LegendOptionsEditor","produce","FormatControls","OptionsColorPicker","OptionsEditorGroup","OptionsEditorGrid","OptionsEditorColumn","SortSelector","ModeSelector","OptionsEditorControl","useChartsTheme","isPercentUnit","Button","FormControl","InputLabel","MenuItem","Select","Stack","Switch","Typography","useMemo","DEFAULT_FORMAT","PieChartOptionsEditorSettings","props","onChange","value","handleCalculationChange","newCalculation","draft","calculation","handleLegendChange","newLegend","legend","handleUnitChange","newFormat","format","handleSortChange","newSort","sort","handleModeChange","newMode","mode","handleShowLabelsChange","_","checked","showLabels","chartsTheme","themePalette","echartsTheme","color","colorPalette","undefined","handleColorChange","Array","isArray","colorScheme","length","handleColorSchemeChange","scheme","colorHelpText","title","label","control","Boolean","disabled","disablePercentageMode","spacing","direction","alignItems","size","sx","minWidth","e","target","onColorChange","c","variant","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,OAAOA,WAAW,eAAe;AACjC,SACEC,mBAAmB,EAEnBC,mBAAmB,QAEd,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SACEC,cAAc,EAEdC,kBAAkB,EAClBC,kBAAkB,EAClBC,iBAAiB,EACjBC,mBAAmB,EACnBC,YAAY,EAEZC,YAAY,EAIZC,oBAAoB,EACpBC,cAAc,QACT,yBAAyB;AAChC,SAA0BC,aAAa,QAAuB,mBAAmB;AACjF,SACEC,MAAM,EACNC,WAAW,EACXC,UAAU,EACVC,QAAQ,EACRC,MAAM,EACNC,KAAK,EACLC,MAAM,EAENC,UAAU,QACL,gBAAgB;AACvB,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAAsDC,cAAc,QAAQ,oBAAoB;AAEhG,OAAO,SAASC,8BAA8BC,KAAiC;IAC7E,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,MAAMG,0BAAgE,CAACC;QACrEH,SACEvB,QAAQwB,OAAO,CAACG;YACdA,MAAMC,WAAW,GAAGF;QACtB;IAEJ;IAEA,MAAMG,qBAA2D,CAACC;QAChEP,SACEvB,QAAQwB,OAAO,CAACG;YACdA,MAAMI,MAAM,GAAGD;QACjB;IAEJ;IAEA,MAAME,mBAAoD,CAACC;QACzDV,SACEvB,QAAQwB,OAAO,CAACG;YACdA,MAAMO,MAAM,GAAGD;QACjB;IAEJ;IAEA,MAAME,mBAAkD,CAACC;QACvDb,SACEvB,QAAQwB,OAAO,CAACG;YACdA,MAAMU,IAAI,GAAG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AASU,OAAM;sEAAW;;;;;;wCAG9B4B,MAAMC,OAAO,CAACJ,iBAAiBA,aAAaM,MAAM,KAAK,mBACtD,KAACrD;4CACC0D,OAAM;4CACNZ,OAAOC,cAAc,CAAC,EAAE,IAAI,AAACH,YAAyB,CAAC,EAAE,IAAI;4CAC7D2B,eAAe,CAACC,IAAcvB,kBAAkB;oDAACuB;iDAAE;;;;gCAIxDhB,+BACC,KAACxC;oCAAWyD,SAAQ;oCAAQ3B,OAAM;8CAC/BU;;;;;kCAKT,KAACvD;wBAAmBwD,OAAM;kCACxB,cAAA,KAAChD;4BACCgE,SAAQ;4BACR3B,OAAM;4BACN4B,SAAS;gCACPrD,SACEvB,QAAQwB,OAAO,CAACG;oCACd,kDAAkD;oCAClDA,MAAMI,MAAM,GAAGmB;oCACfvB,MAAMsB,YAAY,GAAGC;gCACvB;4BAEJ;sCACD;;;;;;;AAOX"}
|
|
1
|
+
{"version":3,"sources":["../../src/PieChartOptionsEditorSettings.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 merge from 'lodash/merge';\nimport {\n CalculationSelector,\n CalculationSelectorProps,\n CalculationType,\n LegendOptionsEditor,\n LegendOptionsEditorProps,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport {\n FormatControls,\n FormatControlsProps,\n OptionsColorPicker,\n OptionsEditorGroup,\n OptionsEditorGrid,\n OptionsEditorColumn,\n SortSelector,\n SortSelectorProps,\n ModeSelector,\n ModeSelectorProps,\n ModeOption,\n SortOption,\n OptionsEditorControl,\n useChartsTheme,\n FormatOptions,\n isPercentUnit,\n} from '@perses-dev/components';\nimport {\n Button,\n FormControl,\n InputLabel,\n MenuItem,\n Select,\n Stack,\n Switch,\n SwitchProps,\n Typography,\n} from '@mui/material';\nimport { ReactElement, useMemo } from 'react';\nimport { PieChartOptions, PieChartOptionsEditorProps, DEFAULT_FORMAT } from './pie-chart-model';\n\nexport function PieChartOptionsEditorSettings(props: PieChartOptionsEditorProps): ReactElement {\n const { onChange, value } = props;\n\n const handleCalculationChange: CalculationSelectorProps['onChange'] = (newCalculation: CalculationType) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.calculation = newCalculation;\n })\n );\n };\n\n const handleLegendChange: LegendOptionsEditorProps['onChange'] = (newLegend) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.legend = newLegend;\n })\n );\n };\n\n const handleUnitChange: FormatControlsProps['onChange'] = (newFormat: FormatOptions) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.format = newFormat;\n })\n );\n };\n\n const handleSortChange: SortSelectorProps['onChange'] = (newSort: SortOption) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.sort = newSort;\n })\n );\n };\n\n const handleModeChange: ModeSelectorProps['onChange'] = (newMode: ModeOption) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.mode = newMode;\n })\n );\n };\n\n const handleShowLabelsChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n draft.showLabels = checked;\n })\n );\n };\n\n const chartsTheme = useChartsTheme();\n const themePalette = chartsTheme.echartsTheme.color;\n\n const colorPalette: string[] | undefined = useMemo(() => {\n return value.colorPalette || undefined;\n }, [value.colorPalette]);\n\n const handleColorChange = (color?: string[]): void => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n if (Array.isArray(color)) {\n draft.colorPalette = color;\n } else if (typeof color === 'string') {\n draft.colorPalette = [color];\n } else {\n draft.colorPalette = undefined;\n }\n })\n );\n };\n\n // ensures decimalPlaces defaults to correct value\n const format = merge({}, DEFAULT_FORMAT, value.format);\n\n type ColorScheme = 'default' | 'theme' | 'gradient';\n\n const colorScheme: ColorScheme = useMemo(() => {\n return Array.isArray(colorPalette) ? (colorPalette.length === 1 ? 'gradient' : 'theme') : 'default';\n }, [colorPalette]);\n\n const handleColorSchemeChange = (scheme: ColorScheme): void => {\n if (scheme === 'theme') {\n handleColorChange(themePalette as string[]);\n } else if (scheme === 'default') {\n handleColorChange();\n } else {\n // gradient: keep existing single color if present (user-chosen via OptionsColorPicker)\n if (Array.isArray(colorPalette) && colorPalette.length === 1) {\n return;\n }\n // initialize with a sensible default so the color picker shows a color\n handleColorChange(['#ff0000']);\n }\n };\n\n const colorHelpText = useMemo(() => {\n if (colorPalette === undefined) {\n return 'Colors will be automatically assigned using metrics name hash.';\n }\n if (Array.isArray(colorPalette) && colorPalette.length > 1) {\n return 'Colors will be automatically assigned using the current theme color palette.';\n }\n if (Array.isArray(colorPalette) && colorPalette.length === 1) {\n return 'All series will use a gradient based on the selected color.';\n }\n return undefined;\n }, [colorPalette]);\n\n return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\n <LegendOptionsEditor calculation=\"comparison\" value={value.legend} onChange={handleLegendChange} />\n <OptionsEditorGroup title=\"Misc\">\n <OptionsEditorControl\n label=\"Show Labels\"\n control={<Switch checked={Boolean(value.showLabels)} onChange={handleShowLabelsChange} />}\n />\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=\"Colors\">\n <Stack spacing={2}>\n <Stack direction=\"row\" spacing={2} alignItems=\"center\">\n <FormControl size=\"small\" sx={{ minWidth: 150 }}>\n <InputLabel>Color Scheme</InputLabel>\n <Select\n value={colorScheme}\n label=\"Color Scheme\"\n onChange={(e) => handleColorSchemeChange(e.target.value as ColorScheme)}\n >\n <MenuItem value=\"default\">Default</MenuItem>\n <MenuItem value=\"theme\">Theme</MenuItem>\n <MenuItem value=\"gradient\">Gradient</MenuItem>\n </Select>\n </FormControl>\n {Array.isArray(colorPalette) && colorPalette.length === 1 && (\n <OptionsColorPicker\n label=\"Color\"\n color={colorPalette?.[0] ?? (themePalette as string[])[0] ?? '#ff0000'}\n onColorChange={(c: string) => handleColorChange([c])}\n />\n )}\n </Stack>\n {colorHelpText && (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {colorHelpText}\n </Typography>\n )}\n </Stack>\n </OptionsEditorGroup>\n <OptionsEditorGroup title=\"Reset Settings\">\n <Button\n variant=\"outlined\"\n color=\"secondary\"\n onClick={() => {\n onChange(\n produce(value, (draft: PieChartOptions) => {\n // reset button removes all optional panel options\n draft.legend = undefined;\n draft.colorPalette = undefined;\n })\n );\n }}\n >\n Reset To Defaults\n </Button>\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n </OptionsEditorGrid>\n );\n}\n"],"names":["merge","CalculationSelector","LegendOptionsEditor","produce","FormatControls","OptionsColorPicker","OptionsEditorGroup","OptionsEditorGrid","OptionsEditorColumn","SortSelector","ModeSelector","OptionsEditorControl","useChartsTheme","isPercentUnit","Button","FormControl","InputLabel","MenuItem","Select","Stack","Switch","Typography","useMemo","DEFAULT_FORMAT","PieChartOptionsEditorSettings","props","onChange","value","handleCalculationChange","newCalculation","draft","calculation","handleLegendChange","newLegend","legend","handleUnitChange","newFormat","format","handleSortChange","newSort","sort","handleModeChange","newMode","mode","handleShowLabelsChange","_","checked","showLabels","chartsTheme","themePalette","echartsTheme","color","colorPalette","undefined","handleColorChange","Array","isArray","colorScheme","length","handleColorSchemeChange","scheme","colorHelpText","title","label","control","Boolean","disabled","disablePercentageMode","spacing","direction","alignItems","size","sx","minWidth","e","target","onColorChange","c","variant","onClick"],"mappings":";AAAA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OAAOC,cAAc,CAAC,EAAE,IAAI,AAACH,YAAyB,CAAC,EAAE,IAAI;4CAC7D2B,eAAe,CAACC,IAAcvB,kBAAkB;oDAACuB;iDAAE;;;;gCAIxDhB,+BACC,KAACxC;oCAAWyD,SAAQ;oCAAQ3B,OAAM;8CAC/BU;;;;;kCAKT,KAACvD;wBAAmBwD,OAAM;kCACxB,cAAA,KAAChD;4BACCgE,SAAQ;4BACR3B,OAAM;4BACN4B,SAAS;gCACPrD,SACEvB,QAAQwB,OAAO,CAACG;oCACd,kDAAkD;oCAClDA,MAAMI,MAAM,GAAGmB;oCACfvB,MAAMsB,YAAY,GAAGC;gCACvB;4BAEJ;sCACD;;;;;;;AAOX"}
|
package/lib/PieChartPanel.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TimeSeriesData } from '@perses-dev/core';
|
|
2
1
|
import { PanelProps } from '@perses-dev/plugin-system';
|
|
3
2
|
import { ReactElement } from 'react';
|
|
3
|
+
import { TimeSeriesData } from '@perses-dev/spec';
|
|
4
4
|
import { PieChartOptions } from './pie-chart-model';
|
|
5
5
|
export type PieChartPanelProps = PanelProps<PieChartOptions, TimeSeriesData>;
|
|
6
6
|
export declare function PieChartPanel(props: PieChartPanelProps): ReactElement | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PieChartPanel.d.ts","sourceRoot":"","sources":["../../src/PieChartPanel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PieChartPanel.d.ts","sourceRoot":"","sources":["../../src/PieChartPanel.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAoC,UAAU,EAAsB,MAAM,2BAA2B,CAAC;AAE7G,OAAO,EAAE,YAAY,EAA6B,MAAM,OAAO,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAKpD,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC;AAE7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,YAAY,GAAG,IAAI,CA4H5E"}
|
package/lib/PieChartPanel.js
CHANGED
|
@@ -12,9 +12,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
import { Box } from '@mui/material';
|
|
15
|
-
import { ContentWithLegend, useChartsTheme, useId } from '@perses-dev/components';
|
|
16
|
-
import { CalculationsMap,
|
|
17
|
-
import { validateLegendSpec } from '@perses-dev/plugin-system';
|
|
15
|
+
import { ContentWithLegend, DEFAULT_LEGEND, useChartsTheme, useId } from '@perses-dev/components';
|
|
16
|
+
import { CalculationsMap, validateLegendSpec } from '@perses-dev/plugin-system';
|
|
18
17
|
import merge from 'lodash/merge';
|
|
19
18
|
import { useMemo, useRef, useState } from 'react';
|
|
20
19
|
import { PieChartListLegendMapper, PieChartTableLegendMapper, sortSeriesData } from './utils';
|
package/lib/PieChartPanel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/PieChartPanel.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 { Box } from '@mui/material';\nimport {\n ChartInstance,\n ContentWithLegend,\n LegendProps,\n SelectedLegendItemState,\n useChartsTheme,\n useId,\n} from '@perses-dev/components';\nimport { CalculationsMap, CalculationType, DEFAULT_LEGEND, TimeSeriesData } from '@perses-dev/core';\nimport { PanelProps, validateLegendSpec } from '@perses-dev/plugin-system';\nimport merge from 'lodash/merge';\nimport { ReactElement, useMemo, useRef, useState } from 'react';\nimport { PieChartOptions } from './pie-chart-model';\nimport { PieChartLegendMapper, PieChartListLegendMapper, PieChartTableLegendMapper, sortSeriesData } from './utils';\nimport { getSeriesColor } from './colors';\nimport { PieChartBase, PieChartData } from './PieChartBase';\n\nexport type PieChartPanelProps = PanelProps<PieChartOptions, TimeSeriesData>;\n\nexport function PieChartPanel(props: PieChartPanelProps): ReactElement | null {\n const {\n spec: { calculation, sort, mode, format: formatOptions, legend: pieChartLegend, colorPalette: colorPalette },\n contentDimensions,\n queryResults,\n } = props;\n const chartsTheme = useChartsTheme();\n const chartId = useId('time-series-panel');\n const seriesNames = queryResults.flatMap((result) => result?.data.series?.map((series) => series.name) || []);\n\n // Memoize the color list so it only regenerates when color/palette/series count changes\n const colorList = useMemo(() => {\n return getSeriesColor(seriesNames, colorPalette);\n }, [colorPalette, seriesNames]);\n\n const pieChartData = useMemo((): Array<Required<PieChartData>> => {\n const calculate = CalculationsMap[calculation as CalculationType];\n const pieChartData: Array<Required<PieChartData>> = [];\n queryResults.forEach((result, queryIndex) => {\n const series = result?.data.series ?? [];\n\n series.forEach((seriesData, seriesIndex) => {\n const seriesId = `${chartId}${seriesData.name}${seriesIndex}${queryIndex}`;\n const seriesColor = colorList[queryIndex * series.length + seriesIndex] ?? '#ff0000';\n\n const seriesItem = {\n id: seriesId,\n value: calculate(seriesData.values) ?? null,\n name: seriesData.formattedName ?? '',\n itemStyle: {\n color: seriesColor,\n },\n };\n\n pieChartData.push(seriesItem);\n });\n });\n\n return sortSeriesData(pieChartData, sort);\n }, [calculation, chartId, colorList, queryResults, sort]);\n\n const { legendItems, legendColumns } = useMemo(() => {\n const pieChartLegendMapper: PieChartLegendMapper =\n pieChartLegend?.mode === 'table' ? new PieChartTableLegendMapper() : new PieChartListLegendMapper();\n const values = pieChartLegend?.values;\n const legendItems = pieChartLegendMapper.mapToLegendItems(pieChartData, values);\n const legendColumns = pieChartLegendMapper.mapToLegendColumns(values, formatOptions);\n return {\n legendItems,\n legendColumns,\n };\n }, [formatOptions, pieChartData, pieChartLegend?.mode, pieChartLegend?.values]);\n\n const contentPadding = chartsTheme.container.padding.default;\n const adjustedContentDimensions: typeof contentDimensions = contentDimensions\n ? {\n width: contentDimensions.width - contentPadding * 2,\n height: contentDimensions.height - contentPadding * 2,\n }\n : undefined;\n\n const legend = useMemo(() => {\n return props.spec.legend && validateLegendSpec(props.spec.legend)\n ? merge({}, DEFAULT_LEGEND, props.spec.legend)\n : undefined;\n }, [props.spec.legend]);\n\n const [selectedLegendItems, setSelectedLegendItems] = useState<SelectedLegendItemState>('ALL');\n\n const [legendSorting, setLegendSorting] = useState<NonNullable<LegendProps['tableProps']>['sorting']>();\n\n const chartRef = useRef<ChartInstance>(null);\n\n // ensures there are fallbacks for unset properties since most\n // users should not need to customize visual display\n\n if (!contentDimensions) return null;\n\n return (\n <Box sx={{ padding: `${contentPadding}px` }}>\n <ContentWithLegend\n width={adjustedContentDimensions?.width ?? 400}\n height={adjustedContentDimensions?.height ?? 1000}\n // Making this small enough that the medium size doesn't get\n // responsive-handling-ed away when in the panel options editor.\n minChildrenHeight={50}\n legendSize={legend?.size}\n legendProps={\n legend && {\n options: legend,\n data: legendItems,\n selectedItems: selectedLegendItems,\n onSelectedItemsChange: setSelectedLegendItems,\n tableProps: {\n columns: legendColumns,\n sorting: legendSorting,\n onSortingChange: setLegendSorting,\n },\n onItemMouseOver: (e, { id }): void => {\n chartRef.current?.highlightSeries({ name: id });\n },\n onItemMouseOut: (): void => {\n chartRef.current?.clearHighlightedSeries();\n },\n }\n }\n >\n {({ height, width }) => {\n return (\n <Box style={{ height, width }}>\n <PieChartBase\n data={pieChartData}\n width={width}\n height={height}\n mode={mode}\n formatOptions={formatOptions}\n showLabels={Boolean(props.spec.showLabels)}\n />\n </Box>\n );\n }}\n </ContentWithLegend>\n </Box>\n );\n}\n"],"names":["Box","ContentWithLegend","useChartsTheme","useId","CalculationsMap","DEFAULT_LEGEND","validateLegendSpec","merge","useMemo","useRef","useState","PieChartListLegendMapper","PieChartTableLegendMapper","sortSeriesData","getSeriesColor","PieChartBase","PieChartPanel","props","spec","calculation","sort","mode","format","formatOptions","legend","pieChartLegend","colorPalette","contentDimensions","queryResults","chartsTheme","chartId","seriesNames","flatMap","result","data","series","map","name","colorList","pieChartData","calculate","forEach","queryIndex","seriesData","seriesIndex","seriesId","seriesColor","length","seriesItem","id","value","values","formattedName","itemStyle","color","push","legendItems","legendColumns","pieChartLegendMapper","mapToLegendItems","mapToLegendColumns","contentPadding","container","padding","default","adjustedContentDimensions","width","height","undefined","selectedLegendItems","setSelectedLegendItems","legendSorting","setLegendSorting","chartRef","sx","minChildrenHeight","legendSize","size","legendProps","options","selectedItems","onSelectedItemsChange","tableProps","columns","sorting","onSortingChange","onItemMouseOver","e","current","highlightSeries","onItemMouseOut","clearHighlightedSeries","style","showLabels","Boolean"],"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,GAAG,QAAQ,gBAAgB;AACpC,SAEEC,iBAAiB,EAGjBC,cAAc,EACdC,KAAK,QACA,yBAAyB;AAChC,SAASC,eAAe,EAAmBC,cAAc,QAAwB,mBAAmB;AACpG,SAAqBC,kBAAkB,QAAQ,4BAA4B;AAC3E,OAAOC,WAAW,eAAe;AACjC,SAAuBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAEhE,SAA+BC,wBAAwB,EAAEC,yBAAyB,EAAEC,cAAc,QAAQ,UAAU;AACpH,SAASC,cAAc,QAAQ,WAAW;AAC1C,SAASC,YAAY,QAAsB,iBAAiB;AAI5D,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EACJC,MAAM,EA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;gBACnB;gBACAc,iBAAiB,CAACC,GAAG,EAAEtC,EAAE,EAAE;oBACzBwB,SAASe,OAAO,EAAEC,gBAAgB;wBAAEpD,MAAMY;oBAAG;gBAC/C;gBACAyC,gBAAgB;oBACdjB,SAASe,OAAO,EAAEG;gBACpB;YACF;sBAGD,CAAC,EAAExB,MAAM,EAAED,KAAK,EAAE;gBACjB,qBACE,KAAClE;oBAAI4F,OAAO;wBAAEzB;wBAAQD;oBAAM;8BAC1B,cAAA,KAACnD;wBACCmB,MAAMK;wBACN2B,OAAOA;wBACPC,QAAQA;wBACR9C,MAAMA;wBACNE,eAAeA;wBACfsE,YAAYC,QAAQ7E,MAAMC,IAAI,CAAC2E,UAAU;;;YAIjD;;;AAIR"}
|
|
1
|
+
{"version":3,"sources":["../../src/PieChartPanel.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 { Box } from '@mui/material';\nimport {\n ChartInstance,\n ContentWithLegend,\n DEFAULT_LEGEND,\n LegendProps,\n SelectedLegendItemState,\n useChartsTheme,\n useId,\n} from '@perses-dev/components';\nimport { CalculationsMap, CalculationType, PanelProps, validateLegendSpec } from '@perses-dev/plugin-system';\nimport merge from 'lodash/merge';\nimport { ReactElement, useMemo, useRef, useState } from 'react';\nimport { TimeSeriesData } from '@perses-dev/spec';\nimport { PieChartOptions } from './pie-chart-model';\nimport { PieChartLegendMapper, PieChartListLegendMapper, PieChartTableLegendMapper, sortSeriesData } from './utils';\nimport { getSeriesColor } from './colors';\nimport { PieChartBase, PieChartData } from './PieChartBase';\n\nexport type PieChartPanelProps = PanelProps<PieChartOptions, TimeSeriesData>;\n\nexport function PieChartPanel(props: PieChartPanelProps): ReactElement | null {\n const {\n spec: { calculation, sort, mode, format: formatOptions, legend: pieChartLegend, colorPalette: colorPalette },\n contentDimensions,\n queryResults,\n } = props;\n const chartsTheme = useChartsTheme();\n const chartId = useId('time-series-panel');\n const seriesNames = queryResults.flatMap((result) => result?.data.series?.map((series) => series.name) || []);\n\n // Memoize the color list so it only regenerates when color/palette/series count changes\n const colorList = useMemo(() => {\n return getSeriesColor(seriesNames, colorPalette);\n }, [colorPalette, seriesNames]);\n\n const pieChartData = useMemo((): Array<Required<PieChartData>> => {\n const calculate = CalculationsMap[calculation as CalculationType];\n const pieChartData: Array<Required<PieChartData>> = [];\n queryResults.forEach((result, queryIndex) => {\n const series = result?.data.series ?? [];\n\n series.forEach((seriesData, seriesIndex) => {\n const seriesId = `${chartId}${seriesData.name}${seriesIndex}${queryIndex}`;\n const seriesColor = colorList[queryIndex * series.length + seriesIndex] ?? '#ff0000';\n\n const seriesItem = {\n id: seriesId,\n value: calculate(seriesData.values) ?? null,\n name: seriesData.formattedName ?? '',\n itemStyle: {\n color: seriesColor,\n },\n };\n\n pieChartData.push(seriesItem);\n });\n });\n\n return sortSeriesData(pieChartData, sort);\n }, [calculation, chartId, colorList, queryResults, sort]);\n\n const { legendItems, legendColumns } = useMemo(() => {\n const pieChartLegendMapper: PieChartLegendMapper =\n pieChartLegend?.mode === 'table' ? new PieChartTableLegendMapper() : new PieChartListLegendMapper();\n const values = pieChartLegend?.values;\n const legendItems = pieChartLegendMapper.mapToLegendItems(pieChartData, values);\n const legendColumns = pieChartLegendMapper.mapToLegendColumns(values, formatOptions);\n return {\n legendItems,\n legendColumns,\n };\n }, [formatOptions, pieChartData, pieChartLegend?.mode, pieChartLegend?.values]);\n\n const contentPadding = chartsTheme.container.padding.default;\n const adjustedContentDimensions: typeof contentDimensions = contentDimensions\n ? {\n width: contentDimensions.width - contentPadding * 2,\n height: contentDimensions.height - contentPadding * 2,\n }\n : undefined;\n\n const legend = useMemo(() => {\n return props.spec.legend && validateLegendSpec(props.spec.legend)\n ? merge({}, DEFAULT_LEGEND, props.spec.legend)\n : undefined;\n }, [props.spec.legend]);\n\n const [selectedLegendItems, setSelectedLegendItems] = useState<SelectedLegendItemState>('ALL');\n\n const [legendSorting, setLegendSorting] = useState<NonNullable<LegendProps['tableProps']>['sorting']>();\n\n const chartRef = useRef<ChartInstance>(null);\n\n // ensures there are fallbacks for unset properties since most\n // users should not need to customize visual display\n\n if (!contentDimensions) return null;\n\n return (\n <Box sx={{ padding: `${contentPadding}px` }}>\n <ContentWithLegend\n width={adjustedContentDimensions?.width ?? 400}\n height={adjustedContentDimensions?.height ?? 1000}\n // Making this small enough that the medium size doesn't get\n // responsive-handling-ed away when in the panel options editor.\n minChildrenHeight={50}\n legendSize={legend?.size}\n legendProps={\n legend && {\n options: legend,\n data: legendItems,\n selectedItems: selectedLegendItems,\n onSelectedItemsChange: setSelectedLegendItems,\n tableProps: {\n columns: legendColumns,\n sorting: legendSorting,\n onSortingChange: setLegendSorting,\n },\n onItemMouseOver: (e, { id }): void => {\n chartRef.current?.highlightSeries({ name: id });\n },\n onItemMouseOut: (): void => {\n chartRef.current?.clearHighlightedSeries();\n },\n }\n }\n >\n {({ height, width }) => {\n return (\n <Box style={{ height, width }}>\n <PieChartBase\n data={pieChartData}\n width={width}\n height={height}\n mode={mode}\n formatOptions={formatOptions}\n showLabels={Boolean(props.spec.showLabels)}\n />\n </Box>\n );\n }}\n </ContentWithLegend>\n </Box>\n );\n}\n"],"names":["Box","ContentWithLegend","DEFAULT_LEGEND","useChartsTheme","useId","CalculationsMap","validateLegendSpec","merge","useMemo","useRef","useState","PieChartListLegendMapper","PieChartTableLegendMapper","sortSeriesData","getSeriesColor","PieChartBase","PieChartPanel","props","spec","calculation","sort","mode","format","formatOptions","legend","pieChartLegend","colorPalette","contentDimensions","queryResults","chartsTheme","chartId","seriesNames","flatMap","result","data","series","map","name","colorList","pieChartData","calculate","forEach","queryIndex","seriesData","seriesIndex","seriesId","seriesColor","length","seriesItem","id","value","values","formattedName","itemStyle","color","push","legendItems","legendColumns","pieChartLegendMapper","mapToLegendItems","mapToLegendColumns","contentPadding","container","padding","default","adjustedContentDimensions","width","height","undefined","selectedLegendItems","setSelectedLegendItems","legendSorting","setLegendSorting","chartRef","sx","minChildrenHeight","legendSize","size","legendProps","options","selectedItems","onSelectedItemsChange","tableProps","columns","sorting","onSortingChange","onItemMouseOver","e","current","highlightSeries","onItemMouseOut","clearHighlightedSeries","style","showLabels","Boolean"],"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,GAAG,QAAQ,gBAAgB;AACpC,SAEEC,iBAAiB,EACjBC,cAAc,EAGdC,cAAc,EACdC,KAAK,QACA,yBAAyB;AAChC,SAASC,eAAe,EAA+BC,kBAAkB,QAAQ,4BAA4B;AAC7G,OAAOC,WAAW,eAAe;AACjC,SAAuBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAGhE,SAA+BC,wBAAwB,EAAEC,yBAAyB,EAAEC,cAAc,QAAQ,UAAU;AACpH,SAASC,cAAc,QAAQ,WAAW;AAC1C,SAASC,YAAY,QAAsB,iBAAiB;AAI5D,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EACJC,MAAM,EAAEC,WAAW,EAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQC,aAAa,EAAEC,QAAQC,cAAc,EAAEC,cAAcA,YAAY,EAAE,EAC5GC,iBAAiB,EACjBC,YAAY,EACb,GAAGX;IACJ,MAAMY,cAAc1B;IACpB,MAAM2B,UAAU1B,MAAM;IACtB,MAAM2B,cAAcH,aAAaI,OAAO,CAAC,CAACC,SAAWA,QAAQC,KAAKC,QA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EzB;wBAAQD;oBAAM;8BAC1B,cAAA,KAACnD;wBACCmB,MAAMK;wBACN2B,OAAOA;wBACPC,QAAQA;wBACR9C,MAAMA;wBACNE,eAAeA;wBACfsE,YAAYC,QAAQ7E,MAAMC,IAAI,CAAC2E,UAAU;;;YAIjD;;;AAIR"}
|
|
@@ -25,7 +25,6 @@ const _merge = /*#__PURE__*/ _interop_require_default(require("lodash/merge"));
|
|
|
25
25
|
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
26
26
|
const _immer = require("immer");
|
|
27
27
|
const _components = require("@perses-dev/components");
|
|
28
|
-
const _core = require("@perses-dev/core");
|
|
29
28
|
const _material = require("@mui/material");
|
|
30
29
|
const _react = require("react");
|
|
31
30
|
const _piechartmodel = require("./pie-chart-model");
|
|
@@ -158,7 +157,7 @@ function PieChartOptionsEditorSettings(props) {
|
|
|
158
157
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ModeSelector, {
|
|
159
158
|
value: value.mode,
|
|
160
159
|
onChange: handleModeChange,
|
|
161
|
-
disablePercentageMode: (0,
|
|
160
|
+
disablePercentageMode: (0, _components.isPercentUnit)(format)
|
|
162
161
|
})
|
|
163
162
|
]
|
|
164
163
|
})
|
package/lib/cjs/PieChartPanel.js
CHANGED
|
@@ -23,7 +23,6 @@ Object.defineProperty(exports, "PieChartPanel", {
|
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _material = require("@mui/material");
|
|
25
25
|
const _components = require("@perses-dev/components");
|
|
26
|
-
const _core = require("@perses-dev/core");
|
|
27
26
|
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
28
27
|
const _merge = /*#__PURE__*/ _interop_require_default(require("lodash/merge"));
|
|
29
28
|
const _react = require("react");
|
|
@@ -48,7 +47,7 @@ function PieChartPanel(props) {
|
|
|
48
47
|
seriesNames
|
|
49
48
|
]);
|
|
50
49
|
const pieChartData = (0, _react.useMemo)(()=>{
|
|
51
|
-
const calculate =
|
|
50
|
+
const calculate = _pluginsystem.CalculationsMap[calculation];
|
|
52
51
|
const pieChartData = [];
|
|
53
52
|
queryResults.forEach((result, queryIndex)=>{
|
|
54
53
|
const series = result?.data.series ?? [];
|
|
@@ -95,7 +94,7 @@ function PieChartPanel(props) {
|
|
|
95
94
|
height: contentDimensions.height - contentPadding * 2
|
|
96
95
|
} : undefined;
|
|
97
96
|
const legend = (0, _react.useMemo)(()=>{
|
|
98
|
-
return props.spec.legend && (0, _pluginsystem.validateLegendSpec)(props.spec.legend) ? (0, _merge.default)({},
|
|
97
|
+
return props.spec.legend && (0, _pluginsystem.validateLegendSpec)(props.spec.legend) ? (0, _merge.default)({}, _components.DEFAULT_LEGEND, props.spec.legend) : undefined;
|
|
99
98
|
}, [
|
|
100
99
|
props.spec.legend
|
|
101
100
|
]);
|
|
@@ -34,7 +34,7 @@ _export(exports, {
|
|
|
34
34
|
return createInitialPieChartOptions;
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
-
const
|
|
37
|
+
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
38
38
|
const DEFAULT_FORMAT = {
|
|
39
39
|
unit: 'decimal',
|
|
40
40
|
shortValues: true
|
|
@@ -43,7 +43,7 @@ const DEFAULT_SORT = 'desc';
|
|
|
43
43
|
const DEFAULT_MODE = 'value';
|
|
44
44
|
function createInitialPieChartOptions() {
|
|
45
45
|
return {
|
|
46
|
-
calculation:
|
|
46
|
+
calculation: _pluginsystem.DEFAULT_CALCULATION,
|
|
47
47
|
format: DEFAULT_FORMAT,
|
|
48
48
|
mode: DEFAULT_MODE,
|
|
49
49
|
radius: 50,
|
package/lib/cjs/utils.js
CHANGED
|
@@ -37,7 +37,7 @@ _export(exports, {
|
|
|
37
37
|
return sortSeriesData;
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
|
-
const
|
|
40
|
+
const _components = require("@perses-dev/components");
|
|
41
41
|
const _echarts = require("echarts");
|
|
42
42
|
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
43
43
|
const _piechartmodel = require("./pie-chart-model");
|
|
@@ -59,7 +59,7 @@ const getTooltipFormatter = (formatOptions)=>{
|
|
|
59
59
|
};
|
|
60
60
|
return ({ name, value, percent })=>{
|
|
61
61
|
if (typeof value === 'number') {
|
|
62
|
-
return `${_echarts.format.encodeHTML(name)}: ${(0,
|
|
62
|
+
return `${_echarts.format.encodeHTML(name)}: ${(0, _components.formatValue)(value, formatOptions)} (${(0, _components.formatValue)(percent, relativeFormatOptions)})`;
|
|
63
63
|
}
|
|
64
64
|
return `${_echarts.format.encodeHTML(name)}: ${_echarts.format.encodeHTML(value.toString())}`;
|
|
65
65
|
};
|
|
@@ -73,7 +73,7 @@ const getLabelFormatter = (mode, formatOptions)=>{
|
|
|
73
73
|
const labelFormatter = (formatOptions)=>{
|
|
74
74
|
return ({ name, value })=>{
|
|
75
75
|
if (typeof value === 'number') {
|
|
76
|
-
return `${name}:\n${(0,
|
|
76
|
+
return `${name}:\n${(0, _components.formatValue)(value, formatOptions)}`;
|
|
77
77
|
}
|
|
78
78
|
return `${name}:\n${_echarts.format.encodeHTML(value.toString())}`;
|
|
79
79
|
};
|
|
@@ -84,7 +84,7 @@ const percentageLabelFormatter = (formatOptions)=>{
|
|
|
84
84
|
decimalPlaces: formatOptions?.decimalPlaces
|
|
85
85
|
};
|
|
86
86
|
return ({ name, percent })=>{
|
|
87
|
-
return `${name}:\n${(0,
|
|
87
|
+
return `${name}:\n${(0, _components.formatValue)(percent, relativeFormatOptions)}`;
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
90
|
class PieChartListLegendMapper {
|
|
@@ -141,7 +141,7 @@ class PieChartTableLegendMapper {
|
|
|
141
141
|
enableSorting: true,
|
|
142
142
|
cell: ({ getValue })=>{
|
|
143
143
|
const cellValue = getValue();
|
|
144
|
-
return typeof cellValue === 'number' && formatOptions ? (0,
|
|
144
|
+
return typeof cellValue === 'number' && formatOptions ? (0, _components.formatValue)(cellValue, v === 'relative' ? relativeFormatOptions : formatOptions) : cellValue;
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
147
|
}) ?? [];
|
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,5 +1,4 @@
|
|
|
1
|
-
import { LegendItem, ModeOption, SortOption, TableColumnConfig } from '@perses-dev/components';
|
|
2
|
-
import { FormatOptions } from '@perses-dev/core';
|
|
1
|
+
import { FormatOptions, LegendItem, ModeOption, SortOption, TableColumnConfig } from '@perses-dev/components';
|
|
3
2
|
import { ComparisonValues, LegendValue } from '@perses-dev/plugin-system';
|
|
4
3
|
import { PieChartData } from './PieChartBase';
|
|
5
4
|
export declare function sortSeriesData<T extends PieChartData>(data: T[], sortOrder?: SortOption): T[];
|
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,OA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|
@@ -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 { formatValue } from '@perses-dev/
|
|
13
|
+
import { formatValue } from '@perses-dev/components';
|
|
14
14
|
import { format } from 'echarts';
|
|
15
15
|
import { comparisonLegends } from '@perses-dev/plugin-system';
|
|
16
16
|
import { DEFAULT_SORT } from './pie-chart-model';
|
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 { LegendItem, ModeOption, SortOption, TableColumnConfig } from '@perses-dev/components';\nimport { FormatOptions, formatValue } from '@perses-dev/core';\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":"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,SAAwBA,WAAW,QAAQ,mBAAmB;AAC9D,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,iBAAiB,QAAuC,4BAA4B;AAE7F,SAASC,YAAY,QAAQ,oBAAoB;AAEjD,OAAO,SAASC,eAAuCC,IAAS,EAAEC,YAAwBH,YAAY;IACpG,OAAOE,KAAKE,IAAI,CAAC,CAACC,GAAGC;QACnB,qEAAqE;QACrE,IAAID,EAAEE,KAAK,KAAK,QAAQD,EAAEC,KAAK,KAAK,MAAM,OAAO;QACjD,IAAIF,EAAEE,KAAK,KAAK,MAAM,OAAO;QAC7B,IAAID,EAAEC,KAAK,KAAK,MAAM,OAAO,CAAC;QAE9B,gBAAgB;QAChB,MAAMC,OAAO,AAACH,CAAAA,EAAEE,KAAK,IAAI,CAAA,IAAMD,CAAAA,EAAEC,KAAK,IAAI,CAAA;QAC1C,OAAOJ,cAAc,QAAQK,OAAO,CAACA;IACvC;AACF;AAGA,OAAO,MAAMC,sBAAsB,CAACC;IAClC,MAAMC,wBAAwB;QAAEC,MAAM;QAAWC,eAAeH,eAAeG;IAA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AAY9C,gBACpCb,YAAY2D,WAAWd,MAAM,aAAa/B,wBAAwBD,iBAClE8C;gBACN;YACF;QACF,MAAM,EAAE;IAEZ;AACF;AAEA,SAAStB,qBAA6ChC,IAAS;IAC7D,MAAMuD,MAAMvD,KAAKwD,MAAM,CAAC,CAACC,aAAa,EAAEpD,KAAK,EAAE,GAAKoD,cAAepD,CAAAA,SAAS,CAAA,GAAI;IAChF,OAAOL,KAAKuB,GAAG,CAAC,CAACmC;QACf,MAAMC,aAAa,AAAED,CAAAA,WAAWrD,KAAK,IAAI,CAAA,IAAKkD,MAAO;QACrD,OAAO;YACL,GAAGG,UAAU;YACbrD,OAAOuD,OAAOD,WAAWE,OAAO,CAAC;QACnC;IACF;AACF;AAEA,MAAMC,wBAAwBC,OAAOC,IAAI,CAACnE;AAC1C,SAAS6C,kBAAkBrC,KAAyB;IAClD,OAAO,OAAOA,UAAU,YAAYyD,sBAAsB5B,QAAQ,CAAC7B;AACrE"}
|
|
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":"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,SAEEA,WAAW,QAKN,yBAAyB;AAChC,SAASC,MAAM,QAAQ,UAAU;AACjC,SAASC,iBAAiB,QAAuC,4BAA4B;AAE7F,SAASC,YAAY,QAAQ,oBAAoB;AAEjD,OAAO,SAASC,eAAuCC,IAAS,EAAEC,YAAwBH,YAAY;IACpG,OAAOE,KAAKE,IAAI,CAAC,CAACC,GAAGC;QACnB,qEAAqE;QACrE,IAAID,EAAEE,KAAK,KAAK,QAAQD,EAAEC,KAAK,KAAK,MAAM,OAAO;QACjD,IAAIF,EAAEE,KAAK,KAAK,MAAM,OAAO;QAC7B,IAAID,EAAEC,KAAK,KAAK,MAAM,OAAO,CAAC;QAE9B,gBAAgB;QAChB,M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