@perses-dev/stat-chart-plugin 0.10.0 → 0.11.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 (48) hide show
  1. package/__mf/css/async/263.d3010b86.css +1 -0
  2. package/__mf/css/async/341.d3010b86.css +1 -0
  3. package/__mf/css/async/759.d3010b86.css +1 -0
  4. package/__mf/js/{StatChart.4380d9d9.js → StatChart.7c0ea76c.js} +3 -3
  5. package/__mf/js/async/{238.e184091d.js → 238.5475e796.js} +1 -1
  6. package/__mf/js/async/298.2736d1ac.js +1 -0
  7. package/__mf/js/async/518.d772e916.js +2 -0
  8. package/__mf/js/async/518.d772e916.js.LICENSE.txt +13 -0
  9. package/__mf/js/async/711.30b0444f.js +22 -0
  10. package/__mf/js/async/{75.0e924b9e.js → 75.c51a3e1b.js} +1 -1
  11. package/__mf/js/async/764.c5215ca9.js +83 -0
  12. package/__mf/js/async/85.559c8591.js +7 -0
  13. package/__mf/js/async/966.4cf38e97.js +65 -0
  14. package/__mf/js/async/__federation_expose_StatChart.20659f63.js +1 -0
  15. package/__mf/js/{main.0d096334.js → main.b4991a3c.js} +3 -3
  16. package/lib/StatChartBase.d.ts +2 -0
  17. package/lib/StatChartBase.d.ts.map +1 -1
  18. package/lib/StatChartBase.js +91 -29
  19. package/lib/StatChartBase.js.map +1 -1
  20. package/lib/StatChartOptionsEditorSettings.d.ts.map +1 -1
  21. package/lib/StatChartOptionsEditorSettings.js +30 -2
  22. package/lib/StatChartOptionsEditorSettings.js.map +1 -1
  23. package/lib/StatChartPanel.d.ts.map +1 -1
  24. package/lib/StatChartPanel.js +4 -3
  25. package/lib/StatChartPanel.js.map +1 -1
  26. package/lib/cjs/StatChartBase.js +90 -28
  27. package/lib/cjs/StatChartOptionsEditorSettings.js +29 -1
  28. package/lib/cjs/StatChartPanel.js +4 -3
  29. package/lib/cjs/stat-chart-model.js +25 -3
  30. package/lib/stat-chart-model.d.ts +7 -0
  31. package/lib/stat-chart-model.d.ts.map +1 -1
  32. package/lib/stat-chart-model.js +14 -0
  33. package/lib/stat-chart-model.js.map +1 -1
  34. package/mf-manifest.json +17 -16
  35. package/mf-stats.json +17 -16
  36. package/package.json +12 -6
  37. package/__mf/css/async/263.1ed8bb01.css +0 -1
  38. package/__mf/css/async/341.1ed8bb01.css +0 -1
  39. package/__mf/css/async/759.1ed8bb01.css +0 -1
  40. package/__mf/js/async/109.8841516b.js +0 -73
  41. package/__mf/js/async/181.985d810b.js +0 -83
  42. package/__mf/js/async/288.b314a020.js +0 -7
  43. package/__mf/js/async/298.db4e15c8.js +0 -1
  44. package/__mf/js/async/828.d18e1139.js +0 -65
  45. package/__mf/js/async/__federation_expose_StatChart.20144587.js +0 -1
  46. /package/__mf/js/async/{109.8841516b.js.LICENSE.txt → 711.30b0444f.js.LICENSE.txt} +0 -0
  47. /package/__mf/js/async/{181.985d810b.js.LICENSE.txt → 764.c5215ca9.js.LICENSE.txt} +0 -0
  48. /package/__mf/js/async/{288.b314a020.js.LICENSE.txt → 85.559c8591.js.LICENSE.txt} +0 -0
@@ -12,13 +12,14 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useMemo } from 'react';
15
- import { Box, Typography, styled } from '@mui/material';
15
+ import { Box, Typography, styled, useTheme } from '@mui/material';
16
16
  import merge from 'lodash/merge';
17
17
  import { use } from 'echarts/core';
18
18
  import { LineChart as EChartsLineChart } from 'echarts/charts';
19
19
  import { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';
20
20
  import { CanvasRenderer } from 'echarts/renderers';
21
21
  import { EChart, useChartsTheme } from '@perses-dev/components';
22
+ import chroma from 'chroma-js';
22
23
  import { useOptimalFontSize } from './utils/calculate-font-size';
23
24
  import { formatStatChartValue } from './utils/format-stat-chart-value';
24
25
  use([
@@ -33,10 +34,12 @@ const LINE_HEIGHT = 1.2;
33
34
  const SERIES_NAME_MAX_FONT_SIZE = 30;
34
35
  const SERIES_NAME_FONT_WEIGHT = 400;
35
36
  const VALUE_FONT_WEIGHT = 700;
37
+ const WHITE_COLOR_CODE = '#FFFFFF';
38
+ const BLACK_COLOR_CODE = '#000000';
36
39
  export const StatChartBase = (props)=>{
37
- const { width, height, data, sparkline, showSeriesName, format, valueFontSize } = props;
40
+ const { width, height, data, data: { color }, sparkline, showSeriesName, format, valueFontSize, colorMode } = props;
41
+ const { palette: { mode: paletteMode, text: { secondary } } } = useTheme();
38
42
  const chartsTheme = useChartsTheme();
39
- const color = data.color;
40
43
  const formattedValue = formatStatChartValue(data.calculatedValue, format);
41
44
  const containerPadding = chartsTheme.container.padding.default;
42
45
  // calculate series name font size and height
@@ -68,10 +71,10 @@ export const StatChartBase = (props)=>{
68
71
  // make sure the series name font size is slightly smaller than value font size
69
72
  seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);
70
73
  const option = useMemo(()=>{
71
- if (data.seriesData === undefined) return chartsTheme.noDataOption;
74
+ if (!data.seriesData) return chartsTheme.noDataOption;
72
75
  const series = data.seriesData;
73
76
  const statSeries = [];
74
- if (sparkline !== undefined) {
77
+ if (sparkline) {
75
78
  const lineSeries = {
76
79
  type: 'line',
77
80
  name: series.name,
@@ -81,7 +84,20 @@ export const StatChartBase = (props)=>{
81
84
  animation: false,
82
85
  silent: true
83
86
  };
84
- const mergedSeries = merge(lineSeries, sparkline);
87
+ const clonedSparkLine = {
88
+ ...sparkline
89
+ };
90
+ if (colorMode === 'background_solid') {
91
+ clonedSparkLine.areaStyle = {
92
+ color: WHITE_COLOR_CODE,
93
+ opacity: 0.4
94
+ };
95
+ clonedSparkLine.lineStyle = {
96
+ color: WHITE_COLOR_CODE,
97
+ opacity: 1
98
+ };
99
+ }
100
+ const mergedSeries = merge(lineSeries, clonedSparkLine);
85
101
  statSeries.push(mergedSeries);
86
102
  }
87
103
  const option = {
@@ -121,35 +137,81 @@ export const StatChartBase = (props)=>{
121
137
  }, [
122
138
  data,
123
139
  chartsTheme,
124
- sparkline
140
+ sparkline,
141
+ colorMode
125
142
  ]);
126
143
  const textAlignment = sparkline ? 'auto' : 'center';
127
- const textStyles = {
128
- display: 'flex',
129
- flexDirection: 'column',
130
- justifyContent: textAlignment,
131
- alignItems: textAlignment
132
- };
144
+ const styledFormattedValue = useMemo(()=>{
145
+ let valueColor = '';
146
+ switch(colorMode){
147
+ case 'background_solid':
148
+ valueColor = chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE) ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
149
+ break;
150
+ case 'none':
151
+ valueColor = paletteMode === 'dark' ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
152
+ break;
153
+ case 'value':
154
+ default:
155
+ valueColor = color;
156
+ break;
157
+ }
158
+ return /*#__PURE__*/ _jsx(Value, {
159
+ variant: "h3",
160
+ color: valueColor,
161
+ fontSize: optimalValueFontSize,
162
+ padding: containerPadding,
163
+ children: formattedValue
164
+ });
165
+ }, [
166
+ colorMode,
167
+ containerPadding,
168
+ optimalValueFontSize,
169
+ formattedValue,
170
+ color,
171
+ paletteMode
172
+ ]);
173
+ const seriesName = useMemo(()=>{
174
+ if (!showSeriesName) return null;
175
+ let textColor = '';
176
+ switch(colorMode){
177
+ case 'background_solid':
178
+ textColor = chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE) ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
179
+ break;
180
+ case 'none':
181
+ case 'value':
182
+ default:
183
+ textColor = secondary;
184
+ break;
185
+ }
186
+ return /*#__PURE__*/ _jsx(SeriesName, {
187
+ padding: containerPadding,
188
+ fontSize: seriesNameFontSize,
189
+ color: textColor,
190
+ children: data.seriesData?.name
191
+ });
192
+ }, [
193
+ colorMode,
194
+ showSeriesName,
195
+ secondary,
196
+ color,
197
+ containerPadding,
198
+ seriesNameFontSize,
199
+ data?.seriesData?.name
200
+ ]);
133
201
  return /*#__PURE__*/ _jsxs(Box, {
134
202
  sx: {
135
203
  height: '100%',
136
204
  width: '100%',
137
- ...textStyles
205
+ backgroundColor: colorMode === 'background_solid' ? color : 'transparent',
206
+ display: 'flex',
207
+ flexDirection: 'column',
208
+ justifyContent: textAlignment,
209
+ alignItems: textAlignment
138
210
  },
139
211
  children: [
140
- showSeriesName && /*#__PURE__*/ _jsx(SeriesName, {
141
- padding: containerPadding,
142
- fontSize: seriesNameFontSize,
143
- children: data.seriesData?.name
144
- }),
145
- /*#__PURE__*/ _jsx(Value, {
146
- variant: "h3",
147
- color: color,
148
- fontSize: optimalValueFontSize,
149
- padding: containerPadding,
150
- children: formattedValue
151
- }),
152
- sparkline !== undefined && /*#__PURE__*/ _jsx(EChart, {
212
+ seriesName,
213
+ styledFormattedValue,
214
+ sparkline && /*#__PURE__*/ _jsx(EChart, {
153
215
  sx: {
154
216
  width: '100%'
155
217
  },
@@ -167,8 +229,8 @@ export const StatChartBase = (props)=>{
167
229
  };
168
230
  const SeriesName = styled(Typography, {
169
231
  shouldForwardProp: (prop)=>prop !== 'padding' && prop !== 'fontSize'
170
- })(({ theme, padding, fontSize })=>({
171
- color: theme.palette.text.secondary,
232
+ })(({ padding, fontSize, color })=>({
233
+ color: color,
172
234
  padding: `${padding}px`,
173
235
  fontSize: `${fontSize}px`,
174
236
  overflow: 'hidden',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChartBase.tsx"],"sourcesContent":["// Copyright 2023 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, useMemo } from 'react';\nimport { FormatOptions } from '@perses-dev/core';\nimport { Box, Typography, styled } 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 { useOptimalFontSize } from './utils/calculate-font-size';\nimport { formatStatChartValue } from './utils/format-stat-chart-value';\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;\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}\n\nexport const StatChartBase: FC<StatChartProps> = (props) => {\n const { width, height, data, sparkline, showSeriesName, format, valueFontSize } = props;\n const chartsTheme = useChartsTheme();\n const color = data.color;\n\n const formattedValue = formatStatChartValue(data.calculatedValue, format);\n\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 === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\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 const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\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]);\n\n const textAlignment = sparkline ? 'auto' : 'center';\n const textStyles = {\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n };\n\n return (\n <Box sx={{ height: '100%', width: '100%', ...textStyles }}>\n {showSeriesName && (\n <SeriesName padding={containerPadding} fontSize={seriesNameFontSize}>\n {data.seriesData?.name}\n </SeriesName>\n )}\n <Value variant=\"h3\" color={color} fontSize={optimalValueFontSize} padding={containerPadding}>\n {formattedValue}\n </Value>\n {sparkline !== undefined && (\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 }>(({ theme, padding, fontSize }) => ({\n color: theme.palette.text.secondary,\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","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","EChart","useChartsTheme","useOptimalFontSize","formatStatChartValue","LINE_HEIGHT","SERIES_NAME_MAX_FONT_SIZE","SERIES_NAME_FONT_WEIGHT","VALUE_FONT_WEIGHT","StatChartBase","props","width","height","data","sparkline","showSeriesName","format","valueFontSize","chartsTheme","color","formattedValue","calculatedValue","containerPadding","container","padding","default","seriesNameFontSize","text","seriesData","name","fontWeight","lineHeight","maxSize","seriesNameHeight","availableWidth","availableHeight","optimalValueFontSize","fontSizeOverride","valueFontHeight","Math","min","option","undefined","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","value","tooltip","textAlignment","textStyles","display","flexDirection","justifyContent","alignItems","sx","SeriesName","fontSize","Value","variant","style","floor","theme","echartsTheme","renderer","shouldForwardProp","prop","palette","secondary","overflow","textOverflow","whiteSpace","primary"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAaA,OAAO,QAAQ,QAAQ;AAEpC,SAASC,GAAG,EAAEC,UAAU,EAAEC,MAAM,QAAQ,gBAAgB;AACxD,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,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,oBAAoB,QAAQ,kCAAkC;AAEvEX,IAAI;IAACE;IAAkBC;IAAeC;IAAkBC;IAAgBC;IAAkBC;CAAe;AAEzG,MAAMK,cAAc;AACpB,MAAMC,4BAA4B;AAClC,MAAMC,0BAA0B;AAChC,MAAMC,oBAAoB;AAkB1B,OAAO,MAAMC,gBAAoC,CAACC;IAChD,MAAM,EAAEC,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,cAAc,EAAEC,MAAM,EAAEC,aAAa,EAAE,GAAGP;IAClF,MAAMQ,cAAchB;IACpB,MAAMiB,Q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,SAAS,aAAaA,SAAS;AAC9D,GAAoE,CAAC,EAAEJ,KAAK,EAAEzD,OAAO,EAAEoD,QAAQ,EAAE,GAAM,CAAA;QACrGzD,OAAO8D,MAAMK,OAAO,CAAC3D,IAAI,CAAC4D,SAAS;QACnC/D,SAAS,GAAGA,QAAQ,EAAE,CAAC;QACvBoD,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBY,UAAU;QACVC,cAAc;QACdC,YAAY;IACd,CAAA;AAEA,MAAMb,QAAQtF,OAAOD,YAAY;IAC/B8F,mBAAmB,CAACC,OAASA,SAAS,WAAWA,SAAS,aAAaA,SAAS,cAAcA,SAAS;AACzG,GACE,CAAC,EAAEJ,KAAK,EAAE9D,KAAK,EAAEK,OAAO,EAAEoD,QAAQ,EAAE9D,SAAS,EAAE,GAAM,CAAA;QACnDK,OAAOA,SAAS8D,MAAMK,OAAO,CAAC3D,IAAI,CAACgE,OAAO;QAC1Cf,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBpD,SAASV,YAAY,GAAGU,QAAQ,GAAG,EAAEA,QAAQ,KAAK,EAAEA,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,EAAEA,QAAQ,EAAE,CAAC;QACnFkE,YAAY;QACZ3D,YAAY1B;IACd,CAAA"}
1
+ {"version":3,"sources":["../../src/StatChartBase.tsx"],"sourcesContent":["// Copyright 2023 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,oCAAoC;AACpC,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,MAAM,EACNC,IAAI,EACJA,MAAM,EAAEC,KAAK,EAAE,EACfC,SAAS,EACTC,cAAc,EACdC,MAAM,EACNC,aAAa,EACbC,SAAS,EACV,GAAGT;IAEJ,MAAM,EACJU,SA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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 +1 @@
1
- {"version":3,"file":"StatChartOptionsEditorSettings.d.ts","sourceRoot":"","sources":["../../src/StatChartOptionsEditorSettings.tsx"],"names":[],"mappings":"AAoCA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAAoB,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAInF,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,2BAA2B,GAAG,YAAY,CA4E/F"}
1
+ {"version":3,"file":"StatChartOptionsEditorSettings.d.ts","sourceRoot":"","sources":["../../src/StatChartOptionsEditorSettings.tsx"],"names":[],"mappings":"AAqCA,OAAO,EAAE,YAAY,EAAwB,MAAM,OAAO,CAAC;AAC3D,OAAO,EAIL,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAI5B,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,2BAA2B,GAAG,YAAY,CA2G/F"}
@@ -12,10 +12,12 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { Switch } from '@mui/material';
15
- import { FontSizeSelector, FormatControls, OptionsEditorColumn, OptionsEditorControl, OptionsEditorGrid, OptionsEditorGroup, ThresholdsEditor } from '@perses-dev/components';
15
+ import { FontSizeSelector, FormatControls, OptionsEditorColumn, OptionsEditorControl, OptionsEditorGrid, OptionsEditorGroup, SettingsAutocomplete, ThresholdsEditor } from '@perses-dev/components';
16
16
  import { CalculationSelector, MetricLabelInput } from '@perses-dev/plugin-system';
17
17
  import { produce } from 'immer';
18
18
  import merge from 'lodash/merge';
19
+ import { useCallback, useMemo } from 'react';
20
+ import { COLOR_MODE_LABELS } from './stat-chart-model';
19
21
  const DEFAULT_FORMAT = {
20
22
  unit: 'percent-decimal'
21
23
  };
@@ -56,6 +58,31 @@ export function StatChartOptionsEditorSettings(props) {
56
58
  draft.valueFontSize = fontSize;
57
59
  }));
58
60
  };
61
+ const handleColorModeChange = useCallback((_, newColorMode)=>{
62
+ onChange(produce(value, (draft)=>{
63
+ draft.colorMode = newColorMode.id;
64
+ }));
65
+ }, [
66
+ onChange,
67
+ value
68
+ ]);
69
+ const selectColorMode = useMemo(()=>{
70
+ return /*#__PURE__*/ _jsx(OptionsEditorControl, {
71
+ label: "Color mode",
72
+ control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
73
+ onChange: handleColorModeChange,
74
+ options: COLOR_MODE_LABELS.map(({ id, label })=>({
75
+ id,
76
+ label
77
+ })),
78
+ disableClearable: true,
79
+ value: COLOR_MODE_LABELS.find((i)=>i.id === value.colorMode) ?? COLOR_MODE_LABELS.find((i)=>i.id === 'value')
80
+ })
81
+ });
82
+ }, [
83
+ value.colorMode,
84
+ handleColorModeChange
85
+ ]);
59
86
  return /*#__PURE__*/ _jsxs(OptionsEditorGrid, {
60
87
  children: [
61
88
  /*#__PURE__*/ _jsx(OptionsEditorColumn, {
@@ -84,7 +111,8 @@ export function StatChartOptionsEditorSettings(props) {
84
111
  /*#__PURE__*/ _jsx(FontSizeSelector, {
85
112
  value: value.valueFontSize,
86
113
  onChange: handleFontSizeChange
87
- })
114
+ }),
115
+ selectColorMode
88
116
  ]
89
117
  })
90
118
  }),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChartOptionsEditorSettings.tsx"],"sourcesContent":["// Copyright 2023 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 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 } from 'react';\nimport { StatChartOptions, StatChartOptionsEditorProps } 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 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 return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\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 </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","ThresholdsEditor","CalculationSelector","MetricLabelInput","produce","merge","DEFAULT_FORMAT","unit","StatChartOptionsEditorSettings","props","onChange","value","format","handleCalculationChange","metricLabel","draft","calculation","handleMetricLabelChange","newCalculation","handleUnitChange","newFormat","handleSparklineChange","_","checked","sparkline","undefined","handleThresholdsChange","thresholds","handleFontSizeChange","fontSize","valueFontSize","title","label","control","disablePercentMode"],"mappings":"AAAA,oCAAoC;AACpC,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,gBAAgB,QAEX,yBAAyB;AAEhC,SACEC,mBAAmB,EAEnBC,gBAAgB,QAEX,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAChC,OAAOC,WAAW,eAAe;AAIjC,MAAMC,iBAAgC;IAAEC,MAAM;AAAkB;AAEhE,OAAO,SAASC,+BAA+BC,KAAkC;IAC/E,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,kDAAkD;IAClD,MAAMG,SAASP,MAAM,CAAC,GAAGC,gBAAgBK,MAAMC,MAAM;IAErD,MAAMC,0BAAgE,CAACC;QACrEJ,SACEN,QAAQO,OAAO,CAACI;YACdA,MAAMC,WAAW,GAAGF;QACtB;IAEJ;IAEA,MAAMG,0BAA6D,CAACC;QAClER,SACEN,QAAQO,OAAO,CAACI;YACdA,MAAMD,WAAW,GAAGI;QACtB;IAEJ;IAEA,MAAMC,mBAAoD,CAACC;QACzDV,SACEN,QAAQO,OAAO,CAACI;YACdA,MAAMH,MAAM,GAAGQ;QACjB;IAEJ;IAEA,MAAMC,wBAAiD,CAACC,GAAYC;QAClEb,SACEN,QAAQO,OAAO,CAACI;YACd,sEAAsE;YACtE,oEAAoE;YACpE,yCAAyC;YACzCA,MAAMS,SAAS,GAAGD,UAAU,CAAC,IAAIE;QACnC;IAEJ;IAEA,MAAMC,yBAA4D,CAACC;QACjEjB,SACEN,QAAQO,OAAO,CAACI;YACdA,MAAMY,UAAU,GAAGA;QACrB;IAEJ;IAEA,MAAMC,uBAA0D,CAACC;QAC/DnB,SACEN,QAAQO,OAAO,CAACI;YACdA,MAAMe,aAAa,GAAGD;QACxB;IAEJ;IAEA,qBACE,MAAC9B;;0BACC,KAACF;0BACC,cAAA,MAACG;oBAAmB+B,OAAM;;sCACxB,KAACjC;4BACCkC,OAAM;4BACNC,uBAAS,KAACvC;gCAAO6B,SAAS,CAAC,CAACZ,MAAMa,SAAS;gCAAEd,UAAUW;;;sCAEzD,KAACzB;4BAAee,OAAOC;4BAAQF,UAAUS;;sCACzC,KAACjB;4BAAoBS,OAAOA,MAAMK,WAAW;4BAAEN,UAAUG;;sCACzD,KAACV;4BAAiBQ,OAAOA,MAAMG,WAAW;4BAAEJ,UAAUO;;sCACtD,KAACtB;4BAAiBgB,OAAOA,MAAMmB,aAAa;4BAAEpB,UAAUkB;;;;;0BAG5D,KAAC/B;0BACC,cAAA,KAACI;oBAAiBiC,kBAAkB;oBAACP,YAAYhB,MAAMgB,UAAU;oBAAEjB,UAAUgB;;;;;AAIrF"}
1
+ {"version":3,"sources":["../../src/StatChartOptionsEditorSettings.tsx"],"sourcesContent":["// Copyright 2023 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 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 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 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=\"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","DEFAULT_FORMAT","unit","StatChartOptionsEditorSettings","props","onChange","value","format","handleCalculationChange","metricLabel","draft","calculation","handleMetricLabelChange","newCalculation","handleUnitChange","newFormat","handleSparklineChange","_","checked","sparkline","undefined","handleThresholdsChange","thresholds","handleFontSizeChange","fontSize","valueFontSize","handleColorModeChange","newColorMode","colorMode","id","selectColorMode","label","control","options","map","disableClearable","find","i","title","disablePercentMode"],"mappings":"AAAA,oCAAoC;AACpC,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,QAIZ,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,SAASV,MAAM,CAAC,GAAGI,gBAAgBK,MAAMC,MAAM;IAErD,MAAMC,0BAAgE,CAACC;QACrEJ,SACET,QAAQU,OAAO,CAACI;YACdA,MAAMC,WAAW,GAAGF;QACtB;IAEJ;IAEA,MAAMG,0BAA6D,CAACC;QAClER,SACET,QAAQU,OAAO,CAACI;YACdA,MAAMD,WAAW,GAAGI;QACtB;IAEJ;IAEA,MAAMC,mBAAoD,CAACC;QACzDV,SACET,QAAQU,OAAO,CAACI;YACdA,MAAMH,MAAM,GAAGQ;QACjB;IAEJ;IAEA,MAAMC,wBAAiD,CAACC,GAAYC;QAClEb,SACET,QAAQU,OAAO,CAACI;YACd,sEAAsE;YACtE,oEAAoE;YACpE,yCAAyC;YACzCA,MAAMS,SAAS,GA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;4BAAEpB,UAAUkB;;wBACvDO;;;;0BAGL,KAAC1C;0BACC,cAAA,KAACK;oBAAiB8C,kBAAkB;oBAACjB,YAAYhB,MAAMgB,UAAU;oBAAEjB,UAAUgB;;;;;AAIrF"}
@@ -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,CAsDlD,CAAC"}
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,CAuDlD,CAAC"}
@@ -23,11 +23,11 @@ const MIN_WIDTH = 100;
23
23
  const SPACING = 2;
24
24
  export const StatChartPanel = (props)=>{
25
25
  const { spec, contentDimensions, queryResults } = props;
26
- const { format, sparkline, valueFontSize: valueFontSize } = spec;
26
+ const { format, sparkline, valueFontSize: valueFontSize, colorMode } = spec;
27
27
  const chartsTheme = useChartsTheme();
28
28
  const statChartData = useStatChartData(queryResults, spec, chartsTheme);
29
29
  const isMultiSeries = statChartData.length > 1;
30
- if (contentDimensions === undefined) return null;
30
+ if (!contentDimensions) return null;
31
31
  // Calculates chart width
32
32
  const spacing = SPACING * (statChartData.length - 1);
33
33
  let chartWidth = (contentDimensions.width - spacing) / statChartData.length;
@@ -54,7 +54,8 @@ export const StatChartPanel = (props)=>{
54
54
  format: format,
55
55
  sparkline: sparklineConfig,
56
56
  showSeriesName: isMultiSeries,
57
- valueFontSize: valueFontSize
57
+ valueFontSize: valueFontSize,
58
+ colorMode: colorMode
58
59
  }, index);
59
60
  }) : /*#__PURE__*/ _jsx(Typography, {
60
61
  sx: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChartPanel.tsx"],"sourcesContent":["// Copyright 2023 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 } = spec;\n const chartsTheme = useChartsTheme();\n const statChartData = useStatChartData(queryResults, spec, chartsTheme);\n\n const isMultiSeries = statChartData.length > 1;\n\n if (contentDimensions === undefined) 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={isMultiSeries}\n valueFontSize={valueFontSize}\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","chartsTheme","statChartData","useStatChartData","isMultiSeries","length","undefined","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","fieldLabel","key","Object","entries","regex","test"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,cAAc,QAAwC,yBAAyB;AACxF,SAASC,KAAK,EAAEC,UAAU,QAAiB,gBAAgB;AAC3D,SAAaC,OAAO,QAAQ,QAAQ;AACpC,SAASC,iBAAiB,EAAUC,qBAAqB,QAAsC,mBAAmB;AAGlH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OAAO,CAACZ,QAAS;QACjD,MAAMa,QAAQ9D,sBAAsB0D;QACpC,IAAII,MAAMC,IAAI,CAACJ,MAAM;YACnB,OAAOH;QACT;IACF;IACA,OAAOpC;AACT"}
1
+ {"version":3,"sources":["../../src/StatChartPanel.tsx"],"sourcesContent":["// Copyright 2023 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 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={isMultiSeries}\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","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,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,cAAc,QAAwC,yBAAyB;AACxF,SAASC,KAAK,EAAEC,UAAU,QAAiB,gBAAgB;AAC3D,SAAaC,OAAO,QAAQ,QAAQ;AACpC,SAASC,iBAAiB,EAAUC,qBAAqB,QAAsC,mBAAmB;AAGlH,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,iBAAiB,QAAQ,oBAAoB;AACtD,SAASC,aAAa,QAAuB,kBAAkB;AAE/D,MAAMC,YAAY;AAClB,MAAMC,UAAU;AAIhB,OAAO,MAAMC,iBAA0C,CAACC;IACtD,MAAM,EAAEC,IAAI,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGH;IAElD,MAAM,EAAEI,MAAM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AE/C,MAAMQ,gBAAiC,EAAE;QACzC,KAAK,MAAM2B,UAAUjC,aAAc;YACjC,KAAK,MAAMkC,cAAcD,OAAOL,IAAI,CAACJ,MAAM,CAAE;gBAC3C,MAAMW,kBAAkB5C,eAAeuC,aAAaI;gBAEpD,yBAAyB;gBACzB,MAAME,aAAaC,cAAcL,aAAaE,WAAWI,MAAM;gBAE/D,8BAA8B;gBAC9B,MAAMC,eAAeC,gBAAgBL,iBAAiBJ,UAAUK;gBAEhE,MAAMT,QAAQnC,kBAAkBa,aAAaP,MAAMqC;gBAEnD,MAAMX,SAAsB;oBAC1BiB,MAAMP,WAAWQ,aAAa,IAAI;oBAClCC,QAAQT,WAAWS,MAAM;gBAC3B;gBAEArC,cAAcsC,IAAI,CAAC;oBAAET,iBAAiBI;oBAAcL,YAAYV;oBAAQG;gBAAM;YAChF;QACF;QACA,OAAOrB;IACT,GAAG;QAACN;QAAcF;QAAMO;KAAY;AACtC;AAEA,MAAMmC,kBAAkB,CACtBK,OACAd,UACAe;IAEA,IAAIA,OAAO;QACT,OAAOA;IACT;IACA,IAAIf,UAAUtB,UAAUoC,UAAUE,aAAaF,UAAU,MAAM;QAC7D,OAAOzD,kBAAkByD,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,QAAQ/D,sBAAsB2D;QACpC,IAAII,MAAMC,IAAI,CAACJ,MAAM;YACnB,OAAOJ;QACT;IACF;IACA,OAAOE;AACT"}
@@ -29,6 +29,7 @@ const _charts = require("echarts/charts");
29
29
  const _components = require("echarts/components");
30
30
  const _renderers = require("echarts/renderers");
31
31
  const _components1 = require("@perses-dev/components");
32
+ const _chromajs = /*#__PURE__*/ _interop_require_default(require("chroma-js"));
32
33
  const _calculatefontsize = require("./utils/calculate-font-size");
33
34
  const _formatstatchartvalue = require("./utils/format-stat-chart-value");
34
35
  function _interop_require_default(obj) {
@@ -48,10 +49,12 @@ const LINE_HEIGHT = 1.2;
48
49
  const SERIES_NAME_MAX_FONT_SIZE = 30;
49
50
  const SERIES_NAME_FONT_WEIGHT = 400;
50
51
  const VALUE_FONT_WEIGHT = 700;
52
+ const WHITE_COLOR_CODE = '#FFFFFF';
53
+ const BLACK_COLOR_CODE = '#000000';
51
54
  const StatChartBase = (props)=>{
52
- const { width, height, data, sparkline, showSeriesName, format, valueFontSize } = props;
55
+ const { width, height, data, data: { color }, sparkline, showSeriesName, format, valueFontSize, colorMode } = props;
56
+ const { palette: { mode: paletteMode, text: { secondary } } } = (0, _material.useTheme)();
53
57
  const chartsTheme = (0, _components1.useChartsTheme)();
54
- const color = data.color;
55
58
  const formattedValue = (0, _formatstatchartvalue.formatStatChartValue)(data.calculatedValue, format);
56
59
  const containerPadding = chartsTheme.container.padding.default;
57
60
  // calculate series name font size and height
@@ -83,10 +86,10 @@ const StatChartBase = (props)=>{
83
86
  // make sure the series name font size is slightly smaller than value font size
84
87
  seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);
85
88
  const option = (0, _react.useMemo)(()=>{
86
- if (data.seriesData === undefined) return chartsTheme.noDataOption;
89
+ if (!data.seriesData) return chartsTheme.noDataOption;
87
90
  const series = data.seriesData;
88
91
  const statSeries = [];
89
- if (sparkline !== undefined) {
92
+ if (sparkline) {
90
93
  const lineSeries = {
91
94
  type: 'line',
92
95
  name: series.name,
@@ -96,7 +99,20 @@ const StatChartBase = (props)=>{
96
99
  animation: false,
97
100
  silent: true
98
101
  };
99
- const mergedSeries = (0, _merge.default)(lineSeries, sparkline);
102
+ const clonedSparkLine = {
103
+ ...sparkline
104
+ };
105
+ if (colorMode === 'background_solid') {
106
+ clonedSparkLine.areaStyle = {
107
+ color: WHITE_COLOR_CODE,
108
+ opacity: 0.4
109
+ };
110
+ clonedSparkLine.lineStyle = {
111
+ color: WHITE_COLOR_CODE,
112
+ opacity: 1
113
+ };
114
+ }
115
+ const mergedSeries = (0, _merge.default)(lineSeries, clonedSparkLine);
100
116
  statSeries.push(mergedSeries);
101
117
  }
102
118
  const option = {
@@ -136,35 +152,81 @@ const StatChartBase = (props)=>{
136
152
  }, [
137
153
  data,
138
154
  chartsTheme,
139
- sparkline
155
+ sparkline,
156
+ colorMode
140
157
  ]);
141
158
  const textAlignment = sparkline ? 'auto' : 'center';
142
- const textStyles = {
143
- display: 'flex',
144
- flexDirection: 'column',
145
- justifyContent: textAlignment,
146
- alignItems: textAlignment
147
- };
159
+ const styledFormattedValue = (0, _react.useMemo)(()=>{
160
+ let valueColor = '';
161
+ switch(colorMode){
162
+ case 'background_solid':
163
+ valueColor = _chromajs.default.contrast(color, WHITE_COLOR_CODE) > _chromajs.default.contrast(color, BLACK_COLOR_CODE) ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
164
+ break;
165
+ case 'none':
166
+ valueColor = paletteMode === 'dark' ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
167
+ break;
168
+ case 'value':
169
+ default:
170
+ valueColor = color;
171
+ break;
172
+ }
173
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(Value, {
174
+ variant: "h3",
175
+ color: valueColor,
176
+ fontSize: optimalValueFontSize,
177
+ padding: containerPadding,
178
+ children: formattedValue
179
+ });
180
+ }, [
181
+ colorMode,
182
+ containerPadding,
183
+ optimalValueFontSize,
184
+ formattedValue,
185
+ color,
186
+ paletteMode
187
+ ]);
188
+ const seriesName = (0, _react.useMemo)(()=>{
189
+ if (!showSeriesName) return null;
190
+ let textColor = '';
191
+ switch(colorMode){
192
+ case 'background_solid':
193
+ textColor = _chromajs.default.contrast(color, WHITE_COLOR_CODE) > _chromajs.default.contrast(color, BLACK_COLOR_CODE) ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
194
+ break;
195
+ case 'none':
196
+ case 'value':
197
+ default:
198
+ textColor = secondary;
199
+ break;
200
+ }
201
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(SeriesName, {
202
+ padding: containerPadding,
203
+ fontSize: seriesNameFontSize,
204
+ color: textColor,
205
+ children: data.seriesData?.name
206
+ });
207
+ }, [
208
+ colorMode,
209
+ showSeriesName,
210
+ secondary,
211
+ color,
212
+ containerPadding,
213
+ seriesNameFontSize,
214
+ data?.seriesData?.name
215
+ ]);
148
216
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
149
217
  sx: {
150
218
  height: '100%',
151
219
  width: '100%',
152
- ...textStyles
220
+ backgroundColor: colorMode === 'background_solid' ? color : 'transparent',
221
+ display: 'flex',
222
+ flexDirection: 'column',
223
+ justifyContent: textAlignment,
224
+ alignItems: textAlignment
153
225
  },
154
226
  children: [
155
- showSeriesName && /*#__PURE__*/ (0, _jsxruntime.jsx)(SeriesName, {
156
- padding: containerPadding,
157
- fontSize: seriesNameFontSize,
158
- children: data.seriesData?.name
159
- }),
160
- /*#__PURE__*/ (0, _jsxruntime.jsx)(Value, {
161
- variant: "h3",
162
- color: color,
163
- fontSize: optimalValueFontSize,
164
- padding: containerPadding,
165
- children: formattedValue
166
- }),
167
- sparkline !== undefined && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components1.EChart, {
227
+ seriesName,
228
+ styledFormattedValue,
229
+ sparkline && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components1.EChart, {
168
230
  sx: {
169
231
  width: '100%'
170
232
  },
@@ -182,8 +244,8 @@ const StatChartBase = (props)=>{
182
244
  };
183
245
  const SeriesName = (0, _material.styled)(_material.Typography, {
184
246
  shouldForwardProp: (prop)=>prop !== 'padding' && prop !== 'fontSize'
185
- })(({ theme, padding, fontSize })=>({
186
- color: theme.palette.text.secondary,
247
+ })(({ padding, fontSize, color })=>({
248
+ color: color,
187
249
  padding: `${padding}px`,
188
250
  fontSize: `${fontSize}px`,
189
251
  overflow: 'hidden',