@perses-dev/stat-chart-plugin 0.10.0 → 0.11.1
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/css/async/442.d3010b86.css +1 -0
- package/__mf/css/async/61.d3010b86.css +1 -0
- package/__mf/css/async/823.d3010b86.css +1 -0
- package/__mf/js/StatChart.91907838.js +6 -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/205.1bcd0ed9.js +83 -0
- package/__mf/js/async/235.046777ba.js +1 -0
- package/__mf/js/async/252.71d76564.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/302.b54c0505.js.LICENSE.txt +13 -0
- package/__mf/js/async/356.f5a1c439.js +1 -0
- package/__mf/js/async/392.a8143615.js +2 -0
- package/__mf/js/async/450.13fefb05.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/{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/790.42bd307b.js +7 -0
- package/__mf/js/async/873.bde3655e.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.fd6bf4ac.js +1 -0
- package/__mf/js/async/lib-router.ed92c54d.js +2 -0
- package/__mf/js/main.5a7ad716.js +6 -0
- package/lib/StatChartBase.d.ts +2 -0
- package/lib/StatChartBase.d.ts.map +1 -1
- package/lib/StatChartBase.js +92 -30
- package/lib/StatChartBase.js.map +1 -1
- package/lib/StatChartOptionsEditorSettings.d.ts.map +1 -1
- package/lib/StatChartOptionsEditorSettings.js +87 -31
- package/lib/StatChartOptionsEditorSettings.js.map +1 -1
- package/lib/StatChartPanel.d.ts.map +1 -1
- package/lib/StatChartPanel.js +7 -4
- package/lib/StatChartPanel.js.map +1 -1
- package/lib/bootstrap.js +1 -1
- package/lib/bootstrap.js.map +1 -1
- package/lib/cjs/StatChartBase.js +90 -28
- package/lib/cjs/StatChartOptionsEditorSettings.js +85 -29
- package/lib/cjs/StatChartPanel.js +7 -4
- package/lib/cjs/index-federation.js +12 -12
- package/lib/cjs/stat-chart-model.js +47 -4
- package/lib/stat-chart-model.d.ts +16 -1
- package/lib/stat-chart-model.d.ts.map +1 -1
- package/lib/stat-chart-model.js +33 -1
- package/lib/stat-chart-model.js.map +1 -1
- package/mf-manifest.json +34 -33
- package/mf-stats.json +34 -33
- package/package.json +12 -6
- package/__mf/css/async/263.1ed8bb01.css +0 -1
- package/__mf/css/async/341.1ed8bb01.css +0 -1
- package/__mf/css/async/759.1ed8bb01.css +0 -1
- package/__mf/js/StatChart.4380d9d9.js +0 -5
- package/__mf/js/async/109.8841516b.js +0 -73
- package/__mf/js/async/173.879ec01b.js +0 -2
- package/__mf/js/async/181.985d810b.js +0 -83
- package/__mf/js/async/224.82f1452f.js +0 -1
- package/__mf/js/async/238.e184091d.js +0 -1
- package/__mf/js/async/288.b314a020.js +0 -7
- package/__mf/js/async/292.a2435289.js +0 -1
- package/__mf/js/async/298.db4e15c8.js +0 -1
- package/__mf/js/async/409.b9808041.js +0 -1
- package/__mf/js/async/651.f2aaf868.js +0 -1
- package/__mf/js/async/694.d6624664.js +0 -1
- package/__mf/js/async/740.2a430835.js +0 -1
- package/__mf/js/async/75.0e924b9e.js +0 -1
- package/__mf/js/async/770.edf0b438.js +0 -1
- package/__mf/js/async/804.ee813935.js +0 -1
- package/__mf/js/async/828.d18e1139.js +0 -65
- 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/981.c97e9bc4.js +0 -2
- package/__mf/js/async/__federation_expose_StatChart.20144587.js +0 -1
- package/__mf/js/async/lib-router.5a2b101a.js +0 -2
- package/__mf/js/main.0d096334.js +0 -5
- /package/__mf/js/async/{964.2c4a1982.js.LICENSE.txt → 121.3f61f76f.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{181.985d810b.js.LICENSE.txt → 205.1bcd0ed9.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{109.8841516b.js.LICENSE.txt → 252.71d76564.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/{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/{288.b314a020.js.LICENSE.txt → 790.42bd307b.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/cjs/StatChartBase.js
CHANGED
|
@@ -29,6 +29,7 @@ const _charts = require("echarts/charts");
|
|
|
29
29
|
const _components = require("echarts/components");
|
|
30
30
|
const _renderers = require("echarts/renderers");
|
|
31
31
|
const _components1 = require("@perses-dev/components");
|
|
32
|
+
const _chromajs = /*#__PURE__*/ _interop_require_default(require("chroma-js"));
|
|
32
33
|
const _calculatefontsize = require("./utils/calculate-font-size");
|
|
33
34
|
const _formatstatchartvalue = require("./utils/format-stat-chart-value");
|
|
34
35
|
function _interop_require_default(obj) {
|
|
@@ -48,10 +49,12 @@ const LINE_HEIGHT = 1.2;
|
|
|
48
49
|
const SERIES_NAME_MAX_FONT_SIZE = 30;
|
|
49
50
|
const SERIES_NAME_FONT_WEIGHT = 400;
|
|
50
51
|
const VALUE_FONT_WEIGHT = 700;
|
|
52
|
+
const WHITE_COLOR_CODE = '#FFFFFF';
|
|
53
|
+
const BLACK_COLOR_CODE = '#000000';
|
|
51
54
|
const StatChartBase = (props)=>{
|
|
52
|
-
const { width, height, data, sparkline, showSeriesName, format, valueFontSize } = props;
|
|
55
|
+
const { width, height, data, data: { color }, sparkline, showSeriesName, format, valueFontSize, colorMode } = props;
|
|
56
|
+
const { palette: { mode: paletteMode, text: { secondary } } } = (0, _material.useTheme)();
|
|
53
57
|
const chartsTheme = (0, _components1.useChartsTheme)();
|
|
54
|
-
const color = data.color;
|
|
55
58
|
const formattedValue = (0, _formatstatchartvalue.formatStatChartValue)(data.calculatedValue, format);
|
|
56
59
|
const containerPadding = chartsTheme.container.padding.default;
|
|
57
60
|
// calculate series name font size and height
|
|
@@ -83,10 +86,10 @@ const StatChartBase = (props)=>{
|
|
|
83
86
|
// make sure the series name font size is slightly smaller than value font size
|
|
84
87
|
seriesNameFontSize = Math.min(optimalValueFontSize * 0.7, seriesNameFontSize);
|
|
85
88
|
const option = (0, _react.useMemo)(()=>{
|
|
86
|
-
if (data.seriesData
|
|
89
|
+
if (!data.seriesData) return chartsTheme.noDataOption;
|
|
87
90
|
const series = data.seriesData;
|
|
88
91
|
const statSeries = [];
|
|
89
|
-
if (sparkline
|
|
92
|
+
if (sparkline) {
|
|
90
93
|
const lineSeries = {
|
|
91
94
|
type: 'line',
|
|
92
95
|
name: series.name,
|
|
@@ -96,7 +99,20 @@ const StatChartBase = (props)=>{
|
|
|
96
99
|
animation: false,
|
|
97
100
|
silent: true
|
|
98
101
|
};
|
|
99
|
-
const
|
|
102
|
+
const clonedSparkLine = {
|
|
103
|
+
...sparkline
|
|
104
|
+
};
|
|
105
|
+
if (colorMode === 'background_solid') {
|
|
106
|
+
clonedSparkLine.areaStyle = {
|
|
107
|
+
color: WHITE_COLOR_CODE,
|
|
108
|
+
opacity: 0.4
|
|
109
|
+
};
|
|
110
|
+
clonedSparkLine.lineStyle = {
|
|
111
|
+
color: WHITE_COLOR_CODE,
|
|
112
|
+
opacity: 1
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const mergedSeries = (0, _merge.default)(lineSeries, clonedSparkLine);
|
|
100
116
|
statSeries.push(mergedSeries);
|
|
101
117
|
}
|
|
102
118
|
const option = {
|
|
@@ -136,35 +152,81 @@ const StatChartBase = (props)=>{
|
|
|
136
152
|
}, [
|
|
137
153
|
data,
|
|
138
154
|
chartsTheme,
|
|
139
|
-
sparkline
|
|
155
|
+
sparkline,
|
|
156
|
+
colorMode
|
|
140
157
|
]);
|
|
141
158
|
const textAlignment = sparkline ? 'auto' : 'center';
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
159
|
+
const styledFormattedValue = (0, _react.useMemo)(()=>{
|
|
160
|
+
let valueColor = '';
|
|
161
|
+
switch(colorMode){
|
|
162
|
+
case 'background_solid':
|
|
163
|
+
valueColor = _chromajs.default.contrast(color, WHITE_COLOR_CODE) > _chromajs.default.contrast(color, BLACK_COLOR_CODE) ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
|
|
164
|
+
break;
|
|
165
|
+
case 'none':
|
|
166
|
+
valueColor = paletteMode === 'dark' ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
|
|
167
|
+
break;
|
|
168
|
+
case 'value':
|
|
169
|
+
default:
|
|
170
|
+
valueColor = color;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(Value, {
|
|
174
|
+
variant: "h3",
|
|
175
|
+
color: valueColor,
|
|
176
|
+
fontSize: optimalValueFontSize,
|
|
177
|
+
padding: containerPadding,
|
|
178
|
+
children: formattedValue
|
|
179
|
+
});
|
|
180
|
+
}, [
|
|
181
|
+
colorMode,
|
|
182
|
+
containerPadding,
|
|
183
|
+
optimalValueFontSize,
|
|
184
|
+
formattedValue,
|
|
185
|
+
color,
|
|
186
|
+
paletteMode
|
|
187
|
+
]);
|
|
188
|
+
const seriesName = (0, _react.useMemo)(()=>{
|
|
189
|
+
if (!showSeriesName) return null;
|
|
190
|
+
let textColor = '';
|
|
191
|
+
switch(colorMode){
|
|
192
|
+
case 'background_solid':
|
|
193
|
+
textColor = _chromajs.default.contrast(color, WHITE_COLOR_CODE) > _chromajs.default.contrast(color, BLACK_COLOR_CODE) ? WHITE_COLOR_CODE : BLACK_COLOR_CODE;
|
|
194
|
+
break;
|
|
195
|
+
case 'none':
|
|
196
|
+
case 'value':
|
|
197
|
+
default:
|
|
198
|
+
textColor = secondary;
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(SeriesName, {
|
|
202
|
+
padding: containerPadding,
|
|
203
|
+
fontSize: seriesNameFontSize,
|
|
204
|
+
color: textColor,
|
|
205
|
+
children: data.seriesData?.name
|
|
206
|
+
});
|
|
207
|
+
}, [
|
|
208
|
+
colorMode,
|
|
209
|
+
showSeriesName,
|
|
210
|
+
secondary,
|
|
211
|
+
color,
|
|
212
|
+
containerPadding,
|
|
213
|
+
seriesNameFontSize,
|
|
214
|
+
data?.seriesData?.name
|
|
215
|
+
]);
|
|
148
216
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
|
|
149
217
|
sx: {
|
|
150
218
|
height: '100%',
|
|
151
219
|
width: '100%',
|
|
152
|
-
|
|
220
|
+
backgroundColor: colorMode === 'background_solid' ? color : 'transparent',
|
|
221
|
+
display: 'flex',
|
|
222
|
+
flexDirection: 'column',
|
|
223
|
+
justifyContent: textAlignment,
|
|
224
|
+
alignItems: textAlignment
|
|
153
225
|
},
|
|
154
226
|
children: [
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
children: data.seriesData?.name
|
|
159
|
-
}),
|
|
160
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(Value, {
|
|
161
|
-
variant: "h3",
|
|
162
|
-
color: color,
|
|
163
|
-
fontSize: optimalValueFontSize,
|
|
164
|
-
padding: containerPadding,
|
|
165
|
-
children: formattedValue
|
|
166
|
-
}),
|
|
167
|
-
sparkline !== undefined && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components1.EChart, {
|
|
227
|
+
seriesName,
|
|
228
|
+
styledFormattedValue,
|
|
229
|
+
sparkline && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components1.EChart, {
|
|
168
230
|
sx: {
|
|
169
231
|
width: '100%'
|
|
170
232
|
},
|
|
@@ -182,8 +244,8 @@ const StatChartBase = (props)=>{
|
|
|
182
244
|
};
|
|
183
245
|
const SeriesName = (0, _material.styled)(_material.Typography, {
|
|
184
246
|
shouldForwardProp: (prop)=>prop !== 'padding' && prop !== 'fontSize'
|
|
185
|
-
})(({
|
|
186
|
-
color:
|
|
247
|
+
})(({ padding, fontSize, color })=>({
|
|
248
|
+
color: color,
|
|
187
249
|
padding: `${padding}px`,
|
|
188
250
|
fontSize: `${fontSize}px`,
|
|
189
251
|
overflow: 'hidden',
|
|
@@ -26,6 +26,8 @@ const _components = require("@perses-dev/components");
|
|
|
26
26
|
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
27
27
|
const _immer = require("immer");
|
|
28
28
|
const _merge = /*#__PURE__*/ _interop_require_default(require("lodash/merge"));
|
|
29
|
+
const _react = require("react");
|
|
30
|
+
const _statchartmodel = require("./stat-chart-model");
|
|
29
31
|
function _interop_require_default(obj) {
|
|
30
32
|
return obj && obj.__esModule ? obj : {
|
|
31
33
|
default: obj
|
|
@@ -48,6 +50,14 @@ function StatChartOptionsEditorSettings(props) {
|
|
|
48
50
|
draft.metricLabel = newCalculation;
|
|
49
51
|
}));
|
|
50
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
|
+
]);
|
|
51
61
|
const handleUnitChange = (newFormat)=>{
|
|
52
62
|
onChange((0, _immer.produce)(value, (draft)=>{
|
|
53
63
|
draft.format = newFormat;
|
|
@@ -71,37 +81,83 @@ function StatChartOptionsEditorSettings(props) {
|
|
|
71
81
|
draft.valueFontSize = fontSize;
|
|
72
82
|
}));
|
|
73
83
|
};
|
|
84
|
+
const handleColorModeChange = (0, _react.useCallback)((_, newColorMode)=>{
|
|
85
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
86
|
+
draft.colorMode = newColorMode.id;
|
|
87
|
+
}));
|
|
88
|
+
}, [
|
|
89
|
+
onChange,
|
|
90
|
+
value
|
|
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
|
+
]);
|
|
106
|
+
const selectColorMode = (0, _react.useMemo)(()=>{
|
|
107
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
108
|
+
label: "Color mode",
|
|
109
|
+
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SettingsAutocomplete, {
|
|
110
|
+
onChange: handleColorModeChange,
|
|
111
|
+
options: _statchartmodel.COLOR_MODE_LABELS.map(({ id, label })=>({
|
|
112
|
+
id,
|
|
113
|
+
label
|
|
114
|
+
})),
|
|
115
|
+
disableClearable: true,
|
|
116
|
+
value: _statchartmodel.COLOR_MODE_LABELS.find((i)=>i.id === value.colorMode) ?? _statchartmodel.COLOR_MODE_LABELS.find((i)=>i.id === 'value')
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
}, [
|
|
120
|
+
value.colorMode,
|
|
121
|
+
handleColorModeChange
|
|
122
|
+
]);
|
|
74
123
|
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGrid, {
|
|
75
124
|
children: [
|
|
76
|
-
/*#__PURE__*/ (0, _jsxruntime.
|
|
77
|
-
children:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
+
]
|
|
105
161
|
}),
|
|
106
162
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorColumn, {
|
|
107
163
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ThresholdsEditor, {
|
|
@@ -33,11 +33,13 @@ const MIN_WIDTH = 100;
|
|
|
33
33
|
const SPACING = 2;
|
|
34
34
|
const StatChartPanel = (props)=>{
|
|
35
35
|
const { spec, contentDimensions, queryResults } = props;
|
|
36
|
-
const { format, sparkline, valueFontSize: valueFontSize } = spec;
|
|
36
|
+
const { format, sparkline, valueFontSize: valueFontSize, colorMode } = spec;
|
|
37
37
|
const chartsTheme = (0, _components.useChartsTheme)();
|
|
38
38
|
const statChartData = useStatChartData(queryResults, spec, chartsTheme);
|
|
39
39
|
const isMultiSeries = statChartData.length > 1;
|
|
40
|
-
|
|
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;
|
|
42
|
+
if (!contentDimensions) return null;
|
|
41
43
|
// Calculates chart width
|
|
42
44
|
const spacing = SPACING * (statChartData.length - 1);
|
|
43
45
|
let chartWidth = (contentDimensions.width - spacing) / statChartData.length;
|
|
@@ -63,8 +65,9 @@ const StatChartPanel = (props)=>{
|
|
|
63
65
|
data: series,
|
|
64
66
|
format: format,
|
|
65
67
|
sparkline: sparklineConfig,
|
|
66
|
-
showSeriesName:
|
|
67
|
-
valueFontSize: valueFontSize
|
|
68
|
+
showSeriesName: shouldShowLegend,
|
|
69
|
+
valueFontSize: valueFontSize,
|
|
70
|
+
colorMode: colorMode
|
|
68
71
|
}, index);
|
|
69
72
|
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
|
|
70
73
|
sx: {
|
|
@@ -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")));
|
|
@@ -14,18 +14,61 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
get COLOR_MODE_LABELS () {
|
|
25
|
+
return COLOR_MODE_LABELS;
|
|
26
|
+
},
|
|
27
|
+
get SHOW_LEGEND_LABELS () {
|
|
28
|
+
return SHOW_LEGEND_LABELS;
|
|
29
|
+
},
|
|
30
|
+
get createInitialStatChartOptions () {
|
|
20
31
|
return createInitialStatChartOptions;
|
|
21
32
|
}
|
|
22
33
|
});
|
|
34
|
+
const COLOR_MODE_LABELS = [
|
|
35
|
+
{
|
|
36
|
+
id: 'none',
|
|
37
|
+
label: 'None'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'value',
|
|
41
|
+
label: 'Text'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: 'background_solid',
|
|
45
|
+
label: 'Background'
|
|
46
|
+
}
|
|
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
|
+
];
|
|
23
65
|
function createInitialStatChartOptions() {
|
|
24
66
|
return {
|
|
25
67
|
calculation: 'last-number',
|
|
26
68
|
format: {
|
|
27
69
|
unit: 'decimal'
|
|
28
70
|
},
|
|
29
|
-
sparkline: {}
|
|
71
|
+
sparkline: {},
|
|
72
|
+
legendMode: 'auto'
|
|
30
73
|
};
|
|
31
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.
|
|
@@ -7,6 +7,19 @@ import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
|
7
7
|
export interface StatChartDefinition extends Definition<StatChartOptions> {
|
|
8
8
|
kind: 'StatChart';
|
|
9
9
|
}
|
|
10
|
+
export type ColorMode = 'none' | 'value' | 'background_solid';
|
|
11
|
+
export type ColorModeLabelItem = {
|
|
12
|
+
id: ColorMode;
|
|
13
|
+
label: string;
|
|
14
|
+
};
|
|
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[];
|
|
10
23
|
export interface StatChartOptions {
|
|
11
24
|
calculation: CalculationType;
|
|
12
25
|
format: FormatOptions;
|
|
@@ -15,6 +28,8 @@ export interface StatChartOptions {
|
|
|
15
28
|
sparkline?: StatChartSparklineOptions;
|
|
16
29
|
valueFontSize?: FontSizeOption;
|
|
17
30
|
mappings?: ValueMapping[];
|
|
31
|
+
colorMode?: ColorMode;
|
|
32
|
+
legendMode?: legendMode;
|
|
18
33
|
}
|
|
19
34
|
export interface StatChartSparklineOptions {
|
|
20
35
|
color?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stat-chart-model.d.ts","sourceRoot":"","sources":["../../src/stat-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"stat-chart-model.d.ts","sourceRoot":"","sources":["../../src/stat-chart-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC9G,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,UAAU,CAAC,gBAAgB,CAAC;IACvE,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,kBAAkB,CAAC;AAE9D,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,EAAE,SAAS,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,kBAAkB,EAIjD,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;AAE/C,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,UAAU,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,mBAAmB,EAInD,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,eAAe,CAAC;IAC7B,MAAM,EAAE,aAAa,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,SAAS,CAAC,EAAE,yBAAyB,CAAC;IACtC,aAAa,CAAC,EAAE,cAAc,CAAC;IAC/B,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,WAAW,yBAAyB;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,2BAA2B,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAE/E,wBAAgB,6BAA6B,IAAI,gBAAgB,CAShE"}
|
package/lib/stat-chart-model.js
CHANGED
|
@@ -10,13 +10,45 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
export const COLOR_MODE_LABELS = [
|
|
14
|
+
{
|
|
15
|
+
id: 'none',
|
|
16
|
+
label: 'None'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'value',
|
|
20
|
+
label: 'Text'
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'background_solid',
|
|
24
|
+
label: 'Background'
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
export const SHOW_LEGEND_LABELS = [
|
|
28
|
+
{
|
|
29
|
+
id: 'auto',
|
|
30
|
+
label: 'Auto',
|
|
31
|
+
description: 'Show legend for multi-series, hide legend for single series'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'on',
|
|
35
|
+
label: 'On',
|
|
36
|
+
description: 'Always show legend'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'off',
|
|
40
|
+
label: 'Off',
|
|
41
|
+
description: 'Always hide legend'
|
|
42
|
+
}
|
|
43
|
+
];
|
|
13
44
|
export function createInitialStatChartOptions() {
|
|
14
45
|
return {
|
|
15
46
|
calculation: 'last-number',
|
|
16
47
|
format: {
|
|
17
48
|
unit: 'decimal'
|
|
18
49
|
},
|
|
19
|
-
sparkline: {}
|
|
50
|
+
sparkline: {},
|
|
51
|
+
legendMode: 'auto'
|
|
20
52
|
};
|
|
21
53
|
}
|
|
22
54
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/stat-chart-model.ts"],"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 {
|
|
1
|
+
{"version":3,"sources":["../../src/stat-chart-model.ts"],"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 { FontSizeOption } from '@perses-dev/components';\nimport { CalculationType, Definition, FormatOptions, ThresholdOptions, ValueMapping } from '@perses-dev/core';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\n\n/**\n * The schema for a StatChart panel.\n */\nexport interface StatChartDefinition extends Definition<StatChartOptions> {\n kind: 'StatChart';\n}\n\nexport type ColorMode = 'none' | 'value' | 'background_solid';\n\nexport type ColorModeLabelItem = {\n id: ColorMode;\n label: string;\n};\n\nexport const COLOR_MODE_LABELS: ColorModeLabelItem[] = [\n { id: 'none', label: 'None' },\n { id: 'value', label: 'Text' },\n { id: 'background_solid', label: 'Background' },\n];\n\nexport type legendMode = 'auto' | 'on' | 'off';\n\nexport type ShowLegendLabelItem = {\n id: legendMode;\n label: string;\n description?: string;\n};\n\nexport const SHOW_LEGEND_LABELS: ShowLegendLabelItem[] = [\n { id: 'auto', label: 'Auto', description: 'Show legend for multi-series, hide legend for single series' },\n { id: 'on', label: 'On', description: 'Always show legend' },\n { id: 'off', label: 'Off', description: 'Always hide legend' },\n];\n\nexport interface StatChartOptions {\n calculation: CalculationType;\n format: FormatOptions;\n metricLabel?: string;\n thresholds?: ThresholdOptions;\n sparkline?: StatChartSparklineOptions;\n valueFontSize?: FontSizeOption;\n mappings?: ValueMapping[];\n colorMode?: ColorMode;\n legendMode?: legendMode;\n}\n\nexport interface StatChartSparklineOptions {\n color?: string;\n width?: number;\n}\n\nexport type StatChartOptionsEditorProps = OptionsEditorProps<StatChartOptions>;\n\nexport function createInitialStatChartOptions(): StatChartOptions {\n return {\n calculation: 'last-number',\n format: {\n unit: 'decimal',\n },\n sparkline: {},\n legendMode: 'auto',\n };\n}\n"],"names":["COLOR_MODE_LABELS","id","label","SHOW_LEGEND_LABELS","description","createInitialStatChartOptions","calculation","format","unit","sparkline","legendMode"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAoBjC,OAAO,MAAMA,oBAA0C;IACrD;QAAEC,IAAI;QAAQC,OAAO;IAAO;IAC5B;QAAED,IAAI;QAASC,OAAO;IAAO;IAC7B;QAAED,IAAI;QAAoBC,OAAO;IAAa;CAC/C,CAAC;AAUF,OAAO,MAAMC,qBAA4C;IACvD;QAAEF,IAAI;QAAQC,OAAO;QAAQE,aAAa;IAA8D;IACxG;QAAEH,IAAI;QAAMC,OAAO;QAAME,aAAa;IAAqB;IAC3D;QAAEH,IAAI;QAAOC,OAAO;QAAOE,aAAa;IAAqB;CAC9D,CAAC;AAqBF,OAAO,SAASC;IACd,OAAO;QACLC,aAAa;QACbC,QAAQ;YACNC,MAAM;QACR;QACAC,WAAW,CAAC;QACZC,YAAY;IACd;AACF"}
|