@perses-dev/components 0.51.0-rc.0 → 0.51.0-rc.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/README.md +1 -8
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +13 -4
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +0 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +0 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/cjs/EChart/EChart.js +11 -2
- package/dist/cjs/TimeSeriesTooltip/index.js +0 -1
- package/dist/cjs/context/ChartsProvider.js +3 -1
- package/dist/cjs/index.js +0 -7
- package/dist/cjs/test-utils/theme.js +1 -0
- package/dist/cjs/utils/axis.js +3 -18
- package/dist/cjs/utils/format.js +0 -21
- package/dist/context/ChartsProvider.d.ts +2 -0
- package/dist/context/ChartsProvider.d.ts.map +1 -1
- package/dist/context/ChartsProvider.js +3 -1
- package/dist/context/ChartsProvider.js.map +1 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -7
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +0 -1
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/test-utils/theme.d.ts.map +1 -1
- package/dist/test-utils/theme.js +1 -0
- package/dist/test-utils/theme.js.map +1 -1
- package/dist/utils/axis.d.ts +0 -4
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +0 -9
- package/dist/utils/axis.js.map +1 -1
- package/dist/utils/chart-actions.d.ts +0 -2
- package/dist/utils/chart-actions.d.ts.map +1 -1
- package/dist/utils/chart-actions.js.map +1 -1
- package/dist/utils/format.d.ts +0 -1
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +0 -20
- package/dist/utils/format.js.map +1 -1
- package/package.json +2 -7
- package/dist/BarChart/BarChart.d.ts +0 -16
- package/dist/BarChart/BarChart.d.ts.map +0 -1
- package/dist/BarChart/BarChart.js +0 -134
- package/dist/BarChart/BarChart.js.map +0 -1
- package/dist/BarChart/index.d.ts +0 -2
- package/dist/BarChart/index.d.ts.map +0 -1
- package/dist/BarChart/index.js +0 -15
- package/dist/BarChart/index.js.map +0 -1
- package/dist/GaugeChart/GaugeChart.d.ts +0 -23
- package/dist/GaugeChart/GaugeChart.d.ts.map +0 -1
- package/dist/GaugeChart/GaugeChart.js +0 -214
- package/dist/GaugeChart/GaugeChart.js.map +0 -1
- package/dist/GaugeChart/index.d.ts +0 -2
- package/dist/GaugeChart/index.d.ts.map +0 -1
- package/dist/GaugeChart/index.js +0 -15
- package/dist/GaugeChart/index.js.map +0 -1
- package/dist/LineChart/LineChart.d.ts +0 -22
- package/dist/LineChart/LineChart.d.ts.map +0 -1
- package/dist/LineChart/LineChart.js +0 -266
- package/dist/LineChart/LineChart.js.map +0 -1
- package/dist/LineChart/index.d.ts +0 -2
- package/dist/LineChart/index.d.ts.map +0 -1
- package/dist/LineChart/index.js +0 -15
- package/dist/LineChart/index.js.map +0 -1
- package/dist/PieChart/PieChart.d.ts +0 -14
- package/dist/PieChart/PieChart.d.ts.map +0 -1
- package/dist/PieChart/PieChart.js +0 -92
- package/dist/PieChart/PieChart.js.map +0 -1
- package/dist/PieChart/index.d.ts +0 -2
- package/dist/PieChart/index.d.ts.map +0 -1
- package/dist/PieChart/index.js +0 -15
- package/dist/PieChart/index.js.map +0 -1
- package/dist/StatChart/StatChart.d.ts +0 -21
- package/dist/StatChart/StatChart.d.ts.map +0 -1
- package/dist/StatChart/StatChart.js +0 -189
- package/dist/StatChart/StatChart.js.map +0 -1
- package/dist/StatChart/calculateFontSize.d.ts +0 -16
- package/dist/StatChart/calculateFontSize.d.ts.map +0 -1
- package/dist/StatChart/calculateFontSize.js +0 -49
- package/dist/StatChart/calculateFontSize.js.map +0 -1
- package/dist/StatChart/index.d.ts +0 -2
- package/dist/StatChart/index.d.ts.map +0 -1
- package/dist/StatChart/index.js +0 -15
- package/dist/StatChart/index.js.map +0 -1
- package/dist/StatChart/utils/formatStatChartValue.d.ts +0 -3
- package/dist/StatChart/utils/formatStatChartValue.d.ts.map +0 -1
- package/dist/StatChart/utils/formatStatChartValue.js +0 -26
- package/dist/StatChart/utils/formatStatChartValue.js.map +0 -1
- package/dist/StatusHistoryChart/StatusHistoryChart.d.ts +0 -27
- package/dist/StatusHistoryChart/StatusHistoryChart.d.ts.map +0 -1
- package/dist/StatusHistoryChart/StatusHistoryChart.js +0 -132
- package/dist/StatusHistoryChart/StatusHistoryChart.js.map +0 -1
- package/dist/StatusHistoryChart/StatusHistoryTooltip.d.ts +0 -13
- package/dist/StatusHistoryChart/StatusHistoryTooltip.d.ts.map +0 -1
- package/dist/StatusHistoryChart/StatusHistoryTooltip.js +0 -47
- package/dist/StatusHistoryChart/StatusHistoryTooltip.js.map +0 -1
- package/dist/StatusHistoryChart/get-formatted-axis-label.d.ts +0 -2
- package/dist/StatusHistoryChart/get-formatted-axis-label.d.ts.map +0 -1
- package/dist/StatusHistoryChart/get-formatted-axis-label.js +0 -41
- package/dist/StatusHistoryChart/get-formatted-axis-label.js.map +0 -1
- package/dist/StatusHistoryChart/index.d.ts +0 -3
- package/dist/StatusHistoryChart/index.d.ts.map +0 -1
- package/dist/StatusHistoryChart/index.js +0 -16
- package/dist/StatusHistoryChart/index.js.map +0 -1
- package/dist/StatusHistoryChart/utils/get-color.d.ts +0 -6
- package/dist/StatusHistoryChart/utils/get-color.d.ts.map +0 -1
- package/dist/StatusHistoryChart/utils/get-color.js +0 -100
- package/dist/StatusHistoryChart/utils/get-color.js.map +0 -1
- package/dist/StatusHistoryChart/utils/get-tooltip-position.d.ts +0 -3
- package/dist/StatusHistoryChart/utils/get-tooltip-position.d.ts.map +0 -1
- package/dist/StatusHistoryChart/utils/get-tooltip-position.js +0 -27
- package/dist/StatusHistoryChart/utils/get-tooltip-position.js.map +0 -1
- package/dist/TimeChart/TimeChart.d.ts +0 -24
- package/dist/TimeChart/TimeChart.d.ts.map +0 -1
- package/dist/TimeChart/TimeChart.js +0 -394
- package/dist/TimeChart/TimeChart.js.map +0 -1
- package/dist/TimeChart/index.d.ts +0 -2
- package/dist/TimeChart/index.d.ts.map +0 -1
- package/dist/TimeChart/index.js +0 -15
- package/dist/TimeChart/index.js.map +0 -1
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts +0 -21
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/LineChartTooltip.js +0 -101
- package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +0 -1
- package/dist/cjs/BarChart/BarChart.js +0 -142
- package/dist/cjs/BarChart/index.js +0 -30
- package/dist/cjs/GaugeChart/GaugeChart.js +0 -227
- package/dist/cjs/GaugeChart/index.js +0 -30
- package/dist/cjs/LineChart/LineChart.js +0 -274
- package/dist/cjs/LineChart/index.js +0 -30
- package/dist/cjs/PieChart/PieChart.js +0 -100
- package/dist/cjs/PieChart/index.js +0 -30
- package/dist/cjs/StatChart/StatChart.js +0 -202
- package/dist/cjs/StatChart/calculateFontSize.js +0 -55
- package/dist/cjs/StatChart/index.js +0 -30
- package/dist/cjs/StatChart/utils/formatStatChartValue.js +0 -34
- package/dist/cjs/StatusHistoryChart/StatusHistoryChart.js +0 -140
- package/dist/cjs/StatusHistoryChart/StatusHistoryTooltip.js +0 -55
- package/dist/cjs/StatusHistoryChart/get-formatted-axis-label.js +0 -48
- package/dist/cjs/StatusHistoryChart/index.js +0 -31
- package/dist/cjs/StatusHistoryChart/utils/get-color.js +0 -125
- package/dist/cjs/StatusHistoryChart/utils/get-tooltip-position.js +0 -35
- package/dist/cjs/TimeChart/TimeChart.js +0 -407
- package/dist/cjs/TimeChart/index.js +0 -30
- package/dist/cjs/TimeSeriesTooltip/LineChartTooltip.js +0 -114
|
@@ -1,394 +0,0 @@
|
|
|
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
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
15
|
-
import { Box } from '@mui/material';
|
|
16
|
-
import merge from 'lodash/merge';
|
|
17
|
-
import isEqual from 'lodash/isEqual';
|
|
18
|
-
import { toZonedTime } from 'date-fns-tz';
|
|
19
|
-
import { getCommonTimeScale } from '@perses-dev/core';
|
|
20
|
-
import { use } from 'echarts/core';
|
|
21
|
-
import { LineChart as EChartsLineChart, BarChart as EChartsBarChart } from 'echarts/charts';
|
|
22
|
-
import { GridComponent, DatasetComponent, DataZoomComponent, MarkAreaComponent, MarkLineComponent, MarkPointComponent, TitleComponent, ToolboxComponent, TooltipComponent } from 'echarts/components';
|
|
23
|
-
import { CanvasRenderer } from 'echarts/renderers';
|
|
24
|
-
import { EChart } from '../EChart';
|
|
25
|
-
import { DEFAULT_PINNED_CROSSHAIR } from '../model';
|
|
26
|
-
import { useChartsContext } from '../context/ChartsProvider';
|
|
27
|
-
import { clearHighlightedSeries, enableDataZoom, getClosestTimestamp, getFormattedAxisLabel, getPointInGrid, getFormattedAxis, restoreChart } from '../utils';
|
|
28
|
-
import { TimeChartTooltip, DEFAULT_TOOLTIP_CONFIG } from '../TimeSeriesTooltip';
|
|
29
|
-
import { useTimeZone } from '../context/TimeZoneProvider';
|
|
30
|
-
use([
|
|
31
|
-
EChartsLineChart,
|
|
32
|
-
EChartsBarChart,
|
|
33
|
-
GridComponent,
|
|
34
|
-
DatasetComponent,
|
|
35
|
-
DataZoomComponent,
|
|
36
|
-
MarkAreaComponent,
|
|
37
|
-
MarkLineComponent,
|
|
38
|
-
MarkPointComponent,
|
|
39
|
-
TitleComponent,
|
|
40
|
-
ToolboxComponent,
|
|
41
|
-
TooltipComponent,
|
|
42
|
-
CanvasRenderer
|
|
43
|
-
]);
|
|
44
|
-
export const TimeChart = /*#__PURE__*/ forwardRef(function TimeChart({ height, data, seriesMapping, timeScale: timeScaleProp, yAxis, format, grid, isStackedBar = false, tooltipConfig = DEFAULT_TOOLTIP_CONFIG, noDataVariant = 'message', syncGroup, onDataZoom, onDoubleClick, __experimentalEChartsOptionsOverride }, ref) {
|
|
45
|
-
const { chartsTheme, enablePinning, lastTooltipPinnedCoords, setLastTooltipPinnedCoords } = useChartsContext();
|
|
46
|
-
const isPinningEnabled = tooltipConfig.enablePinning && enablePinning;
|
|
47
|
-
const chartRef = useRef();
|
|
48
|
-
const [showTooltip, setShowTooltip] = useState(true);
|
|
49
|
-
const [tooltipPinnedCoords, setTooltipPinnedCoords] = useState(null);
|
|
50
|
-
const [pinnedCrosshair, setPinnedCrosshair] = useState(null);
|
|
51
|
-
const [isDragging, setIsDragging] = useState(false);
|
|
52
|
-
const [startX, setStartX] = useState(0);
|
|
53
|
-
const { timeZone } = useTimeZone();
|
|
54
|
-
let timeScale;
|
|
55
|
-
if (timeScaleProp === undefined) {
|
|
56
|
-
const commonTimeScale = getCommonTimeScale(data);
|
|
57
|
-
if (commonTimeScale === undefined) {
|
|
58
|
-
// set default to past 5 years
|
|
59
|
-
const today = new Date();
|
|
60
|
-
const pastDate = new Date(today);
|
|
61
|
-
pastDate.setFullYear(today.getFullYear() - 5);
|
|
62
|
-
const todayMs = today.getTime();
|
|
63
|
-
const pastDateMs = pastDate.getTime();
|
|
64
|
-
timeScale = {
|
|
65
|
-
startMs: pastDateMs,
|
|
66
|
-
endMs: todayMs,
|
|
67
|
-
stepMs: 1,
|
|
68
|
-
rangeMs: todayMs - pastDateMs
|
|
69
|
-
};
|
|
70
|
-
} else {
|
|
71
|
-
timeScale = commonTimeScale;
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
timeScale = timeScaleProp;
|
|
75
|
-
}
|
|
76
|
-
useImperativeHandle(ref, ()=>{
|
|
77
|
-
return {
|
|
78
|
-
highlightSeries ({ name }) {
|
|
79
|
-
if (!chartRef.current) {
|
|
80
|
-
// when chart undef, do not highlight series when hovering over legend
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
chartRef.current.dispatchAction({
|
|
84
|
-
type: 'highlight',
|
|
85
|
-
seriesId: name
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
clearHighlightedSeries: ()=>{
|
|
89
|
-
if (!chartRef.current) {
|
|
90
|
-
// when chart undef, do not clear highlight series
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
clearHighlightedSeries(chartRef.current);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}, []);
|
|
97
|
-
const handleEvents = useMemo(()=>{
|
|
98
|
-
return {
|
|
99
|
-
datazoom: (params)=>{
|
|
100
|
-
if (onDataZoom === undefined) {
|
|
101
|
-
setTimeout(()=>{
|
|
102
|
-
// workaround so unpin happens after click event
|
|
103
|
-
setTooltipPinnedCoords(null);
|
|
104
|
-
}, 10);
|
|
105
|
-
}
|
|
106
|
-
if (onDataZoom === undefined || params.batch[0] === undefined) return;
|
|
107
|
-
const xAxisStartValue = params.batch[0].startValue;
|
|
108
|
-
const xAxisEndValue = params.batch[0].endValue;
|
|
109
|
-
if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
|
|
110
|
-
const zoomEvent = {
|
|
111
|
-
start: xAxisStartValue,
|
|
112
|
-
end: xAxisEndValue
|
|
113
|
-
};
|
|
114
|
-
onDataZoom(zoomEvent);
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
finished: ()=>{
|
|
118
|
-
if (chartRef.current !== undefined) {
|
|
119
|
-
enableDataZoom(chartRef.current);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}, [
|
|
124
|
-
onDataZoom,
|
|
125
|
-
setTooltipPinnedCoords
|
|
126
|
-
]);
|
|
127
|
-
const { noDataOption } = chartsTheme;
|
|
128
|
-
const option = useMemo(()=>{
|
|
129
|
-
// The "chart" `noDataVariant` is only used when the `timeSeries` is an
|
|
130
|
-
// empty array because a `null` value will throw an error.
|
|
131
|
-
if (data === null || data.length === 0 && noDataVariant === 'message') return noDataOption;
|
|
132
|
-
// Utilizes ECharts dataset so raw data is separate from series option style properties
|
|
133
|
-
// https://apache.github.io/echarts-handbook/en/concepts/dataset/
|
|
134
|
-
const dataset = [];
|
|
135
|
-
const isLocalTimeZone = timeZone === 'local';
|
|
136
|
-
data.map((d, index)=>{
|
|
137
|
-
const values = d.values.map(([timestamp, value])=>{
|
|
138
|
-
const val = value === null ? '-' : value; // echarts use '-' to represent null data
|
|
139
|
-
return [
|
|
140
|
-
isLocalTimeZone ? timestamp : toZonedTime(timestamp, timeZone),
|
|
141
|
-
val
|
|
142
|
-
];
|
|
143
|
-
});
|
|
144
|
-
dataset.push({
|
|
145
|
-
id: index,
|
|
146
|
-
source: [
|
|
147
|
-
...values
|
|
148
|
-
],
|
|
149
|
-
dimensions: [
|
|
150
|
-
'time',
|
|
151
|
-
'value'
|
|
152
|
-
]
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
const updatedSeriesMapping = enablePinning && pinnedCrosshair !== null ? [
|
|
156
|
-
...seriesMapping,
|
|
157
|
-
pinnedCrosshair
|
|
158
|
-
] : seriesMapping;
|
|
159
|
-
const option = {
|
|
160
|
-
dataset: dataset,
|
|
161
|
-
series: updatedSeriesMapping,
|
|
162
|
-
xAxis: {
|
|
163
|
-
type: 'time',
|
|
164
|
-
min: isLocalTimeZone ? timeScale.startMs : toZonedTime(timeScale.startMs, timeZone),
|
|
165
|
-
max: isLocalTimeZone ? timeScale.endMs : toZonedTime(timeScale.endMs, timeZone),
|
|
166
|
-
axisLabel: {
|
|
167
|
-
hideOverlap: true,
|
|
168
|
-
formatter: getFormattedAxisLabel(timeScale.rangeMs ?? 0)
|
|
169
|
-
},
|
|
170
|
-
axisPointer: {
|
|
171
|
-
snap: false
|
|
172
|
-
}
|
|
173
|
-
},
|
|
174
|
-
yAxis: getFormattedAxis(yAxis, format),
|
|
175
|
-
animation: false,
|
|
176
|
-
tooltip: {
|
|
177
|
-
show: true,
|
|
178
|
-
// ECharts tooltip content hidden by default since we use custom tooltip instead.
|
|
179
|
-
// Stacked bar uses ECharts tooltip so subgroup data shows correctly.
|
|
180
|
-
showContent: isStackedBar,
|
|
181
|
-
trigger: isStackedBar ? 'item' : 'axis',
|
|
182
|
-
appendToBody: isStackedBar
|
|
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: false
|
|
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
|
-
format,
|
|
212
|
-
grid,
|
|
213
|
-
noDataOption,
|
|
214
|
-
__experimentalEChartsOptionsOverride,
|
|
215
|
-
noDataVariant,
|
|
216
|
-
timeZone,
|
|
217
|
-
isStackedBar,
|
|
218
|
-
enablePinning,
|
|
219
|
-
pinnedCrosshair
|
|
220
|
-
]);
|
|
221
|
-
// Update adjacent charts so tooltip is unpinned when current chart is clicked.
|
|
222
|
-
useEffect(()=>{
|
|
223
|
-
// Only allow pinning one tooltip at a time, subsequent tooltip click unpins previous.
|
|
224
|
-
// Multiple tooltips can only be pinned if Ctrl or Cmd key is pressed while clicking.
|
|
225
|
-
const multipleTooltipsPinned = tooltipPinnedCoords !== null && lastTooltipPinnedCoords !== null;
|
|
226
|
-
if (multipleTooltipsPinned) {
|
|
227
|
-
if (!isEqual(lastTooltipPinnedCoords, tooltipPinnedCoords)) {
|
|
228
|
-
setTooltipPinnedCoords(null);
|
|
229
|
-
if (tooltipPinnedCoords !== null && pinnedCrosshair !== null) {
|
|
230
|
-
setPinnedCrosshair(null);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
// tooltipPinnedCoords CANNOT be in dep array or tooltip pinning breaks in the current chart's onClick
|
|
235
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
236
|
-
}, [
|
|
237
|
-
lastTooltipPinnedCoords,
|
|
238
|
-
seriesMapping
|
|
239
|
-
]);
|
|
240
|
-
return /*#__PURE__*/ _jsxs(Box, {
|
|
241
|
-
style: {
|
|
242
|
-
height
|
|
243
|
-
},
|
|
244
|
-
// onContextMenu={(e) => {
|
|
245
|
-
// // TODO: confirm tooltip pinning works correctly on Windows, should e.preventDefault() be added here
|
|
246
|
-
// e.preventDefault(); // Prevent the default behaviour when right clicked
|
|
247
|
-
// }}
|
|
248
|
-
onClick: (e)=>{
|
|
249
|
-
// Allows user to opt-in to multi tooltip pinning when Ctrl or Cmd key held down
|
|
250
|
-
const isControlKeyPressed = e.ctrlKey || e.metaKey;
|
|
251
|
-
if (isControlKeyPressed) {
|
|
252
|
-
e.preventDefault();
|
|
253
|
-
}
|
|
254
|
-
// Determine where on chart canvas to plot pinned crosshair as markLine.
|
|
255
|
-
const pointInGrid = getPointInGrid(e.nativeEvent.offsetX, e.nativeEvent.offsetY, chartRef.current);
|
|
256
|
-
if (pointInGrid === null) {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
// Pin and unpin when clicking on chart canvas but not tooltip text.
|
|
260
|
-
if (isPinningEnabled && e.target instanceof HTMLCanvasElement) {
|
|
261
|
-
// Pin tooltip and update shared charts context to remember these coordinates.
|
|
262
|
-
const pinnedPos = {
|
|
263
|
-
page: {
|
|
264
|
-
x: e.pageX,
|
|
265
|
-
y: e.pageY
|
|
266
|
-
},
|
|
267
|
-
client: {
|
|
268
|
-
x: e.clientX,
|
|
269
|
-
y: e.clientY
|
|
270
|
-
},
|
|
271
|
-
plotCanvas: {
|
|
272
|
-
x: e.nativeEvent.offsetX,
|
|
273
|
-
y: e.nativeEvent.offsetY
|
|
274
|
-
},
|
|
275
|
-
target: e.target
|
|
276
|
-
};
|
|
277
|
-
setTooltipPinnedCoords((current)=>{
|
|
278
|
-
if (current === null) {
|
|
279
|
-
return pinnedPos;
|
|
280
|
-
} else {
|
|
281
|
-
setPinnedCrosshair(null);
|
|
282
|
-
return null;
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
setPinnedCrosshair((current)=>{
|
|
286
|
-
// Only add pinned crosshair line series when there is not one already in seriesMapping.
|
|
287
|
-
if (current === null) {
|
|
288
|
-
const cursorX = pointInGrid[0];
|
|
289
|
-
// Only need to loop through first dataset source since getCommonTimeScale ensures xAxis timestamps are consistent
|
|
290
|
-
const firstTimeSeriesValues = data[0]?.values;
|
|
291
|
-
const closestTimestamp = getClosestTimestamp(firstTimeSeriesValues, cursorX);
|
|
292
|
-
// Crosshair snaps to nearest timestamp since cursor may be slightly to left or right
|
|
293
|
-
const pinnedCrosshair = merge({}, DEFAULT_PINNED_CROSSHAIR, {
|
|
294
|
-
markLine: {
|
|
295
|
-
data: [
|
|
296
|
-
{
|
|
297
|
-
xAxis: closestTimestamp
|
|
298
|
-
}
|
|
299
|
-
]
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
return pinnedCrosshair;
|
|
303
|
-
} else {
|
|
304
|
-
// Clear previously set pinned crosshair
|
|
305
|
-
return null;
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
if (!isControlKeyPressed) {
|
|
309
|
-
setLastTooltipPinnedCoords(pinnedPos);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
onMouseDown: (e)=>{
|
|
314
|
-
const { clientX } = e;
|
|
315
|
-
setIsDragging(true);
|
|
316
|
-
setStartX(clientX);
|
|
317
|
-
},
|
|
318
|
-
onMouseMove: (e)=>{
|
|
319
|
-
// Allow clicking inside tooltip to copy labels.
|
|
320
|
-
if (!(e.target instanceof HTMLCanvasElement)) {
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
const { clientX } = e;
|
|
324
|
-
if (isDragging) {
|
|
325
|
-
const deltaX = clientX - startX;
|
|
326
|
-
if (deltaX > 0) {
|
|
327
|
-
// Hide tooltip when user drags to zoom.
|
|
328
|
-
setShowTooltip(false);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
},
|
|
332
|
-
onMouseUp: ()=>{
|
|
333
|
-
setIsDragging(false);
|
|
334
|
-
setStartX(0);
|
|
335
|
-
setShowTooltip(true);
|
|
336
|
-
},
|
|
337
|
-
onMouseLeave: ()=>{
|
|
338
|
-
if (tooltipPinnedCoords === null) {
|
|
339
|
-
setShowTooltip(false);
|
|
340
|
-
}
|
|
341
|
-
if (chartRef.current !== undefined) {
|
|
342
|
-
clearHighlightedSeries(chartRef.current);
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
onMouseEnter: ()=>{
|
|
346
|
-
setShowTooltip(true);
|
|
347
|
-
if (chartRef.current !== undefined) {
|
|
348
|
-
enableDataZoom(chartRef.current);
|
|
349
|
-
}
|
|
350
|
-
},
|
|
351
|
-
onDoubleClick: (e)=>{
|
|
352
|
-
setTooltipPinnedCoords(null);
|
|
353
|
-
// either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
|
|
354
|
-
if (onDoubleClick === undefined) {
|
|
355
|
-
if (chartRef.current !== undefined) {
|
|
356
|
-
restoreChart(chartRef.current);
|
|
357
|
-
}
|
|
358
|
-
} else {
|
|
359
|
-
onDoubleClick(e);
|
|
360
|
-
}
|
|
361
|
-
},
|
|
362
|
-
children: [
|
|
363
|
-
showTooltip === true && option.tooltip?.showContent === false && tooltipConfig.hidden !== true && /*#__PURE__*/ _jsx(TimeChartTooltip, {
|
|
364
|
-
containerId: chartsTheme.tooltipPortalContainerId,
|
|
365
|
-
chartRef: chartRef,
|
|
366
|
-
data: data,
|
|
367
|
-
seriesMapping: seriesMapping,
|
|
368
|
-
wrapLabels: tooltipConfig.wrapLabels,
|
|
369
|
-
enablePinning: isPinningEnabled,
|
|
370
|
-
pinnedPos: tooltipPinnedCoords,
|
|
371
|
-
format: format,
|
|
372
|
-
onUnpinClick: ()=>{
|
|
373
|
-
// Unpins tooltip when clicking Pin icon in TooltipHeader.
|
|
374
|
-
setTooltipPinnedCoords(null);
|
|
375
|
-
// Clear previously set pinned crosshair.
|
|
376
|
-
setPinnedCrosshair(null);
|
|
377
|
-
}
|
|
378
|
-
}),
|
|
379
|
-
/*#__PURE__*/ _jsx(EChart, {
|
|
380
|
-
sx: {
|
|
381
|
-
width: '100%',
|
|
382
|
-
height: '100%'
|
|
383
|
-
},
|
|
384
|
-
option: option,
|
|
385
|
-
theme: chartsTheme.echartsTheme,
|
|
386
|
-
onEvents: handleEvents,
|
|
387
|
-
_instance: chartRef,
|
|
388
|
-
syncGroup: syncGroup
|
|
389
|
-
})
|
|
390
|
-
]
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
//# sourceMappingURL=TimeChart.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeChart/TimeChart.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { forwardRef, MouseEvent, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport merge from 'lodash/merge';\nimport isEqual from 'lodash/isEqual';\nimport { DatasetOption } from 'echarts/types/dist/shared';\nimport { toZonedTime } from 'date-fns-tz';\nimport { getCommonTimeScale, TimeScale, FormatOptions, TimeSeries } from '@perses-dev/core';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n YAXisComponentOption,\n TooltipComponentOption,\n} from 'echarts';\nimport { ECharts as EChartsInstance, use } from 'echarts/core';\nimport { LineChart as EChartsLineChart, BarChart as EChartsBarChart } from 'echarts/charts';\nimport {\n GridComponent,\n DatasetComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, OnEventsType } from '../EChart';\nimport { ChartInstanceFocusOpts, ChartInstance, TimeChartSeriesMapping, DEFAULT_PINNED_CROSSHAIR } from '../model';\nimport { useChartsContext } from '../context/ChartsProvider';\nimport {\n clearHighlightedSeries,\n enableDataZoom,\n getClosestTimestamp,\n getFormattedAxisLabel,\n getPointInGrid,\n getFormattedAxis,\n restoreChart,\n ZoomEventData,\n} from '../utils';\nimport { CursorCoordinates, TimeChartTooltip, TooltipConfig, DEFAULT_TOOLTIP_CONFIG } from '../TimeSeriesTooltip';\nimport { useTimeZone } from '../context/TimeZoneProvider';\n\nuse([\n EChartsLineChart,\n EChartsBarChart,\n GridComponent,\n DatasetComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\nexport interface TimeChartProps {\n height: number;\n data: TimeSeries[];\n seriesMapping: TimeChartSeriesMapping;\n timeScale?: TimeScale;\n yAxis?: YAXisComponentOption;\n format?: FormatOptions;\n grid?: GridComponentOption;\n tooltipConfig?: TooltipConfig;\n noDataVariant?: 'chart' | 'message';\n syncGroup?: string;\n isStackedBar?: boolean;\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n __experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;\n}\n\nexport const TimeChart = forwardRef<ChartInstance, TimeChartProps>(function TimeChart(\n {\n height,\n data,\n seriesMapping,\n timeScale: timeScaleProp,\n yAxis,\n format,\n grid,\n isStackedBar = false,\n tooltipConfig = DEFAULT_TOOLTIP_CONFIG,\n noDataVariant = 'message',\n syncGroup,\n onDataZoom,\n onDoubleClick,\n __experimentalEChartsOptionsOverride,\n },\n ref\n) {\n const { chartsTheme, enablePinning, lastTooltipPinnedCoords, setLastTooltipPinnedCoords } = useChartsContext();\n const isPinningEnabled = tooltipConfig.enablePinning && enablePinning;\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [tooltipPinnedCoords, setTooltipPinnedCoords] = useState<CursorCoordinates | null>(null);\n const [pinnedCrosshair, setPinnedCrosshair] = useState<LineSeriesOption | null>(null);\n const [isDragging, setIsDragging] = useState(false);\n const [startX, setStartX] = useState(0);\n const { timeZone } = useTimeZone();\n let timeScale: TimeScale;\n if (timeScaleProp === undefined) {\n const commonTimeScale = getCommonTimeScale(data);\n if (commonTimeScale === undefined) {\n // set default to past 5 years\n const today = new Date();\n const pastDate = new Date(today);\n pastDate.setFullYear(today.getFullYear() - 5);\n const todayMs = today.getTime();\n const pastDateMs = pastDate.getTime();\n timeScale = { startMs: pastDateMs, endMs: todayMs, stepMs: 1, rangeMs: todayMs - pastDateMs };\n } else {\n timeScale = commonTimeScale;\n }\n } else {\n timeScale = timeScaleProp;\n }\n\n useImperativeHandle(ref, () => {\n return {\n highlightSeries({ name }: ChartInstanceFocusOpts): void {\n if (!chartRef.current) {\n // when chart undef, do not highlight series when hovering over legend\n return;\n }\n\n chartRef.current.dispatchAction({ type: 'highlight', seriesId: name });\n },\n clearHighlightedSeries: (): void => {\n if (!chartRef.current) {\n // when chart undef, do not clear highlight series\n return;\n }\n clearHighlightedSeries(chartRef.current);\n },\n };\n }, []);\n\n const handleEvents: OnEventsType<LineSeriesOption['data'] | unknown> = useMemo(() => {\n return {\n datazoom: (params): void => {\n if (onDataZoom === undefined) {\n setTimeout(() => {\n // workaround so unpin happens after click event\n setTooltipPinnedCoords(null);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const xAxisStartValue = params.batch[0].startValue;\n const xAxisEndValue = params.batch[0].endValue;\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n };\n onDataZoom(zoomEvent);\n }\n },\n finished: (): void => {\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n },\n };\n }, [onDataZoom, setTooltipPinnedCoords]);\n\n const { noDataOption } = chartsTheme;\n\n const option: EChartsCoreOption = useMemo(() => {\n // The \"chart\" `noDataVariant` is only used when the `timeSeries` is an\n // empty array because a `null` value will throw an error.\n if (data === null || (data.length === 0 && noDataVariant === 'message')) return noDataOption;\n\n // Utilizes ECharts dataset so raw data is separate from series option style properties\n // https://apache.github.io/echarts-handbook/en/concepts/dataset/\n const dataset: DatasetOption[] = [];\n const isLocalTimeZone = timeZone === 'local';\n data.map((d, index) => {\n const values = d.values.map(([timestamp, value]) => {\n const val: string | number = value === null ? '-' : value; // echarts use '-' to represent null data\n return [isLocalTimeZone ? timestamp : toZonedTime(timestamp, timeZone), val];\n });\n dataset.push({ id: index, source: [...values], dimensions: ['time', 'value'] });\n });\n\n const updatedSeriesMapping =\n enablePinning && pinnedCrosshair !== null ? [...seriesMapping, pinnedCrosshair] : seriesMapping;\n\n const option: EChartsCoreOption = {\n dataset: dataset,\n series: updatedSeriesMapping,\n xAxis: {\n type: 'time',\n min: isLocalTimeZone ? timeScale.startMs : toZonedTime(timeScale.startMs, timeZone),\n max: isLocalTimeZone ? timeScale.endMs : toZonedTime(timeScale.endMs, timeZone),\n axisLabel: {\n hideOverlap: true,\n formatter: getFormattedAxisLabel(timeScale.rangeMs ?? 0),\n },\n axisPointer: {\n snap: false, // important so shared crosshair does not lag\n },\n },\n yAxis: getFormattedAxis(yAxis, format),\n animation: false,\n tooltip: {\n show: true,\n // ECharts tooltip content hidden by default since we use custom tooltip instead.\n // Stacked bar uses ECharts tooltip so subgroup data shows correctly.\n showContent: isStackedBar,\n trigger: isStackedBar ? 'item' : 'axis',\n appendToBody: isStackedBar,\n },\n // https://echarts.apache.org/en/option.html#axisPointer\n axisPointer: {\n type: 'line',\n z: 0, // ensure point symbol shows on top of dashed line\n triggerEmphasis: false, // https://github.com/apache/echarts/issues/18495\n triggerTooltip: false,\n snap: false, // xAxis.axisPointer.snap takes priority\n },\n toolbox: {\n feature: {\n dataZoom: {\n icon: null, // https://stackoverflow.com/a/67684076/17575201\n yAxisIndex: 'none',\n },\n },\n },\n grid,\n };\n\n if (__experimentalEChartsOptionsOverride) {\n return __experimentalEChartsOptionsOverride(option);\n }\n\n return option;\n }, [\n data,\n seriesMapping,\n timeScale,\n yAxis,\n format,\n grid,\n noDataOption,\n __experimentalEChartsOptionsOverride,\n noDataVariant,\n timeZone,\n isStackedBar,\n enablePinning,\n pinnedCrosshair,\n ]);\n\n // Update adjacent charts so tooltip is unpinned when current chart is clicked.\n useEffect(() => {\n // Only allow pinning one tooltip at a time, subsequent tooltip click unpins previous.\n // Multiple tooltips can only be pinned if Ctrl or Cmd key is pressed while clicking.\n const multipleTooltipsPinned = tooltipPinnedCoords !== null && lastTooltipPinnedCoords !== null;\n if (multipleTooltipsPinned) {\n if (!isEqual(lastTooltipPinnedCoords, tooltipPinnedCoords)) {\n setTooltipPinnedCoords(null);\n if (tooltipPinnedCoords !== null && pinnedCrosshair !== null) {\n setPinnedCrosshair(null);\n }\n }\n }\n // tooltipPinnedCoords CANNOT be in dep array or tooltip pinning breaks in the current chart's onClick\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [lastTooltipPinnedCoords, seriesMapping]);\n\n return (\n <Box\n style={{ height }}\n // onContextMenu={(e) => {\n // // TODO: confirm tooltip pinning works correctly on Windows, should e.preventDefault() be added here\n // e.preventDefault(); // Prevent the default behaviour when right clicked\n // }}\n onClick={(e) => {\n // Allows user to opt-in to multi tooltip pinning when Ctrl or Cmd key held down\n const isControlKeyPressed = e.ctrlKey || e.metaKey;\n if (isControlKeyPressed) {\n e.preventDefault();\n }\n\n // Determine where on chart canvas to plot pinned crosshair as markLine.\n const pointInGrid = getPointInGrid(e.nativeEvent.offsetX, e.nativeEvent.offsetY, chartRef.current);\n if (pointInGrid === null) {\n return;\n }\n\n // Pin and unpin when clicking on chart canvas but not tooltip text.\n if (isPinningEnabled && e.target instanceof HTMLCanvasElement) {\n // Pin tooltip and update shared charts context to remember these coordinates.\n const pinnedPos: CursorCoordinates = {\n page: {\n x: e.pageX,\n y: e.pageY,\n },\n client: {\n x: e.clientX,\n y: e.clientY,\n },\n plotCanvas: {\n x: e.nativeEvent.offsetX,\n y: e.nativeEvent.offsetY,\n },\n target: e.target,\n };\n\n setTooltipPinnedCoords((current) => {\n if (current === null) {\n return pinnedPos;\n } else {\n setPinnedCrosshair(null);\n return null;\n }\n });\n\n setPinnedCrosshair((current) => {\n // Only add pinned crosshair line series when there is not one already in seriesMapping.\n if (current === null) {\n const cursorX = pointInGrid[0];\n\n // Only need to loop through first dataset source since getCommonTimeScale ensures xAxis timestamps are consistent\n const firstTimeSeriesValues = data[0]?.values;\n const closestTimestamp = getClosestTimestamp(firstTimeSeriesValues, cursorX);\n\n // Crosshair snaps to nearest timestamp since cursor may be slightly to left or right\n const pinnedCrosshair = merge({}, DEFAULT_PINNED_CROSSHAIR, {\n markLine: {\n data: [\n {\n xAxis: closestTimestamp,\n },\n ],\n },\n } as LineSeriesOption);\n return pinnedCrosshair;\n } else {\n // Clear previously set pinned crosshair\n return null;\n }\n });\n\n if (!isControlKeyPressed) {\n setLastTooltipPinnedCoords(pinnedPos);\n }\n }\n }}\n onMouseDown={(e) => {\n const { clientX } = e;\n setIsDragging(true);\n setStartX(clientX);\n }}\n onMouseMove={(e) => {\n // Allow clicking inside tooltip to copy labels.\n if (!(e.target instanceof HTMLCanvasElement)) {\n return;\n }\n const { clientX } = e;\n if (isDragging) {\n const deltaX = clientX - startX;\n if (deltaX > 0) {\n // Hide tooltip when user drags to zoom.\n setShowTooltip(false);\n }\n }\n }}\n onMouseUp={() => {\n setIsDragging(false);\n setStartX(0);\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n if (tooltipPinnedCoords === null) {\n setShowTooltip(false);\n }\n if (chartRef.current !== undefined) {\n clearHighlightedSeries(chartRef.current);\n }\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n }}\n onDoubleClick={(e) => {\n setTooltipPinnedCoords(null);\n // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior\n if (onDoubleClick === undefined) {\n if (chartRef.current !== undefined) {\n restoreChart(chartRef.current);\n }\n } else {\n onDoubleClick(e);\n }\n }}\n >\n {/* Allows overrides prop to hide custom tooltip and use the ECharts option.tooltip instead */}\n {showTooltip === true &&\n (option.tooltip as TooltipComponentOption)?.showContent === false &&\n tooltipConfig.hidden !== true && (\n <TimeChartTooltip\n containerId={chartsTheme.tooltipPortalContainerId}\n chartRef={chartRef}\n data={data}\n seriesMapping={seriesMapping}\n wrapLabels={tooltipConfig.wrapLabels}\n enablePinning={isPinningEnabled}\n pinnedPos={tooltipPinnedCoords}\n format={format}\n onUnpinClick={() => {\n // Unpins tooltip when clicking Pin icon in TooltipHeader.\n setTooltipPinnedCoords(null);\n // Clear previously set pinned crosshair.\n setPinnedCrosshair(null);\n }}\n />\n )}\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n onEvents={handleEvents}\n _instance={chartRef}\n syncGroup={syncGroup}\n />\n </Box>\n );\n});\n"],"names":["forwardRef","useEffect","useImperativeHandle","useMemo","useRef","useState","Box","merge","isEqual","toZonedTime","getCommonTimeScale","use","LineChart","EChartsLineChart","BarChart","EChartsBarChart","GridComponent","DatasetComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","CanvasRenderer","EChart","DEFAULT_PINNED_CROSSHAIR","useChartsContext","clearHighlightedSeries","enableDataZoom","getClosestTimestamp","getFormattedAxisLabel","getPointInGrid","getFormattedAxis","restoreChart","TimeChartTooltip","DEFAULT_TOOLTIP_CONFIG","useTimeZone","TimeChart","height","data","seriesMapping","timeScale","timeScaleProp","yAxis","format","grid","isStackedBar","tooltipConfig","noDataVariant","syncGroup","onDataZoom","onDoubleClick","__experimentalEChartsOptionsOverride","ref","chartsTheme","enablePinning","lastTooltipPinnedCoords","setLastTooltipPinnedCoords","isPinningEnabled","chartRef","showTooltip","setShowTooltip","tooltipPinnedCoords","setTooltipPinnedCoords","pinnedCrosshair","setPinnedCrosshair","isDragging","setIsDragging","startX","setStartX","timeZone","undefined","commonTimeScale","today","Date","pastDate","setFullYear","getFullYear","todayMs","getTime","pastDateMs","startMs","endMs","stepMs","rangeMs","highlightSeries","name","current","dispatchAction","type","seriesId","handleEvents","datazoom","params","setTimeout","batch","xAxisStartValue","startValue","xAxisEndValue","endValue","zoomEvent","start","end","finished","noDataOption","option","length","dataset","isLocalTimeZone","map","d","index","values","timestamp","value","val","push","id","source","dimensions","updatedSeriesMapping","series","xAxis","min","max","axisLabel","hideOverlap","formatter","axisPointer","snap","animation","tooltip","show","showContent","trigger","appendToBody","z","triggerEmphasis","triggerTooltip","toolbox","feature","dataZoom","icon","yAxisIndex","multipleTooltipsPinned","style","onClick","e","isControlKeyPressed","ctrlKey","metaKey","preventDefault","pointInGrid","nativeEvent","offsetX","offsetY","target","HTMLCanvasElement","pinnedPos","page","x","pageX","y","pageY","client","clientX","clientY","plotCanvas","cursorX","firstTimeSeriesValues","closestTimestamp","markLine","onMouseDown","onMouseMove","deltaX","onMouseUp","onMouseLeave","onMouseEnter","hidden","containerId","tooltipPortalContainerId","wrapLabels","onUnpinClick","sx","width","theme","echartsTheme","onEvents","_instance"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,EAAcC,SAAS,EAAEC,mBAAmB,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC1G,SAASC,GAAG,QAAQ,gBAAgB;AACpC,OAAOC,WAAW,eAAe;AACjC,OAAOC,aAAa,iBAAiB;AAErC,SAASC,WAAW,QAAQ,cAAc;AAC1C,SAASC,kBAAkB,QAA8C,mBAAmB;AAQ5F,SAAqCC,GAAG,QAAQ,eAAe;AAC/D,SAASC,aAAaC,gBAAgB,EAAEC,YAAYC,eAAe,QAAQ,iBAAiB;AAC5F,SACEC,aAAa,EACbC,gBAAgB,EAChBC,iBAAiB,EACjBC,iBAAiB,EACjBC,iBAAiB,EACjBC,kBAAkB,EAClBC,cAAc,EACdC,gBAAgB,EAChBC,gBAAgB,QACX,qBAAqB;A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;gBAC/BC,UAAUhG;gBACViG,WAAWjI;gBACXV,WAAWA;;;;AAInB,GAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TimeChart/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC"}
|
package/dist/TimeChart/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
export * from './TimeChart';
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeChart/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './TimeChart';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,cAAc"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { FormatOptions } from '@perses-dev/core';
|
|
2
|
-
import { ECharts as EChartsInstance } from 'echarts/core';
|
|
3
|
-
import { MutableRefObject } from 'react';
|
|
4
|
-
import { EChartsDataFormat } from '../model';
|
|
5
|
-
import { CursorCoordinates } from './tooltip-model';
|
|
6
|
-
export interface TimeSeriesTooltipProps {
|
|
7
|
-
chartRef: MutableRefObject<EChartsInstance | undefined>;
|
|
8
|
-
chartData: EChartsDataFormat;
|
|
9
|
-
enablePinning?: boolean;
|
|
10
|
-
wrapLabels?: boolean;
|
|
11
|
-
format?: FormatOptions;
|
|
12
|
-
onUnpinClick?: () => void;
|
|
13
|
-
pinnedPos: CursorCoordinates | null;
|
|
14
|
-
/**
|
|
15
|
-
* The id of the container that will have the chart tooltip appended to it.
|
|
16
|
-
* By default, the chart tooltip is attached to document.body.
|
|
17
|
-
*/
|
|
18
|
-
containerId?: string;
|
|
19
|
-
}
|
|
20
|
-
export declare const LineChartTooltip: import("react").NamedExoticComponent<TimeSeriesTooltipProps>;
|
|
21
|
-
//# sourceMappingURL=LineChartTooltip.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LineChartTooltip.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/LineChartTooltip.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAQ,gBAAgB,EAAkC,MAAM,OAAO,CAAC;AAE/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAI7C,OAAO,EACL,iBAAiB,EAMlB,MAAM,iBAAiB,CAAC;AAGzB,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IACxD,SAAS,EAAE,iBAAiB,CAAC;IAC7B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,SAAS,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACpC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,gBAAgB,8DA2F3B,CAAC"}
|
|
@@ -1,101 +0,0 @@
|
|
|
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
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { Box, Portal, Stack } from '@mui/material';
|
|
15
|
-
import { memo, useRef, useState } from 'react';
|
|
16
|
-
import useResizeObserver from 'use-resize-observer';
|
|
17
|
-
import { TooltipContent } from './TooltipContent';
|
|
18
|
-
import { TooltipHeader } from './TooltipHeader';
|
|
19
|
-
import { legacyGetNearbySeriesData } from './nearby-series';
|
|
20
|
-
import { TOOLTIP_BG_COLOR_FALLBACK, TOOLTIP_MAX_HEIGHT, TOOLTIP_MAX_WIDTH, TOOLTIP_MIN_WIDTH, useMousePosition } from './tooltip-model';
|
|
21
|
-
import { assembleTransform } from './utils';
|
|
22
|
-
export const LineChartTooltip = /*#__PURE__*/ memo(function LineChartTooltip({ chartRef, chartData, enablePinning = true, wrapLabels, format, onUnpinClick, pinnedPos, containerId }) {
|
|
23
|
-
const [showAllSeries, setShowAllSeries] = useState(false);
|
|
24
|
-
const mousePos = useMousePosition();
|
|
25
|
-
const { height, width, ref: tooltipRef } = useResizeObserver();
|
|
26
|
-
const transform = useRef();
|
|
27
|
-
const isTooltipPinned = pinnedPos !== null && enablePinning;
|
|
28
|
-
if (mousePos === null || mousePos.target === null) return null;
|
|
29
|
-
// Ensure user is hovering over a chart before checking for nearby series.
|
|
30
|
-
if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
|
|
31
|
-
const chart = chartRef.current;
|
|
32
|
-
// Get series nearby the cursor and pass into tooltip content children.
|
|
33
|
-
const nearbySeries = legacyGetNearbySeriesData({
|
|
34
|
-
mousePos,
|
|
35
|
-
chartData,
|
|
36
|
-
pinnedPos,
|
|
37
|
-
chart,
|
|
38
|
-
format,
|
|
39
|
-
showAllSeries
|
|
40
|
-
});
|
|
41
|
-
if (nearbySeries.length === 0) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
const totalSeries = chartData.timeSeries.length;
|
|
45
|
-
const containerElement = containerId ? document.querySelector(containerId) : undefined;
|
|
46
|
-
// if tooltip is attached to a container, set max height to the height of the container so tooltip does not get cut off
|
|
47
|
-
const maxHeight = containerElement ? containerElement.getBoundingClientRect().height : undefined;
|
|
48
|
-
transform.current = assembleTransform(mousePos, pinnedPos, height ?? 0, width ?? 0, containerElement);
|
|
49
|
-
return /*#__PURE__*/ _jsx(Portal, {
|
|
50
|
-
container: containerElement,
|
|
51
|
-
children: /*#__PURE__*/ _jsx(Box, {
|
|
52
|
-
ref: tooltipRef,
|
|
53
|
-
sx: (theme)=>({
|
|
54
|
-
minWidth: TOOLTIP_MIN_WIDTH,
|
|
55
|
-
maxWidth: TOOLTIP_MAX_WIDTH,
|
|
56
|
-
maxHeight: maxHeight ?? TOOLTIP_MAX_HEIGHT,
|
|
57
|
-
padding: 0,
|
|
58
|
-
position: 'absolute',
|
|
59
|
-
top: 0,
|
|
60
|
-
left: 0,
|
|
61
|
-
backgroundColor: theme.palette.designSystem?.grey[800] ?? TOOLTIP_BG_COLOR_FALLBACK,
|
|
62
|
-
borderRadius: '6px',
|
|
63
|
-
color: '#fff',
|
|
64
|
-
fontSize: '11px',
|
|
65
|
-
visibility: 'visible',
|
|
66
|
-
opacity: 1,
|
|
67
|
-
transition: 'all 0.1s ease-out',
|
|
68
|
-
// Ensure pinned tooltip shows behind edit panel drawer and sticky header
|
|
69
|
-
zIndex: pinnedPos !== null ? 'auto' : theme.zIndex.tooltip,
|
|
70
|
-
overflow: 'hidden',
|
|
71
|
-
'&:hover': {
|
|
72
|
-
overflowY: 'auto'
|
|
73
|
-
}
|
|
74
|
-
}),
|
|
75
|
-
style: {
|
|
76
|
-
transform: transform.current,
|
|
77
|
-
display: transform.current ? 'block' : 'none'
|
|
78
|
-
},
|
|
79
|
-
children: /*#__PURE__*/ _jsxs(Stack, {
|
|
80
|
-
spacing: 0.5,
|
|
81
|
-
children: [
|
|
82
|
-
/*#__PURE__*/ _jsx(TooltipHeader, {
|
|
83
|
-
nearbySeries: nearbySeries,
|
|
84
|
-
totalSeries: totalSeries,
|
|
85
|
-
enablePinning: enablePinning,
|
|
86
|
-
isTooltipPinned: isTooltipPinned,
|
|
87
|
-
showAllSeries: showAllSeries,
|
|
88
|
-
onShowAllClick: (checked)=>setShowAllSeries(checked),
|
|
89
|
-
onUnpinClick: onUnpinClick
|
|
90
|
-
}),
|
|
91
|
-
/*#__PURE__*/ _jsx(TooltipContent, {
|
|
92
|
-
series: nearbySeries,
|
|
93
|
-
wrapLabels: wrapLabels
|
|
94
|
-
})
|
|
95
|
-
]
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
//# sourceMappingURL=LineChartTooltip.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/TimeSeriesTooltip/LineChartTooltip.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, Portal, Stack } from '@mui/material';\nimport { FormatOptions } from '@perses-dev/core';\nimport { ECharts as EChartsInstance } from 'echarts/core';\nimport { memo, MutableRefObject, ReactElement, useRef, useState } from 'react';\nimport useResizeObserver from 'use-resize-observer';\nimport { EChartsDataFormat } from '../model';\nimport { TooltipContent } from './TooltipContent';\nimport { TooltipHeader } from './TooltipHeader';\nimport { legacyGetNearbySeriesData } from './nearby-series';\nimport {\n CursorCoordinates,\n TOOLTIP_BG_COLOR_FALLBACK,\n TOOLTIP_MAX_HEIGHT,\n TOOLTIP_MAX_WIDTH,\n TOOLTIP_MIN_WIDTH,\n useMousePosition,\n} from './tooltip-model';\nimport { assembleTransform } from './utils';\n\nexport interface TimeSeriesTooltipProps {\n chartRef: MutableRefObject<EChartsInstance | undefined>;\n chartData: EChartsDataFormat;\n enablePinning?: boolean;\n wrapLabels?: boolean;\n format?: FormatOptions;\n onUnpinClick?: () => void;\n pinnedPos: CursorCoordinates | null;\n /**\n * The id of the container that will have the chart tooltip appended to it.\n * By default, the chart tooltip is attached to document.body.\n */\n containerId?: string;\n}\n\nexport const LineChartTooltip = memo(function LineChartTooltip({\n chartRef,\n chartData,\n enablePinning = true,\n wrapLabels,\n format,\n onUnpinClick,\n pinnedPos,\n containerId,\n}: TimeSeriesTooltipProps): ReactElement | null {\n const [showAllSeries, setShowAllSeries] = useState(false);\n const mousePos = useMousePosition();\n const { height, width, ref: tooltipRef } = useResizeObserver();\n const transform = useRef<string | undefined>();\n\n const isTooltipPinned = pinnedPos !== null && enablePinning;\n\n if (mousePos === null || mousePos.target === null) return null;\n\n // Ensure user is hovering over a chart before checking for nearby series.\n if (pinnedPos === null && (mousePos.target as HTMLElement).tagName !== 'CANVAS') return null;\n\n const chart = chartRef.current;\n\n // Get series nearby the cursor and pass into tooltip content children.\n const nearbySeries = legacyGetNearbySeriesData({\n mousePos,\n chartData,\n pinnedPos,\n chart,\n format,\n showAllSeries,\n });\n if (nearbySeries.length === 0) {\n return null;\n }\n\n const totalSeries = chartData.timeSeries.length;\n\n const containerElement = containerId ? document.querySelector(containerId) : undefined;\n // if tooltip is attached to a container, set max height to the height of the container so tooltip does not get cut off\n const maxHeight = containerElement ? containerElement.getBoundingClientRect().height : undefined;\n\n transform.current = assembleTransform(mousePos, pinnedPos, height ?? 0, width ?? 0, containerElement);\n\n return (\n <Portal container={containerElement}>\n <Box\n ref={tooltipRef}\n sx={(theme) => ({\n minWidth: TOOLTIP_MIN_WIDTH,\n maxWidth: TOOLTIP_MAX_WIDTH,\n maxHeight: maxHeight ?? TOOLTIP_MAX_HEIGHT,\n padding: 0,\n position: 'absolute',\n top: 0,\n left: 0,\n backgroundColor: theme.palette.designSystem?.grey[800] ?? TOOLTIP_BG_COLOR_FALLBACK,\n borderRadius: '6px',\n color: '#fff',\n fontSize: '11px',\n visibility: 'visible',\n opacity: 1,\n transition: 'all 0.1s ease-out',\n // Ensure pinned tooltip shows behind edit panel drawer and sticky header\n zIndex: pinnedPos !== null ? 'auto' : theme.zIndex.tooltip,\n overflow: 'hidden',\n '&:hover': {\n overflowY: 'auto',\n },\n })}\n style={{\n transform: transform.current,\n display: transform.current ? 'block' : 'none',\n }}\n >\n <Stack spacing={0.5}>\n <TooltipHeader\n nearbySeries={nearbySeries}\n totalSeries={totalSeries}\n enablePinning={enablePinning}\n isTooltipPinned={isTooltipPinned}\n showAllSeries={showAllSeries}\n onShowAllClick={(checked) => setShowAllSeries(checked)}\n onUnpinClick={onUnpinClick}\n />\n <TooltipContent series={nearbySeries} wrapLabels={wrapLabels} />\n </Stack>\n </Box>\n </Portal>\n );\n});\n"],"names":["Box","Portal","Stack","memo","useRef","useState","useResizeObserver","TooltipContent","TooltipHeader","legacyGetNearbySeriesData","TOOLTIP_BG_COLOR_FALLBACK","TOOLTIP_MAX_HEIGHT","TOOLTIP_MAX_WIDTH","TOOLTIP_MIN_WIDTH","useMousePosition","assembleTransform","LineChartTooltip","chartRef","chartData","enablePinning","wrapLabels","format","onUnpinClick","pinnedPos","containerId","showAllSeries","setShowAllSeries","mousePos","height","width","ref","tooltipRef","transform","isTooltipPinned","target","tagName","chart","current","nearbySeries","length","totalSeries","timeSeries","containerElement","document","querySelector","undefined","maxHeight","getBoundingClientRect","container","sx","theme","minWidth","maxWidth","padding","position","top","left","backgroundColor","palette","designSystem","grey","borderRadius","color","fontSize","visibility","opacity","transition","zIndex","tooltip","overflow","overflowY","style","display","spacing","onShowAllClick","checked","series"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,GAAG,EAAEC,MAAM,EAAEC,KAAK,QAAQ,gBAAgB;AAGnD,SAASC,IAAI,EAAkCC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC/E,OAAOC,uBAAuB,sBAAsB;AAEpD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,yBAAyB,QAAQ,kBAAkB;AAC5D,SAEEC,yBAAyB,EACzBC,kBAAkB,EAClBC,iBAAiB,EACjBC,iBAAiB,EACjBC,gBAAgB,QACX,kBAAkB;AACzB,SAASC,iBAAiB,QAAQ,UAAU;AAiB5C,OAAO,MAAMC,iCAA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