@perses-dev/components 0.0.0-snapshot-react-18-v-0-51-rc-0-8090608 → 0.0.0-snapshot-time-zone-selector-946f408

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.
Files changed (95) hide show
  1. package/README.md +1 -5
  2. package/dist/EChart/EChart.d.ts.map +1 -1
  3. package/dist/EChart/EChart.js +9 -4
  4. package/dist/EChart/EChart.js.map +1 -1
  5. package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts +2 -1
  6. package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts.map +1 -1
  7. package/dist/TimeRangeSelector/DateTimeRangePicker.js +5 -6
  8. package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
  9. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +5 -1
  10. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +1 -1
  11. package/dist/TimeRangeSelector/TimeRangeSelector.js +14 -10
  12. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
  13. package/dist/TimeSeriesTooltip/index.d.ts +0 -1
  14. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  15. package/dist/TimeSeriesTooltip/index.js +0 -1
  16. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  17. package/dist/TimeZoneSelector/TimeZoneSelector.d.ts +10 -0
  18. package/dist/TimeZoneSelector/TimeZoneSelector.d.ts.map +1 -0
  19. package/dist/TimeZoneSelector/TimeZoneSelector.js +143 -0
  20. package/dist/TimeZoneSelector/TimeZoneSelector.js.map +1 -0
  21. package/dist/TimeZoneSelector/index.d.ts +2 -0
  22. package/dist/TimeZoneSelector/index.d.ts.map +1 -0
  23. package/dist/{LineChart → TimeZoneSelector}/index.js +2 -2
  24. package/dist/TimeZoneSelector/index.js.map +1 -0
  25. package/dist/cjs/EChart/EChart.js +7 -2
  26. package/dist/cjs/TimeRangeSelector/DateTimeRangePicker.js +5 -6
  27. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +12 -8
  28. package/dist/cjs/TimeSeriesTooltip/index.js +0 -1
  29. package/dist/cjs/TimeZoneSelector/TimeZoneSelector.js +156 -0
  30. package/dist/cjs/{LineChart → TimeZoneSelector}/index.js +2 -2
  31. package/dist/cjs/context/index.js +0 -1
  32. package/dist/cjs/index.js +1 -2
  33. package/dist/cjs/model/index.js +1 -0
  34. package/dist/cjs/model/timeZoneOption.js +100 -0
  35. package/dist/cjs/utils/axis.js +3 -18
  36. package/dist/cjs/utils/format.js +0 -21
  37. package/dist/context/index.d.ts +0 -1
  38. package/dist/context/index.d.ts.map +1 -1
  39. package/dist/context/index.js +0 -1
  40. package/dist/context/index.js.map +1 -1
  41. package/dist/index.d.ts +1 -2
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +1 -2
  44. package/dist/index.js.map +1 -1
  45. package/dist/model/graph.d.ts +0 -1
  46. package/dist/model/graph.d.ts.map +1 -1
  47. package/dist/model/graph.js.map +1 -1
  48. package/dist/model/index.d.ts +1 -0
  49. package/dist/model/index.d.ts.map +1 -1
  50. package/dist/model/index.js +1 -0
  51. package/dist/model/index.js.map +1 -1
  52. package/dist/model/timeZoneOption.d.ts +10 -0
  53. package/dist/model/timeZoneOption.d.ts.map +1 -0
  54. package/dist/model/timeZoneOption.js +79 -0
  55. package/dist/model/timeZoneOption.js.map +1 -0
  56. package/dist/utils/axis.d.ts +0 -4
  57. package/dist/utils/axis.d.ts.map +1 -1
  58. package/dist/utils/axis.js +0 -9
  59. package/dist/utils/axis.js.map +1 -1
  60. package/dist/utils/chart-actions.d.ts +0 -2
  61. package/dist/utils/chart-actions.d.ts.map +1 -1
  62. package/dist/utils/chart-actions.js.map +1 -1
  63. package/dist/utils/format.d.ts +0 -1
  64. package/dist/utils/format.d.ts.map +1 -1
  65. package/dist/utils/format.js +0 -20
  66. package/dist/utils/format.js.map +1 -1
  67. package/package.json +4 -7
  68. package/dist/LineChart/LineChart.d.ts +0 -22
  69. package/dist/LineChart/LineChart.d.ts.map +0 -1
  70. package/dist/LineChart/LineChart.js +0 -266
  71. package/dist/LineChart/LineChart.js.map +0 -1
  72. package/dist/LineChart/index.d.ts +0 -2
  73. package/dist/LineChart/index.d.ts.map +0 -1
  74. package/dist/LineChart/index.js.map +0 -1
  75. package/dist/TimeChart/TimeChart.d.ts +0 -24
  76. package/dist/TimeChart/TimeChart.d.ts.map +0 -1
  77. package/dist/TimeChart/TimeChart.js +0 -394
  78. package/dist/TimeChart/TimeChart.js.map +0 -1
  79. package/dist/TimeChart/index.d.ts +0 -2
  80. package/dist/TimeChart/index.d.ts.map +0 -1
  81. package/dist/TimeChart/index.js +0 -15
  82. package/dist/TimeChart/index.js.map +0 -1
  83. package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts +0 -21
  84. package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +0 -1
  85. package/dist/TimeSeriesTooltip/LineChartTooltip.js +0 -101
  86. package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +0 -1
  87. package/dist/cjs/LineChart/LineChart.js +0 -274
  88. package/dist/cjs/TimeChart/TimeChart.js +0 -407
  89. package/dist/cjs/TimeChart/index.js +0 -30
  90. package/dist/cjs/TimeSeriesTooltip/LineChartTooltip.js +0 -114
  91. package/dist/cjs/context/TimeZoneProvider.js +0 -98
  92. package/dist/context/TimeZoneProvider.d.ts +0 -13
  93. package/dist/context/TimeZoneProvider.d.ts.map +0 -1
  94. package/dist/context/TimeZoneProvider.js +0 -38
  95. package/dist/context/TimeZoneProvider.js.map +0 -1
@@ -1,274 +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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "LineChart", {
18
- enumerable: true,
19
- get: function() {
20
- return LineChart;
21
- }
22
- });
23
- const _jsxruntime = require("react/jsx-runtime");
24
- const _react = require("react");
25
- const _material = require("@mui/material");
26
- const _core = 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 _context = require("../context");
32
- const _TimeSeriesTooltip = require("../TimeSeriesTooltip");
33
- const _utils = require("../utils");
34
- (0, _core.use)([
35
- _charts.LineChart,
36
- _components.GridComponent,
37
- _components.DataZoomComponent,
38
- _components.MarkAreaComponent,
39
- _components.MarkLineComponent,
40
- _components.MarkPointComponent,
41
- _components.TitleComponent,
42
- _components.ToolboxComponent,
43
- _components.TooltipComponent,
44
- _components.LegendComponent,
45
- _renderers.CanvasRenderer
46
- ]);
47
- const LineChart = /*#__PURE__*/ (0, _react.forwardRef)(function LineChart({ height, data, yAxis, format, grid, legend, tooltipConfig = _TimeSeriesTooltip.DEFAULT_TOOLTIP_CONFIG, noDataVariant = 'message', syncGroup, onDataZoom, onDoubleClick, __experimentalEChartsOptionsOverride }, ref) {
48
- const chartsTheme = (0, _context.useChartsTheme)();
49
- const chartRef = (0, _react.useRef)();
50
- const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
51
- const [tooltipPinnedCoords, setTooltipPinnedCoords] = (0, _react.useState)(null);
52
- const { timeZone } = (0, _context.useTimeZone)();
53
- const [isDragging, setIsDragging] = (0, _react.useState)(false);
54
- const [startX, setStartX] = (0, _react.useState)(0);
55
- (0, _react.useImperativeHandle)(ref, ()=>{
56
- return {
57
- highlightSeries ({ id }) {
58
- if (!chartRef.current) {
59
- // when chart undef, do not highlight series when hovering over legend
60
- return;
61
- }
62
- chartRef.current.dispatchAction({
63
- type: 'highlight',
64
- seriesId: id
65
- });
66
- },
67
- clearHighlightedSeries: ()=>{
68
- if (!chartRef.current) {
69
- // when chart undef, do not clear highlight series
70
- return;
71
- }
72
- (0, _utils.clearHighlightedSeries)(chartRef.current);
73
- }
74
- };
75
- }, []);
76
- const handleEvents = (0, _react.useMemo)(()=>{
77
- return {
78
- datazoom: (params)=>{
79
- if (onDataZoom === undefined) {
80
- setTimeout(()=>{
81
- // workaround so unpin happens after click event
82
- setTooltipPinnedCoords(null);
83
- }, 10);
84
- }
85
- if (onDataZoom === undefined || params.batch[0] === undefined) return;
86
- const startIndex = params.batch[0].startValue ?? 0;
87
- const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;
88
- const xAxisStartValue = data.xAxis[startIndex];
89
- const xAxisEndValue = data.xAxis[endIndex];
90
- if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
91
- const zoomEvent = {
92
- start: xAxisStartValue,
93
- end: xAxisEndValue,
94
- startIndex,
95
- endIndex
96
- };
97
- onDataZoom(zoomEvent);
98
- }
99
- }
100
- };
101
- }, [
102
- data,
103
- onDataZoom,
104
- setTooltipPinnedCoords
105
- ]);
106
- if (chartRef.current !== undefined) {
107
- (0, _utils.enableDataZoom)(chartRef.current);
108
- }
109
- const { noDataOption } = chartsTheme;
110
- const option = (0, _react.useMemo)(()=>{
111
- if (data.timeSeries === undefined) return {};
112
- // The "chart" `noDataVariant` is only used when the `timeSeries` is an
113
- // empty array because a `null` value will throw an error.
114
- if (data.timeSeries === null || data.timeSeries.length === 0 && noDataVariant === 'message') return noDataOption;
115
- const rangeMs = data.rangeMs ?? (0, _utils.getDateRange)(data.xAxis);
116
- const option = {
117
- series: data.timeSeries,
118
- xAxis: {
119
- type: 'category',
120
- data: data.xAxis,
121
- max: data.xAxisMax,
122
- axisLabel: {
123
- formatter: (value)=>{
124
- return (0, _utils.getFormattedDate)(value, rangeMs, timeZone);
125
- }
126
- }
127
- },
128
- yAxis: (0, _utils.getFormattedAxis)(yAxis, format),
129
- animation: false,
130
- tooltip: {
131
- show: true,
132
- trigger: 'axis',
133
- showContent: false
134
- },
135
- // https://echarts.apache.org/en/option.html#axisPointer
136
- axisPointer: {
137
- type: 'line',
138
- z: 0,
139
- triggerEmphasis: false,
140
- triggerTooltip: false,
141
- snap: true
142
- },
143
- toolbox: {
144
- feature: {
145
- dataZoom: {
146
- icon: null,
147
- yAxisIndex: 'none'
148
- }
149
- }
150
- },
151
- grid,
152
- legend
153
- };
154
- if (__experimentalEChartsOptionsOverride) {
155
- return __experimentalEChartsOptionsOverride(option);
156
- }
157
- return option;
158
- }, [
159
- data,
160
- yAxis,
161
- format,
162
- grid,
163
- legend,
164
- noDataOption,
165
- timeZone,
166
- __experimentalEChartsOptionsOverride,
167
- noDataVariant
168
- ]);
169
- return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
170
- style: {
171
- height
172
- },
173
- onClick: (e)=>{
174
- // Pin and unpin when clicking on chart canvas but not tooltip text.
175
- if (tooltipConfig.enablePinning && e.target instanceof HTMLCanvasElement) {
176
- setTooltipPinnedCoords((current)=>{
177
- if (current === null) {
178
- return {
179
- page: {
180
- x: e.pageX,
181
- y: e.pageY
182
- },
183
- client: {
184
- x: e.clientX,
185
- y: e.clientY
186
- },
187
- plotCanvas: {
188
- x: e.nativeEvent.offsetX,
189
- y: e.nativeEvent.offsetY
190
- },
191
- target: e.target
192
- };
193
- } else {
194
- return null;
195
- }
196
- });
197
- }
198
- },
199
- onMouseDown: (e)=>{
200
- const { clientX } = e;
201
- setIsDragging(true);
202
- setStartX(clientX);
203
- },
204
- onMouseMove: (e)=>{
205
- // Allow clicking inside tooltip to copy labels.
206
- if (!(e.target instanceof HTMLCanvasElement)) {
207
- return;
208
- }
209
- const { clientX } = e;
210
- if (isDragging) {
211
- const deltaX = clientX - startX;
212
- if (deltaX > 0) {
213
- // Hide tooltip when user drags to zoom.
214
- setShowTooltip(false);
215
- }
216
- }
217
- },
218
- onMouseUp: ()=>{
219
- setIsDragging(false);
220
- setStartX(0);
221
- setShowTooltip(true);
222
- },
223
- onMouseLeave: ()=>{
224
- if (tooltipPinnedCoords === null) {
225
- setShowTooltip(false);
226
- }
227
- if (chartRef.current !== undefined) {
228
- (0, _utils.clearHighlightedSeries)(chartRef.current);
229
- }
230
- },
231
- onMouseEnter: ()=>{
232
- setShowTooltip(true);
233
- if (chartRef.current !== undefined) {
234
- (0, _utils.enableDataZoom)(chartRef.current);
235
- }
236
- },
237
- onDoubleClick: (e)=>{
238
- setTooltipPinnedCoords(null);
239
- // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
240
- if (onDoubleClick === undefined) {
241
- if (chartRef.current !== undefined) {
242
- (0, _utils.restoreChart)(chartRef.current);
243
- }
244
- } else {
245
- onDoubleClick(e);
246
- }
247
- },
248
- children: [
249
- showTooltip === true && option.tooltip?.showContent === false && tooltipConfig.hidden !== true && /*#__PURE__*/ (0, _jsxruntime.jsx)(_TimeSeriesTooltip.LineChartTooltip, {
250
- chartRef: chartRef,
251
- chartData: data,
252
- wrapLabels: tooltipConfig.wrapLabels,
253
- enablePinning: tooltipConfig.enablePinning,
254
- pinnedPos: tooltipPinnedCoords,
255
- format: format,
256
- onUnpinClick: ()=>{
257
- setTooltipPinnedCoords(null);
258
- },
259
- containerId: chartsTheme.tooltipPortalContainerId
260
- }),
261
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_EChart.EChart, {
262
- sx: {
263
- width: '100%',
264
- height: '100%'
265
- },
266
- option: option,
267
- theme: chartsTheme.echartsTheme,
268
- onEvents: handleEvents,
269
- _instance: chartRef,
270
- syncGroup: syncGroup
271
- })
272
- ]
273
- });
274
- });
@@ -1,407 +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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- Object.defineProperty(exports, "TimeChart", {
18
- enumerable: true,
19
- get: function() {
20
- return TimeChart;
21
- }
22
- });
23
- const _jsxruntime = require("react/jsx-runtime");
24
- const _react = require("react");
25
- const _material = require("@mui/material");
26
- const _merge = /*#__PURE__*/ _interop_require_default(require("lodash/merge"));
27
- const _isEqual = /*#__PURE__*/ _interop_require_default(require("lodash/isEqual"));
28
- const _datefnstz = require("date-fns-tz");
29
- const _core = require("@perses-dev/core");
30
- const _core1 = require("echarts/core");
31
- const _charts = require("echarts/charts");
32
- const _components = require("echarts/components");
33
- const _renderers = require("echarts/renderers");
34
- const _EChart = require("../EChart");
35
- const _model = require("../model");
36
- const _ChartsProvider = require("../context/ChartsProvider");
37
- const _utils = require("../utils");
38
- const _TimeSeriesTooltip = require("../TimeSeriesTooltip");
39
- const _TimeZoneProvider = require("../context/TimeZoneProvider");
40
- function _interop_require_default(obj) {
41
- return obj && obj.__esModule ? obj : {
42
- default: obj
43
- };
44
- }
45
- (0, _core1.use)([
46
- _charts.LineChart,
47
- _charts.BarChart,
48
- _components.GridComponent,
49
- _components.DatasetComponent,
50
- _components.DataZoomComponent,
51
- _components.MarkAreaComponent,
52
- _components.MarkLineComponent,
53
- _components.MarkPointComponent,
54
- _components.TitleComponent,
55
- _components.ToolboxComponent,
56
- _components.TooltipComponent,
57
- _renderers.CanvasRenderer
58
- ]);
59
- const TimeChart = /*#__PURE__*/ (0, _react.forwardRef)(function TimeChart({ height, data, seriesMapping, timeScale: timeScaleProp, yAxis, format, grid, isStackedBar = false, tooltipConfig = _TimeSeriesTooltip.DEFAULT_TOOLTIP_CONFIG, noDataVariant = 'message', syncGroup, onDataZoom, onDoubleClick, __experimentalEChartsOptionsOverride }, ref) {
60
- const { chartsTheme, enablePinning, enableSyncGrouping, lastTooltipPinnedCoords, setLastTooltipPinnedCoords } = (0, _ChartsProvider.useChartsContext)();
61
- const isPinningEnabled = tooltipConfig.enablePinning && enablePinning;
62
- const chartRef = (0, _react.useRef)();
63
- const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
64
- const [tooltipPinnedCoords, setTooltipPinnedCoords] = (0, _react.useState)(null);
65
- const [pinnedCrosshair, setPinnedCrosshair] = (0, _react.useState)(null);
66
- const [isDragging, setIsDragging] = (0, _react.useState)(false);
67
- const [startX, setStartX] = (0, _react.useState)(0);
68
- const { timeZone } = (0, _TimeZoneProvider.useTimeZone)();
69
- let timeScale;
70
- if (timeScaleProp === undefined) {
71
- const commonTimeScale = (0, _core.getCommonTimeScale)(data);
72
- if (commonTimeScale === undefined) {
73
- // set default to past 5 years
74
- const today = new Date();
75
- const pastDate = new Date(today);
76
- pastDate.setFullYear(today.getFullYear() - 5);
77
- const todayMs = today.getTime();
78
- const pastDateMs = pastDate.getTime();
79
- timeScale = {
80
- startMs: pastDateMs,
81
- endMs: todayMs,
82
- stepMs: 1,
83
- rangeMs: todayMs - pastDateMs
84
- };
85
- } else {
86
- timeScale = commonTimeScale;
87
- }
88
- } else {
89
- timeScale = timeScaleProp;
90
- }
91
- (0, _react.useImperativeHandle)(ref, ()=>{
92
- return {
93
- highlightSeries ({ name }) {
94
- if (!chartRef.current) {
95
- // when chart undef, do not highlight series when hovering over legend
96
- return;
97
- }
98
- chartRef.current.dispatchAction({
99
- type: 'highlight',
100
- seriesId: name
101
- });
102
- },
103
- clearHighlightedSeries: ()=>{
104
- if (!chartRef.current) {
105
- // when chart undef, do not clear highlight series
106
- return;
107
- }
108
- (0, _utils.clearHighlightedSeries)(chartRef.current);
109
- }
110
- };
111
- }, []);
112
- const handleEvents = (0, _react.useMemo)(()=>{
113
- return {
114
- datazoom: (params)=>{
115
- if (onDataZoom === undefined) {
116
- setTimeout(()=>{
117
- // workaround so unpin happens after click event
118
- setTooltipPinnedCoords(null);
119
- }, 10);
120
- }
121
- if (onDataZoom === undefined || params.batch[0] === undefined) return;
122
- const xAxisStartValue = params.batch[0].startValue;
123
- const xAxisEndValue = params.batch[0].endValue;
124
- if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
125
- const zoomEvent = {
126
- start: xAxisStartValue,
127
- end: xAxisEndValue
128
- };
129
- onDataZoom(zoomEvent);
130
- }
131
- },
132
- finished: ()=>{
133
- if (chartRef.current !== undefined) {
134
- (0, _utils.enableDataZoom)(chartRef.current);
135
- }
136
- }
137
- };
138
- }, [
139
- onDataZoom,
140
- setTooltipPinnedCoords
141
- ]);
142
- const { noDataOption } = chartsTheme;
143
- const option = (0, _react.useMemo)(()=>{
144
- // The "chart" `noDataVariant` is only used when the `timeSeries` is an
145
- // empty array because a `null` value will throw an error.
146
- if (data === null || data.length === 0 && noDataVariant === 'message') return noDataOption;
147
- // Utilizes ECharts dataset so raw data is separate from series option style properties
148
- // https://apache.github.io/echarts-handbook/en/concepts/dataset/
149
- const dataset = [];
150
- const isLocalTimeZone = timeZone === 'local';
151
- data.map((d, index)=>{
152
- const values = d.values.map(([timestamp, value])=>{
153
- const val = value === null ? '-' : value; // echarts use '-' to represent null data
154
- return [
155
- isLocalTimeZone ? timestamp : (0, _datefnstz.toZonedTime)(timestamp, timeZone),
156
- val
157
- ];
158
- });
159
- dataset.push({
160
- id: index,
161
- source: [
162
- ...values
163
- ],
164
- dimensions: [
165
- 'time',
166
- 'value'
167
- ]
168
- });
169
- });
170
- const updatedSeriesMapping = enablePinning && pinnedCrosshair !== null ? [
171
- ...seriesMapping,
172
- pinnedCrosshair
173
- ] : seriesMapping;
174
- const option = {
175
- dataset: dataset,
176
- series: updatedSeriesMapping,
177
- xAxis: {
178
- type: 'time',
179
- min: isLocalTimeZone ? timeScale.startMs : (0, _datefnstz.toZonedTime)(timeScale.startMs, timeZone),
180
- max: isLocalTimeZone ? timeScale.endMs : (0, _datefnstz.toZonedTime)(timeScale.endMs, timeZone),
181
- axisLabel: {
182
- hideOverlap: true,
183
- formatter: (0, _utils.getFormattedAxisLabel)(timeScale.rangeMs ?? 0)
184
- },
185
- axisPointer: {
186
- snap: false
187
- }
188
- },
189
- yAxis: (0, _utils.getFormattedAxis)(yAxis, format),
190
- animation: false,
191
- tooltip: {
192
- show: true,
193
- // ECharts tooltip content hidden by default since we use custom tooltip instead.
194
- // Stacked bar uses ECharts tooltip so subgroup data shows correctly.
195
- showContent: isStackedBar,
196
- trigger: isStackedBar ? 'item' : 'axis',
197
- appendToBody: isStackedBar
198
- },
199
- // https://echarts.apache.org/en/option.html#axisPointer
200
- axisPointer: {
201
- type: 'line',
202
- z: 0,
203
- triggerEmphasis: false,
204
- triggerTooltip: false,
205
- snap: false
206
- },
207
- toolbox: {
208
- feature: {
209
- dataZoom: {
210
- icon: null,
211
- yAxisIndex: 'none'
212
- }
213
- }
214
- },
215
- grid
216
- };
217
- if (__experimentalEChartsOptionsOverride) {
218
- return __experimentalEChartsOptionsOverride(option);
219
- }
220
- return option;
221
- }, [
222
- data,
223
- seriesMapping,
224
- timeScale,
225
- yAxis,
226
- format,
227
- grid,
228
- noDataOption,
229
- __experimentalEChartsOptionsOverride,
230
- noDataVariant,
231
- timeZone,
232
- isStackedBar,
233
- enablePinning,
234
- pinnedCrosshair
235
- ]);
236
- // Update adjacent charts so tooltip is unpinned when current chart is clicked.
237
- (0, _react.useEffect)(()=>{
238
- // Only allow pinning one tooltip at a time, subsequent tooltip click unpins previous.
239
- // Multiple tooltips can only be pinned if Ctrl or Cmd key is pressed while clicking.
240
- const multipleTooltipsPinned = tooltipPinnedCoords !== null && lastTooltipPinnedCoords !== null;
241
- if (multipleTooltipsPinned) {
242
- if (!(0, _isEqual.default)(lastTooltipPinnedCoords, tooltipPinnedCoords)) {
243
- setTooltipPinnedCoords(null);
244
- if (tooltipPinnedCoords !== null && pinnedCrosshair !== null) {
245
- setPinnedCrosshair(null);
246
- }
247
- }
248
- }
249
- // tooltipPinnedCoords CANNOT be in dep array or tooltip pinning breaks in the current chart's onClick
250
- // eslint-disable-next-line react-hooks/exhaustive-deps
251
- }, [
252
- lastTooltipPinnedCoords,
253
- seriesMapping
254
- ]);
255
- return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
256
- style: {
257
- height
258
- },
259
- // onContextMenu={(e) => {
260
- // // TODO: confirm tooltip pinning works correctly on Windows, should e.preventDefault() be added here
261
- // e.preventDefault(); // Prevent the default behaviour when right clicked
262
- // }}
263
- onClick: (e)=>{
264
- // Allows user to opt-in to multi tooltip pinning when Ctrl or Cmd key held down
265
- const isControlKeyPressed = e.ctrlKey || e.metaKey;
266
- if (isControlKeyPressed) {
267
- e.preventDefault();
268
- }
269
- // Determine where on chart canvas to plot pinned crosshair as markLine.
270
- const pointInGrid = (0, _utils.getPointInGrid)(e.nativeEvent.offsetX, e.nativeEvent.offsetY, chartRef.current);
271
- if (pointInGrid === null) {
272
- return;
273
- }
274
- // Pin and unpin when clicking on chart canvas but not tooltip text.
275
- if (isPinningEnabled && e.target instanceof HTMLCanvasElement) {
276
- // Pin tooltip and update shared charts context to remember these coordinates.
277
- const pinnedPos = {
278
- page: {
279
- x: e.pageX,
280
- y: e.pageY
281
- },
282
- client: {
283
- x: e.clientX,
284
- y: e.clientY
285
- },
286
- plotCanvas: {
287
- x: e.nativeEvent.offsetX,
288
- y: e.nativeEvent.offsetY
289
- },
290
- target: e.target
291
- };
292
- setTooltipPinnedCoords((current)=>{
293
- if (current === null) {
294
- return pinnedPos;
295
- } else {
296
- setPinnedCrosshair(null);
297
- return null;
298
- }
299
- });
300
- setPinnedCrosshair((current)=>{
301
- // Only add pinned crosshair line series when there is not one already in seriesMapping.
302
- if (current === null) {
303
- const cursorX = pointInGrid[0];
304
- // Only need to loop through first dataset source since getCommonTimeScale ensures xAxis timestamps are consistent
305
- const firstTimeSeriesValues = data[0]?.values;
306
- const closestTimestamp = (0, _utils.getClosestTimestamp)(firstTimeSeriesValues, cursorX);
307
- // Crosshair snaps to nearest timestamp since cursor may be slightly to left or right
308
- const pinnedCrosshair = (0, _merge.default)({}, _model.DEFAULT_PINNED_CROSSHAIR, {
309
- markLine: {
310
- data: [
311
- {
312
- xAxis: closestTimestamp
313
- }
314
- ]
315
- }
316
- });
317
- return pinnedCrosshair;
318
- } else {
319
- // Clear previously set pinned crosshair
320
- return null;
321
- }
322
- });
323
- if (!isControlKeyPressed) {
324
- setLastTooltipPinnedCoords(pinnedPos);
325
- }
326
- }
327
- },
328
- onMouseDown: (e)=>{
329
- const { clientX } = e;
330
- setIsDragging(true);
331
- setStartX(clientX);
332
- },
333
- onMouseMove: (e)=>{
334
- // Allow clicking inside tooltip to copy labels.
335
- if (!(e.target instanceof HTMLCanvasElement)) {
336
- return;
337
- }
338
- const { clientX } = e;
339
- if (isDragging) {
340
- const deltaX = clientX - startX;
341
- if (deltaX > 0) {
342
- // Hide tooltip when user drags to zoom.
343
- setShowTooltip(false);
344
- }
345
- }
346
- },
347
- onMouseUp: ()=>{
348
- setIsDragging(false);
349
- setStartX(0);
350
- setShowTooltip(true);
351
- },
352
- onMouseLeave: ()=>{
353
- if (tooltipPinnedCoords === null) {
354
- setShowTooltip(false);
355
- }
356
- if (chartRef.current !== undefined) {
357
- (0, _utils.clearHighlightedSeries)(chartRef.current);
358
- }
359
- },
360
- onMouseEnter: ()=>{
361
- setShowTooltip(true);
362
- if (chartRef.current !== undefined) {
363
- (0, _utils.enableDataZoom)(chartRef.current);
364
- }
365
- },
366
- onDoubleClick: (e)=>{
367
- setTooltipPinnedCoords(null);
368
- // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
369
- if (onDoubleClick === undefined) {
370
- if (chartRef.current !== undefined) {
371
- (0, _utils.restoreChart)(chartRef.current);
372
- }
373
- } else {
374
- onDoubleClick(e);
375
- }
376
- },
377
- children: [
378
- showTooltip === true && option.tooltip?.showContent === false && tooltipConfig.hidden !== true && /*#__PURE__*/ (0, _jsxruntime.jsx)(_TimeSeriesTooltip.TimeChartTooltip, {
379
- containerId: chartsTheme.tooltipPortalContainerId,
380
- chartRef: chartRef,
381
- data: data,
382
- seriesMapping: seriesMapping,
383
- wrapLabels: tooltipConfig.wrapLabels,
384
- enablePinning: isPinningEnabled,
385
- pinnedPos: tooltipPinnedCoords,
386
- format: format,
387
- onUnpinClick: ()=>{
388
- // Unpins tooltip when clicking Pin icon in TooltipHeader.
389
- setTooltipPinnedCoords(null);
390
- // Clear previously set pinned crosshair.
391
- setPinnedCrosshair(null);
392
- }
393
- }),
394
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_EChart.EChart, {
395
- sx: {
396
- width: '100%',
397
- height: '100%'
398
- },
399
- option: option,
400
- theme: chartsTheme.echartsTheme,
401
- onEvents: handleEvents,
402
- _instance: chartRef,
403
- syncGroup: enableSyncGrouping ? syncGroup : undefined
404
- })
405
- ]
406
- });
407
- });