@perses-dev/components 0.4.2 → 0.5.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/README.md +18 -0
- package/dist/EChart.d.ts +4 -1
- package/dist/EChart.d.ts.map +1 -1
- package/dist/EChart.js +1 -1
- package/dist/{GaugeChart.d.ts → GaugeChart/GaugeChart.d.ts} +2 -1
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -0
- package/dist/GaugeChart/GaugeChart.js +1 -0
- package/dist/GaugeChart/index.d.ts +2 -0
- package/dist/GaugeChart/index.d.ts.map +1 -0
- package/dist/GaugeChart/index.js +1 -0
- package/dist/InfoTooltip/InfoTooltip.d.ts +17 -0
- package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -0
- package/dist/InfoTooltip/InfoTooltip.js +1 -0
- package/dist/InfoTooltip/InfoTooltip.test.d.ts +2 -0
- package/dist/InfoTooltip/InfoTooltip.test.d.ts.map +1 -0
- package/dist/InfoTooltip/InfoTooltip.test.js +1 -0
- package/dist/InfoTooltip/index.d.ts +2 -0
- package/dist/InfoTooltip/index.d.ts.map +1 -0
- package/dist/InfoTooltip/index.js +1 -0
- package/dist/LineChart/LineChart.d.ts +17 -0
- package/dist/LineChart/LineChart.d.ts.map +1 -0
- package/dist/LineChart/LineChart.js +1 -0
- package/dist/LineChart/index.d.ts +3 -0
- package/dist/LineChart/index.d.ts.map +1 -0
- package/dist/LineChart/index.js +1 -0
- package/dist/LineChart/utils.d.ts +12 -0
- package/dist/LineChart/utils.d.ts.map +1 -0
- package/dist/LineChart/utils.js +1 -0
- package/dist/{StatChart.d.ts → StatChart/StatChart.d.ts} +4 -9
- package/dist/StatChart/StatChart.d.ts.map +1 -0
- package/dist/StatChart/StatChart.js +1 -0
- package/dist/StatChart/StatChart.test.d.ts +2 -0
- package/dist/StatChart/StatChart.test.d.ts.map +1 -0
- package/dist/StatChart/StatChart.test.js +1 -0
- package/dist/StatChart/index.d.ts +2 -0
- package/dist/StatChart/index.d.ts.map +1 -0
- package/dist/StatChart/index.js +1 -0
- package/dist/{tooltip → Tooltip}/SeriesInfo.d.ts +0 -0
- package/dist/{tooltip → Tooltip}/SeriesInfo.d.ts.map +1 -1
- package/dist/{tooltip → Tooltip}/SeriesInfo.js +0 -0
- package/dist/{tooltip → Tooltip}/SeriesMarker.d.ts +0 -0
- package/dist/{tooltip → Tooltip}/SeriesMarker.d.ts.map +1 -1
- package/dist/{tooltip → Tooltip}/SeriesMarker.js +0 -0
- package/dist/{tooltip → Tooltip}/Tooltip.d.ts +1 -1
- package/dist/{tooltip → Tooltip}/Tooltip.d.ts.map +1 -1
- package/dist/{tooltip → Tooltip}/Tooltip.js +0 -0
- package/dist/{tooltip → Tooltip}/TooltipContent.d.ts +0 -0
- package/dist/{tooltip → Tooltip}/TooltipContent.d.ts.map +1 -1
- package/dist/{tooltip → Tooltip}/TooltipContent.js +0 -0
- package/dist/{tooltip → Tooltip}/focused-series.d.ts +1 -1
- package/dist/{tooltip → Tooltip}/focused-series.d.ts.map +1 -1
- package/dist/{tooltip → Tooltip}/focused-series.js +0 -0
- package/dist/Tooltip/focused-series.test.d.ts +2 -0
- package/dist/Tooltip/focused-series.test.d.ts.map +1 -0
- package/dist/Tooltip/focused-series.test.js +1 -0
- package/dist/Tooltip/index.d.ts +3 -0
- package/dist/Tooltip/index.d.ts.map +1 -0
- package/dist/Tooltip/index.js +1 -0
- package/dist/{tooltip → Tooltip}/tooltip-model.d.ts +0 -0
- package/dist/{tooltip → Tooltip}/tooltip-model.d.ts.map +1 -1
- package/dist/{tooltip → Tooltip}/tooltip-model.js +0 -0
- package/dist/cjs/EChart.js +3 -3
- package/dist/cjs/{GaugeChart.js → GaugeChart/GaugeChart.js} +12 -45
- package/dist/cjs/GaugeChart/index.js +29 -0
- package/dist/cjs/InfoTooltip/InfoTooltip.js +39 -0
- package/dist/cjs/InfoTooltip/InfoTooltip.test.js +33 -0
- package/dist/cjs/InfoTooltip/index.js +29 -0
- package/dist/cjs/LineChart/LineChart.js +154 -0
- package/dist/cjs/LineChart/index.js +29 -0
- package/dist/cjs/LineChart/utils.js +72 -0
- package/dist/cjs/StatChart/StatChart.js +104 -0
- package/dist/cjs/StatChart/StatChart.test.js +45 -0
- package/dist/cjs/StatChart/index.js +29 -0
- package/dist/cjs/{tooltip → Tooltip}/SeriesInfo.js +0 -0
- package/dist/cjs/{tooltip → Tooltip}/SeriesMarker.js +0 -0
- package/dist/cjs/{tooltip → Tooltip}/Tooltip.js +0 -0
- package/dist/cjs/{tooltip → Tooltip}/TooltipContent.js +0 -0
- package/dist/cjs/{tooltip → Tooltip}/focused-series.js +0 -0
- package/dist/cjs/Tooltip/focused-series.test.js +57 -0
- package/dist/cjs/Tooltip/index.js +30 -0
- package/dist/cjs/{tooltip → Tooltip}/tooltip-model.js +0 -0
- package/dist/cjs/context/ChartsThemeProvider.js +36 -0
- package/dist/cjs/index.js +5 -4
- package/dist/cjs/model/{graph-model.js → graph.js} +0 -0
- package/dist/cjs/model/index.js +31 -0
- package/dist/cjs/model/theme.js +14 -0
- package/dist/cjs/model/units.js +58 -85
- package/dist/cjs/test/index.js +29 -0
- package/dist/cjs/test/render.js +26 -0
- package/dist/cjs/test/setup-tests.js +18 -0
- package/dist/cjs/utils/index.js +30 -0
- package/dist/cjs/utils/theme-gen.js +180 -0
- package/dist/cjs/utils/theme-gen.test.js +196 -0
- package/dist/context/ChartsThemeProvider.d.ts +11 -0
- package/dist/context/ChartsThemeProvider.d.ts.map +1 -0
- package/dist/context/ChartsThemeProvider.js +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/model/{graph-model.d.ts → graph.d.ts} +6 -2
- package/dist/model/graph.d.ts.map +1 -0
- package/dist/model/{graph-model.js → graph.js} +0 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +1 -0
- package/dist/model/theme.d.ts +16 -0
- package/dist/model/theme.d.ts.map +1 -0
- package/dist/model/theme.js +1 -0
- package/dist/model/units.d.ts +22 -11
- package/dist/model/units.d.ts.map +1 -1
- package/dist/model/units.js +1 -1
- package/dist/test/index.d.ts +2 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +1 -0
- package/dist/test/render.d.ts +7 -0
- package/dist/test/render.d.ts.map +1 -0
- package/dist/test/render.js +1 -0
- package/dist/test/setup-tests.d.ts +2 -0
- package/dist/test/setup-tests.d.ts.map +1 -0
- package/dist/test/setup-tests.js +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/theme-gen.d.ts +6 -0
- package/dist/utils/theme-gen.d.ts.map +1 -0
- package/dist/utils/theme-gen.js +1 -0
- package/dist/utils/theme-gen.test.d.ts +2 -0
- package/dist/utils/theme-gen.test.d.ts.map +1 -0
- package/dist/utils/theme-gen.test.js +1 -0
- package/package.json +5 -4
- package/dist/GaugeChart.d.ts.map +0 -1
- package/dist/GaugeChart.js +0 -1
- package/dist/LineChart.d.ts +0 -22
- package/dist/LineChart.d.ts.map +0 -1
- package/dist/LineChart.js +0 -1
- package/dist/StatChart.d.ts.map +0 -1
- package/dist/StatChart.js +0 -1
- package/dist/cjs/LineChart.js +0 -252
- package/dist/cjs/StatChart.js +0 -207
- package/dist/model/graph-model.d.ts.map +0 -1
package/dist/cjs/LineChart.js
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LineChart = void 0;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
// Copyright 2022 The Perses Authors
|
|
9
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
// you may not use this file except in compliance with the License.
|
|
11
|
-
// You may obtain a copy of the License at
|
|
12
|
-
//
|
|
13
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
//
|
|
15
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
// See the License for the specific language governing permissions and
|
|
19
|
-
// limitations under the License.
|
|
20
|
-
const react_1 = require("react");
|
|
21
|
-
const core_1 = require("@perses-dev/core");
|
|
22
|
-
const material_1 = require("@mui/material");
|
|
23
|
-
const merge_1 = __importDefault(require("lodash/merge"));
|
|
24
|
-
const core_2 = require("echarts/core");
|
|
25
|
-
const charts_1 = require("echarts/charts");
|
|
26
|
-
const components_1 = require("echarts/components");
|
|
27
|
-
const renderers_1 = require("echarts/renderers");
|
|
28
|
-
const EChart_1 = require("./EChart");
|
|
29
|
-
const graph_model_1 = require("./model/graph-model");
|
|
30
|
-
const units_1 = require("./model/units");
|
|
31
|
-
const tooltip_model_1 = require("./tooltip/tooltip-model");
|
|
32
|
-
const Tooltip_1 = require("./tooltip/Tooltip");
|
|
33
|
-
(0, core_2.use)([
|
|
34
|
-
charts_1.LineChart,
|
|
35
|
-
components_1.GridComponent,
|
|
36
|
-
components_1.DataZoomComponent,
|
|
37
|
-
components_1.MarkAreaComponent,
|
|
38
|
-
components_1.MarkLineComponent,
|
|
39
|
-
components_1.MarkPointComponent,
|
|
40
|
-
components_1.TitleComponent,
|
|
41
|
-
components_1.ToolboxComponent,
|
|
42
|
-
components_1.TooltipComponent,
|
|
43
|
-
components_1.LegendComponent,
|
|
44
|
-
components_1.VisualMapComponent,
|
|
45
|
-
renderers_1.CanvasRenderer,
|
|
46
|
-
]);
|
|
47
|
-
const noDataOption = {
|
|
48
|
-
title: {
|
|
49
|
-
show: true,
|
|
50
|
-
textStyle: {
|
|
51
|
-
color: 'grey',
|
|
52
|
-
fontSize: 16,
|
|
53
|
-
fontWeight: 400,
|
|
54
|
-
},
|
|
55
|
-
text: 'No data',
|
|
56
|
-
left: 'center',
|
|
57
|
-
top: 'center',
|
|
58
|
-
},
|
|
59
|
-
xAxis: {
|
|
60
|
-
show: false,
|
|
61
|
-
},
|
|
62
|
-
yAxis: {
|
|
63
|
-
show: false,
|
|
64
|
-
},
|
|
65
|
-
series: [],
|
|
66
|
-
};
|
|
67
|
-
function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEnabled, onDataZoom, }) {
|
|
68
|
-
const theme = (0, material_1.useTheme)();
|
|
69
|
-
const chartRef = (0, react_1.useRef)();
|
|
70
|
-
const [showTooltip, setShowTooltip] = (0, react_1.useState)(true);
|
|
71
|
-
const handleEvents = (0, react_1.useMemo)(() => {
|
|
72
|
-
return {
|
|
73
|
-
datazoom: (params) => {
|
|
74
|
-
var _a, _b;
|
|
75
|
-
if (onDataZoom === undefined || params.batch[0] === undefined)
|
|
76
|
-
return;
|
|
77
|
-
const startIndex = (_a = params.batch[0].startValue) !== null && _a !== void 0 ? _a : 0;
|
|
78
|
-
const endIndex = (_b = params.batch[0].endValue) !== null && _b !== void 0 ? _b : data.xAxis.length - 1;
|
|
79
|
-
const xAxisStartValue = data.xAxis[startIndex];
|
|
80
|
-
const xAxisEndValue = data.xAxis[endIndex];
|
|
81
|
-
if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
|
|
82
|
-
const zoomEvent = {
|
|
83
|
-
start: xAxisStartValue,
|
|
84
|
-
end: xAxisEndValue,
|
|
85
|
-
startIndex,
|
|
86
|
-
endIndex,
|
|
87
|
-
};
|
|
88
|
-
onDataZoom(zoomEvent);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
};
|
|
92
|
-
}, [data, onDataZoom]);
|
|
93
|
-
if (chartRef.current !== undefined && dataZoomEnabled === true) {
|
|
94
|
-
const chart = chartRef.current;
|
|
95
|
-
chart.dispatchAction({
|
|
96
|
-
type: 'takeGlobalCursor',
|
|
97
|
-
key: 'dataZoomSelect',
|
|
98
|
-
dataZoomSelectActive: true,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
const handleOnMouseDown = (event) => {
|
|
102
|
-
// hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
|
|
103
|
-
if (event.target instanceof HTMLCanvasElement) {
|
|
104
|
-
setShowTooltip(false);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const handleOnMouseUp = () => {
|
|
108
|
-
setShowTooltip(true);
|
|
109
|
-
};
|
|
110
|
-
const handleOnMouseEnter = () => {
|
|
111
|
-
setShowTooltip(true);
|
|
112
|
-
};
|
|
113
|
-
const handleOnMouseLeave = () => {
|
|
114
|
-
setShowTooltip(false);
|
|
115
|
-
};
|
|
116
|
-
const option = (0, core_1.useDeepMemo)(() => {
|
|
117
|
-
var _a;
|
|
118
|
-
if (data.timeSeries === undefined)
|
|
119
|
-
return {};
|
|
120
|
-
if (data.timeSeries === null || data.timeSeries.length === 0)
|
|
121
|
-
return noDataOption;
|
|
122
|
-
const showPointsOnHover = data.timeSeries.length < graph_model_1.PROGRESSIVE_MODE_SERIES_LIMIT;
|
|
123
|
-
const defaultGrid = {
|
|
124
|
-
top: 10,
|
|
125
|
-
right: 20,
|
|
126
|
-
bottom: 5,
|
|
127
|
-
left: 20,
|
|
128
|
-
containLabel: true,
|
|
129
|
-
};
|
|
130
|
-
const defaultToolbox = {
|
|
131
|
-
show: true,
|
|
132
|
-
top: 10,
|
|
133
|
-
right: 10,
|
|
134
|
-
iconStyle: {
|
|
135
|
-
borderColor: theme.palette.text.primary,
|
|
136
|
-
},
|
|
137
|
-
feature: {
|
|
138
|
-
dataZoom: {
|
|
139
|
-
icon: dataZoomEnabled ? null : undefined,
|
|
140
|
-
yAxisIndex: 'none',
|
|
141
|
-
},
|
|
142
|
-
restore: {},
|
|
143
|
-
},
|
|
144
|
-
emphasis: {
|
|
145
|
-
iconStyle: {
|
|
146
|
-
textFill: theme.palette.text.primary,
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
if (dataZoomEnabled === false) {
|
|
151
|
-
delete defaultToolbox.feature.dataZoom.icon;
|
|
152
|
-
}
|
|
153
|
-
const rangeMs = (_a = data.rangeMs) !== null && _a !== void 0 ? _a : getDateRange(data.xAxis);
|
|
154
|
-
const option = {
|
|
155
|
-
title: {
|
|
156
|
-
show: false,
|
|
157
|
-
},
|
|
158
|
-
grid: (0, merge_1.default)(defaultGrid, grid),
|
|
159
|
-
toolbox: (0, merge_1.default)(defaultToolbox, toolbox),
|
|
160
|
-
series: data.timeSeries,
|
|
161
|
-
xAxis: {
|
|
162
|
-
type: 'category',
|
|
163
|
-
data: data.xAxis,
|
|
164
|
-
max: data.xAxisMax,
|
|
165
|
-
axisLabel: {
|
|
166
|
-
margin: 15,
|
|
167
|
-
color: theme.palette.text.primary,
|
|
168
|
-
formatter: (value) => {
|
|
169
|
-
return getFormattedDate(value, rangeMs);
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
axisTick: {
|
|
173
|
-
show: false,
|
|
174
|
-
},
|
|
175
|
-
axisLine: {
|
|
176
|
-
lineStyle: {
|
|
177
|
-
color: theme.palette.grey['600'],
|
|
178
|
-
},
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
yAxis: {
|
|
182
|
-
type: 'value',
|
|
183
|
-
boundaryGap: [0, '10%'],
|
|
184
|
-
axisLabel: {
|
|
185
|
-
margin: 12,
|
|
186
|
-
color: theme.palette.text.primary,
|
|
187
|
-
formatter: (value) => {
|
|
188
|
-
return (0, units_1.abbreviateLargeNumber)(value);
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
splitLine: {
|
|
192
|
-
show: true,
|
|
193
|
-
lineStyle: {
|
|
194
|
-
width: 0.5,
|
|
195
|
-
color: theme.palette.grey['300'],
|
|
196
|
-
opacity: 0.95,
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
animation: false,
|
|
201
|
-
tooltip: {
|
|
202
|
-
show: showPointsOnHover,
|
|
203
|
-
trigger: 'axis',
|
|
204
|
-
showContent: false,
|
|
205
|
-
axisPointer: {
|
|
206
|
-
type: 'none',
|
|
207
|
-
},
|
|
208
|
-
},
|
|
209
|
-
legend,
|
|
210
|
-
visualMap,
|
|
211
|
-
};
|
|
212
|
-
return option;
|
|
213
|
-
// TODO (sjcobb): consolidate option props using echarts theme to reduce num of items in dep array
|
|
214
|
-
}, [data, theme, grid, legend, toolbox, dataZoomEnabled, visualMap]);
|
|
215
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
216
|
-
height,
|
|
217
|
-
}, onMouseDown: handleOnMouseDown, onMouseUp: handleOnMouseUp, onMouseLeave: handleOnMouseLeave, onMouseEnter: handleOnMouseEnter, children: [showTooltip === true && ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { chartRef: chartRef, tooltipData: tooltip_model_1.emptyTooltipData, chartData: data, wrapLabels: true })), (0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
|
|
218
|
-
width: '100%',
|
|
219
|
-
height: '100%',
|
|
220
|
-
}, option: option, onEvents: handleEvents, _instance: chartRef })] }));
|
|
221
|
-
}
|
|
222
|
-
exports.LineChart = LineChart;
|
|
223
|
-
// fallback when xAxis time range not passed as prop
|
|
224
|
-
function getDateRange(data) {
|
|
225
|
-
const defaultRange = 3600000; // hour in ms
|
|
226
|
-
if (data.length === 0)
|
|
227
|
-
return defaultRange;
|
|
228
|
-
const lastDatum = data[data.length - 1];
|
|
229
|
-
if (data[0] === undefined || lastDatum === undefined)
|
|
230
|
-
return defaultRange;
|
|
231
|
-
return lastDatum - data[0];
|
|
232
|
-
}
|
|
233
|
-
// determines time granularity for axis labels, defaults to hh:mm
|
|
234
|
-
function getFormattedDate(value, rangeMs) {
|
|
235
|
-
const dateFormatOptions = {
|
|
236
|
-
hour: 'numeric',
|
|
237
|
-
minute: 'numeric',
|
|
238
|
-
hourCycle: 'h23',
|
|
239
|
-
};
|
|
240
|
-
const thirtyMinMs = 1800000;
|
|
241
|
-
const dayMs = 86400000;
|
|
242
|
-
if (rangeMs <= thirtyMinMs) {
|
|
243
|
-
dateFormatOptions.second = 'numeric';
|
|
244
|
-
}
|
|
245
|
-
else if (rangeMs >= dayMs) {
|
|
246
|
-
dateFormatOptions.month = 'numeric';
|
|
247
|
-
dateFormatOptions.day = 'numeric';
|
|
248
|
-
}
|
|
249
|
-
const DATE_FORMAT = new Intl.DateTimeFormat(undefined, dateFormatOptions);
|
|
250
|
-
// remove comma when month / day present
|
|
251
|
-
return DATE_FORMAT.format(value).replace(/, /g, ' ');
|
|
252
|
-
}
|
package/dist/cjs/StatChart.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
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
|
-
// Copyright 2022 The Perses Authors
|
|
6
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
// you may not use this file except in compliance with the License.
|
|
8
|
-
// You may obtain a copy of the License at
|
|
9
|
-
//
|
|
10
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
//
|
|
12
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
// See the License for the specific language governing permissions and
|
|
16
|
-
// limitations under the License.
|
|
17
|
-
const react_1 = require("react");
|
|
18
|
-
const material_1 = require("@mui/material");
|
|
19
|
-
const lodash_es_1 = require("lodash-es");
|
|
20
|
-
const core_1 = require("echarts/core");
|
|
21
|
-
const charts_1 = require("echarts/charts");
|
|
22
|
-
const charts_2 = require("echarts/charts");
|
|
23
|
-
const components_1 = require("echarts/components");
|
|
24
|
-
const renderers_1 = require("echarts/renderers");
|
|
25
|
-
const units_1 = require("./model/units");
|
|
26
|
-
const EChart_1 = require("./EChart");
|
|
27
|
-
(0, core_1.use)([
|
|
28
|
-
charts_1.GaugeChart,
|
|
29
|
-
charts_2.LineChart,
|
|
30
|
-
components_1.GridComponent,
|
|
31
|
-
components_1.DatasetComponent,
|
|
32
|
-
components_1.TitleComponent,
|
|
33
|
-
components_1.TooltipComponent,
|
|
34
|
-
renderers_1.CanvasRenderer,
|
|
35
|
-
]);
|
|
36
|
-
const noDataOption = {
|
|
37
|
-
title: {
|
|
38
|
-
show: true,
|
|
39
|
-
textStyle: {
|
|
40
|
-
color: 'grey',
|
|
41
|
-
fontSize: 16,
|
|
42
|
-
fontWeight: 400,
|
|
43
|
-
},
|
|
44
|
-
text: 'No data',
|
|
45
|
-
left: 'center',
|
|
46
|
-
top: 'center',
|
|
47
|
-
},
|
|
48
|
-
xAxis: {
|
|
49
|
-
show: false,
|
|
50
|
-
},
|
|
51
|
-
yAxis: {
|
|
52
|
-
show: false,
|
|
53
|
-
},
|
|
54
|
-
series: [],
|
|
55
|
-
};
|
|
56
|
-
function StatChart(props) {
|
|
57
|
-
const { width, height, data, unit, backgroundColor, sparkline } = props;
|
|
58
|
-
const theme = (0, material_1.useTheme)();
|
|
59
|
-
const option = (0, react_1.useMemo)(() => {
|
|
60
|
-
var _a;
|
|
61
|
-
if (data.seriesData === undefined)
|
|
62
|
-
return {};
|
|
63
|
-
if (data.seriesData === null || data.calculatedValue === undefined)
|
|
64
|
-
return noDataOption;
|
|
65
|
-
const series = data.seriesData;
|
|
66
|
-
const calculatedValue = (_a = data.calculatedValue) !== null && _a !== void 0 ? _a : 0;
|
|
67
|
-
const isLargePanel = width > 250 ? true : false;
|
|
68
|
-
const showName = isLargePanel;
|
|
69
|
-
const name = showName === true ? data.name : '';
|
|
70
|
-
const smallestSide = Math.min(width, height * 1.2);
|
|
71
|
-
const baseFontSize = Math.min((smallestSide / 4) * 0.65, 72);
|
|
72
|
-
const nameFontSize = baseFontSize * 0.5;
|
|
73
|
-
const statSeries = [
|
|
74
|
-
{
|
|
75
|
-
type: 'gauge',
|
|
76
|
-
data: [
|
|
77
|
-
{
|
|
78
|
-
value: calculatedValue,
|
|
79
|
-
name: name,
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
detail: {
|
|
83
|
-
show: true,
|
|
84
|
-
offsetCenter: ['0%', '-65%'],
|
|
85
|
-
formatter: [`{name|${name}}`, `{value|${(0, units_1.formatValue)(calculatedValue, unit)}}`].join('\n'),
|
|
86
|
-
rich: {
|
|
87
|
-
name: {
|
|
88
|
-
padding: showName === true ? [0, 0, 5, 0] : 0,
|
|
89
|
-
fontSize: nameFontSize,
|
|
90
|
-
lineHeight: nameFontSize * 2.5,
|
|
91
|
-
fontWeight: 500,
|
|
92
|
-
},
|
|
93
|
-
value: {},
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
center: ['50%', '60%'],
|
|
97
|
-
animation: false,
|
|
98
|
-
silent: true,
|
|
99
|
-
title: { show: false },
|
|
100
|
-
progress: { show: false },
|
|
101
|
-
pointer: { show: false },
|
|
102
|
-
axisLine: { show: false },
|
|
103
|
-
axisTick: { show: false },
|
|
104
|
-
splitLine: { show: false },
|
|
105
|
-
axisLabel: { show: false },
|
|
106
|
-
anchor: { show: false },
|
|
107
|
-
zlevel: 2,
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
if (sparkline !== undefined) {
|
|
111
|
-
const lineSeries = {
|
|
112
|
-
type: 'line',
|
|
113
|
-
data: [...series.values],
|
|
114
|
-
zlevel: 1,
|
|
115
|
-
symbol: 'none',
|
|
116
|
-
animation: false,
|
|
117
|
-
lineStyle: {
|
|
118
|
-
color: '#FFFFFF',
|
|
119
|
-
opacity: 0.6,
|
|
120
|
-
},
|
|
121
|
-
areaStyle: {
|
|
122
|
-
color: '#FFFFFF',
|
|
123
|
-
opacity: 0.3,
|
|
124
|
-
},
|
|
125
|
-
silent: true,
|
|
126
|
-
};
|
|
127
|
-
const mergedSeries = (0, lodash_es_1.merge)(lineSeries, sparkline);
|
|
128
|
-
statSeries.push(mergedSeries);
|
|
129
|
-
}
|
|
130
|
-
const option = {
|
|
131
|
-
title: {
|
|
132
|
-
show: false,
|
|
133
|
-
},
|
|
134
|
-
grid: [
|
|
135
|
-
{
|
|
136
|
-
show: true,
|
|
137
|
-
backgroundColor: backgroundColor,
|
|
138
|
-
top: 0,
|
|
139
|
-
right: 0,
|
|
140
|
-
bottom: 0,
|
|
141
|
-
left: 0,
|
|
142
|
-
containLabel: false,
|
|
143
|
-
borderWidth: 0,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
show: false,
|
|
147
|
-
top: '45%',
|
|
148
|
-
right: 0,
|
|
149
|
-
bottom: 0,
|
|
150
|
-
left: 0,
|
|
151
|
-
containLabel: false,
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
xAxis: {
|
|
155
|
-
type: 'time',
|
|
156
|
-
show: false,
|
|
157
|
-
boundaryGap: false,
|
|
158
|
-
gridIndex: 1, // sparkline grid
|
|
159
|
-
},
|
|
160
|
-
yAxis: {
|
|
161
|
-
type: 'value',
|
|
162
|
-
show: false,
|
|
163
|
-
gridIndex: 1,
|
|
164
|
-
},
|
|
165
|
-
tooltip: {
|
|
166
|
-
show: false,
|
|
167
|
-
},
|
|
168
|
-
series: statSeries,
|
|
169
|
-
textStyle: {
|
|
170
|
-
color: backgroundColor === 'transparent' ? theme.palette.text.primary : '#FFFFFF',
|
|
171
|
-
fontSize: 25,
|
|
172
|
-
lineHeight: 18,
|
|
173
|
-
fontFamily: '"Lato", sans-serif',
|
|
174
|
-
fontWeight: 'bold',
|
|
175
|
-
},
|
|
176
|
-
media: [
|
|
177
|
-
{
|
|
178
|
-
query: {
|
|
179
|
-
maxWidth: 150,
|
|
180
|
-
},
|
|
181
|
-
option: {
|
|
182
|
-
textStyle: {
|
|
183
|
-
fontSize: 12,
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
query: {
|
|
189
|
-
minWidth: 150,
|
|
190
|
-
},
|
|
191
|
-
option: {
|
|
192
|
-
textStyle: {
|
|
193
|
-
fontSize: `max(14px, ${baseFontSize}px)`,
|
|
194
|
-
lineHeight: Math.min(16, baseFontSize * 1.2),
|
|
195
|
-
},
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
};
|
|
200
|
-
return option;
|
|
201
|
-
}, [data, height, theme, unit, width, sparkline, backgroundColor]);
|
|
202
|
-
return ((0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
|
|
203
|
-
width: width,
|
|
204
|
-
height: height,
|
|
205
|
-
}, option: option }));
|
|
206
|
-
}
|
|
207
|
-
exports.StatChart = StatChart;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"graph-model.d.ts","sourceRoot":"","sources":["../../src/model/graph-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAEjD,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,oBAAY,qBAAqB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3E,oBAAY,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAEvE,IAAI,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,aAAa,EAAE,CAAC;CACzD;AAED,oBAAY,iBAAiB,GAAG;IAC9B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
|