@perses-dev/stat-chart-plugin 0.11.0 → 0.12.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mf/js/StatChart.7df52118.js +6 -0
- package/__mf/js/async/119.b85eb681.js +83 -0
- package/__mf/js/async/{964.2c4a1982.js → 121.3f61f76f.js} +2 -2
- package/__mf/js/async/{488.daa22b59.js → 177.eb221fda.js} +1 -1
- package/__mf/js/async/192.8a915b5e.js +1 -0
- package/__mf/js/async/2.086684e1.js +1 -0
- package/__mf/js/async/235.046777ba.js +1 -0
- package/__mf/js/async/252.05fbd2b1.js +22 -0
- package/__mf/js/async/274.d4e1eee8.js +2 -0
- package/__mf/js/async/293.d523e0ab.js +1 -0
- package/__mf/js/async/302.b54c0505.js +2 -0
- package/__mf/js/async/356.f5a1c439.js +1 -0
- package/__mf/js/async/392.a8143615.js +2 -0
- package/__mf/js/async/450.6c3d739b.js +1 -0
- package/__mf/js/async/465.fc9973fc.js +2 -0
- package/__mf/js/async/470.57be52e3.js +2 -0
- package/__mf/js/async/555.b1ac32bc.js +7 -0
- package/__mf/js/async/{214.fbd87600.js → 587.6d7b1a7f.js} +1 -1
- package/__mf/js/async/588.496be9cb.js +1 -0
- package/__mf/js/async/616.f83c59ff.js +1 -0
- package/__mf/js/async/71.603fe88a.js +1 -0
- package/__mf/js/async/721.0467c07c.js +1 -0
- package/__mf/js/async/873.c0881a00.js +1 -0
- package/__mf/js/async/911.29a700f7.js +65 -0
- package/__mf/js/async/941.c1c0755a.js +2 -0
- package/__mf/js/async/{738.ab4d3413.js → 968.eb198ceb.js} +1 -1
- package/__mf/js/async/978.c7471d24.js +1 -0
- package/__mf/js/async/__federation_expose_StatChart.2dcf8b3a.js +1 -0
- package/__mf/js/async/lib-router.ed92c54d.js +2 -0
- package/__mf/js/main.4a371943.js +6 -0
- package/lib/StatChartBase.js +1 -1
- package/lib/StatChartBase.js.map +1 -1
- package/lib/StatChartOptionsEditorSettings.d.ts.map +1 -1
- package/lib/StatChartOptionsEditorSettings.js +60 -32
- package/lib/StatChartOptionsEditorSettings.js.map +1 -1
- package/lib/StatChartPanel.d.ts.map +1 -1
- package/lib/StatChartPanel.js +3 -1
- package/lib/StatChartPanel.js.map +1 -1
- package/lib/bootstrap.js +1 -1
- package/lib/bootstrap.js.map +1 -1
- package/lib/cjs/StatChartOptionsEditorSettings.js +58 -30
- package/lib/cjs/StatChartPanel.js +3 -1
- package/lib/cjs/index-federation.js +12 -12
- package/lib/cjs/stat-chart-model.js +25 -4
- package/lib/stat-chart-model.d.ts +9 -1
- package/lib/stat-chart-model.d.ts.map +1 -1
- package/lib/stat-chart-model.js +19 -1
- package/lib/stat-chart-model.js.map +1 -1
- package/mf-manifest.json +34 -34
- package/mf-stats.json +34 -34
- package/package.json +4 -4
- package/__mf/js/StatChart.7c0ea76c.js +0 -5
- package/__mf/js/async/173.879ec01b.js +0 -2
- package/__mf/js/async/224.82f1452f.js +0 -1
- package/__mf/js/async/238.5475e796.js +0 -1
- package/__mf/js/async/292.a2435289.js +0 -1
- package/__mf/js/async/298.2736d1ac.js +0 -1
- package/__mf/js/async/409.b9808041.js +0 -1
- package/__mf/js/async/518.d772e916.js +0 -2
- package/__mf/js/async/651.f2aaf868.js +0 -1
- package/__mf/js/async/694.d6624664.js +0 -1
- package/__mf/js/async/711.30b0444f.js +0 -22
- package/__mf/js/async/740.2a430835.js +0 -1
- package/__mf/js/async/75.c51a3e1b.js +0 -1
- package/__mf/js/async/764.c5215ca9.js +0 -83
- package/__mf/js/async/770.edf0b438.js +0 -1
- package/__mf/js/async/804.ee813935.js +0 -1
- package/__mf/js/async/85.559c8591.js +0 -7
- package/__mf/js/async/863.41130256.js +0 -2
- package/__mf/js/async/954.8c39b26f.js +0 -2
- package/__mf/js/async/960.a322ec99.js +0 -2
- package/__mf/js/async/962.5508c92d.js +0 -1
- package/__mf/js/async/966.4cf38e97.js +0 -65
- package/__mf/js/async/981.c97e9bc4.js +0 -2
- package/__mf/js/async/__federation_expose_StatChart.20659f63.js +0 -1
- package/__mf/js/async/lib-router.5a2b101a.js +0 -2
- package/__mf/js/main.b4991a3c.js +0 -5
- /package/__mf/css/async/{263.d3010b86.css → 442.d3010b86.css} +0 -0
- /package/__mf/css/async/{341.d3010b86.css → 61.d3010b86.css} +0 -0
- /package/__mf/css/async/{759.d3010b86.css → 823.d3010b86.css} +0 -0
- /package/__mf/js/async/{764.c5215ca9.js.LICENSE.txt → 119.b85eb681.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{964.2c4a1982.js.LICENSE.txt → 121.3f61f76f.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{711.30b0444f.js.LICENSE.txt → 252.05fbd2b1.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{960.a322ec99.js.LICENSE.txt → 274.d4e1eee8.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{518.d772e916.js.LICENSE.txt → 302.b54c0505.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{981.c97e9bc4.js.LICENSE.txt → 392.a8143615.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{954.8c39b26f.js.LICENSE.txt → 465.fc9973fc.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{173.879ec01b.js.LICENSE.txt → 470.57be52e3.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{85.559c8591.js.LICENSE.txt → 555.b1ac32bc.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{863.41130256.js.LICENSE.txt → 941.c1c0755a.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{lib-router.5a2b101a.js.LICENSE.txt → lib-router.ed92c54d.js.LICENSE.txt} +0 -0
package/lib/StatChartBase.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/StatChartBase.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FC, ReactNode, useMemo } from 'react';\nimport { FormatOptions } from '@perses-dev/core';\nimport { Box, Typography, styled, useTheme } from '@mui/material';\nimport merge from 'lodash/merge';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, FontSizeOption, GraphSeries, useChartsTheme } from '@perses-dev/components';\nimport chroma from 'chroma-js';\nimport { useOptimalFontSize } from './utils/calculate-font-size';\nimport { formatStatChartValue } from './utils/format-stat-chart-value';\nimport { ColorMode } from './stat-chart-model';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst LINE_HEIGHT = 1.2;\nconst SERIES_NAME_MAX_FONT_SIZE = 30;\nconst SERIES_NAME_FONT_WEIGHT = 400;\nconst VALUE_FONT_WEIGHT = 700;\nconst WHITE_COLOR_CODE = '#FFFFFF';\nconst BLACK_COLOR_CODE = '#000000';\n\nexport interface StatChartData {\n color: string;\n calculatedValue?: string | number | null;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n format?: FormatOptions;\n sparkline?: LineSeriesOption;\n showSeriesName?: boolean;\n valueFontSize?: FontSizeOption;\n colorMode?: ColorMode;\n}\n\nexport const StatChartBase: FC<StatChartProps> = (props) => {\n const {\n width,\n height,\n data,\n data: { color },\n sparkline,\n showSeriesName,\n format,\n valueFontSize,\n colorMode,\n } = props;\n\n const {\n palette: {\n mode: paletteMode,\n text: { secondary },\n },\n } = useTheme();\n const chartsTheme = useChartsTheme();\n const formattedValue = formatStatChartValue(data.calculatedValue, format);\n const containerPadding = chartsTheme.container.padding.default;\n\n // calculate series name font size and height\n let seriesNameFontSize = useOptimalFontSize({\n text: data?.seriesData?.name ?? '',\n fontWeight: SERIES_NAME_FONT_WEIGHT,\n width,\n height: height * 0.125, // assume series name will take 12.5% of available height\n lineHeight: LINE_HEIGHT,\n maxSize: SERIES_NAME_MAX_FONT_SIZE,\n });\n\n const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;\n\n // calculate value font size and height\n const availableWidth = width - containerPadding * 2;\n const availableHeight = height - seriesNameHeight;\n const optimalValueFontSize = useOptimalFontSize({\n text: formattedValue,\n // override the font size if user selects it in the settings\n fontSizeOverride: valueFontSize,\n fontWeight: VALUE_FONT_WEIGHT,\n // without sparkline, use only 50% of the available width so it looks better for multiseries\n width: sparkline ? availableWidth : availableWidth * 0.5,\n // with sparkline, use only 25% of available height to leave room for chart\n // without sparkline, value should take up 90% of available space\n height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,\n lineHeight: LINE_HEIGHT,\n });\n const valueFontHeight = optimalValueFontSize * LINE_HEIGHT;\n\n // make sure the series name font size is slightly smaller than value font size\n seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (!data.seriesData) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline) {\n const lineSeries = {\n type: 'line',\n name: series.name,\n data: series.values,\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n\n const clonedSparkLine = { ...sparkline };\n if (colorMode === 'background_solid') {\n clonedSparkLine.areaStyle = { color: WHITE_COLOR_CODE, opacity: 0.4 };\n clonedSparkLine.lineStyle = { color: WHITE_COLOR_CODE, opacity: 1 };\n }\n\n const mergedSeries = merge(lineSeries, clonedSparkLine);\n statSeries.push(mergedSeries);\n }\n\n const option: EChartsCoreOption = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n min: (value: { min: number; max: number }): number => {\n if (value.min >= 0 && value.min <= 1) {\n // helps with percent-decimal units, or datasets that return 0 or 1 booleans\n return 0;\n }\n return value.min;\n },\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline, colorMode]);\n\n const textAlignment = sparkline ? 'auto' : 'center';\n\n const styledFormattedValue = useMemo(() => {\n let valueColor = '';\n\n switch (colorMode) {\n case 'background_solid':\n valueColor =\n chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE)\n ? WHITE_COLOR_CODE\n : BLACK_COLOR_CODE;\n break;\n case 'none':\n valueColor = paletteMode === 'dark' ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;\n break;\n case 'value':\n default:\n valueColor = color;\n break;\n }\n\n return (\n <Value variant=\"h3\" color={valueColor} fontSize={optimalValueFontSize} padding={containerPadding}>\n {formattedValue}\n </Value>\n );\n }, [colorMode, containerPadding, optimalValueFontSize, formattedValue, color, paletteMode]);\n\n const seriesName = useMemo((): ReactNode | null => {\n if (!showSeriesName) return null;\n\n let textColor = '';\n\n switch (colorMode) {\n case 'background_solid':\n textColor =\n chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE)\n ? WHITE_COLOR_CODE\n : BLACK_COLOR_CODE;\n break;\n case 'none':\n case 'value':\n default:\n textColor = secondary;\n break;\n }\n\n return (\n <SeriesName padding={containerPadding} fontSize={seriesNameFontSize} color={textColor}>\n {data.seriesData?.name}\n </SeriesName>\n );\n }, [colorMode, showSeriesName, secondary, color, containerPadding, seriesNameFontSize, data?.seriesData?.name]);\n\n return (\n <Box\n sx={{\n height: '100%',\n width: '100%',\n backgroundColor: colorMode === 'background_solid' ? color : 'transparent',\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n }}\n >\n {seriesName}\n {styledFormattedValue}\n {sparkline && (\n <EChart\n sx={{\n width: '100%',\n }}\n style={{\n // ECharts rounds the height to the nearest integer by default.\n // This can cause unneccessary scrollbars when the total height of this chart exceeds the 'height' prop.\n height: Math.floor(height - seriesNameHeight - valueFontHeight),\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n};\n\nconst SeriesName = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'padding' && prop !== 'fontSize',\n})<{ padding?: number; fontSize?: number; textAlignment?: string; color?: string }>(({ padding, fontSize, color }) => ({\n color: color,\n padding: `${padding}px`,\n fontSize: `${fontSize}px`,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n}));\n\nconst Value = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline',\n})<{ color?: string; padding?: number; fontSize?: number; sparkline?: boolean }>(\n ({ theme, color, padding, fontSize, sparkline }) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `${fontSize}px`,\n padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,\n whiteSpace: 'nowrap',\n lineHeight: LINE_HEIGHT,\n })\n);\n"],"names":["useMemo","Box","Typography","styled","useTheme","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","EChart","useChartsTheme","chroma","useOptimalFontSize","formatStatChartValue","LINE_HEIGHT","SERIES_NAME_MAX_FONT_SIZE","SERIES_NAME_FONT_WEIGHT","VALUE_FONT_WEIGHT","WHITE_COLOR_CODE","BLACK_COLOR_CODE","StatChartBase","props","width","height","data","color","sparkline","showSeriesName","format","valueFontSize","colorMode","palette","mode","paletteMode","text","secondary","chartsTheme","formattedValue","calculatedValue","containerPadding","container","padding","default","seriesNameFontSize","seriesData","name","fontWeight","lineHeight","maxSize","seriesNameHeight","availableWidth","availableHeight","optimalValueFontSize","fontSizeOverride","valueFontHeight","Math","min","option","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","clonedSparkLine","areaStyle","opacity","lineStyle","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","value","tooltip","textAlignment","styledFormattedValue","valueColor","contrast","Value","variant","fontSize","seriesName","textColor","SeriesName","sx","backgroundColor","display","flexDirection","justifyContent","alignItems","style","floor","theme","echartsTheme","renderer","shouldForwardProp","prop","overflow","textOverflow","whiteSpace","primary"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAwBA,OAAO,QAAQ,QAAQ;AAE/C,SAASC,GAAG,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,gBAAgB;AAClE,OAAOC,WAAW,eAAe;AACjC,SAASC,GAAG,QAA2B,eAAe;AACtD,SAASC,aAAaC,gBAAgB,QAA0B,iBAAiB;AACjF,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,qBAAqB;AACvG,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,MAAM,EAA+BC,cAAc,QAAQ,yBAAyB;AAC7F,OAAOC,YAAY,YAAY;AAC/B,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,oBAAoB,QAAQ,kCAAkC;AAGvEZ,IAAI;IAACE;IAAkBC;IAAeC;IAAkBC;IAAgBC;IAAkBC;CAAe;AAEzG,MAAMM,cAAc;AACpB,MAA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sE,YAAY;gBAC/BC,UAAS;;;;AAKnB,EAAE;AAEF,MAAMX,aAAalG,OAAOD,YAAY;IACpC+G,mBAAmB,CAACC,OAASA,SAAS,aAAaA,SAAS;AAC9D,GAAoF,CAAC,EAAEpE,OAAO,EAAEoD,QAAQ,EAAEpE,KAAK,EAAE,GAAM,CAAA;QACrHA,OAAOA;QACPgB,SAAS,GAAGA,QAAQ,EAAE,CAAC;QACvBoD,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBiB,UAAU;QACVC,cAAc;QACdC,YAAY;IACd,CAAA;AAEA,MAAMrB,QAAQ7F,OAAOD,YAAY;IAC/B+G,mBAAmB,CAACC,OAASA,SAAS,WAAWA,SAAS,aAAaA,SAAS,cAAcA,SAAS;AACzG,GACE,CAAC,EAAEJ,KAAK,EAAEhF,KAAK,EAAEgB,OAAO,EAAEoD,QAAQ,EAAEnE,SAAS,EAAE,GAAM,CAAA;QACnDD,OAAOA,SAASgF,MAAM1E,OAAO,CAACG,IAAI,CAAC+E,OAAO;QAC1CpB,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBpD,SAASf,YAAY,GAAGe,QAAQ,GAAG,EAAEA,QAAQ,KAAK,EAAEA,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,EAAEA,QAAQ,EAAE,CAAC;QACnFuE,YAAY;QACZjE,YAAYjC;IACd,CAAA"}
|
|
1
|
+
{"version":3,"sources":["../../src/StatChartBase.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { FC, ReactNode, useMemo } from 'react';\nimport { FormatOptions } from '@perses-dev/core';\nimport { Box, Typography, styled, useTheme } from '@mui/material';\nimport merge from 'lodash/merge';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, FontSizeOption, GraphSeries, useChartsTheme } from '@perses-dev/components';\nimport chroma from 'chroma-js';\nimport { useOptimalFontSize } from './utils/calculate-font-size';\nimport { formatStatChartValue } from './utils/format-stat-chart-value';\nimport { ColorMode } from './stat-chart-model';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst LINE_HEIGHT = 1.2;\nconst SERIES_NAME_MAX_FONT_SIZE = 30;\nconst SERIES_NAME_FONT_WEIGHT = 400;\nconst VALUE_FONT_WEIGHT = 700;\nconst WHITE_COLOR_CODE = '#FFFFFF';\nconst BLACK_COLOR_CODE = '#000000';\n\nexport interface StatChartData {\n color: string;\n calculatedValue?: string | number | null;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n format?: FormatOptions;\n sparkline?: LineSeriesOption;\n showSeriesName?: boolean;\n valueFontSize?: FontSizeOption;\n colorMode?: ColorMode;\n}\n\nexport const StatChartBase: FC<StatChartProps> = (props) => {\n const {\n width,\n height,\n data,\n data: { color },\n sparkline,\n showSeriesName,\n format,\n valueFontSize,\n colorMode,\n } = props;\n\n const {\n palette: {\n mode: paletteMode,\n text: { secondary },\n },\n } = useTheme();\n const chartsTheme = useChartsTheme();\n const formattedValue = formatStatChartValue(data.calculatedValue, format);\n const containerPadding = chartsTheme.container.padding.default;\n\n // calculate series name font size and height\n let seriesNameFontSize = useOptimalFontSize({\n text: data?.seriesData?.name ?? '',\n fontWeight: SERIES_NAME_FONT_WEIGHT,\n width,\n height: height * 0.125, // assume series name will take 12.5% of available height\n lineHeight: LINE_HEIGHT,\n maxSize: SERIES_NAME_MAX_FONT_SIZE,\n });\n\n const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;\n\n // calculate value font size and height\n const availableWidth = width - containerPadding * 2;\n const availableHeight = height - seriesNameHeight;\n const optimalValueFontSize = useOptimalFontSize({\n text: formattedValue,\n // override the font size if user selects it in the settings\n fontSizeOverride: valueFontSize,\n fontWeight: VALUE_FONT_WEIGHT,\n // without sparkline, use only 50% of the available width so it looks better for multiseries\n width: sparkline ? availableWidth : availableWidth * 0.5,\n // with sparkline, use only 25% of available height to leave room for chart\n // without sparkline, value should take up 90% of available space\n height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,\n lineHeight: LINE_HEIGHT,\n });\n const valueFontHeight = optimalValueFontSize * LINE_HEIGHT;\n\n // make sure the series name font size is slightly smaller than value font size\n seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (!data.seriesData) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline) {\n const lineSeries = {\n type: 'line',\n name: series.name,\n data: series.values,\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n\n const clonedSparkLine = { ...sparkline };\n if (colorMode === 'background_solid') {\n clonedSparkLine.areaStyle = { color: WHITE_COLOR_CODE, opacity: 0.4 };\n clonedSparkLine.lineStyle = { color: WHITE_COLOR_CODE, opacity: 1 };\n }\n\n const mergedSeries = merge(lineSeries, clonedSparkLine);\n statSeries.push(mergedSeries);\n }\n\n const option: EChartsCoreOption = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n min: (value: { min: number; max: number }): number => {\n if (value.min >= 0 && value.min <= 1) {\n // helps with percent-decimal units, or datasets that return 0 or 1 booleans\n return 0;\n }\n return value.min;\n },\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline, colorMode]);\n\n const textAlignment = sparkline ? 'auto' : 'center';\n\n const styledFormattedValue = useMemo(() => {\n let valueColor = '';\n\n switch (colorMode) {\n case 'background_solid':\n valueColor =\n chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE)\n ? WHITE_COLOR_CODE\n : BLACK_COLOR_CODE;\n break;\n case 'none':\n valueColor = paletteMode === 'dark' ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;\n break;\n case 'value':\n default:\n valueColor = color;\n break;\n }\n\n return (\n <Value variant=\"h3\" color={valueColor} fontSize={optimalValueFontSize} padding={containerPadding}>\n {formattedValue}\n </Value>\n );\n }, [colorMode, containerPadding, optimalValueFontSize, formattedValue, color, paletteMode]);\n\n const seriesName = useMemo((): ReactNode | null => {\n if (!showSeriesName) return null;\n\n let textColor = '';\n\n switch (colorMode) {\n case 'background_solid':\n textColor =\n chroma.contrast(color, WHITE_COLOR_CODE) > chroma.contrast(color, BLACK_COLOR_CODE)\n ? WHITE_COLOR_CODE\n : BLACK_COLOR_CODE;\n break;\n case 'none':\n case 'value':\n default:\n textColor = secondary;\n break;\n }\n\n return (\n <SeriesName padding={containerPadding} fontSize={seriesNameFontSize} color={textColor}>\n {data.seriesData?.name}\n </SeriesName>\n );\n }, [colorMode, showSeriesName, secondary, color, containerPadding, seriesNameFontSize, data?.seriesData?.name]);\n\n return (\n <Box\n sx={{\n height: '100%',\n width: '100%',\n backgroundColor: colorMode === 'background_solid' ? color : 'transparent',\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n }}\n >\n {seriesName}\n {styledFormattedValue}\n {sparkline && (\n <EChart\n sx={{\n width: '100%',\n }}\n style={{\n // ECharts rounds the height to the nearest integer by default.\n // This can cause unneccessary scrollbars when the total height of this chart exceeds the 'height' prop.\n height: Math.floor(height - seriesNameHeight - valueFontHeight),\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n};\n\nconst SeriesName = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'padding' && prop !== 'fontSize',\n})<{ padding?: number; fontSize?: number; textAlignment?: string; color?: string }>(({ padding, fontSize, color }) => ({\n color: color,\n padding: `${padding}px`,\n fontSize: `${fontSize}px`,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n}));\n\nconst Value = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline',\n})<{ color?: string; padding?: number; fontSize?: number; sparkline?: boolean }>(\n ({ theme, color, padding, fontSize, sparkline }) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `${fontSize}px`,\n padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,\n whiteSpace: 'nowrap',\n lineHeight: LINE_HEIGHT,\n })\n);\n"],"names":["useMemo","Box","Typography","styled","useTheme","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","EChart","useChartsTheme","chroma","useOptimalFontSize","formatStatChartValue","LINE_HEIGHT","SERIES_NAME_MAX_FONT_SIZE","SERIES_NAME_FONT_WEIGHT","VALUE_FONT_WEIGHT","WHITE_COLOR_CODE","BLACK_COLOR_CODE","StatChartBase","props","width","height","data","color","sparkline","showSeriesName","format","valueFontSize","colorMode","palette","mode","paletteMode","text","secondary","chartsTheme","formattedValue","calculatedValue","containerPadding","container","padding","default","seriesNameFontSize","seriesData","name","fontWeight","lineHeight","maxSize","seriesNameHeight","availableWidth","availableHeight","optimalValueFontSize","fontSizeOverride","valueFontHeight","Math","min","option","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","clonedSparkLine","areaStyle","opacity","lineStyle","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","value","tooltip","textAlignment","styledFormattedValue","valueColor","contrast","Value","variant","fontSize","seriesName","textColor","SeriesName","sx","backgroundColor","display","flexDirection","justifyContent","alignItems","style","floor","theme","echartsTheme","renderer","shouldForwardProp","prop","overflow","textOverflow","whiteSpace","primary"],"mappings":";AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAwBA,OAAO,QAAQ,QAAQ;AAE/C,SAASC,GAAG,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,gBAAgB;AAClE,OAAOC,WAAW,eAAe;AACjC,SAASC,GAAG,QAA2B,eAAe;AACtD,SAASC,aAAaC,gBAAgB,QAA0B,iBAAiB;AACjF,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,qBAAqB;AACvG,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,MAAM,EAA+BC,cAAc,QAAQ,yBAAyB;AAC7F,OAAOC,YAAY,YAAY;AAC/B,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,oBAAoB,QAAQ,kCAAkC;AAGvEZ,IAAI;IAACE;IAAkBC;IAAeC;IAAkBC;IAAgBC;IAAkBC;CAAe;AAEzG,MAAMM,cAAc;AACpB,MAAMC,4BAA4B;AAClC,MAAMC,0BAA0B;AAChC,MAAMC,oBAAoB;AAC1B,MAAMC,mBAAmB;AACzB,MAAMC,mBAAmB;AAmBzB,OAAO,MAAMC,gBAAoC,CAACC;IAChD,MAAM,EACJC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJA,MAAM,EAAEC,KAAK,EAAE,EACfC,SAAS,EACTC,cAAc,EACd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AAQ,EAAE,CAAC;QACvBoD,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBiB,UAAU;QACVC,cAAc;QACdC,YAAY;IACd,CAAA;AAEA,MAAMrB,QAAQ7F,OAAOD,YAAY;IAC/B+G,mBAAmB,CAACC,OAASA,SAAS,WAAWA,SAAS,aAAaA,SAAS,cAAcA,SAAS;AACzG,GACE,CAAC,EAAEJ,KAAK,EAAEhF,KAAK,EAAEgB,OAAO,EAAEoD,QAAQ,EAAEnE,SAAS,EAAE,GAAM,CAAA;QACnDD,OAAOA,SAASgF,MAAM1E,OAAO,CAACG,IAAI,CAAC+E,OAAO;QAC1CpB,UAAU,GAAGA,SAAS,EAAE,CAAC;QACzBpD,SAASf,YAAY,GAAGe,QAAQ,GAAG,EAAEA,QAAQ,KAAK,EAAEA,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,EAAEA,QAAQ,EAAE,CAAC;QACnFuE,YAAY;QACZjE,YAAYjC;IACd,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatChartOptionsEditorSettings.d.ts","sourceRoot":"","sources":["../../src/StatChartOptionsEditorSettings.tsx"],"names":[],"mappings":"AAqCA,OAAO,EAAE,YAAY,EAAwB,MAAM,OAAO,CAAC;AAC3D,OAAO,
|
|
1
|
+
{"version":3,"file":"StatChartOptionsEditorSettings.d.ts","sourceRoot":"","sources":["../../src/StatChartOptionsEditorSettings.tsx"],"names":[],"mappings":"AAqCA,OAAO,EAAE,YAAY,EAAwB,MAAM,OAAO,CAAC;AAC3D,OAAO,EAML,2BAA2B,EAC5B,MAAM,oBAAoB,CAAC;AAI5B,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,2BAA2B,GAAG,YAAY,CA0I/F"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
2
|
// Copyright 2023 The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,14 +11,13 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { Switch } from '@mui/material';
|
|
15
15
|
import { FontSizeSelector, FormatControls, OptionsEditorColumn, OptionsEditorControl, OptionsEditorGrid, OptionsEditorGroup, SettingsAutocomplete, ThresholdsEditor } from '@perses-dev/components';
|
|
16
16
|
import { CalculationSelector, MetricLabelInput } from '@perses-dev/plugin-system';
|
|
17
17
|
import { produce } from 'immer';
|
|
18
18
|
import merge from 'lodash/merge';
|
|
19
19
|
import { useCallback, useMemo } from 'react';
|
|
20
|
-
import { COLOR_MODE_LABELS } from './stat-chart-model';
|
|
20
|
+
import { COLOR_MODE_LABELS, SHOW_LEGEND_LABELS } from './stat-chart-model';
|
|
21
21
|
const DEFAULT_FORMAT = {
|
|
22
22
|
unit: 'percent-decimal'
|
|
23
23
|
};
|
|
@@ -35,6 +35,14 @@ export function StatChartOptionsEditorSettings(props) {
|
|
|
35
35
|
draft.metricLabel = newCalculation;
|
|
36
36
|
}));
|
|
37
37
|
};
|
|
38
|
+
const handleShowLegendChange = useCallback((_, newShowLegend)=>{
|
|
39
|
+
onChange(produce(value, (draft)=>{
|
|
40
|
+
draft.legendMode = newShowLegend.id;
|
|
41
|
+
}));
|
|
42
|
+
}, [
|
|
43
|
+
onChange,
|
|
44
|
+
value
|
|
45
|
+
]);
|
|
38
46
|
const handleUnitChange = (newFormat)=>{
|
|
39
47
|
onChange(produce(value, (draft)=>{
|
|
40
48
|
draft.format = newFormat;
|
|
@@ -66,6 +74,20 @@ export function StatChartOptionsEditorSettings(props) {
|
|
|
66
74
|
onChange,
|
|
67
75
|
value
|
|
68
76
|
]);
|
|
77
|
+
const selectShowLegend = useMemo(()=>{
|
|
78
|
+
return /*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
79
|
+
label: "Show",
|
|
80
|
+
control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
|
|
81
|
+
onChange: handleShowLegendChange,
|
|
82
|
+
options: SHOW_LEGEND_LABELS,
|
|
83
|
+
disableClearable: true,
|
|
84
|
+
value: SHOW_LEGEND_LABELS.find((i)=>i.id === value.legendMode) ?? SHOW_LEGEND_LABELS.find((i)=>i.id === 'auto')
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
}, [
|
|
88
|
+
value.legendMode,
|
|
89
|
+
handleShowLegendChange
|
|
90
|
+
]);
|
|
69
91
|
const selectColorMode = useMemo(()=>{
|
|
70
92
|
return /*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
71
93
|
label: "Color mode",
|
|
@@ -85,36 +107,42 @@ export function StatChartOptionsEditorSettings(props) {
|
|
|
85
107
|
]);
|
|
86
108
|
return /*#__PURE__*/ _jsxs(OptionsEditorGrid, {
|
|
87
109
|
children: [
|
|
88
|
-
/*#__PURE__*/
|
|
89
|
-
children:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
/*#__PURE__*/ _jsxs(OptionsEditorColumn, {
|
|
111
|
+
children: [
|
|
112
|
+
/*#__PURE__*/ _jsx(OptionsEditorGroup, {
|
|
113
|
+
title: "Legend",
|
|
114
|
+
children: selectShowLegend
|
|
115
|
+
}),
|
|
116
|
+
/*#__PURE__*/ _jsxs(OptionsEditorGroup, {
|
|
117
|
+
title: "Misc",
|
|
118
|
+
children: [
|
|
119
|
+
/*#__PURE__*/ _jsx(OptionsEditorControl, {
|
|
120
|
+
label: "Sparkline",
|
|
121
|
+
control: /*#__PURE__*/ _jsx(Switch, {
|
|
122
|
+
checked: !!value.sparkline,
|
|
123
|
+
onChange: handleSparklineChange
|
|
124
|
+
})
|
|
125
|
+
}),
|
|
126
|
+
/*#__PURE__*/ _jsx(FormatControls, {
|
|
127
|
+
value: format,
|
|
128
|
+
onChange: handleUnitChange
|
|
129
|
+
}),
|
|
130
|
+
/*#__PURE__*/ _jsx(CalculationSelector, {
|
|
131
|
+
value: value.calculation,
|
|
132
|
+
onChange: handleCalculationChange
|
|
133
|
+
}),
|
|
134
|
+
/*#__PURE__*/ _jsx(MetricLabelInput, {
|
|
135
|
+
value: value.metricLabel,
|
|
136
|
+
onChange: handleMetricLabelChange
|
|
137
|
+
}),
|
|
138
|
+
/*#__PURE__*/ _jsx(FontSizeSelector, {
|
|
139
|
+
value: value.valueFontSize,
|
|
140
|
+
onChange: handleFontSizeChange
|
|
141
|
+
}),
|
|
142
|
+
selectColorMode
|
|
143
|
+
]
|
|
144
|
+
})
|
|
145
|
+
]
|
|
118
146
|
}),
|
|
119
147
|
/*#__PURE__*/ _jsx(OptionsEditorColumn, {
|
|
120
148
|
children: /*#__PURE__*/ _jsx(ThresholdsEditor, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/StatChartOptionsEditorSettings.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Switch, SwitchProps } from '@mui/material';\nimport {\n FontSizeOption,\n FontSizeSelector,\n FontSizeSelectorProps,\n FormatControls,\n FormatControlsProps,\n OptionsEditorColumn,\n OptionsEditorControl,\n OptionsEditorGrid,\n OptionsEditorGroup,\n SettingsAutocomplete,\n ThresholdsEditor,\n ThresholdsEditorProps,\n} from '@perses-dev/components';\nimport { FormatOptions } from '@perses-dev/core';\nimport {\n CalculationSelector,\n CalculationSelectorProps,\n MetricLabelInput,\n MetricLabelInputProps,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport merge from 'lodash/merge';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport {\n COLOR_MODE_LABELS,\n ColorModeLabelItem,\n StatChartOptions,\n StatChartOptionsEditorProps,\n} from './stat-chart-model';\n\nconst DEFAULT_FORMAT: FormatOptions = { unit: 'percent-decimal' };\n\nexport function StatChartOptionsEditorSettings(props: StatChartOptionsEditorProps): ReactElement {\n const { onChange, value } = props;\n\n // ensures decimalPlaces defaults to correct value\n const format = merge({}, DEFAULT_FORMAT, value.format);\n\n const handleCalculationChange: CalculationSelectorProps['onChange'] = (metricLabel) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.calculation = metricLabel;\n })\n );\n };\n\n const handleMetricLabelChange: MetricLabelInputProps['onChange'] = (newCalculation) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.metricLabel = newCalculation;\n })\n );\n };\n\n const handleUnitChange: FormatControlsProps['onChange'] = (newFormat) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.format = newFormat;\n })\n );\n };\n\n const handleSparklineChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n // For now, setting to an empty object when checked, so the stat chart\n // uses the default chart color and line styles. In the future, this\n // will likely be configurable in the UI.\n draft.sparkline = checked ? {} : undefined;\n })\n );\n };\n\n const handleThresholdsChange: ThresholdsEditorProps['onChange'] = (thresholds) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.thresholds = thresholds;\n })\n );\n };\n\n const handleFontSizeChange: FontSizeSelectorProps['onChange'] = (fontSize: FontSizeOption) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.valueFontSize = fontSize;\n })\n );\n };\n\n const handleColorModeChange = useCallback(\n (_: unknown, newColorMode: ColorModeLabelItem): void => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.colorMode = newColorMode.id;\n })\n );\n },\n [onChange, value]\n );\n\n const selectColorMode = useMemo((): ReactElement => {\n return (\n <OptionsEditorControl\n label=\"Color mode\"\n control={\n <SettingsAutocomplete\n onChange={handleColorModeChange}\n options={COLOR_MODE_LABELS.map(({ id, label }) => ({ id, label }))}\n disableClearable\n value={\n COLOR_MODE_LABELS.find((i) => i.id === value.colorMode) ??\n COLOR_MODE_LABELS.find((i) => i.id === 'value')!\n }\n />\n }\n />\n );\n }, [value.colorMode, handleColorModeChange]);\n\n return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\n <OptionsEditorGroup title=\"Misc\">\n <OptionsEditorControl\n label=\"Sparkline\"\n control={<Switch checked={!!value.sparkline} onChange={handleSparklineChange} />}\n />\n <FormatControls value={format} onChange={handleUnitChange} />\n <CalculationSelector value={value.calculation} onChange={handleCalculationChange} />\n <MetricLabelInput value={value.metricLabel} onChange={handleMetricLabelChange} />\n <FontSizeSelector value={value.valueFontSize} onChange={handleFontSizeChange} />\n {selectColorMode}\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n <OptionsEditorColumn>\n <ThresholdsEditor disablePercentMode thresholds={value.thresholds} onChange={handleThresholdsChange} />\n </OptionsEditorColumn>\n </OptionsEditorGrid>\n );\n}\n"],"names":["Switch","FontSizeSelector","FormatControls","OptionsEditorColumn","OptionsEditorControl","OptionsEditorGrid","OptionsEditorGroup","SettingsAutocomplete","ThresholdsEditor","CalculationSelector","MetricLabelInput","produce","merge","useCallback","useMemo","COLOR_MODE_LABELS","DEFAULT_FORMAT","unit","StatChartOptionsEditorSettings","props","onChange","value","format","handleCalculationChange","metricLabel","draft","calculation","handleMetricLabelChange","newCalculation","handleUnitChange","newFormat","handleSparklineChange","
|
|
1
|
+
{"version":3,"sources":["../../src/StatChartOptionsEditorSettings.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Switch, SwitchProps } from '@mui/material';\nimport {\n FontSizeOption,\n FontSizeSelector,\n FontSizeSelectorProps,\n FormatControls,\n FormatControlsProps,\n OptionsEditorColumn,\n OptionsEditorControl,\n OptionsEditorGrid,\n OptionsEditorGroup,\n SettingsAutocomplete,\n ThresholdsEditor,\n ThresholdsEditorProps,\n} from '@perses-dev/components';\nimport { FormatOptions } from '@perses-dev/core';\nimport {\n CalculationSelector,\n CalculationSelectorProps,\n MetricLabelInput,\n MetricLabelInputProps,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport merge from 'lodash/merge';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport {\n COLOR_MODE_LABELS,\n ColorModeLabelItem,\n SHOW_LEGEND_LABELS,\n ShowLegendLabelItem,\n StatChartOptions,\n StatChartOptionsEditorProps,\n} from './stat-chart-model';\n\nconst DEFAULT_FORMAT: FormatOptions = { unit: 'percent-decimal' };\n\nexport function StatChartOptionsEditorSettings(props: StatChartOptionsEditorProps): ReactElement {\n const { onChange, value } = props;\n\n // ensures decimalPlaces defaults to correct value\n const format = merge({}, DEFAULT_FORMAT, value.format);\n\n const handleCalculationChange: CalculationSelectorProps['onChange'] = (metricLabel) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.calculation = metricLabel;\n })\n );\n };\n\n const handleMetricLabelChange: MetricLabelInputProps['onChange'] = (newCalculation) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.metricLabel = newCalculation;\n })\n );\n };\n\n const handleShowLegendChange = useCallback(\n (_: unknown, newShowLegend: ShowLegendLabelItem): void => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.legendMode = newShowLegend.id;\n })\n );\n },\n [onChange, value]\n );\n\n const handleUnitChange: FormatControlsProps['onChange'] = (newFormat) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.format = newFormat;\n })\n );\n };\n\n const handleSparklineChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n // For now, setting to an empty object when checked, so the stat chart\n // uses the default chart color and line styles. In the future, this\n // will likely be configurable in the UI.\n draft.sparkline = checked ? {} : undefined;\n })\n );\n };\n\n const handleThresholdsChange: ThresholdsEditorProps['onChange'] = (thresholds) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.thresholds = thresholds;\n })\n );\n };\n\n const handleFontSizeChange: FontSizeSelectorProps['onChange'] = (fontSize: FontSizeOption) => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.valueFontSize = fontSize;\n })\n );\n };\n\n const handleColorModeChange = useCallback(\n (_: unknown, newColorMode: ColorModeLabelItem): void => {\n onChange(\n produce(value, (draft: StatChartOptions) => {\n draft.colorMode = newColorMode.id;\n })\n );\n },\n [onChange, value]\n );\n\n const selectShowLegend = useMemo((): ReactElement => {\n return (\n <OptionsEditorControl\n label=\"Show\"\n control={\n <SettingsAutocomplete\n onChange={handleShowLegendChange}\n options={SHOW_LEGEND_LABELS}\n disableClearable\n value={\n SHOW_LEGEND_LABELS.find((i) => i.id === value.legendMode) ??\n SHOW_LEGEND_LABELS.find((i) => i.id === 'auto')!\n }\n />\n }\n />\n );\n }, [value.legendMode, handleShowLegendChange]);\n\n const selectColorMode = useMemo((): ReactElement => {\n return (\n <OptionsEditorControl\n label=\"Color mode\"\n control={\n <SettingsAutocomplete\n onChange={handleColorModeChange}\n options={COLOR_MODE_LABELS.map(({ id, label }) => ({ id, label }))}\n disableClearable\n value={\n COLOR_MODE_LABELS.find((i) => i.id === value.colorMode) ??\n COLOR_MODE_LABELS.find((i) => i.id === 'value')!\n }\n />\n }\n />\n );\n }, [value.colorMode, handleColorModeChange]);\n\n return (\n <OptionsEditorGrid>\n <OptionsEditorColumn>\n <OptionsEditorGroup title=\"Legend\">{selectShowLegend}</OptionsEditorGroup>\n <OptionsEditorGroup title=\"Misc\">\n <OptionsEditorControl\n label=\"Sparkline\"\n control={<Switch checked={!!value.sparkline} onChange={handleSparklineChange} />}\n />\n <FormatControls value={format} onChange={handleUnitChange} />\n <CalculationSelector value={value.calculation} onChange={handleCalculationChange} />\n <MetricLabelInput value={value.metricLabel} onChange={handleMetricLabelChange} />\n <FontSizeSelector value={value.valueFontSize} onChange={handleFontSizeChange} />\n {selectColorMode}\n </OptionsEditorGroup>\n </OptionsEditorColumn>\n <OptionsEditorColumn>\n <ThresholdsEditor disablePercentMode thresholds={value.thresholds} onChange={handleThresholdsChange} />\n </OptionsEditorColumn>\n </OptionsEditorGrid>\n );\n}\n"],"names":["Switch","FontSizeSelector","FormatControls","OptionsEditorColumn","OptionsEditorControl","OptionsEditorGrid","OptionsEditorGroup","SettingsAutocomplete","ThresholdsEditor","CalculationSelector","MetricLabelInput","produce","merge","useCallback","useMemo","COLOR_MODE_LABELS","SHOW_LEGEND_LABELS","DEFAULT_FORMAT","unit","StatChartOptionsEditorSettings","props","onChange","value","format","handleCalculationChange","metricLabel","draft","calculation","handleMetricLabelChange","newCalculation","handleShowLegendChange","_","newShowLegend","legendMode","id","handleUnitChange","newFormat","handleSparklineChange","checked","sparkline","undefined","handleThresholdsChange","thresholds","handleFontSizeChange","fontSize","valueFontSize","handleColorModeChange","newColorMode","colorMode","selectShowLegend","label","control","options","disableClearable","find","i","selectColorMode","map","title","disablePercentMode"],"mappings":";AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,MAAM,QAAqB,gBAAgB;AACpD,SAEEC,gBAAgB,EAEhBC,cAAc,EAEdC,mBAAmB,EACnBC,oBAAoB,EACpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,oBAAoB,EACpBC,gBAAgB,QAEX,yBAAyB;AAEhC,SACEC,mBAAmB,EAEnBC,gBAAgB,QAEX,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAChC,OAAOC,WAAW,eAAe;AACjC,SAAuBC,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC3D,SACEC,iBAAiB,EAEjBC,kBAAkB,QAIb,qBAAqB;AAE5B,MAAMC,iBAAgC;IAAEC,MAAM;AAAkB;AAEhE,OAAO,SAASC,+BAA+BC,KAAkC;IAC/E,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,kDAAkD;IAClD,MAAMG,SAASX,MAAM,CAAC,GAAGK,gBAAgBK,MAAMC,MAAM;IAErD,MAAMC,0BAAgE,CAACC;QACrEJ,SACEV,QAAQW,OAAO,CAACI;YACdA,MAAMC,WAAW,GAAGF;QACtB;IAEJ;IAEA,MAAMG,0BAA6D,CAACC;QAClER,SACEV,QAAQW,OAAO,CAACI;YACdA,MAAMD,WAAW,GAAGI;QACtB;IAEJ;IAEA,MAAMC,yBAAyBjB,YAC7B,CAACkB,GAAYC;QACXX,SACEV,QAAQW,OAAO,CAACI;YACdA,MAAMO,UAAU,GAAGD,cAAcE,EAAE;QACrC;IAEJ,GACA;QAACb;QAAUC;KAAM;IAGnB,MAAMa,mBAAoD,CAACC;QACzDf,SACEV,QAAQW,OAAO,CAACI;Y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S,KACtDjC,kBAAkBuC,IAAI,CAAC,CAACC,IAAMA,EAAErB,EAAE,KAAK;;;IAMnD,GAAG;QAACZ,MAAM0B,SAAS;QAAEF;KAAsB;IAE3C,qBACE,MAACzC;;0BACC,MAACF;;kCACC,KAACG;wBAAmBoD,OAAM;kCAAUT;;kCACpC,MAAC3C;wBAAmBoD,OAAM;;0CACxB,KAACtD;gCACC8C,OAAM;gCACNC,uBAAS,KAACnD;oCAAOsC,SAAS,CAAC,CAAChB,MAAMiB,SAAS;oCAAElB,UAAUgB;;;0CAEzD,KAACnC;gCAAeoB,OAAOC;gCAAQF,UAAUc;;0CACzC,KAAC1B;gCAAoBa,OAAOA,MAAMK,WAAW;gCAAEN,UAAUG;;0CACzD,KAACd;gCAAiBY,OAAOA,MAAMG,WAAW;gCAAEJ,UAAUO;;0CACtD,KAAC3B;gCAAiBqB,OAAOA,MAAMuB,aAAa;gCAAExB,UAAUsB;;4BACvDa;;;;;0BAGL,KAACrD;0BACC,cAAA,KAACK;oBAAiBmD,kBAAkB;oBAACjB,YAAYpB,MAAMoB,UAAU;oBAAErB,UAAUoB;;;;;AAIrF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StatChartPanel.d.ts","sourceRoot":"","sources":["../../src/StatChartPanel.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,EAAE,EAAW,MAAM,OAAO,CAAC;AACpC,OAAO,EAAoD,cAAc,EAAgB,MAAM,kBAAkB,CAAC;AAClH,OAAO,EAAE,UAAU,EAAa,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAE/E,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"StatChartPanel.d.ts","sourceRoot":"","sources":["../../src/StatChartPanel.tsx"],"names":[],"mappings":"AAgBA,OAAO,EAAE,EAAE,EAAW,MAAM,OAAO,CAAC;AACpC,OAAO,EAAoD,cAAc,EAAgB,MAAM,kBAAkB,CAAC;AAClH,OAAO,EAAE,UAAU,EAAa,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAStD,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;AAE/E,eAAO,MAAM,cAAc,EAAE,EAAE,CAAC,mBAAmB,CA0DlD,CAAC"}
|
package/lib/StatChartPanel.js
CHANGED
|
@@ -27,6 +27,8 @@ export const StatChartPanel = (props)=>{
|
|
|
27
27
|
const chartsTheme = useChartsTheme();
|
|
28
28
|
const statChartData = useStatChartData(queryResults, spec, chartsTheme);
|
|
29
29
|
const isMultiSeries = statChartData.length > 1;
|
|
30
|
+
// Handle three-state showLegend: 'on' | 'off' | 'auto' (or undefined for backward compatibility)
|
|
31
|
+
const shouldShowLegend = spec.legendMode === 'on' ? true : spec.legendMode === 'off' ? false : isMultiSeries;
|
|
30
32
|
if (!contentDimensions) return null;
|
|
31
33
|
// Calculates chart width
|
|
32
34
|
const spacing = SPACING * (statChartData.length - 1);
|
|
@@ -53,7 +55,7 @@ export const StatChartPanel = (props)=>{
|
|
|
53
55
|
data: series,
|
|
54
56
|
format: format,
|
|
55
57
|
sparkline: sparklineConfig,
|
|
56
|
-
showSeriesName:
|
|
58
|
+
showSeriesName: shouldShowLegend,
|
|
57
59
|
valueFontSize: valueFontSize,
|
|
58
60
|
colorMode: colorMode
|
|
59
61
|
}, index);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/StatChartPanel.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TitleComponentOption } from 'echarts';\nimport { useChartsTheme, GraphSeries, PersesChartsTheme } from '@perses-dev/components';\nimport { Stack, Typography, SxProps } from '@mui/material';\nimport { FC, useMemo } from 'react';\nimport { applyValueMapping, Labels, createRegexFromString, TimeSeriesData, ValueMapping } from '@perses-dev/core';\nimport { PanelProps, PanelData } from '@perses-dev/plugin-system';\nimport { StatChartOptions } from './stat-chart-model';\nimport { convertSparkline } from './utils/data-transform';\nimport { calculateValue } from './utils/calculate-value';\nimport { getStatChartColor } from './utils/get-color';\nimport { StatChartBase, StatChartData } from './StatChartBase';\n\nconst MIN_WIDTH = 100;\nconst SPACING = 2;\n\nexport type StatChartPanelProps = PanelProps<StatChartOptions, TimeSeriesData>;\n\nexport const StatChartPanel: FC<StatChartPanelProps> = (props) => {\n const { spec, contentDimensions, queryResults } = props;\n\n const { format, sparkline, valueFontSize: valueFontSize, colorMode } = spec;\n const chartsTheme = useChartsTheme();\n const statChartData = useStatChartData(queryResults, spec, chartsTheme);\n\n const isMultiSeries = statChartData.length > 1;\n\n if (!contentDimensions) return null;\n\n // Calculates chart width\n const spacing = SPACING * (statChartData.length - 1);\n let chartWidth = (contentDimensions.width - spacing) / statChartData.length;\n if (isMultiSeries && chartWidth < MIN_WIDTH) {\n chartWidth = MIN_WIDTH;\n }\n\n const noDataTextStyle = (chartsTheme.noDataOption.title as TitleComponentOption).textStyle;\n\n return (\n <Stack\n height={contentDimensions.height}\n width={contentDimensions.width}\n spacing={`${SPACING}px`}\n direction=\"row\"\n justifyContent={isMultiSeries ? 'left' : 'center'}\n alignItems=\"center\"\n sx={{\n overflowX: isMultiSeries ? 'scroll' : 'auto',\n }}\n >\n {statChartData.length ? (\n statChartData.map((series, index) => {\n const sparklineConfig = convertSparkline(chartsTheme, series.color, sparkline);\n\n return (\n <StatChartBase\n key={index}\n width={chartWidth}\n height={contentDimensions.height}\n data={series}\n format={format}\n sparkline={sparklineConfig}\n showSeriesName={
|
|
1
|
+
{"version":3,"sources":["../../src/StatChartPanel.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TitleComponentOption } from 'echarts';\nimport { useChartsTheme, GraphSeries, PersesChartsTheme } from '@perses-dev/components';\nimport { Stack, Typography, SxProps } from '@mui/material';\nimport { FC, useMemo } from 'react';\nimport { applyValueMapping, Labels, createRegexFromString, TimeSeriesData, ValueMapping } from '@perses-dev/core';\nimport { PanelProps, PanelData } from '@perses-dev/plugin-system';\nimport { StatChartOptions } from './stat-chart-model';\nimport { convertSparkline } from './utils/data-transform';\nimport { calculateValue } from './utils/calculate-value';\nimport { getStatChartColor } from './utils/get-color';\nimport { StatChartBase, StatChartData } from './StatChartBase';\n\nconst MIN_WIDTH = 100;\nconst SPACING = 2;\n\nexport type StatChartPanelProps = PanelProps<StatChartOptions, TimeSeriesData>;\n\nexport const StatChartPanel: FC<StatChartPanelProps> = (props) => {\n const { spec, contentDimensions, queryResults } = props;\n\n const { format, sparkline, valueFontSize: valueFontSize, colorMode } = spec;\n const chartsTheme = useChartsTheme();\n const statChartData = useStatChartData(queryResults, spec, chartsTheme);\n\n const isMultiSeries = statChartData.length > 1;\n\n // Handle three-state showLegend: 'on' | 'off' | 'auto' (or undefined for backward compatibility)\n const shouldShowLegend = spec.legendMode === 'on' ? true : spec.legendMode === 'off' ? false : isMultiSeries;\n\n if (!contentDimensions) return null;\n\n // Calculates chart width\n const spacing = SPACING * (statChartData.length - 1);\n let chartWidth = (contentDimensions.width - spacing) / statChartData.length;\n if (isMultiSeries && chartWidth < MIN_WIDTH) {\n chartWidth = MIN_WIDTH;\n }\n\n const noDataTextStyle = (chartsTheme.noDataOption.title as TitleComponentOption).textStyle;\n\n return (\n <Stack\n height={contentDimensions.height}\n width={contentDimensions.width}\n spacing={`${SPACING}px`}\n direction=\"row\"\n justifyContent={isMultiSeries ? 'left' : 'center'}\n alignItems=\"center\"\n sx={{\n overflowX: isMultiSeries ? 'scroll' : 'auto',\n }}\n >\n {statChartData.length ? (\n statChartData.map((series, index) => {\n const sparklineConfig = convertSparkline(chartsTheme, series.color, sparkline);\n\n return (\n <StatChartBase\n key={index}\n width={chartWidth}\n height={contentDimensions.height}\n data={series}\n format={format}\n sparkline={sparklineConfig}\n showSeriesName={shouldShowLegend}\n valueFontSize={valueFontSize}\n colorMode={colorMode}\n />\n );\n })\n ) : (\n <Typography sx={{ ...noDataTextStyle } as SxProps}>No data</Typography>\n )}\n </Stack>\n );\n};\n\nconst useStatChartData = (\n queryResults: Array<PanelData<TimeSeriesData>>,\n spec: StatChartOptions,\n chartsTheme: PersesChartsTheme\n): StatChartData[] => {\n return useMemo(() => {\n const { calculation, mappings, metricLabel } = spec;\n\n const statChartData: StatChartData[] = [];\n for (const result of queryResults) {\n for (const seriesData of result.data.series) {\n const calculatedValue = calculateValue(calculation, seriesData);\n\n // get label metric value\n const labelValue = getLabelValue(metricLabel, seriesData.labels);\n\n // get actual value to display\n const displayValue = getValueOrLabel(calculatedValue, mappings, labelValue);\n\n const color = getStatChartColor(chartsTheme, spec, calculatedValue);\n\n const series: GraphSeries = {\n name: seriesData.formattedName ?? '',\n values: seriesData.values,\n };\n\n statChartData.push({ calculatedValue: displayValue, seriesData: series, color });\n }\n }\n return statChartData;\n }, [queryResults, spec, chartsTheme]);\n};\n\nconst getValueOrLabel = (\n value?: number | null,\n mappings?: ValueMapping[],\n label?: string\n): string | number | undefined | null => {\n if (label) {\n return label;\n }\n if (mappings?.length && value !== undefined && value !== null) {\n return applyValueMapping(value, mappings).value;\n } else {\n return value;\n }\n};\n\nconst getLabelValue = (fieldLabel?: string, labels?: Labels): string | undefined => {\n if (!labels || !fieldLabel) {\n return undefined;\n }\n for (const [key, value] of Object.entries(labels)) {\n const regex = createRegexFromString(fieldLabel);\n if (regex.test(key)) {\n return value;\n }\n }\n return undefined;\n};\n"],"names":["useChartsTheme","Stack","Typography","useMemo","applyValueMapping","createRegexFromString","convertSparkline","calculateValue","getStatChartColor","StatChartBase","MIN_WIDTH","SPACING","StatChartPanel","props","spec","contentDimensions","queryResults","format","sparkline","valueFontSize","colorMode","chartsTheme","statChartData","useStatChartData","isMultiSeries","length","shouldShowLegend","legendMode","spacing","chartWidth","width","noDataTextStyle","noDataOption","title","textStyle","height","direction","justifyContent","alignItems","sx","overflowX","map","series","index","sparklineConfig","color","data","showSeriesName","calculation","mappings","metricLabel","result","seriesData","calculatedValue","labelValue","getLabelValue","labels","displayValue","getValueOrLabel","name","formattedName","values","push","value","label","undefined","fieldLabel","key","Object","entries","regex","test"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,cAAc,QAAwC,yBAAyB;AACxF,SAASC,KAAK,EAAEC,UAAU,QAAiB,gBAAgB;AAC3D,SAAaC,OAAO,QAAQ,QAAQ;AACpC,SAASC,iBAAiB,EAAUC,qBAAqB,QAAsC,mBAAmB;AAGlH,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,iBAAiB,QAAQ,oBAAoB;AACtD,SAASC,aAAa,QAAuB,kBAAkB;AAE/D,MAAMC,YAAY;AAClB,MAAMC,UAAU;AAIhB,OAAO,MA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AMC,IAAI,CAACJ,MAAM;YACnB,OAAOJ;QACT;IACF;IACA,OAAOE;AACT"}
|
package/lib/bootstrap.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright 2024 The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import React from 'react';
|
|
15
15
|
import ReactDOM from 'react-dom/client';
|
|
16
16
|
const root = ReactDOM.createRoot(document.getElementById('root'));
|
package/lib/bootstrap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bootstrap.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\n\nconst root = ReactDOM.createRoot(document.getElementById('root')!);\nroot.render(<React.StrictMode></React.StrictMode>);\n"],"names":["React","ReactDOM","root","createRoot","document","getElementById","render","StrictMode"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC
|
|
1
|
+
{"version":3,"sources":["../../src/bootstrap.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\n\nconst root = ReactDOM.createRoot(document.getElementById('root')!);\nroot.render(<React.StrictMode></React.StrictMode>);\n"],"names":["React","ReactDOM","root","createRoot","document","getElementById","render","StrictMode"],"mappings":";AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,cAAc,mBAAmB;AAExC,MAAMC,OAAOD,SAASE,UAAU,CAACC,SAASC,cAAc,CAAC;AACzDH,KAAKI,MAAM,eAAC,KAACN,MAAMO,UAAU"}
|
|
@@ -50,6 +50,14 @@ function StatChartOptionsEditorSettings(props) {
|
|
|
50
50
|
draft.metricLabel = newCalculation;
|
|
51
51
|
}));
|
|
52
52
|
};
|
|
53
|
+
const handleShowLegendChange = (0, _react.useCallback)((_, newShowLegend)=>{
|
|
54
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
55
|
+
draft.legendMode = newShowLegend.id;
|
|
56
|
+
}));
|
|
57
|
+
}, [
|
|
58
|
+
onChange,
|
|
59
|
+
value
|
|
60
|
+
]);
|
|
53
61
|
const handleUnitChange = (newFormat)=>{
|
|
54
62
|
onChange((0, _immer.produce)(value, (draft)=>{
|
|
55
63
|
draft.format = newFormat;
|
|
@@ -81,6 +89,20 @@ function StatChartOptionsEditorSettings(props) {
|
|
|
81
89
|
onChange,
|
|
82
90
|
value
|
|
83
91
|
]);
|
|
92
|
+
const selectShowLegend = (0, _react.useMemo)(()=>{
|
|
93
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
94
|
+
label: "Show",
|
|
95
|
+
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SettingsAutocomplete, {
|
|
96
|
+
onChange: handleShowLegendChange,
|
|
97
|
+
options: _statchartmodel.SHOW_LEGEND_LABELS,
|
|
98
|
+
disableClearable: true,
|
|
99
|
+
value: _statchartmodel.SHOW_LEGEND_LABELS.find((i)=>i.id === value.legendMode) ?? _statchartmodel.SHOW_LEGEND_LABELS.find((i)=>i.id === 'auto')
|
|
100
|
+
})
|
|
101
|
+
});
|
|
102
|
+
}, [
|
|
103
|
+
value.legendMode,
|
|
104
|
+
handleShowLegendChange
|
|
105
|
+
]);
|
|
84
106
|
const selectColorMode = (0, _react.useMemo)(()=>{
|
|
85
107
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
86
108
|
label: "Color mode",
|
|
@@ -100,36 +122,42 @@ function StatChartOptionsEditorSettings(props) {
|
|
|
100
122
|
]);
|
|
101
123
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGrid, {
|
|
102
124
|
children: [
|
|
103
|
-
/*#__PURE__*/ (0, _jsxruntime.
|
|
104
|
-
children:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
125
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorColumn, {
|
|
126
|
+
children: [
|
|
127
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorGroup, {
|
|
128
|
+
title: "Legend",
|
|
129
|
+
children: selectShowLegend
|
|
130
|
+
}),
|
|
131
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGroup, {
|
|
132
|
+
title: "Misc",
|
|
133
|
+
children: [
|
|
134
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
135
|
+
label: "Sparkline",
|
|
136
|
+
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Switch, {
|
|
137
|
+
checked: !!value.sparkline,
|
|
138
|
+
onChange: handleSparklineChange
|
|
139
|
+
})
|
|
140
|
+
}),
|
|
141
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.FormatControls, {
|
|
142
|
+
value: format,
|
|
143
|
+
onChange: handleUnitChange
|
|
144
|
+
}),
|
|
145
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.CalculationSelector, {
|
|
146
|
+
value: value.calculation,
|
|
147
|
+
onChange: handleCalculationChange
|
|
148
|
+
}),
|
|
149
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.MetricLabelInput, {
|
|
150
|
+
value: value.metricLabel,
|
|
151
|
+
onChange: handleMetricLabelChange
|
|
152
|
+
}),
|
|
153
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.FontSizeSelector, {
|
|
154
|
+
value: value.valueFontSize,
|
|
155
|
+
onChange: handleFontSizeChange
|
|
156
|
+
}),
|
|
157
|
+
selectColorMode
|
|
158
|
+
]
|
|
159
|
+
})
|
|
160
|
+
]
|
|
133
161
|
}),
|
|
134
162
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorColumn, {
|
|
135
163
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ThresholdsEditor, {
|
|
@@ -37,6 +37,8 @@ const StatChartPanel = (props)=>{
|
|
|
37
37
|
const chartsTheme = (0, _components.useChartsTheme)();
|
|
38
38
|
const statChartData = useStatChartData(queryResults, spec, chartsTheme);
|
|
39
39
|
const isMultiSeries = statChartData.length > 1;
|
|
40
|
+
// Handle three-state showLegend: 'on' | 'off' | 'auto' (or undefined for backward compatibility)
|
|
41
|
+
const shouldShowLegend = spec.legendMode === 'on' ? true : spec.legendMode === 'off' ? false : isMultiSeries;
|
|
40
42
|
if (!contentDimensions) return null;
|
|
41
43
|
// Calculates chart width
|
|
42
44
|
const spacing = SPACING * (statChartData.length - 1);
|
|
@@ -63,7 +65,7 @@ const StatChartPanel = (props)=>{
|
|
|
63
65
|
data: series,
|
|
64
66
|
format: format,
|
|
65
67
|
sparkline: sparklineConfig,
|
|
66
|
-
showSeriesName:
|
|
68
|
+
showSeriesName: shouldShowLegend,
|
|
67
69
|
valueFontSize: valueFontSize,
|
|
68
70
|
colorMode: colorMode
|
|
69
71
|
}, index);
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
// Copyright 2024 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
1
|
"use strict";
|
|
14
2
|
function _getRequireWildcardCache(nodeInterop) {
|
|
15
3
|
if (typeof WeakMap !== "function") return null;
|
|
@@ -52,4 +40,16 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
52
40
|
}
|
|
53
41
|
return newObj;
|
|
54
42
|
}
|
|
43
|
+
// Copyright 2024 The Perses Authors
|
|
44
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
45
|
+
// you may not use this file except in compliance with the License.
|
|
46
|
+
// You may obtain a copy of the License at
|
|
47
|
+
//
|
|
48
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
49
|
+
//
|
|
50
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
51
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
52
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
53
|
+
// See the License for the specific language governing permissions and
|
|
54
|
+
// limitations under the License.
|
|
55
55
|
Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("./bootstrap")));
|
|
@@ -17,14 +17,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
17
17
|
function _export(target, all) {
|
|
18
18
|
for(var name in all)Object.defineProperty(target, name, {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: all
|
|
20
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
COLOR_MODE_LABELS
|
|
24
|
+
get COLOR_MODE_LABELS () {
|
|
25
25
|
return COLOR_MODE_LABELS;
|
|
26
26
|
},
|
|
27
|
-
|
|
27
|
+
get SHOW_LEGEND_LABELS () {
|
|
28
|
+
return SHOW_LEGEND_LABELS;
|
|
29
|
+
},
|
|
30
|
+
get createInitialStatChartOptions () {
|
|
28
31
|
return createInitialStatChartOptions;
|
|
29
32
|
}
|
|
30
33
|
});
|
|
@@ -42,12 +45,30 @@ const COLOR_MODE_LABELS = [
|
|
|
42
45
|
label: 'Background'
|
|
43
46
|
}
|
|
44
47
|
];
|
|
48
|
+
const SHOW_LEGEND_LABELS = [
|
|
49
|
+
{
|
|
50
|
+
id: 'auto',
|
|
51
|
+
label: 'Auto',
|
|
52
|
+
description: 'Show legend for multi-series, hide legend for single series'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'on',
|
|
56
|
+
label: 'On',
|
|
57
|
+
description: 'Always show legend'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'off',
|
|
61
|
+
label: 'Off',
|
|
62
|
+
description: 'Always hide legend'
|
|
63
|
+
}
|
|
64
|
+
];
|
|
45
65
|
function createInitialStatChartOptions() {
|
|
46
66
|
return {
|
|
47
67
|
calculation: 'last-number',
|
|
48
68
|
format: {
|
|
49
69
|
unit: 'decimal'
|
|
50
70
|
},
|
|
51
|
-
sparkline: {}
|
|
71
|
+
sparkline: {},
|
|
72
|
+
legendMode: 'auto'
|
|
52
73
|
};
|
|
53
74
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CalculationType, Definition, ThresholdOptions, FormatOptions, ValueMapping } from '@perses-dev/core';
|
|
2
1
|
import { FontSizeOption } from '@perses-dev/components';
|
|
2
|
+
import { CalculationType, Definition, FormatOptions, ThresholdOptions, ValueMapping } from '@perses-dev/core';
|
|
3
3
|
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
4
4
|
/**
|
|
5
5
|
* The schema for a StatChart panel.
|
|
@@ -13,6 +13,13 @@ export type ColorModeLabelItem = {
|
|
|
13
13
|
label: string;
|
|
14
14
|
};
|
|
15
15
|
export declare const COLOR_MODE_LABELS: ColorModeLabelItem[];
|
|
16
|
+
export type legendMode = 'auto' | 'on' | 'off';
|
|
17
|
+
export type ShowLegendLabelItem = {
|
|
18
|
+
id: legendMode;
|
|
19
|
+
label: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const SHOW_LEGEND_LABELS: ShowLegendLabelItem[];
|
|
16
23
|
export interface StatChartOptions {
|
|
17
24
|
calculation: CalculationType;
|
|
18
25
|
format: FormatOptions;
|
|
@@ -22,6 +29,7 @@ export interface StatChartOptions {
|
|
|
22
29
|
valueFontSize?: FontSizeOption;
|
|
23
30
|
mappings?: ValueMapping[];
|
|
24
31
|
colorMode?: ColorMode;
|
|
32
|
+
legendMode?: legendMode;
|
|
25
33
|
}
|
|
26
34
|
export interface StatChartSparklineOptions {
|
|
27
35
|
color?: string;
|