@perses-dev/components 0.36.1 → 0.37.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/FontSizeSelector/FontSizeSelector.d.ts +8 -0
- package/dist/FontSizeSelector/FontSizeSelector.d.ts.map +1 -0
- package/dist/FontSizeSelector/FontSizeSelector.js +124 -0
- package/dist/FontSizeSelector/FontSizeSelector.js.map +1 -0
- package/dist/FontSizeSelector/index.d.ts +2 -0
- package/dist/FontSizeSelector/index.d.ts.map +1 -0
- package/dist/FontSizeSelector/index.js +15 -0
- package/dist/FontSizeSelector/index.js.map +1 -0
- package/dist/LineChart/LineChart.d.ts +5 -25
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +6 -6
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/index.d.ts +0 -1
- package/dist/LineChart/index.d.ts.map +1 -1
- package/dist/LineChart/index.js +0 -1
- package/dist/LineChart/index.js.map +1 -1
- package/dist/StatChart/StatChart.d.ts +2 -0
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +7 -5
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/StatChart/calculateFontSize.d.ts +3 -1
- package/dist/StatChart/calculateFontSize.d.ts.map +1 -1
- package/dist/StatChart/calculateFontSize.js +5 -1
- package/dist/StatChart/calculateFontSize.js.map +1 -1
- package/dist/TimeChart/TimeChart.d.ts +23 -0
- package/dist/TimeChart/TimeChart.d.ts.map +1 -0
- package/dist/TimeChart/TimeChart.js +313 -0
- package/dist/TimeChart/TimeChart.js.map +1 -0
- package/dist/TimeChart/index.d.ts +2 -0
- package/dist/TimeChart/index.d.ts.map +1 -0
- package/dist/TimeChart/index.js +15 -0
- package/dist/TimeChart/index.js.map +1 -0
- package/dist/TimeSeriesTooltip/{TimeSeriesTooltip.d.ts → LineChartTooltip.d.ts} +2 -2
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/{TimeSeriesTooltip.js → LineChartTooltip.js} +4 -4
- package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +1 -0
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +16 -0
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +76 -0
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -0
- package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipHeader.js +3 -4
- package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +2 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +2 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +23 -5
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.js +166 -4
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +4 -0
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts +25 -0
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +29 -1
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/cjs/FontSizeSelector/FontSizeSelector.js +130 -0
- package/dist/cjs/FontSizeSelector/index.js +28 -0
- package/dist/cjs/LineChart/LineChart.js +5 -44
- package/dist/cjs/LineChart/index.js +0 -1
- package/dist/cjs/StatChart/StatChart.js +7 -5
- package/dist/cjs/StatChart/calculateFontSize.js +5 -1
- package/dist/cjs/TimeChart/TimeChart.js +319 -0
- package/dist/cjs/TimeChart/index.js +28 -0
- package/dist/cjs/TimeSeriesTooltip/{TimeSeriesTooltip.js → LineChartTooltip.js} +4 -4
- package/dist/cjs/TimeSeriesTooltip/TimeChartTooltip.js +87 -0
- package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +3 -4
- package/dist/cjs/TimeSeriesTooltip/index.js +2 -1
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +162 -4
- package/dist/cjs/TimeSeriesTooltip/utils.js +35 -3
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/utils/axis.js +58 -0
- package/dist/cjs/{LineChart/utils.js → utils/chart-actions.js} +0 -54
- package/dist/cjs/utils/format.js +47 -1
- package/dist/cjs/utils/index.js +3 -1
- package/dist/cjs/utils/theme-gen.js +37 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +19 -2
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/utils/axis.d.ts +14 -0
- package/dist/utils/axis.d.ts.map +1 -0
- package/dist/utils/axis.js +45 -0
- package/dist/utils/axis.js.map +1 -0
- package/dist/utils/chart-actions.d.ts +18 -0
- package/dist/utils/chart-actions.d.ts.map +1 -0
- package/dist/utils/chart-actions.js +52 -0
- package/dist/utils/chart-actions.js.map +1 -0
- package/dist/utils/format.d.ts +6 -0
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +47 -0
- package/dist/utils/format.js.map +1 -1
- package/dist/utils/index.d.ts +3 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/theme-gen.d.ts.map +1 -1
- package/dist/utils/theme-gen.js +37 -0
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +3 -3
- package/dist/LineChart/utils.d.ts +0 -31
- package/dist/LineChart/utils.d.ts.map +0 -1
- package/dist/LineChart/utils.js +0 -103
- package/dist/LineChart/utils.js.map +0 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +0 -1
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TimeChart", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>TimeChart
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = require("react");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _dateFnsTz = require("date-fns-tz");
|
|
25
|
+
const _core = require("@perses-dev/core");
|
|
26
|
+
const _core1 = require("echarts/core");
|
|
27
|
+
const _charts = require("echarts/charts");
|
|
28
|
+
const _components = require("echarts/components");
|
|
29
|
+
const _renderers = require("echarts/renderers");
|
|
30
|
+
const _echart = require("../EChart");
|
|
31
|
+
const _chartsThemeProvider = require("../context/ChartsThemeProvider");
|
|
32
|
+
const _utils = require("../utils");
|
|
33
|
+
const _timeSeriesTooltip = require("../TimeSeriesTooltip");
|
|
34
|
+
const _timeZoneProvider = require("../context/TimeZoneProvider");
|
|
35
|
+
(0, _core1.use)([
|
|
36
|
+
_charts.LineChart,
|
|
37
|
+
_components.GridComponent,
|
|
38
|
+
_components.DatasetComponent,
|
|
39
|
+
_components.DataZoomComponent,
|
|
40
|
+
_components.MarkAreaComponent,
|
|
41
|
+
_components.MarkLineComponent,
|
|
42
|
+
_components.MarkPointComponent,
|
|
43
|
+
_components.TitleComponent,
|
|
44
|
+
_components.ToolboxComponent,
|
|
45
|
+
_components.TooltipComponent,
|
|
46
|
+
_renderers.CanvasRenderer
|
|
47
|
+
]);
|
|
48
|
+
const TimeChart = /*#__PURE__*/ (0, _react.forwardRef)(function TimeChart({ height , data , seriesMapping , timeScale: timeScaleProp , yAxis , unit , grid , tooltipConfig ={
|
|
49
|
+
wrapLabels: true
|
|
50
|
+
} , noDataVariant ='message' , syncGroup , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride , }, ref) {
|
|
51
|
+
var ref1;
|
|
52
|
+
const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
|
|
53
|
+
const chartRef = (0, _react.useRef)();
|
|
54
|
+
const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
|
|
55
|
+
const [tooltipPinnedCoords, setTooltipPinnedCoords] = (0, _react.useState)(null);
|
|
56
|
+
const [isDragging, setIsDragging] = (0, _react.useState)(false);
|
|
57
|
+
const [startX, setStartX] = (0, _react.useState)(0);
|
|
58
|
+
const { timeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
59
|
+
var ref2;
|
|
60
|
+
const totalSeries = (ref2 = data === null || data === void 0 ? void 0 : data.length) !== null && ref2 !== void 0 ? ref2 : 0;
|
|
61
|
+
let timeScale;
|
|
62
|
+
if (timeScaleProp === undefined) {
|
|
63
|
+
const commonTimeScale = (0, _core.getCommonTimeScale)(data);
|
|
64
|
+
if (commonTimeScale === undefined) {
|
|
65
|
+
// set default to past 5 years
|
|
66
|
+
const today = new Date();
|
|
67
|
+
const pastDate = new Date(today);
|
|
68
|
+
pastDate.setFullYear(today.getFullYear() - 5);
|
|
69
|
+
const todayMs = today.getTime();
|
|
70
|
+
const pastDateMs = pastDate.getTime();
|
|
71
|
+
timeScale = {
|
|
72
|
+
startMs: pastDateMs,
|
|
73
|
+
endMs: todayMs,
|
|
74
|
+
stepMs: 1,
|
|
75
|
+
rangeMs: todayMs - pastDateMs
|
|
76
|
+
};
|
|
77
|
+
} else {
|
|
78
|
+
timeScale = commonTimeScale;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
timeScale = timeScaleProp;
|
|
82
|
+
}
|
|
83
|
+
(0, _react.useImperativeHandle)(ref, ()=>{
|
|
84
|
+
return {
|
|
85
|
+
highlightSeries ({ name }) {
|
|
86
|
+
if (!chartRef.current) {
|
|
87
|
+
// when chart undef, do not highlight series when hovering over legend
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
chartRef.current.dispatchAction({
|
|
91
|
+
type: 'highlight',
|
|
92
|
+
seriesId: name
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
clearHighlightedSeries: ()=>{
|
|
96
|
+
if (!chartRef.current) {
|
|
97
|
+
// when chart undef, do not clear highlight series
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
(0, _utils.clearHighlightedSeries)(chartRef.current, totalSeries);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}, [
|
|
104
|
+
totalSeries
|
|
105
|
+
]);
|
|
106
|
+
const handleEvents = (0, _react.useMemo)(()=>{
|
|
107
|
+
return {
|
|
108
|
+
datazoom: (params)=>{
|
|
109
|
+
if (onDataZoom === undefined) {
|
|
110
|
+
setTimeout(()=>{
|
|
111
|
+
// workaround so unpin happens after click event
|
|
112
|
+
setTooltipPinnedCoords(null);
|
|
113
|
+
}, 10);
|
|
114
|
+
}
|
|
115
|
+
if (onDataZoom === undefined || params.batch[0] === undefined) return;
|
|
116
|
+
const xAxisStartValue = params.batch[0].startValue;
|
|
117
|
+
const xAxisEndValue = params.batch[0].endValue;
|
|
118
|
+
if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
|
|
119
|
+
const zoomEvent = {
|
|
120
|
+
start: xAxisStartValue,
|
|
121
|
+
end: xAxisEndValue
|
|
122
|
+
};
|
|
123
|
+
onDataZoom(zoomEvent);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}, [
|
|
128
|
+
onDataZoom,
|
|
129
|
+
setTooltipPinnedCoords
|
|
130
|
+
]);
|
|
131
|
+
if (chartRef.current !== undefined) {
|
|
132
|
+
(0, _utils.enableDataZoom)(chartRef.current);
|
|
133
|
+
}
|
|
134
|
+
const { noDataOption } = chartsTheme;
|
|
135
|
+
const option = (0, _react.useMemo)(()=>{
|
|
136
|
+
// TODO: fix loading state and noData variants
|
|
137
|
+
// if (data === undefined) return {};
|
|
138
|
+
// The "chart" `noDataVariant` is only used when the `timeSeries` is an
|
|
139
|
+
// empty array because a `null` value will throw an error.
|
|
140
|
+
if (data === null || data.length === 0 && noDataVariant === 'message') return noDataOption;
|
|
141
|
+
// Utilizes ECharts dataset so raw data is separate from series option style properties
|
|
142
|
+
// https://apache.github.io/echarts-handbook/en/concepts/dataset/
|
|
143
|
+
const dataset = [];
|
|
144
|
+
const isLocalTimeZone = timeZone === 'local';
|
|
145
|
+
data.map((d, index)=>{
|
|
146
|
+
const values = d.values.map(([timestamp, value])=>{
|
|
147
|
+
const val = value === null ? '-' : value; // echarts use '-' to represent null data
|
|
148
|
+
return [
|
|
149
|
+
isLocalTimeZone ? timestamp : (0, _dateFnsTz.utcToZonedTime)(timestamp, timeZone),
|
|
150
|
+
val
|
|
151
|
+
];
|
|
152
|
+
});
|
|
153
|
+
dataset.push({
|
|
154
|
+
id: index,
|
|
155
|
+
source: [
|
|
156
|
+
...values
|
|
157
|
+
],
|
|
158
|
+
dimensions: [
|
|
159
|
+
'time',
|
|
160
|
+
'value'
|
|
161
|
+
]
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
var _rangeMs;
|
|
165
|
+
const option = {
|
|
166
|
+
dataset: dataset,
|
|
167
|
+
series: seriesMapping,
|
|
168
|
+
xAxis: {
|
|
169
|
+
type: 'time',
|
|
170
|
+
min: isLocalTimeZone ? timeScale.startMs : (0, _dateFnsTz.utcToZonedTime)(timeScale.startMs, timeZone),
|
|
171
|
+
max: isLocalTimeZone ? timeScale.endMs : (0, _dateFnsTz.utcToZonedTime)(timeScale.endMs, timeZone),
|
|
172
|
+
axisLabel: {
|
|
173
|
+
hideOverlap: true,
|
|
174
|
+
formatter: (0, _utils.getFormattedAxisLabel)((_rangeMs = timeScale.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : 0)
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
yAxis: (0, _utils.getYAxes)(yAxis, unit),
|
|
178
|
+
animation: false,
|
|
179
|
+
tooltip: {
|
|
180
|
+
show: true,
|
|
181
|
+
trigger: 'axis',
|
|
182
|
+
showContent: false
|
|
183
|
+
},
|
|
184
|
+
// https://echarts.apache.org/en/option.html#axisPointer
|
|
185
|
+
axisPointer: {
|
|
186
|
+
type: 'line',
|
|
187
|
+
z: 0,
|
|
188
|
+
triggerEmphasis: false,
|
|
189
|
+
triggerTooltip: false,
|
|
190
|
+
snap: true
|
|
191
|
+
},
|
|
192
|
+
toolbox: {
|
|
193
|
+
feature: {
|
|
194
|
+
dataZoom: {
|
|
195
|
+
icon: null,
|
|
196
|
+
yAxisIndex: 'none'
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
grid
|
|
201
|
+
};
|
|
202
|
+
if (__experimentalEChartsOptionsOverride) {
|
|
203
|
+
return __experimentalEChartsOptionsOverride(option);
|
|
204
|
+
}
|
|
205
|
+
return option;
|
|
206
|
+
}, [
|
|
207
|
+
data,
|
|
208
|
+
seriesMapping,
|
|
209
|
+
timeScale,
|
|
210
|
+
yAxis,
|
|
211
|
+
unit,
|
|
212
|
+
grid,
|
|
213
|
+
noDataOption,
|
|
214
|
+
__experimentalEChartsOptionsOverride,
|
|
215
|
+
noDataVariant,
|
|
216
|
+
timeZone
|
|
217
|
+
]);
|
|
218
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
219
|
+
sx: {
|
|
220
|
+
height
|
|
221
|
+
},
|
|
222
|
+
onClick: (e)=>{
|
|
223
|
+
// Pin and unpin when clicking on chart canvas but not tooltip text.
|
|
224
|
+
if (e.target instanceof HTMLCanvasElement) {
|
|
225
|
+
setTooltipPinnedCoords((current)=>{
|
|
226
|
+
if (current === null) {
|
|
227
|
+
return {
|
|
228
|
+
page: {
|
|
229
|
+
x: e.pageX,
|
|
230
|
+
y: e.pageY
|
|
231
|
+
},
|
|
232
|
+
client: {
|
|
233
|
+
x: e.clientX,
|
|
234
|
+
y: e.clientY
|
|
235
|
+
},
|
|
236
|
+
plotCanvas: {
|
|
237
|
+
x: e.nativeEvent.offsetX,
|
|
238
|
+
y: e.nativeEvent.offsetY
|
|
239
|
+
},
|
|
240
|
+
target: e.target
|
|
241
|
+
};
|
|
242
|
+
} else {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
onMouseDown: (e)=>{
|
|
249
|
+
const { clientX } = e;
|
|
250
|
+
setIsDragging(true);
|
|
251
|
+
setStartX(clientX);
|
|
252
|
+
},
|
|
253
|
+
onMouseMove: (e)=>{
|
|
254
|
+
// Allow clicking inside tooltip to copy labels.
|
|
255
|
+
if (!(e.target instanceof HTMLCanvasElement)) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
const { clientX } = e;
|
|
259
|
+
if (isDragging) {
|
|
260
|
+
const deltaX = clientX - startX;
|
|
261
|
+
if (deltaX > 0) {
|
|
262
|
+
// Hide tooltip when user drags to zoom.
|
|
263
|
+
setShowTooltip(false);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
onMouseUp: ()=>{
|
|
268
|
+
setIsDragging(false);
|
|
269
|
+
setStartX(0);
|
|
270
|
+
setShowTooltip(true);
|
|
271
|
+
},
|
|
272
|
+
onMouseLeave: ()=>{
|
|
273
|
+
if (tooltipPinnedCoords === null) {
|
|
274
|
+
setShowTooltip(false);
|
|
275
|
+
}
|
|
276
|
+
if (chartRef.current !== undefined) {
|
|
277
|
+
(0, _utils.clearHighlightedSeries)(chartRef.current, totalSeries);
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
onMouseEnter: ()=>{
|
|
281
|
+
setShowTooltip(true);
|
|
282
|
+
if (chartRef.current !== undefined) {
|
|
283
|
+
(0, _utils.enableDataZoom)(chartRef.current);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
onDoubleClick: (e)=>{
|
|
287
|
+
setTooltipPinnedCoords(null);
|
|
288
|
+
// either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
|
|
289
|
+
if (onDoubleClick === undefined) {
|
|
290
|
+
if (chartRef.current !== undefined) {
|
|
291
|
+
(0, _utils.restoreChart)(chartRef.current);
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
onDoubleClick(e);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
children: [
|
|
298
|
+
showTooltip === true && ((ref1 = option.tooltip) === null || ref1 === void 0 ? void 0 : ref1.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesTooltip.TimeChartTooltip, {
|
|
299
|
+
chartRef: chartRef,
|
|
300
|
+
data: data,
|
|
301
|
+
seriesMapping: seriesMapping,
|
|
302
|
+
wrapLabels: tooltipConfig.wrapLabels,
|
|
303
|
+
pinnedPos: tooltipPinnedCoords,
|
|
304
|
+
unit: unit
|
|
305
|
+
}),
|
|
306
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
|
|
307
|
+
sx: {
|
|
308
|
+
width: '100%',
|
|
309
|
+
height: '100%'
|
|
310
|
+
},
|
|
311
|
+
option: option,
|
|
312
|
+
theme: chartsTheme.echartsTheme,
|
|
313
|
+
onEvents: handleEvents,
|
|
314
|
+
_instance: chartRef,
|
|
315
|
+
syncGroup: syncGroup
|
|
316
|
+
})
|
|
317
|
+
]
|
|
318
|
+
});
|
|
319
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./TimeChart"), 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
|
+
}
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
Object.defineProperty(exports, "
|
|
17
|
+
Object.defineProperty(exports, "LineChartTooltip", {
|
|
18
18
|
enumerable: true,
|
|
19
|
-
get: ()=>
|
|
19
|
+
get: ()=>LineChartTooltip
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _material = require("@mui/material");
|
|
@@ -32,7 +32,7 @@ function _interopRequireDefault(obj) {
|
|
|
32
32
|
default: obj
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const LineChartTooltip = /*#__PURE__*/ (0, _react.memo)(function LineChartTooltip({ chartRef , chartData , wrapLabels , unit , onUnpinClick , pinnedPos }) {
|
|
36
36
|
const [showAllSeries, setShowAllSeries] = (0, _react.useState)(false);
|
|
37
37
|
const mousePos = (0, _tooltipModel.useMousePosition)();
|
|
38
38
|
const { height , width , ref: tooltipRef } = (0, _useResizeObserver.default)();
|
|
@@ -45,7 +45,7 @@ const TimeSeriesTooltip = /*#__PURE__*/ (0, _react.memo)(function TimeSeriesTool
|
|
|
45
45
|
const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : _tooltipModel.FALLBACK_CHART_WIDTH; // Fallback width not likely to ever be needed.
|
|
46
46
|
const cursorTransform = (0, _utils.assembleTransform)(mousePos, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
|
|
47
47
|
// Get series nearby the cursor and pass into tooltip content children.
|
|
48
|
-
const nearbySeries = (0, _nearbySeries.
|
|
48
|
+
const nearbySeries = (0, _nearbySeries.legacyGetNearbySeriesData)({
|
|
49
49
|
mousePos,
|
|
50
50
|
chartData,
|
|
51
51
|
pinnedPos,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TimeChartTooltip", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>TimeChartTooltip
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = require("react");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _useResizeObserver = /*#__PURE__*/ _interopRequireDefault(require("use-resize-observer"));
|
|
25
|
+
const _tooltipModel = require("./tooltip-model");
|
|
26
|
+
const _utils = require("./utils");
|
|
27
|
+
const _nearbySeries = require("./nearby-series");
|
|
28
|
+
const _tooltipHeader = require("./TooltipHeader");
|
|
29
|
+
const _tooltipContent = require("./TooltipContent");
|
|
30
|
+
function _interopRequireDefault(obj) {
|
|
31
|
+
return obj && obj.__esModule ? obj : {
|
|
32
|
+
default: obj
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const TimeChartTooltip = /*#__PURE__*/ (0, _react.memo)(function TimeChartTooltip({ chartRef , data , seriesMapping , wrapLabels , unit , onUnpinClick , pinnedPos }) {
|
|
36
|
+
const [showAllSeries, setShowAllSeries] = (0, _react.useState)(false);
|
|
37
|
+
const mousePos = (0, _tooltipModel.useMousePosition)();
|
|
38
|
+
const { height , width , ref: tooltipRef } = (0, _useResizeObserver.default)();
|
|
39
|
+
const isTooltipPinned = pinnedPos !== null;
|
|
40
|
+
if (mousePos === null || mousePos.target === null || data === null) return null;
|
|
41
|
+
// Ensure user is hovering over a chart before checking for nearby series.
|
|
42
|
+
if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
|
|
43
|
+
const chart = chartRef.current;
|
|
44
|
+
var ref;
|
|
45
|
+
const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : _tooltipModel.FALLBACK_CHART_WIDTH; // Fallback width not likely to ever be needed.
|
|
46
|
+
const cursorTransform = (0, _utils.assembleTransform)(mousePos, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
|
|
47
|
+
// Get series nearby the cursor and pass into tooltip content children.
|
|
48
|
+
const nearbySeries = (0, _nearbySeries.getNearbySeriesData)({
|
|
49
|
+
mousePos,
|
|
50
|
+
data,
|
|
51
|
+
seriesMapping,
|
|
52
|
+
pinnedPos,
|
|
53
|
+
chart,
|
|
54
|
+
unit,
|
|
55
|
+
showAllSeries
|
|
56
|
+
});
|
|
57
|
+
if (nearbySeries.length === 0) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
const totalSeries = data.length;
|
|
61
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Portal, {
|
|
62
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
63
|
+
ref: tooltipRef,
|
|
64
|
+
sx: (theme)=>(0, _utils.getTooltipStyles)(theme, pinnedPos),
|
|
65
|
+
style: {
|
|
66
|
+
transform: cursorTransform
|
|
67
|
+
},
|
|
68
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
69
|
+
spacing: 0.5,
|
|
70
|
+
children: [
|
|
71
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipHeader.TooltipHeader, {
|
|
72
|
+
nearbySeries: nearbySeries,
|
|
73
|
+
totalSeries: totalSeries,
|
|
74
|
+
isTooltipPinned: isTooltipPinned,
|
|
75
|
+
showAllSeries: showAllSeries,
|
|
76
|
+
onShowAllClick: (checked)=>setShowAllSeries(checked),
|
|
77
|
+
onUnpinClick: onUnpinClick
|
|
78
|
+
}),
|
|
79
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipContent.TooltipContent, {
|
|
80
|
+
series: nearbySeries,
|
|
81
|
+
wrapLabels: wrapLabels
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -23,7 +23,7 @@ const _material = require("@mui/material");
|
|
|
23
23
|
const _pin = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pin"));
|
|
24
24
|
const _pinOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOutline"));
|
|
25
25
|
const _react = require("react");
|
|
26
|
-
const
|
|
26
|
+
const _dateFns = require("date-fns");
|
|
27
27
|
const _tooltipModel = require("./tooltip-model");
|
|
28
28
|
function _interopRequireDefault(obj) {
|
|
29
29
|
return obj && obj.__esModule ? obj : {
|
|
@@ -32,7 +32,6 @@ function _interopRequireDefault(obj) {
|
|
|
32
32
|
}
|
|
33
33
|
const TooltipHeader = /*#__PURE__*/ (0, _react.memo)(function TooltipHeader({ nearbySeries , totalSeries , isTooltipPinned , showAllSeries , onShowAllClick , onUnpinClick }) {
|
|
34
34
|
var ref;
|
|
35
|
-
const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
|
|
36
35
|
var ref1;
|
|
37
36
|
const seriesTimeMs = (ref1 = (ref = nearbySeries[0]) === null || ref === void 0 ? void 0 : ref.date) !== null && ref1 !== void 0 ? ref1 : null;
|
|
38
37
|
if (seriesTimeMs === null) {
|
|
@@ -40,8 +39,8 @@ const TooltipHeader = /*#__PURE__*/ (0, _react.memo)(function TooltipHeader({ ne
|
|
|
40
39
|
}
|
|
41
40
|
const formatTimeSeriesHeader = (timeMs)=>{
|
|
42
41
|
const date = new Date(timeMs);
|
|
43
|
-
const formattedDate =
|
|
44
|
-
const formattedTime =
|
|
42
|
+
const formattedDate = (0, _dateFns.format)(date, 'MMM dd, yyyy - ');
|
|
43
|
+
const formattedTime = (0, _dateFns.format)(date, 'HH:mm:ss');
|
|
45
44
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
46
45
|
children: [
|
|
47
46
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
|
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_exportStar(require("./
|
|
17
|
+
_exportStar(require("./LineChartTooltip"), exports);
|
|
18
18
|
_exportStar(require("./SeriesInfo"), exports);
|
|
19
19
|
_exportStar(require("./SeriesLabelsStack"), exports);
|
|
20
20
|
_exportStar(require("./SeriesMarker"), exports);
|
|
21
|
+
_exportStar(require("./TimeChartTooltip"), exports);
|
|
21
22
|
_exportStar(require("./TooltipContent"), exports);
|
|
22
23
|
_exportStar(require("./TooltipHeader"), exports);
|
|
23
24
|
_exportStar(require("./nearby-series"), exports);
|