@perses-dev/bar-chart-plugin 0.11.0 → 0.13.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) 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/BarChart.684cf4ee.js +7 -0
  87. package/__mf/js/async/121.697325de.js +2 -0
  88. package/__mf/js/async/177.83b4a0c7.js +1 -0
  89. package/__mf/js/async/187.dce780a3.js +24 -0
  90. package/__mf/js/async/{648.477ab52d.js.LICENSE.txt → 187.dce780a3.js.LICENSE.txt} +0 -16
  91. package/__mf/js/async/192.978ad416.js +1 -0
  92. package/__mf/js/async/235.dcb2a938.js +1 -0
  93. package/__mf/js/async/236.1e90c5b6.js +7 -0
  94. package/__mf/js/async/{955.120f903e.js.LICENSE.txt → 236.1e90c5b6.js.LICENSE.txt} +19 -1
  95. package/__mf/js/async/274.48038fad.js +2 -0
  96. package/__mf/js/async/356.3310d2e7.js +1 -0
  97. package/__mf/js/async/377.fbdc975f.js +1 -0
  98. package/__mf/js/async/392.2095dbb3.js +2 -0
  99. package/__mf/js/async/435.dc0a9a8a.js +1 -0
  100. package/__mf/js/async/{77.f584b802.js → 458.8fe7d3e6.js} +1 -1
  101. package/__mf/js/async/46.f0465d0c.js +101 -0
  102. package/__mf/js/async/470.306558f6.js +2 -0
  103. package/__mf/js/async/496.1c041ac9.js +1 -0
  104. package/__mf/js/async/568.0c8cf5cf.js +1 -0
  105. package/__mf/js/async/587.f983bd0d.js +1 -0
  106. package/__mf/js/async/588.c5433cac.js +1 -0
  107. package/__mf/js/async/616.3805dee7.js +1 -0
  108. package/__mf/js/async/71.63183692.js +1 -0
  109. package/__mf/js/async/721.497b5f27.js +1 -0
  110. package/__mf/js/async/77.317669de.js +1 -0
  111. package/__mf/js/async/823.d7e96856.js +10 -0
  112. package/__mf/js/async/{255.41e8af2d.js.LICENSE.txt → 823.d7e96856.js.LICENSE.txt} +1 -1
  113. package/__mf/js/async/854.c97a2bb3.js +1 -0
  114. package/__mf/js/async/873.be346a58.js +1 -0
  115. package/__mf/js/async/934.ffdb04e7.js +2 -0
  116. package/__mf/js/async/941.4dad52d6.js +2 -0
  117. package/__mf/js/async/958.30e78b21.js +39 -0
  118. package/__mf/js/async/{148.2fc9171f.js.LICENSE.txt → 958.30e78b21.js.LICENSE.txt} +17 -1
  119. package/__mf/js/async/963.2293b290.js +1 -0
  120. package/__mf/js/async/968.fc1dd4a5.js +1 -0
  121. package/__mf/js/async/978.fd94d741.js +1 -0
  122. package/__mf/js/async/__federation_expose_BarChart.44843c4d.js +1 -0
  123. package/__mf/js/async/lib-router.354c6b86.js +2 -0
  124. package/__mf/js/main.2ce2f26b.js +7 -0
  125. package/lib/BarChart.d.ts.map +1 -1
  126. package/lib/BarChart.js +8 -1
  127. package/lib/BarChart.js.map +1 -1
  128. package/lib/BarChartBase.d.ts +12 -2
  129. package/lib/BarChartBase.d.ts.map +1 -1
  130. package/lib/BarChartBase.js +104 -12
  131. package/lib/BarChartBase.js.map +1 -1
  132. package/lib/BarChartExportAction.d.ts +4 -0
  133. package/lib/BarChartExportAction.d.ts.map +1 -0
  134. package/lib/BarChartExportAction.js +70 -0
  135. package/lib/BarChartExportAction.js.map +1 -0
  136. package/lib/BarChartOptionsEditorSettings.d.ts.map +1 -1
  137. package/lib/BarChartOptionsEditorSettings.js +98 -29
  138. package/lib/BarChartOptionsEditorSettings.js.map +1 -1
  139. package/lib/BarChartPanel.d.ts +1 -1
  140. package/lib/BarChartPanel.d.ts.map +1 -1
  141. package/lib/BarChartPanel.js +71 -4
  142. package/lib/BarChartPanel.js.map +1 -1
  143. package/lib/bar-chart-model.d.ts +9 -3
  144. package/lib/bar-chart-model.d.ts.map +1 -1
  145. package/lib/bar-chart-model.js +8 -2
  146. package/lib/bar-chart-model.js.map +1 -1
  147. package/lib/cjs/BarChart.js +8 -1
  148. package/lib/cjs/BarChartBase.js +107 -15
  149. package/lib/cjs/BarChartExportAction.js +124 -0
  150. package/lib/cjs/BarChartOptionsEditorSettings.js +95 -26
  151. package/lib/cjs/BarChartPanel.js +72 -5
  152. package/lib/cjs/bar-chart-model.js +18 -3
  153. package/lib/tresholds.d.ts +1 -1
  154. package/lib/tresholds.d.ts.map +1 -1
  155. package/lib/tresholds.js.map +1 -1
  156. package/mf-manifest.json +76 -62
  157. package/mf-stats.json +92 -64
  158. package/package.json +4 -4
  159. package/__mf/css/async/442.d3010b86.css +0 -1
  160. package/__mf/css/async/61.d3010b86.css +0 -1
  161. package/__mf/css/async/823.d3010b86.css +0 -1
  162. package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
  163. package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
  164. package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
  165. package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
  166. package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
  167. package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
  168. package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
  169. package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
  170. package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
  171. package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
  172. package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
  173. package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
  174. package/__mf/js/BarChart.cded7431.js +0 -6
  175. package/__mf/js/async/102.b7abdc1f.js +0 -1
  176. package/__mf/js/async/121.517e00e8.js +0 -2
  177. package/__mf/js/async/148.2fc9171f.js +0 -102
  178. package/__mf/js/async/160.edce75b3.js +0 -1
  179. package/__mf/js/async/177.91621efa.js +0 -1
  180. package/__mf/js/async/192.73182890.js +0 -1
  181. package/__mf/js/async/204.d6cc804e.js +0 -1
  182. package/__mf/js/async/235.f90d3b9a.js +0 -38
  183. package/__mf/js/async/255.41e8af2d.js +0 -10
  184. package/__mf/js/async/274.9bfff28e.js +0 -2
  185. package/__mf/js/async/350.d8b63400.js +0 -1
  186. package/__mf/js/async/356.6146b01c.js +0 -1
  187. package/__mf/js/async/377.5b9c90dc.js +0 -1
  188. package/__mf/js/async/392.63dbc9c4.js +0 -2
  189. package/__mf/js/async/458.cffba90f.js +0 -1
  190. package/__mf/js/async/470.82e9b967.js +0 -2
  191. package/__mf/js/async/473.2df10452.js +0 -1
  192. package/__mf/js/async/496.b35b3a0a.js +0 -1
  193. package/__mf/js/async/587.bcc920f1.js +0 -1
  194. package/__mf/js/async/588.680cfad0.js +0 -1
  195. package/__mf/js/async/616.302bdae0.js +0 -1
  196. package/__mf/js/async/648.477ab52d.js +0 -22
  197. package/__mf/js/async/703.16dd2eaa.js +0 -2
  198. package/__mf/js/async/71.dab9ec76.js +0 -1
  199. package/__mf/js/async/854.7be16fdf.js +0 -1
  200. package/__mf/js/async/873.daa0c1ab.js +0 -1
  201. package/__mf/js/async/941.4efdb193.js +0 -2
  202. package/__mf/js/async/955.120f903e.js +0 -7
  203. package/__mf/js/async/963.85d5346b.js +0 -1
  204. package/__mf/js/async/968.d562d0d2.js +0 -1
  205. package/__mf/js/async/978.458b6e7d.js +0 -1
  206. package/__mf/js/async/__federation_expose_BarChart.f725ca63.js +0 -1
  207. package/__mf/js/async/lib-router.66821436.js +0 -2
  208. package/__mf/js/main.6e028457.js +0 -6
  209. /package/__mf/js/async/{121.517e00e8.js.LICENSE.txt → 121.697325de.js.LICENSE.txt} +0 -0
  210. /package/__mf/js/async/{274.9bfff28e.js.LICENSE.txt → 274.48038fad.js.LICENSE.txt} +0 -0
  211. /package/__mf/js/async/{392.63dbc9c4.js.LICENSE.txt → 392.2095dbb3.js.LICENSE.txt} +0 -0
  212. /package/__mf/js/async/{470.82e9b967.js.LICENSE.txt → 470.306558f6.js.LICENSE.txt} +0 -0
  213. /package/__mf/js/async/{703.16dd2eaa.js.LICENSE.txt → 934.ffdb04e7.js.LICENSE.txt} +0 -0
  214. /package/__mf/js/async/{941.4efdb193.js.LICENSE.txt → 941.4dad52d6.js.LICENSE.txt} +0 -0
  215. /package/__mf/js/async/{lib-router.66821436.js.LICENSE.txt → lib-router.354c6b86.js.LICENSE.txt} +0 -0
@@ -23,28 +23,97 @@ Object.defineProperty(exports, "BarChartBase", {
23
23
  const _jsxruntime = require("react/jsx-runtime");
24
24
  const _react = require("react");
25
25
  const _components = require("@perses-dev/components");
26
- const _core = require("@perses-dev/core");
27
- const _core1 = require("echarts/core");
26
+ const _core = require("echarts/core");
28
27
  const _charts = require("echarts/charts");
29
28
  const _components1 = require("echarts/components");
30
29
  const _renderers = require("echarts/renderers");
31
30
  const _material = require("@mui/material");
32
- (0, _core1.use)([
31
+ (0, _core.use)([
33
32
  _charts.BarChart,
34
33
  _components1.GridComponent,
35
34
  _components1.DatasetComponent,
36
35
  _components1.TitleComponent,
37
36
  _components1.TooltipComponent,
37
+ _components1.LegendComponent,
38
38
  _renderers.CanvasRenderer
39
39
  ]);
40
40
  const BAR_WIN_WIDTH = 14;
41
41
  const BAR_GAP = 6;
42
+ const LEGEND_HEIGHT = 20;
42
43
  function BarChartBase(props) {
43
44
  const { width, height, data, format = {
44
45
  unit: 'decimal'
45
- }, mode = 'value' } = props;
46
+ }, mode = 'value', groupedData, isStacked = false, orientation = 'horizontal' } = props;
46
47
  const chartsTheme = (0, _components.useChartsTheme)();
48
+ const isHorizontal = orientation === 'horizontal';
47
49
  const option = (0, _react.useMemo)(()=>{
50
+ if (groupedData) {
51
+ if (!groupedData.series.length || !groupedData.categories.length) return chartsTheme.noDataOption;
52
+ const { categories, series } = groupedData;
53
+ return {
54
+ title: {
55
+ show: false
56
+ },
57
+ legend: {
58
+ type: 'scroll',
59
+ show: true,
60
+ bottom: 0
61
+ },
62
+ xAxis: isHorizontal ? (0, _components.getFormattedAxis)({}, format) : {
63
+ type: 'category',
64
+ data: categories,
65
+ splitLine: {
66
+ show: false
67
+ },
68
+ axisLabel: {
69
+ overflow: 'truncate',
70
+ width: width / 3
71
+ }
72
+ },
73
+ yAxis: isHorizontal ? {
74
+ type: 'category',
75
+ data: categories,
76
+ splitLine: {
77
+ show: false
78
+ },
79
+ axisLabel: {
80
+ overflow: 'truncate',
81
+ width: width / 3
82
+ }
83
+ } : (0, _components.getFormattedAxis)({}, format),
84
+ series: series.map((s)=>({
85
+ name: s.name,
86
+ type: 'bar',
87
+ stack: isStacked ? 'total' : undefined,
88
+ data: s.values,
89
+ label: {
90
+ show: false
91
+ },
92
+ itemStyle: {
93
+ borderRadius: isStacked ? 0 : 4
94
+ }
95
+ })),
96
+ tooltip: {
97
+ trigger: 'axis',
98
+ axisPointer: {
99
+ type: 'shadow'
100
+ },
101
+ appendToBody: true,
102
+ confine: true,
103
+ formatter: (params)=>{
104
+ if (!params.length) return '';
105
+ const header = `<b>${params[0]?.name}</b><br/>`;
106
+ const rows = params.filter((p)=>p.data !== null).map((p)=>`<span style="display:inline-block;margin-right:5px;border-radius:50%;width:10px;height:10px;background-color:${p.color}"></span>` + `${p.seriesName}: <b>${(0, _components.formatValue)(p.data, format)}</b>`).join('<br/>');
107
+ return header + rows;
108
+ }
109
+ },
110
+ grid: {
111
+ left: '5%',
112
+ right: '5%',
113
+ bottom: LEGEND_HEIGHT * 2
114
+ }
115
+ };
116
+ }
48
117
  if (!data || !data.length) return chartsTheme.noDataOption;
49
118
  const source = [];
50
119
  data.map((d)=>{
@@ -66,8 +135,7 @@ function BarChartBase(props) {
66
135
  source: source
67
136
  }
68
137
  ],
69
- xAxis: (0, _components.getFormattedAxis)({}, format),
70
- yAxis: {
138
+ xAxis: isHorizontal ? (0, _components.getFormattedAxis)({}, format) : {
71
139
  type: 'category',
72
140
  splitLine: {
73
141
  show: false
@@ -77,25 +145,35 @@ function BarChartBase(props) {
77
145
  width: width / 3
78
146
  }
79
147
  },
148
+ yAxis: isHorizontal ? {
149
+ type: 'category',
150
+ splitLine: {
151
+ show: false
152
+ },
153
+ axisLabel: {
154
+ overflow: 'truncate',
155
+ width: width / 3
156
+ }
157
+ } : (0, _components.getFormattedAxis)({}, format),
80
158
  series: {
81
159
  type: 'bar',
160
+ barMinWidth: BAR_WIN_WIDTH,
161
+ barCategoryGap: BAR_GAP,
82
162
  label: {
83
163
  show: true,
84
- position: 'right',
164
+ position: isHorizontal ? 'right' : 'top',
85
165
  formatter: (params)=>{
86
166
  if (!params.data[1]) {
87
167
  return undefined;
88
168
  }
89
169
  if (mode === 'percentage') {
90
- return (0, _core.formatValue)(params.data[1], {
170
+ return (0, _components.formatValue)(params.data[1], {
91
171
  unit: 'percent',
92
172
  decimalPlaces: format.decimalPlaces
93
173
  });
94
174
  }
95
- return (0, _core.formatValue)(params.data[1], format);
96
- },
97
- barMinWidth: BAR_WIN_WIDTH,
98
- barCategoryGap: BAR_GAP
175
+ return (0, _components.formatValue)(params.data[1], format);
176
+ }
99
177
  },
100
178
  itemStyle: {
101
179
  borderRadius: 4,
@@ -105,7 +183,7 @@ function BarChartBase(props) {
105
183
  tooltip: {
106
184
  appendToBody: true,
107
185
  confine: true,
108
- formatter: (params)=>params.data[1] && `<b>${params.name}</b> &emsp; ${(0, _core.formatValue)(params.data[1], format)}`
186
+ formatter: (params)=>params.data[1] && `<b>${params.name}</b> &emsp; ${(0, _components.formatValue)(params.data[1], format)}`
109
187
  },
110
188
  // increase distance between grid and container to prevent y axis labels from getting cut off
111
189
  grid: {
@@ -115,11 +193,25 @@ function BarChartBase(props) {
115
193
  };
116
194
  }, [
117
195
  data,
196
+ groupedData,
197
+ isStacked,
118
198
  chartsTheme,
119
199
  width,
120
200
  mode,
121
- format
201
+ format,
202
+ isHorizontal
122
203
  ]);
204
+ const numGroupedRows = groupedData ? isStacked ? groupedData.categories.length : groupedData.categories.length * groupedData.series.length : 0;
205
+ function getChartHeight() {
206
+ if (groupedData) {
207
+ if (!isHorizontal) return height;
208
+ return Math.max(height, numGroupedRows * (BAR_WIN_WIDTH + BAR_GAP) + LEGEND_HEIGHT * 2 + 20);
209
+ }
210
+ if (data) {
211
+ return data.length * (BAR_WIN_WIDTH + BAR_GAP);
212
+ }
213
+ return '100%';
214
+ }
123
215
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
124
216
  style: {
125
217
  width: width,
@@ -131,7 +223,7 @@ function BarChartBase(props) {
131
223
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.EChart, {
132
224
  style: {
133
225
  minHeight: height,
134
- height: data ? data.length * (BAR_WIN_WIDTH + BAR_GAP) : '100%'
226
+ height: getChartHeight()
135
227
  },
136
228
  option: option,
137
229
  theme: chartsTheme.echartsTheme
@@ -0,0 +1,124 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "BarChartExportAction", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return BarChartExportAction;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
25
+ const _pluginsystem = require("@perses-dev/plugin-system");
26
+ const _components = require("@perses-dev/components");
27
+ const _material = require("@mui/material");
28
+ const _Download = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Download"));
29
+ function _interop_require_default(obj) {
30
+ return obj && obj.__esModule ? obj : {
31
+ default: obj
32
+ };
33
+ }
34
+ function _getRequireWildcardCache(nodeInterop) {
35
+ if (typeof WeakMap !== "function") return null;
36
+ var cacheBabelInterop = new WeakMap();
37
+ var cacheNodeInterop = new WeakMap();
38
+ return (_getRequireWildcardCache = function(nodeInterop) {
39
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
40
+ })(nodeInterop);
41
+ }
42
+ function _interop_require_wildcard(obj, nodeInterop) {
43
+ if (!nodeInterop && obj && obj.__esModule) {
44
+ return obj;
45
+ }
46
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
47
+ return {
48
+ default: obj
49
+ };
50
+ }
51
+ var cache = _getRequireWildcardCache(nodeInterop);
52
+ if (cache && cache.has(obj)) {
53
+ return cache.get(obj);
54
+ }
55
+ var newObj = {
56
+ __proto__: null
57
+ };
58
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
59
+ for(var key in obj){
60
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
61
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
62
+ if (desc && (desc.get || desc.set)) {
63
+ Object.defineProperty(newObj, key, desc);
64
+ } else {
65
+ newObj[key] = obj[key];
66
+ }
67
+ }
68
+ }
69
+ newObj.default = obj;
70
+ if (cache) {
71
+ cache.set(obj, newObj);
72
+ }
73
+ return newObj;
74
+ }
75
+ const BarChartExportAction = ({ queryResults, definition })=>{
76
+ const exportableData = (0, _react.useMemo)(()=>{
77
+ return (0, _pluginsystem.extractExportableData)(queryResults);
78
+ }, [
79
+ queryResults
80
+ ]);
81
+ const canExport = (0, _react.useMemo)(()=>{
82
+ return (0, _pluginsystem.isExportableData)(exportableData);
83
+ }, [
84
+ exportableData
85
+ ]);
86
+ const handleExport = (0, _react.useCallback)(()=>{
87
+ if (!exportableData || !canExport) return;
88
+ try {
89
+ const title = definition?.spec?.display?.name || 'Time Series Data';
90
+ const csvBlob = (0, _pluginsystem.exportDataAsCSV)({
91
+ data: exportableData
92
+ });
93
+ const baseFilename = (0, _pluginsystem.sanitizeFilename)(title);
94
+ const filename = `${baseFilename}_data.csv`;
95
+ const link = document.createElement('a');
96
+ link.href = URL.createObjectURL(csvBlob);
97
+ link.download = filename;
98
+ document.body.appendChild(link);
99
+ link.click();
100
+ document.body.removeChild(link);
101
+ URL.revokeObjectURL(link.href);
102
+ } catch (error) {
103
+ console.error('Time series export failed:', error);
104
+ }
105
+ }, [
106
+ exportableData,
107
+ canExport,
108
+ definition
109
+ ]);
110
+ if (!canExport) {
111
+ return null;
112
+ }
113
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.InfoTooltip, {
114
+ description: "Export as CSV",
115
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
116
+ size: "small",
117
+ onClick: handleExport,
118
+ "aria-label": "Export time series data as CSV",
119
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Download.default, {
120
+ fontSize: "inherit"
121
+ })
122
+ })
123
+ });
124
+ };
@@ -21,9 +21,9 @@ Object.defineProperty(exports, "BarChartOptionsEditorSettings", {
21
21
  }
22
22
  });
23
23
  const _jsxruntime = require("react/jsx-runtime");
24
+ const _react = require("react");
24
25
  const _material = require("@mui/material");
25
26
  const _components = require("@perses-dev/components");
26
- const _core = require("@perses-dev/core");
27
27
  const _pluginsystem = require("@perses-dev/plugin-system");
28
28
  const _immer = require("immer");
29
29
  const _merge = /*#__PURE__*/ _interop_require_default(require("lodash/merge"));
@@ -57,40 +57,109 @@ function BarChartOptionsEditorSettings(props) {
57
57
  };
58
58
  const handleResetSettings = ()=>{
59
59
  onChange((0, _immer.produce)(value, (draft)=>{
60
- draft.calculation = _core.DEFAULT_CALCULATION;
60
+ draft.calculation = _pluginsystem.DEFAULT_CALCULATION;
61
61
  draft.format = _barchartmodel.DEFAULT_FORMAT;
62
62
  draft.sort = _barchartmodel.DEFAULT_SORT;
63
63
  draft.mode = _barchartmodel.DEFAULT_MODE;
64
+ draft.groupBy = _barchartmodel.DEFAULT_GROUP_BY;
65
+ draft.isStacked = _barchartmodel.DEFAULT_IS_STACKED;
66
+ draft.orientation = _barchartmodel.DEFAULT_ORIENTATION;
64
67
  }));
65
68
  };
66
69
  // ensures decimalPlaces defaults to correct value
67
70
  const format = (0, _merge.default)({}, _barchartmodel.DEFAULT_FORMAT, value.format);
71
+ const groupBy = value.groupBy ?? _barchartmodel.DEFAULT_GROUP_BY;
72
+ const isStacked = value.isStacked ?? _barchartmodel.DEFAULT_IS_STACKED;
68
73
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGrid, {
69
74
  children: [
70
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorColumn, {
71
- children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGroup, {
72
- title: "Misc",
73
- children: [
74
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.FormatControls, {
75
- value: format,
76
- onChange: handleUnitChange,
77
- disabled: value.mode === 'percentage'
78
- }),
79
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.CalculationSelector, {
80
- value: value.calculation,
81
- onChange: handleCalculationChange
82
- }),
83
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SortSelector, {
84
- value: value.sort,
85
- onChange: handleSortChange
86
- }),
87
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ModeSelector, {
88
- value: value.mode,
89
- onChange: handleModeChange,
90
- disablePercentageMode: (0, _core.isPercentUnit)(format)
91
- })
92
- ]
93
- })
75
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorColumn, {
76
+ children: [
77
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGroup, {
78
+ title: "Misc",
79
+ children: [
80
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.FormatControls, {
81
+ value: format,
82
+ onChange: handleUnitChange,
83
+ disabled: value.mode === 'percentage'
84
+ }),
85
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.CalculationSelector, {
86
+ value: value.calculation,
87
+ onChange: handleCalculationChange
88
+ }),
89
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SortSelector, {
90
+ value: value.sort,
91
+ onChange: handleSortChange
92
+ }),
93
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ModeSelector, {
94
+ value: value.mode,
95
+ onChange: handleModeChange,
96
+ disablePercentageMode: (0, _components.isPercentUnit)(format)
97
+ }),
98
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.ToggleButtonGroup, {
99
+ exclusive: true,
100
+ size: "small",
101
+ value: value.orientation ?? 'horizontal',
102
+ onChange: (_, v)=>v && onChange((0, _immer.produce)(value, (draft)=>{
103
+ draft.orientation = v;
104
+ })),
105
+ children: [
106
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ToggleButton, {
107
+ value: "horizontal",
108
+ children: "Horizontal"
109
+ }),
110
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ToggleButton, {
111
+ value: "vertical",
112
+ children: "Vertical"
113
+ })
114
+ ]
115
+ })
116
+ ]
117
+ }),
118
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGroup, {
119
+ title: "Stacking",
120
+ children: [
121
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Autocomplete, {
122
+ multiple: true,
123
+ freeSolo: true,
124
+ value: groupBy,
125
+ onChange: (_, newValue)=>{
126
+ const filtered = newValue.filter((v)=>v.trim() !== '');
127
+ onChange((0, _immer.produce)(value, (draft)=>{
128
+ draft.groupBy = filtered;
129
+ if (filtered.length === 0) draft.isStacked = false;
130
+ }));
131
+ },
132
+ options: [],
133
+ renderTags: (tagValues, getTagProps)=>tagValues.map((option, index)=>/*#__PURE__*/ (0, _react.createElement)(_material.Chip, {
134
+ size: "small",
135
+ variant: "outlined",
136
+ label: option,
137
+ ...getTagProps({
138
+ index
139
+ }),
140
+ key: option
141
+ })),
142
+ renderInput: (params)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
143
+ ...params,
144
+ size: "small",
145
+ label: "Group By Labels",
146
+ placeholder: "Type label name + Enter"
147
+ })
148
+ }),
149
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.FormControlLabel, {
150
+ control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Switch, {
151
+ size: "small",
152
+ checked: isStacked,
153
+ disabled: groupBy.length === 0,
154
+ onChange: (e)=>onChange((0, _immer.produce)(value, (draft)=>{
155
+ draft.isStacked = e.target.checked;
156
+ }))
157
+ }),
158
+ label: "Stack bars"
159
+ })
160
+ ]
161
+ })
162
+ ]
94
163
  }),
95
164
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorColumn, {
96
165
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorGroup, {
@@ -24,15 +24,16 @@ const _jsxruntime = require("react/jsx-runtime");
24
24
  const _components = require("@perses-dev/components");
25
25
  const _material = require("@mui/material");
26
26
  const _react = require("react");
27
- const _core = require("@perses-dev/core");
27
+ const _pluginsystem = require("@perses-dev/plugin-system");
28
28
  const _utils = require("./utils");
29
29
  const _BarChartBase = require("./BarChartBase");
30
30
  function BarChartPanel(props) {
31
- const { spec: { calculation, format, sort, mode }, contentDimensions, queryResults } = props;
31
+ const { spec: { calculation, format, sort, mode, groupBy = [], isStacked = false, orientation = 'horizontal' }, contentDimensions, queryResults } = props;
32
32
  const chartsTheme = (0, _components.useChartsTheme)();
33
33
  const PADDING = chartsTheme.container.padding.default;
34
34
  const barChartData = (0, _react.useMemo)(()=>{
35
- const calculate = _core.CalculationsMap[calculation];
35
+ if (groupBy.length > 0) return [];
36
+ const calculate = _pluginsystem.CalculationsMap[calculation];
36
37
  const barChartData = [];
37
38
  for (const result of queryResults){
38
39
  for (const seriesData of result.data.series){
@@ -53,9 +54,72 @@ function BarChartPanel(props) {
53
54
  queryResults,
54
55
  sort,
55
56
  mode,
57
+ calculation,
58
+ groupBy
59
+ ]);
60
+ const stackedBarChartData = (0, _react.useMemo)(()=>{
61
+ if (groupBy.length === 0) return null;
62
+ const calculate = _pluginsystem.CalculationsMap[calculation];
63
+ const groupMap = new Map();
64
+ const segmentNamesOrdered = [];
65
+ const segmentNamesSet = new Set();
66
+ for (const queryResult of queryResults){
67
+ for (const seriesData of queryResult.data.series){
68
+ const labels = seriesData.labels ?? {};
69
+ const groupKey = groupBy.map((k)=>labels[k] ?? '').join(' / ');
70
+ const remainingEntries = Object.entries(labels).filter(([k])=>!groupBy.includes(k));
71
+ const segmentName = remainingEntries.length > 0 ? '{' + remainingEntries.map(([k, v])=>`${k}="${v}"`).join(', ') + '}' : seriesData.formattedName ?? seriesData.name;
72
+ if (!groupMap.has(groupKey)) {
73
+ groupMap.set(groupKey, new Map());
74
+ }
75
+ const segMap = groupMap.get(groupKey);
76
+ if (!segMap) continue;
77
+ const value = calculate(seriesData.values) ?? 0;
78
+ segMap.set(segmentName, (segMap.get(segmentName) ?? 0) + value);
79
+ if (!segmentNamesSet.has(segmentName)) {
80
+ segmentNamesSet.add(segmentName);
81
+ segmentNamesOrdered.push(segmentName);
82
+ }
83
+ }
84
+ }
85
+ if (groupMap.size === 0) return null;
86
+ const getTotalValue = (cat)=>Array.from(groupMap.get(cat)?.values() ?? []).reduce((a, b)=>a + b, 0);
87
+ let categories = Array.from(groupMap.keys());
88
+ if (sort === 'asc') {
89
+ categories = categories.sort((a, b)=>getTotalValue(a) - getTotalValue(b));
90
+ } else if (sort === 'desc') {
91
+ categories = categories.sort((a, b)=>getTotalValue(b) - getTotalValue(a));
92
+ }
93
+ const series = segmentNamesOrdered.map((segName)=>{
94
+ const values = categories.map((cat)=>{
95
+ const rawVal = groupMap.get(cat)?.get(segName) ?? null;
96
+ if (mode === 'percentage' && rawVal !== null) {
97
+ const total = getTotalValue(cat);
98
+ return total > 0 ? rawVal / total * 100 : 0;
99
+ }
100
+ return rawVal;
101
+ });
102
+ return {
103
+ name: segName,
104
+ values
105
+ };
106
+ });
107
+ return {
108
+ categories,
109
+ series
110
+ };
111
+ }, [
112
+ queryResults,
113
+ groupBy,
114
+ sort,
115
+ mode,
56
116
  calculation
57
117
  ]);
58
118
  if (contentDimensions === undefined) return null;
119
+ const effectiveFormat = mode === 'percentage' ? {
120
+ unit: 'percent',
121
+ decimalPlaces: format?.decimalPlaces
122
+ } : format;
59
123
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
60
124
  sx: {
61
125
  padding: `${PADDING}px`
@@ -64,8 +128,11 @@ function BarChartPanel(props) {
64
128
  width: contentDimensions.width - PADDING * 2,
65
129
  height: contentDimensions.height - PADDING * 2,
66
130
  data: barChartData,
67
- format: format,
68
- mode: mode
131
+ format: groupBy.length > 0 ? effectiveFormat : format,
132
+ mode: mode,
133
+ groupedData: stackedBarChartData,
134
+ isStacked: isStacked,
135
+ orientation: orientation
69
136
  })
70
137
  });
71
138
  }
@@ -24,9 +24,18 @@ _export(exports, {
24
24
  get DEFAULT_FORMAT () {
25
25
  return DEFAULT_FORMAT;
26
26
  },
27
+ get DEFAULT_GROUP_BY () {
28
+ return DEFAULT_GROUP_BY;
29
+ },
30
+ get DEFAULT_IS_STACKED () {
31
+ return DEFAULT_IS_STACKED;
32
+ },
27
33
  get DEFAULT_MODE () {
28
34
  return DEFAULT_MODE;
29
35
  },
36
+ get DEFAULT_ORIENTATION () {
37
+ return DEFAULT_ORIENTATION;
38
+ },
30
39
  get DEFAULT_SORT () {
31
40
  return DEFAULT_SORT;
32
41
  },
@@ -34,18 +43,24 @@ _export(exports, {
34
43
  return createInitialBarChartOptions;
35
44
  }
36
45
  });
37
- const _core = require("@perses-dev/core");
46
+ const _pluginsystem = require("@perses-dev/plugin-system");
38
47
  const DEFAULT_FORMAT = {
39
48
  unit: 'decimal',
40
49
  shortValues: true
41
50
  };
42
51
  const DEFAULT_SORT = 'desc';
43
52
  const DEFAULT_MODE = 'value';
53
+ const DEFAULT_ORIENTATION = 'horizontal';
54
+ const DEFAULT_GROUP_BY = [];
55
+ const DEFAULT_IS_STACKED = false;
44
56
  function createInitialBarChartOptions() {
45
57
  return {
46
- calculation: _core.DEFAULT_CALCULATION,
58
+ calculation: _pluginsystem.DEFAULT_CALCULATION,
47
59
  format: DEFAULT_FORMAT,
48
60
  sort: DEFAULT_SORT,
49
- mode: DEFAULT_MODE
61
+ mode: DEFAULT_MODE,
62
+ orientation: DEFAULT_ORIENTATION,
63
+ groupBy: DEFAULT_GROUP_BY,
64
+ isStacked: DEFAULT_IS_STACKED
50
65
  };
51
66
  }
@@ -1,4 +1,4 @@
1
- import { ThresholdColorPalette, ThresholdOptions, FormatOptions } from '@perses-dev/core';
1
+ import { FormatOptions, ThresholdColorPalette, ThresholdOptions } from '@perses-dev/components';
2
2
  export type GaugeColorStop = [number, string];
3
3
  export type EChartsAxisLineColors = GaugeColorStop[];
4
4
  export declare const defaultThresholdInput: ThresholdOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"tresholds.d.ts","sourceRoot":"","sources":["../../src/tresholds.ts"],"names":[],"mappings":"AAaA,OAAO,EAAe,qBAAqB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGvG,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9C,MAAM,MAAM,qBAAqB,GAAG,cAAc,EAAE,CAAC;AAErD,eAAO,MAAM,qBAAqB,EAAE,gBAA4C,CAAC;AAEjF,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,qBAAqB,GAC7B,qBAAqB,CA4BvB"}
1
+ {"version":3,"file":"tresholds.d.ts","sourceRoot":"","sources":["../../src/tresholds.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAe,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG7G,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE9C,MAAM,MAAM,qBAAqB,GAAG,cAAc,EAAE,CAAC;AAErD,eAAO,MAAM,qBAAqB,EAAE,gBAA4C,CAAC;AAEjF,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,gBAAgB,EAC5B,IAAI,EAAE,aAAa,EACnB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,qBAAqB,GAC7B,qBAAqB,CA4BvB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/tresholds.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 { StepOptions, ThresholdColorPalette, ThresholdOptions, FormatOptions } from '@perses-dev/core';\nimport zip from 'lodash/zip';\n\nexport type GaugeColorStop = [number, string];\n\nexport type EChartsAxisLineColors = GaugeColorStop[];\n\nexport const defaultThresholdInput: ThresholdOptions = { steps: [{ value: 0 }] };\n\nexport function convertThresholds(\n thresholds: ThresholdOptions,\n unit: FormatOptions,\n max: number,\n palette: ThresholdColorPalette\n): EChartsAxisLineColors {\n const defaultThresholdColor = thresholds.defaultColor ?? palette.defaultColor;\n const defaultThresholdSteps: EChartsAxisLineColors = [[0, defaultThresholdColor]];\n\n if (thresholds.steps !== undefined) {\n // https://echarts.apache.org/en/option.html#series-gauge.axisLine.lineStyle.color\n // color segments must be decimal between 0 and 1\n const segmentMax = 1;\n const valuesArr: number[] = thresholds.steps.map((step: StepOptions) => {\n if (thresholds.mode === 'percent') {\n return step.value / 100;\n }\n return step.value / max;\n });\n valuesArr.push(segmentMax);\n\n const colorsArr = thresholds.steps.map((step: StepOptions, index) => step.color ?? palette.palette[index]);\n colorsArr.unshift(defaultThresholdColor);\n\n const zippedArr = zip(valuesArr, colorsArr);\n return zippedArr.map((elem) => {\n const convertedValues = elem[0] ?? segmentMax;\n const convertedColors = elem[1] ?? defaultThresholdColor;\n return [convertedValues, convertedColors];\n });\n } else {\n return defaultThresholdSteps;\n }\n}\n"],"names":["zip","defaultThresholdInput","steps","value","convertThresholds","thresholds","unit","max","palette","defaultThresholdColor","defaultColor","defaultThresholdSteps","undefined","segmentMax","valuesArr","map","step","mode","push","colorsArr","index","color","unshift","zippedArr","elem","convertedValues","convertedColors"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,OAAOA,SAAS,aAAa;AAM7B,OAAO,MAAMC,wBAA0C;IAAEC,OAAO;QAAC;YAAEC,OAAO;QAAE;KAAE;AAAC,EAAE;AAEjF,OAAO,SAASC,kBACdC,UAA4B,EAC5BC,IAAmB,EACnBC,GAAW,EACXC,OAA8B;IAE9B,MAAMC,wBAAwBJ,WAAWK,YAAY,IAAIF,QAAQE,YAAY;IAC7E,MAAMC,wBAA+C;QAAC;YAAC;YAAGF;SAAsB;KAAC;IAEjF,IAAIJ,WAAWH,KAAK,KAAKU,WAAW;QAClC,kFAAkF;QAClF,iDAAiD;QACjD,MAAMC,aAAa;QACnB,MAAMC,YAAsBT,WAAWH,KAAK,CAACa,GAAG,CAAC,CAACC;YAChD,IAAIX,WAAWY,IAAI,KAAK,WAAW;gBACjC,OAAOD,KAAKb,KAAK,GAAG;YACtB;YACA,OAAOa,KAAKb,KAAK,GAAGI;QACtB;QACAO,UAAUI,IAAI,CAACL;QAEf,MAAMM,YAAYd,WAAWH,KAAK,CAACa,GAAG,CAAC,CAACC,MAAmBI,QAAUJ,KAAKK,KAAK,IAAIb,QAAQA,OAAO,CAACY,MAAM;QACzGD,UAAUG,OAAO,CAACb;QAElB,MAAMc,YAAYvB,IAAIc,WAAWK;QACjC,OAAOI,UAAUR,GAAG,CAAC,CAACS;YACpB,MAAMC,kBAAkBD,IAAI,CAAC,EAAE,IAAIX;YACnC,MAAMa,kBAAkBF,IAAI,CAAC,EAAE,IAAIf;YACnC,OAAO;gBAACgB;gBAAiBC;aAAgB;QAC3C;IACF,OAAO;QACL,OAAOf;IACT;AACF"}
1
+ {"version":3,"sources":["../../src/tresholds.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, StepOptions, ThresholdColorPalette, ThresholdOptions } from '@perses-dev/components';\nimport zip from 'lodash/zip';\n\nexport type GaugeColorStop = [number, string];\n\nexport type EChartsAxisLineColors = GaugeColorStop[];\n\nexport const defaultThresholdInput: ThresholdOptions = { steps: [{ value: 0 }] };\n\nexport function convertThresholds(\n thresholds: ThresholdOptions,\n unit: FormatOptions,\n max: number,\n palette: ThresholdColorPalette\n): EChartsAxisLineColors {\n const defaultThresholdColor = thresholds.defaultColor ?? palette.defaultColor;\n const defaultThresholdSteps: EChartsAxisLineColors = [[0, defaultThresholdColor]];\n\n if (thresholds.steps !== undefined) {\n // https://echarts.apache.org/en/option.html#series-gauge.axisLine.lineStyle.color\n // color segments must be decimal between 0 and 1\n const segmentMax = 1;\n const valuesArr: number[] = thresholds.steps.map((step: StepOptions) => {\n if (thresholds.mode === 'percent') {\n return step.value / 100;\n }\n return step.value / max;\n });\n valuesArr.push(segmentMax);\n\n const colorsArr = thresholds.steps.map((step: StepOptions, index) => step.color ?? palette.palette[index]);\n colorsArr.unshift(defaultThresholdColor);\n\n const zippedArr = zip(valuesArr, colorsArr);\n return zippedArr.map((elem) => {\n const convertedValues = elem[0] ?? segmentMax;\n const convertedColors = elem[1] ?? defaultThresholdColor;\n return [convertedValues, convertedColors];\n });\n } else {\n return defaultThresholdSteps;\n }\n}\n"],"names":["zip","defaultThresholdInput","steps","value","convertThresholds","thresholds","unit","max","palette","defaultThresholdColor","defaultColor","defaultThresholdSteps","undefined","segmentMax","valuesArr","map","step","mode","push","colorsArr","index","color","unshift","zippedArr","elem","convertedValues","convertedColors"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,OAAOA,SAAS,aAAa;AAM7B,OAAO,MAAMC,wBAA0C;IAAEC,OAAO;QAAC;YAAEC,OAAO;QAAE;KAAE;AAAC,EAAE;AAEjF,OAAO,SAASC,kBACdC,UAA4B,EAC5BC,IAAmB,EACnBC,GAAW,EACXC,OAA8B;IAE9B,MAAMC,wBAAwBJ,WAAWK,YAAY,IAAIF,QAAQE,YAAY;IAC7E,MAAMC,wBAA+C;QAAC;YAAC;YAAGF;SAAsB;KAAC;IAEjF,IAAIJ,WAAWH,KAAK,KAAKU,WAAW;QAClC,kFAAkF;QAClF,iDAAiD;QACjD,MAAMC,aAAa;QACnB,MAAMC,YAAsBT,WAAWH,KAAK,CAACa,GAAG,CAAC,CAACC;YAChD,IAAIX,WAAWY,IAAI,KAAK,WAAW;gBACjC,OAAOD,KAAKb,KAAK,GAAG;YACtB;YACA,OAAOa,KAAKb,KAAK,GAAGI;QACtB;QACAO,UAAUI,IAAI,CAACL;QAEf,MAAMM,YAAYd,WAAWH,KAAK,CAACa,GAAG,CAAC,CAACC,MAAmBI,QAAUJ,KAAKK,KAAK,IAAIb,QAAQA,OAAO,CAACY,MAAM;QACzGD,UAAUG,OAAO,CAACb;QAElB,MAAMc,YAAYvB,IAAIc,WAAWK;QACjC,OAAOI,UAAUR,GAAG,CAAC,CAACS;YACpB,MAAMC,kBAAkBD,IAAI,CAAC,EAAE,IAAIX;YACnC,MAAMa,kBAAkBF,IAAI,CAAC,EAAE,IAAIf;YACnC,OAAO;gBAACgB;gBAAiBC;aAAgB;QAC3C;IACF,OAAO;QACL,OAAOf;IACT;AACF"}