@perses-dev/components 0.31.0 → 0.32.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.
Files changed (89) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.d.ts +11 -0
  2. package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -0
  3. package/dist/ContentWithLegend/ContentWithLegend.js +65 -0
  4. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -0
  5. package/dist/ContentWithLegend/index.d.ts +2 -0
  6. package/dist/ContentWithLegend/index.d.ts.map +1 -0
  7. package/dist/ContentWithLegend/index.js +15 -0
  8. package/dist/ContentWithLegend/index.js.map +1 -0
  9. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +68 -0
  10. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -0
  11. package/dist/ContentWithLegend/model/content-with-legend-model.js +90 -0
  12. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -0
  13. package/dist/EChart/EChart.d.ts.map +1 -1
  14. package/dist/EChart/EChart.js +9 -1
  15. package/dist/EChart/EChart.js.map +1 -1
  16. package/dist/Legend/Legend.d.ts.map +1 -1
  17. package/dist/Legend/Legend.js +30 -15
  18. package/dist/Legend/Legend.js.map +1 -1
  19. package/dist/Legend/ListLegend.d.ts.map +1 -1
  20. package/dist/Legend/ListLegend.js +2 -23
  21. package/dist/Legend/ListLegend.js.map +1 -1
  22. package/dist/Legend/ListLegendItem.d.ts +1 -1
  23. package/dist/Legend/TableLegend.d.ts +12 -0
  24. package/dist/Legend/TableLegend.d.ts.map +1 -0
  25. package/dist/Legend/TableLegend.js +61 -0
  26. package/dist/Legend/TableLegend.js.map +1 -0
  27. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  28. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +35 -3
  29. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  30. package/dist/LineChart/LineChart.d.ts.map +1 -1
  31. package/dist/LineChart/LineChart.js +60 -22
  32. package/dist/LineChart/LineChart.js.map +1 -1
  33. package/dist/StatChart/StatChart.d.ts.map +1 -1
  34. package/dist/StatChart/StatChart.js +8 -1
  35. package/dist/StatChart/StatChart.js.map +1 -1
  36. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +5 -5
  37. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  38. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +36 -54
  39. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  40. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +0 -2
  41. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  42. package/dist/TimeSeriesTooltip/TooltipContent.js +21 -97
  43. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  44. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +12 -0
  45. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -0
  46. package/dist/TimeSeriesTooltip/TooltipHeader.js +163 -0
  47. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -0
  48. package/dist/TimeSeriesTooltip/index.d.ts +1 -0
  49. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  50. package/dist/TimeSeriesTooltip/index.js +1 -0
  51. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  52. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
  53. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  54. package/dist/TimeSeriesTooltip/nearby-series.js +2 -2
  55. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  56. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +10 -14
  57. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  58. package/dist/TimeSeriesTooltip/tooltip-model.js +2 -1
  59. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  60. package/dist/TimeSeriesTooltip/utils.js +2 -2
  61. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  62. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
  63. package/dist/cjs/ContentWithLegend/index.js +28 -0
  64. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
  65. package/dist/cjs/EChart/EChart.js +9 -1
  66. package/dist/cjs/Legend/Legend.js +30 -15
  67. package/dist/cjs/Legend/ListLegend.js +2 -23
  68. package/dist/cjs/Legend/TableLegend.js +67 -0
  69. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
  70. package/dist/cjs/LineChart/LineChart.js +60 -22
  71. package/dist/cjs/StatChart/StatChart.js +8 -1
  72. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +34 -91
  73. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +19 -100
  74. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +174 -0
  75. package/dist/cjs/TimeSeriesTooltip/index.js +1 -0
  76. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -2
  77. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +3 -1
  78. package/dist/cjs/TimeSeriesTooltip/utils.js +2 -2
  79. package/dist/cjs/index.js +1 -0
  80. package/dist/cjs/model/legend.js +30 -1
  81. package/dist/index.d.ts +1 -0
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +1 -0
  84. package/dist/index.js.map +1 -1
  85. package/dist/model/legend.d.ts +9 -3
  86. package/dist/model/legend.d.ts.map +1 -1
  87. package/dist/model/legend.js +26 -1
  88. package/dist/model/legend.js.map +1 -1
  89. package/package.json +3 -3
@@ -0,0 +1,67 @@
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, "TableLegend", {
18
+ enumerable: true,
19
+ get: ()=>TableLegend
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _table = require("../Table");
24
+ const COLUMNS = [
25
+ {
26
+ accessorKey: 'label',
27
+ header: 'Name',
28
+ // Starting with `title` attr instead of a tooltip because it is easier to
29
+ // implement. We should try adding a tooltip in the future, but we'll need
30
+ // to be very careful about performance when doing so with large tables.
31
+ cell: ({ getValue })=>/*#__PURE__*/ (0, _jsxRuntime.jsx)("span", {
32
+ title: getValue(),
33
+ children: getValue()
34
+ })
35
+ }
36
+ ];
37
+ const getRowId = (data)=>{
38
+ return data.id;
39
+ };
40
+ const getCheckboxColor = (data)=>{
41
+ return data.color;
42
+ };
43
+ function TableLegend({ items , selectedItems: initRowSelection , onSelectedItemsChange , height , width }) {
44
+ const rowSelection = (0, _react.useMemo)(()=>{
45
+ return typeof initRowSelection !== 'string' ? initRowSelection : // items for checkboxes.
46
+ // TODO: clean this up if we switch to also using checkboxes in list legend.
47
+ items.reduce((allRowSelection, item, index)=>{
48
+ allRowSelection[getRowId(item, index)] = true;
49
+ return allRowSelection;
50
+ }, {});
51
+ }, [
52
+ initRowSelection,
53
+ items
54
+ ]);
55
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_table.Table, {
56
+ height: height,
57
+ width: width,
58
+ rowSelection: rowSelection,
59
+ onRowSelectionChange: onSelectedItemsChange,
60
+ data: items,
61
+ columns: COLUMNS,
62
+ density: "compact",
63
+ getRowId: getRowId,
64
+ getCheckboxColor: getCheckboxColor,
65
+ checkboxSelection: true
66
+ });
67
+ }
@@ -29,6 +29,12 @@ const POSITION_OPTIONS = Object.entries(_model.LEGEND_POSITIONS_CONFIG).map(([id
29
29
  ...config
30
30
  };
31
31
  });
32
+ const MODE_OPTIONS = Object.entries(_model.LEGEND_MODE_CONFIG).map(([id, config])=>{
33
+ return {
34
+ id: id,
35
+ ...config
36
+ };
37
+ });
32
38
  function LegendOptionsEditor({ value , onChange }) {
33
39
  const handleLegendShowChange = (_, checked)=>{
34
40
  // legend is hidden when legend obj is undefined
@@ -43,9 +49,18 @@ function LegendOptionsEditor({ value , onChange }) {
43
49
  position: newValue.id
44
50
  });
45
51
  };
52
+ const handleLegendModeChange = (_, newValue)=>{
53
+ onChange({
54
+ ...value,
55
+ position: currentPosition,
56
+ mode: newValue.id
57
+ });
58
+ };
46
59
  const isValidLegend = (0, _model.validateLegendSpec)(value);
47
60
  const currentPosition = (0, _model.getLegendPosition)(value === null || value === void 0 ? void 0 : value.position);
48
- const legendConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
61
+ const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
62
+ const currentMode = (0, _model.getLegendMode)(value === null || value === void 0 ? void 0 : value.mode);
63
+ const legendModeConfig = _model.LEGEND_MODE_CONFIG[currentMode];
49
64
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
50
65
  children: [
51
66
  !isValidLegend && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_errorAlert.ErrorAlert, {
@@ -65,7 +80,7 @@ function LegendOptionsEditor({ value , onChange }) {
65
80
  label: "Position",
66
81
  control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
67
82
  value: {
68
- ...legendConfig,
83
+ ...legendPositionConfig,
69
84
  id: currentPosition
70
85
  },
71
86
  options: POSITION_OPTIONS,
@@ -77,6 +92,23 @@ function LegendOptionsEditor({ value , onChange }) {
77
92
  disabled: value === undefined,
78
93
  disableClearable: true
79
94
  })
95
+ }),
96
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
97
+ label: "Mode",
98
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
99
+ value: {
100
+ ...legendModeConfig,
101
+ id: currentMode
102
+ },
103
+ options: MODE_OPTIONS,
104
+ isOptionEqualToValue: (option, value)=>option.id === value.id,
105
+ renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
106
+ ...params
107
+ }),
108
+ onChange: handleLegendModeChange,
109
+ disabled: value === undefined,
110
+ disableClearable: true
111
+ })
80
112
  })
81
113
  ]
82
114
  });
@@ -89,15 +89,17 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
89
89
  const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
90
90
  const chartRef = (0, _react.useRef)();
91
91
  const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
92
- const [isTooltipPinned, setIsTooltipPinned] = (0, _react.useState)(false);
92
+ const [tooltipPinnedCoords, setTooltipPinnedCoords] = (0, _react.useState)(null);
93
93
  const { timeZone } = (0, _timeZoneProvider.useTimeZone)();
94
+ const [isDragging, setIsDragging] = (0, _react.useState)(false);
95
+ const [startX, setStartX] = (0, _react.useState)(0);
94
96
  const handleEvents = (0, _react.useMemo)(()=>{
95
97
  return {
96
98
  datazoom: (params)=>{
97
99
  if (onDataZoom === undefined) {
98
100
  setTimeout(()=>{
99
101
  // workaround so unpin happens after click event
100
- setIsTooltipPinned(false);
102
+ setTooltipPinnedCoords(null);
101
103
  }, 10);
102
104
  }
103
105
  if (onDataZoom === undefined || params.batch[0] === undefined) return;
@@ -121,22 +123,11 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
121
123
  }, [
122
124
  data,
123
125
  onDataZoom,
124
- setIsTooltipPinned
126
+ setTooltipPinnedCoords
125
127
  ]);
126
128
  if (chartRef.current !== undefined) {
127
129
  (0, _utils.enableDataZoom)(chartRef.current);
128
130
  }
129
- const handleOnDoubleClick = (e)=>{
130
- setIsTooltipPinned(false);
131
- // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
132
- if (onDoubleClick === undefined) {
133
- if (chartRef.current !== undefined) {
134
- (0, _utils.restoreChart)(chartRef.current);
135
- }
136
- } else {
137
- onDoubleClick(e);
138
- }
139
- };
140
131
  const { noDataOption } = chartsTheme;
141
132
  const option = (0, _react.useMemo)(()=>{
142
133
  if (data.timeSeries === undefined) return {};
@@ -205,20 +196,57 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
205
196
  onClick: (e)=>{
206
197
  // Pin and unpin when clicking on chart canvas but not tooltip text.
207
198
  if (e.target instanceof HTMLCanvasElement) {
208
- setIsTooltipPinned((current)=>!current);
199
+ setTooltipPinnedCoords((current)=>{
200
+ if (current === null) {
201
+ return {
202
+ page: {
203
+ x: e.pageX,
204
+ y: e.pageY
205
+ },
206
+ client: {
207
+ x: e.clientX,
208
+ y: e.clientY
209
+ },
210
+ plotCanvas: {
211
+ x: e.nativeEvent.offsetX,
212
+ y: e.nativeEvent.offsetY
213
+ },
214
+ target: e.target
215
+ };
216
+ } else {
217
+ return null;
218
+ }
219
+ });
209
220
  }
210
221
  },
211
222
  onMouseDown: (e)=>{
212
- // Hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels.
213
- if (e.target instanceof HTMLCanvasElement) {
214
- setShowTooltip(false);
223
+ const { clientX } = e;
224
+ setIsDragging(true);
225
+ setStartX(clientX);
226
+ },
227
+ onMouseMove: (e)=>{
228
+ // Allow clicking inside tooltip to copy labels.
229
+ if (!(e.target instanceof HTMLCanvasElement)) {
230
+ return;
231
+ }
232
+ const { clientX } = e;
233
+ if (isDragging) {
234
+ const deltaX = clientX - startX;
235
+ if (deltaX > 0) {
236
+ // Hide tooltip when user drags to zoom.
237
+ setShowTooltip(false);
238
+ }
215
239
  }
216
240
  },
217
241
  onMouseUp: ()=>{
242
+ setIsDragging(false);
243
+ setStartX(0);
218
244
  setShowTooltip(true);
219
245
  },
220
246
  onMouseLeave: ()=>{
221
- setShowTooltip(false);
247
+ if (tooltipPinnedCoords === null) {
248
+ setShowTooltip(false);
249
+ }
222
250
  },
223
251
  onMouseEnter: ()=>{
224
252
  setShowTooltip(true);
@@ -226,16 +254,26 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
226
254
  (0, _utils.enableDataZoom)(chartRef.current);
227
255
  }
228
256
  },
229
- onDoubleClick: handleOnDoubleClick,
257
+ onDoubleClick: (e)=>{
258
+ setTooltipPinnedCoords(null);
259
+ // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
260
+ if (onDoubleClick === undefined) {
261
+ if (chartRef.current !== undefined) {
262
+ (0, _utils.restoreChart)(chartRef.current);
263
+ }
264
+ } else {
265
+ onDoubleClick(e);
266
+ }
267
+ },
230
268
  children: [
231
269
  showTooltip === true && ((ref = option.tooltip) === null || ref === void 0 ? void 0 : ref.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesTooltip.TimeSeriesTooltip, {
232
270
  chartRef: chartRef,
233
271
  chartData: data,
234
272
  wrapLabels: tooltipConfig.wrapLabels,
235
- isTooltipPinned: isTooltipPinned,
273
+ pinnedPos: tooltipPinnedCoords,
236
274
  unit: unit,
237
275
  onUnpinClick: ()=>{
238
- setIsTooltipPinned(false);
276
+ setTooltipPinnedCoords(null);
239
277
  }
240
278
  }),
241
279
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
@@ -80,7 +80,14 @@ function StatChart(props) {
80
80
  },
81
81
  yAxis: {
82
82
  type: 'value',
83
- show: false
83
+ show: false,
84
+ min: (value)=>{
85
+ if (value.min >= 0 && value.min <= 1) {
86
+ // helps with PercentDecimal units, or datasets that return 0 or 1 booleans
87
+ return 0;
88
+ }
89
+ return value.min;
90
+ }
84
91
  },
85
92
  tooltip: {
86
93
  show: false
@@ -20,9 +20,10 @@ Object.defineProperty(exports, "TimeSeriesTooltip", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
+ const _react = require("react");
24
24
  const _useResizeObserver = /*#__PURE__*/ _interopRequireDefault(require("use-resize-observer"));
25
25
  const _tooltipContent = require("./TooltipContent");
26
+ const _tooltipHeader = require("./TooltipHeader");
26
27
  const _nearbySeries = require("./nearby-series");
27
28
  const _tooltipModel = require("./tooltip-model");
28
29
  const _utils = require("./utils");
@@ -31,59 +32,20 @@ function _interopRequireDefault(obj) {
31
32
  default: obj
32
33
  };
33
34
  }
34
- function _getRequireWildcardCache(nodeInterop) {
35
- if (typeof WeakMap !== "function") return null;
36
- var cacheBabelInterop = new WeakMap();
37
- var cacheNodeInterop = new WeakMap();
38
- return (_getRequireWildcardCache = function(nodeInterop) {
39
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
40
- })(nodeInterop);
41
- }
42
- function _interopRequireWildcard(obj, nodeInterop) {
43
- if (!nodeInterop && obj && obj.__esModule) {
44
- return obj;
45
- }
46
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
47
- return {
48
- default: obj
49
- };
50
- }
51
- var cache = _getRequireWildcardCache(nodeInterop);
52
- if (cache && cache.has(obj)) {
53
- return cache.get(obj);
54
- }
55
- var newObj = {};
56
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
57
- for(var key in obj){
58
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
59
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
60
- if (desc && (desc.get || desc.set)) {
61
- Object.defineProperty(newObj, key, desc);
62
- } else {
63
- newObj[key] = obj[key];
64
- }
65
- }
66
- }
67
- newObj.default = obj;
68
- if (cache) {
69
- cache.set(obj, newObj);
70
- }
71
- return newObj;
72
- }
73
- const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , isTooltipPinned , unit , onUnpinClick }) {
35
+ const TimeSeriesTooltip = /*#__PURE__*/ (0, _react.memo)(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , unit , onUnpinClick , pinnedPos }) {
74
36
  const [showAllSeries, setShowAllSeries] = (0, _react.useState)(false);
75
- const [pinnedPos, setPinnedPos] = (0, _react.useState)(null);
76
37
  const mousePos = (0, _tooltipModel.useMousePosition)();
77
38
  const { height , width , ref: tooltipRef } = (0, _useResizeObserver.default)();
39
+ const isTooltipPinned = pinnedPos !== null;
78
40
  if (mousePos === null || mousePos.target === null) return null;
79
41
  // Ensure user is hovering over a chart before checking for nearby series.
80
42
  if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
81
43
  const chart = chartRef.current;
82
44
  var ref;
83
- 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 every be needed.
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.
84
46
  const cursorTransform = (0, _utils.assembleTransform)(mousePos, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
85
47
  // Get series nearby the cursor and pass into tooltip content children.
86
- const focusedSeries = (0, _nearbySeries.getNearbySeriesData)({
48
+ const nearbySeries = (0, _nearbySeries.getNearbySeriesData)({
87
49
  mousePos,
88
50
  chartData,
89
51
  pinnedPos,
@@ -91,27 +53,25 @@ const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesT
91
53
  unit,
92
54
  showAllSeries
93
55
  });
94
- if (focusedSeries.length === 0) {
56
+ if (nearbySeries.length === 0) {
95
57
  return null;
96
58
  }
97
- if (isTooltipPinned === true && pinnedPos === null) {
98
- setPinnedPos(mousePos);
99
- }
100
- // Option for user to see all series instead of only the nearby focused series.
101
- // Only relevant when there are more total series than are visible.
102
- const showAllSeriesToggle = isTooltipPinned === true && showAllSeries === false && chartData.timeSeries.length > 1 && focusedSeries.length !== chartData.timeSeries.length;
59
+ const totalSeries = chartData.timeSeries.length;
60
+ var ref1;
103
61
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Portal, {
104
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
62
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
105
63
  ref: tooltipRef,
106
- sx: (theme)=>({
64
+ sx: (theme)=>{
65
+ var ref;
66
+ return {
107
67
  minWidth: _tooltipModel.TOOLTIP_MIN_WIDTH,
108
68
  maxWidth: _tooltipModel.TOOLTIP_MAX_WIDTH,
109
69
  maxHeight: _tooltipModel.TOOLTIP_MAX_HEIGHT,
110
- padding: theme.spacing(0.5, 2),
70
+ padding: 0,
111
71
  position: 'absolute',
112
72
  top: 0,
113
73
  left: 0,
114
- backgroundColor: '#2E313E',
74
+ backgroundColor: (ref1 = (ref = theme.palette.designSystem) === null || ref === void 0 ? void 0 : ref.grey[800]) !== null && ref1 !== void 0 ? ref1 : _tooltipModel.TOOLTIP_BG_COLOR_FALLBACK,
115
75
  borderRadius: '6px',
116
76
  color: '#fff',
117
77
  fontSize: '11px',
@@ -123,45 +83,28 @@ const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesT
123
83
  '&:hover': {
124
84
  overflowY: 'auto'
125
85
  }
126
- }),
86
+ };
87
+ },
127
88
  style: {
128
89
  transform: cursorTransform
129
90
  },
130
- children: [
131
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipContent.TooltipContent, {
132
- series: focusedSeries,
133
- wrapLabels: wrapLabels,
134
- isTooltipPinned: isTooltipPinned,
135
- onUnpinClick: ()=>{
136
- setPinnedPos(null);
137
- if (onUnpinClick !== undefined) {
138
- onUnpinClick();
139
- }
140
- }
141
- }),
142
- showAllSeriesToggle && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
143
- direction: "row",
144
- gap: 1,
145
- alignItems: "center",
146
- sx: {
147
- textAlign: 'right'
148
- },
149
- children: [
150
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
151
- children: "Show All?"
152
- }),
153
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
154
- checked: showAllSeries,
155
- onChange: (_, checked)=>setShowAllSeries(checked),
156
- sx: (theme)=>({
157
- '& .MuiSwitch-switchBase': {
158
- color: theme.palette.common.white
159
- }
160
- })
161
- })
162
- ]
163
- })
164
- ]
91
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
92
+ spacing: 0.5,
93
+ children: [
94
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipHeader.TooltipHeader, {
95
+ nearbySeries: nearbySeries,
96
+ totalSeries: totalSeries,
97
+ isTooltipPinned: isTooltipPinned,
98
+ showAllSeries: showAllSeries,
99
+ onShowAllClick: (checked)=>setShowAllSeries(checked),
100
+ onUnpinClick: onUnpinClick
101
+ }),
102
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipContent.TooltipContent, {
103
+ series: nearbySeries,
104
+ wrapLabels: wrapLabels
105
+ })
106
+ ]
107
+ })
165
108
  })
166
109
  });
167
110
  });
@@ -20,118 +20,37 @@ Object.defineProperty(exports, "TooltipContent", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _react = require("react");
23
- const _pinOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOutline"));
24
- const _pin = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pin"));
25
23
  const _material = require("@mui/material");
26
- const _timeZoneProvider = require("../context/TimeZoneProvider");
27
24
  const _seriesInfo = require("./SeriesInfo");
28
- function _interopRequireDefault(obj) {
29
- return obj && obj.__esModule ? obj : {
30
- default: obj
31
- };
32
- }
33
25
  function TooltipContent(props) {
34
- const { series , wrapLabels , isTooltipPinned , onUnpinClick } = props;
35
- const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
36
- const seriesTime = series && series[0] && series[0].date ? series[0].date : null;
37
- const formatTimeSeriesHeader = (timeMs)=>{
38
- const date = new Date(timeMs);
39
- const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
40
- const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');
41
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
42
- children: [
43
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
44
- variant: "caption",
45
- sx: (theme)=>({
46
- color: theme.palette.common.white
47
- }),
48
- children: formattedDate
49
- }),
50
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
51
- variant: "caption",
52
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("strong", {
53
- children: formattedTime
54
- })
55
- })
56
- ]
57
- });
58
- };
26
+ const { series , wrapLabels } = props;
59
27
  const sortedFocusedSeries = (0, _react.useMemo)(()=>{
60
28
  if (series === null) return null;
61
29
  return series.sort((a, b)=>a.y > b.y ? -1 : 1);
62
30
  }, [
63
31
  series
64
32
  ]);
65
- if (sortedFocusedSeries === null || seriesTime === null) {
33
+ if (series === null || sortedFocusedSeries === null) {
66
34
  return null;
67
35
  }
68
36
  // TODO: use react-virtuoso to improve performance
69
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
70
- py: 1,
71
- spacing: 0.5,
72
- children: [
73
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
74
- sx: {
75
- display: 'flex',
76
- justifyContent: 'start',
77
- alignItems: 'center'
78
- },
79
- children: [
80
- formatTimeSeriesHeader(seriesTime),
81
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
82
- direction: "row",
83
- gap: 1,
84
- sx: {
85
- marginLeft: 'auto'
86
- },
87
- children: [
88
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Typography, {
89
- sx: {
90
- fontSize: 11
91
- },
92
- children: [
93
- "Click to ",
94
- isTooltipPinned ? 'Unpin' : 'Pin'
95
- ]
96
- }),
97
- isTooltipPinned ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pin.default, {
98
- onClick: onUnpinClick,
99
- sx: {
100
- fontSize: 16,
101
- cursor: 'pointer'
102
- }
103
- }) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOutline.default, {
104
- sx: {
105
- fontSize: 16
106
- }
107
- })
108
- ]
109
- })
110
- ]
111
- }),
112
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {
113
- sx: (theme)=>({
114
- borderColor: theme.palette.grey['500']
115
- })
37
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
38
+ sx: (theme)=>({
39
+ display: 'table',
40
+ padding: theme.spacing(0.5, 2)
116
41
  }),
117
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
118
- sx: {
119
- display: 'table'
120
- },
121
- children: sortedFocusedSeries.map(({ datumIdx , seriesIdx , seriesName , y , formattedY , markerColor , isClosestToCursor })=>{
122
- if (datumIdx === null || seriesIdx === null) return null;
123
- const key = seriesIdx.toString() + datumIdx.toString();
124
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_seriesInfo.SeriesInfo, {
125
- seriesName: seriesName,
126
- y: y,
127
- formattedY: formattedY,
128
- markerColor: markerColor,
129
- totalSeries: sortedFocusedSeries.length,
130
- wrapLabels: wrapLabels,
131
- emphasizeText: isClosestToCursor
132
- }, key);
133
- })
134
- })
135
- ]
42
+ children: sortedFocusedSeries.map(({ datumIdx , seriesIdx , seriesName , y , formattedY , markerColor , isClosestToCursor })=>{
43
+ if (datumIdx === null || seriesIdx === null) return null;
44
+ const key = seriesIdx.toString() + datumIdx.toString();
45
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_seriesInfo.SeriesInfo, {
46
+ seriesName: seriesName,
47
+ y: y,
48
+ formattedY: formattedY,
49
+ markerColor: markerColor,
50
+ totalSeries: sortedFocusedSeries.length,
51
+ wrapLabels: wrapLabels,
52
+ emphasizeText: isClosestToCursor
53
+ }, key);
54
+ })
136
55
  });
137
56
  }