@perses-dev/stat-chart-plugin 0.12.1 → 0.13.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) 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/StatChart.8655e48a.js +7 -0
  87. package/__mf/js/async/121.86811fc5.js +2 -0
  88. package/__mf/js/async/177.47e93ede.js +1 -0
  89. package/__mf/js/async/192.c8e5200d.js +1 -0
  90. package/__mf/js/async/2.35776588.js +1 -0
  91. package/__mf/js/async/235.d89662f4.js +1 -0
  92. package/__mf/js/async/236.bc0e7181.js +7 -0
  93. package/__mf/js/async/{901.44b39122.js.LICENSE.txt → 236.bc0e7181.js.LICENSE.txt} +19 -1
  94. package/__mf/js/async/274.0a3b59a5.js +2 -0
  95. package/__mf/js/async/356.44f67235.js +1 -0
  96. package/__mf/js/async/392.342419bd.js +2 -0
  97. package/__mf/js/async/450.0ad74d00.js +1 -0
  98. package/__mf/js/async/465.178c329d.js +2 -0
  99. package/__mf/js/async/470.02952871.js +2 -0
  100. package/__mf/js/async/471.f69d2e5b.js +66 -0
  101. package/__mf/js/async/{119.b85eb681.js.LICENSE.txt → 471.f69d2e5b.js.LICENSE.txt} +11 -23
  102. package/__mf/js/async/558.0e64d762.js +1 -0
  103. package/__mf/js/async/568.c64a5ffb.js +24 -0
  104. package/__mf/js/async/{634.26891fea.js.LICENSE.txt → 568.c64a5ffb.js.LICENSE.txt} +0 -16
  105. package/__mf/js/async/570.f407deb7.js +2 -0
  106. package/__mf/js/async/587.806e94c8.js +1 -0
  107. package/__mf/js/async/588.5332d073.js +1 -0
  108. package/__mf/js/async/616.68b848ee.js +1 -0
  109. package/__mf/js/async/71.b1847413.js +1 -0
  110. package/__mf/js/async/721.bc9d8f7f.js +1 -0
  111. package/__mf/js/async/866.e6542737.js +83 -0
  112. package/__mf/js/async/866.e6542737.js.LICENSE.txt +27 -0
  113. package/__mf/js/async/873.05eb2387.js +1 -0
  114. package/__mf/js/async/941.349eff0d.js +2 -0
  115. package/__mf/js/async/968.86a4b472.js +1 -0
  116. package/__mf/js/async/978.6beaa6c4.js +1 -0
  117. package/__mf/js/async/__federation_expose_StatChart.c148f9d8.js +1 -0
  118. package/__mf/js/async/lib-router.040bbb94.js +2 -0
  119. package/__mf/js/main.3f92b718.js +7 -0
  120. package/lib/StatChartBase.d.ts +1 -2
  121. package/lib/StatChartBase.d.ts.map +1 -1
  122. package/lib/StatChartBase.js.map +1 -1
  123. package/lib/StatChartOptionsEditorSettings.js.map +1 -1
  124. package/lib/StatChartPanel.d.ts +1 -1
  125. package/lib/StatChartPanel.d.ts.map +1 -1
  126. package/lib/StatChartPanel.js +1 -2
  127. package/lib/StatChartPanel.js.map +1 -1
  128. package/lib/StatChartValueMappingEditor.d.ts.map +1 -1
  129. package/lib/StatChartValueMappingEditor.js.map +1 -1
  130. package/lib/cjs/StatChartPanel.js +2 -3
  131. package/lib/cjs/utils/calculate-value.js +4 -4
  132. package/lib/cjs/utils/format-stat-chart-value.js +2 -2
  133. package/lib/cjs/utils/get-color.js +2 -2
  134. package/lib/stat-chart-model.d.ts +3 -3
  135. package/lib/stat-chart-model.d.ts.map +1 -1
  136. package/lib/stat-chart-model.js.map +1 -1
  137. package/lib/utils/calculate-value.d.ts +2 -1
  138. package/lib/utils/calculate-value.d.ts.map +1 -1
  139. package/lib/utils/calculate-value.js +1 -1
  140. package/lib/utils/calculate-value.js.map +1 -1
  141. package/lib/utils/format-stat-chart-value.d.ts +1 -1
  142. package/lib/utils/format-stat-chart-value.d.ts.map +1 -1
  143. package/lib/utils/format-stat-chart-value.js +1 -1
  144. package/lib/utils/format-stat-chart-value.js.map +1 -1
  145. package/lib/utils/get-color.d.ts.map +1 -1
  146. package/lib/utils/get-color.js +1 -1
  147. package/lib/utils/get-color.js.map +1 -1
  148. package/mf-manifest.json +62 -51
  149. package/mf-stats.json +73 -51
  150. package/package.json +4 -4
  151. package/__mf/css/async/442.d3010b86.css +0 -1
  152. package/__mf/css/async/61.d3010b86.css +0 -1
  153. package/__mf/css/async/823.d3010b86.css +0 -1
  154. package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
  155. package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
  156. package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
  157. package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
  158. package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
  159. package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
  160. package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
  161. package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
  162. package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
  163. package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
  164. package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
  165. package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
  166. package/__mf/js/StatChart.d861cce0.js +0 -6
  167. package/__mf/js/async/119.b85eb681.js +0 -83
  168. package/__mf/js/async/121.3f61f76f.js +0 -2
  169. package/__mf/js/async/177.eb221fda.js +0 -1
  170. package/__mf/js/async/192.8a915b5e.js +0 -1
  171. package/__mf/js/async/2.086684e1.js +0 -1
  172. package/__mf/js/async/235.046777ba.js +0 -1
  173. package/__mf/js/async/274.d4e1eee8.js +0 -2
  174. package/__mf/js/async/293.d523e0ab.js +0 -1
  175. package/__mf/js/async/302.b54c0505.js +0 -2
  176. package/__mf/js/async/356.f5a1c439.js +0 -1
  177. package/__mf/js/async/392.b57d43bb.js +0 -2
  178. package/__mf/js/async/450.6c3d739b.js +0 -1
  179. package/__mf/js/async/465.fc9973fc.js +0 -2
  180. package/__mf/js/async/470.57be52e3.js +0 -2
  181. package/__mf/js/async/587.6d7b1a7f.js +0 -1
  182. package/__mf/js/async/588.496be9cb.js +0 -1
  183. package/__mf/js/async/604.e0d336cb.js +0 -65
  184. package/__mf/js/async/616.f83c59ff.js +0 -1
  185. package/__mf/js/async/634.26891fea.js +0 -24
  186. package/__mf/js/async/71.603fe88a.js +0 -1
  187. package/__mf/js/async/721.0467c07c.js +0 -1
  188. package/__mf/js/async/873.c0881a00.js +0 -1
  189. package/__mf/js/async/901.44b39122.js +0 -7
  190. package/__mf/js/async/941.c1c0755a.js +0 -2
  191. package/__mf/js/async/968.eb198ceb.js +0 -1
  192. package/__mf/js/async/978.c7471d24.js +0 -1
  193. package/__mf/js/async/__federation_expose_StatChart.61c049f1.js +0 -1
  194. package/__mf/js/async/lib-router.18b45155.js +0 -2
  195. package/__mf/js/main.4d2cb031.js +0 -6
  196. /package/__mf/js/async/{121.3f61f76f.js.LICENSE.txt → 121.86811fc5.js.LICENSE.txt} +0 -0
  197. /package/__mf/js/async/{274.d4e1eee8.js.LICENSE.txt → 274.0a3b59a5.js.LICENSE.txt} +0 -0
  198. /package/__mf/js/async/{392.b57d43bb.js.LICENSE.txt → 392.342419bd.js.LICENSE.txt} +0 -0
  199. /package/__mf/js/async/{465.fc9973fc.js.LICENSE.txt → 465.178c329d.js.LICENSE.txt} +0 -0
  200. /package/__mf/js/async/{470.57be52e3.js.LICENSE.txt → 470.02952871.js.LICENSE.txt} +0 -0
  201. /package/__mf/js/async/{302.b54c0505.js.LICENSE.txt → 570.f407deb7.js.LICENSE.txt} +0 -0
  202. /package/__mf/js/async/{941.c1c0755a.js.LICENSE.txt → 941.349eff0d.js.LICENSE.txt} +0 -0
  203. /package/__mf/js/async/{lib-router.18b45155.js.LICENSE.txt → lib-router.040bbb94.js.LICENSE.txt} +0 -0
@@ -1,7 +1,6 @@
1
1
  import { FC } from 'react';
2
- import { FormatOptions } from '@perses-dev/core';
3
2
  import { LineSeriesOption } from 'echarts/charts';
4
- import { FontSizeOption, GraphSeries } from '@perses-dev/components';
3
+ import { FontSizeOption, FormatOptions, GraphSeries } from '@perses-dev/components';
5
4
  import { ColorMode } from './stat-chart-model';
6
5
  export interface StatChartData {
7
6
  color: string;
@@ -1 +1 @@
1
- {"version":3,"file":"StatChartBase.d.ts","sourceRoot":"","sources":["../../src/StatChartBase.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,EAAE,EAAsB,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIjD,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGjF,OAAO,EAAU,cAAc,EAAE,WAAW,EAAkB,MAAM,wBAAwB,CAAC;AAI7F,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAW/C,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACzC,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,cAAc,CA4M5C,CAAC"}
1
+ {"version":3,"file":"StatChartBase.d.ts","sourceRoot":"","sources":["../../src/StatChartBase.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,EAAE,EAAsB,MAAM,OAAO,CAAC;AAI/C,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGjF,OAAO,EAAU,cAAc,EAAE,aAAa,EAAE,WAAW,EAAkB,MAAM,wBAAwB,CAAC;AAI5G,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAW/C,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACzC,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AAED,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,cAAc,CA4M5C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChartBase.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 { FC, ReactNode, useMemo } from 'react';\nimport { FormatOptions } from '@perses-dev/core';\nimport { Box, Typography, styled, useTheme } from '@mui/material';\nimport merge from 'lodash/merge';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, FontSizeOption, GraphSeries, useChartsTheme } from '@perses-dev/components';\nimport chroma from 'chroma-js';\nimport { useOptimalFontSize } from './utils/calculate-font-size';\nimport { formatStatChartValue } from './utils/format-stat-chart-value';\nimport { ColorMode } from './stat-chart-model';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst LINE_HEIGHT = 1.2;\nconst SERIES_NAME_MAX_FONT_SIZE = 30;\nconst SERIES_NAME_FONT_WEIGHT = 400;\nconst VALUE_FONT_WEIGHT = 700;\nconst WHITE_COLOR_CODE = '#FFFFFF';\nconst BLACK_COLOR_CODE = '#000000';\n\nexport interface StatChartData {\n color: string;\n calculatedValue?: string | number | null;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n format?: FormatOptions;\n sparkline?: LineSeriesOption;\n showSeriesName?: boolean;\n valueFontSize?: FontSizeOption;\n colorMode?: ColorMode;\n}\n\nexport const StatChartBase: FC<StatChartProps> = (props) => {\n const {\n width,\n height,\n data,\n data: { color },\n sparkline,\n showSeriesName,\n format,\n valueFontSize,\n colorMode,\n } = props;\n\n const {\n palette: {\n mode: paletteMode,\n text: { secondary },\n },\n } = useTheme();\n const chartsTheme = useChartsTheme();\n const formattedValue = formatStatChartValue(data.calculatedValue, format);\n const containerPadding = chartsTheme.container.padding.default;\n\n // calculate series name font size and height\n let seriesNameFontSize = useOptimalFontSize({\n text: data?.seriesData?.name ?? '',\n fontWeight: SERIES_NAME_FONT_WEIGHT,\n width,\n height: height * 0.125, // assume series name will take 12.5% of available height\n lineHeight: LINE_HEIGHT,\n maxSize: SERIES_NAME_MAX_FONT_SIZE,\n });\n\n const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;\n\n // calculate value font size and height\n const availableWidth = width - containerPadding * 2;\n const availableHeight = height - seriesNameHeight;\n const optimalValueFontSize = useOptimalFontSize({\n text: formattedValue,\n // override the font size if user selects it in the settings\n fontSizeOverride: valueFontSize,\n fontWeight: VALUE_FONT_WEIGHT,\n // without sparkline, use only 50% of the available width so it looks better for multiseries\n width: sparkline ? availableWidth : availableWidth * 0.5,\n // with sparkline, use only 25% of available height to leave room for chart\n // without sparkline, value should take up 90% of available space\n height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,\n lineHeight: LINE_HEIGHT,\n });\n const valueFontHeight = optimalValueFontSize * LINE_HEIGHT;\n\n // make sure the series name font size is slightly smaller than value font size\n seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (!data.seriesData) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline) {\n const lineSeries = {\n type: 'line',\n name: series.name,\n data: series.values,\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n\n const clonedSparkLine = { ...sparkline };\n if (colorMode === 'background_solid') {\n clonedSparkLine.areaStyle = { color: WHITE_COLOR_CODE, opacity: 0.4 };\n clonedSparkLine.lineStyle = { color: WHITE_COLOR_CODE, opacity: 1 };\n }\n\n const mergedSeries = merge(lineSeries, clonedSparkLine);\n statSeries.push(mergedSeries);\n }\n\n const option: EChartsCoreOption = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n min: (value: { min: number; max: number }): number => {\n if (value.min >= 0 && value.min <= 1) {\n // helps with percent-decimal units, or datasets that return 0 or 1 booleans\n return 0;\n }\n return value.min;\n },\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline, colorMode]);\n\n const textAlignment = sparkline ? 'auto' : 'center';\n\n const styledFormattedValue = useMemo(() => {\n let valueColor = '';\n\n switch (colorMode) {\n case 'background_solid':\n valueColor =\n chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE)\n ? WHITE_COLOR_CODE\n : BLACK_COLOR_CODE;\n break;\n case 'none':\n valueColor = paletteMode === 'dark' ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;\n break;\n case 'value':\n default:\n valueColor = color;\n break;\n }\n\n return (\n <Value variant=\"h3\" color={valueColor} fontSize={optimalValueFontSize} padding={containerPadding}>\n {formattedValue}\n </Value>\n );\n }, [colorMode, containerPadding, optimalValueFontSize, formattedValue, color, paletteMode]);\n\n const seriesName = useMemo((): ReactNode | null => {\n if (!showSeriesName) return null;\n\n let textColor = '';\n\n switch (colorMode) {\n case 'background_solid':\n textColor =\n chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE)\n ? WHITE_COLOR_CODE\n : BLACK_COLOR_CODE;\n break;\n case 'none':\n case 'value':\n default:\n textColor = secondary;\n break;\n }\n\n return (\n <SeriesName padding={containerPadding} fontSize={seriesNameFontSize} color={textColor}>\n {data.seriesData?.name}\n </SeriesName>\n );\n }, [colorMode, showSeriesName, secondary, color, containerPadding, seriesNameFontSize, data?.seriesData?.name]);\n\n return (\n <Box\n sx={{\n height: '100%',\n width: '100%',\n backgroundColor: colorMode === 'background_solid' ? color : 'transparent',\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n }}\n >\n {seriesName}\n {styledFormattedValue}\n {sparkline && (\n <EChart\n sx={{\n width: '100%',\n }}\n style={{\n // ECharts rounds the height to the nearest integer by default.\n // This can cause unneccessary scrollbars when the total height of this chart exceeds the 'height' prop.\n height: Math.floor(height - seriesNameHeight - valueFontHeight),\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n};\n\nconst SeriesName = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'padding' && prop !== 'fontSize',\n})<{ padding?: number; fontSize?: number; textAlignment?: string; color?: string }>(({ padding, fontSize, color }) => ({\n color: color,\n padding: `${padding}px`,\n fontSize: `${fontSize}px`,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n}));\n\nconst Value = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline',\n})<{ color?: string; padding?: number; fontSize?: number; sparkline?: boolean }>(\n ({ theme, color, padding, fontSize, sparkline }) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `${fontSize}px`,\n padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,\n whiteSpace: 'nowrap',\n lineHeight: LINE_HEIGHT,\n })\n);\n"],"names":["useMemo","Box","Typography","styled","useTheme","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","EChart","useChartsTheme","chroma","useOptimalFontSize","formatStatChartValue","LINE_HEIGHT","SERIES_NAME_MAX_FONT_SIZE","SERIES_NAME_FONT_WEIGHT","VALUE_FONT_WEIGHT","WHITE_COLOR_CODE","BLACK_COLOR_CODE","StatChartBase","props","width","height","data","color","sparkline","showSeriesName","format","valueFontSize","colorMode","palette","mode","paletteMode","text","secondary","chartsTheme","formattedValue","calculatedValue","containerPadding","container","padding","default","seriesNameFontSize","seriesData","name","fontWeight","lineHeight","maxSize","seriesNameHeight","availableWidth","availableHeight","optimalValueFontSize","fontSizeOverride","valueFontHeight","Math","min","option","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","clonedSparkLine","areaStyle","opacity","lineStyle","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","value","tooltip","textAlignment","styledFormattedValue","valueColor","contrast","Value","variant","fontSize","seriesName","textColor","SeriesName","sx","backgroundColor","display","flexDirection","justifyContent","alignItems","style","floor","theme","echartsTheme","renderer","shouldForwardProp","prop","overflow","textOverflow","whiteSpace","primary"],"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,SAAwBA,OAAO,QAAQ,QAAQ;AAE/C,SAASC,GAAG,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,gBAAgB;AAClE,OAAOC,WAAW,eAAe;AACjC,SAASC,GAAG,QAA2B,eAAe;AACtD,SAASC,aAAaC,gBAAgB,QAA0B,iBAAiB;AACjF,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,qBAAqB;AACvG,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,MAAM,EAA+BC,cAAc,QAAQ,yBAAyB;AAC7F,OAAOC,YAAY,YAAY;AAC/B,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,oBAAoB,QAAQ,kCAAkC;AAGvEZ,IAAI;IAACE;IAAkBC;IAAeC;IAAkBC;IAAgBC;IAAkBC;CAAe;AAEzG,MAAMM,cAAc;AACpB,MAAMC,4BAA4B;AAClC,MAAMC,0BAA0B;AAChC,MAAMC,oBAAoB;AAC1B,MAAMC,mBAAmB;AACzB,MAAMC,mBAAmB;AAmBzB,OAAO,MAAMC,gBAAoC,CAACC;IAChD,MAAM,EACJC,KAAK,EACLC,MAA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AQ,EAAEpE,KAAK,EAAE,GAAM,CAAA;QACrHA,OAAOA;QACPgB,SAAS,GAAGA,QAAQ,EAAE,CAAC;QACvBoD,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBiB,UAAU;QACVC,cAAc;QACdC,YAAY;IACd,CAAA;AAEA,MAAMrB,QAAQ7F,OAAOD,YAAY;IAC/B+G,mBAAmB,CAACC,OAASA,SAAS,WAAWA,SAAS,aAAaA,SAAS,cAAcA,SAAS;AACzG,GACE,CAAC,EAAEJ,KAAK,EAAEhF,KAAK,EAAEgB,OAAO,EAAEoD,QAAQ,EAAEnE,SAAS,EAAE,GAAM,CAAA;QACnDD,OAAOA,SAASgF,MAAM1E,OAAO,CAACG,IAAI,CAAC+E,OAAO;QAC1CpB,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBpD,SAASf,YAAY,GAAGe,QAAQ,GAAG,EAAEA,QAAQ,KAAK,EAAEA,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,EAAEA,QAAQ,EAAE,CAAC;QACnFuE,YAAY;QACZjE,YAAYjC;IACd,CAAA"}
1
+ {"version":3,"sources":["../../src/StatChartBase.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 { FC, ReactNode, useMemo } from 'react';\nimport { Box, Typography, styled, useTheme } from '@mui/material';\nimport merge from 'lodash/merge';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, FontSizeOption, FormatOptions, GraphSeries, useChartsTheme } from '@perses-dev/components';\nimport chroma from 'chroma-js';\nimport { useOptimalFontSize } from './utils/calculate-font-size';\nimport { formatStatChartValue } from './utils/format-stat-chart-value';\nimport { ColorMode } from './stat-chart-model';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst LINE_HEIGHT = 1.2;\nconst SERIES_NAME_MAX_FONT_SIZE = 30;\nconst SERIES_NAME_FONT_WEIGHT = 400;\nconst VALUE_FONT_WEIGHT = 700;\nconst WHITE_COLOR_CODE = '#FFFFFF';\nconst BLACK_COLOR_CODE = '#000000';\n\nexport interface StatChartData {\n color: string;\n calculatedValue?: string | number | null;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n format?: FormatOptions;\n sparkline?: LineSeriesOption;\n showSeriesName?: boolean;\n valueFontSize?: FontSizeOption;\n colorMode?: ColorMode;\n}\n\nexport const StatChartBase: FC<StatChartProps> = (props) => {\n const {\n width,\n height,\n data,\n data: { color },\n sparkline,\n showSeriesName,\n format,\n valueFontSize,\n colorMode,\n } = props;\n\n const {\n palette: {\n mode: paletteMode,\n text: { secondary },\n },\n } = useTheme();\n const chartsTheme = useChartsTheme();\n const formattedValue = formatStatChartValue(data.calculatedValue, format);\n const containerPadding = chartsTheme.container.padding.default;\n\n // calculate series name font size and height\n let seriesNameFontSize = useOptimalFontSize({\n text: data?.seriesData?.name ?? '',\n fontWeight: SERIES_NAME_FONT_WEIGHT,\n width,\n height: height * 0.125, // assume series name will take 12.5% of available height\n lineHeight: LINE_HEIGHT,\n maxSize: SERIES_NAME_MAX_FONT_SIZE,\n });\n\n const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;\n\n // calculate value font size and height\n const availableWidth = width - containerPadding * 2;\n const availableHeight = height - seriesNameHeight;\n const optimalValueFontSize = useOptimalFontSize({\n text: formattedValue,\n // override the font size if user selects it in the settings\n fontSizeOverride: valueFontSize,\n fontWeight: VALUE_FONT_WEIGHT,\n // without sparkline, use only 50% of the available width so it looks better for multiseries\n width: sparkline ? availableWidth : availableWidth * 0.5,\n // with sparkline, use only 25% of available height to leave room for chart\n // without sparkline, value should take up 90% of available space\n height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,\n lineHeight: LINE_HEIGHT,\n });\n const valueFontHeight = optimalValueFontSize * LINE_HEIGHT;\n\n // make sure the series name font size is slightly smaller than value font size\n seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (!data.seriesData) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline) {\n const lineSeries = {\n type: 'line',\n name: series.name,\n data: series.values,\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n\n const clonedSparkLine = { ...sparkline };\n if (colorMode === 'background_solid') {\n clonedSparkLine.areaStyle = { color: WHITE_COLOR_CODE, opacity: 0.4 };\n clonedSparkLine.lineStyle = { color: WHITE_COLOR_CODE, opacity: 1 };\n }\n\n const mergedSeries = merge(lineSeries, clonedSparkLine);\n statSeries.push(mergedSeries);\n }\n\n const option: EChartsCoreOption = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n min: (value: { min: number; max: number }): number => {\n if (value.min >= 0 && value.min <= 1) {\n // helps with percent-decimal units, or datasets that return 0 or 1 booleans\n return 0;\n }\n return value.min;\n },\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline, colorMode]);\n\n const textAlignment = sparkline ? 'auto' : 'center';\n\n const styledFormattedValue = useMemo(() => {\n let valueColor = '';\n\n switch (colorMode) {\n case 'background_solid':\n valueColor =\n chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE)\n ? WHITE_COLOR_CODE\n : BLACK_COLOR_CODE;\n break;\n case 'none':\n valueColor = paletteMode === 'dark' ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;\n break;\n case 'value':\n default:\n valueColor = color;\n break;\n }\n\n return (\n <Value variant=\"h3\" color={valueColor} fontSize={optimalValueFontSize} padding={containerPadding}>\n {formattedValue}\n </Value>\n );\n }, [colorMode, containerPadding, optimalValueFontSize, formattedValue, color, paletteMode]);\n\n const seriesName = useMemo((): ReactNode | null => {\n if (!showSeriesName) return null;\n\n let textColor = '';\n\n switch (colorMode) {\n case 'background_solid':\n textColor =\n chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE)\n ? WHITE_COLOR_CODE\n : BLACK_COLOR_CODE;\n break;\n case 'none':\n case 'value':\n default:\n textColor = secondary;\n break;\n }\n\n return (\n <SeriesName padding={containerPadding} fontSize={seriesNameFontSize} color={textColor}>\n {data.seriesData?.name}\n </SeriesName>\n );\n }, [colorMode, showSeriesName, secondary, color, containerPadding, seriesNameFontSize, data?.seriesData?.name]);\n\n return (\n <Box\n sx={{\n height: '100%',\n width: '100%',\n backgroundColor: colorMode === 'background_solid' ? color : 'transparent',\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n }}\n >\n {seriesName}\n {styledFormattedValue}\n {sparkline && (\n <EChart\n sx={{\n width: '100%',\n }}\n style={{\n // ECharts rounds the height to the nearest integer by default.\n // This can cause unneccessary scrollbars when the total height of this chart exceeds the 'height' prop.\n height: Math.floor(height - seriesNameHeight - valueFontHeight),\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n};\n\nconst SeriesName = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'padding' && prop !== 'fontSize',\n})<{ padding?: number; fontSize?: number; textAlignment?: string; color?: string }>(({ padding, fontSize, color }) => ({\n color: color,\n padding: `${padding}px`,\n fontSize: `${fontSize}px`,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n}));\n\nconst Value = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline',\n})<{ color?: string; padding?: number; fontSize?: number; sparkline?: boolean }>(\n ({ theme, color, padding, fontSize, sparkline }) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `${fontSize}px`,\n padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,\n whiteSpace: 'nowrap',\n lineHeight: LINE_HEIGHT,\n })\n);\n"],"names":["useMemo","Box","Typography","styled","useTheme","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","EChart","useChartsTheme","chroma","useOptimalFontSize","formatStatChartValue","LINE_HEIGHT","SERIES_NAME_MAX_FONT_SIZE","SERIES_NAME_FONT_WEIGHT","VALUE_FONT_WEIGHT","WHITE_COLOR_CODE","BLACK_COLOR_CODE","StatChartBase","props","width","height","data","color","sparkline","showSeriesName","format","valueFontSize","colorMode","palette","mode","paletteMode","text","secondary","chartsTheme","formattedValue","calculatedValue","containerPadding","container","padding","default","seriesNameFontSize","seriesData","name","fontWeight","lineHeight","maxSize","seriesNameHeight","availableWidth","availableHeight","optimalValueFontSize","fontSizeOverride","valueFontHeight","Math","min","option","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","clonedSparkLine","areaStyle","opacity","lineStyle","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","value","tooltip","textAlignment","styledFormattedValue","valueColor","contrast","Value","variant","fontSize","seriesName","textColor","SeriesName","sx","backgroundColor","display","flexDirection","justifyContent","alignItems","style","floor","theme","echartsTheme","renderer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,SAAS,cAAcA,SAAS;AACzG,GACE,CAAC,EAAEJ,KAAK,EAAEhF,KAAK,EAAEgB,OAAO,EAAEoD,QAAQ,EAAEnE,SAAS,EAAE,GAAM,CAAA;QACnDD,OAAOA,SAASgF,MAAM1E,OAAO,CAACG,IAAI,CAAC+E,OAAO;QAC1CpB,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBpD,SAASf,YAAY,GAAGe,QAAQ,GAAG,EAAEA,QAAQ,KAAK,EAAEA,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,EAAEA,QAAQ,EAAE,CAAC;QACnFuE,YAAY;QACZjE,YAAYjC;IACd,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChartOptionsEditorSettings.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 { Switch, SwitchProps } from '@mui/material';\nimport {\n FontSizeOption,\n FontSizeSelector,\n FontSizeSelectorProps,\n FormatControls,\n FormatControlsProps,\n OptionsEditorColumn,\n OptionsEditorControl,\n OptionsEditorGrid,\n OptionsEditorGroup,\n SettingsAutocomplete,\n ThresholdsEditor,\n ThresholdsEditorProps,\n} from '@perses-dev/components';\nimport { FormatOptions } from '@perses-dev/core';\nimport {\n CalculationSelector,\n CalculationSelectorProps,\n MetricLabelInput,\n MetricLabelInputProps,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport merge from 'lodash/merge';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport {\n COLOR_MODE_LABELS,\n ColorModeLabelItem,\n SHOW_LEGEND_LABELS,\n ShowLegendLabelItem,\n StatChartOptions,\n StatChartOptionsEditorProps,\n} from './stat-chart-model';\n\nconst DEFAULT_FORMAT: FormatOptions = { unit: 'percent-decimal' };\n\nexport function StatChartOptionsEditorSettings(props: StatChartOptionsEditorProps): ReactElement {\n const { onChange, value } = props;\n\n // ensures decimalPlaces defaults to correct value\n const format = merge({}, DEFAULT_FORMAT, value.format);\n\n const handleCalculationChange: CalculationSelectorProps['onChange'] = (metricLabel) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.calculation = metricLabel;\n })\n );\n };\n\n const handleMetricLabelChange: MetricLabelInputProps['onChange'] = (newCalculation) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.metricLabel = newCalculation;\n })\n );\n };\n\n const handleShowLegendChange = useCallback(\n (_: unknown, newShowLegend: ShowLegendLabelItem): void => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.legendMode = newShowLegend.id;\n })\n );\n },\n [onChange, value]\n );\n\n const handleUnitChange: FormatControlsProps['onChange'] = (newFormat) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.format = newFormat;\n })\n );\n };\n\n const handleSparklineChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n // For now, setting to an empty object when checked, so the stat chart\n // uses the default chart color and line styles. In the future, this\n // will likely be configurable in the UI.\n draft.sparkline = checked ? {} : undefined;\n })\n );\n };\n\n const handleThresholdsChange: ThresholdsEditorProps['onChange'] = (thresholds) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.thresholds = thresholds;\n })\n );\n };\n\n const handleFontSizeChange: FontSizeSelectorProps['onChange'] = (fontSize: FontSizeOption) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.valueFontSize = fontSize;\n })\n );\n };\n\n const handleColorModeChange = useCallback(\n (_: unknown, newColorMode: ColorModeLabelItem): void => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.colorMode = newColorMode.id;\n })\n );\n },\n [onChange, value]\n );\n\n const selectShowLegend = useMemo((): ReactElement => {\n return (\n <OptionsEditorControl\n label=\"Show\"\n control={\n <SettingsAutocomplete\n onChange={handleShowLegendChange}\n options={SHOW_LEGEND_LABELS}\n disableClearable\n value={\n SHOW_LEGEND_LABELS.find((i) => i.id === value.legendMode) ??\n SHOW_LEGEND_LABELS.find((i) => i.id === 'auto')!\n }\n />\n }\n />\n );\n }, [value.legendMode, handleShowLegendChange]);\n\n const selectColorMode = useMemo((): ReactElement => {\n return (\n <OptionsEditorControl\n label=\"Color mode\"\n control={\n <SettingsAutocomplete\n onChange={handleColorModeChange}\n options={COLOR_MODE_LABELS.map(({ id, label }) => ({ id, label }))}\n disableClearable\n value={\n COLOR_MODE_LABELS.find((i) => i.id === value.colorMode) ??\n COLOR_MODE_LABELS.find((i) => i.id === 'value')!\n }\n />\n }\n />\n );\n }, [value.colorMode, handleColorModeChange]);\n\n return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\n <OptionsEditorGroup title=\"Legend\">{selectShowLegend}</OptionsEditorGroup>\n <OptionsEditorGroup title=\"Misc\">\n <OptionsEditorControl\n label=\"Sparkline\"\n control={<Switch checked={!!value.sparkline} onChange={handleSparklineChange} />}\n />\n <FormatControls value={format} onChange={handleUnitChange} />\n <CalculationSelector value={value.calculation} onChange={handleCalculationChange} />\n <MetricLabelInput value={value.metricLabel} onChange={handleMetricLabelChange} />\n <FontSizeSelector value={value.valueFontSize} onChange={handleFontSizeChange} />\n {selectColorMode}\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n <OptionsEditorColumn>\n <ThresholdsEditor disablePercentMode thresholds={value.thresholds} onChange={handleThresholdsChange} />\n </OptionsEditorColumn>\n </OptionsEditorGrid>\n );\n}\n"],"names":["Switch","FontSizeSelector","FormatControls","OptionsEditorColumn","OptionsEditorControl","OptionsEditorGrid","OptionsEditorGroup","SettingsAutocomplete","ThresholdsEditor","CalculationSelector","MetricLabelInput","produce","merge","useCallback","useMemo","COLOR_MODE_LABELS","SHOW_LEGEND_LABELS","DEFAULT_FORMAT","unit","StatChartOptionsEditorSettings","props","onChange","value","format","handleCalculationChange","metricLabel","draft","calculation","handleMetricLabelChange","newCalculation","handleShowLegendChange","_","newShowLegend","legendMode","id","handleUnitChange","newFormat","handleSparklineChange","checked","sparkline","undefined","handleThresholdsChange","thresholds","handleFontSizeChange","fontSize","valueFontSize","handleColorModeChange","newColorMode","colorMode","selectShowLegend","label","control","options","disableClearable","find","i","selectColorMode","map","title","disablePercentMode"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAqB,gBAAgB;AACpD,SAEEC,gBAAgB,EAEhBC,cAAc,EAEdC,mBAAmB,EACnBC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,oBAAoB,EACpBC,gBAAgB,QAEX,yBAAyB;AAEhC,SACEC,mBAAmB,EAEnBC,gBAAgB,QAEX,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAChC,OAAOC,WAAW,eAAe;AACjC,SAAuBC,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC3D,SACEC,iBAAiB,EAEjBC,kBAAkB,QAIb,qBAAqB;AAE5B,MAAMC,iBAAgC;IAAEC,MAAM;AAAkB;AAEhE,OAAO,SAASC,+BAA+BC,KAAkC;IAC/E,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,kDAAkD;IAClD,MAAMG,SAASX,MAAM,CAAC,GAAGK,gBAAgBK,MAAMC,MAAM;IAErD,MAAMC,0BAAgE,CAACC;QACrEJ,SACEV,QAAQW,OAAO,CAACI;YACdA,MAAMC,WAAW,GAAGF;QACtB;IAEJ;IAEA,MAAMG,0BAA6D,CAACC;QA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ACE,KAACV;YACC8C,OAAM;YACNC,uBACE,KAAC5C;gBACCc,UAAUyB;gBACVM,SAASrC,kBAAkB0C,GAAG,CAAC,CAAC,EAAEvB,EAAE,EAAEgB,KAAK,EAAE,GAAM,CAAA;wBAAEhB;wBAAIgB;oBAAM,CAAA;gBAC/DG,gBAAgB;gBAChB/B,OACEP,kBAAkBuC,IAAI,CAAC,CAACC,IAAMA,EAAErB,EAAE,KAAKZ,MAAM0B,SAAS,KACtDjC,kBAAkBuC,IAAI,CAAC,CAACC,IAAMA,EAAErB,EAAE,KAAK;;;IAMnD,GAAG;QAACZ,MAAM0B,SAAS;QAAEF;KAAsB;IAE3C,qBACE,MAACzC;;0BACC,MAACF;;kCACC,KAACG;wBAAmBoD,OAAM;kCAAUT;;kCACpC,MAAC3C;wBAAmBoD,OAAM;;0CACxB,KAACtD;gCACC8C,OAAM;gCACNC,uBAAS,KAACnD;oCAAOsC,SAAS,CAAC,CAAChB,MAAMiB,SAAS;oCAAElB,UAAUgB;;;0CAEzD,KAACnC;gCAAeoB,OAAOC;gCAAQF,UAAUc;;0CACzC,KAAC1B;gCAAoBa,OAAOA,MAAMK,WAAW;gCAAEN,UAAUG;;0CACzD,KAACd;gCAAiBY,OAAOA,MAAMG,WAAW;gCAAEJ,UAAUO;;0CACtD,KAAC3B;gCAAiBqB,OAAOA,MAAMuB,aAAa;gCAAExB,UAAUsB;;4BACvDa;;;;;0BAGL,KAACrD;0BACC,cAAA,KAACK;oBAAiBmD,kBAAkB;oBAACjB,YAAYpB,MAAMoB,UAAU;oBAAErB,UAAUoB;;;;;AAIrF"}
1
+ {"version":3,"sources":["../../src/StatChartOptionsEditorSettings.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 { Switch, SwitchProps } from '@mui/material';\nimport {\n FontSizeOption,\n FontSizeSelector,\n FontSizeSelectorProps,\n FormatControls,\n FormatControlsProps,\n FormatOptions,\n OptionsEditorColumn,\n OptionsEditorControl,\n OptionsEditorGrid,\n OptionsEditorGroup,\n SettingsAutocomplete,\n ThresholdsEditor,\n ThresholdsEditorProps,\n} from '@perses-dev/components';\nimport {\n CalculationSelector,\n CalculationSelectorProps,\n MetricLabelInput,\n MetricLabelInputProps,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport merge from 'lodash/merge';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport {\n COLOR_MODE_LABELS,\n ColorModeLabelItem,\n SHOW_LEGEND_LABELS,\n ShowLegendLabelItem,\n StatChartOptions,\n StatChartOptionsEditorProps,\n} from './stat-chart-model';\n\nconst DEFAULT_FORMAT: FormatOptions = { unit: 'percent-decimal' };\n\nexport function StatChartOptionsEditorSettings(props: StatChartOptionsEditorProps): ReactElement {\n const { onChange, value } = props;\n\n // ensures decimalPlaces defaults to correct value\n const format = merge({}, DEFAULT_FORMAT, value.format);\n\n const handleCalculationChange: CalculationSelectorProps['onChange'] = (metricLabel) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.calculation = metricLabel;\n })\n );\n };\n\n const handleMetricLabelChange: MetricLabelInputProps['onChange'] = (newCalculation) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.metricLabel = newCalculation;\n })\n );\n };\n\n const handleShowLegendChange = useCallback(\n (_: unknown, newShowLegend: ShowLegendLabelItem): void => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.legendMode = newShowLegend.id;\n })\n );\n },\n [onChange, value]\n );\n\n const handleUnitChange: FormatControlsProps['onChange'] = (newFormat) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.format = newFormat;\n })\n );\n };\n\n const handleSparklineChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n // For now, setting to an empty object when checked, so the stat chart\n // uses the default chart color and line styles. In the future, this\n // will likely be configurable in the UI.\n draft.sparkline = checked ? {} : undefined;\n })\n );\n };\n\n const handleThresholdsChange: ThresholdsEditorProps['onChange'] = (thresholds) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.thresholds = thresholds;\n })\n );\n };\n\n const handleFontSizeChange: FontSizeSelectorProps['onChange'] = (fontSize: FontSizeOption) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.valueFontSize = fontSize;\n })\n );\n };\n\n const handleColorModeChange = useCallback(\n (_: unknown, newColorMode: ColorModeLabelItem): void => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.colorMode = newColorMode.id;\n })\n );\n },\n [onChange, value]\n );\n\n const selectShowLegend = useMemo((): ReactElement => {\n return (\n <OptionsEditorControl\n label=\"Show\"\n control={\n <SettingsAutocomplete\n onChange={handleShowLegendChange}\n options={SHOW_LEGEND_LABELS}\n disableClearable\n value={\n SHOW_LEGEND_LABELS.find((i) => i.id === value.legendMode) ??\n SHOW_LEGEND_LABELS.find((i) => i.id === 'auto')!\n }\n />\n }\n />\n );\n }, [value.legendMode, handleShowLegendChange]);\n\n const selectColorMode = useMemo((): ReactElement => {\n return (\n <OptionsEditorControl\n label=\"Color mode\"\n control={\n <SettingsAutocomplete\n onChange={handleColorModeChange}\n options={COLOR_MODE_LABELS.map(({ id, label }) => ({ id, label }))}\n disableClearable\n value={\n COLOR_MODE_LABELS.find((i) => i.id === value.colorMode) ??\n COLOR_MODE_LABELS.find((i) => i.id === 'value')!\n }\n />\n }\n />\n );\n }, [value.colorMode, handleColorModeChange]);\n\n return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\n <OptionsEditorGroup title=\"Legend\">{selectShowLegend}</OptionsEditorGroup>\n <OptionsEditorGroup title=\"Misc\">\n <OptionsEditorControl\n label=\"Sparkline\"\n control={<Switch checked={!!value.sparkline} onChange={handleSparklineChange} />}\n />\n <FormatControls value={format} onChange={handleUnitChange} />\n <CalculationSelector value={value.calculation} onChange={handleCalculationChange} />\n <MetricLabelInput value={value.metricLabel} onChange={handleMetricLabelChange} />\n <FontSizeSelector value={value.valueFontSize} onChange={handleFontSizeChange} />\n {selectColorMode}\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n <OptionsEditorColumn>\n <ThresholdsEditor disablePercentMode thresholds={value.thresholds} onChange={handleThresholdsChange} />\n </OptionsEditorColumn>\n </OptionsEditorGrid>\n );\n}\n"],"names":["Switch","FontSizeSelector","FormatControls","OptionsEditorColumn","OptionsEditorControl","OptionsEditorGrid","OptionsEditorGroup","SettingsAutocomplete","ThresholdsEditor","CalculationSelector","MetricLabelInput","produce","merge","useCallback","useMemo","COLOR_MODE_LABELS","SHOW_LEGEND_LABELS","DEFAULT_FORMAT","unit","StatChartOptionsEditorSettings","props","onChange","value","format","handleCalculationChange","metricLabel","draft","calculation","handleMetricLabelChange","newCalculation","handleShowLegendChange","_","newShowLegend","legendMode","id","handleUnitChange","newFormat","handleSparklineChange","checked","sparkline","undefined","handleThresholdsChange","thresholds","handleFontSizeChange","fontSize","valueFontSize","handleColorModeChange","newColorMode","colorMode","selectShowLegend","label","control","options","disableClearable","find","i","selectColorMode","map","title","disablePercentMode"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAqB,gBAAgB;AACpD,SAEEC,gBAAgB,EAEhBC,cAAc,EAGdC,mBAAmB,EACnBC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,oBAAoB,EACpBC,gBAAgB,QAEX,yBAAyB;A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AAC1B;gCAAoBa,OAAOA,MAAMK,WAAW;gCAAEN,UAAUG;;0CACzD,KAACd;gCAAiBY,OAAOA,MAAMG,WAAW;gCAAEJ,UAAUO;;0CACtD,KAAC3B;gCAAiBqB,OAAOA,MAAMuB,aAAa;gCAAExB,UAAUsB;;4BACvDa;;;;;0BAGL,KAACrD;0BACC,cAAA,KAACK;oBAAiBmD,kBAAkB;oBAACjB,YAAYpB,MAAMoB,UAAU;oBAAErB,UAAUoB;;;;;AAIrF"}
@@ -1,6 +1,6 @@
1
1
  import { FC } from 'react';
2
- import { TimeSeriesData } from '@perses-dev/core';
3
2
  import { PanelProps } from '@perses-dev/plugin-system';
3
+ import { TimeSeriesData } from '@perses-dev/spec';
4
4
  import { StatChartOptions } from './stat-chart-model';
5
5
  export type StatChartPanelProps = PanelProps<StatChartOptions, TimeSeriesData>;
6
6
  export declare const StatChartPanel: FC<StatChartPanelProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"StatChartPanel.d.ts","sourceRoot":"","sources":["../../src/StatChartPanel.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,EAAE,EAAW,MAAM,OAAO,CAAC;AACpC,OAAO,EAAoD,cAAc,EAAgB,MAAM,kBAAkB,CAAC;AAClH,OAAO,EAAE,UAAU,EAAa,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAE/E,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CA0DlD,CAAC"}
1
+ {"version":3,"file":"StatChartPanel.d.ts","sourceRoot":"","sources":["../../src/StatChartPanel.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAE,EAAE,EAAW,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,UAAU,EAAa,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAU,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAE/E,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CA0DlD,CAAC"}
@@ -11,10 +11,9 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { useChartsTheme } from '@perses-dev/components';
14
+ import { useChartsTheme, applyValueMapping, createRegexFromString } from '@perses-dev/components';
15
15
  import { Stack, Typography } from '@mui/material';
16
16
  import { useMemo } from 'react';
17
- import { applyValueMapping, createRegexFromString } from '@perses-dev/core';
18
17
  import { convertSparkline } from './utils/data-transform';
19
18
  import { calculateValue } from './utils/calculate-value';
20
19
  import { getStatChartColor } from './utils/get-color';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChartPanel.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 { TitleComponentOption } from 'echarts';\nimport { useChartsTheme, GraphSeries, PersesChartsTheme } from '@perses-dev/components';\nimport { Stack, Typography, SxProps } from '@mui/material';\nimport { FC, useMemo } from 'react';\nimport { applyValueMapping, Labels, createRegexFromString, TimeSeriesData, ValueMapping } from '@perses-dev/core';\nimport { PanelProps, PanelData } from '@perses-dev/plugin-system';\nimport { StatChartOptions } from './stat-chart-model';\nimport { convertSparkline } from './utils/data-transform';\nimport { calculateValue } from './utils/calculate-value';\nimport { getStatChartColor } from './utils/get-color';\nimport { StatChartBase, StatChartData } from './StatChartBase';\n\nconst MIN_WIDTH = 100;\nconst SPACING = 2;\n\nexport type StatChartPanelProps = PanelProps<StatChartOptions, TimeSeriesData>;\n\nexport const StatChartPanel: FC<StatChartPanelProps> = (props) => {\n const { spec, contentDimensions, queryResults } = props;\n\n const { format, sparkline, valueFontSize: valueFontSize, colorMode } = spec;\n const chartsTheme = useChartsTheme();\n const statChartData = useStatChartData(queryResults, spec, chartsTheme);\n\n const isMultiSeries = statChartData.length > 1;\n\n // Handle three-state showLegend: 'on' | 'off' | 'auto' (or undefined for backward compatibility)\n const shouldShowLegend = spec.legendMode === 'on' ? true : spec.legendMode === 'off' ? false : isMultiSeries;\n\n if (!contentDimensions) return null;\n\n // Calculates chart width\n const spacing = SPACING * (statChartData.length - 1);\n let chartWidth = (contentDimensions.width - spacing) / statChartData.length;\n if (isMultiSeries && chartWidth < MIN_WIDTH) {\n chartWidth = MIN_WIDTH;\n }\n\n const noDataTextStyle = (chartsTheme.noDataOption.title as TitleComponentOption).textStyle;\n\n return (\n <Stack\n height={contentDimensions.height}\n width={contentDimensions.width}\n spacing={`${SPACING}px`}\n direction=\"row\"\n justifyContent={isMultiSeries ? 'left' : 'center'}\n alignItems=\"center\"\n sx={{\n overflowX: isMultiSeries ? 'scroll' : 'auto',\n }}\n >\n {statChartData.length ? (\n statChartData.map((series, index) => {\n const sparklineConfig = convertSparkline(chartsTheme, series.color, sparkline);\n\n return (\n <StatChartBase\n key={index}\n width={chartWidth}\n height={contentDimensions.height}\n data={series}\n format={format}\n sparkline={sparklineConfig}\n showSeriesName={shouldShowLegend}\n valueFontSize={valueFontSize}\n colorMode={colorMode}\n />\n );\n })\n ) : (\n <Typography sx={{ ...noDataTextStyle } as SxProps}>No data</Typography>\n )}\n </Stack>\n );\n};\n\nconst useStatChartData = (\n queryResults: Array<PanelData<TimeSeriesData>>,\n spec: StatChartOptions,\n chartsTheme: PersesChartsTheme\n): StatChartData[] => {\n return useMemo(() => {\n const { calculation, mappings, metricLabel } = spec;\n\n const statChartData: StatChartData[] = [];\n for (const result of queryResults) {\n for (const seriesData of result.data.series) {\n const calculatedValue = calculateValue(calculation, seriesData);\n\n // get label metric value\n const labelValue = getLabelValue(metricLabel, seriesData.labels);\n\n // get actual value to display\n const displayValue = getValueOrLabel(calculatedValue, mappings, labelValue);\n\n const color = getStatChartColor(chartsTheme, spec, calculatedValue);\n\n const series: GraphSeries = {\n name: seriesData.formattedName ?? '',\n values: seriesData.values,\n };\n\n statChartData.push({ calculatedValue: displayValue, seriesData: series, color });\n }\n }\n return statChartData;\n }, [queryResults, spec, chartsTheme]);\n};\n\nconst getValueOrLabel = (\n value?: number | null,\n mappings?: ValueMapping[],\n label?: string\n): string | number | undefined | null => {\n if (label) {\n return label;\n }\n if (mappings?.length && value !== undefined && value !== null) {\n return applyValueMapping(value, mappings).value;\n } else {\n return value;\n }\n};\n\nconst getLabelValue = (fieldLabel?: string, labels?: Labels): string | undefined => {\n if (!labels || !fieldLabel) {\n return undefined;\n }\n for (const [key, value] of Object.entries(labels)) {\n const regex = createRegexFromString(fieldLabel);\n if (regex.test(key)) {\n return value;\n }\n }\n return undefined;\n};\n"],"names":["useChartsTheme","Stack","Typography","useMemo","applyValueMapping","createRegexFromString","convertSparkline","calculateValue","getStatChartColor","StatChartBase","MIN_WIDTH","SPACING","StatChartPanel","props","spec","contentDimensions","queryResults","format","sparkline","valueFontSize","colorMode","chartsTheme","statChartData","useStatChartData","isMultiSeries","length","shouldShowLegend","legendMode","spacing","chartWidth","width","noDataTextStyle","noDataOption","title","textStyle","height","direction","justifyContent","alignItems","sx","overflowX","map","series","index","sparklineConfig","color","data","showSeriesName","calculation","mappings","metricLabel","result","seriesData","calculatedValue","labelValue","getLabelValue","labels","displayValue","getValueOrLabel","name","formattedName","values","push","value","label","undefined","fieldLabel","key","Object","entries","regex","test"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EA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B;IACT,GAAG;QAACN;QAAcF;QAAMO;KAAY;AACtC;AAEA,MAAMqC,kBAAkB,CACtBK,OACAd,UACAe;IAEA,IAAIA,OAAO;QACT,OAAOA;IACT;IACA,IAAIf,UAAUxB,UAAUsC,UAAUE,aAAaF,UAAU,MAAM;QAC7D,OAAO3D,kBAAkB2D,OAAOd,UAAUc,KAAK;IACjD,OAAO;QACL,OAAOA;IACT;AACF;AAEA,MAAMR,gBAAgB,CAACW,YAAqBV;IAC1C,IAAI,CAACA,UAAU,CAACU,YAAY;QAC1B,OAAOD;IACT;IACA,KAAK,MAAM,CAACE,KAAKJ,MAAM,IAAIK,OAAOC,OAAO,CAACb,QAAS;QACjD,MAAMc,QAAQjE,sBAAsB6D;QACpC,IAAII,MAAMC,IAAI,CAACJ,MAAM;YACnB,OAAOJ;QACT;IACF;IACA,OAAOE;AACT"}
1
+ {"version":3,"sources":["../../src/StatChartPanel.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 { TitleComponentOption } from 'echarts';\nimport {\n useChartsTheme,\n GraphSeries,\n PersesChartsTheme,\n ValueMapping,\n applyValueMapping,\n createRegexFromString,\n} from '@perses-dev/components';\nimport { Stack, Typography, SxProps } from '@mui/material';\nimport { FC, useMemo } from 'react';\nimport { PanelProps, PanelData } from '@perses-dev/plugin-system';\nimport { Labels, TimeSeriesData } from '@perses-dev/spec';\nimport { StatChartOptions } from './stat-chart-model';\nimport { convertSparkline } from './utils/data-transform';\nimport { calculateValue } from './utils/calculate-value';\nimport { getStatChartColor } from './utils/get-color';\nimport { StatChartBase, StatChartData } from './StatChartBase';\n\nconst MIN_WIDTH = 100;\nconst SPACING = 2;\n\nexport type StatChartPanelProps = PanelProps<StatChartOptions, TimeSeriesData>;\n\nexport const StatChartPanel: FC<StatChartPanelProps> = (props) => {\n const { spec, contentDimensions, queryResults } = props;\n\n const { format, sparkline, valueFontSize: valueFontSize, colorMode } = spec;\n const chartsTheme = useChartsTheme();\n const statChartData = useStatChartData(queryResults, spec, chartsTheme);\n\n const isMultiSeries = statChartData.length > 1;\n\n // Handle three-state showLegend: 'on' | 'off' | 'auto' (or undefined for backward compatibility)\n const shouldShowLegend = spec.legendMode === 'on' ? true : spec.legendMode === 'off' ? false : isMultiSeries;\n\n if (!contentDimensions) return null;\n\n // Calculates chart width\n const spacing = SPACING * (statChartData.length - 1);\n let chartWidth = (contentDimensions.width - spacing) / statChartData.length;\n if (isMultiSeries && chartWidth < MIN_WIDTH) {\n chartWidth = MIN_WIDTH;\n }\n\n const noDataTextStyle = (chartsTheme.noDataOption.title as TitleComponentOption).textStyle;\n\n return (\n <Stack\n height={contentDimensions.height}\n width={contentDimensions.width}\n spacing={`${SPACING}px`}\n direction=\"row\"\n justifyContent={isMultiSeries ? 'left' : 'center'}\n alignItems=\"center\"\n sx={{\n overflowX: isMultiSeries ? 'scroll' : 'auto',\n }}\n >\n {statChartData.length ? (\n statChartData.map((series, index) => {\n const sparklineConfig = convertSparkline(chartsTheme, series.color, sparkline);\n\n return (\n <StatChartBase\n key={index}\n width={chartWidth}\n height={contentDimensions.height}\n data={series}\n format={format}\n sparkline={sparklineConfig}\n showSeriesName={shouldShowLegend}\n valueFontSize={valueFontSize}\n colorMode={colorMode}\n />\n );\n })\n ) : (\n <Typography sx={{ ...noDataTextStyle } as SxProps}>No data</Typography>\n )}\n </Stack>\n );\n};\n\nconst useStatChartData = (\n queryResults: Array<PanelData<TimeSeriesData>>,\n spec: StatChartOptions,\n chartsTheme: PersesChartsTheme\n): StatChartData[] => {\n return useMemo(() => {\n const { calculation, mappings, metricLabel } = spec;\n\n const statChartData: StatChartData[] = [];\n for (const result of queryResults) {\n for (const seriesData of result.data.series) {\n const calculatedValue = calculateValue(calculation, seriesData);\n\n // get label metric value\n const labelValue = getLabelValue(metricLabel, seriesData.labels);\n\n // get actual value to display\n const displayValue = getValueOrLabel(calculatedValue, mappings, labelValue);\n\n const color = getStatChartColor(chartsTheme, spec, calculatedValue);\n\n const series: GraphSeries = {\n name: seriesData.formattedName ?? '',\n values: seriesData.values,\n };\n\n statChartData.push({ calculatedValue: displayValue, seriesData: series, color });\n }\n }\n return statChartData;\n }, [queryResults, spec, chartsTheme]);\n};\n\nconst getValueOrLabel = (\n value?: number | null,\n mappings?: ValueMapping[],\n label?: string\n): string | number | undefined | null => {\n if (label) {\n return label;\n }\n if (mappings?.length && value !== undefined && value !== null) {\n return applyValueMapping(value, mappings).value;\n } else {\n return value;\n }\n};\n\nconst getLabelValue = (fieldLabel?: string, labels?: Labels): string | undefined => {\n if (!labels || !fieldLabel) {\n return undefined;\n }\n for (const [key, value] of Object.entries(labels)) {\n const regex = createRegexFromString(fieldLabel);\n if (regex.test(key)) {\n return value;\n }\n }\n return undefined;\n};\n"],"names":["useChartsTheme","applyValueMapping","createRegexFromString","Stack","Typography","useMemo","convertSparkline","calculateValue","getStatChartColor","StatChartBase","MIN_WIDTH","SPACING","StatChartPanel","props","spec","contentDimensions","queryResults","format","sparkline","valueFontSize","colorMode","chartsTheme","statChartData","useStatChartData","isMultiSeries","length","shouldShowLegend","legendMode","spacing","chartWidth","width","noDataTextStyle","noDataOption","title","textStyle","height","direction","justifyContent","alignItems","sx","overflowX","map","series","index","sparklineConfig","color","data","showSeriesName","calculation","mappings","metricLabel","result","seriesData","calculatedValue","labelValue","getLabelValue","labels","displayValue","getValueOrLabel","name","formattedName","values","push","value","label","undefined","fieldLabel","key","Object","entries","regex","test"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE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A,MAAMqC,kBAAkB,CACtBK,OACAd,UACAe;IAEA,IAAIA,OAAO;QACT,OAAOA;IACT;IACA,IAAIf,UAAUxB,UAAUsC,UAAUE,aAAaF,UAAU,MAAM;QAC7D,OAAO9D,kBAAkB8D,OAAOd,UAAUc,KAAK;IACjD,OAAO;QACL,OAAOA;IACT;AACF;AAEA,MAAMR,gBAAgB,CAACW,YAAqBV;IAC1C,IAAI,CAACA,UAAU,CAACU,YAAY;QAC1B,OAAOD;IACT;IACA,KAAK,MAAM,CAACE,KAAKJ,MAAM,IAAIK,OAAOC,OAAO,CAACb,QAAS;QACjD,MAAMc,QAAQpE,sBAAsBgE;QACpC,IAAII,MAAMC,IAAI,CAACJ,MAAM;YACnB,OAAOJ;QACT;IACF;IACA,OAAOE;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"StatChartValueMappingEditor.d.ts","sourceRoot":"","sources":["../../src/StatChartValueMappingEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,MAAM,gCAAgC,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAEpF,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAAC,gCAAgC,CAM5E,CAAC"}
1
+ {"version":3,"file":"StatChartValueMappingEditor.d.ts","sourceRoot":"","sources":["../../src/StatChartValueMappingEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,MAAM,gCAAgC,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAEpF,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAAC,gCAAgC,CAM5E,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChartValueMappingEditor.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 { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { ValueMapping } from '@perses-dev/core';\nimport { ValueMappingsEditor } from '@perses-dev/components';\nimport { FC } from 'react';\nimport { StatChartOptions } from './stat-chart-model';\n\nexport type StatChartValueMappingEditorProps = OptionsEditorProps<StatChartOptions>;\n\nexport const StatChartValueMappingEditor: FC<StatChartValueMappingEditorProps> = ({ onChange, value }) => {\n function handleValueMappingChange(mappings: ValueMapping[]): void {\n onChange({ ...value, mappings });\n }\n\n return <ValueMappingsEditor mappings={value.mappings ?? []} onChange={handleValueMappingChange} />;\n};\n"],"names":["ValueMappingsEditor","StatChartValueMappingEditor","onChange","value","handleValueMappingChange","mappings"],"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;;AAIjC,SAASA,mBAAmB,QAAQ,yBAAyB;AAM7D,OAAO,MAAMC,8BAAoE,CAAC,EAAEC,QAAQ,EAAEC,KAAK,EAAE;IACnG,SAASC,yBAAyBC,QAAwB;QACxDH,SAAS;YAAE,GAAGC,KAAK;YAAEE;QAAS;IAChC;IAEA,qBAAO,KAACL;QAAoBK,UAAUF,MAAME,QAAQ,IAAI,EAAE;QAAEH,UAAUE;;AACxE,EAAE"}
1
+ {"version":3,"sources":["../../src/StatChartValueMappingEditor.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 { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { ValueMapping, ValueMappingsEditor } from '@perses-dev/components';\nimport { FC } from 'react';\nimport { StatChartOptions } from './stat-chart-model';\n\nexport type StatChartValueMappingEditorProps = OptionsEditorProps<StatChartOptions>;\n\nexport const StatChartValueMappingEditor: FC<StatChartValueMappingEditorProps> = ({ onChange, value }) => {\n function handleValueMappingChange(mappings: ValueMapping[]): void {\n onChange({ ...value, mappings });\n }\n\n return <ValueMappingsEditor mappings={value.mappings ?? []} onChange={handleValueMappingChange} />;\n};\n"],"names":["ValueMappingsEditor","StatChartValueMappingEditor","onChange","value","handleValueMappingChange","mappings"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAAuBA,mBAAmB,QAAQ,yBAAyB;AAM3E,OAAO,MAAMC,8BAAoE,CAAC,EAAEC,QAAQ,EAAEC,KAAK,EAAE;IACnG,SAASC,yBAAyBC,QAAwB;QACxDH,SAAS;YAAE,GAAGC,KAAK;YAAEE;QAAS;IAChC;IAEA,qBAAO,KAACL;QAAoBK,UAAUF,MAAME,QAAQ,IAAI,EAAE;QAAEH,UAAUE;;AACxE,EAAE"}
@@ -24,7 +24,6 @@ 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");
28
27
  const _datatransform = require("./utils/data-transform");
29
28
  const _calculatevalue = require("./utils/calculate-value");
30
29
  const _getcolor = require("./utils/get-color");
@@ -112,7 +111,7 @@ const getValueOrLabel = (value, mappings, label)=>{
112
111
  return label;
113
112
  }
114
113
  if (mappings?.length && value !== undefined && value !== null) {
115
- return (0, _core.applyValueMapping)(value, mappings).value;
114
+ return (0, _components.applyValueMapping)(value, mappings).value;
116
115
  } else {
117
116
  return value;
118
117
  }
@@ -122,7 +121,7 @@ const getLabelValue = (fieldLabel, labels)=>{
122
121
  return undefined;
123
122
  }
124
123
  for (const [key, value] of Object.entries(labels)){
125
- const regex = (0, _core.createRegexFromString)(fieldLabel);
124
+ const regex = (0, _components.createRegexFromString)(fieldLabel);
126
125
  if (regex.test(key)) {
127
126
  return value;
128
127
  }
@@ -20,11 +20,11 @@ Object.defineProperty(exports, "calculateValue", {
20
20
  return calculateValue;
21
21
  }
22
22
  });
23
- const _core = require("@perses-dev/core");
23
+ const _pluginsystem = require("@perses-dev/plugin-system");
24
24
  const calculateValue = (calculation, seriesData)=>{
25
- if (_core.CalculationsMap[calculation] === undefined) {
26
- console.warn(`Invalid StatChart panel calculation ${calculation}, fallback to ${_core.DEFAULT_CALCULATION}`);
25
+ if (_pluginsystem.CalculationsMap[calculation] === undefined) {
26
+ console.warn(`Invalid StatChart panel calculation ${calculation}, fallback to ${_pluginsystem.DEFAULT_CALCULATION}`);
27
27
  }
28
- const calculate = _core.CalculationsMap[calculation] ?? _core.CalculationsMap[_core.DEFAULT_CALCULATION];
28
+ const calculate = _pluginsystem.CalculationsMap[calculation] ?? _pluginsystem.CalculationsMap[_pluginsystem.DEFAULT_CALCULATION];
29
29
  return calculate(seriesData.values);
30
30
  };
@@ -20,12 +20,12 @@ Object.defineProperty(exports, "formatStatChartValue", {
20
20
  return formatStatChartValue;
21
21
  }
22
22
  });
23
- const _core = require("@perses-dev/core");
23
+ const _components = require("@perses-dev/components");
24
24
  const formatStatChartValue = (value, format)=>{
25
25
  if (value === null) {
26
26
  return 'null';
27
27
  } else if (typeof value === 'number') {
28
- return (0, _core.formatValue)(value, format);
28
+ return (0, _components.formatValue)(value, format);
29
29
  } else if (value === undefined) {
30
30
  return '';
31
31
  } else {
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "getStatChartColor", {
20
20
  return getStatChartColor;
21
21
  }
22
22
  });
23
- const _core = require("@perses-dev/core");
23
+ const _components = require("@perses-dev/components");
24
24
  function getStatChartColor(chartsTheme, spec, value) {
25
25
  const { mappings, thresholds } = spec ?? {};
26
26
  // Determine the default color from thresholds or theme
@@ -47,7 +47,7 @@ function getStatChartColor(chartsTheme, spec, value) {
47
47
  }
48
48
  function getColorFromMappings(value, mappings) {
49
49
  if (mappings?.length && value !== undefined && value !== null) {
50
- const { color } = (0, _core.applyValueMapping)(value, mappings);
50
+ const { color } = (0, _components.applyValueMapping)(value, mappings);
51
51
  return color || null;
52
52
  }
53
53
  return null;
@@ -1,6 +1,6 @@
1
- import { FontSizeOption } from '@perses-dev/components';
2
- import { CalculationType, Definition, FormatOptions, ThresholdOptions, ValueMapping } from '@perses-dev/core';
3
- import { OptionsEditorProps } from '@perses-dev/plugin-system';
1
+ import { FontSizeOption, FormatOptions, ThresholdOptions, ValueMapping } from '@perses-dev/components';
2
+ import { CalculationType, OptionsEditorProps } from '@perses-dev/plugin-system';
3
+ import { Definition } from '@perses-dev/spec';
4
4
  /**
5
5
  * The schema for a StatChart panel.
6
6
  */
@@ -1 +1 @@
1
- {"version":3,"file":"stat-chart-model.d.ts","sourceRoot":"","sources":["../../src/stat-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAE,gBAA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CAAC;IACtB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,2BAA2B,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAE/E,wBAAgB,6BAA6B,IAAI,gBAAgB,CAShE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/stat-chart-model.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FontSizeOption } from '@perses-dev/components';\nimport { CalculationType, Definition, FormatOptions, ThresholdOptions, ValueMapping } from '@perses-dev/core';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\n\n/**\n * The schema for a StatChart panel.\n */\nexport interface StatChartDefinition extends Definition<StatChartOptions> {\n kind: 'StatChart';\n}\n\nexport type ColorMode = 'none' | 'value' | 'background_solid';\n\nexport type ColorModeLabelItem = {\n id: ColorMode;\n label: string;\n};\n\nexport const COLOR_MODE_LABELS: ColorModeLabelItem[] = [\n { id: 'none', label: 'None' },\n { id: 'value', label: 'Text' },\n { id: 'background_solid', label: 'Background' },\n];\n\nexport type legendMode = 'auto' | 'on' | 'off';\n\nexport type ShowLegendLabelItem = {\n id: legendMode;\n label: string;\n description?: string;\n};\n\nexport const SHOW_LEGEND_LABELS: ShowLegendLabelItem[] = [\n { id: 'auto', label: 'Auto', description: 'Show legend for multi-series, hide legend for single series' },\n { id: 'on', label: 'On', description: 'Always show legend' },\n { id: 'off', label: 'Off', description: 'Always hide legend' },\n];\n\nexport interface StatChartOptions {\n calculation: CalculationType;\n format: FormatOptions;\n metricLabel?: string;\n thresholds?: ThresholdOptions;\n sparkline?: StatChartSparklineOptions;\n valueFontSize?: FontSizeOption;\n mappings?: ValueMapping[];\n colorMode?: ColorMode;\n legendMode?: legendMode;\n}\n\nexport interface StatChartSparklineOptions {\n color?: string;\n width?: number;\n}\n\nexport type StatChartOptionsEditorProps = OptionsEditorProps<StatChartOptions>;\n\nexport function createInitialStatChartOptions(): StatChartOptions {\n return {\n calculation: 'last-number',\n format: {\n unit: 'decimal',\n },\n sparkline: {},\n legendMode: 'auto',\n };\n}\n"],"names":["COLOR_MODE_LABELS","id","label","SHOW_LEGEND_LABELS","description","createInitialStatChartOptions","calculation","format","unit","sparkline","legendMode"],"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;AAoBjC,OAAO,MAAMA,oBAA0C;IACrD;QAAEC,IAAI;QAAQC,OAAO;IAAO;IAC5B;QAAED,IAAI;QAASC,OAAO;IAAO;IAC7B;QAAED,IAAI;QAAoBC,OAAO;IAAa;CAC/C,CAAC;AAUF,OAAO,MAAMC,qBAA4C;IACvD;QAAEF,IAAI;QAAQC,OAAO;QAAQE,aAAa;IAA8D;IACxG;QAAEH,IAAI;QAAMC,OAAO;QAAME,aAAa;IAAqB;IAC3D;QAAEH,IAAI;QAAOC,OAAO;QAAOE,aAAa;IAAqB;CAC9D,CAAC;AAqBF,OAAO,SAASC;IACd,OAAO;QACLC,aAAa;QACbC,QAAQ;YACNC,MAAM;QACR;QACAC,WAAW,CAAC;QACZC,YAAY;IACd;AACF"}
1
+ {"version":3,"sources":["../../src/stat-chart-model.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FontSizeOption, FormatOptions, ThresholdOptions, ValueMapping } from '@perses-dev/components';\nimport { CalculationType, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Definition } from '@perses-dev/spec';\n\n/**\n * The schema for a StatChart panel.\n */\nexport interface StatChartDefinition extends Definition<StatChartOptions> {\n kind: 'StatChart';\n}\n\nexport type ColorMode = 'none' | 'value' | 'background_solid';\n\nexport type ColorModeLabelItem = {\n id: ColorMode;\n label: string;\n};\n\nexport const COLOR_MODE_LABELS: ColorModeLabelItem[] = [\n { id: 'none', label: 'None' },\n { id: 'value', label: 'Text' },\n { id: 'background_solid', label: 'Background' },\n];\n\nexport type legendMode = 'auto' | 'on' | 'off';\n\nexport type ShowLegendLabelItem = {\n id: legendMode;\n label: string;\n description?: string;\n};\n\nexport const SHOW_LEGEND_LABELS: ShowLegendLabelItem[] = [\n { id: 'auto', label: 'Auto', description: 'Show legend for multi-series, hide legend for single series' },\n { id: 'on', label: 'On', description: 'Always show legend' },\n { id: 'off', label: 'Off', description: 'Always hide legend' },\n];\n\nexport interface StatChartOptions {\n calculation: CalculationType;\n format: FormatOptions;\n metricLabel?: string;\n thresholds?: ThresholdOptions;\n sparkline?: StatChartSparklineOptions;\n valueFontSize?: FontSizeOption;\n mappings?: ValueMapping[];\n colorMode?: ColorMode;\n legendMode?: legendMode;\n}\n\nexport interface StatChartSparklineOptions {\n color?: string;\n width?: number;\n}\n\nexport type StatChartOptionsEditorProps = OptionsEditorProps<StatChartOptions>;\n\nexport function createInitialStatChartOptions(): StatChartOptions {\n return {\n calculation: 'last-number',\n format: {\n unit: 'decimal',\n },\n sparkline: {},\n legendMode: 'auto',\n };\n}\n"],"names":["COLOR_MODE_LABELS","id","label","SHOW_LEGEND_LABELS","description","createInitialStatChartOptions","calculation","format","unit","sparkline","legendMode"],"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;AAoBjC,OAAO,MAAMA,oBAA0C;IACrD;QAAEC,IAAI;QAAQC,OAAO;IAAO;IAC5B;QAAED,IAAI;QAASC,OAAO;IAAO;IAC7B;QAAED,IAAI;QAAoBC,OAAO;IAAa;CAC/C,CAAC;AAUF,OAAO,MAAMC,qBAA4C;IACvD;QAAEF,IAAI;QAAQC,OAAO;QAAQE,aAAa;IAA8D;IACxG;QAAEH,IAAI;QAAMC,OAAO;QAAME,aAAa;IAAqB;IAC3D;QAAEH,IAAI;QAAOC,OAAO;QAAOE,aAAa;IAAqB;CAC9D,CAAC;AAqBF,OAAO,SAASC;IACd,OAAO;QACLC,aAAa;QACbC,QAAQ;YACNC,MAAM;QACR;QACAC,WAAW,CAAC;QACZC,YAAY;IACd;AACF"}
@@ -1,3 +1,4 @@
1
- import { CalculationsMap, CalculationType, TimeSeries } from '@perses-dev/core';
1
+ import { CalculationsMap, CalculationType } from '@perses-dev/plugin-system';
2
+ import { TimeSeries } from '@perses-dev/spec';
2
3
  export declare const calculateValue: (calculation: CalculationType, seriesData: TimeSeries) => ReturnType<(typeof CalculationsMap)[CalculationType]>;
3
4
  //# sourceMappingURL=calculate-value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"calculate-value.d.ts","sourceRoot":"","sources":["../../../src/utils/calculate-value.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAuB,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAErG,eAAO,MAAM,cAAc,GACzB,aAAa,eAAe,EAC5B,YAAY,UAAU,KACrB,UAAU,CAAC,CAAC,OAAO,eAAe,EAAE,eAAe,CAAC,CAMtD,CAAC"}
1
+ {"version":3,"file":"calculate-value.d.ts","sourceRoot":"","sources":["../../../src/utils/calculate-value.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAuB,MAAM,2BAA2B,CAAC;AAClG,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,eAAO,MAAM,cAAc,GACzB,aAAa,eAAe,EAC5B,YAAY,UAAU,KACrB,UAAU,CAAC,CAAC,OAAO,eAAe,EAAE,eAAe,CAAC,CAMtD,CAAC"}
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { CalculationsMap, DEFAULT_CALCULATION } from '@perses-dev/core';
13
+ import { CalculationsMap, DEFAULT_CALCULATION } from '@perses-dev/plugin-system';
14
14
  export const calculateValue = (calculation, seriesData)=>{
15
15
  if (CalculationsMap[calculation] === undefined) {
16
16
  console.warn(`Invalid StatChart panel calculation ${calculation}, fallback to ${DEFAULT_CALCULATION}`);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/calculate-value.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 { CalculationsMap, CalculationType, DEFAULT_CALCULATION, TimeSeries } from '@perses-dev/core';\n\nexport const calculateValue = (\n calculation: CalculationType,\n seriesData: TimeSeries\n): ReturnType<(typeof CalculationsMap)[CalculationType]> => {\n if (CalculationsMap[calculation] === undefined) {\n console.warn(`Invalid StatChart panel calculation ${calculation}, fallback to ${DEFAULT_CALCULATION}`);\n }\n const calculate = CalculationsMap[calculation] ?? CalculationsMap[DEFAULT_CALCULATION];\n return calculate(seriesData.values);\n};\n"],"names":["CalculationsMap","DEFAULT_CALCULATION","calculateValue","calculation","seriesData","undefined","console","warn","calculate","values"],"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,eAAe,EAAmBC,mBAAmB,QAAoB,mBAAmB;AAErG,OAAO,MAAMC,iBAAiB,CAC5BC,aACAC;IAEA,IAAIJ,eAAe,CAACG,YAAY,KAAKE,WAAW;QAC9CC,QAAQC,IAAI,CAAC,CAAC,oCAAoC,EAAEJ,YAAY,cAAc,EAAEF,qBAAqB;IACvG;IACA,MAAMO,YAAYR,eAAe,CAACG,YAAY,IAAIH,eAAe,CAACC,oBAAoB;IACtF,OAAOO,UAAUJ,WAAWK,MAAM;AACpC,EAAE"}
1
+ {"version":3,"sources":["../../../src/utils/calculate-value.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 { CalculationsMap, CalculationType, DEFAULT_CALCULATION } from '@perses-dev/plugin-system';\nimport { TimeSeries } from '@perses-dev/spec';\n\nexport const calculateValue = (\n calculation: CalculationType,\n seriesData: TimeSeries\n): ReturnType<(typeof CalculationsMap)[CalculationType]> => {\n if (CalculationsMap[calculation] === undefined) {\n console.warn(`Invalid StatChart panel calculation ${calculation}, fallback to ${DEFAULT_CALCULATION}`);\n }\n const calculate = CalculationsMap[calculation] ?? CalculationsMap[DEFAULT_CALCULATION];\n return calculate(seriesData.values);\n};\n"],"names":["CalculationsMap","DEFAULT_CALCULATION","calculateValue","calculation","seriesData","undefined","console","warn","calculate","values"],"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,eAAe,EAAmBC,mBAAmB,QAAQ,4BAA4B;AAGlG,OAAO,MAAMC,iBAAiB,CAC5BC,aACAC;IAEA,IAAIJ,eAAe,CAACG,YAAY,KAAKE,WAAW;QAC9CC,QAAQC,IAAI,CAAC,CAAC,oCAAoC,EAAEJ,YAAY,cAAc,EAAEF,qBAAqB;IACvG;IACA,MAAMO,YAAYR,eAAe,CAACG,YAAY,IAAIH,eAAe,CAACC,oBAAoB;IACtF,OAAOO,UAAUJ,WAAWK,MAAM;AACpC,EAAE"}
@@ -1,3 +1,3 @@
1
- import { FormatOptions } from '@perses-dev/core';
1
+ import { FormatOptions } from '@perses-dev/components';
2
2
  export declare const formatStatChartValue: (value?: string | number | null, format?: FormatOptions) => string;
3
3
  //# sourceMappingURL=format-stat-chart-value.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"format-stat-chart-value.d.ts","sourceRoot":"","sources":["../../../src/utils/format-stat-chart-value.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAe,MAAM,kBAAkB,CAAC;AAE9D,eAAO,MAAM,oBAAoB,GAAI,QAAQ,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,SAAS,aAAa,KAAG,MAU7F,CAAC"}
1
+ {"version":3,"file":"format-stat-chart-value.d.ts","sourceRoot":"","sources":["../../../src/utils/format-stat-chart-value.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAe,MAAM,wBAAwB,CAAC;AAEpE,eAAO,MAAM,oBAAoB,GAAI,QAAQ,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,SAAS,aAAa,KAAG,MAU7F,CAAC"}
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { formatValue } from '@perses-dev/core';
13
+ import { formatValue } from '@perses-dev/components';
14
14
  export const formatStatChartValue = (value, format)=>{
15
15
  if (value === null) {
16
16
  return 'null';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/format-stat-chart-value.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, formatValue } from '@perses-dev/core';\n\nexport const formatStatChartValue = (value?: string | number | null, format?: FormatOptions): string => {\n if (value === null) {\n return 'null';\n } else if (typeof value === 'number') {\n return formatValue(value, format);\n } else if (value === undefined) {\n return '';\n } else {\n return value;\n }\n};\n"],"names":["formatValue","formatStatChartValue","value","format","undefined"],"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,SAAwBA,WAAW,QAAQ,mBAAmB;AAE9D,OAAO,MAAMC,uBAAuB,CAACC,OAAgCC;IACnE,IAAID,UAAU,MAAM;QAClB,OAAO;IACT,OAAO,IAAI,OAAOA,UAAU,UAAU;QACpC,OAAOF,YAAYE,OAAOC;IAC5B,OAAO,IAAID,UAAUE,WAAW;QAC9B,OAAO;IACT,OAAO;QACL,OAAOF;IACT;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../src/utils/format-stat-chart-value.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, formatValue } from '@perses-dev/components';\n\nexport const formatStatChartValue = (value?: string | number | null, format?: FormatOptions): string => {\n if (value === null) {\n return 'null';\n } else if (typeof value === 'number') {\n return formatValue(value, format);\n } else if (value === undefined) {\n return '';\n } else {\n return value;\n }\n};\n"],"names":["formatValue","formatStatChartValue","value","format","undefined"],"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,SAAwBA,WAAW,QAAQ,yBAAyB;AAEpE,OAAO,MAAMC,uBAAuB,CAACC,OAAgCC;IACnE,IAAID,UAAU,MAAM;QAClB,OAAO;IACT,OAAO,IAAI,OAAOA,UAAU,UAAU;QACpC,OAAOF,YAAYE,OAAOC;IAC5B,OAAO,IAAID,UAAUE,WAAW;QAC9B,OAAO;IACT,OAAO;QACL,OAAOF;IACT;AACF,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-color.d.ts","sourceRoot":"","sources":["../../../src/utils/get-color.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,KAAK,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE7C,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,iBAAiB,EAC9B,IAAI,CAAC,EAAE,gBAAgB,EACvB,KAAK,CAAC,EAAE,cAAc,GACrB,MAAM,CA4BR"}
1
+ {"version":3,"file":"get-color.d.ts","sourceRoot":"","sources":["../../../src/utils/get-color.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,iBAAiB,EAAkC,MAAM,wBAAwB,CAAC;AAC9G,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,KAAK,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE7C,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,iBAAiB,EAC9B,IAAI,CAAC,EAAE,gBAAgB,EACvB,KAAK,CAAC,EAAE,cAAc,GACrB,MAAM,CA4BR"}
@@ -10,7 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { applyValueMapping } from '@perses-dev/core';
13
+ import { applyValueMapping } from '@perses-dev/components';
14
14
  export function getStatChartColor(chartsTheme, spec, value) {
15
15
  const { mappings, thresholds } = spec ?? {};
16
16
  // Determine the default color from thresholds or theme
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/utils/get-color.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 { PersesChartsTheme } from '@perses-dev/components';\nimport { applyValueMapping, ThresholdOptions, ValueMapping } from '@perses-dev/core';\nimport { StatChartOptions } from '../stat-chart-model';\n\ntype StatChartValue = number | string | null;\n\nexport function getStatChartColor(\n chartsTheme: PersesChartsTheme,\n spec?: StatChartOptions,\n value?: StatChartValue\n): string {\n const { mappings, thresholds } = spec ?? {};\n\n // Determine the default color from thresholds or theme\n const defaultColor = thresholds?.defaultColor ?? chartsTheme.thresholds.defaultColor;\n\n if (value === undefined || value === null || value === '' || (!thresholds?.steps && !mappings)) {\n return defaultColor;\n }\n\n // Check mappings first\n if (mappings?.length) {\n const colorFromMappings = getColorFromMappings(value, mappings);\n if (colorFromMappings) {\n return colorFromMappings;\n }\n }\n\n // Check thresholds next\n if (thresholds) {\n const colorFromThresholds = getColorFromThresholds(value, thresholds, chartsTheme, defaultColor);\n if (colorFromThresholds) {\n return colorFromThresholds;\n }\n }\n\n // Fallback to default color\n return defaultColor;\n}\n\nfunction getColorFromMappings(value: StatChartValue, mappings: ValueMapping[]): string | null {\n if (mappings?.length && value !== undefined && value !== null) {\n const { color } = applyValueMapping(value, mappings);\n return color || null;\n }\n return null;\n}\n\nfunction getColorFromThresholds(\n value: StatChartValue,\n thresholds: ThresholdOptions,\n chartsTheme: PersesChartsTheme,\n defaultColor: string\n): string | null {\n if (thresholds?.steps && typeof value === 'number') {\n const matchingColors = thresholds.steps\n .map((step, index) => {\n if (value >= step.value) {\n return step.color ?? chartsTheme.thresholds.palette[index] ?? defaultColor;\n }\n return null;\n })\n .filter((color): color is string => color !== null);\n\n return matchingColors[matchingColors.length - 1] ?? null;\n }\n return null;\n}\n"],"names":["applyValueMapping","getStatChartColor","chartsTheme","spec","value","mappings","thresholds","defaultColor","undefined","steps","length","colorFromMappings","getColorFromMappings","colorFromThresholds","getColorFromThresholds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AMC;YACV,IAAIf,SAASc,KAAKd,KAAK,EAAE;gBACvB,OAAOc,KAAKH,KAAK,IAAIb,YAAYI,UAAU,CAACc,OAAO,CAACD,MAAM,IAAIZ;YAChE;YACA,OAAO;QACT,GACCc,MAAM,CAAC,CAACN,QAA2BA,UAAU;QAEhD,OAAOC,cAAc,CAACA,eAAeN,MAAM,GAAG,EAAE,IAAI;IACtD;IACA,OAAO;AACT"}
1
+ {"version":3,"sources":["../../../src/utils/get-color.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 { applyValueMapping, PersesChartsTheme, ThresholdOptions, ValueMapping } from '@perses-dev/components';\nimport { StatChartOptions } from '../stat-chart-model';\n\ntype StatChartValue = number | string | null;\n\nexport function getStatChartColor(\n chartsTheme: PersesChartsTheme,\n spec?: StatChartOptions,\n value?: StatChartValue\n): string {\n const { mappings, thresholds } = spec ?? {};\n\n // Determine the default color from thresholds or theme\n const defaultColor = thresholds?.defaultColor ?? chartsTheme.thresholds.defaultColor;\n\n if (value === undefined || value === null || value === '' || (!thresholds?.steps && !mappings)) {\n return defaultColor;\n }\n\n // Check mappings first\n if (mappings?.length) {\n const colorFromMappings = getColorFromMappings(value, mappings);\n if (colorFromMappings) {\n return colorFromMappings;\n }\n }\n\n // Check thresholds next\n if (thresholds) {\n const colorFromThresholds = getColorFromThresholds(value, thresholds, chartsTheme, defaultColor);\n if (colorFromThresholds) {\n return colorFromThresholds;\n }\n }\n\n // Fallback to default color\n return defaultColor;\n}\n\nfunction getColorFromMappings(value: StatChartValue, mappings: ValueMapping[]): string | null {\n if (mappings?.length && value !== undefined && value !== null) {\n const { color } = applyValueMapping(value, mappings);\n return color || null;\n }\n return null;\n}\n\nfunction getColorFromThresholds(\n value: StatChartValue,\n thresholds: ThresholdOptions,\n chartsTheme: PersesChartsTheme,\n defaultColor: string\n): string | null {\n if (thresholds?.steps && typeof value === 'number') {\n const matchingColors = thresholds.steps\n .map((step, index) => {\n if (value >= step.value) {\n return step.color ?? chartsTheme.thresholds.palette[index] ?? defaultColor;\n }\n return null;\n })\n .filter((color): color is string => color !== null);\n\n return matchingColors[matchingColors.length - 1] ?? null;\n }\n return null;\n}\n"],"names":["applyValueMapping","getStatChartColor","chartsTheme","spec","value","mappings","thresholds","defaultColor","undefined","steps","length","colorFromMappings","getColorFromMappings","colorFromThresholds","getColorFromThresholds","color","matchingColors","map","step","index","palette","filter"],"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,iBAAiB,QAA2D,yBAAyB;AAK9G,OAAO,SAASC,kBACdC,WAA8B,EAC9BC,IAAuB,EACvBC,KAAsB;IAEtB,MAAM,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAAGH,QAAQ,CAAC;IAE1C,uDAAuD;IACvD,MAAMI,eAAeD,YAAYC,gBAAgBL,YAAYI,UAAU,CAACC,YAAY;IAEpF,IAAIH,UAAUI,aAAaJ,UAAU,QAAQA,UAAU,MAAO,CAACE,YAAYG,SAAS,CAACJ,UAAW;QAC9F,OAAOE;IACT;IAEA,uBAAuB;IACvB,IAAIF,UAAUK,QAAQ;QACpB,MAAMC,oBAAoBC,qBAAqBR,OAAOC;QACtD,IAAIM,mBAAmB;YACrB,OAAOA;QACT;IACF;IAEA,wBAAwB;IACxB,IAAIL,YAAY;QACd,MAAMO,sBAAsBC,uBAAuBV,OAAOE,YAAYJ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