@perses-dev/stat-chart-plugin 0.6.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/LICENSE +201 -0
- package/README.md +41 -0
- package/__mf/css/async/263.1ed8bb01.css +1 -0
- package/__mf/css/async/341.1ed8bb01.css +1 -0
- package/__mf/css/async/759.1ed8bb01.css +1 -0
- package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
- package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
- package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
- package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
- package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
- package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
- package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
- package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
- package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
- package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
- package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
- package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
- package/__mf/js/435.f40076fc.js +5 -0
- package/__mf/js/StatChart.b0400032.js +5 -0
- package/__mf/js/async/162.6eaaf026.js +73 -0
- package/__mf/js/async/162.6eaaf026.js.LICENSE.txt +19 -0
- package/__mf/js/async/173.b6c742e7.js +2 -0
- package/__mf/js/async/173.b6c742e7.js.LICENSE.txt +19 -0
- package/__mf/js/async/214.60d550e8.js +1 -0
- package/__mf/js/async/224.978cad14.js +1 -0
- package/__mf/js/async/238.6c65e7fc.js +1 -0
- package/__mf/js/async/292.4573cfd2.js +1 -0
- package/__mf/js/async/298.0f019169.js +1 -0
- package/__mf/js/async/318.98a6e364.js +83 -0
- package/__mf/js/async/318.98a6e364.js.LICENSE.txt +27 -0
- package/__mf/js/async/488.078788e1.js +1 -0
- package/__mf/js/async/610.dad41cbd.js +1 -0
- package/__mf/js/async/620.415051b8.js +2 -0
- package/__mf/js/async/620.415051b8.js.LICENSE.txt +9 -0
- package/__mf/js/async/651.4eb924e1.js +1 -0
- package/__mf/js/async/656.dbf72cfa.js +1 -0
- package/__mf/js/async/694.5088b7d2.js +1 -0
- package/__mf/js/async/738.5905ca00.js +1 -0
- package/__mf/js/async/740.6ca05ea5.js +1 -0
- package/__mf/js/async/75.fb6da1e8.js +1 -0
- package/__mf/js/async/770.0eef8b15.js +1 -0
- package/__mf/js/async/870.3ed3413d.js +29 -0
- package/__mf/js/async/870.3ed3413d.js.LICENSE.txt +59 -0
- package/__mf/js/async/877.0e870142.js +65 -0
- package/__mf/js/async/960.b6b50cb1.js +2 -0
- package/__mf/js/async/960.b6b50cb1.js.LICENSE.txt +8 -0
- package/__mf/js/async/964.f3efac0a.js +2 -0
- package/__mf/js/async/964.f3efac0a.js.LICENSE.txt +9 -0
- package/__mf/js/async/981.0942fcbb.js +2 -0
- package/__mf/js/async/981.0942fcbb.js.LICENSE.txt +8 -0
- package/__mf/js/async/996.7e490e79.js +2 -0
- package/__mf/js/async/996.7e490e79.js.LICENSE.txt +24 -0
- package/__mf/js/async/__federation_expose_StatChart.0d43d15e.js +1 -0
- package/__mf/js/async/lib-router.3a3f0205.js +2 -0
- package/__mf/js/async/lib-router.3a3f0205.js.LICENSE.txt +32 -0
- package/__mf/js/main.628b2309.js +1 -0
- package/lib/StatChart.d.ts +8 -0
- package/lib/StatChart.d.ts.map +1 -0
- package/lib/StatChart.js +37 -0
- package/lib/StatChart.js.map +1 -0
- package/lib/StatChartOptionsEditorSettings.d.ts +4 -0
- package/lib/StatChartOptionsEditorSettings.d.ts.map +1 -0
- package/lib/StatChartOptionsEditorSettings.js +102 -0
- package/lib/StatChartOptionsEditorSettings.js.map +1 -0
- package/lib/StatChartPanel.d.ts +7 -0
- package/lib/StatChartPanel.d.ts.map +1 -0
- package/lib/StatChartPanel.js +119 -0
- package/lib/StatChartPanel.js.map +1 -0
- package/lib/StatChartValueMappingEditor.d.ts +6 -0
- package/lib/StatChartValueMappingEditor.d.ts.map +1 -0
- package/lib/StatChartValueMappingEditor.js +28 -0
- package/lib/StatChartValueMappingEditor.js.map +1 -0
- package/lib/bootstrap.d.ts +2 -0
- package/lib/bootstrap.d.ts.map +1 -0
- package/lib/bootstrap.js +19 -0
- package/lib/bootstrap.js.map +1 -0
- package/lib/cjs/StatChart.js +43 -0
- package/lib/cjs/StatChartOptionsEditorSettings.js +115 -0
- package/lib/cjs/StatChartPanel.js +127 -0
- package/lib/cjs/StatChartValueMappingEditor.js +36 -0
- package/lib/cjs/bootstrap.js +26 -0
- package/lib/cjs/env.d.js +14 -0
- package/lib/cjs/getPluginModule.js +27 -0
- package/lib/cjs/index-federation.js +55 -0
- package/lib/cjs/index.js +29 -0
- package/lib/cjs/setup-tests.js +19 -0
- package/lib/cjs/stat-chart-model.js +31 -0
- package/lib/cjs/utils/calculate-value.js +30 -0
- package/lib/cjs/utils/data-transform.js +36 -0
- package/lib/cjs/utils/get-color.js +66 -0
- package/lib/env.d.js +15 -0
- package/lib/env.d.js.map +1 -0
- package/lib/getPluginModule.d.ts +6 -0
- package/lib/getPluginModule.d.ts.map +1 -0
- package/lib/getPluginModule.js +16 -0
- package/lib/getPluginModule.js.map +1 -0
- package/lib/index-federation.d.ts +1 -0
- package/lib/index-federation.d.ts.map +1 -0
- package/lib/index-federation.js +15 -0
- package/lib/index-federation.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/setup-tests.d.ts +2 -0
- package/lib/setup-tests.d.ts.map +1 -0
- package/lib/setup-tests.js +17 -0
- package/lib/setup-tests.js.map +1 -0
- package/lib/stat-chart-model.d.ts +25 -0
- package/lib/stat-chart-model.d.ts.map +1 -0
- package/lib/stat-chart-model.js +23 -0
- package/lib/stat-chart-model.js.map +1 -0
- package/lib/utils/calculate-value.d.ts +3 -0
- package/lib/utils/calculate-value.d.ts.map +1 -0
- package/lib/utils/calculate-value.js +22 -0
- package/lib/utils/calculate-value.js.map +1 -0
- package/lib/utils/data-transform.d.ts +5 -0
- package/lib/utils/data-transform.d.ts.map +1 -0
- package/lib/utils/data-transform.js +28 -0
- package/lib/utils/data-transform.js.map +1 -0
- package/lib/utils/get-color.d.ts +6 -0
- package/lib/utils/get-color.d.ts.map +1 -0
- package/lib/utils/get-color.js +58 -0
- package/lib/utils/get-color.js.map +1 -0
- package/mf-manifest.json +320 -0
- package/mf-stats.json +365 -0
- package/package.json +53 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Copyright 2023 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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { StatChart, useChartsTheme } from '@perses-dev/components';
|
|
15
|
+
import { Stack, Typography } from '@mui/material';
|
|
16
|
+
import { useMemo } from 'react';
|
|
17
|
+
import { applyValueMapping, createRegexFromString } from '@perses-dev/core';
|
|
18
|
+
import { convertSparkline } from './utils/data-transform';
|
|
19
|
+
import { calculateValue } from './utils/calculate-value';
|
|
20
|
+
import { getStatChartColor } from './utils/get-color';
|
|
21
|
+
const MIN_WIDTH = 100;
|
|
22
|
+
const SPACING = 2;
|
|
23
|
+
export const StatChartPanel = (props)=>{
|
|
24
|
+
const { spec, contentDimensions, queryResults } = props;
|
|
25
|
+
const { format, sparkline, valueFontSize: valueFontSize } = spec;
|
|
26
|
+
const chartsTheme = useChartsTheme();
|
|
27
|
+
const statChartData = useStatChartData(queryResults, spec, chartsTheme);
|
|
28
|
+
const isMultiSeries = statChartData.length > 1;
|
|
29
|
+
if (contentDimensions === undefined) return null;
|
|
30
|
+
// Calculates chart width
|
|
31
|
+
const spacing = SPACING * (statChartData.length - 1);
|
|
32
|
+
let chartWidth = (contentDimensions.width - spacing) / statChartData.length;
|
|
33
|
+
if (isMultiSeries && chartWidth < MIN_WIDTH) {
|
|
34
|
+
chartWidth = MIN_WIDTH;
|
|
35
|
+
}
|
|
36
|
+
const noDataTextStyle = chartsTheme.noDataOption.title.textStyle;
|
|
37
|
+
return /*#__PURE__*/ _jsx(Stack, {
|
|
38
|
+
height: contentDimensions.height,
|
|
39
|
+
width: contentDimensions.width,
|
|
40
|
+
spacing: `${SPACING}px`,
|
|
41
|
+
direction: "row",
|
|
42
|
+
justifyContent: isMultiSeries ? 'left' : 'center',
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
sx: {
|
|
45
|
+
overflowX: isMultiSeries ? 'scroll' : 'auto'
|
|
46
|
+
},
|
|
47
|
+
children: statChartData.length ? statChartData.map((series, index)=>{
|
|
48
|
+
const sparklineConfig = convertSparkline(chartsTheme, series.color, sparkline);
|
|
49
|
+
return /*#__PURE__*/ _jsx(StatChart, {
|
|
50
|
+
width: chartWidth,
|
|
51
|
+
height: contentDimensions.height,
|
|
52
|
+
data: series,
|
|
53
|
+
format: format,
|
|
54
|
+
sparkline: sparklineConfig,
|
|
55
|
+
showSeriesName: isMultiSeries,
|
|
56
|
+
valueFontSize: valueFontSize
|
|
57
|
+
}, index);
|
|
58
|
+
}) : /*#__PURE__*/ _jsx(Typography, {
|
|
59
|
+
sx: {
|
|
60
|
+
...noDataTextStyle
|
|
61
|
+
},
|
|
62
|
+
children: "No data"
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
const useStatChartData = (queryResults, spec, chartsTheme)=>{
|
|
67
|
+
return useMemo(()=>{
|
|
68
|
+
const { calculation, mappings, metricLabel } = spec;
|
|
69
|
+
const statChartData = [];
|
|
70
|
+
for (const result of queryResults){
|
|
71
|
+
for (const seriesData of result.data.series){
|
|
72
|
+
const calculatedValue = calculateValue(calculation, seriesData);
|
|
73
|
+
// get label metric value
|
|
74
|
+
const labelValue = getLabelValue(metricLabel, seriesData.labels);
|
|
75
|
+
// get actual value to display
|
|
76
|
+
const displayValue = getValueOrLabel(calculatedValue, mappings, labelValue);
|
|
77
|
+
const color = getStatChartColor(chartsTheme, spec, calculatedValue);
|
|
78
|
+
const series = {
|
|
79
|
+
name: seriesData.formattedName ?? '',
|
|
80
|
+
values: seriesData.values
|
|
81
|
+
};
|
|
82
|
+
statChartData.push({
|
|
83
|
+
calculatedValue: displayValue,
|
|
84
|
+
seriesData: series,
|
|
85
|
+
color
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return statChartData;
|
|
90
|
+
}, [
|
|
91
|
+
queryResults,
|
|
92
|
+
spec,
|
|
93
|
+
chartsTheme
|
|
94
|
+
]);
|
|
95
|
+
};
|
|
96
|
+
const getValueOrLabel = (value, mappings, label)=>{
|
|
97
|
+
if (label) {
|
|
98
|
+
return label;
|
|
99
|
+
}
|
|
100
|
+
if (mappings?.length && value !== undefined && value !== null) {
|
|
101
|
+
return applyValueMapping(value, mappings).value;
|
|
102
|
+
} else {
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const getLabelValue = (fieldLabel, labels)=>{
|
|
107
|
+
if (!labels || !fieldLabel) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
for (const [key, value] of Object.entries(labels)){
|
|
111
|
+
const regex = createRegexFromString(fieldLabel);
|
|
112
|
+
if (regex.test(key)) {
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
//# sourceMappingURL=StatChartPanel.js.map
|
|
@@ -0,0 +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 { StatChart, StatChartData, 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';\n\nconst MIN_WIDTH = 100;\nconst SPACING = 2;\n\nexport type StatChartPanelProps = PanelProps<StatChartOptions, TimeSeriesData>;\n\nexport const StatChartPanel: FC<StatChartPanelProps> = (props) => {\n const { spec, contentDimensions, queryResults } = props;\n\n const { format, sparkline, valueFontSize: valueFontSize } = spec;\n const chartsTheme = useChartsTheme();\n const statChartData = useStatChartData(queryResults, spec, chartsTheme);\n\n const isMultiSeries = statChartData.length > 1;\n\n if (contentDimensions === undefined) return null;\n\n // Calculates chart width\n const spacing = SPACING * (statChartData.length - 1);\n let chartWidth = (contentDimensions.width - spacing) / statChartData.length;\n if (isMultiSeries && chartWidth < MIN_WIDTH) {\n chartWidth = MIN_WIDTH;\n }\n\n const noDataTextStyle = (chartsTheme.noDataOption.title as TitleComponentOption).textStyle;\n\n return (\n <Stack\n height={contentDimensions.height}\n width={contentDimensions.width}\n spacing={`${SPACING}px`}\n direction=\"row\"\n justifyContent={isMultiSeries ? 'left' : 'center'}\n alignItems=\"center\"\n sx={{\n overflowX: isMultiSeries ? 'scroll' : 'auto',\n }}\n >\n {statChartData.length ? (\n statChartData.map((series, index) => {\n const sparklineConfig = convertSparkline(chartsTheme, series.color, sparkline);\n\n return (\n <StatChart\n key={index}\n width={chartWidth}\n height={contentDimensions.height}\n data={series}\n format={format}\n sparkline={sparklineConfig}\n showSeriesName={isMultiSeries}\n valueFontSize={valueFontSize}\n />\n );\n })\n ) : (\n <Typography sx={{ ...noDataTextStyle } as SxProps}>No data</Typography>\n )}\n </Stack>\n );\n};\n\nconst useStatChartData = (\n queryResults: Array<PanelData<TimeSeriesData>>,\n spec: StatChartOptions,\n chartsTheme: PersesChartsTheme\n): StatChartData[] => {\n return useMemo(() => {\n const { calculation, mappings, metricLabel } = spec;\n\n const statChartData: StatChartData[] = [];\n for (const result of queryResults) {\n for (const seriesData of result.data.series) {\n const calculatedValue = calculateValue(calculation, seriesData);\n\n // get label metric value\n const labelValue = getLabelValue(metricLabel, seriesData.labels);\n\n // get actual value to display\n const displayValue = getValueOrLabel(calculatedValue, mappings, labelValue);\n\n const color = getStatChartColor(chartsTheme, spec, calculatedValue);\n\n const series: GraphSeries = {\n name: seriesData.formattedName ?? '',\n values: seriesData.values,\n };\n\n statChartData.push({ calculatedValue: displayValue, seriesData: series, color });\n }\n }\n return statChartData;\n }, [queryResults, spec, chartsTheme]);\n};\n\nconst getValueOrLabel = (\n value?: number | null,\n mappings?: ValueMapping[],\n label?: string\n): string | number | undefined | null => {\n if (label) {\n return label;\n }\n if (mappings?.length && value !== undefined && value !== null) {\n return applyValueMapping(value, mappings).value;\n } else {\n return value;\n }\n};\n\nconst getLabelValue = (fieldLabel?: string, labels?: Labels): string | undefined => {\n if (!labels || !fieldLabel) {\n return undefined;\n }\n for (const [key, value] of Object.entries(labels)) {\n const regex = createRegexFromString(fieldLabel);\n if (regex.test(key)) {\n return value;\n }\n }\n return undefined;\n};\n"],"names":["StatChart","useChartsTheme","Stack","Typography","useMemo","applyValueMapping","createRegexFromString","convertSparkline","calculateValue","getStatChartColor","MIN_WIDTH","SPACING","StatChartPanel","props","spec","contentDimensions","queryResults","format","sparkline","valueFontSize","chartsTheme","statChartData","useStatChartData","isMultiSeries","length","undefined","spacing","chartWidth","width","noDataTextStyle","noDataOption","title","textStyle","height","direction","justifyContent","alignItems","sx","overflowX","map","series","index","sparklineConfig","color","data","showSeriesName","calculation","mappings","metricLabel","result","seriesData","calculatedValue","labelValue","getLabelValue","labels","displayValue","getValueOrLabel","name","formattedName","values","push","value","label","fieldLabel","key","Object","entries","regex","test"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,SAAS,EAAiBC,cAAc,QAAwC,yBAAyB;AAClH,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;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,eAAeA,aAAa,EAAE,GAAGL;IAC5D,MAAMM,cAAcnB;IACpB,MAAMoB,gBAAgBC,iBAAiBN,cAAcF,MAAMM;IAE3D,MAAMG,gBAAgBF,cAAcG,MAAM,GAAG;IAE7C,IAAIT,sBAAsBU,WAAW,OAAO;IAE5C,yBAAyB;IACzB,MAAMC,UAAUf,UAAWU,CAAAA,cAAcG,MAAM,GAAG,CAAA;IAClD,IAAIG,aAAa,AAACZ,CAAAA,kBAAkBa,KAAK,GAAGF,OAAM,IAAKL,cAAcG,MAAM;IAC3E,IAAID,iBAAiBI,aAAajB,WAAW;QAC3CiB,aAAajB;IACf;IAEA,MAAMmB,kBAAkB,AAACT,YAAYU,YAAY,CAACC,KAAK,CAA0BC,SAAS;IAE1F,qBACE,KAAC9B;QACC+B,QAAQlB,kBAAkBkB,MAAM;QAChCL,OAAOb,kBAAkBa,KAAK;QAC9BF,SAAS,GAAGf,QAAQ,EAAE,CAAC;QACvBuB,WAAU;QACVC,gBAAgBZ,gBAAgB,SAAS;QACzCa,YAAW;QACXC,IAAI;YACFC,WAAWf,gBAAgB,WAAW;QACxC;kBAECF,cAAcG,MAAM,GACnBH,cAAckB,GAAG,CAAC,CAACC,QAAQC;YACzB,MAAMC,kBAAkBnC,iBAAiBa,aAAaoB,OAAOG,KAAK,EAAEzB;YAEpE,qBACE,KAAClB;gBAEC4B,OAAOD;gBACPM,QAAQlB,kBAAkBkB,MAAM;gBAChCW,MAAMJ;gBACNvB,QAAQA;gBACRC,WAAWwB;gBACXG,gBAAgBtB;gBAChBJ,eAAeA;eAPVsB;QAUX,mBAEA,KAACtC;YAAWkC,IAAI;gBAAE,GAAGR,eAAe;YAAC;sBAAc;;;AAI3D,EAAE;AAEF,MAAMP,mBAAmB,CACvBN,cACAF,MACAM;IAEA,OAAOhB,QAAQ;QACb,MAAM,EAAE0C,WAAW,EAAEC,QAAQ,EAAEC,WAAW,EAAE,GAAGlC;QAE/C,MAAMO,gBAAiC,EAAE;QACzC,KAAK,MAAM4B,UAAUjC,aAAc;YACjC,KAAK,MAAMkC,cAAcD,OAAOL,IAAI,CAACJ,MAAM,CAAE;gBAC3C,MAAMW,kBAAkB3C,eAAesC,aAAaI;gBAEpD,yBAAyB;gBACzB,MAAME,aAAaC,cAAcL,aAAaE,WAAWI,MAAM;gBAE/D,8BAA8B;gBAC9B,MAAMC,eAAeC,gBAAgBL,iBAAiBJ,UAAUK;gBAEhE,MAAMT,QAAQlC,kBAAkBW,aAAaN,MAAMqC;gBAEnD,MAAMX,SAAsB;oBAC1BiB,MAAMP,WAAWQ,aAAa,IAAI;oBAClCC,QAAQT,WAAWS,MAAM;gBAC3B;gBAEAtC,cAAcuC,IAAI,CAAC;oBAAET,iBAAiBI;oBAAcL,YAAYV;oBAAQG;gBAAM;YAChF;QACF;QACA,OAAOtB;IACT,GAAG;QAACL;QAAcF;QAAMM;KAAY;AACtC;AAEA,MAAMoC,kBAAkB,CACtBK,OACAd,UACAe;IAEA,IAAIA,OAAO;QACT,OAAOA;IACT;IACA,IAAIf,UAAUvB,UAAUqC,UAAUpC,aAAaoC,UAAU,MAAM;QAC7D,OAAOxD,kBAAkBwD,OAAOd,UAAUc,KAAK;IACjD,OAAO;QACL,OAAOA;IACT;AACF;AAEA,MAAMR,gBAAgB,CAACU,YAAqBT;IAC1C,IAAI,CAACA,UAAU,CAACS,YAAY;QAC1B,OAAOtC;IACT;IACA,KAAK,MAAM,CAACuC,KAAKH,MAAM,IAAII,OAAOC,OAAO,CAACZ,QAAS;QACjD,MAAMa,QAAQ7D,sBAAsByD;QACpC,IAAII,MAAMC,IAAI,CAACJ,MAAM;YACnB,OAAOH;QACT;IACF;IACA,OAAOpC;AACT"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
2
|
+
import { FC } from 'react';
|
|
3
|
+
import { StatChartOptions } from './stat-chart-model';
|
|
4
|
+
export type StatChartValueMappingEditorProps = OptionsEditorProps<StatChartOptions>;
|
|
5
|
+
export declare const StatChartValueMappingEditor: FC<StatChartValueMappingEditorProps>;
|
|
6
|
+
//# sourceMappingURL=StatChartValueMappingEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatChartValueMappingEditor.d.ts","sourceRoot":"","sources":["../../src/StatChartValueMappingEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAG/D,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,MAAM,gCAAgC,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAEpF,eAAO,MAAM,2BAA2B,EAAE,EAAE,CAAC,gCAAgC,CAM5E,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { ValueMappingsEditor } from '@perses-dev/components';
|
|
15
|
+
export const StatChartValueMappingEditor = ({ onChange, value })=>{
|
|
16
|
+
function handleValueMappingChange(mappings) {
|
|
17
|
+
onChange({
|
|
18
|
+
...value,
|
|
19
|
+
mappings
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return /*#__PURE__*/ _jsx(ValueMappingsEditor, {
|
|
23
|
+
mappings: value.mappings ?? [],
|
|
24
|
+
onChange: handleValueMappingChange
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=StatChartValueMappingEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/StatChartValueMappingEditor.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 { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { ValueMapping } from '@perses-dev/core';\nimport { ValueMappingsEditor } from '@perses-dev/components';\nimport { FC } from 'react';\nimport { StatChartOptions } from './stat-chart-model';\n\nexport type StatChartValueMappingEditorProps = OptionsEditorProps<StatChartOptions>;\n\nexport const StatChartValueMappingEditor: FC<StatChartValueMappingEditorProps> = ({ onChange, value }) => {\n function handleValueMappingChange(mappings: ValueMapping[]): void {\n onChange({ ...value, mappings });\n }\n\n return <ValueMappingsEditor mappings={value.mappings ?? []} onChange={handleValueMappingChange} />;\n};\n"],"names":["ValueMappingsEditor","StatChartValueMappingEditor","onChange","value","handleValueMappingChange","mappings"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAIjC,SAASA,mBAAmB,QAAQ,yBAAyB;AAM7D,OAAO,MAAMC,8BAAoE,CAAC,EAAEC,QAAQ,EAAEC,KAAK,EAAE;IACnG,SAASC,yBAAyBC,QAAwB;QACxDH,SAAS;YAAE,GAAGC,KAAK;YAAEE;QAAS;IAChC;IAEA,qBAAO,KAACL;QAAoBK,UAAUF,MAAME,QAAQ,IAAI,EAAE;QAAEH,UAAUE;;AACxE,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/bootstrap.tsx"],"names":[],"mappings":""}
|
package/lib/bootstrap.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import ReactDOM from 'react-dom/client';
|
|
16
|
+
const root = ReactDOM.createRoot(document.getElementById('root'));
|
|
17
|
+
root.render(/*#__PURE__*/ _jsx(React.StrictMode, {}));
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=bootstrap.js.map
|
|
@@ -0,0 +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;;AAEjC,OAAOA,WAAW,QAAQ;AAC1B,OAAOC,cAAc,mBAAmB;AAExC,MAAMC,OAAOD,SAASE,UAAU,CAACC,SAASC,cAAc,CAAC;AACzDH,KAAKI,MAAM,eAAC,KAACN,MAAMO,UAAU"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "StatChart", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return StatChart;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _statchartmodel = require("./stat-chart-model");
|
|
24
|
+
const _StatChartValueMappingEditor = require("./StatChartValueMappingEditor");
|
|
25
|
+
const _StatChartOptionsEditorSettings = require("./StatChartOptionsEditorSettings");
|
|
26
|
+
const _StatChartPanel = require("./StatChartPanel");
|
|
27
|
+
const StatChart = {
|
|
28
|
+
PanelComponent: _StatChartPanel.StatChartPanel,
|
|
29
|
+
supportedQueryTypes: [
|
|
30
|
+
'TimeSeriesQuery'
|
|
31
|
+
],
|
|
32
|
+
panelOptionsEditorComponents: [
|
|
33
|
+
{
|
|
34
|
+
label: 'Settings',
|
|
35
|
+
content: _StatChartOptionsEditorSettings.StatChartOptionsEditorSettings
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: 'Value mapping',
|
|
39
|
+
content: _StatChartValueMappingEditor.StatChartValueMappingEditor
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
createInitialOptions: _statchartmodel.createInitialStatChartOptions
|
|
43
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "StatChartOptionsEditorSettings", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return StatChartOptionsEditorSettings;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
+
const _material = require("@mui/material");
|
|
25
|
+
const _components = require("@perses-dev/components");
|
|
26
|
+
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
27
|
+
const _immer = require("immer");
|
|
28
|
+
const _merge = /*#__PURE__*/ _interop_require_default(require("lodash/merge"));
|
|
29
|
+
function _interop_require_default(obj) {
|
|
30
|
+
return obj && obj.__esModule ? obj : {
|
|
31
|
+
default: obj
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const DEFAULT_FORMAT = {
|
|
35
|
+
unit: 'percent-decimal'
|
|
36
|
+
};
|
|
37
|
+
function StatChartOptionsEditorSettings(props) {
|
|
38
|
+
const { onChange, value } = props;
|
|
39
|
+
// ensures decimalPlaces defaults to correct value
|
|
40
|
+
const format = (0, _merge.default)({}, DEFAULT_FORMAT, value.format);
|
|
41
|
+
const handleCalculationChange = (metricLabel)=>{
|
|
42
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
43
|
+
draft.calculation = metricLabel;
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
const handleMetricLabelChange = (newCalculation)=>{
|
|
47
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
48
|
+
draft.metricLabel = newCalculation;
|
|
49
|
+
}));
|
|
50
|
+
};
|
|
51
|
+
const handleUnitChange = (newFormat)=>{
|
|
52
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
53
|
+
draft.format = newFormat;
|
|
54
|
+
}));
|
|
55
|
+
};
|
|
56
|
+
const handleSparklineChange = (_, checked)=>{
|
|
57
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
58
|
+
// For now, setting to an empty object when checked, so the stat chart
|
|
59
|
+
// uses the default chart color and line styles. In the future, this
|
|
60
|
+
// will likely be configurable in the UI.
|
|
61
|
+
draft.sparkline = checked ? {} : undefined;
|
|
62
|
+
}));
|
|
63
|
+
};
|
|
64
|
+
const handleThresholdsChange = (thresholds)=>{
|
|
65
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
66
|
+
draft.thresholds = thresholds;
|
|
67
|
+
}));
|
|
68
|
+
};
|
|
69
|
+
const handleFontSizeChange = (fontSize)=>{
|
|
70
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
71
|
+
draft.valueFontSize = fontSize;
|
|
72
|
+
}));
|
|
73
|
+
};
|
|
74
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGrid, {
|
|
75
|
+
children: [
|
|
76
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorColumn, {
|
|
77
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGroup, {
|
|
78
|
+
title: "Misc",
|
|
79
|
+
children: [
|
|
80
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
81
|
+
label: "Sparkline",
|
|
82
|
+
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Switch, {
|
|
83
|
+
checked: !!value.sparkline,
|
|
84
|
+
onChange: handleSparklineChange
|
|
85
|
+
})
|
|
86
|
+
}),
|
|
87
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.FormatControls, {
|
|
88
|
+
value: format,
|
|
89
|
+
onChange: handleUnitChange
|
|
90
|
+
}),
|
|
91
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.CalculationSelector, {
|
|
92
|
+
value: value.calculation,
|
|
93
|
+
onChange: handleCalculationChange
|
|
94
|
+
}),
|
|
95
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.MetricLabelInput, {
|
|
96
|
+
value: value.metricLabel,
|
|
97
|
+
onChange: handleMetricLabelChange
|
|
98
|
+
}),
|
|
99
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.FontSizeSelector, {
|
|
100
|
+
value: value.valueFontSize,
|
|
101
|
+
onChange: handleFontSizeChange
|
|
102
|
+
})
|
|
103
|
+
]
|
|
104
|
+
})
|
|
105
|
+
}),
|
|
106
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorColumn, {
|
|
107
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ThresholdsEditor, {
|
|
108
|
+
disablePercentMode: true,
|
|
109
|
+
thresholds: value.thresholds,
|
|
110
|
+
onChange: handleThresholdsChange
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "StatChartPanel", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return StatChartPanel;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
+
const _components = require("@perses-dev/components");
|
|
25
|
+
const _material = require("@mui/material");
|
|
26
|
+
const _react = require("react");
|
|
27
|
+
const _core = require("@perses-dev/core");
|
|
28
|
+
const _datatransform = require("./utils/data-transform");
|
|
29
|
+
const _calculatevalue = require("./utils/calculate-value");
|
|
30
|
+
const _getcolor = require("./utils/get-color");
|
|
31
|
+
const MIN_WIDTH = 100;
|
|
32
|
+
const SPACING = 2;
|
|
33
|
+
const StatChartPanel = (props)=>{
|
|
34
|
+
const { spec, contentDimensions, queryResults } = props;
|
|
35
|
+
const { format, sparkline, valueFontSize: valueFontSize } = spec;
|
|
36
|
+
const chartsTheme = (0, _components.useChartsTheme)();
|
|
37
|
+
const statChartData = useStatChartData(queryResults, spec, chartsTheme);
|
|
38
|
+
const isMultiSeries = statChartData.length > 1;
|
|
39
|
+
if (contentDimensions === undefined) return null;
|
|
40
|
+
// Calculates chart width
|
|
41
|
+
const spacing = SPACING * (statChartData.length - 1);
|
|
42
|
+
let chartWidth = (contentDimensions.width - spacing) / statChartData.length;
|
|
43
|
+
if (isMultiSeries && chartWidth < MIN_WIDTH) {
|
|
44
|
+
chartWidth = MIN_WIDTH;
|
|
45
|
+
}
|
|
46
|
+
const noDataTextStyle = chartsTheme.noDataOption.title.textStyle;
|
|
47
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
|
|
48
|
+
height: contentDimensions.height,
|
|
49
|
+
width: contentDimensions.width,
|
|
50
|
+
spacing: `${SPACING}px`,
|
|
51
|
+
direction: "row",
|
|
52
|
+
justifyContent: isMultiSeries ? 'left' : 'center',
|
|
53
|
+
alignItems: "center",
|
|
54
|
+
sx: {
|
|
55
|
+
overflowX: isMultiSeries ? 'scroll' : 'auto'
|
|
56
|
+
},
|
|
57
|
+
children: statChartData.length ? statChartData.map((series, index)=>{
|
|
58
|
+
const sparklineConfig = (0, _datatransform.convertSparkline)(chartsTheme, series.color, sparkline);
|
|
59
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.StatChart, {
|
|
60
|
+
width: chartWidth,
|
|
61
|
+
height: contentDimensions.height,
|
|
62
|
+
data: series,
|
|
63
|
+
format: format,
|
|
64
|
+
sparkline: sparklineConfig,
|
|
65
|
+
showSeriesName: isMultiSeries,
|
|
66
|
+
valueFontSize: valueFontSize
|
|
67
|
+
}, index);
|
|
68
|
+
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
|
|
69
|
+
sx: {
|
|
70
|
+
...noDataTextStyle
|
|
71
|
+
},
|
|
72
|
+
children: "No data"
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const useStatChartData = (queryResults, spec, chartsTheme)=>{
|
|
77
|
+
return (0, _react.useMemo)(()=>{
|
|
78
|
+
const { calculation, mappings, metricLabel } = spec;
|
|
79
|
+
const statChartData = [];
|
|
80
|
+
for (const result of queryResults){
|
|
81
|
+
for (const seriesData of result.data.series){
|
|
82
|
+
const calculatedValue = (0, _calculatevalue.calculateValue)(calculation, seriesData);
|
|
83
|
+
// get label metric value
|
|
84
|
+
const labelValue = getLabelValue(metricLabel, seriesData.labels);
|
|
85
|
+
// get actual value to display
|
|
86
|
+
const displayValue = getValueOrLabel(calculatedValue, mappings, labelValue);
|
|
87
|
+
const color = (0, _getcolor.getStatChartColor)(chartsTheme, spec, calculatedValue);
|
|
88
|
+
const series = {
|
|
89
|
+
name: seriesData.formattedName ?? '',
|
|
90
|
+
values: seriesData.values
|
|
91
|
+
};
|
|
92
|
+
statChartData.push({
|
|
93
|
+
calculatedValue: displayValue,
|
|
94
|
+
seriesData: series,
|
|
95
|
+
color
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return statChartData;
|
|
100
|
+
}, [
|
|
101
|
+
queryResults,
|
|
102
|
+
spec,
|
|
103
|
+
chartsTheme
|
|
104
|
+
]);
|
|
105
|
+
};
|
|
106
|
+
const getValueOrLabel = (value, mappings, label)=>{
|
|
107
|
+
if (label) {
|
|
108
|
+
return label;
|
|
109
|
+
}
|
|
110
|
+
if (mappings?.length && value !== undefined && value !== null) {
|
|
111
|
+
return (0, _core.applyValueMapping)(value, mappings).value;
|
|
112
|
+
} else {
|
|
113
|
+
return value;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const getLabelValue = (fieldLabel, labels)=>{
|
|
117
|
+
if (!labels || !fieldLabel) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
for (const [key, value] of Object.entries(labels)){
|
|
121
|
+
const regex = (0, _core.createRegexFromString)(fieldLabel);
|
|
122
|
+
if (regex.test(key)) {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "StatChartValueMappingEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return StatChartValueMappingEditor;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
+
const _components = require("@perses-dev/components");
|
|
25
|
+
const StatChartValueMappingEditor = ({ onChange, value })=>{
|
|
26
|
+
function handleValueMappingChange(mappings) {
|
|
27
|
+
onChange({
|
|
28
|
+
...value,
|
|
29
|
+
mappings
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ValueMappingsEditor, {
|
|
33
|
+
mappings: value.mappings ?? [],
|
|
34
|
+
onChange: handleValueMappingChange
|
|
35
|
+
});
|
|
36
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
18
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
19
|
+
const _client = /*#__PURE__*/ _interop_require_default(require("react-dom/client"));
|
|
20
|
+
function _interop_require_default(obj) {
|
|
21
|
+
return obj && obj.__esModule ? obj : {
|
|
22
|
+
default: obj
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const root = _client.default.createRoot(document.getElementById('root'));
|
|
26
|
+
root.render(/*#__PURE__*/ (0, _jsxruntime.jsx)(_react.default.StrictMode, {}));
|
package/lib/cjs/env.d.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
/// <reference types="@rsbuild/core/types" />
|
|
14
|
+
"use strict";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "getPluginModule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getPluginModule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _packagejson = /*#__PURE__*/ _interop_require_default(require("../package.json"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function getPluginModule() {
|
|
18
|
+
const { name, version, perses } = _packagejson.default;
|
|
19
|
+
return {
|
|
20
|
+
kind: 'PluginModule',
|
|
21
|
+
metadata: {
|
|
22
|
+
name,
|
|
23
|
+
version
|
|
24
|
+
},
|
|
25
|
+
spec: perses
|
|
26
|
+
};
|
|
27
|
+
}
|