@perses-dev/components 0.30.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 (187) 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/CompactLegend.d.ts +6 -4
  17. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  18. package/dist/Legend/CompactLegend.js +4 -1
  19. package/dist/Legend/CompactLegend.js.map +1 -1
  20. package/dist/Legend/Legend.d.ts +11 -9
  21. package/dist/Legend/Legend.d.ts.map +1 -1
  22. package/dist/Legend/Legend.js +70 -21
  23. package/dist/Legend/Legend.js.map +1 -1
  24. package/dist/Legend/ListLegend.d.ts +5 -8
  25. package/dist/Legend/ListLegend.d.ts.map +1 -1
  26. package/dist/Legend/ListLegend.js +17 -103
  27. package/dist/Legend/ListLegend.js.map +1 -1
  28. package/dist/Legend/ListLegendItem.d.ts +8 -8
  29. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  30. package/dist/Legend/ListLegendItem.js +9 -12
  31. package/dist/Legend/ListLegendItem.js.map +1 -1
  32. package/dist/Legend/TableLegend.d.ts +12 -0
  33. package/dist/Legend/TableLegend.d.ts.map +1 -0
  34. package/dist/Legend/TableLegend.js +61 -0
  35. package/dist/Legend/TableLegend.js.map +1 -0
  36. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  37. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +35 -3
  38. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  39. package/dist/LineChart/LineChart.d.ts +2 -1
  40. package/dist/LineChart/LineChart.d.ts.map +1 -1
  41. package/dist/LineChart/LineChart.js +83 -36
  42. package/dist/LineChart/LineChart.js.map +1 -1
  43. package/dist/StatChart/StatChart.d.ts.map +1 -1
  44. package/dist/StatChart/StatChart.js +8 -1
  45. package/dist/StatChart/StatChart.js.map +1 -1
  46. package/dist/Table/InnerTable.d.ts +9 -0
  47. package/dist/Table/InnerTable.d.ts.map +1 -0
  48. package/dist/Table/InnerTable.js +38 -0
  49. package/dist/Table/InnerTable.js.map +1 -0
  50. package/dist/Table/Table.d.ts +10 -0
  51. package/dist/Table/Table.d.ts.map +1 -0
  52. package/dist/Table/Table.js +101 -0
  53. package/dist/Table/Table.js.map +1 -0
  54. package/dist/Table/TableBody.d.ts +6 -0
  55. package/dist/Table/TableBody.d.ts.map +1 -0
  56. package/dist/Table/TableBody.js +23 -0
  57. package/dist/Table/TableBody.js.map +1 -0
  58. package/dist/Table/TableCell.d.ts +18 -0
  59. package/dist/Table/TableCell.d.ts.map +1 -0
  60. package/dist/Table/TableCell.js +91 -0
  61. package/dist/Table/TableCell.js.map +1 -0
  62. package/dist/Table/TableCheckbox.d.ts +9 -0
  63. package/dist/Table/TableCheckbox.d.ts.map +1 -0
  64. package/dist/Table/TableCheckbox.js +49 -0
  65. package/dist/Table/TableCheckbox.js.map +1 -0
  66. package/dist/Table/TableHead.d.ts +6 -0
  67. package/dist/Table/TableHead.d.ts.map +1 -0
  68. package/dist/Table/TableHead.js +23 -0
  69. package/dist/Table/TableHead.js.map +1 -0
  70. package/dist/Table/TableRow.d.ts +9 -0
  71. package/dist/Table/TableRow.d.ts.map +1 -0
  72. package/dist/Table/TableRow.js +29 -0
  73. package/dist/Table/TableRow.js.map +1 -0
  74. package/dist/Table/VirtualizedTable.d.ts +11 -0
  75. package/dist/Table/VirtualizedTable.d.ts.map +1 -0
  76. package/dist/Table/VirtualizedTable.js +152 -0
  77. package/dist/Table/VirtualizedTable.js.map +1 -0
  78. package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
  79. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
  80. package/dist/Table/VirtualizedTableContainer.js +24 -0
  81. package/dist/Table/VirtualizedTableContainer.js.map +1 -0
  82. package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
  83. package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
  84. package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
  85. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
  86. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
  87. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
  88. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
  89. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
  90. package/dist/Table/index.d.ts +4 -0
  91. package/dist/Table/index.d.ts.map +1 -0
  92. package/dist/Table/index.js +16 -0
  93. package/dist/Table/index.js.map +1 -0
  94. package/dist/Table/model/table-model.d.ts +83 -0
  95. package/dist/Table/model/table-model.d.ts.map +1 -0
  96. package/dist/Table/model/table-model.js +73 -0
  97. package/dist/Table/model/table-model.js.map +1 -0
  98. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
  99. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  100. package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
  101. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  102. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +6 -5
  103. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  104. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +48 -21
  105. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  106. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +3 -3
  107. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  108. package/dist/TimeSeriesTooltip/TooltipContent.js +28 -67
  109. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  110. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +12 -0
  111. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -0
  112. package/dist/TimeSeriesTooltip/TooltipHeader.js +163 -0
  113. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -0
  114. package/dist/TimeSeriesTooltip/index.d.ts +2 -1
  115. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  116. package/dist/TimeSeriesTooltip/index.js +2 -1
  117. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  118. package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
  119. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
  120. package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
  121. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
  122. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +17 -17
  123. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  124. package/dist/TimeSeriesTooltip/tooltip-model.js +7 -2
  125. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  126. package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
  127. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  128. package/dist/TimeSeriesTooltip/utils.js +6 -5
  129. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  130. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
  131. package/dist/cjs/ContentWithLegend/index.js +28 -0
  132. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
  133. package/dist/cjs/EChart/EChart.js +9 -1
  134. package/dist/cjs/Legend/CompactLegend.js +4 -1
  135. package/dist/cjs/Legend/Legend.js +70 -21
  136. package/dist/cjs/Legend/ListLegend.js +17 -103
  137. package/dist/cjs/Legend/ListLegendItem.js +8 -11
  138. package/dist/cjs/Legend/TableLegend.js +67 -0
  139. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
  140. package/dist/cjs/LineChart/LineChart.js +83 -36
  141. package/dist/cjs/StatChart/StatChart.js +8 -1
  142. package/dist/cjs/Table/InnerTable.js +44 -0
  143. package/dist/cjs/Table/Table.js +102 -0
  144. package/dist/cjs/Table/TableBody.js +29 -0
  145. package/dist/cjs/Table/TableCell.js +97 -0
  146. package/dist/cjs/Table/TableCheckbox.js +55 -0
  147. package/dist/cjs/Table/TableHead.js +29 -0
  148. package/dist/cjs/Table/TableRow.js +35 -0
  149. package/dist/cjs/Table/VirtualizedTable.js +155 -0
  150. package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
  151. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
  152. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
  153. package/dist/cjs/Table/index.js +33 -0
  154. package/dist/cjs/Table/model/table-model.js +80 -0
  155. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
  156. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +45 -57
  157. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +26 -65
  158. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +174 -0
  159. package/dist/cjs/TimeSeriesTooltip/index.js +2 -1
  160. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
  161. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +13 -3
  162. package/dist/cjs/TimeSeriesTooltip/utils.js +5 -4
  163. package/dist/cjs/context/SnackbarProvider.js +66 -0
  164. package/dist/cjs/index.js +3 -0
  165. package/dist/cjs/model/legend.js +37 -2
  166. package/dist/cjs/theme/palette/grey.js +6 -2
  167. package/dist/context/SnackbarProvider.d.ts +23 -0
  168. package/dist/context/SnackbarProvider.d.ts.map +1 -0
  169. package/dist/context/SnackbarProvider.js +59 -0
  170. package/dist/context/SnackbarProvider.js.map +1 -0
  171. package/dist/index.d.ts +3 -0
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +3 -0
  174. package/dist/index.js.map +1 -1
  175. package/dist/model/legend.d.ts +19 -5
  176. package/dist/model/legend.d.ts.map +1 -1
  177. package/dist/model/legend.js +31 -1
  178. package/dist/model/legend.js.map +1 -1
  179. package/dist/theme/palette/grey.d.ts.map +1 -1
  180. package/dist/theme/palette/grey.js +6 -2
  181. package/dist/theme/palette/grey.js.map +1 -1
  182. package/package.json +6 -6
  183. package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
  184. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
  185. package/dist/TimeSeriesTooltip/focused-series.js +0 -110
  186. package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
  187. package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -116
@@ -20,10 +20,11 @@ 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 _focusedSeries = require("./focused-series");
26
+ const _tooltipHeader = require("./TooltipHeader");
27
+ const _nearbySeries = require("./nearby-series");
27
28
  const _tooltipModel = require("./tooltip-model");
28
29
  const _utils = require("./utils");
29
30
  function _interopRequireDefault(obj) {
@@ -31,73 +32,46 @@ 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 , pinTooltip , unit }) {
74
- const [pinnedPos, setPinnedPos] = (0, _react.useState)(null);
35
+ const TimeSeriesTooltip = /*#__PURE__*/ (0, _react.memo)(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , unit , onUnpinClick , pinnedPos }) {
36
+ const [showAllSeries, setShowAllSeries] = (0, _react.useState)(false);
75
37
  const mousePos = (0, _tooltipModel.useMousePosition)();
76
38
  const { height , width , ref: tooltipRef } = (0, _useResizeObserver.default)();
39
+ const isTooltipPinned = pinnedPos !== null;
77
40
  if (mousePos === null || mousePos.target === null) return null;
78
- // ensure user is hovering over a chart before checking for nearby series
41
+ // Ensure user is hovering over a chart before checking for nearby series.
79
42
  if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
80
43
  const chart = chartRef.current;
81
- const focusedSeries = (0, _focusedSeries.getFocusedSeriesData)(mousePos, chartData, pinnedPos, chart, unit);
82
44
  var ref;
83
- const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : 750;
84
- const cursorTransform = (0, _utils.assembleTransform)(mousePos, focusedSeries.length, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
85
- if (focusedSeries.length === 0) {
45
+ const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : _tooltipModel.FALLBACK_CHART_WIDTH; // Fallback width not likely to ever be needed.
46
+ const cursorTransform = (0, _utils.assembleTransform)(mousePos, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
47
+ // Get series nearby the cursor and pass into tooltip content children.
48
+ const nearbySeries = (0, _nearbySeries.getNearbySeriesData)({
49
+ mousePos,
50
+ chartData,
51
+ pinnedPos,
52
+ chart,
53
+ unit,
54
+ showAllSeries
55
+ });
56
+ if (nearbySeries.length === 0) {
86
57
  return null;
87
58
  }
88
- if (pinTooltip === true && pinnedPos === null) {
89
- setPinnedPos(mousePos);
90
- }
59
+ const totalSeries = chartData.timeSeries.length;
60
+ var ref1;
91
61
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Portal, {
92
62
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
93
63
  ref: tooltipRef,
94
- sx: (theme)=>({
64
+ sx: (theme)=>{
65
+ var ref;
66
+ return {
67
+ minWidth: _tooltipModel.TOOLTIP_MIN_WIDTH,
95
68
  maxWidth: _tooltipModel.TOOLTIP_MAX_WIDTH,
96
69
  maxHeight: _tooltipModel.TOOLTIP_MAX_HEIGHT,
70
+ padding: 0,
97
71
  position: 'absolute',
98
72
  top: 0,
99
73
  left: 0,
100
- 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,
101
75
  borderRadius: '6px',
102
76
  color: '#fff',
103
77
  fontSize: '11px',
@@ -109,13 +83,27 @@ const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesT
109
83
  '&:hover': {
110
84
  overflowY: 'auto'
111
85
  }
112
- }),
86
+ };
87
+ },
113
88
  style: {
114
89
  transform: cursorTransform
115
90
  },
116
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipContent.TooltipContent, {
117
- focusedSeries: focusedSeries,
118
- wrapLabels: wrapLabels
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
+ ]
119
107
  })
120
108
  })
121
109
  });
@@ -21,75 +21,36 @@ Object.defineProperty(exports, "TooltipContent", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _react = require("react");
23
23
  const _material = require("@mui/material");
24
- const _timeZoneProvider = require("../context/TimeZoneProvider");
25
24
  const _seriesInfo = require("./SeriesInfo");
26
25
  function TooltipContent(props) {
27
- const { focusedSeries , wrapLabels } = props;
28
- const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
29
- const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;
30
- const formatTimeSeriesHeader = (timeMs)=>{
31
- const date = new Date(timeMs);
32
- const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
33
- const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');
34
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
35
- children: [
36
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
37
- variant: "caption",
38
- sx: (theme)=>({
39
- color: theme.palette.common.white
40
- }),
41
- children: formattedDate
42
- }),
43
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
44
- variant: "caption",
45
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("strong", {
46
- children: formattedTime
47
- })
48
- })
49
- ]
50
- });
51
- };
26
+ const { series , wrapLabels } = props;
52
27
  const sortedFocusedSeries = (0, _react.useMemo)(()=>{
53
- if (focusedSeries === null) return null;
54
- return focusedSeries.sort((a, b)=>a.y > b.y ? -1 : 1);
28
+ if (series === null) return null;
29
+ return series.sort((a, b)=>a.y > b.y ? -1 : 1);
55
30
  }, [
56
- focusedSeries
31
+ series
57
32
  ]);
58
- if (sortedFocusedSeries !== null && seriesTime !== null) {
59
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
60
- py: 1,
61
- px: 1.5,
62
- spacing: 0.5,
63
- children: [
64
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
65
- variant: "caption",
66
- children: formatTimeSeriesHeader(seriesTime)
67
- }),
68
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {
69
- sx: (theme)=>({
70
- borderColor: theme.palette.grey['500']
71
- })
72
- }),
73
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
74
- sx: {
75
- display: 'table'
76
- },
77
- children: sortedFocusedSeries.map(({ datumIdx , seriesIdx , seriesName , y , formattedY , markerColor })=>{
78
- if (datumIdx === null || seriesIdx === null) return null;
79
- const key = seriesIdx.toString() + datumIdx.toString();
80
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_seriesInfo.SeriesInfo, {
81
- seriesName: seriesName,
82
- y: y,
83
- formattedY: formattedY,
84
- markerColor: markerColor,
85
- totalSeries: sortedFocusedSeries.length,
86
- wrapLabels: wrapLabels
87
- }, key);
88
- })
89
- })
90
- ]
91
- });
92
- } else {
93
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
33
+ if (series === null || sortedFocusedSeries === null) {
34
+ return null;
94
35
  }
36
+ // TODO: use react-virtuoso to improve performance
37
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
38
+ sx: (theme)=>({
39
+ display: 'table',
40
+ padding: theme.spacing(0.5, 2)
41
+ }),
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
+ })
55
+ });
95
56
  }
@@ -0,0 +1,174 @@
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, "TooltipHeader", {
18
+ enumerable: true,
19
+ get: ()=>TooltipHeader
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _pin = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pin"));
24
+ const _pinOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOutline"));
25
+ const _react = require("react");
26
+ const _timeZoneProvider = require("../context/TimeZoneProvider");
27
+ const _tooltipModel = require("./tooltip-model");
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ const TooltipHeader = /*#__PURE__*/ (0, _react.memo)(function TooltipHeader({ nearbySeries , totalSeries , isTooltipPinned , showAllSeries , onShowAllClick , onUnpinClick }) {
34
+ var ref;
35
+ const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
36
+ var ref1;
37
+ const seriesTimeMs = (ref1 = (ref = nearbySeries[0]) === null || ref === void 0 ? void 0 : ref.date) !== null && ref1 !== void 0 ? ref1 : null;
38
+ if (seriesTimeMs === null) {
39
+ return null;
40
+ }
41
+ const formatTimeSeriesHeader = (timeMs)=>{
42
+ const date = new Date(timeMs);
43
+ const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
44
+ const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');
45
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
46
+ children: [
47
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
48
+ variant: "caption",
49
+ sx: (theme)=>({
50
+ color: theme.palette.common.white
51
+ }),
52
+ children: formattedDate
53
+ }),
54
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
55
+ variant: "caption",
56
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("strong", {
57
+ children: formattedTime
58
+ })
59
+ })
60
+ ]
61
+ });
62
+ };
63
+ // TODO: accurately calc whether more series are outside scrollable region using yBuffer, avg series name length, TOOLTIP_MAX_HEIGHT
64
+ const showAllSeriesToggle = totalSeries > 5;
65
+ var ref2;
66
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
67
+ sx: (theme)=>{
68
+ var ref;
69
+ return {
70
+ width: '100%',
71
+ maxWidth: _tooltipModel.TOOLTIP_MAX_WIDTH,
72
+ padding: theme.spacing(1.5, 2, 0.5, 2),
73
+ backgroundColor: (ref2 = (ref = theme.palette.designSystem) === null || ref === void 0 ? void 0 : ref.grey[800]) !== null && ref2 !== void 0 ? ref2 : _tooltipModel.TOOLTIP_BG_COLOR_FALLBACK,
74
+ position: 'sticky',
75
+ top: 0,
76
+ left: 0
77
+ };
78
+ },
79
+ children: [
80
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
81
+ sx: {
82
+ width: '100%',
83
+ display: 'flex',
84
+ justifyContent: 'start',
85
+ alignItems: 'center',
86
+ paddingBottom: 0.5
87
+ },
88
+ children: [
89
+ formatTimeSeriesHeader(seriesTimeMs),
90
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
91
+ direction: "row",
92
+ gap: 1,
93
+ sx: {
94
+ marginLeft: 'auto'
95
+ },
96
+ children: [
97
+ showAllSeriesToggle && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
98
+ direction: "row",
99
+ gap: 0.5,
100
+ alignItems: "center",
101
+ sx: {
102
+ textAlign: 'right'
103
+ },
104
+ children: [
105
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
106
+ sx: {
107
+ fontSize: 11
108
+ },
109
+ children: "Show All"
110
+ }),
111
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
112
+ checked: showAllSeries,
113
+ size: "small",
114
+ onChange: (_, checked)=>{
115
+ if (onShowAllClick !== undefined) {
116
+ return onShowAllClick(checked);
117
+ }
118
+ },
119
+ sx: (theme)=>({
120
+ '& .MuiSwitch-switchBase': {
121
+ color: theme.palette.common.white
122
+ },
123
+ '& .MuiSwitch-track': {
124
+ backgroundColor: theme.palette.common.white
125
+ }
126
+ })
127
+ })
128
+ ]
129
+ }),
130
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
131
+ direction: "row",
132
+ alignItems: "center",
133
+ children: [
134
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Typography, {
135
+ sx: {
136
+ marginRight: 0.5,
137
+ fontSize: 11,
138
+ verticalAlign: 'middle'
139
+ },
140
+ children: [
141
+ "Click to ",
142
+ isTooltipPinned ? 'Unpin' : 'Pin'
143
+ ]
144
+ }),
145
+ isTooltipPinned ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pin.default, {
146
+ onClick: ()=>{
147
+ if (onUnpinClick !== undefined) {
148
+ onUnpinClick();
149
+ }
150
+ },
151
+ sx: {
152
+ fontSize: 16,
153
+ cursor: 'pointer'
154
+ }
155
+ }) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOutline.default, {
156
+ sx: {
157
+ fontSize: 16
158
+ }
159
+ })
160
+ ]
161
+ })
162
+ ]
163
+ })
164
+ ]
165
+ }),
166
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {
167
+ sx: (theme)=>({
168
+ width: '100%',
169
+ borderColor: theme.palette.grey['500']
170
+ })
171
+ })
172
+ ]
173
+ });
174
+ });
@@ -19,7 +19,8 @@ _exportStar(require("./SeriesInfo"), exports);
19
19
  _exportStar(require("./SeriesLabelsStack"), exports);
20
20
  _exportStar(require("./SeriesMarker"), exports);
21
21
  _exportStar(require("./TooltipContent"), exports);
22
- _exportStar(require("./focused-series"), exports);
22
+ _exportStar(require("./TooltipHeader"), exports);
23
+ _exportStar(require("./nearby-series"), exports);
23
24
  _exportStar(require("./tooltip-model"), exports);
24
25
  _exportStar(require("./utils"), exports);
25
26
  function _exportStar(from, to) {
@@ -0,0 +1,206 @@
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
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ INCREASE_NEARBY_SERIES_MULTIPLIER: ()=>INCREASE_NEARBY_SERIES_MULTIPLIER,
25
+ DYNAMIC_NEARBY_SERIES_MULTIPLIER: ()=>DYNAMIC_NEARBY_SERIES_MULTIPLIER,
26
+ SHOW_FEWER_SERIES_LIMIT: ()=>SHOW_FEWER_SERIES_LIMIT,
27
+ checkforNearbySeries: ()=>checkforNearbySeries,
28
+ getNearbySeriesData: ()=>getNearbySeriesData,
29
+ isWithinPercentageRange: ()=>isWithinPercentageRange,
30
+ getYBuffer: ()=>getYBuffer
31
+ });
32
+ const _model = require("../model");
33
+ const INCREASE_NEARBY_SERIES_MULTIPLIER = 5.5; // adjusts how many series show in tooltip (higher == more series shown)
34
+ const DYNAMIC_NEARBY_SERIES_MULTIPLIER = 30; // used for adjustment after series number divisor
35
+ const SHOW_FEWER_SERIES_LIMIT = 5;
36
+ function checkforNearbySeries(data, pointInGrid, yBuffer, chart, unit) {
37
+ const currentNearbySeriesData = [];
38
+ var ref;
39
+ const cursorX = (ref = pointInGrid[0]) !== null && ref !== void 0 ? ref : null;
40
+ var ref1;
41
+ const cursorY = (ref1 = pointInGrid[1]) !== null && ref1 !== void 0 ? ref1 : null;
42
+ if (cursorX === null || cursorY === null) {
43
+ return currentNearbySeriesData;
44
+ }
45
+ const nearbySeriesIndexes = [];
46
+ const emphasizedSeriesIndexes = [];
47
+ const nonEmphasizedSeriesIndexes = [];
48
+ const totalSeries = data.timeSeries.length;
49
+ if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {
50
+ for(let seriesIdx = 0; seriesIdx < totalSeries; seriesIdx++){
51
+ const currentSeries = data.timeSeries[seriesIdx];
52
+ if (currentNearbySeriesData.length >= _model.OPTIMIZED_MODE_SERIES_LIMIT) break;
53
+ if (currentSeries !== undefined) {
54
+ const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';
55
+ var _color;
56
+ const markerColor = (_color = currentSeries.color) !== null && _color !== void 0 ? _color : '#000';
57
+ if (Array.isArray(currentSeries.data)) {
58
+ for(let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++){
59
+ var _datumIdx;
60
+ const xValue = (_datumIdx = data.xAxis[datumIdx]) !== null && _datumIdx !== void 0 ? _datumIdx : 0;
61
+ const yValue = currentSeries.data[datumIdx];
62
+ // ensure null values not displayed in tooltip
63
+ if (yValue !== undefined && yValue !== null && cursorX === datumIdx) {
64
+ if (yValue !== '-' && cursorY <= yValue + yBuffer && cursorY >= yValue - yBuffer) {
65
+ // show fewer bold series in tooltip when many total series
66
+ const minPercentRange = totalSeries > SHOW_FEWER_SERIES_LIMIT ? 2 : 5;
67
+ const percentRangeToCheck = Math.max(minPercentRange, 100 / totalSeries);
68
+ const isClosestToCursor = isWithinPercentageRange({
69
+ valueToCheck: cursorY,
70
+ baseValue: yValue,
71
+ percentage: percentRangeToCheck
72
+ });
73
+ if (isClosestToCursor) {
74
+ emphasizedSeriesIndexes.push(seriesIdx);
75
+ } else {
76
+ nonEmphasizedSeriesIndexes.push(seriesIdx);
77
+ // ensure series not close to cursor are not highlighted
78
+ if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
79
+ chart.dispatchAction({
80
+ type: 'downplay',
81
+ seriesIndex: seriesIdx
82
+ });
83
+ }
84
+ }
85
+ // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
86
+ const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
87
+ const formattedY = (0, _model.formatValue)(yValue, unit);
88
+ currentNearbySeriesData.push({
89
+ seriesIdx: seriesIdx,
90
+ datumIdx: datumIdx,
91
+ seriesName: currentSeriesName,
92
+ date: xValueMilliSeconds,
93
+ x: xValue,
94
+ y: yValue,
95
+ formattedY: formattedY,
96
+ markerColor: markerColor.toString(),
97
+ isClosestToCursor
98
+ });
99
+ nearbySeriesIndexes.push(seriesIdx);
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
108
+ // Clears emphasis state of all lines that are not emphasized.
109
+ // Emphasized is a subset of just the nearby series that are closest to cursor.
110
+ chart.dispatchAction({
111
+ type: 'downplay',
112
+ seriesIndex: nonEmphasizedSeriesIndexes
113
+ });
114
+ // https://echarts.apache.org/en/api.html#action.highlight
115
+ if (emphasizedSeriesIndexes.length > 0) {
116
+ // Fadeout opacity of all series not closest to cursor.
117
+ chart.dispatchAction({
118
+ type: 'highlight',
119
+ seriesIndex: emphasizedSeriesIndexes,
120
+ notBlur: false
121
+ });
122
+ } else {
123
+ // When no emphasized series with bold text, notBlur allows opacity fadeout to not trigger.
124
+ chart.dispatchAction({
125
+ type: 'highlight',
126
+ seriesIndex: nearbySeriesIndexes,
127
+ notBlur: true
128
+ });
129
+ }
130
+ }
131
+ return currentNearbySeriesData;
132
+ }
133
+ function getNearbySeriesData({ mousePos , pinnedPos , chartData , chart , unit , showAllSeries =false }) {
134
+ if (chart === undefined || mousePos === null) return [];
135
+ // prevents multiple tooltips showing from adjacent charts unless tooltip is pinned
136
+ let cursorTargetMatchesChart = false;
137
+ if (mousePos.target !== null) {
138
+ const currentParent = mousePos.target.parentElement;
139
+ if (currentParent !== null) {
140
+ const currentGrandparent = currentParent.parentElement;
141
+ if (currentGrandparent !== null) {
142
+ const chartDom = chart.getDom();
143
+ if (chartDom === currentGrandparent) {
144
+ cursorTargetMatchesChart = true;
145
+ }
146
+ }
147
+ }
148
+ }
149
+ // allows moving cursor inside tooltip without it fading away
150
+ if (pinnedPos !== null) {
151
+ mousePos = pinnedPos;
152
+ cursorTargetMatchesChart = true;
153
+ }
154
+ if (cursorTargetMatchesChart === false) return [];
155
+ if (chart['_model'] === undefined) return [];
156
+ const chartModel = chart['_model'];
157
+ const yInterval = chartModel.getComponent('yAxis').axis.scale._interval;
158
+ const totalSeries = chartData.timeSeries.length;
159
+ const yBuffer = getYBuffer({
160
+ yInterval,
161
+ totalSeries,
162
+ showAllSeries
163
+ });
164
+ var _x, _y;
165
+ const pointInPixel = [
166
+ (_x = mousePos.plotCanvas.x) !== null && _x !== void 0 ? _x : 0,
167
+ (_y = mousePos.plotCanvas.y) !== null && _y !== void 0 ? _y : 0
168
+ ];
169
+ if (chart.containPixel('grid', pointInPixel)) {
170
+ const pointInGrid = chart.convertFromPixel('grid', pointInPixel);
171
+ if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {
172
+ return checkforNearbySeries(chartData, pointInGrid, yBuffer, chart, unit);
173
+ }
174
+ }
175
+ // clear all highlighted series when cursor exits canvas
176
+ // https://echarts.apache.org/en/api.html#action.downplay
177
+ for(let i = 0; i < totalSeries; i++){
178
+ if ((chart === null || chart === void 0 ? void 0 : chart.dispatchAction) !== undefined) {
179
+ chart.dispatchAction({
180
+ type: 'downplay',
181
+ seriesIndex: i
182
+ });
183
+ }
184
+ }
185
+ return [];
186
+ }
187
+ function isWithinPercentageRange({ valueToCheck , baseValue , percentage }) {
188
+ const range = percentage / 100 * baseValue;
189
+ const lowerBound = baseValue - range;
190
+ const upperBound = baseValue + range;
191
+ return valueToCheck >= lowerBound && valueToCheck <= upperBound;
192
+ }
193
+ function getYBuffer({ yInterval , totalSeries , showAllSeries =false }) {
194
+ if (showAllSeries) {
195
+ return yInterval * 10; // roughly correlates with grid so entire canvas is searched
196
+ }
197
+ // never let nearby series range be less than roughly the size of a single tick
198
+ const yBufferMin = yInterval * 0.3;
199
+ // tooltip trigger area gets smaller with more series
200
+ if (totalSeries > SHOW_FEWER_SERIES_LIMIT) {
201
+ const adjustedBuffer = yInterval * DYNAMIC_NEARBY_SERIES_MULTIPLIER / totalSeries;
202
+ return Math.max(yBufferMin, adjustedBuffer);
203
+ }
204
+ // increase multiplier to expand nearby series range
205
+ return Math.max(yBufferMin, yInterval * INCREASE_NEARBY_SERIES_MULTIPLIER);
206
+ }
@@ -21,20 +21,30 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
+ TOOLTIP_MIN_WIDTH: ()=>TOOLTIP_MIN_WIDTH,
24
25
  TOOLTIP_MAX_WIDTH: ()=>TOOLTIP_MAX_WIDTH,
25
26
  TOOLTIP_MAX_HEIGHT: ()=>TOOLTIP_MAX_HEIGHT,
26
27
  TOOLTIP_LABELS_MAX_WIDTH: ()=>TOOLTIP_LABELS_MAX_WIDTH,
27
- TOOLTIP_MAX_ITEMS: ()=>TOOLTIP_MAX_ITEMS,
28
+ TOOLTIP_ADJUST_Y_POS_MULTIPLIER: ()=>TOOLTIP_ADJUST_Y_POS_MULTIPLIER,
29
+ FALLBACK_CHART_WIDTH: ()=>FALLBACK_CHART_WIDTH,
30
+ NEARBY_SERIES_DESCRIPTION: ()=>NEARBY_SERIES_DESCRIPTION,
31
+ EMPHASIZED_SERIES_DESCRIPTION: ()=>EMPHASIZED_SERIES_DESCRIPTION,
32
+ TOOLTIP_BG_COLOR_FALLBACK: ()=>TOOLTIP_BG_COLOR_FALLBACK,
28
33
  TOOLTIP_DATE_FORMAT: ()=>TOOLTIP_DATE_FORMAT,
29
34
  defaultCursorData: ()=>defaultCursorData,
30
35
  emptyTooltipData: ()=>emptyTooltipData,
31
36
  useMousePosition: ()=>useMousePosition
32
37
  });
33
38
  const _react = require("react");
39
+ const TOOLTIP_MIN_WIDTH = 375;
34
40
  const TOOLTIP_MAX_WIDTH = 650;
35
- const TOOLTIP_MAX_HEIGHT = 400;
41
+ const TOOLTIP_MAX_HEIGHT = 650;
36
42
  const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;
37
- const TOOLTIP_MAX_ITEMS = 50;
43
+ const TOOLTIP_ADJUST_Y_POS_MULTIPLIER = 0.75;
44
+ const FALLBACK_CHART_WIDTH = 750;
45
+ const NEARBY_SERIES_DESCRIPTION = 'nearby series showing in tooltip';
46
+ const EMPHASIZED_SERIES_DESCRIPTION = 'emphasized series showing as bold in tooltip';
47
+ const TOOLTIP_BG_COLOR_FALLBACK = '#2E313E';
38
48
  const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
39
49
  year: 'numeric',
40
50
  month: 'short',