@perses-dev/components 0.8.1 → 0.10.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/dist/Drawer/Drawer.d.ts +3 -4
- package/dist/Drawer/Drawer.d.ts.map +1 -1
- package/dist/Drawer/Drawer.js +35 -1
- package/dist/Drawer/Drawer.js.map +1 -0
- package/dist/Drawer/index.js +15 -1
- package/dist/Drawer/index.js.map +1 -0
- package/dist/EChart.d.ts.map +1 -1
- package/dist/EChart.js +142 -1
- package/dist/EChart.js.map +1 -0
- package/dist/ErrorAlert.js +25 -1
- package/dist/ErrorAlert.js.map +1 -0
- package/dist/ErrorBoundary.js +16 -1
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/GaugeChart/GaugeChart.js +172 -1
- package/dist/GaugeChart/GaugeChart.js.map +1 -0
- package/dist/GaugeChart/index.js +15 -1
- package/dist/GaugeChart/index.js.map +1 -0
- package/dist/InfoTooltip/InfoTooltip.js +79 -1
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -0
- package/dist/InfoTooltip/InfoTooltip.test.js +36 -1
- package/dist/InfoTooltip/InfoTooltip.test.js.map +1 -0
- package/dist/InfoTooltip/index.js +15 -1
- package/dist/InfoTooltip/index.js.map +1 -0
- package/dist/LineChart/LineChart.js +198 -1
- package/dist/LineChart/LineChart.js.map +1 -0
- package/dist/LineChart/index.js +15 -1
- package/dist/LineChart/index.js.map +1 -0
- package/dist/LineChart/utils.js +63 -1
- package/dist/LineChart/utils.js.map +1 -0
- package/dist/StatChart/StatChart.js +121 -1
- package/dist/StatChart/StatChart.js.map +1 -0
- package/dist/StatChart/StatChart.test.js +82 -1
- package/dist/StatChart/StatChart.test.js.map +1 -0
- package/dist/StatChart/index.js +15 -1
- package/dist/StatChart/index.js.map +1 -0
- package/dist/TimeRangeSelector/AbsoluteTimePicker.js +175 -1
- package/dist/TimeRangeSelector/AbsoluteTimePicker.js.map +1 -0
- package/dist/TimeRangeSelector/TimeRangeSelector.js +52 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -0
- package/dist/TimeRangeSelector/index.js +16 -1
- package/dist/TimeRangeSelector/index.js.map +1 -0
- package/dist/TimeRangeSelector/utils.js +36 -1
- package/dist/TimeRangeSelector/utils.js.map +1 -0
- package/dist/Tooltip/SeriesInfo.js +143 -1
- package/dist/Tooltip/SeriesInfo.js.map +1 -0
- package/dist/Tooltip/SeriesMarker.js +33 -1
- package/dist/Tooltip/SeriesMarker.js.map +1 -0
- package/dist/Tooltip/Tooltip.js +72 -1
- package/dist/Tooltip/Tooltip.js.map +1 -0
- package/dist/Tooltip/TooltipContent.js +89 -1
- package/dist/Tooltip/TooltipContent.js.map +1 -0
- package/dist/Tooltip/focused-series.js +108 -1
- package/dist/Tooltip/focused-series.js.map +1 -0
- package/dist/Tooltip/focused-series.test.js +75 -1
- package/dist/Tooltip/focused-series.test.js.map +1 -0
- package/dist/Tooltip/index.js +16 -1
- package/dist/Tooltip/index.js.map +1 -0
- package/dist/Tooltip/tooltip-model.js +80 -1
- package/dist/Tooltip/tooltip-model.js.map +1 -0
- package/dist/Tooltip/utils.js +46 -1
- package/dist/Tooltip/utils.js.map +1 -0
- package/dist/cjs/Drawer/Drawer.js +26 -13
- package/dist/cjs/Drawer/index.js +16 -17
- package/dist/cjs/EChart.js +114 -89
- package/dist/cjs/ErrorAlert.js +16 -12
- package/dist/cjs/ErrorBoundary.js +10 -6
- package/dist/cjs/GaugeChart/GaugeChart.js +90 -57
- package/dist/cjs/GaugeChart/index.js +16 -17
- package/dist/cjs/InfoTooltip/InfoTooltip.js +90 -33
- package/dist/cjs/InfoTooltip/InfoTooltip.test.js +27 -17
- package/dist/cjs/InfoTooltip/index.js +16 -17
- package/dist/cjs/LineChart/LineChart.js +122 -87
- package/dist/cjs/LineChart/index.js +16 -17
- package/dist/cjs/LineChart/utils.js +23 -23
- package/dist/cjs/StatChart/StatChart.js +107 -46
- package/dist/cjs/StatChart/StatChart.test.js +65 -21
- package/dist/cjs/StatChart/index.js +16 -17
- package/dist/cjs/TimeRangeSelector/AbsoluteTimePicker.js +144 -64
- package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +45 -22
- package/dist/cjs/TimeRangeSelector/index.js +17 -18
- package/dist/cjs/TimeRangeSelector/utils.js +19 -16
- package/dist/cjs/Tooltip/SeriesInfo.js +120 -48
- package/dist/cjs/Tooltip/SeriesMarker.js +20 -11
- package/dist/cjs/Tooltip/Tooltip.js +95 -67
- package/dist/cjs/Tooltip/TooltipContent.js +76 -31
- package/dist/cjs/Tooltip/focused-series.js +40 -36
- package/dist/cjs/Tooltip/focused-series.test.js +36 -16
- package/dist/cjs/Tooltip/index.js +17 -18
- package/dist/cjs/Tooltip/tooltip-model.js +46 -30
- package/dist/cjs/Tooltip/utils.js +13 -16
- package/dist/cjs/context/ChartsThemeProvider.js +65 -13
- package/dist/cjs/index.js +27 -28
- package/dist/cjs/model/graph.js +10 -5
- package/dist/cjs/model/index.js +18 -19
- package/dist/cjs/model/theme.js +4 -2
- package/dist/cjs/model/units.js +68 -51
- package/dist/cjs/test/index.js +16 -17
- package/dist/cjs/test/render.js +22 -12
- package/dist/cjs/test/setup-tests.js +4 -2
- package/dist/cjs/utils/combine-sx.js +15 -16
- package/dist/cjs/utils/index.js +17 -18
- package/dist/cjs/utils/theme-gen.js +64 -55
- package/dist/cjs/utils/theme-gen.test.js +14 -12
- package/dist/context/ChartsThemeProvider.js +36 -1
- package/dist/context/ChartsThemeProvider.js.map +1 -0
- package/dist/index.js +26 -1
- package/dist/index.js.map +1 -0
- package/dist/model/graph.js +15 -1
- package/dist/model/graph.js.map +1 -0
- package/dist/model/index.js +17 -1
- package/dist/model/index.js.map +1 -0
- package/dist/model/theme.js +15 -1
- package/dist/model/theme.js.map +1 -0
- package/dist/model/units.d.ts.map +1 -1
- package/dist/model/units.js +196 -1
- package/dist/model/units.js.map +1 -0
- package/dist/test/index.js +15 -1
- package/dist/test/index.js.map +1 -0
- package/dist/test/render.js +32 -1
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.js +18 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/utils/combine-sx.js +27 -1
- package/dist/utils/combine-sx.js.map +1 -0
- package/dist/utils/index.js +16 -1
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/theme-gen.js +183 -1
- package/dist/utils/theme-gen.js.map +1 -0
- package/dist/utils/theme-gen.test.js +196 -1
- package/dist/utils/theme-gen.test.js.map +1 -0
- package/package.json +8 -4
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LineChart = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
1
|
// Copyright 2022 The Perses Authors
|
|
6
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -14,52 +10,61 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
14
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
11
|
// See the License for the specific language governing permissions and
|
|
16
12
|
// limitations under the License.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "LineChart", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>LineChart
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = require("react");
|
|
23
|
+
const _core = require("@perses-dev/core");
|
|
24
|
+
const _material = require("@mui/material");
|
|
25
|
+
const _core1 = require("echarts/core");
|
|
26
|
+
const _charts = require("echarts/charts");
|
|
27
|
+
const _components = require("echarts/components");
|
|
28
|
+
const _renderers = require("echarts/renderers");
|
|
29
|
+
const _echart = require("../EChart");
|
|
30
|
+
const _graph = require("../model/graph");
|
|
31
|
+
const _units = require("../model/units");
|
|
32
|
+
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
33
|
+
const _tooltip = require("../Tooltip/Tooltip");
|
|
34
|
+
const _utils = require("./utils");
|
|
35
|
+
(0, _core1.use)([
|
|
36
|
+
_charts.LineChart,
|
|
37
|
+
_components.GridComponent,
|
|
38
|
+
_components.DataZoomComponent,
|
|
39
|
+
_components.MarkAreaComponent,
|
|
40
|
+
_components.MarkLineComponent,
|
|
41
|
+
_components.MarkPointComponent,
|
|
42
|
+
_components.TitleComponent,
|
|
43
|
+
_components.ToolboxComponent,
|
|
44
|
+
_components.TooltipComponent,
|
|
45
|
+
_components.LegendComponent,
|
|
46
|
+
_components.VisualMapComponent,
|
|
47
|
+
_renderers.CanvasRenderer
|
|
43
48
|
]);
|
|
44
|
-
function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, onDoubleClick
|
|
45
|
-
const chartsTheme = (0,
|
|
46
|
-
const chartRef = (0,
|
|
47
|
-
const [showTooltip, setShowTooltip] = (0,
|
|
48
|
-
const [pinTooltip, setPinTooltip] = (0,
|
|
49
|
-
const handleEvents = (0,
|
|
49
|
+
function LineChart({ height , data , unit , grid , legend , visualMap , onDataZoom , onDoubleClick }) {
|
|
50
|
+
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
51
|
+
const chartRef = (0, _react.useRef)();
|
|
52
|
+
const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
|
|
53
|
+
const [pinTooltip, setPinTooltip] = (0, _react.useState)(false);
|
|
54
|
+
const handleEvents = (0, _react.useMemo)(()=>{
|
|
50
55
|
return {
|
|
51
|
-
datazoom: (params)
|
|
52
|
-
var _a, _b;
|
|
56
|
+
datazoom: (params)=>{
|
|
53
57
|
if (onDataZoom === undefined) {
|
|
54
|
-
setTimeout(()
|
|
58
|
+
setTimeout(()=>{
|
|
55
59
|
// workaround so unpin happens after click event
|
|
56
60
|
setPinTooltip(false);
|
|
57
61
|
}, 10);
|
|
58
62
|
}
|
|
59
|
-
if (onDataZoom === undefined || params.batch[0] === undefined)
|
|
60
|
-
|
|
61
|
-
const startIndex = (
|
|
62
|
-
|
|
63
|
+
if (onDataZoom === undefined || params.batch[0] === undefined) return;
|
|
64
|
+
var _startValue;
|
|
65
|
+
const startIndex = (_startValue = params.batch[0].startValue) !== null && _startValue !== void 0 ? _startValue : 0;
|
|
66
|
+
var _endValue;
|
|
67
|
+
const endIndex = (_endValue = params.batch[0].endValue) !== null && _endValue !== void 0 ? _endValue : data.xAxis.length - 1;
|
|
63
68
|
const xAxisStartValue = data.xAxis[startIndex];
|
|
64
69
|
const xAxisEndValue = data.xAxis[endIndex];
|
|
65
70
|
if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
|
|
@@ -67,54 +72,54 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, on
|
|
|
67
72
|
start: xAxisStartValue,
|
|
68
73
|
end: xAxisEndValue,
|
|
69
74
|
startIndex,
|
|
70
|
-
endIndex
|
|
75
|
+
endIndex
|
|
71
76
|
};
|
|
72
77
|
onDataZoom(zoomEvent);
|
|
73
78
|
}
|
|
74
|
-
}
|
|
75
|
-
// TODO: use legendselectchanged event to fix tooltip when legend selected
|
|
79
|
+
}
|
|
76
80
|
};
|
|
77
|
-
}, [
|
|
81
|
+
}, [
|
|
82
|
+
data,
|
|
83
|
+
onDataZoom,
|
|
84
|
+
setPinTooltip
|
|
85
|
+
]);
|
|
78
86
|
if (chartRef.current !== undefined) {
|
|
79
|
-
(0,
|
|
87
|
+
(0, _utils.enableDataZoom)(chartRef.current);
|
|
80
88
|
}
|
|
81
|
-
const handleOnClick = ()
|
|
82
|
-
const handleOnDoubleClick = (e)
|
|
89
|
+
const handleOnClick = ()=>setPinTooltip((current)=>!current);
|
|
90
|
+
const handleOnDoubleClick = (e)=>{
|
|
83
91
|
setPinTooltip(false);
|
|
84
92
|
// either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
|
|
85
93
|
if (onDoubleClick === undefined) {
|
|
86
94
|
if (chartRef.current !== undefined) {
|
|
87
|
-
(0,
|
|
95
|
+
(0, _utils.restoreChart)(chartRef.current);
|
|
88
96
|
}
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
97
|
+
} else {
|
|
91
98
|
onDoubleClick(e);
|
|
92
99
|
}
|
|
93
100
|
};
|
|
94
|
-
const handleOnMouseDown = (e)
|
|
101
|
+
const handleOnMouseDown = (e)=>{
|
|
95
102
|
// hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
|
|
96
103
|
if (e.target instanceof HTMLCanvasElement) {
|
|
97
104
|
setShowTooltip(false);
|
|
98
105
|
}
|
|
99
106
|
};
|
|
100
|
-
const handleOnMouseUp = ()
|
|
107
|
+
const handleOnMouseUp = ()=>{
|
|
101
108
|
setShowTooltip(true);
|
|
102
109
|
};
|
|
103
|
-
const handleOnMouseEnter = ()
|
|
110
|
+
const handleOnMouseEnter = ()=>{
|
|
104
111
|
setShowTooltip(true);
|
|
105
112
|
};
|
|
106
|
-
const handleOnMouseLeave = ()
|
|
113
|
+
const handleOnMouseLeave = ()=>{
|
|
107
114
|
setShowTooltip(false);
|
|
108
115
|
setPinTooltip(false);
|
|
109
116
|
};
|
|
110
|
-
const option = (0,
|
|
111
|
-
|
|
112
|
-
if (data.timeSeries ===
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const showPointsOnHover = data.timeSeries.length < graph_1.PROGRESSIVE_MODE_SERIES_LIMIT;
|
|
117
|
-
const rangeMs = (_a = data.rangeMs) !== null && _a !== void 0 ? _a : (0, utils_1.getDateRange)(data.xAxis);
|
|
117
|
+
const option = (0, _core.useDeepMemo)(()=>{
|
|
118
|
+
if (data.timeSeries === undefined) return {};
|
|
119
|
+
if (data.timeSeries === null || data.timeSeries.length === 0) return chartsTheme.noDataOption;
|
|
120
|
+
const showPointsOnHover = data.timeSeries.length < _graph.PROGRESSIVE_MODE_SERIES_LIMIT;
|
|
121
|
+
var _rangeMs;
|
|
122
|
+
const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : (0, _utils.getDateRange)(data.xAxis);
|
|
118
123
|
const option = {
|
|
119
124
|
series: data.timeSeries,
|
|
120
125
|
xAxis: {
|
|
@@ -122,19 +127,22 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, on
|
|
|
122
127
|
data: data.xAxis,
|
|
123
128
|
max: data.xAxisMax,
|
|
124
129
|
axisLabel: {
|
|
125
|
-
formatter: (value)
|
|
126
|
-
return (0,
|
|
127
|
-
}
|
|
128
|
-
}
|
|
130
|
+
formatter: (value)=>{
|
|
131
|
+
return (0, _utils.getFormattedDate)(value, rangeMs);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
129
134
|
},
|
|
130
135
|
yAxis: {
|
|
131
136
|
type: 'value',
|
|
132
|
-
boundaryGap: [
|
|
137
|
+
boundaryGap: [
|
|
138
|
+
0,
|
|
139
|
+
'10%'
|
|
140
|
+
],
|
|
133
141
|
axisLabel: {
|
|
134
|
-
formatter: (value)
|
|
135
|
-
return (0,
|
|
136
|
-
}
|
|
137
|
-
}
|
|
142
|
+
formatter: (value)=>{
|
|
143
|
+
return (0, _units.formatValue)(value, unit);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
138
146
|
},
|
|
139
147
|
animation: false,
|
|
140
148
|
tooltip: {
|
|
@@ -142,28 +150,55 @@ function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom, on
|
|
|
142
150
|
trigger: 'axis',
|
|
143
151
|
showContent: false,
|
|
144
152
|
axisPointer: {
|
|
145
|
-
type: 'none'
|
|
146
|
-
}
|
|
153
|
+
type: 'none'
|
|
154
|
+
}
|
|
147
155
|
},
|
|
148
156
|
toolbox: {
|
|
149
157
|
feature: {
|
|
150
158
|
dataZoom: {
|
|
151
159
|
icon: null,
|
|
152
|
-
yAxisIndex: 'none'
|
|
153
|
-
}
|
|
154
|
-
}
|
|
160
|
+
yAxisIndex: 'none'
|
|
161
|
+
}
|
|
162
|
+
}
|
|
155
163
|
},
|
|
156
164
|
grid,
|
|
157
165
|
legend,
|
|
158
|
-
visualMap
|
|
166
|
+
visualMap
|
|
159
167
|
};
|
|
160
168
|
return option;
|
|
161
|
-
}, [
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
169
|
+
}, [
|
|
170
|
+
data,
|
|
171
|
+
grid,
|
|
172
|
+
legend,
|
|
173
|
+
visualMap
|
|
174
|
+
]);
|
|
175
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
176
|
+
sx: {
|
|
177
|
+
height
|
|
178
|
+
},
|
|
179
|
+
onClick: handleOnClick,
|
|
180
|
+
onDoubleClick: handleOnDoubleClick,
|
|
181
|
+
onMouseDown: handleOnMouseDown,
|
|
182
|
+
onMouseUp: handleOnMouseUp,
|
|
183
|
+
onMouseLeave: handleOnMouseLeave,
|
|
184
|
+
onMouseEnter: handleOnMouseEnter,
|
|
185
|
+
children: [
|
|
186
|
+
showTooltip === true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
|
|
187
|
+
chartRef: chartRef,
|
|
188
|
+
chartData: data,
|
|
189
|
+
wrapLabels: true,
|
|
190
|
+
pinTooltip: pinTooltip
|
|
191
|
+
}),
|
|
192
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
193
|
+
sx: {
|
|
165
194
|
width: '100%',
|
|
166
|
-
height: '100%'
|
|
167
|
-
},
|
|
195
|
+
height: '100%'
|
|
196
|
+
},
|
|
197
|
+
option: option,
|
|
198
|
+
theme: chartsTheme.themeName,
|
|
199
|
+
onEvents: handleEvents,
|
|
200
|
+
_instance: chartRef
|
|
201
|
+
})
|
|
202
|
+
]
|
|
203
|
+
});
|
|
168
204
|
}
|
|
169
|
-
exports.LineChart = LineChart;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2022 The Perses Authors
|
|
3
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -11,19 +10,19 @@
|
|
|
11
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
11
|
// See the License for the specific language governing permissions and
|
|
13
12
|
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Object.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./LineChart"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// Copyright 2022 The Perses Authors
|
|
3
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -11,57 +10,59 @@
|
|
|
11
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
11
|
// See the License for the specific language governing permissions and
|
|
13
12
|
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
enableDataZoom: ()=>enableDataZoom,
|
|
25
|
+
restoreChart: ()=>restoreChart,
|
|
26
|
+
getDateRange: ()=>getDateRange,
|
|
27
|
+
getFormattedDate: ()=>getFormattedDate
|
|
28
|
+
});
|
|
17
29
|
function enableDataZoom(chart) {
|
|
18
30
|
const chartModel = chart['_model'];
|
|
19
|
-
if (chartModel === undefined)
|
|
20
|
-
return;
|
|
31
|
+
if (chartModel === undefined) return;
|
|
21
32
|
if (chartModel.option.toolbox !== undefined && chartModel.option.toolbox.length > 0) {
|
|
22
33
|
// check if hidden data zoom icon is unselected (if selected it would be 'emphasis' instead of 'normal')
|
|
23
34
|
if (chartModel.option.toolbox[0].feature.dataZoom.iconStatus.zoom === 'normal') {
|
|
24
35
|
chart.dispatchAction({
|
|
25
36
|
type: 'takeGlobalCursor',
|
|
26
37
|
key: 'dataZoomSelect',
|
|
27
|
-
dataZoomSelectActive: true
|
|
38
|
+
dataZoomSelectActive: true
|
|
28
39
|
});
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
|
-
exports.enableDataZoom = enableDataZoom;
|
|
33
|
-
// restore chart to original state before zoom or other actions were dispatched
|
|
34
|
-
// TODO: support incremental unzoom instead of restore to original state
|
|
35
43
|
function restoreChart(chart) {
|
|
36
44
|
chart.dispatchAction({
|
|
37
|
-
type: 'restore'
|
|
45
|
+
type: 'restore'
|
|
38
46
|
});
|
|
39
47
|
}
|
|
40
|
-
exports.restoreChart = restoreChart;
|
|
41
|
-
// fallback when xAxis time range not passed as prop
|
|
42
48
|
function getDateRange(data) {
|
|
43
49
|
const defaultRange = 3600000; // hour in ms
|
|
44
|
-
if (data.length === 0)
|
|
45
|
-
return defaultRange;
|
|
50
|
+
if (data.length === 0) return defaultRange;
|
|
46
51
|
const lastDatum = data[data.length - 1];
|
|
47
|
-
if (data[0] === undefined || lastDatum === undefined)
|
|
48
|
-
return defaultRange;
|
|
52
|
+
if (data[0] === undefined || lastDatum === undefined) return defaultRange;
|
|
49
53
|
return lastDatum - data[0];
|
|
50
54
|
}
|
|
51
|
-
exports.getDateRange = getDateRange;
|
|
52
|
-
// determines time granularity for axis labels, defaults to hh:mm
|
|
53
55
|
function getFormattedDate(value, rangeMs) {
|
|
54
56
|
const dateFormatOptions = {
|
|
55
57
|
hour: 'numeric',
|
|
56
58
|
minute: 'numeric',
|
|
57
|
-
hourCycle: 'h23'
|
|
59
|
+
hourCycle: 'h23'
|
|
58
60
|
};
|
|
59
61
|
const thirtyMinMs = 1800000;
|
|
60
62
|
const dayMs = 86400000;
|
|
61
63
|
if (rangeMs <= thirtyMinMs) {
|
|
62
64
|
dateFormatOptions.second = 'numeric';
|
|
63
|
-
}
|
|
64
|
-
else if (rangeMs >= dayMs) {
|
|
65
|
+
} else if (rangeMs >= dayMs) {
|
|
65
66
|
dateFormatOptions.month = 'numeric';
|
|
66
67
|
dateFormatOptions.day = 'numeric';
|
|
67
68
|
}
|
|
@@ -69,4 +70,3 @@ function getFormattedDate(value, rangeMs) {
|
|
|
69
70
|
// remove comma when month / day present
|
|
70
71
|
return DATE_FORMAT.format(value).replace(/, /g, ' ');
|
|
71
72
|
}
|
|
72
|
-
exports.getFormattedDate = getFormattedDate;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StatChart = void 0;
|
|
4
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
1
|
// Copyright 2022 The Perses Authors
|
|
6
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -14,53 +10,101 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
14
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
11
|
// See the License for the specific language governing permissions and
|
|
16
12
|
// limitations under the License.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "StatChart", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>StatChart
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _lodashEs = require("lodash-es");
|
|
25
|
+
const _core = require("echarts/core");
|
|
26
|
+
const _charts = require("echarts/charts");
|
|
27
|
+
const _components = require("echarts/components");
|
|
28
|
+
const _renderers = require("echarts/renderers");
|
|
29
|
+
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
30
|
+
const _units = require("../model/units");
|
|
31
|
+
const _echart = require("../EChart");
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
33
|
+
if (typeof WeakMap !== "function") return null;
|
|
34
|
+
var cacheBabelInterop = new WeakMap();
|
|
35
|
+
var cacheNodeInterop = new WeakMap();
|
|
36
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
37
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
38
|
+
})(nodeInterop);
|
|
39
|
+
}
|
|
40
|
+
function _interopRequireWildcard(obj, nodeInterop) {
|
|
41
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
45
|
+
return {
|
|
46
|
+
default: obj
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
50
|
+
if (cache && cache.has(obj)) {
|
|
51
|
+
return cache.get(obj);
|
|
52
|
+
}
|
|
53
|
+
var newObj = {};
|
|
54
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
55
|
+
for(var key in obj){
|
|
56
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
57
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
58
|
+
if (desc && (desc.get || desc.set)) {
|
|
59
|
+
Object.defineProperty(newObj, key, desc);
|
|
60
|
+
} else {
|
|
61
|
+
newObj[key] = obj[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
newObj.default = obj;
|
|
66
|
+
if (cache) {
|
|
67
|
+
cache.set(obj, newObj);
|
|
68
|
+
}
|
|
69
|
+
return newObj;
|
|
70
|
+
}
|
|
71
|
+
(0, _core.use)([
|
|
72
|
+
_charts.GaugeChart,
|
|
73
|
+
_charts.LineChart,
|
|
74
|
+
_components.GridComponent,
|
|
75
|
+
_components.DatasetComponent,
|
|
76
|
+
_components.TitleComponent,
|
|
77
|
+
_components.TooltipComponent,
|
|
78
|
+
_renderers.CanvasRenderer
|
|
36
79
|
]);
|
|
37
80
|
const PANEL_PADDING = 32;
|
|
38
81
|
const MIN_VALUE_SIZE = 12;
|
|
39
82
|
const MAX_VALUE_SIZE = 36;
|
|
40
83
|
function StatChart(props) {
|
|
41
|
-
const { width, height, data, unit, sparkline
|
|
42
|
-
const chartsTheme = (0,
|
|
43
|
-
const formattedValue = data.calculatedValue === undefined ? '
|
|
44
|
-
const option = (0,
|
|
45
|
-
if (data.seriesData === undefined)
|
|
46
|
-
return chartsTheme.noDataOption;
|
|
84
|
+
const { width , height , data , unit , sparkline } = props;
|
|
85
|
+
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
86
|
+
const formattedValue = data.calculatedValue === undefined ? '' : (0, _units.formatValue)(data.calculatedValue, unit);
|
|
87
|
+
const option = (0, _react.useMemo)(()=>{
|
|
88
|
+
if (data.seriesData === undefined) return chartsTheme.noDataOption;
|
|
47
89
|
const series = data.seriesData;
|
|
48
90
|
const statSeries = [];
|
|
49
91
|
if (sparkline !== undefined) {
|
|
50
92
|
const lineSeries = {
|
|
51
93
|
type: 'line',
|
|
52
|
-
data: [
|
|
94
|
+
data: [
|
|
95
|
+
...series.values
|
|
96
|
+
],
|
|
53
97
|
zlevel: 1,
|
|
54
98
|
symbol: 'none',
|
|
55
99
|
animation: false,
|
|
56
|
-
silent: true
|
|
100
|
+
silent: true
|
|
57
101
|
};
|
|
58
|
-
const mergedSeries = (0,
|
|
102
|
+
const mergedSeries = (0, _lodashEs.merge)(lineSeries, sparkline);
|
|
59
103
|
statSeries.push(mergedSeries);
|
|
60
104
|
}
|
|
61
105
|
const option = {
|
|
62
106
|
title: {
|
|
63
|
-
show: false
|
|
107
|
+
show: false
|
|
64
108
|
},
|
|
65
109
|
grid: {
|
|
66
110
|
show: false,
|
|
@@ -68,37 +112,54 @@ function StatChart(props) {
|
|
|
68
112
|
right: 0,
|
|
69
113
|
bottom: 0,
|
|
70
114
|
left: 0,
|
|
71
|
-
containLabel: false
|
|
115
|
+
containLabel: false
|
|
72
116
|
},
|
|
73
117
|
xAxis: {
|
|
74
118
|
type: 'time',
|
|
75
119
|
show: false,
|
|
76
|
-
boundaryGap: false
|
|
120
|
+
boundaryGap: false
|
|
77
121
|
},
|
|
78
122
|
yAxis: {
|
|
79
123
|
type: 'value',
|
|
80
|
-
show: false
|
|
124
|
+
show: false
|
|
81
125
|
},
|
|
82
126
|
tooltip: {
|
|
83
|
-
show: false
|
|
127
|
+
show: false
|
|
84
128
|
},
|
|
85
|
-
series: statSeries
|
|
129
|
+
series: statSeries
|
|
86
130
|
};
|
|
87
131
|
return option;
|
|
88
|
-
}, [
|
|
132
|
+
}, [
|
|
133
|
+
data,
|
|
134
|
+
chartsTheme,
|
|
135
|
+
sparkline
|
|
136
|
+
]);
|
|
89
137
|
const isLargePanel = width > 250 && height > 180;
|
|
90
138
|
// adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
|
|
91
139
|
const charactersAdjust = formattedValue.length;
|
|
92
140
|
const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
|
|
93
|
-
return (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
141
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
142
|
+
children: [
|
|
143
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
144
|
+
variant: "h3",
|
|
145
|
+
sx: (theme)=>({
|
|
146
|
+
color: theme.palette.text.primary,
|
|
147
|
+
fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`
|
|
148
|
+
}),
|
|
149
|
+
children: formattedValue
|
|
150
|
+
}),
|
|
151
|
+
sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
152
|
+
sx: {
|
|
97
153
|
width: width + PANEL_PADDING,
|
|
98
154
|
height: height,
|
|
99
155
|
position: 'absolute',
|
|
100
156
|
bottom: 0,
|
|
101
|
-
left: 0
|
|
102
|
-
},
|
|
157
|
+
left: 0
|
|
158
|
+
},
|
|
159
|
+
option: option,
|
|
160
|
+
theme: chartsTheme.themeName,
|
|
161
|
+
renderer: "svg"
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
});
|
|
103
165
|
}
|
|
104
|
-
exports.StatChart = StatChart;
|