@perses-dev/stat-chart-plugin 0.15.0-beta.2 → 0.15.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mf/js/{StatChart.bb7e0ece.js → StatChart.ae08c232.js} +5 -5
- package/__mf/js/async/{121.f7e8e4a7.js → 121.beb69e34.js} +2 -2
- package/__mf/js/async/{192.9808d269.js → 192.a7711fa3.js} +1 -1
- package/__mf/js/async/{2.a13c5048.js → 2.2b56e05c.js} +1 -1
- package/__mf/js/async/{235.7bcd2051.js → 235.71387fda.js} +1 -1
- package/__mf/js/async/{274.8d8be5c9.js → 274.be05817c.js} +2 -2
- package/__mf/js/async/356.5739ad43.js +1 -0
- package/__mf/js/async/{392.cb707a93.js → 392.07346c9e.js} +2 -2
- package/__mf/js/async/{450.3a0b1ae3.js → 450.0b2aa209.js} +1 -1
- package/__mf/js/async/{465.0b7086ef.js → 465.3607405d.js} +2 -2
- package/__mf/js/async/{470.26952ddf.js → 470.cabf687e.js} +2 -2
- package/__mf/js/async/{496.b9973ffe.js → 496.97c79a52.js} +1 -1
- package/__mf/js/async/{570.36d078cd.js → 570.3b8aa468.js} +2 -2
- package/__mf/js/async/587.241ec511.js +1 -0
- package/__mf/js/async/{588.29eb8c38.js → 588.2c442d65.js} +1 -1
- package/__mf/js/async/{616.42a14f39.js → 616.24b1b0c3.js} +1 -1
- package/__mf/js/async/639.97fbc532.js +29 -0
- package/__mf/js/async/{71.7f97cf3a.js → 71.b54b84a8.js} +1 -1
- package/__mf/js/async/{721.9ed0b42d.js → 721.eca4d9fa.js} +1 -1
- package/__mf/js/async/{77.048fc50c.js → 77.d77867d5.js} +1 -1
- package/__mf/js/async/{788.d3786b94.js → 788.d1e8ac39.js} +5 -5
- package/__mf/js/async/{866.180c7c1d.js → 866.84144485.js} +2 -2
- package/__mf/js/async/868.5a32825a.js +53 -0
- package/__mf/js/async/{873.d6bb2952.js → 873.417a7ffe.js} +1 -1
- package/__mf/js/async/{941.bf04fa66.js → 941.04b1526c.js} +2 -2
- package/__mf/js/async/968.6134540a.js +1 -0
- package/__mf/js/async/{978.6043d74f.js → 978.d96121a4.js} +1 -1
- package/__mf/js/async/__federation_expose_StatChart.34d84800.js +1 -0
- package/__mf/js/async/{lib-router.a0b2cd64.js → lib-router.a2cdf386.js} +2 -2
- package/__mf/js/{main.ca1383be.js → main.b6ed713f.js} +5 -5
- package/lib/StatChartBase.d.ts +3 -0
- package/lib/StatChartBase.d.ts.map +1 -1
- package/lib/StatChartBase.js +19 -15
- package/lib/StatChartBase.js.map +1 -1
- package/lib/StatChartOptionsEditorSettings.d.ts.map +1 -1
- package/lib/StatChartOptionsEditorSettings.js +13 -2
- package/lib/StatChartOptionsEditorSettings.js.map +1 -1
- package/lib/StatChartPanel.d.ts.map +1 -1
- package/lib/StatChartPanel.js +82 -6
- package/lib/StatChartPanel.js.map +1 -1
- package/lib/stat-chart-model.d.ts +1 -0
- package/lib/stat-chart-model.d.ts.map +1 -1
- package/lib/stat-chart-model.js.map +1 -1
- package/lib/utils/calculate-font-size.d.ts +4 -0
- package/lib/utils/calculate-font-size.d.ts.map +1 -1
- package/lib/utils/calculate-font-size.js +7 -0
- package/lib/utils/calculate-font-size.js.map +1 -1
- package/lib/utils/calculate-value.d.ts.map +1 -1
- package/lib/utils/format-stat-chart-value.d.ts.map +1 -1
- package/mf-manifest.json +36 -36
- package/mf-stats.json +36 -36
- package/package.json +5 -5
- package/__mf/js/async/345.f2a95d9c.js +0 -29
- package/__mf/js/async/356.defde8e9.js +0 -1
- package/__mf/js/async/407.07aba336.js +0 -4
- package/__mf/js/async/587.528aba30.js +0 -1
- package/__mf/js/async/968.0754c6b9.js +0 -1
- package/__mf/js/async/__federation_expose_StatChart.ea6bcd68.js +0 -1
- /package/__mf/js/async/{121.f7e8e4a7.js.LICENSE.txt → 121.beb69e34.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{274.8d8be5c9.js.LICENSE.txt → 274.be05817c.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{392.cb707a93.js.LICENSE.txt → 392.07346c9e.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{465.0b7086ef.js.LICENSE.txt → 465.3607405d.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{470.26952ddf.js.LICENSE.txt → 470.cabf687e.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{570.36d078cd.js.LICENSE.txt → 570.3b8aa468.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{788.d3786b94.js.LICENSE.txt → 788.d1e8ac39.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{866.180c7c1d.js.LICENSE.txt → 866.84144485.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{407.07aba336.js.LICENSE.txt → 868.5a32825a.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{941.bf04fa66.js.LICENSE.txt → 941.04b1526c.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{lib-router.a0b2cd64.js.LICENSE.txt → lib-router.a2cdf386.js.LICENSE.txt} +0 -0
package/lib/StatChartBase.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ export interface StatChartProps {
|
|
|
15
15
|
sparkline?: LineSeriesOption;
|
|
16
16
|
showSeriesName?: boolean;
|
|
17
17
|
valueFontSize?: FontSizeOption;
|
|
18
|
+
legendFontSize?: FontSizeOption;
|
|
18
19
|
colorMode?: ColorMode;
|
|
20
|
+
alignmentText?: string;
|
|
21
|
+
alignmentSeriesName?: string;
|
|
19
22
|
}
|
|
20
23
|
export declare const StatChartBase: FC<StatChartProps>;
|
|
21
24
|
//# sourceMappingURL=StatChartBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatChartBase.d.ts","sourceRoot":"","sources":["../../src/StatChartBase.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGzF,OAAO,K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AAM,CAAC,EAAE,aAAa,CAAC;IACvB,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,eAAO,MAAM,aAAa,EAAE,EAAE,CAAC,cAAc,CAuN5C,CAAC"}
|
package/lib/StatChartBase.js
CHANGED
|
@@ -37,39 +37,42 @@ const VALUE_FONT_WEIGHT = 700;
|
|
|
37
37
|
const WHITE_COLOR_CODE = '#FFFFFF';
|
|
38
38
|
const BLACK_COLOR_CODE = '#000000';
|
|
39
39
|
export const StatChartBase = (props)=>{
|
|
40
|
-
const { width, height, data, data: { color }, sparkline, showSeriesName, format, valueFontSize, colorMode } = props;
|
|
40
|
+
const { width, height, data, data: { color }, sparkline, showSeriesName, format, valueFontSize, legendFontSize, colorMode, alignmentText, alignmentSeriesName } = props;
|
|
41
41
|
const { palette: { mode: paletteMode, text: { secondary } } } = useTheme();
|
|
42
42
|
const chartsTheme = useChartsTheme();
|
|
43
43
|
const formattedValue = formatStatChartValue(data.calculatedValue, format);
|
|
44
44
|
const containerPadding = chartsTheme.container.padding.default;
|
|
45
|
-
|
|
45
|
+
const availableWidth = width - containerPadding * 2;
|
|
46
|
+
// in multi-series: legend gets a fixed portion of height (like Grafana)
|
|
46
47
|
let seriesNameFontSize = useOptimalFontSize({
|
|
47
48
|
text: data?.seriesData?.name ?? '',
|
|
48
49
|
fontWeight: SERIES_NAME_FONT_WEIGHT,
|
|
49
50
|
width,
|
|
50
|
-
height: height * 0.
|
|
51
|
+
height: height * 0.2,
|
|
51
52
|
lineHeight: LINE_HEIGHT,
|
|
52
53
|
maxSize: SERIES_NAME_MAX_FONT_SIZE
|
|
53
54
|
});
|
|
55
|
+
if (legendFontSize !== undefined) {
|
|
56
|
+
seriesNameFontSize = legendFontSize;
|
|
57
|
+
} else if (alignmentSeriesName !== undefined) {
|
|
58
|
+
// multi-series: use 15% of cell height for legend, clamped between 14px and 30px
|
|
59
|
+
seriesNameFontSize = Math.max(14, Math.min(height * 0.15 / LINE_HEIGHT, SERIES_NAME_MAX_FONT_SIZE));
|
|
60
|
+
}
|
|
54
61
|
const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;
|
|
55
|
-
// calculate value font size and height
|
|
56
|
-
const availableWidth = width - containerPadding * 2;
|
|
57
62
|
const availableHeight = height - seriesNameHeight;
|
|
58
63
|
const optimalValueFontSize = useOptimalFontSize({
|
|
59
|
-
text: formattedValue,
|
|
60
|
-
// override the font size if user selects it in the settings
|
|
64
|
+
text: alignmentText || formattedValue,
|
|
61
65
|
fontSizeOverride: valueFontSize,
|
|
62
66
|
fontWeight: VALUE_FONT_WEIGHT,
|
|
63
|
-
// without sparkline, use only 50% of the available width so it looks better for multiseries
|
|
64
67
|
width: sparkline ? availableWidth : availableWidth * 0.5,
|
|
65
|
-
// with sparkline, use only 25% of available height to leave room for chart
|
|
66
|
-
// without sparkline, value should take up 90% of available space
|
|
67
68
|
height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,
|
|
68
69
|
lineHeight: LINE_HEIGHT
|
|
69
70
|
});
|
|
70
71
|
const valueFontHeight = optimalValueFontSize * LINE_HEIGHT;
|
|
71
|
-
//
|
|
72
|
-
|
|
72
|
+
// single-series: keep legend smaller than value (unless explicitly set)
|
|
73
|
+
if (alignmentSeriesName === undefined && legendFontSize === undefined) {
|
|
74
|
+
seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);
|
|
75
|
+
}
|
|
73
76
|
const option = useMemo(()=>{
|
|
74
77
|
if (!data.seriesData) return chartsTheme.noDataOption;
|
|
75
78
|
const series = data.seriesData;
|
|
@@ -201,7 +204,10 @@ export const StatChartBase = (props)=>{
|
|
|
201
204
|
return /*#__PURE__*/ _jsxs(Box, {
|
|
202
205
|
sx: {
|
|
203
206
|
height: '100%',
|
|
204
|
-
width:
|
|
207
|
+
width: width,
|
|
208
|
+
minWidth: width,
|
|
209
|
+
flexShrink: 0,
|
|
210
|
+
overflow: 'hidden',
|
|
205
211
|
backgroundColor: colorMode === 'background_solid' ? color : 'transparent',
|
|
206
212
|
display: 'flex',
|
|
207
213
|
flexDirection: 'column',
|
|
@@ -233,8 +239,6 @@ const SeriesName = styled(Typography, {
|
|
|
233
239
|
color: color,
|
|
234
240
|
padding: `${padding}px`,
|
|
235
241
|
fontSize: `${fontSize}px`,
|
|
236
|
-
overflow: 'hidden',
|
|
237
|
-
textOverflow: 'ellipsis',
|
|
238
242
|
whiteSpace: 'nowrap'
|
|
239
243
|
}));
|
|
240
244
|
const Value = styled(Typography, {
|
package/lib/StatChartBase.js.map
CHANGED
|
@@ -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 { Box, Typography, styled, useTheme } from '@mui/material';\nimport type { FontSizeOption, FormatOptions, GraphSeries } from '@perses-dev/components';\nimport { EChart, useChartsTheme } from '@perses-dev/components';\nimport chroma from 'chroma-js';\nimport type { LineSeriesOption } from 'echarts/charts';\nimport { LineChart as EChartsLineChart } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport type { EChartsCoreOption } from 'echarts/core';\nimport { use as registerECharts } from 'echarts/core';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport merge from 'lodash/merge';\nimport type { FC, ReactNode } from 'react';\nimport { useMemo } from 'react';\n\nimport type { ColorMode } from './stat-chart-model';\nimport { useOptimalFontSize } from './utils/calculate-font-size';\nimport { formatStatChartValue } from './utils/format-stat-chart-value';\n\nregisterECharts([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":["Box","Typography","styled","useTheme","EChart","useChartsTheme","chroma","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","use","registerECharts","CanvasRenderer","merge","useMemo","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,SAASA,GAAG,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,gBAAgB;AAElE,SAASC,MAAM,EAAEC,cAAc,QAAQ,yBAAyB;AAChE,OAAOC,YAAY,YAAY;AAE/B,SAASC,aAAaC,gBAAgB,QAAQ,iBAAiB;AAC/D,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,qBAAqB;AAEvG,SAASC,OAAOC,eAAe,QAAQ,eAAe;AACtD,SAASC,cAAc,QAAQ,oBAAoB;AACnD,OAAOC,WAAW,eAAe;AAEjC,SAASC,OAAO,QAAQ,QAAQ;AAGhC,SAASC,kBAAkB,QAAQ,iCAA8B;AACjE,SAASC,oBAAoB,QAAQ,qCAAkC;AAEvEL,gBAAgB;IAACN;IAAkBC;IAAeC;IAAkBC;IAAgBC;IAAkBG;CAAe;AAErH,MAAMK,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,SAAS,EACPC,MAAMC,WAAW,EACjBC,MAAM,EAAEC,SAAS,EAAE,EACpB,EACF,GAAGtC;IACJ,MAAMuC,cAAcrC;IACpB,MAAMsC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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 { Box, Typography, styled, useTheme } from '@mui/material';\nimport type { FontSizeOption, FormatOptions, GraphSeries } from '@perses-dev/components';\nimport { EChart, useChartsTheme } from '@perses-dev/components';\nimport chroma from 'chroma-js';\nimport type { LineSeriesOption } from 'echarts/charts';\nimport { LineChart as EChartsLineChart } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport type { EChartsCoreOption } from 'echarts/core';\nimport { use as registerECharts } from 'echarts/core';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport merge from 'lodash/merge';\nimport type { FC, ReactNode } from 'react';\nimport { useMemo } from 'react';\n\nimport type { ColorMode } from './stat-chart-model';\nimport { useOptimalFontSize } from './utils/calculate-font-size';\nimport { formatStatChartValue } from './utils/format-stat-chart-value';\n\nregisterECharts([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 legendFontSize?: FontSizeOption;\n colorMode?: ColorMode;\n alignmentText?: string;\n alignmentSeriesName?: string;\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 legendFontSize,\n colorMode,\n alignmentText,\n alignmentSeriesName,\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 const availableWidth = width - containerPadding * 2;\n\n // in multi-series: legend gets a fixed portion of height (like Grafana)\n let seriesNameFontSize = useOptimalFontSize({\n text: data?.seriesData?.name ?? '',\n fontWeight: SERIES_NAME_FONT_WEIGHT,\n width,\n height: height * 0.2,\n lineHeight: LINE_HEIGHT,\n maxSize: SERIES_NAME_MAX_FONT_SIZE,\n });\n\n if (legendFontSize !== undefined) {\n seriesNameFontSize = legendFontSize;\n } else if (alignmentSeriesName !== undefined) {\n // multi-series: use 15% of cell height for legend, clamped between 14px and 30px\n seriesNameFontSize = Math.max(14, Math.min((height * 0.15) / LINE_HEIGHT, SERIES_NAME_MAX_FONT_SIZE));\n }\n\n const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;\n\n const availableHeight = height - seriesNameHeight;\n const optimalValueFontSize = useOptimalFontSize({\n text: alignmentText || formattedValue,\n fontSizeOverride: valueFontSize,\n fontWeight: VALUE_FONT_WEIGHT,\n width: sparkline ? availableWidth : availableWidth * 0.5,\n height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,\n lineHeight: LINE_HEIGHT,\n });\n const valueFontHeight = optimalValueFontSize * LINE_HEIGHT;\n\n // single-series: keep legend smaller than value (unless explicitly set)\n if (alignmentSeriesName === undefined && legendFontSize === undefined) {\n seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);\n }\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: width,\n minWidth: width,\n flexShrink: 0,\n overflow: 'hidden',\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 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":["Box","Typography","styled","useTheme","EChart","useChartsTheme","chroma","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","use","registerECharts","CanvasRenderer","merge","useMemo","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","legendFontSize","colorMode","alignmentText","alignmentSeriesName","palette","mode","paletteMode","text","secondary","chartsTheme","formattedValue","calculatedValue","containerPadding","container","padding","default","availableWidth","seriesNameFontSize","seriesData","name","fontWeight","lineHeight","maxSize","undefined","Math","max","min","seriesNameHeight","availableHeight","optimalValueFontSize","fontSizeOverride","valueFontHeight","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","minWidth","flexShrink","overflow","backgroundColor","display","flexDirection","justifyContent","alignItems","style","floor","theme","echartsTheme","renderer","shouldForwardProp","prop","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,SAASA,GAAG,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,gBAAgB;AAElE,SAASC,MAAM,EAAEC,cAAc,QAAQ,yBAAyB;AAChE,OAAOC,YAAY,YAAY;AAE/B,SAASC,aAAaC,gBAAgB,QAAQ,iBAAiB;AAC/D,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,qBAAqB;AAEvG,SAASC,OAAOC,eAAe,QAAQ,eAAe;AACtD,SAASC,cAAc,QAAQ,oBAAoB;AACnD,OAAOC,WAAW,eAAe;AAEjC,SAASC,OAAO,QAAQ,QAAQ;AAGhC,SAASC,kBAAkB,QAAQ,iCAA8B;AACjE,SAASC,oBAAoB,QAAQ,qCAAkC;AAEvEL,gBAAgB;IAACN;IAAkBC;IAAeC;IAAkBC;IAAgBC;IAAkBG;CAAe;AAErH,MAAMK,cAAc;AACpB,MAAMC,4BAA4B;AAClC,MAAMC,0BAA0B;AAChC,MAAMC,oBAAoB;AAC1B,MAAMC,mBAAmB;AACzB,MAAMC,mBAAmB;AAsBzB,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,cAAc,EACdC,SAAS,EACTC,aAAa,EACbC,mBAAmB,EACpB,GAA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AazG,OAAOD,YAAY;IACpCyH,mBAAmB,CAACC,OAASA,SAAS,aAAaA,SAAS;AAC9D,GAAoF,CAAC,EAAEzE,OAAO,EAAEsD,QAAQ,EAAEzE,KAAK,EAAE,GAAM,CAAA;QACrHA,OAAOA;QACPmB,SAAS,GAAGA,QAAQ,EAAE,CAAC;QACvBsD,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBoB,YAAY;IACd,CAAA;AAEA,MAAMtB,QAAQpG,OAAOD,YAAY;IAC/ByH,mBAAmB,CAACC,OAASA,SAAS,WAAWA,SAAS,aAAaA,SAAS,cAAcA,SAAS;AACzG,GACE,CAAC,EAAEJ,KAAK,EAAExF,KAAK,EAAEmB,OAAO,EAAEsD,QAAQ,EAAExE,SAAS,EAAE,GAAM,CAAA;QACnDD,OAAOA,SAASwF,MAAM/E,OAAO,CAACG,IAAI,CAACkF,OAAO;QAC1CrB,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBtD,SAASlB,YAAY,GAAGkB,QAAQ,GAAG,EAAEA,QAAQ,KAAK,EAAEA,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,EAAEA,QAAQ,EAAE,CAAC;QACnF0E,YAAY;QACZnE,YAAYrC;IACd,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatChartOptionsEditorSettings.d.ts","sourceRoot":"","sources":["../../src/StatChartOptionsEditorSettings.tsx"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,KAAK,EAIV,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAK5B,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,2BAA2B,GAAG,YAAY,
|
|
1
|
+
{"version":3,"file":"StatChartOptionsEditorSettings.d.ts","sourceRoot":"","sources":["../../src/StatChartOptionsEditorSettings.tsx"],"names":[],"mappings":"AAoCA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAG1C,OAAO,KAAK,EAIV,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAK5B,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,2BAA2B,GAAG,YAAY,CAqJ/F"}
|
|
@@ -66,6 +66,11 @@ export function StatChartOptionsEditorSettings(props) {
|
|
|
66
66
|
draft.valueFontSize = fontSize;
|
|
67
67
|
}));
|
|
68
68
|
};
|
|
69
|
+
const handleLegendFontSizeChange = (fontSize)=>{
|
|
70
|
+
onChange(produce(value, (draft)=>{
|
|
71
|
+
draft.legendFontSize = fontSize;
|
|
72
|
+
}));
|
|
73
|
+
};
|
|
69
74
|
const handleColorModeChange = useCallback((_, newColorMode)=>{
|
|
70
75
|
onChange(produce(value, (draft)=>{
|
|
71
76
|
draft.colorMode = newColorMode.id;
|
|
@@ -109,9 +114,15 @@ export function StatChartOptionsEditorSettings(props) {
|
|
|
109
114
|
children: [
|
|
110
115
|
/*#__PURE__*/ _jsxs(OptionsEditorColumn, {
|
|
111
116
|
children: [
|
|
112
|
-
/*#__PURE__*/
|
|
117
|
+
/*#__PURE__*/ _jsxs(OptionsEditorGroup, {
|
|
113
118
|
title: "Legend",
|
|
114
|
-
children:
|
|
119
|
+
children: [
|
|
120
|
+
selectShowLegend,
|
|
121
|
+
/*#__PURE__*/ _jsx(FontSizeSelector, {
|
|
122
|
+
value: value.legendFontSize,
|
|
123
|
+
onChange: handleLegendFontSizeChange
|
|
124
|
+
})
|
|
125
|
+
]
|
|
115
126
|
}),
|
|
116
127
|
/*#__PURE__*/ _jsxs(OptionsEditorGroup, {
|
|
117
128
|
title: "Misc",
|
|
@@ -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 type { SwitchProps } from '@mui/material';\nimport { Switch } from '@mui/material';\nimport type {\n FontSizeOption,\n FontSizeSelectorProps,\n FormatControlsProps,\n FormatOptions,\n ThresholdsEditorProps,\n} from '@perses-dev/components';\nimport {\n FontSizeSelector,\n FormatControls,\n OptionsEditorColumn,\n OptionsEditorControl,\n OptionsEditorGrid,\n OptionsEditorGroup,\n SettingsAutocomplete,\n ThresholdsEditor,\n} from '@perses-dev/components';\nimport type { CalculationSelectorProps, MetricLabelInputProps } from '@perses-dev/plugin-system';\nimport { CalculationSelector, MetricLabelInput } from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport merge from 'lodash/merge';\nimport type { ReactElement } from 'react';\nimport { useCallback, useMemo } from 'react';\n\nimport type {\n ColorModeLabelItem,\n ShowLegendLabelItem,\n StatChartOptions,\n StatChartOptionsEditorProps,\n} from './stat-chart-model';\nimport { COLOR_MODE_LABELS, SHOW_LEGEND_LABELS } 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;;AAGjC,SAASA,MAAM,QAAQ,gBAAgB;AAQvC,SACEC,g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,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 type { SwitchProps } from '@mui/material';\nimport { Switch } from '@mui/material';\nimport type {\n FontSizeOption,\n FontSizeSelectorProps,\n FormatControlsProps,\n FormatOptions,\n ThresholdsEditorProps,\n} from '@perses-dev/components';\nimport {\n FontSizeSelector,\n FormatControls,\n OptionsEditorColumn,\n OptionsEditorControl,\n OptionsEditorGrid,\n OptionsEditorGroup,\n SettingsAutocomplete,\n ThresholdsEditor,\n} from '@perses-dev/components';\nimport type { CalculationSelectorProps, MetricLabelInputProps } from '@perses-dev/plugin-system';\nimport { CalculationSelector, MetricLabelInput } from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport merge from 'lodash/merge';\nimport type { ReactElement } from 'react';\nimport { useCallback, useMemo } from 'react';\n\nimport type {\n ColorModeLabelItem,\n ShowLegendLabelItem,\n StatChartOptions,\n StatChartOptionsEditorProps,\n} from './stat-chart-model';\nimport { COLOR_MODE_LABELS, SHOW_LEGEND_LABELS } 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 handleLegendFontSizeChange: FontSizeSelectorProps['onChange'] = (fontSize: FontSizeOption) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.legendFontSize = 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\">\n {selectShowLegend}\n <FontSizeSelector value={value.legendFontSize} onChange={handleLegendFontSizeChange} />\n </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","handleLegendFontSizeChange","legendFontSize","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;;AAGjC,SAASA,MAAM,QAAQ,gBAAgB;AAQvC,SACEC,gBAAgB,EAChBC,cAAc,EACdC,mBAAmB,EACnBC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,oBAAoB,EACpBC,gBAAgB,QACX,yBAAyB;AAEhC,SAASC,mBAAmB,EAAEC,gBAAgB,QAAQ,4BAA4B;AAClF,SAASC,OAAO,QAAQ,QAAQ;AAChC,OAAOC,WAAW,eAAe;AAEjC,SAASC,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAQ7C,SAASC,iBAAiB,EAAEC,kBAAkB,QAAQ,wBAAqB;AAE3E,MAAMC,iBAAgC;IAAEC,MAAM;AAA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,OAAOA,MAAMG,WAAW;gCAAEJ,UAAUO;;0CACtD,KAAC3B;gCAAiBqB,OAAOA,MAAMuB,aAAa;gCAAExB,UAAUsB;;4BACvDe;;;;;0BAGL,KAACvD;0BACC,cAAA,KAACK;oBAAiBqD,kBAAkB;oBAACnB,YAAYpB,MAAMoB,UAAU;oBAAErB,UAAUoB;;;;;AAIrF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatChartPanel.d.ts","sourceRoot":"","sources":["../../src/StatChartPanel.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAU,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE/D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"StatChartPanel.d.ts","sourceRoot":"","sources":["../../src/StatChartPanel.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,2BAA2B,CAAC;AACvE,OAAO,KAAK,EAAU,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAE/D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAGhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAY3D,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAE/E,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CAuIlD,CAAC"}
|
package/lib/StatChartPanel.js
CHANGED
|
@@ -15,17 +15,62 @@ import { Stack, Typography } from "@mui/material";
|
|
|
15
15
|
import { useChartsTheme, applyValueMapping, createRegexFromString } from "@perses-dev/components";
|
|
16
16
|
import { useMemo } from "react";
|
|
17
17
|
import { StatChartBase } from "./StatChartBase.js";
|
|
18
|
+
import { measureTextWidth } from "./utils/calculate-font-size.js";
|
|
18
19
|
import { calculateValue } from "./utils/calculate-value.js";
|
|
19
20
|
import { convertSparkline } from "./utils/data-transform.js";
|
|
21
|
+
import { formatStatChartValue } from "./utils/format-stat-chart-value.js";
|
|
20
22
|
import { getStatChartColor } from "./utils/get-color.js";
|
|
21
23
|
const MIN_WIDTH = 100;
|
|
22
24
|
const SPACING = 2;
|
|
23
25
|
export const StatChartPanel = (props)=>{
|
|
24
26
|
const { spec, contentDimensions, queryResults } = props;
|
|
25
|
-
const { format, sparkline, valueFontSize, colorMode } = spec;
|
|
27
|
+
const { format, sparkline, valueFontSize, legendFontSize, colorMode } = spec;
|
|
26
28
|
const chartsTheme = useChartsTheme();
|
|
27
29
|
const statChartData = useStatChartData(queryResults, spec, chartsTheme);
|
|
28
30
|
const isMultiSeries = statChartData.length > 1;
|
|
31
|
+
// Find the widest value text (by pixel width) to use as alignment reference
|
|
32
|
+
const alignmentText = useMemo(()=>{
|
|
33
|
+
if (!isMultiSeries) return undefined;
|
|
34
|
+
const fontFamily = chartsTheme.echartsTheme.textStyle?.fontFamily ?? 'Lato';
|
|
35
|
+
const fontSize = Number(chartsTheme.echartsTheme.textStyle?.fontSize) || 12;
|
|
36
|
+
let widest = '';
|
|
37
|
+
let maxWidth = 0;
|
|
38
|
+
for (const series of statChartData){
|
|
39
|
+
const formatted = formatStatChartValue(series.calculatedValue, format);
|
|
40
|
+
const width = measureTextWidth(formatted, 700, fontSize, fontFamily);
|
|
41
|
+
if (width > maxWidth) {
|
|
42
|
+
maxWidth = width;
|
|
43
|
+
widest = formatted;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return widest;
|
|
47
|
+
}, [
|
|
48
|
+
statChartData,
|
|
49
|
+
format,
|
|
50
|
+
isMultiSeries,
|
|
51
|
+
chartsTheme.echartsTheme.textStyle
|
|
52
|
+
]);
|
|
53
|
+
// Find the longest series name (by pixel width) to unify legend sizing
|
|
54
|
+
const alignmentSeriesName = useMemo(()=>{
|
|
55
|
+
if (!isMultiSeries) return undefined;
|
|
56
|
+
const fontFamily = chartsTheme.echartsTheme.textStyle?.fontFamily ?? 'Lato';
|
|
57
|
+
const fontSize = Number(chartsTheme.echartsTheme.textStyle?.fontSize) || 12;
|
|
58
|
+
let widest = '';
|
|
59
|
+
let maxWidth = 0;
|
|
60
|
+
for (const series of statChartData){
|
|
61
|
+
const name = series.seriesData?.name ?? '';
|
|
62
|
+
const width = measureTextWidth(name, 400, fontSize, fontFamily);
|
|
63
|
+
if (width > maxWidth) {
|
|
64
|
+
maxWidth = width;
|
|
65
|
+
widest = name;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return widest;
|
|
69
|
+
}, [
|
|
70
|
+
statChartData,
|
|
71
|
+
isMultiSeries,
|
|
72
|
+
chartsTheme.echartsTheme.textStyle
|
|
73
|
+
]);
|
|
29
74
|
// Handle three-state showLegend: 'on' | 'off' | 'auto' (or undefined for backward compatibility)
|
|
30
75
|
let shouldShowLegend = isMultiSeries;
|
|
31
76
|
if (spec.legendMode === 'on') {
|
|
@@ -34,11 +79,21 @@ export const StatChartPanel = (props)=>{
|
|
|
34
79
|
shouldShowLegend = false;
|
|
35
80
|
}
|
|
36
81
|
if (!contentDimensions) return null;
|
|
37
|
-
// Calculates chart width
|
|
82
|
+
// Calculates chart width — ensure cells are wide enough to show full series names
|
|
38
83
|
const spacing = SPACING * (statChartData.length - 1);
|
|
39
84
|
let chartWidth = (contentDimensions.width - spacing) / statChartData.length;
|
|
40
|
-
if (isMultiSeries
|
|
41
|
-
|
|
85
|
+
if (isMultiSeries) {
|
|
86
|
+
const fontFamily = chartsTheme.echartsTheme.textStyle?.fontFamily ?? 'Lato';
|
|
87
|
+
const seriesNameFontSize = legendFontSize ?? Math.max(14, Math.min(contentDimensions.height * 0.15 / 1.2, 30));
|
|
88
|
+
const padding = chartsTheme.container.padding.default;
|
|
89
|
+
let maxTextWidth = MIN_WIDTH;
|
|
90
|
+
for (const series of statChartData){
|
|
91
|
+
const nameWidth = measureTextWidth(series.seriesData?.name ?? '', 400, seriesNameFontSize, fontFamily);
|
|
92
|
+
const valWidth = measureTextWidth(formatStatChartValue(series.calculatedValue, format), 700, seriesNameFontSize * 1.5, fontFamily);
|
|
93
|
+
const needed = Math.max(nameWidth, valWidth) + padding * 2;
|
|
94
|
+
if (needed > maxTextWidth) maxTextWidth = needed;
|
|
95
|
+
}
|
|
96
|
+
chartWidth = Math.max(chartWidth, maxTextWidth);
|
|
42
97
|
}
|
|
43
98
|
const noDataTextStyle = chartsTheme.noDataOption.title.textStyle;
|
|
44
99
|
return /*#__PURE__*/ _jsx(Stack, {
|
|
@@ -49,7 +104,25 @@ export const StatChartPanel = (props)=>{
|
|
|
49
104
|
justifyContent: isMultiSeries ? 'left' : 'center',
|
|
50
105
|
alignItems: "center",
|
|
51
106
|
sx: {
|
|
52
|
-
overflowX: isMultiSeries ? '
|
|
107
|
+
overflowX: isMultiSeries ? 'auto' : 'hidden',
|
|
108
|
+
'&::-webkit-scrollbar': {
|
|
109
|
+
height: '4px'
|
|
110
|
+
},
|
|
111
|
+
'&::-webkit-scrollbar-track': {
|
|
112
|
+
background: 'transparent'
|
|
113
|
+
},
|
|
114
|
+
'&::-webkit-scrollbar-thumb': {
|
|
115
|
+
background: 'transparent',
|
|
116
|
+
borderRadius: '2px'
|
|
117
|
+
},
|
|
118
|
+
'&:hover::-webkit-scrollbar-thumb': {
|
|
119
|
+
background: 'rgba(128, 128, 128, 0.4)'
|
|
120
|
+
},
|
|
121
|
+
scrollbarWidth: 'thin',
|
|
122
|
+
scrollbarColor: 'transparent transparent',
|
|
123
|
+
'&:hover': {
|
|
124
|
+
scrollbarColor: 'rgba(128, 128, 128, 0.4) transparent'
|
|
125
|
+
}
|
|
53
126
|
},
|
|
54
127
|
children: statChartData.length ? statChartData.map((series, index)=>{
|
|
55
128
|
const sparklineConfig = convertSparkline(chartsTheme, series.color, sparkline);
|
|
@@ -61,7 +134,10 @@ export const StatChartPanel = (props)=>{
|
|
|
61
134
|
sparkline: sparklineConfig,
|
|
62
135
|
showSeriesName: shouldShowLegend,
|
|
63
136
|
valueFontSize: valueFontSize,
|
|
64
|
-
colorMode: colorMode
|
|
137
|
+
colorMode: colorMode,
|
|
138
|
+
legendFontSize: legendFontSize,
|
|
139
|
+
alignmentText: alignmentText,
|
|
140
|
+
alignmentSeriesName: alignmentSeriesName
|
|
65
141
|
}, index);
|
|
66
142
|
}) : /*#__PURE__*/ _jsx(Typography, {
|
|
67
143
|
sx: {
|
|
@@ -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 type { SxProps } from '@mui/material';\nimport { Stack, Typography } from '@mui/material';\nimport type { GraphSeries, PersesChartsTheme, ValueMapping } from '@perses-dev/components';\nimport { useChartsTheme, applyValueMapping, createRegexFromString } from '@perses-dev/components';\nimport type { PanelProps, PanelData } from '@perses-dev/plugin-system';\nimport type { Labels, TimeSeriesData } from '@perses-dev/spec';\nimport type { TitleComponentOption } from 'echarts';\nimport type { FC } from 'react';\nimport { useMemo } from 'react';\n\nimport type { StatChartOptions } from './stat-chart-model';\nimport type { StatChartData } from './StatChartBase';\nimport { StatChartBase } from './StatChartBase';\nimport { calculateValue } from './utils/calculate-value';\nimport { convertSparkline } from './utils/data-transform';\nimport { getStatChartColor } from './utils/get-color';\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, 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 let shouldShowLegend = isMultiSeries;\n if (spec.legendMode === 'on') {\n shouldShowLegend = true;\n } else if (spec.legendMode === 'off') {\n shouldShowLegend = false;\n }\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":["Stack","Typography","useChartsTheme","applyValueMapping","createRegexFromString","useMemo","StatChartBase","calculateValue","convertSparkline","getStatChartColor","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;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,i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,CACtBK,OACAd,UACAe;IAEA,IAAIA,OAAO;QACT,OAAOA;IACT;IACA,IAAIf,UAAUxB,UAAUsC,UAAUE,aAAaF,UAAU,MAAM;QAC7D,OAAO5D,kBAAkB4D,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,QAAQlE,sBAAsB8D;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 type { SxProps } from '@mui/material';\nimport { Stack, Typography } from '@mui/material';\nimport type { GraphSeries, PersesChartsTheme, ValueMapping } from '@perses-dev/components';\nimport { useChartsTheme, applyValueMapping, createRegexFromString } from '@perses-dev/components';\nimport type { PanelProps, PanelData } from '@perses-dev/plugin-system';\nimport type { Labels, TimeSeriesData } from '@perses-dev/spec';\nimport type { TitleComponentOption } from 'echarts';\nimport type { FC } from 'react';\nimport { useMemo } from 'react';\n\nimport type { StatChartOptions } from './stat-chart-model';\nimport type { StatChartData } from './StatChartBase';\nimport { StatChartBase } from './StatChartBase';\nimport { measureTextWidth } from './utils/calculate-font-size';\nimport { calculateValue } from './utils/calculate-value';\nimport { convertSparkline } from './utils/data-transform';\nimport { formatStatChartValue } from './utils/format-stat-chart-value';\nimport { getStatChartColor } from './utils/get-color';\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, legendFontSize, colorMode } = spec;\n const chartsTheme = useChartsTheme();\n const statChartData = useStatChartData(queryResults, spec, chartsTheme);\n\n const isMultiSeries = statChartData.length > 1;\n\n // Find the widest value text (by pixel width) to use as alignment reference\n const alignmentText = useMemo(() => {\n if (!isMultiSeries) return undefined;\n const fontFamily = chartsTheme.echartsTheme.textStyle?.fontFamily ?? 'Lato';\n const fontSize = Number(chartsTheme.echartsTheme.textStyle?.fontSize) || 12;\n let widest = '';\n let maxWidth = 0;\n for (const series of statChartData) {\n const formatted = formatStatChartValue(series.calculatedValue, format);\n const width = measureTextWidth(formatted, 700, fontSize, fontFamily);\n if (width > maxWidth) {\n maxWidth = width;\n widest = formatted;\n }\n }\n return widest;\n }, [statChartData, format, isMultiSeries, chartsTheme.echartsTheme.textStyle]);\n\n // Find the longest series name (by pixel width) to unify legend sizing\n const alignmentSeriesName = useMemo(() => {\n if (!isMultiSeries) return undefined;\n const fontFamily = chartsTheme.echartsTheme.textStyle?.fontFamily ?? 'Lato';\n const fontSize = Number(chartsTheme.echartsTheme.textStyle?.fontSize) || 12;\n let widest = '';\n let maxWidth = 0;\n for (const series of statChartData) {\n const name = series.seriesData?.name ?? '';\n const width = measureTextWidth(name, 400, fontSize, fontFamily);\n if (width > maxWidth) {\n maxWidth = width;\n widest = name;\n }\n }\n return widest;\n }, [statChartData, isMultiSeries, chartsTheme.echartsTheme.textStyle]);\n\n // Handle three-state showLegend: 'on' | 'off' | 'auto' (or undefined for backward compatibility)\n let shouldShowLegend = isMultiSeries;\n if (spec.legendMode === 'on') {\n shouldShowLegend = true;\n } else if (spec.legendMode === 'off') {\n shouldShowLegend = false;\n }\n\n if (!contentDimensions) return null;\n\n // Calculates chart width — ensure cells are wide enough to show full series names\n const spacing = SPACING * (statChartData.length - 1);\n let chartWidth = (contentDimensions.width - spacing) / statChartData.length;\n if (isMultiSeries) {\n const fontFamily = chartsTheme.echartsTheme.textStyle?.fontFamily ?? 'Lato';\n const seriesNameFontSize = legendFontSize ?? Math.max(14, Math.min((contentDimensions.height * 0.15) / 1.2, 30));\n const padding = chartsTheme.container.padding.default;\n let maxTextWidth = MIN_WIDTH;\n for (const series of statChartData) {\n const nameWidth = measureTextWidth(series.seriesData?.name ?? '', 400, seriesNameFontSize, fontFamily);\n const valWidth = measureTextWidth(\n formatStatChartValue(series.calculatedValue, format),\n 700,\n seriesNameFontSize * 1.5,\n fontFamily,\n );\n const needed = Math.max(nameWidth, valWidth) + padding * 2;\n if (needed > maxTextWidth) maxTextWidth = needed;\n }\n chartWidth = Math.max(chartWidth, maxTextWidth);\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 ? 'auto' : 'hidden',\n '&::-webkit-scrollbar': {\n height: '4px',\n },\n '&::-webkit-scrollbar-track': {\n background: 'transparent',\n },\n '&::-webkit-scrollbar-thumb': {\n background: 'transparent',\n borderRadius: '2px',\n },\n '&:hover::-webkit-scrollbar-thumb': {\n background: 'rgba(128, 128, 128, 0.4)',\n },\n scrollbarWidth: 'thin',\n scrollbarColor: 'transparent transparent',\n '&:hover': {\n scrollbarColor: 'rgba(128, 128, 128, 0.4) transparent',\n },\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 legendFontSize={legendFontSize}\n alignmentText={alignmentText}\n alignmentSeriesName={alignmentSeriesName}\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":["Stack","Typography","useChartsTheme","applyValueMapping","createRegexFromString","useMemo","StatChartBase","measureTextWidth","calculateValue","convertSparkline","formatStatChartValue","getStatChartColor","MIN_WIDTH","SPACING","StatChartPanel","props","spec","contentDimensions","queryResults","format","sparkline","valueFontSize","legendFontSize","colorMode","chartsTheme","statChartData","useStatChartData","isMultiSeries","length","alignmentText","undefined","fontFamily","echartsTheme","textStyle","fontSize","Number","widest","maxWidth","series","formatted","calculatedValue","width","alignmentSeriesName","name","seriesData","shouldShowLegend","legendMode","spacing","chartWidth","seriesNameFontSize","Math","max","min","height","padding","container","default","maxTextWidth","nameWidth","valWidth","needed","noDataTextStyle","noDataOption","title","direction","justifyContent","alignItems","sx","overflowX","background","borderRadius","scrollbarWidth","scrollbarColor","map","index","sparklineConfig","color","data","showSeriesName","calculation","mappings","metricLabel","result","labelValue","getLabelValue","labels","displayValue","getValueOrLabel","formattedName","values","push","value","label","fieldLabel","key","Object","entries","regex","test"],"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,SAASA,KAAK,EAAEC,UAAU,QAAQ,gBAAgB;AAElD,SAASC,cAAc,EAAEC,iBAAiB,EAAEC,qBAAqB,QAAQ,yBAAyB;AAKlG,SAASC,OAAO,QAAQ,QAAQ;AAIhC,SAASC,aAAa,QAAQ,qBAAkB;AAChD,SAASC,gBAAgB,QAAQ,iCAA8B;AAC/D,SAASC,cAAc,QAAQ,6BAA0B;AACzD,SAASC,gBAAgB,QAAQ,4BAAyB;AAC1D,SAASC,oBAAoB,QAAQ,qCAAkC;AACvE,SAASC,iBAAiB,QAAQ,uBAAoB;AAEtD,MAAMC,YAAY;AAClB,MAAMC,UAAU;AAIhB,OAAO,MAAMC,iBAA0C,CAACC;IACtD,MAAM,EAAEC,IAAI,EAAEC,iBAAiB,EAAEC,YAAY,EAAE,GAAGH;IAElD,MAAM,EAAEI,MAAM,EAAEC,SAAS,EAAEC,aAAa,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAA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QAAQ7C,WAAW6C,MAAM;gBAC3B;gBAEAhE,cAAciE,IAAI,CAAC;oBAAElD,iBAAiB8C;oBAAc1C,YAAYN;oBAAQsC;gBAAM;YAChF;QACF;QACA,OAAOnD;IACT,GAAG;QAACP;QAAcF;QAAMQ;KAAY;AACtC;AAEA,MAAM+D,kBAAkB,CACtBI,OACAX,UACAY;IAEA,IAAIA,OAAO;QACT,OAAOA;IACT;IACA,IAAIZ,UAAUpD,UAAU+D,UAAU7D,aAAa6D,UAAU,MAAM;QAC7D,OAAOxF,kBAAkBwF,OAAOX,UAAUW,KAAK;IACjD,OAAO;QACL,OAAOA;IACT;AACF;AAEA,MAAMP,gBAAgB,CAACS,YAAqBR;IAC1C,IAAI,CAACA,UAAU,CAACQ,YAAY;QAC1B,OAAO/D;IACT;IACA,KAAK,MAAM,CAACgE,KAAKH,MAAM,IAAII,OAAOC,OAAO,CAACX,QAAS;QACjD,MAAMY,QAAQ7F,sBAAsByF;QACpC,IAAII,MAAMC,IAAI,CAACJ,MAAM;YACnB,OAAOH;QACT;IACF;IACA,OAAO7D;AACT"}
|
|
@@ -27,6 +27,7 @@ export interface StatChartOptions {
|
|
|
27
27
|
thresholds?: ThresholdOptions;
|
|
28
28
|
sparkline?: StatChartSparklineOptions;
|
|
29
29
|
valueFontSize?: FontSizeOption;
|
|
30
|
+
legendFontSize?: FontSizeOption;
|
|
30
31
|
mappings?: ValueMapping[];
|
|
31
32
|
colorMode?: ColorMode;
|
|
32
33
|
legendMode?: legendMode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stat-chart-model.d.ts","sourceRoot":"","sources":["../../src/stat-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC5G,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,KAAK,EAA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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 type { FontSizeOption, FormatOptions, ThresholdOptions, ValueMapping } from '@perses-dev/components';\nimport type { CalculationType, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport type { 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;
|
|
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 type { FontSizeOption, FormatOptions, ThresholdOptions, ValueMapping } from '@perses-dev/components';\nimport type { CalculationType, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport type { 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 legendFontSize?: 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;AAsBF,OAAO,SAASC;IACd,OAAO;QACLC,aAAa;QACbC,QAAQ;YACNC,MAAM;QACR;QACAC,WAAW,CAAC;QACZC,YAAY;IACd;AACF"}
|
|
@@ -8,6 +8,10 @@ interface CalculateFontSize {
|
|
|
8
8
|
maxSize?: number;
|
|
9
9
|
fontSizeOverride?: FontSizeOption;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Measure the pixel width of text at a given font weight and size.
|
|
13
|
+
*/
|
|
14
|
+
export declare function measureTextWidth(text: string, fontWeight: number, fontSize: number, fontFamily: string): number;
|
|
11
15
|
/**
|
|
12
16
|
* Find the optimal font size given available space
|
|
13
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculate-font-size.d.ts","sourceRoot":"","sources":["../../../src/utils/calculate-font-size.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,cAAc,CAAC;CACnC;AAcD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,UAAU,EACV,KAAK,EACL,MAAM,EACN,UAAU,EACV,OAAO,EACP,gBAAgB,GACjB,EAAE,iBAAiB,GAAG,MAAM,CA0B5B"}
|
|
1
|
+
{"version":3,"file":"calculate-font-size.d.ts","sourceRoot":"","sources":["../../../src/utils/calculate-font-size.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAG7D,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,cAAc,CAAC;CACnC;AAcD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAI/G;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,UAAU,EACV,KAAK,EACL,MAAM,EACN,UAAU,EACV,OAAO,EACP,gBAAgB,GACjB,EAAE,iBAAiB,GAAG,MAAM,CA0B5B"}
|
|
@@ -21,6 +21,13 @@ function getGlobalCanvasContext() {
|
|
|
21
21
|
}
|
|
22
22
|
return canvasContext;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Measure the pixel width of text at a given font weight and size.
|
|
26
|
+
*/ export function measureTextWidth(text, fontWeight, fontSize, fontFamily) {
|
|
27
|
+
const ctx = getGlobalCanvasContext();
|
|
28
|
+
ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
29
|
+
return ctx.measureText(text).width;
|
|
30
|
+
}
|
|
24
31
|
/**
|
|
25
32
|
* Find the optimal font size given available space
|
|
26
33
|
*/ export function useOptimalFontSize({ text, fontWeight, width, height, lineHeight, maxSize, fontSizeOverride }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/calculate-font-size.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 type { FontSizeOption } from '@perses-dev/components';\nimport { useChartsTheme } from '@perses-dev/components';\n\ninterface CalculateFontSize {\n text: string;\n fontWeight: number;\n width: number;\n height: number;\n lineHeight: number;\n maxSize?: number;\n fontSizeOverride?: FontSizeOption;\n}\n\nlet canvasContext: CanvasRenderingContext2D | null;\n\nfunction getGlobalCanvasContext(): CanvasRenderingContext2D {\n if (!canvasContext) {\n canvasContext = document.createElement('canvas').getContext('2d');\n if (canvasContext === null) {\n throw new Error('Canvas context is null.');\n }\n }\n return canvasContext;\n}\n\n/**\n * Find the optimal font size given available space\n */\nexport function useOptimalFontSize({\n text,\n fontWeight,\n width,\n height,\n lineHeight,\n maxSize,\n fontSizeOverride,\n}: CalculateFontSize): number {\n const ctx = getGlobalCanvasContext();\n const { echartsTheme } = useChartsTheme();\n\n // if user has selected a font size in the settings, use it instead of calculating the optimal size\n if (fontSizeOverride !== undefined) {\n return Number(fontSizeOverride);\n }\n\n const textStyle = echartsTheme.textStyle;\n const fontSize = Number(textStyle?.fontSize ?? 12);\n const fontFamily = textStyle?.fontFamily ?? 'Lato';\n\n // set the font on the canvas context\n const fontStyle = `${fontWeight} ${fontSize}px ${fontFamily}`;\n ctx.font = fontStyle;\n // measure the width of the text with the given font style\n const textMetrics: TextMetrics = ctx.measureText(text);\n\n // check how much bigger we can make the font while staying within the width and height\n const fontSizeBasedOnWidth = (width / textMetrics.width) * fontSize;\n const fontSizeBasedOnHeight = height / lineHeight;\n\n // return the smaller font size\n const finalFontSize = Math.min(fontSizeBasedOnHeight, fontSizeBasedOnWidth);\n return maxSize ? Math.min(finalFontSize, maxSize) : finalFontSize;\n}\n"],"names":["useChartsTheme","canvasContext","getGlobalCanvasContext","document","createElement","getContext","Error","
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/calculate-font-size.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 type { FontSizeOption } from '@perses-dev/components';\nimport { useChartsTheme } from '@perses-dev/components';\n\ninterface CalculateFontSize {\n text: string;\n fontWeight: number;\n width: number;\n height: number;\n lineHeight: number;\n maxSize?: number;\n fontSizeOverride?: FontSizeOption;\n}\n\nlet canvasContext: CanvasRenderingContext2D | null;\n\nfunction getGlobalCanvasContext(): CanvasRenderingContext2D {\n if (!canvasContext) {\n canvasContext = document.createElement('canvas').getContext('2d');\n if (canvasContext === null) {\n throw new Error('Canvas context is null.');\n }\n }\n return canvasContext;\n}\n\n/**\n * Measure the pixel width of text at a given font weight and size.\n */\nexport function measureTextWidth(text: string, fontWeight: number, fontSize: number, fontFamily: string): number {\n const ctx = getGlobalCanvasContext();\n ctx.font = `${fontWeight} ${fontSize}px ${fontFamily}`;\n return ctx.measureText(text).width;\n}\n\n/**\n * Find the optimal font size given available space\n */\nexport function useOptimalFontSize({\n text,\n fontWeight,\n width,\n height,\n lineHeight,\n maxSize,\n fontSizeOverride,\n}: CalculateFontSize): number {\n const ctx = getGlobalCanvasContext();\n const { echartsTheme } = useChartsTheme();\n\n // if user has selected a font size in the settings, use it instead of calculating the optimal size\n if (fontSizeOverride !== undefined) {\n return Number(fontSizeOverride);\n }\n\n const textStyle = echartsTheme.textStyle;\n const fontSize = Number(textStyle?.fontSize ?? 12);\n const fontFamily = textStyle?.fontFamily ?? 'Lato';\n\n // set the font on the canvas context\n const fontStyle = `${fontWeight} ${fontSize}px ${fontFamily}`;\n ctx.font = fontStyle;\n // measure the width of the text with the given font style\n const textMetrics: TextMetrics = ctx.measureText(text);\n\n // check how much bigger we can make the font while staying within the width and height\n const fontSizeBasedOnWidth = (width / textMetrics.width) * fontSize;\n const fontSizeBasedOnHeight = height / lineHeight;\n\n // return the smaller font size\n const finalFontSize = Math.min(fontSizeBasedOnHeight, fontSizeBasedOnWidth);\n return maxSize ? Math.min(finalFontSize, maxSize) : finalFontSize;\n}\n"],"names":["useChartsTheme","canvasContext","getGlobalCanvasContext","document","createElement","getContext","Error","measureTextWidth","text","fontWeight","fontSize","fontFamily","ctx","font","measureText","width","useOptimalFontSize","height","lineHeight","maxSize","fontSizeOverride","echartsTheme","undefined","Number","textStyle","fontStyle","textMetrics","fontSizeBasedOnWidth","fontSizeBasedOnHeight","finalFontSize","Math","min"],"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,SAASA,cAAc,QAAQ,yBAAyB;AAYxD,IAAIC;AAEJ,SAASC;IACP,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d.ts","sourceRoot":"","sources":["../../../src/utils/calculate-value.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAuB,MAAM,2BAA2B,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"calculate-value.d.ts","sourceRoot":"","sources":["../../../src/utils/calculate-value.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAuB,MAAM,2BAA2B,CAAC;AACjF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,eAAO,MAAM,cAAc,gBACZ,eAAe,cAChB,UAAU,KACrB,UAAU,CAAC,CAAC,OAAO,eAAe,CAAC,CAAC,eAAe,CAAC,CAMtD,CAAC"}
|
|
@@ -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,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAG5D,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"format-stat-chart-value.d.ts","sourceRoot":"","sources":["../../../src/utils/format-stat-chart-value.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAG5D,eAAO,MAAM,oBAAoB,WAAY,MAAM,GAAG,MAAM,GAAG,IAAI,WAAW,aAAa,KAAG,MAU7F,CAAC"}
|