@perses-dev/components 0.4.0 → 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 +1 -1
- 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.js → LineChart/LineChart.js} +36 -109
- 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 +2 -1
- 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} +7 -1
- 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 -3
- 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/StatChart.js +0 -207
- package/dist/model/graph-model.d.ts.map +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InfoTooltip = exports.TooltipPlacement = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const material_1 = require("@mui/material");
|
|
6
|
+
var TooltipPlacement;
|
|
7
|
+
(function (TooltipPlacement) {
|
|
8
|
+
TooltipPlacement["Top"] = "top";
|
|
9
|
+
TooltipPlacement["Left"] = "left";
|
|
10
|
+
TooltipPlacement["Right"] = "right";
|
|
11
|
+
TooltipPlacement["Bottom"] = "bottom";
|
|
12
|
+
})(TooltipPlacement = exports.TooltipPlacement || (exports.TooltipPlacement = {}));
|
|
13
|
+
const InfoTooltip = ({ id, title, description, placement, children }) => {
|
|
14
|
+
return ((0, jsx_runtime_1.jsx)(StyledTooltip, { arrow: true, id: id, placement: placement, title: (0, jsx_runtime_1.jsx)(TooltipContent, { title: title, description: description }), children: (0, jsx_runtime_1.jsx)("div", { children: children }) }));
|
|
15
|
+
};
|
|
16
|
+
exports.InfoTooltip = InfoTooltip;
|
|
17
|
+
const TooltipContent = ({ title, description }) => {
|
|
18
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [title && ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "body2", sx: (theme) => ({
|
|
19
|
+
color: theme.palette.text.primary,
|
|
20
|
+
fontWeight: theme.typography.fontWeightMedium,
|
|
21
|
+
}), children: title })), (0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "caption", sx: (theme) => ({
|
|
22
|
+
color: theme.palette.text.primary,
|
|
23
|
+
}), children: description })] }));
|
|
24
|
+
};
|
|
25
|
+
const StyledTooltip = (0, material_1.styled)(({ className, ...props }) => ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { ...props, classes: { popper: className } })))(({ theme }) => ({
|
|
26
|
+
[`& .${material_1.tooltipClasses.tooltip}`]: {
|
|
27
|
+
backgroundColor: theme.palette.secondary.main,
|
|
28
|
+
color: theme.palette.grey[900],
|
|
29
|
+
maxWidth: '300px',
|
|
30
|
+
padding: theme.spacing(1),
|
|
31
|
+
boxShadow: theme.shadows[1],
|
|
32
|
+
},
|
|
33
|
+
[`& .${material_1.tooltipClasses.arrow}`]: {
|
|
34
|
+
color: theme.palette.background.paper,
|
|
35
|
+
'&::before': {
|
|
36
|
+
backgroundColor: theme.palette.secondary.main,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}));
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
// Copyright 2022 The Perses Authors
|
|
8
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
// you may not use this file except in compliance with the License.
|
|
10
|
+
// You may obtain a copy of the License at
|
|
11
|
+
//
|
|
12
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
//
|
|
14
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
// See the License for the specific language governing permissions and
|
|
18
|
+
// limitations under the License.
|
|
19
|
+
const react_1 = require("@testing-library/react");
|
|
20
|
+
const user_event_1 = __importDefault(require("@testing-library/user-event"));
|
|
21
|
+
const dom_1 = require("@testing-library/dom");
|
|
22
|
+
const InfoTooltip_1 = require("./InfoTooltip");
|
|
23
|
+
describe('InfoTooltip', () => {
|
|
24
|
+
const title = 'Tooltip Title';
|
|
25
|
+
const description = 'this is a tooltip';
|
|
26
|
+
it('should render title and description', async () => {
|
|
27
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(InfoTooltip_1.InfoTooltip, { title: title, description: description, children: (0, jsx_runtime_1.jsx)("div", { children: "tooltipAnchor" }) }));
|
|
28
|
+
const tooltipAnchor = dom_1.screen.getByText('tooltipAnchor');
|
|
29
|
+
user_event_1.default.hover(tooltipAnchor);
|
|
30
|
+
await dom_1.screen.findByText(title);
|
|
31
|
+
dom_1.screen.findByText(description);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./InfoTooltip"), exports);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.LineChart = void 0;
|
|
7
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
@@ -20,16 +17,17 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
20
17
|
const react_1 = require("react");
|
|
21
18
|
const core_1 = require("@perses-dev/core");
|
|
22
19
|
const material_1 = require("@mui/material");
|
|
23
|
-
const merge_1 = __importDefault(require("lodash/merge"));
|
|
24
20
|
const core_2 = require("echarts/core");
|
|
25
21
|
const charts_1 = require("echarts/charts");
|
|
26
22
|
const components_1 = require("echarts/components");
|
|
27
23
|
const renderers_1 = require("echarts/renderers");
|
|
28
|
-
const EChart_1 = require("
|
|
29
|
-
const
|
|
30
|
-
const units_1 = require("
|
|
31
|
-
const
|
|
32
|
-
const
|
|
24
|
+
const EChart_1 = require("../EChart");
|
|
25
|
+
const graph_1 = require("../model/graph");
|
|
26
|
+
const units_1 = require("../model/units");
|
|
27
|
+
const ChartsThemeProvider_1 = require("../context/ChartsThemeProvider");
|
|
28
|
+
const tooltip_model_1 = require("../Tooltip/tooltip-model");
|
|
29
|
+
const Tooltip_1 = require("../Tooltip/Tooltip");
|
|
30
|
+
const utils_1 = require("./utils");
|
|
33
31
|
(0, core_2.use)([
|
|
34
32
|
charts_1.LineChart,
|
|
35
33
|
components_1.GridComponent,
|
|
@@ -44,32 +42,13 @@ const Tooltip_1 = require("./tooltip/Tooltip");
|
|
|
44
42
|
components_1.VisualMapComponent,
|
|
45
43
|
renderers_1.CanvasRenderer,
|
|
46
44
|
]);
|
|
47
|
-
|
|
48
|
-
|
|
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)();
|
|
45
|
+
function LineChart({ height, data, unit, grid, legend, visualMap, onDataZoom }) {
|
|
46
|
+
const chartsTheme = (0, ChartsThemeProvider_1.useChartsTheme)();
|
|
69
47
|
const chartRef = (0, react_1.useRef)();
|
|
70
48
|
const [showTooltip, setShowTooltip] = (0, react_1.useState)(true);
|
|
71
49
|
const handleEvents = (0, react_1.useMemo)(() => {
|
|
72
50
|
return {
|
|
51
|
+
// TODO: use legendselectchanged event to fix tooltip when legend selected
|
|
73
52
|
datazoom: (params) => {
|
|
74
53
|
var _a, _b;
|
|
75
54
|
if (onDataZoom === undefined || params.batch[0] === undefined)
|
|
@@ -90,14 +69,14 @@ function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEna
|
|
|
90
69
|
},
|
|
91
70
|
};
|
|
92
71
|
}, [data, onDataZoom]);
|
|
93
|
-
if (chartRef.current !== undefined
|
|
94
|
-
|
|
95
|
-
chart.dispatchAction({
|
|
96
|
-
type: 'takeGlobalCursor',
|
|
97
|
-
key: 'dataZoomSelect',
|
|
98
|
-
dataZoomSelectActive: true,
|
|
99
|
-
});
|
|
72
|
+
if (chartRef.current !== undefined) {
|
|
73
|
+
(0, utils_1.enableDataZoom)(chartRef.current);
|
|
100
74
|
}
|
|
75
|
+
const handleOnDoubleClick = () => {
|
|
76
|
+
if (chartRef.current !== undefined) {
|
|
77
|
+
(0, utils_1.restoreChart)(chartRef.current);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
101
80
|
const handleOnMouseDown = (event) => {
|
|
102
81
|
// hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
|
|
103
82
|
if (event.target instanceof HTMLCanvasElement) {
|
|
@@ -114,65 +93,22 @@ function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEna
|
|
|
114
93
|
setShowTooltip(false);
|
|
115
94
|
};
|
|
116
95
|
const option = (0, core_1.useDeepMemo)(() => {
|
|
96
|
+
var _a;
|
|
117
97
|
if (data.timeSeries === undefined)
|
|
118
98
|
return {};
|
|
119
99
|
if (data.timeSeries === null || data.timeSeries.length === 0)
|
|
120
|
-
return noDataOption;
|
|
121
|
-
const showPointsOnHover = data.timeSeries.length <
|
|
122
|
-
const
|
|
123
|
-
top: 10,
|
|
124
|
-
right: 20,
|
|
125
|
-
bottom: 5,
|
|
126
|
-
left: 20,
|
|
127
|
-
containLabel: true,
|
|
128
|
-
};
|
|
129
|
-
const defaultToolbox = {
|
|
130
|
-
show: true,
|
|
131
|
-
top: 10,
|
|
132
|
-
right: 10,
|
|
133
|
-
iconStyle: {
|
|
134
|
-
borderColor: theme.palette.text.primary,
|
|
135
|
-
},
|
|
136
|
-
feature: {
|
|
137
|
-
dataZoom: {
|
|
138
|
-
icon: dataZoomEnabled ? null : undefined,
|
|
139
|
-
yAxisIndex: 'none',
|
|
140
|
-
},
|
|
141
|
-
restore: {},
|
|
142
|
-
},
|
|
143
|
-
emphasis: {
|
|
144
|
-
iconStyle: {
|
|
145
|
-
textFill: theme.palette.text.primary,
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
};
|
|
149
|
-
if (dataZoomEnabled === false) {
|
|
150
|
-
delete defaultToolbox.feature.dataZoom.icon;
|
|
151
|
-
}
|
|
100
|
+
return chartsTheme.noDataOption;
|
|
101
|
+
const showPointsOnHover = data.timeSeries.length < graph_1.PROGRESSIVE_MODE_SERIES_LIMIT;
|
|
102
|
+
const rangeMs = (_a = data.rangeMs) !== null && _a !== void 0 ? _a : (0, utils_1.getDateRange)(data.xAxis);
|
|
152
103
|
const option = {
|
|
153
|
-
title: {
|
|
154
|
-
show: false,
|
|
155
|
-
},
|
|
156
|
-
grid: (0, merge_1.default)(defaultGrid, grid),
|
|
157
|
-
toolbox: (0, merge_1.default)(defaultToolbox, toolbox),
|
|
158
104
|
series: data.timeSeries,
|
|
159
105
|
xAxis: {
|
|
160
106
|
type: 'category',
|
|
161
107
|
data: data.xAxis,
|
|
162
|
-
max:
|
|
108
|
+
max: data.xAxisMax,
|
|
163
109
|
axisLabel: {
|
|
164
|
-
margin: 15,
|
|
165
|
-
color: theme.palette.text.primary,
|
|
166
110
|
formatter: (value) => {
|
|
167
|
-
return getFormattedDate(value);
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
axisTick: {
|
|
171
|
-
show: false,
|
|
172
|
-
},
|
|
173
|
-
axisLine: {
|
|
174
|
-
lineStyle: {
|
|
175
|
-
color: theme.palette.grey['600'],
|
|
111
|
+
return (0, utils_1.getFormattedDate)(value, rangeMs);
|
|
176
112
|
},
|
|
177
113
|
},
|
|
178
114
|
},
|
|
@@ -180,18 +116,8 @@ function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEna
|
|
|
180
116
|
type: 'value',
|
|
181
117
|
boundaryGap: [0, '10%'],
|
|
182
118
|
axisLabel: {
|
|
183
|
-
margin: 12,
|
|
184
|
-
color: theme.palette.text.primary,
|
|
185
119
|
formatter: (value) => {
|
|
186
|
-
return (0, units_1.
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
splitLine: {
|
|
190
|
-
show: true,
|
|
191
|
-
lineStyle: {
|
|
192
|
-
width: 0.5,
|
|
193
|
-
color: theme.palette.grey['300'],
|
|
194
|
-
opacity: 0.95,
|
|
120
|
+
return (0, units_1.formatValue)(value, unit);
|
|
195
121
|
},
|
|
196
122
|
},
|
|
197
123
|
},
|
|
@@ -204,24 +130,25 @@ function LineChart({ height, data, grid, legend, toolbox, visualMap, dataZoomEna
|
|
|
204
130
|
type: 'none',
|
|
205
131
|
},
|
|
206
132
|
},
|
|
133
|
+
toolbox: {
|
|
134
|
+
feature: {
|
|
135
|
+
dataZoom: {
|
|
136
|
+
icon: null,
|
|
137
|
+
yAxisIndex: 'none',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
grid,
|
|
207
142
|
legend,
|
|
208
143
|
visualMap,
|
|
209
144
|
};
|
|
210
145
|
return option;
|
|
211
|
-
}, [data,
|
|
146
|
+
}, [data, grid, legend, visualMap]);
|
|
212
147
|
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
213
148
|
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)(EChart_1.EChart, { sx: {
|
|
149
|
+
}, onDoubleClick: handleOnDoubleClick, 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: {
|
|
215
150
|
width: '100%',
|
|
216
151
|
height: '100%',
|
|
217
|
-
}, option: option, onEvents: handleEvents, _instance: chartRef })] }));
|
|
152
|
+
}, option: option, theme: chartsTheme.themeName, onEvents: handleEvents, _instance: chartRef })] }));
|
|
218
153
|
}
|
|
219
154
|
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
|
-
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./LineChart"), exports);
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 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.getFormattedDate = exports.getDateRange = exports.restoreChart = exports.enableDataZoom = void 0;
|
|
16
|
+
// enable dataZoom without requring user to click toolbox icon
|
|
17
|
+
function enableDataZoom(chart) {
|
|
18
|
+
const chartModel = chart['_model'];
|
|
19
|
+
if (chartModel === undefined)
|
|
20
|
+
return;
|
|
21
|
+
if (chartModel.option.toolbox !== undefined && chartModel.option.toolbox.length > 0) {
|
|
22
|
+
// check if hidden data zoom icon is unselected (if selected it would be 'emphasis' instead of 'normal')
|
|
23
|
+
if (chartModel.option.toolbox[0].feature.dataZoom.iconStatus.zoom === 'normal') {
|
|
24
|
+
chart.dispatchAction({
|
|
25
|
+
type: 'takeGlobalCursor',
|
|
26
|
+
key: 'dataZoomSelect',
|
|
27
|
+
dataZoomSelectActive: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
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
|
+
function restoreChart(chart) {
|
|
36
|
+
chart.dispatchAction({
|
|
37
|
+
type: 'restore', // https://echarts.apache.org/en/api.html#events.restore
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.restoreChart = restoreChart;
|
|
41
|
+
// fallback when xAxis time range not passed as prop
|
|
42
|
+
function getDateRange(data) {
|
|
43
|
+
const defaultRange = 3600000; // hour in ms
|
|
44
|
+
if (data.length === 0)
|
|
45
|
+
return defaultRange;
|
|
46
|
+
const lastDatum = data[data.length - 1];
|
|
47
|
+
if (data[0] === undefined || lastDatum === undefined)
|
|
48
|
+
return defaultRange;
|
|
49
|
+
return lastDatum - data[0];
|
|
50
|
+
}
|
|
51
|
+
exports.getDateRange = getDateRange;
|
|
52
|
+
// determines time granularity for axis labels, defaults to hh:mm
|
|
53
|
+
function getFormattedDate(value, rangeMs) {
|
|
54
|
+
const dateFormatOptions = {
|
|
55
|
+
hour: 'numeric',
|
|
56
|
+
minute: 'numeric',
|
|
57
|
+
hourCycle: 'h23',
|
|
58
|
+
};
|
|
59
|
+
const thirtyMinMs = 1800000;
|
|
60
|
+
const dayMs = 86400000;
|
|
61
|
+
if (rangeMs <= thirtyMinMs) {
|
|
62
|
+
dateFormatOptions.second = 'numeric';
|
|
63
|
+
}
|
|
64
|
+
else if (rangeMs >= dayMs) {
|
|
65
|
+
dateFormatOptions.month = 'numeric';
|
|
66
|
+
dateFormatOptions.day = 'numeric';
|
|
67
|
+
}
|
|
68
|
+
const DATE_FORMAT = new Intl.DateTimeFormat(undefined, dateFormatOptions);
|
|
69
|
+
// remove comma when month / day present
|
|
70
|
+
return DATE_FORMAT.format(value).replace(/, /g, ' ');
|
|
71
|
+
}
|
|
72
|
+
exports.getFormattedDate = getFormattedDate;
|
|
@@ -0,0 +1,104 @@
|
|
|
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 ChartsThemeProvider_1 = require("../context/ChartsThemeProvider");
|
|
26
|
+
const units_1 = require("../model/units");
|
|
27
|
+
const EChart_1 = require("../EChart");
|
|
28
|
+
(0, core_1.use)([
|
|
29
|
+
charts_1.GaugeChart,
|
|
30
|
+
charts_2.LineChart,
|
|
31
|
+
components_1.GridComponent,
|
|
32
|
+
components_1.DatasetComponent,
|
|
33
|
+
components_1.TitleComponent,
|
|
34
|
+
components_1.TooltipComponent,
|
|
35
|
+
renderers_1.CanvasRenderer,
|
|
36
|
+
]);
|
|
37
|
+
const PANEL_PADDING = 32;
|
|
38
|
+
const MIN_VALUE_SIZE = 12;
|
|
39
|
+
const MAX_VALUE_SIZE = 36;
|
|
40
|
+
function StatChart(props) {
|
|
41
|
+
const { width, height, data, unit, sparkline } = props;
|
|
42
|
+
const chartsTheme = (0, ChartsThemeProvider_1.useChartsTheme)();
|
|
43
|
+
const formattedValue = data.calculatedValue === undefined ? 'No data' : (0, units_1.formatValue)(data.calculatedValue, unit);
|
|
44
|
+
const option = (0, react_1.useMemo)(() => {
|
|
45
|
+
if (data.seriesData === undefined)
|
|
46
|
+
return chartsTheme.noDataOption;
|
|
47
|
+
const series = data.seriesData;
|
|
48
|
+
const statSeries = [];
|
|
49
|
+
if (sparkline !== undefined) {
|
|
50
|
+
const lineSeries = {
|
|
51
|
+
type: 'line',
|
|
52
|
+
data: [...series.values],
|
|
53
|
+
zlevel: 1,
|
|
54
|
+
symbol: 'none',
|
|
55
|
+
animation: false,
|
|
56
|
+
silent: true,
|
|
57
|
+
};
|
|
58
|
+
const mergedSeries = (0, lodash_es_1.merge)(lineSeries, sparkline);
|
|
59
|
+
statSeries.push(mergedSeries);
|
|
60
|
+
}
|
|
61
|
+
const option = {
|
|
62
|
+
title: {
|
|
63
|
+
show: false,
|
|
64
|
+
},
|
|
65
|
+
grid: {
|
|
66
|
+
show: false,
|
|
67
|
+
top: '35%',
|
|
68
|
+
right: 0,
|
|
69
|
+
bottom: 0,
|
|
70
|
+
left: 0,
|
|
71
|
+
containLabel: false,
|
|
72
|
+
},
|
|
73
|
+
xAxis: {
|
|
74
|
+
type: 'time',
|
|
75
|
+
show: false,
|
|
76
|
+
boundaryGap: false,
|
|
77
|
+
},
|
|
78
|
+
yAxis: {
|
|
79
|
+
type: 'value',
|
|
80
|
+
show: false,
|
|
81
|
+
},
|
|
82
|
+
tooltip: {
|
|
83
|
+
show: false,
|
|
84
|
+
},
|
|
85
|
+
series: statSeries,
|
|
86
|
+
};
|
|
87
|
+
return option;
|
|
88
|
+
}, [data, chartsTheme, sparkline]);
|
|
89
|
+
const isLargePanel = width > 250 && height > 180;
|
|
90
|
+
// adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
|
|
91
|
+
const charactersAdjust = formattedValue.length;
|
|
92
|
+
const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
|
|
93
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h3", sx: (theme) => ({
|
|
94
|
+
color: theme.palette.text.primary,
|
|
95
|
+
fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
|
|
96
|
+
}), children: formattedValue }), sparkline !== undefined && ((0, jsx_runtime_1.jsx)(EChart_1.EChart, { sx: {
|
|
97
|
+
width: width + PANEL_PADDING,
|
|
98
|
+
height: height,
|
|
99
|
+
position: 'absolute',
|
|
100
|
+
bottom: 0,
|
|
101
|
+
left: 0,
|
|
102
|
+
}, option: option, theme: chartsTheme.themeName, renderer: "svg" }))] }));
|
|
103
|
+
}
|
|
104
|
+
exports.StatChart = StatChart;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const react_1 = require("@testing-library/react");
|
|
5
|
+
const ChartsThemeProvider_1 = require("../context/ChartsThemeProvider");
|
|
6
|
+
const StatChart_1 = require("./StatChart");
|
|
7
|
+
describe('StatChart', () => {
|
|
8
|
+
const contentDimensions = {
|
|
9
|
+
width: 200,
|
|
10
|
+
height: 200,
|
|
11
|
+
};
|
|
12
|
+
const unit = {
|
|
13
|
+
kind: 'Decimal',
|
|
14
|
+
decimal_places: 2,
|
|
15
|
+
};
|
|
16
|
+
const mockStatData = {
|
|
17
|
+
calculatedValue: 7.72931659687181,
|
|
18
|
+
name: 'Example Stat Chart',
|
|
19
|
+
seriesData: {
|
|
20
|
+
name: '(((count(count(node_cpu_seconds_total{job="example"}) by (cpu))',
|
|
21
|
+
values: [
|
|
22
|
+
[1654006170000, 7.736401673473903],
|
|
23
|
+
[1654006185000, 7.733891213538757],
|
|
24
|
+
[1654006200000, 7.731101813010433],
|
|
25
|
+
[1654006215000, 7.722454672079215],
|
|
26
|
+
[1654006230000, 7.722733612256738],
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const exampleChartsTheme = {
|
|
31
|
+
themeName: 'perses',
|
|
32
|
+
echartsTheme: {},
|
|
33
|
+
noDataOption: {},
|
|
34
|
+
sparkline: {
|
|
35
|
+
width: 1,
|
|
36
|
+
color: '#000000',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
describe('Render default options (no sparkline)', () => {
|
|
40
|
+
it('should render', () => {
|
|
41
|
+
(0, react_1.render)((0, jsx_runtime_1.jsx)(ChartsThemeProvider_1.ChartsThemeProvider, { themeName: "perses", chartsTheme: exampleChartsTheme, children: (0, jsx_runtime_1.jsx)(StatChart_1.StatChart, { width: contentDimensions.width, height: contentDimensions.height, data: mockStatData, unit: unit }) }));
|
|
42
|
+
expect(react_1.screen.getByText('7.73')).toBeInTheDocument();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 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
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
__exportStar(require("./StatChart"), exports);
|
|
@@ -42,7 +42,8 @@ function SeriesInfo(props) {
|
|
|
42
42
|
}), children: formattedSeriesLabels.split(',').map((name) => {
|
|
43
43
|
if (name) {
|
|
44
44
|
const [key, value] = jsonFormattedSeries ? name.split(':') : name.split('=');
|
|
45
|
-
|
|
45
|
+
const formattedKey = value !== undefined ? `${key}: ` : key;
|
|
46
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: 'flex', gap: '4px' }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { sx: { fontSize: '11px' }, children: formattedKey }), (0, jsx_runtime_1.jsx)(material_1.Typography, { sx: (theme) => ({
|
|
46
47
|
color: theme.palette.common.white,
|
|
47
48
|
fontWeight: 700,
|
|
48
49
|
fontSize: '11px',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|