@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.
Files changed (194) hide show
  1. package/__mf/css/async/236.85c2cbf6.css +1 -0
  2. package/__mf/font/inter-cyrillic-300-normal.432f2b21.woff +0 -0
  3. package/__mf/font/inter-cyrillic-300-normal.9da91009.woff2 +0 -0
  4. package/__mf/font/inter-cyrillic-400-normal.372704ff.woff2 +0 -0
  5. package/__mf/font/inter-cyrillic-400-normal.a6b6ef6f.woff +0 -0
  6. package/__mf/font/inter-cyrillic-500-normal.7c15bba8.woff2 +0 -0
  7. package/__mf/font/inter-cyrillic-500-normal.b9f8c929.woff +0 -0
  8. package/__mf/font/inter-cyrillic-600-normal.2f42892a.woff2 +0 -0
  9. package/__mf/font/inter-cyrillic-600-normal.c3987adc.woff +0 -0
  10. package/__mf/font/inter-cyrillic-700-normal.93eba3c3.woff +0 -0
  11. package/__mf/font/inter-cyrillic-700-normal.e9e5b2dc.woff2 +0 -0
  12. package/__mf/font/inter-cyrillic-900-normal.f285bd7a.woff2 +0 -0
  13. package/__mf/font/inter-cyrillic-900-normal.ffbd8a3a.woff +0 -0
  14. package/__mf/font/inter-cyrillic-ext-300-normal.95bb9038.woff2 +0 -0
  15. package/__mf/font/inter-cyrillic-ext-300-normal.cfc143a9.woff +0 -0
  16. package/__mf/font/inter-cyrillic-ext-400-normal.2a31c04b.woff +0 -0
  17. package/__mf/font/inter-cyrillic-ext-400-normal.f572b170.woff2 +0 -0
  18. package/__mf/font/inter-cyrillic-ext-500-normal.5a6bb1da.woff +0 -0
  19. package/__mf/font/inter-cyrillic-ext-500-normal.fe0d9b14.woff2 +0 -0
  20. package/__mf/font/inter-cyrillic-ext-600-normal.ecbdecad.woff +0 -0
  21. package/__mf/font/inter-cyrillic-ext-600-normal.f7b3c15b.woff2 +0 -0
  22. package/__mf/font/inter-cyrillic-ext-700-normal.4b4022a6.woff +0 -0
  23. package/__mf/font/inter-cyrillic-ext-700-normal.74b516d2.woff2 +0 -0
  24. package/__mf/font/inter-cyrillic-ext-900-normal.9970ddb5.woff +0 -0
  25. package/__mf/font/inter-cyrillic-ext-900-normal.a0d59adc.woff2 +0 -0
  26. package/__mf/font/inter-greek-300-normal.0d7be683.woff2 +0 -0
  27. package/__mf/font/inter-greek-300-normal.8f0b988e.woff +0 -0
  28. package/__mf/font/inter-greek-400-normal.cc58c11b.woff +0 -0
  29. package/__mf/font/inter-greek-400-normal.d7020e3c.woff2 +0 -0
  30. package/__mf/font/inter-greek-500-normal.d9a33207.woff +0 -0
  31. package/__mf/font/inter-greek-500-normal.f41f43db.woff2 +0 -0
  32. package/__mf/font/inter-greek-600-normal.4ec0c1c1.woff +0 -0
  33. package/__mf/font/inter-greek-600-normal.cc532937.woff2 +0 -0
  34. package/__mf/font/inter-greek-700-normal.5ec6c758.woff +0 -0
  35. package/__mf/font/inter-greek-700-normal.97f0eeeb.woff2 +0 -0
  36. package/__mf/font/inter-greek-900-normal.46b66369.woff2 +0 -0
  37. package/__mf/font/inter-greek-900-normal.9ae3a3c5.woff +0 -0
  38. package/__mf/font/inter-greek-ext-300-normal.10247a66.woff2 +0 -0
  39. package/__mf/font/inter-greek-ext-300-normal.4668e5cb.woff +0 -0
  40. package/__mf/font/inter-greek-ext-400-normal.4ce1df5d.woff2 +0 -0
  41. package/__mf/font/inter-greek-ext-400-normal.88ede1ea.woff +0 -0
  42. package/__mf/font/inter-greek-ext-500-normal.7a4aa726.woff +0 -0
  43. package/__mf/font/inter-greek-ext-500-normal.cbd51e2d.woff2 +0 -0
  44. package/__mf/font/inter-greek-ext-600-normal.089a95ee.woff +0 -0
  45. package/__mf/font/inter-greek-ext-600-normal.1f33d317.woff2 +0 -0
  46. package/__mf/font/inter-greek-ext-700-normal.31f1075d.woff +0 -0
  47. package/__mf/font/inter-greek-ext-700-normal.827cd618.woff2 +0 -0
  48. package/__mf/font/inter-greek-ext-900-normal.531bcee7.woff +0 -0
  49. package/__mf/font/inter-greek-ext-900-normal.8a9b36b9.woff2 +0 -0
  50. package/__mf/font/inter-latin-300-normal.15fb600d.woff2 +0 -0
  51. package/__mf/font/inter-latin-300-normal.6f95f590.woff +0 -0
  52. package/__mf/font/inter-latin-400-normal.2c7a775c.woff +0 -0
  53. package/__mf/font/inter-latin-400-normal.ef6d3f52.woff2 +0 -0
  54. package/__mf/font/inter-latin-500-normal.b7b43ace.woff2 +0 -0
  55. package/__mf/font/inter-latin-500-normal.cb4c8ceb.woff +0 -0
  56. package/__mf/font/inter-latin-600-normal.8fb1a964.woff2 +0 -0
  57. package/__mf/font/inter-latin-600-normal.ce0f5f43.woff +0 -0
  58. package/__mf/font/inter-latin-700-normal.953b7aa5.woff2 +0 -0
  59. package/__mf/font/inter-latin-700-normal.9c21d4dc.woff +0 -0
  60. package/__mf/font/inter-latin-900-normal.2a8028ec.woff2 +0 -0
  61. package/__mf/font/inter-latin-900-normal.fa252135.woff +0 -0
  62. package/__mf/font/inter-latin-ext-300-normal.167cc8c9.woff2 +0 -0
  63. package/__mf/font/inter-latin-ext-300-normal.f695be66.woff +0 -0
  64. package/__mf/font/inter-latin-ext-400-normal.32a25442.woff2 +0 -0
  65. package/__mf/font/inter-latin-ext-400-normal.4edcaace.woff +0 -0
  66. package/__mf/font/inter-latin-ext-500-normal.a19a84a6.woff +0 -0
  67. package/__mf/font/inter-latin-ext-500-normal.d9b491de.woff2 +0 -0
  68. package/__mf/font/inter-latin-ext-600-normal.38b075d8.woff2 +0 -0
  69. package/__mf/font/inter-latin-ext-600-normal.49faa47a.woff +0 -0
  70. package/__mf/font/inter-latin-ext-700-normal.93534b50.woff +0 -0
  71. package/__mf/font/inter-latin-ext-700-normal.b63daa1a.woff2 +0 -0
  72. package/__mf/font/inter-latin-ext-900-normal.0efdb307.woff +0 -0
  73. package/__mf/font/inter-latin-ext-900-normal.9c0fc2c7.woff2 +0 -0
  74. package/__mf/font/inter-vietnamese-300-normal.aad496d8.woff +0 -0
  75. package/__mf/font/inter-vietnamese-300-normal.ad9ef503.woff2 +0 -0
  76. package/__mf/font/inter-vietnamese-400-normal.a9dd2faf.woff +0 -0
  77. package/__mf/font/inter-vietnamese-400-normal.de4fc44f.woff2 +0 -0
  78. package/__mf/font/inter-vietnamese-500-normal.7c0a695f.woff2 +0 -0
  79. package/__mf/font/inter-vietnamese-500-normal.a3a73b95.woff +0 -0
  80. package/__mf/font/inter-vietnamese-600-normal.9d518599.woff2 +0 -0
  81. package/__mf/font/inter-vietnamese-600-normal.c5ce3fcb.woff +0 -0
  82. package/__mf/font/inter-vietnamese-700-normal.bc68b199.woff +0 -0
  83. package/__mf/font/inter-vietnamese-700-normal.faf12809.woff2 +0 -0
  84. package/__mf/font/inter-vietnamese-900-normal.2b782045.woff +0 -0
  85. package/__mf/font/inter-vietnamese-900-normal.e639b65a.woff2 +0 -0
  86. package/__mf/js/PieChart.4874b5a3.js +7 -0
  87. package/__mf/js/async/121.77d8ca8d.js +2 -0
  88. package/__mf/js/async/177.5b05acb8.js +1 -0
  89. package/__mf/js/async/192.8567667d.js +1 -0
  90. package/__mf/js/async/2.1fd70a85.js +1 -0
  91. package/__mf/js/async/204.0b9b3971.js +1 -0
  92. package/__mf/js/async/235.47f639e4.js +1 -0
  93. package/__mf/js/async/236.93daa9e1.js +7 -0
  94. package/__mf/js/async/{390.99d822cd.js.LICENSE.txt → 236.93daa9e1.js.LICENSE.txt} +19 -1
  95. package/__mf/js/async/274.a688b81f.js +2 -0
  96. package/__mf/js/async/356.f9173bd6.js +1 -0
  97. package/__mf/js/async/376.9566e7f3.js +110 -0
  98. package/__mf/js/async/376.9566e7f3.js.LICENSE.txt +27 -0
  99. package/__mf/js/async/392.fd732e61.js +2 -0
  100. package/__mf/js/async/469.3c02be86.js +1 -0
  101. package/__mf/js/async/47.58c2f69b.js +39 -0
  102. package/__mf/js/async/{67.5bf7fff1.js.LICENSE.txt → 47.58c2f69b.js.LICENSE.txt} +11 -23
  103. package/__mf/js/async/470.f4861d15.js +2 -0
  104. package/__mf/js/async/554.97159342.js +2 -0
  105. package/__mf/js/async/558.38ed78e0.js +1 -0
  106. package/__mf/js/async/568.21c3aaad.js +24 -0
  107. package/__mf/js/async/{648.924b8cfc.js.LICENSE.txt → 568.21c3aaad.js.LICENSE.txt} +0 -16
  108. package/__mf/js/async/587.cb45262d.js +1 -0
  109. package/__mf/js/async/616.b87a9b8b.js +1 -0
  110. package/__mf/js/async/663.69a57e79.js +1 -0
  111. package/__mf/js/async/721.6e66d127.js +1 -0
  112. package/__mf/js/async/873.10a8cf00.js +1 -0
  113. package/__mf/js/async/941.8d9ea74e.js +2 -0
  114. package/__mf/js/async/968.1b0e9683.js +1 -0
  115. package/__mf/js/async/__federation_expose_PieChart.944f7c8e.js +4 -0
  116. package/__mf/js/async/lib-router.6ba1ce34.js +2 -0
  117. package/__mf/js/main.641ea30c.js +7 -0
  118. package/lib/PieChartBase.d.ts +6 -0
  119. package/lib/PieChartBase.d.ts.map +1 -1
  120. package/lib/PieChartBase.js +5 -4
  121. package/lib/PieChartBase.js.map +1 -1
  122. package/lib/PieChartOptionsEditorSettings.d.ts.map +1 -1
  123. package/lib/PieChartOptionsEditorSettings.js +1 -2
  124. package/lib/PieChartOptionsEditorSettings.js.map +1 -1
  125. package/lib/PieChartPanel.d.ts +1 -1
  126. package/lib/PieChartPanel.d.ts.map +1 -1
  127. package/lib/PieChartPanel.js +25 -70
  128. package/lib/PieChartPanel.js.map +1 -1
  129. package/lib/cjs/PieChartBase.js +4 -3
  130. package/lib/cjs/PieChartOptionsEditorSettings.js +1 -2
  131. package/lib/cjs/PieChartPanel.js +24 -69
  132. package/lib/cjs/pie-chart-model.js +2 -2
  133. package/lib/cjs/utils.js +123 -12
  134. package/lib/pie-chart-model.d.ts +3 -3
  135. package/lib/pie-chart-model.d.ts.map +1 -1
  136. package/lib/pie-chart-model.js +1 -1
  137. package/lib/pie-chart-model.js.map +1 -1
  138. package/lib/utils.d.ts +22 -6
  139. package/lib/utils.d.ts.map +1 -1
  140. package/lib/utils.js +112 -10
  141. package/lib/utils.js.map +1 -1
  142. package/mf-manifest.json +56 -46
  143. package/mf-stats.json +70 -47
  144. package/package.json +4 -4
  145. package/__mf/css/async/442.d3010b86.css +0 -1
  146. package/__mf/css/async/61.d3010b86.css +0 -1
  147. package/__mf/css/async/823.d3010b86.css +0 -1
  148. package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
  149. package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
  150. package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
  151. package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
  152. package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
  153. package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
  154. package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
  155. package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
  156. package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
  157. package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
  158. package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
  159. package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
  160. package/__mf/js/PieChart.cf3c31fc.js +0 -6
  161. package/__mf/js/async/121.281eb287.js +0 -2
  162. package/__mf/js/async/177.c83badab.js +0 -1
  163. package/__mf/js/async/192.b0eb01c2.js +0 -1
  164. package/__mf/js/async/2.ba8aa6eb.js +0 -1
  165. package/__mf/js/async/235.88141957.js +0 -1
  166. package/__mf/js/async/274.78035147.js +0 -2
  167. package/__mf/js/async/337.13482c5c.js +0 -1
  168. package/__mf/js/async/350.7f227cc5.js +0 -1
  169. package/__mf/js/async/356.75a8af4c.js +0 -1
  170. package/__mf/js/async/390.99d822cd.js +0 -7
  171. package/__mf/js/async/392.2780a75e.js +0 -2
  172. package/__mf/js/async/469.e52e96c4.js +0 -1
  173. package/__mf/js/async/470.844ea64f.js +0 -2
  174. package/__mf/js/async/554.2692322c.js +0 -2
  175. package/__mf/js/async/587.6f746ff5.js +0 -1
  176. package/__mf/js/async/616.b6650249.js +0 -1
  177. package/__mf/js/async/634.282182cd.js +0 -38
  178. package/__mf/js/async/648.924b8cfc.js +0 -22
  179. package/__mf/js/async/663.c0629798.js +0 -1
  180. package/__mf/js/async/67.5bf7fff1.js +0 -110
  181. package/__mf/js/async/721.8dc45583.js +0 -1
  182. package/__mf/js/async/873.8b5831f0.js +0 -1
  183. package/__mf/js/async/941.4ea66ef3.js +0 -2
  184. package/__mf/js/async/968.a62ee0f7.js +0 -1
  185. package/__mf/js/async/__federation_expose_PieChart.329ca150.js +0 -1
  186. package/__mf/js/async/lib-router.48213c49.js +0 -2
  187. package/__mf/js/main.2fa79bb4.js +0 -6
  188. /package/__mf/js/async/{121.281eb287.js.LICENSE.txt → 121.77d8ca8d.js.LICENSE.txt} +0 -0
  189. /package/__mf/js/async/{274.78035147.js.LICENSE.txt → 274.a688b81f.js.LICENSE.txt} +0 -0
  190. /package/__mf/js/async/{392.2780a75e.js.LICENSE.txt → 392.fd732e61.js.LICENSE.txt} +0 -0
  191. /package/__mf/js/async/{470.844ea64f.js.LICENSE.txt → 470.f4861d15.js.LICENSE.txt} +0 -0
  192. /package/__mf/js/async/{554.2692322c.js.LICENSE.txt → 554.97159342.js.LICENSE.txt} +0 -0
  193. /package/__mf/js/async/{941.4ea66ef3.js.LICENSE.txt → 941.8d9ea74e.js.LICENSE.txt} +0 -0
  194. /package/__mf/js/async/{lib-router.48213c49.js.LICENSE.txt → lib-router.6ba1ce34.js.LICENSE.txt} +0 -0
@@ -13,10 +13,11 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  // limitations under the License.
14
14
  import { use } from 'echarts/core';
15
15
  import { PieChart as EChartsPieChart } from 'echarts/charts';
16
- import { GridComponent, DatasetComponent, TitleComponent, TooltipComponent, LegendComponent } from 'echarts/components';
16
+ import { DatasetComponent, GridComponent, LegendComponent, TitleComponent, TooltipComponent } from 'echarts/components';
17
17
  import { CanvasRenderer } from 'echarts/renderers';
18
18
  import { Box, useTheme } from '@mui/material';
19
19
  import { EChart, useChartsTheme } from '@perses-dev/components';
20
+ import { getLabelFormatter, getTooltipFormatter } from './utils';
20
21
  use([
21
22
  EChartsPieChart,
22
23
  GridComponent,
@@ -27,13 +28,13 @@ use([
27
28
  CanvasRenderer
28
29
  ]);
29
30
  export function PieChartBase(props) {
30
- const { width, height, data, showLabels } = props;
31
+ const { width, height, data, mode, formatOptions, showLabels } = props;
31
32
  const chartsTheme = useChartsTheme();
32
33
  const muiTheme = useTheme();
33
34
  const option = {
34
35
  tooltip: {
35
36
  trigger: 'item',
36
- formatter: '{b}: {c} ({d}%)',
37
+ formatter: getTooltipFormatter(formatOptions),
37
38
  appendTo: document.body,
38
39
  confine: false
39
40
  },
@@ -45,7 +46,7 @@ export function PieChartBase(props) {
45
46
  show: Boolean(showLabels),
46
47
  position: 'inner',
47
48
  fontSize: 14,
48
- formatter: '{b}\n{c}',
49
+ formatter: getLabelFormatter(mode, formatOptions),
49
50
  overflow: 'truncate',
50
51
  fontWeight: 'bold'
51
52
  },
@@ -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 { GridComponent, DatasetComponent, TitleComponent, TooltipComponent, LegendComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { Box, useTheme } from '@mui/material';\nimport { ReactElement } from 'react';\nimport { EChart, useChartsTheme } from '@perses-dev/components';\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}\n\nexport interface PieChartBaseProps {\n width: number;\n height: number;\n data: PieChartData[] | null;\n showLabels?: boolean;\n}\n\nexport function PieChartBase(props: PieChartBaseProps): ReactElement {\n const { width, height, data, showLabels } = props;\n const chartsTheme = useChartsTheme();\n const muiTheme = useTheme();\n\n const option = {\n tooltip: {\n trigger: 'item',\n formatter: '{b}: {c} ({d}%)',\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: '{b}\\n{c}',\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","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","LegendComponent","CanvasRenderer","Box","useTheme","EChart","useChartsTheme","PieChartBase","props","width","height","data","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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,OAAO;YACLpC,OAAOA;YACPC,QAAQA;QACV;QACAoC,IAAI;YAAEf,UAAU;QAAO;kBAEvB,cAAA,KAAC1B;YACCyC,IAAI;gBACFrC,OAAO;gBACPC,QAAQ;YACV;YACAK,QAAQA;YACRgC,OAAOlC,YAAYmC,YAAY;;;AAIvC"}
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":"AAiDA,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"}
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[]) => {\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) => {\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,MAA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,cAAA,MAAC3C;4BAAMiD,SAAS;;8CACd,MAACjD;oCAAMkD,WAAU;oCAAMD,SAAS;oCAAGE,YAAW;;sDAC5C,MAACvD;4CAAYwD,MAAK;4CAAQC,IAAI;gDAAEC,UAAU;4CAAI;;8DAC5C,KAACzD;8DAAW;;8DACZ,MAACE;oDACCS,OAAO8B;oDACPM,OAAM;oDACNrC,UAAU,CAACgD,IAAMf,wBAAwBe,EAAEC,MAAM,CAAChD,KAAK;;sEAEvD,KAACV;4DAASU,OAAM;sEAAU;;sEAC1B,KAACV;4DAASU,OAAM;sEAAQ;;sEACxB,KAACV;4DAASU,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,+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,EAGnBC,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,EAEdC,aAAa,QACR,yBAAyB;AAChC,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,S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C,IAAI;gDAAEC,UAAU;4CAAI;;8DAC5C,KAACzD;8DAAW;;8DACZ,MAACE;oDACCS,OAAO8B;oDACPM,OAAM;oDACNrC,UAAU,CAACgD,IAAMf,wBAAwBe,EAAEC,MAAM,CAAChD,KAAK;;sEAEvD,KAACV;4DAASU,OAAM;sEAAU;;sEAC1B,KAACV;4DAASU,OAAM;sEAAQ;;sEACxB,KAACV;4DAASU,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,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":"AAwBA,OAAO,EAAoD,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpG,OAAO,EAAuC,UAAU,EAAsB,MAAM,2BAA2B,CAAC;AAEhH,OAAO,EAAE,YAAY,EAA6B,MAAM,OAAO,CAAC;AAChE,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,CA2K5E"}
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"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- //Copyright 2024 The Perses Authors
2
+ // Copyright The Perses Authors
3
3
  // Licensed under the Apache License, Version 2.0 (the "License");
4
4
  // you may not use this file except in compliance with the License.
5
5
  // You may obtain a copy of the License at
@@ -12,16 +12,15 @@ 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, DEFAULT_LEGEND } from '@perses-dev/core';
17
- import { comparisonLegends, 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
- import { calculatePercentages, sortSeriesData } from './utils';
19
+ import { PieChartListLegendMapper, PieChartTableLegendMapper, sortSeriesData } from './utils';
21
20
  import { getSeriesColor } from './colors';
22
21
  import { PieChartBase } from './PieChartBase';
23
22
  export function PieChartPanel(props) {
24
- const { spec: { calculation, sort, mode, legend: pieChartLegend, colorPalette: colorPalette }, contentDimensions, queryResults } = props;
23
+ const { spec: { calculation, sort, mode, format: formatOptions, legend: pieChartLegend, colorPalette: colorPalette }, contentDimensions, queryResults } = props;
25
24
  const chartsTheme = useChartsTheme();
26
25
  const chartId = useId('time-series-panel');
27
26
  const seriesNames = queryResults.flatMap((result)=>result?.data.series?.map((series)=>series.name) || []);
@@ -32,11 +31,9 @@ export function PieChartPanel(props) {
32
31
  colorPalette,
33
32
  seriesNames
34
33
  ]);
35
- const { pieChartData, legendItems, legendColumns } = useMemo(()=>{
34
+ const pieChartData = useMemo(()=>{
36
35
  const calculate = CalculationsMap[calculation];
37
36
  const pieChartData = [];
38
- const legendItems = [];
39
- const legendColumns = [];
40
37
  queryResults.forEach((result, queryIndex)=>{
41
38
  const series = result?.data.series ?? [];
42
39
  series.forEach((seriesData, seriesIndex)=>{
@@ -51,74 +48,30 @@ export function PieChartPanel(props) {
51
48
  }
52
49
  };
53
50
  pieChartData.push(seriesItem);
54
- legendItems.push({
55
- id: seriesId,
56
- label: seriesData.formattedName ?? '',
57
- color: seriesColor,
58
- data: {}
59
- });
60
51
  });
61
52
  });
62
- const sortedPieChartData = sortSeriesData(pieChartData, sort);
63
- // Reorder legend items to reflect the current sorting order of series
64
- const valueById = new Map(sortedPieChartData.map((pd)=>[
65
- pd.id ?? pd.name,
66
- pd.value ?? 0
67
- ]));
68
- legendItems.sort((a, b)=>{
69
- const av = valueById.get(a.id) ?? 0;
70
- const bv = valueById.get(b.id) ?? 0;
71
- return sort === 'asc' ? av - bv : bv - av;
72
- });
73
- if (pieChartLegend?.values?.length && pieChartLegend?.mode === 'table') {
74
- const { values } = pieChartLegend;
75
- [
76
- ...values
77
- ].sort().forEach((v)=>{
78
- /* First, create a column for the current legend value */ legendColumns.push({
79
- accessorKey: `data.${v}`,
80
- header: comparisonLegends[v]?.label || v,
81
- headerDescription: comparisonLegends[v]?.description,
82
- width: 90,
83
- align: 'right',
84
- cellDescription: true,
85
- enableSorting: true
86
- });
87
- /* Then, settle the legend items related to this legend value */ switch(v){
88
- case 'abs':
89
- legendItems.forEach((li)=>{
90
- const { value: itemAbsoluteValue } = pieChartData.find((pd)=>li.id === pd.id) || {};
91
- if (typeof itemAbsoluteValue === 'number' && li.data) {
92
- li.data['abs'] = itemAbsoluteValue;
93
- }
94
- });
95
- break;
96
- case 'relative':
97
- legendItems.forEach((li)=>{
98
- const { value: itemPercentageValue } = calculatePercentages(sortedPieChartData).find((ppd)=>li.id === ppd.id) || {};
99
- if (typeof itemPercentageValue === 'number' && li.data) {
100
- li.data['relative'] = `${itemPercentageValue.toFixed(2)}%`;
101
- }
102
- });
103
- break;
104
- default:
105
- break;
106
- }
107
- });
108
- }
53
+ return sortSeriesData(pieChartData, sort);
54
+ }, [
55
+ calculation,
56
+ chartId,
57
+ colorList,
58
+ queryResults,
59
+ sort
60
+ ]);
61
+ const { legendItems, legendColumns } = useMemo(()=>{
62
+ const pieChartLegendMapper = pieChartLegend?.mode === 'table' ? new PieChartTableLegendMapper() : new PieChartListLegendMapper();
63
+ const values = pieChartLegend?.values;
64
+ const legendItems = pieChartLegendMapper.mapToLegendItems(pieChartData, values);
65
+ const legendColumns = pieChartLegendMapper.mapToLegendColumns(values, formatOptions);
109
66
  return {
110
- pieChartData: mode === 'percentage' ? calculatePercentages(sortedPieChartData) : sortedPieChartData,
111
67
  legendItems,
112
68
  legendColumns
113
69
  };
114
70
  }, [
115
- calculation,
116
- sort,
117
- mode,
118
- queryResults,
119
- colorList,
120
- chartId,
121
- pieChartLegend
71
+ formatOptions,
72
+ pieChartData,
73
+ pieChartLegend?.mode,
74
+ pieChartLegend?.values
122
75
  ]);
123
76
  const contentPadding = chartsTheme.container.padding.default;
124
77
  const adjustedContentDimensions = contentDimensions ? {
@@ -176,6 +129,8 @@ export function PieChartPanel(props) {
176
129
  data: pieChartData,
177
130
  width: width,
178
131
  height: height,
132
+ mode: mode,
133
+ formatOptions: formatOptions,
179
134
  showLabels: Boolean(props.spec.showLabels)
180
135
  })
181
136
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/PieChartPanel.tsx"],"sourcesContent":["//Copyright 2024 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 LegendItem,\n LegendProps,\n SelectedLegendItemState,\n TableColumnConfig,\n useChartsTheme,\n useId,\n} from '@perses-dev/components';\nimport { CalculationType, CalculationsMap, DEFAULT_LEGEND, TimeSeriesData } from '@perses-dev/core';\nimport { comparisonLegends, ComparisonValues, 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 { calculatePercentages, 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, 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, legendItems, legendColumns } = useMemo(() => {\n const calculate = CalculationsMap[calculation as CalculationType];\n const pieChartData: PieChartData[] = [];\n const legendItems: LegendItem[] = [];\n const legendColumns: Array<TableColumnConfig<LegendItem>> = [];\n\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 legendItems.push({\n id: seriesId,\n label: seriesData.formattedName ?? '',\n color: seriesColor,\n data: {},\n });\n });\n });\n\n const sortedPieChartData = sortSeriesData(pieChartData, sort);\n\n // Reorder legend items to reflect the current sorting order of series\n const valueById = new Map(sortedPieChartData.map((pd) => [pd.id ?? pd.name, pd.value ?? 0]));\n legendItems.sort((a, b) => {\n const av = valueById.get(a.id) ?? 0;\n const bv = valueById.get(b.id) ?? 0;\n return sort === 'asc' ? av - bv : bv - av;\n });\n\n if (pieChartLegend?.values?.length && pieChartLegend?.mode === 'table') {\n const { values } = pieChartLegend;\n [...values].sort().forEach((v) => {\n /* First, create a column for the current legend value */\n legendColumns.push({\n accessorKey: `data.${v}`,\n header: comparisonLegends[v as ComparisonValues]?.label || v,\n headerDescription: comparisonLegends[v as ComparisonValues]?.description,\n width: 90,\n align: 'right',\n cellDescription: true,\n enableSorting: true,\n });\n /* Then, settle the legend items related to this legend value */\n switch (v) {\n case 'abs':\n legendItems.forEach((li) => {\n const { value: itemAbsoluteValue } = pieChartData.find((pd) => li.id === pd.id) || {};\n if (typeof itemAbsoluteValue === 'number' && li.data) {\n li.data['abs'] = itemAbsoluteValue;\n }\n });\n break;\n case 'relative':\n legendItems.forEach((li) => {\n const { value: itemPercentageValue } =\n calculatePercentages(sortedPieChartData).find((ppd) => li.id === ppd.id) || {};\n if (typeof itemPercentageValue === 'number' && li.data) {\n li.data['relative'] = `${itemPercentageValue.toFixed(2)}%`;\n }\n });\n break;\n default:\n break;\n }\n });\n }\n\n return {\n pieChartData: mode === 'percentage' ? calculatePercentages(sortedPieChartData) : sortedPieChartData,\n legendItems,\n legendColumns,\n };\n }, [calculation, sort, mode, queryResults, colorList, chartId, pieChartLegend]);\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 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","comparisonLegends","validateLegendSpec","merge","useMemo","useRef","useState","calculatePercentages","sortSeriesData","getSeriesColor","PieChartBase","PieChartPanel","props","spec","calculation","sort","mode","legend","pieChartLegend","colorPalette","contentDimensions","queryResults","chartsTheme","chartId","seriesNames","flatMap","result","data","series","map","name","colorList","pieChartData","legendItems","legendColumns","calculate","forEach","queryIndex","seriesData","seriesIndex","seriesId","seriesColor","length","seriesItem","id","value","values","formattedName","itemStyle","color","push","label","sortedPieChartData","valueById","Map","pd","a","b","av","get","bv","v","accessorKey","header","headerDescription","description","width","align","cellDescription","enableSorting","li","itemAbsoluteValue","find","itemPercentageValue","ppd","toFixed","contentPadding","container","padding","default","adjustedContentDimensions","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,mCAAmC;AACnC,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,iB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MAAM,IAC3CiE;IACN,GAAG;QAACtE,MAAMC,IAAI,CAACI,MAAM;KAAC;IAEtB,MAAM,CAACkE,qBAAqBC,uBAAuB,GAAG9E,SAAkC;IAExF,MAAM,CAAC+E,eAAeC,iBAAiB,GAAGhF;IAE1C,MAAMiF,WAAWlF,OAAsB;IAEvC,8DAA8D;IAC9D,oDAAoD;IAEpD,IAAI,CAACe,mBAAmB,OAAO;IAE/B,qBACE,KAACzB;QAAI6F,IAAI;YAAEV,SAAS,GAAGF,eAAe,EAAE,CAAC;QAAC;kBACxC,cAAA,KAAChF;YACCsE,OAAOc,2BAA2Bd,SAAS;YAC3Ce,QAAQD,2BAA2BC,UAAU;YAC7C,4DAA4D;YAC5D,gEAAgE;YAChEQ,mBAAmB;YACnBC,YAAYzE,QAAQ0E;YACpBC,aACE3E,UAAU;gBACR4E,SAAS5E;gBACTU,MAAMM;gBACN6D,eAAeX;gBACfY,uBAAuBX;gBACvBY,YAAY;oBACVC,SAAS/D;oBACTgE,SAASb;oBACTc,iBAAiBb;gBACnB;gBACAc,iBAAiB,CAACC,GAAG,EAAEzD,EAAE,EAAE;oBACzB2C,SAASe,OAAO,EAAEC,gBAAgB;wBAAEzE,MAAMc;oBAAG;gBAC/C;gBACA4D,gBAAgB;oBACdjB,SAASe,OAAO,EAAEG;gBACpB;YACF;sBAGD,CAAC,EAAExB,MAAM,EAAEf,KAAK,EAAE;gBACjB,qBACE,KAACvE;oBAAI+G,OAAO;wBAAEzB;wBAAQf;oBAAM;8BAC1B,cAAA,KAACxD;wBACCiB,MAAMK;wBACNkC,OAAOA;wBACPe,QAAQA;wBACR0B,YAAYC,QAAQhG,MAAMC,IAAI,CAAC8F,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,yBAA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AAS,GAAGF,eAAe,EAAE,CAAC;QAAC;kBACxC,cAAA,KAAC5D;YACCiE,OAAOD,2BAA2BC,SAAS;YAC3CC,QAAQF,2BAA2BE,UAAU;YAC7C,4DAA4D;YAC5D,gEAAgE;YAChEQ,mBAAmB;YACnBC,YAAYpD,QAAQqD;YACpBC,aACEtD,UAAU;gBACRuD,SAASvD;gBACTU,MAAMsB;gBACNwB,eAAeX;gBACfY,uBAAuBX;gBACvBY,YAAY;oBACVC,SAAS1B;oBACT2B,SAASb;oBACTc,iBAAiBb;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"}
@@ -27,6 +27,7 @@ const _components = require("echarts/components");
27
27
  const _renderers = require("echarts/renderers");
28
28
  const _material = require("@mui/material");
29
29
  const _components1 = require("@perses-dev/components");
30
+ const _utils = require("./utils");
30
31
  (0, _core.use)([
31
32
  _charts.PieChart,
32
33
  _components.GridComponent,
@@ -37,13 +38,13 @@ const _components1 = require("@perses-dev/components");
37
38
  _renderers.CanvasRenderer
38
39
  ]);
39
40
  function PieChartBase(props) {
40
- const { width, height, data, showLabels } = props;
41
+ const { width, height, data, mode, formatOptions, showLabels } = props;
41
42
  const chartsTheme = (0, _components1.useChartsTheme)();
42
43
  const muiTheme = (0, _material.useTheme)();
43
44
  const option = {
44
45
  tooltip: {
45
46
  trigger: 'item',
46
- formatter: '{b}: {c} ({d}%)',
47
+ formatter: (0, _utils.getTooltipFormatter)(formatOptions),
47
48
  appendTo: document.body,
48
49
  confine: false
49
50
  },
@@ -55,7 +56,7 @@ function PieChartBase(props) {
55
56
  show: Boolean(showLabels),
56
57
  position: 'inner',
57
58
  fontSize: 14,
58
- formatter: '{b}\n{c}',
59
+ formatter: (0, _utils.getLabelFormatter)(mode, formatOptions),
59
60
  overflow: 'truncate',
60
61
  fontWeight: 'bold'
61
62
  },
@@ -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, _core.isPercentUnit)(format)
160
+ disablePercentageMode: (0, _components.isPercentUnit)(format)
162
161
  })
163
162
  ]
164
163
  })
@@ -1,4 +1,4 @@
1
- //Copyright 2024 The Perses Authors
1
+ // Copyright The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -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");
@@ -36,7 +35,7 @@ function _interop_require_default(obj) {
36
35
  };
37
36
  }
38
37
  function PieChartPanel(props) {
39
- const { spec: { calculation, sort, mode, legend: pieChartLegend, colorPalette: colorPalette }, contentDimensions, queryResults } = props;
38
+ const { spec: { calculation, sort, mode, format: formatOptions, legend: pieChartLegend, colorPalette: colorPalette }, contentDimensions, queryResults } = props;
40
39
  const chartsTheme = (0, _components.useChartsTheme)();
41
40
  const chartId = (0, _components.useId)('time-series-panel');
42
41
  const seriesNames = queryResults.flatMap((result)=>result?.data.series?.map((series)=>series.name) || []);
@@ -47,11 +46,9 @@ function PieChartPanel(props) {
47
46
  colorPalette,
48
47
  seriesNames
49
48
  ]);
50
- const { pieChartData, legendItems, legendColumns } = (0, _react.useMemo)(()=>{
51
- const calculate = _core.CalculationsMap[calculation];
49
+ const pieChartData = (0, _react.useMemo)(()=>{
50
+ const calculate = _pluginsystem.CalculationsMap[calculation];
52
51
  const pieChartData = [];
53
- const legendItems = [];
54
- const legendColumns = [];
55
52
  queryResults.forEach((result, queryIndex)=>{
56
53
  const series = result?.data.series ?? [];
57
54
  series.forEach((seriesData, seriesIndex)=>{
@@ -66,74 +63,30 @@ function PieChartPanel(props) {
66
63
  }
67
64
  };
68
65
  pieChartData.push(seriesItem);
69
- legendItems.push({
70
- id: seriesId,
71
- label: seriesData.formattedName ?? '',
72
- color: seriesColor,
73
- data: {}
74
- });
75
66
  });
76
67
  });
77
- const sortedPieChartData = (0, _utils.sortSeriesData)(pieChartData, sort);
78
- // Reorder legend items to reflect the current sorting order of series
79
- const valueById = new Map(sortedPieChartData.map((pd)=>[
80
- pd.id ?? pd.name,
81
- pd.value ?? 0
82
- ]));
83
- legendItems.sort((a, b)=>{
84
- const av = valueById.get(a.id) ?? 0;
85
- const bv = valueById.get(b.id) ?? 0;
86
- return sort === 'asc' ? av - bv : bv - av;
87
- });
88
- if (pieChartLegend?.values?.length && pieChartLegend?.mode === 'table') {
89
- const { values } = pieChartLegend;
90
- [
91
- ...values
92
- ].sort().forEach((v)=>{
93
- /* First, create a column for the current legend value */ legendColumns.push({
94
- accessorKey: `data.${v}`,
95
- header: _pluginsystem.comparisonLegends[v]?.label || v,
96
- headerDescription: _pluginsystem.comparisonLegends[v]?.description,
97
- width: 90,
98
- align: 'right',
99
- cellDescription: true,
100
- enableSorting: true
101
- });
102
- /* Then, settle the legend items related to this legend value */ switch(v){
103
- case 'abs':
104
- legendItems.forEach((li)=>{
105
- const { value: itemAbsoluteValue } = pieChartData.find((pd)=>li.id === pd.id) || {};
106
- if (typeof itemAbsoluteValue === 'number' && li.data) {
107
- li.data['abs'] = itemAbsoluteValue;
108
- }
109
- });
110
- break;
111
- case 'relative':
112
- legendItems.forEach((li)=>{
113
- const { value: itemPercentageValue } = (0, _utils.calculatePercentages)(sortedPieChartData).find((ppd)=>li.id === ppd.id) || {};
114
- if (typeof itemPercentageValue === 'number' && li.data) {
115
- li.data['relative'] = `${itemPercentageValue.toFixed(2)}%`;
116
- }
117
- });
118
- break;
119
- default:
120
- break;
121
- }
122
- });
123
- }
68
+ return (0, _utils.sortSeriesData)(pieChartData, sort);
69
+ }, [
70
+ calculation,
71
+ chartId,
72
+ colorList,
73
+ queryResults,
74
+ sort
75
+ ]);
76
+ const { legendItems, legendColumns } = (0, _react.useMemo)(()=>{
77
+ const pieChartLegendMapper = pieChartLegend?.mode === 'table' ? new _utils.PieChartTableLegendMapper() : new _utils.PieChartListLegendMapper();
78
+ const values = pieChartLegend?.values;
79
+ const legendItems = pieChartLegendMapper.mapToLegendItems(pieChartData, values);
80
+ const legendColumns = pieChartLegendMapper.mapToLegendColumns(values, formatOptions);
124
81
  return {
125
- pieChartData: mode === 'percentage' ? (0, _utils.calculatePercentages)(sortedPieChartData) : sortedPieChartData,
126
82
  legendItems,
127
83
  legendColumns
128
84
  };
129
85
  }, [
130
- calculation,
131
- sort,
132
- mode,
133
- queryResults,
134
- colorList,
135
- chartId,
136
- pieChartLegend
86
+ formatOptions,
87
+ pieChartData,
88
+ pieChartLegend?.mode,
89
+ pieChartLegend?.values
137
90
  ]);
138
91
  const contentPadding = chartsTheme.container.padding.default;
139
92
  const adjustedContentDimensions = contentDimensions ? {
@@ -141,7 +94,7 @@ function PieChartPanel(props) {
141
94
  height: contentDimensions.height - contentPadding * 2
142
95
  } : undefined;
143
96
  const legend = (0, _react.useMemo)(()=>{
144
- return props.spec.legend && (0, _pluginsystem.validateLegendSpec)(props.spec.legend) ? (0, _merge.default)({}, _core.DEFAULT_LEGEND, props.spec.legend) : undefined;
97
+ return props.spec.legend && (0, _pluginsystem.validateLegendSpec)(props.spec.legend) ? (0, _merge.default)({}, _components.DEFAULT_LEGEND, props.spec.legend) : undefined;
145
98
  }, [
146
99
  props.spec.legend
147
100
  ]);
@@ -191,6 +144,8 @@ function PieChartPanel(props) {
191
144
  data: pieChartData,
192
145
  width: width,
193
146
  height: height,
147
+ mode: mode,
148
+ formatOptions: formatOptions,
194
149
  showLabels: Boolean(props.spec.showLabels)
195
150
  })
196
151
  });
@@ -34,7 +34,7 @@ _export(exports, {
34
34
  return createInitialPieChartOptions;
35
35
  }
36
36
  });
37
- const _core = require("@perses-dev/core");
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: _core.DEFAULT_CALCULATION,
46
+ calculation: _pluginsystem.DEFAULT_CALCULATION,
47
47
  format: DEFAULT_FORMAT,
48
48
  mode: DEFAULT_MODE,
49
49
  radius: 50,