@perses-dev/components 0.3.0 → 0.3.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/dist/cjs/ECharts.js +103 -0
- package/dist/cjs/ErrorAlert.js +25 -0
- package/dist/cjs/ErrorBoundary.js +18 -0
- package/dist/cjs/GaugeChart.js +178 -0
- package/dist/cjs/LineChart.js +227 -0
- package/dist/cjs/StatChart.js +205 -0
- package/dist/cjs/index.js +37 -0
- package/dist/cjs/model/graph-model.js +16 -0
- package/dist/cjs/model/units.js +211 -0
- package/dist/cjs/tooltip/SeriesInfo.js +76 -0
- package/dist/cjs/tooltip/SeriesMarker.js +30 -0
- package/dist/cjs/tooltip/Tooltip.js +99 -0
- package/dist/cjs/tooltip/TooltipContent.js +50 -0
- package/dist/cjs/tooltip/focused-series.js +108 -0
- package/dist/cjs/tooltip/tooltip-model.js +82 -0
- package/dist/cjs/utils/combine-sx.js +30 -0
- package/dist/model/units.d.ts +4 -0
- package/dist/model/units.d.ts.map +1 -1
- package/dist/model/units.js +1 -1
- package/dist/tooltip/SeriesInfo.js +1 -1
- package/dist/tooltip/TooltipContent.js +1 -1
- package/package.json +4 -2
|
@@ -0,0 +1,103 @@
|
|
|
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.ECharts = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
// Copyright 2021 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 debounce_1 = __importDefault(require("lodash/debounce"));
|
|
22
|
+
const core_1 = require("echarts/core");
|
|
23
|
+
const material_1 = require("@mui/material");
|
|
24
|
+
const mouseEvents = [
|
|
25
|
+
'click',
|
|
26
|
+
'dblclick',
|
|
27
|
+
'mousedown',
|
|
28
|
+
'mousemove',
|
|
29
|
+
'mouseup',
|
|
30
|
+
'mouseover',
|
|
31
|
+
'mouseout',
|
|
32
|
+
'globalout',
|
|
33
|
+
'contextmenu',
|
|
34
|
+
];
|
|
35
|
+
const batchEvents = ['datazoom', 'downplay', 'highlight'];
|
|
36
|
+
function ECharts({ sx, _instance, onChartInitialized, option, onEvents }) {
|
|
37
|
+
const [containerRef, setContainerRef] = (0, react_1.useState)(null);
|
|
38
|
+
const [echart, setChart] = (0, react_1.useState)(undefined);
|
|
39
|
+
// Create a chart instance in the container
|
|
40
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
41
|
+
if (containerRef === null)
|
|
42
|
+
return;
|
|
43
|
+
const chart = (0, core_1.init)(containerRef);
|
|
44
|
+
setChart(chart);
|
|
45
|
+
if (_instance !== undefined) {
|
|
46
|
+
_instance.current = chart;
|
|
47
|
+
}
|
|
48
|
+
bindEvents(chart, onEvents);
|
|
49
|
+
onChartInitialized === null || onChartInitialized === void 0 ? void 0 : onChartInitialized(chart);
|
|
50
|
+
return () => {
|
|
51
|
+
chart.dispose();
|
|
52
|
+
};
|
|
53
|
+
}, [containerRef, _instance, onChartInitialized, onEvents]);
|
|
54
|
+
// Sync options with chart instance
|
|
55
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
56
|
+
if (echart === undefined)
|
|
57
|
+
return;
|
|
58
|
+
echart.setOption(option);
|
|
59
|
+
}, [echart, option]);
|
|
60
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
61
|
+
const updateSize = (0, debounce_1.default)(() => {
|
|
62
|
+
echart === null || echart === void 0 ? void 0 : echart.resize();
|
|
63
|
+
}, 200);
|
|
64
|
+
window.addEventListener('resize', updateSize);
|
|
65
|
+
updateSize();
|
|
66
|
+
return () => window.removeEventListener('resize', updateSize);
|
|
67
|
+
}, [echart]);
|
|
68
|
+
return (0, jsx_runtime_1.jsx)(material_1.Box, { ref: setContainerRef, sx: sx });
|
|
69
|
+
}
|
|
70
|
+
exports.ECharts = ECharts;
|
|
71
|
+
// Validate event config and bind custom events
|
|
72
|
+
function bindEvents(instance, events) {
|
|
73
|
+
var _a;
|
|
74
|
+
if (events === undefined)
|
|
75
|
+
return;
|
|
76
|
+
function bindEvent(eventName, onEventFunction) {
|
|
77
|
+
if (typeof onEventFunction === 'function') {
|
|
78
|
+
if (isMouseEvent(eventName)) {
|
|
79
|
+
instance.on(eventName, (param) => onEventFunction(param, instance));
|
|
80
|
+
}
|
|
81
|
+
else if (isBatchEvent(eventName)) {
|
|
82
|
+
instance.on(eventName, (param) => onEventFunction(param));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
instance.on(eventName, () => onEventFunction(null, instance));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (const eventName in events) {
|
|
90
|
+
if (Object.prototype.hasOwnProperty.call(events, eventName)) {
|
|
91
|
+
const customEvent = (_a = events[eventName]) !== null && _a !== void 0 ? _a : null;
|
|
92
|
+
if (customEvent) {
|
|
93
|
+
bindEvent(eventName, customEvent);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function isMouseEvent(eventName) {
|
|
99
|
+
return mouseEvents.includes(eventName);
|
|
100
|
+
}
|
|
101
|
+
function isBatchEvent(eventName) {
|
|
102
|
+
return batchEvents.includes(eventName);
|
|
103
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorAlert = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2021 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 material_1 = require("@mui/material");
|
|
18
|
+
/**
|
|
19
|
+
* Shows an MUI Alert with the `Error.message` as its contents.
|
|
20
|
+
*/
|
|
21
|
+
function ErrorAlert(props) {
|
|
22
|
+
const { error } = props;
|
|
23
|
+
return (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message });
|
|
24
|
+
}
|
|
25
|
+
exports.ErrorAlert = ErrorAlert;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ErrorBoundary = void 0;
|
|
16
|
+
// Just use react-error-boundary as-is for now
|
|
17
|
+
var react_error_boundary_1 = require("react-error-boundary");
|
|
18
|
+
Object.defineProperty(exports, "ErrorBoundary", { enumerable: true, get: function () { return react_error_boundary_1.ErrorBoundary; } });
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GaugeChart = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2021 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 core_1 = require("echarts/core");
|
|
19
|
+
const charts_1 = require("echarts/charts");
|
|
20
|
+
const components_1 = require("echarts/components");
|
|
21
|
+
const renderers_1 = require("echarts/renderers");
|
|
22
|
+
const units_1 = require("./model/units");
|
|
23
|
+
const ECharts_1 = require("./ECharts");
|
|
24
|
+
(0, core_1.use)([charts_1.GaugeChart, components_1.GridComponent, components_1.TitleComponent, components_1.TooltipComponent, renderers_1.CanvasRenderer]);
|
|
25
|
+
const noDataOption = {
|
|
26
|
+
title: {
|
|
27
|
+
show: true,
|
|
28
|
+
textStyle: {
|
|
29
|
+
color: 'grey',
|
|
30
|
+
fontSize: 16,
|
|
31
|
+
fontWeight: 400,
|
|
32
|
+
},
|
|
33
|
+
text: 'No data',
|
|
34
|
+
left: 'center',
|
|
35
|
+
top: 'center',
|
|
36
|
+
},
|
|
37
|
+
xAxis: {
|
|
38
|
+
show: false,
|
|
39
|
+
},
|
|
40
|
+
yAxis: {
|
|
41
|
+
show: false,
|
|
42
|
+
},
|
|
43
|
+
series: [],
|
|
44
|
+
};
|
|
45
|
+
function GaugeChart(props) {
|
|
46
|
+
const { width, height, data, unit, axisLine } = props;
|
|
47
|
+
const option = (0, react_1.useMemo)(() => {
|
|
48
|
+
if (data === null || data === undefined)
|
|
49
|
+
return noDataOption;
|
|
50
|
+
const calculatedValue = data;
|
|
51
|
+
return {
|
|
52
|
+
title: {
|
|
53
|
+
show: false,
|
|
54
|
+
},
|
|
55
|
+
tooltip: {
|
|
56
|
+
show: false,
|
|
57
|
+
},
|
|
58
|
+
series: [
|
|
59
|
+
{
|
|
60
|
+
type: 'gauge',
|
|
61
|
+
center: ['50%', '65%'],
|
|
62
|
+
radius: '100%',
|
|
63
|
+
startAngle: 200,
|
|
64
|
+
endAngle: -20,
|
|
65
|
+
min: 0,
|
|
66
|
+
max: 100,
|
|
67
|
+
splitNumber: 12,
|
|
68
|
+
silent: true,
|
|
69
|
+
progress: {
|
|
70
|
+
show: true,
|
|
71
|
+
width: 22,
|
|
72
|
+
itemStyle: {
|
|
73
|
+
color: 'auto',
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
pointer: {
|
|
77
|
+
show: false,
|
|
78
|
+
},
|
|
79
|
+
axisLine: {
|
|
80
|
+
lineStyle: {
|
|
81
|
+
color: [[1, '#e1e5e9']],
|
|
82
|
+
width: 22,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
axisTick: {
|
|
86
|
+
show: false,
|
|
87
|
+
distance: -28,
|
|
88
|
+
splitNumber: 5,
|
|
89
|
+
lineStyle: {
|
|
90
|
+
width: 2,
|
|
91
|
+
color: '#999',
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
splitLine: {
|
|
95
|
+
show: false,
|
|
96
|
+
distance: -32,
|
|
97
|
+
length: 6,
|
|
98
|
+
lineStyle: {
|
|
99
|
+
width: 2,
|
|
100
|
+
color: '#999',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
axisLabel: {
|
|
104
|
+
show: false,
|
|
105
|
+
distance: -18,
|
|
106
|
+
color: '#999',
|
|
107
|
+
fontSize: 12,
|
|
108
|
+
},
|
|
109
|
+
anchor: {
|
|
110
|
+
show: false,
|
|
111
|
+
},
|
|
112
|
+
title: {
|
|
113
|
+
show: false,
|
|
114
|
+
},
|
|
115
|
+
detail: {
|
|
116
|
+
show: false,
|
|
117
|
+
},
|
|
118
|
+
data: [
|
|
119
|
+
{
|
|
120
|
+
value: calculatedValue,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
type: 'gauge',
|
|
126
|
+
center: ['50%', '65%'],
|
|
127
|
+
radius: '114%',
|
|
128
|
+
startAngle: 200,
|
|
129
|
+
endAngle: -20,
|
|
130
|
+
min: 0,
|
|
131
|
+
max: 100,
|
|
132
|
+
pointer: {
|
|
133
|
+
show: false,
|
|
134
|
+
itemStyle: {
|
|
135
|
+
color: 'auto',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
axisLine,
|
|
139
|
+
axisTick: {
|
|
140
|
+
show: false,
|
|
141
|
+
},
|
|
142
|
+
splitLine: {
|
|
143
|
+
show: false,
|
|
144
|
+
},
|
|
145
|
+
axisLabel: {
|
|
146
|
+
show: false,
|
|
147
|
+
},
|
|
148
|
+
detail: {
|
|
149
|
+
show: true,
|
|
150
|
+
valueAnimation: false,
|
|
151
|
+
width: '60%',
|
|
152
|
+
borderRadius: 8,
|
|
153
|
+
offsetCenter: [0, '-9%'],
|
|
154
|
+
fontSize: 20,
|
|
155
|
+
fontWeight: 'bolder',
|
|
156
|
+
color: 'inherit',
|
|
157
|
+
formatter: (value) => {
|
|
158
|
+
return (0, units_1.formatValue)(value, {
|
|
159
|
+
kind: unit.kind,
|
|
160
|
+
decimal_places: 0,
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
data: [
|
|
165
|
+
{
|
|
166
|
+
value: calculatedValue,
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
}, [data, unit, axisLine]);
|
|
173
|
+
return ((0, jsx_runtime_1.jsx)(ECharts_1.ECharts, { sx: {
|
|
174
|
+
width: width,
|
|
175
|
+
height: height,
|
|
176
|
+
}, option: option }));
|
|
177
|
+
}
|
|
178
|
+
exports.GaugeChart = GaugeChart;
|
|
@@ -0,0 +1,227 @@
|
|
|
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 2021 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 material_1 = require("@mui/material");
|
|
22
|
+
const merge_1 = __importDefault(require("lodash/merge"));
|
|
23
|
+
const core_1 = require("echarts/core");
|
|
24
|
+
const charts_1 = require("echarts/charts");
|
|
25
|
+
const components_1 = require("echarts/components");
|
|
26
|
+
const renderers_1 = require("echarts/renderers");
|
|
27
|
+
const ECharts_1 = require("./ECharts");
|
|
28
|
+
const graph_model_1 = require("./model/graph-model");
|
|
29
|
+
const units_1 = require("./model/units");
|
|
30
|
+
const tooltip_model_1 = require("./tooltip/tooltip-model");
|
|
31
|
+
const Tooltip_1 = require("./tooltip/Tooltip");
|
|
32
|
+
(0, core_1.use)([
|
|
33
|
+
charts_1.LineChart,
|
|
34
|
+
components_1.GridComponent,
|
|
35
|
+
components_1.DataZoomComponent,
|
|
36
|
+
components_1.MarkAreaComponent,
|
|
37
|
+
components_1.MarkLineComponent,
|
|
38
|
+
components_1.MarkPointComponent,
|
|
39
|
+
components_1.TitleComponent,
|
|
40
|
+
components_1.ToolboxComponent,
|
|
41
|
+
components_1.TooltipComponent,
|
|
42
|
+
components_1.LegendComponent,
|
|
43
|
+
components_1.VisualMapComponent,
|
|
44
|
+
renderers_1.CanvasRenderer,
|
|
45
|
+
]);
|
|
46
|
+
const noDataOption = {
|
|
47
|
+
title: {
|
|
48
|
+
show: true,
|
|
49
|
+
textStyle: {
|
|
50
|
+
color: 'grey',
|
|
51
|
+
fontSize: 16,
|
|
52
|
+
fontWeight: 400,
|
|
53
|
+
},
|
|
54
|
+
text: 'No data',
|
|
55
|
+
left: 'center',
|
|
56
|
+
top: 'center',
|
|
57
|
+
},
|
|
58
|
+
xAxis: {
|
|
59
|
+
show: false,
|
|
60
|
+
},
|
|
61
|
+
yAxis: {
|
|
62
|
+
show: false,
|
|
63
|
+
},
|
|
64
|
+
series: [],
|
|
65
|
+
};
|
|
66
|
+
function LineChart(props) {
|
|
67
|
+
const { height, data, grid, legend, toolbox, dataZoomEnabled, onDataZoom } = props;
|
|
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, react_1.useMemo)(() => {
|
|
117
|
+
if (data.timeSeries === undefined)
|
|
118
|
+
return {};
|
|
119
|
+
if (data.timeSeries === null || data.timeSeries.length === 0)
|
|
120
|
+
return noDataOption;
|
|
121
|
+
const showPointsOnHover = data.timeSeries.length < graph_model_1.PROGRESSIVE_MODE_SERIES_LIMIT;
|
|
122
|
+
const defaultGrid = {
|
|
123
|
+
show: true,
|
|
124
|
+
backgroundColor: theme.palette.mode === 'dark' ? theme.palette.grey[100] : theme.palette.background.paper,
|
|
125
|
+
borderColor: theme.palette.grey['300'],
|
|
126
|
+
top: 10,
|
|
127
|
+
right: 20,
|
|
128
|
+
bottom: 0,
|
|
129
|
+
left: 20,
|
|
130
|
+
containLabel: true,
|
|
131
|
+
};
|
|
132
|
+
const defaultToolbox = {
|
|
133
|
+
show: true,
|
|
134
|
+
top: 10,
|
|
135
|
+
right: 10,
|
|
136
|
+
iconStyle: {
|
|
137
|
+
borderColor: theme.palette.text.primary,
|
|
138
|
+
},
|
|
139
|
+
feature: {
|
|
140
|
+
dataZoom: {
|
|
141
|
+
icon: dataZoomEnabled ? null : undefined,
|
|
142
|
+
yAxisIndex: 'none',
|
|
143
|
+
},
|
|
144
|
+
restore: {},
|
|
145
|
+
},
|
|
146
|
+
emphasis: {
|
|
147
|
+
iconStyle: {
|
|
148
|
+
textFill: theme.palette.text.primary,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
if (dataZoomEnabled === false) {
|
|
153
|
+
delete defaultToolbox.feature.dataZoom.icon;
|
|
154
|
+
}
|
|
155
|
+
const option = {
|
|
156
|
+
title: {
|
|
157
|
+
show: false,
|
|
158
|
+
},
|
|
159
|
+
grid: (0, merge_1.default)(defaultGrid, grid),
|
|
160
|
+
toolbox: (0, merge_1.default)(defaultToolbox, toolbox),
|
|
161
|
+
series: data.timeSeries,
|
|
162
|
+
xAxis: {
|
|
163
|
+
type: 'category',
|
|
164
|
+
data: data.xAxis,
|
|
165
|
+
axisLabel: {
|
|
166
|
+
color: theme.palette.text.primary,
|
|
167
|
+
margin: 12,
|
|
168
|
+
formatter: (value) => {
|
|
169
|
+
return getFormattedDate(value);
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
axisTick: {
|
|
173
|
+
show: true,
|
|
174
|
+
length: 6,
|
|
175
|
+
},
|
|
176
|
+
axisLine: {
|
|
177
|
+
lineStyle: {
|
|
178
|
+
color: theme.palette.grey['600'],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
yAxis: {
|
|
183
|
+
type: 'value',
|
|
184
|
+
boundaryGap: ['10%', '10%'],
|
|
185
|
+
axisLabel: {
|
|
186
|
+
showMinLabel: false,
|
|
187
|
+
showMaxLabel: true,
|
|
188
|
+
color: theme.palette.text.primary,
|
|
189
|
+
formatter: (value) => {
|
|
190
|
+
return (0, units_1.abbreviateLargeNumber)(value);
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
splitLine: {
|
|
194
|
+
lineStyle: {
|
|
195
|
+
color: theme.palette.grey['300'],
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
animation: false,
|
|
200
|
+
tooltip: {
|
|
201
|
+
show: showPointsOnHover,
|
|
202
|
+
trigger: 'axis',
|
|
203
|
+
showContent: false,
|
|
204
|
+
axisPointer: {
|
|
205
|
+
type: 'none',
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
legend,
|
|
209
|
+
};
|
|
210
|
+
return option;
|
|
211
|
+
}, [data, theme, grid, legend, toolbox, dataZoomEnabled]);
|
|
212
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
213
|
+
height,
|
|
214
|
+
}, 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)(ECharts_1.ECharts, { sx: {
|
|
215
|
+
width: '100%',
|
|
216
|
+
height: '100%',
|
|
217
|
+
}, option: option, onEvents: handleEvents, _instance: chartRef })] }));
|
|
218
|
+
}
|
|
219
|
+
exports.LineChart = LineChart;
|
|
220
|
+
function getFormattedDate(value) {
|
|
221
|
+
const XAXIS_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
|
|
222
|
+
hour: 'numeric',
|
|
223
|
+
minute: 'numeric',
|
|
224
|
+
hour12: false,
|
|
225
|
+
});
|
|
226
|
+
return XAXIS_DATE_FORMAT.format(value * 1000);
|
|
227
|
+
}
|