@perses-dev/components 0.29.1 → 0.31.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 (198) hide show
  1. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  2. package/dist/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  3. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  4. package/dist/EChart/EChart.d.ts.map +1 -1
  5. package/dist/EChart/EChart.js +1 -7
  6. package/dist/EChart/EChart.js.map +1 -1
  7. package/dist/Legend/CompactLegend.d.ts +6 -4
  8. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  9. package/dist/Legend/CompactLegend.js +4 -1
  10. package/dist/Legend/CompactLegend.js.map +1 -1
  11. package/dist/Legend/Legend.d.ts +11 -9
  12. package/dist/Legend/Legend.d.ts.map +1 -1
  13. package/dist/Legend/Legend.js +45 -11
  14. package/dist/Legend/Legend.js.map +1 -1
  15. package/dist/Legend/ListLegend.d.ts +5 -8
  16. package/dist/Legend/ListLegend.d.ts.map +1 -1
  17. package/dist/Legend/ListLegend.js +34 -99
  18. package/dist/Legend/ListLegend.js.map +1 -1
  19. package/dist/Legend/ListLegendItem.d.ts +8 -8
  20. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  21. package/dist/Legend/ListLegendItem.js +9 -12
  22. package/dist/Legend/ListLegendItem.js.map +1 -1
  23. package/dist/LineChart/LineChart.d.ts +2 -1
  24. package/dist/LineChart/LineChart.d.ts.map +1 -1
  25. package/dist/LineChart/LineChart.js +35 -22
  26. package/dist/LineChart/LineChart.js.map +1 -1
  27. package/dist/StatChart/StatChart.d.ts.map +1 -1
  28. package/dist/StatChart/StatChart.js +5 -1
  29. package/dist/StatChart/StatChart.js.map +1 -1
  30. package/dist/Table/InnerTable.d.ts +9 -0
  31. package/dist/Table/InnerTable.d.ts.map +1 -0
  32. package/dist/Table/InnerTable.js +38 -0
  33. package/dist/Table/InnerTable.js.map +1 -0
  34. package/dist/Table/Table.d.ts +10 -0
  35. package/dist/Table/Table.d.ts.map +1 -0
  36. package/dist/Table/Table.js +101 -0
  37. package/dist/Table/Table.js.map +1 -0
  38. package/dist/Table/TableBody.d.ts +6 -0
  39. package/dist/Table/TableBody.d.ts.map +1 -0
  40. package/dist/Table/TableBody.js +23 -0
  41. package/dist/Table/TableBody.js.map +1 -0
  42. package/dist/Table/TableCell.d.ts +18 -0
  43. package/dist/Table/TableCell.d.ts.map +1 -0
  44. package/dist/Table/TableCell.js +91 -0
  45. package/dist/Table/TableCell.js.map +1 -0
  46. package/dist/Table/TableCheckbox.d.ts +9 -0
  47. package/dist/Table/TableCheckbox.d.ts.map +1 -0
  48. package/dist/Table/TableCheckbox.js +49 -0
  49. package/dist/Table/TableCheckbox.js.map +1 -0
  50. package/dist/Table/TableHead.d.ts +6 -0
  51. package/dist/Table/TableHead.d.ts.map +1 -0
  52. package/dist/Table/TableHead.js +23 -0
  53. package/dist/Table/TableHead.js.map +1 -0
  54. package/dist/Table/TableRow.d.ts +9 -0
  55. package/dist/Table/TableRow.d.ts.map +1 -0
  56. package/dist/Table/TableRow.js +29 -0
  57. package/dist/Table/TableRow.js.map +1 -0
  58. package/dist/Table/VirtualizedTable.d.ts +11 -0
  59. package/dist/Table/VirtualizedTable.d.ts.map +1 -0
  60. package/dist/Table/VirtualizedTable.js +152 -0
  61. package/dist/Table/VirtualizedTable.js.map +1 -0
  62. package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
  63. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
  64. package/dist/Table/VirtualizedTableContainer.js +24 -0
  65. package/dist/Table/VirtualizedTableContainer.js.map +1 -0
  66. package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
  67. package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
  68. package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
  69. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
  70. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
  71. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
  72. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
  73. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
  74. package/dist/Table/index.d.ts +4 -0
  75. package/dist/Table/index.d.ts.map +1 -0
  76. package/dist/Table/index.js +16 -0
  77. package/dist/Table/index.js.map +1 -0
  78. package/dist/Table/model/table-model.d.ts +83 -0
  79. package/dist/Table/model/table-model.d.ts.map +1 -0
  80. package/dist/Table/model/table-model.js +73 -0
  81. package/dist/Table/model/table-model.js.map +1 -0
  82. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
  83. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  84. package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
  85. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  86. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +3 -2
  87. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  88. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +63 -17
  89. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  90. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +5 -3
  91. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  92. package/dist/TimeSeriesTooltip/TooltipContent.js +81 -44
  93. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  94. package/dist/TimeSeriesTooltip/index.d.ts +1 -1
  95. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  96. package/dist/TimeSeriesTooltip/index.js +1 -1
  97. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  98. package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
  99. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
  100. package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
  101. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
  102. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +12 -4
  103. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  104. package/dist/TimeSeriesTooltip/tooltip-model.js +10 -2
  105. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  106. package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
  107. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  108. package/dist/TimeSeriesTooltip/utils.js +7 -15
  109. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  110. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  111. package/dist/UnitSelector/UnitSelector.js +40 -17
  112. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  113. package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  114. package/dist/cjs/EChart/EChart.js +1 -7
  115. package/dist/cjs/Legend/CompactLegend.js +4 -1
  116. package/dist/cjs/Legend/Legend.js +45 -11
  117. package/dist/cjs/Legend/ListLegend.js +33 -98
  118. package/dist/cjs/Legend/ListLegendItem.js +8 -11
  119. package/dist/cjs/LineChart/LineChart.js +35 -22
  120. package/dist/cjs/StatChart/StatChart.js +5 -1
  121. package/dist/cjs/Table/InnerTable.js +44 -0
  122. package/dist/cjs/Table/Table.js +102 -0
  123. package/dist/cjs/Table/TableBody.js +29 -0
  124. package/dist/cjs/Table/TableCell.js +97 -0
  125. package/dist/cjs/Table/TableCheckbox.js +55 -0
  126. package/dist/cjs/Table/TableHead.js +29 -0
  127. package/dist/cjs/Table/TableRow.js +35 -0
  128. package/dist/cjs/Table/VirtualizedTable.js +155 -0
  129. package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
  130. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
  131. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
  132. package/dist/cjs/Table/index.js +33 -0
  133. package/dist/cjs/Table/model/table-model.js +80 -0
  134. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
  135. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +67 -16
  136. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +85 -43
  137. package/dist/cjs/TimeSeriesTooltip/index.js +1 -1
  138. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
  139. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +15 -3
  140. package/dist/cjs/TimeSeriesTooltip/utils.js +6 -14
  141. package/dist/cjs/UnitSelector/UnitSelector.js +39 -16
  142. package/dist/cjs/context/SnackbarProvider.js +66 -0
  143. package/dist/cjs/index.js +2 -0
  144. package/dist/cjs/model/legend.js +7 -1
  145. package/dist/cjs/model/units/bytes.js +25 -21
  146. package/dist/cjs/model/units/constants.js +3 -3
  147. package/dist/cjs/model/units/decimal.js +22 -19
  148. package/dist/cjs/model/units/percent.js +15 -22
  149. package/dist/cjs/model/units/time.js +24 -20
  150. package/dist/cjs/model/units/units.js +2 -2
  151. package/dist/cjs/model/units/utils.js +42 -0
  152. package/dist/cjs/theme/palette/grey.js +6 -2
  153. package/dist/context/SnackbarProvider.d.ts +23 -0
  154. package/dist/context/SnackbarProvider.d.ts.map +1 -0
  155. package/dist/context/SnackbarProvider.js +59 -0
  156. package/dist/context/SnackbarProvider.js.map +1 -0
  157. package/dist/index.d.ts +2 -0
  158. package/dist/index.d.ts.map +1 -1
  159. package/dist/index.js +2 -0
  160. package/dist/index.js.map +1 -1
  161. package/dist/model/legend.d.ts +10 -2
  162. package/dist/model/legend.d.ts.map +1 -1
  163. package/dist/model/legend.js +5 -0
  164. package/dist/model/legend.js.map +1 -1
  165. package/dist/model/units/bytes.d.ts +1 -1
  166. package/dist/model/units/bytes.d.ts.map +1 -1
  167. package/dist/model/units/bytes.js +26 -22
  168. package/dist/model/units/bytes.js.map +1 -1
  169. package/dist/model/units/constants.d.ts +1 -1
  170. package/dist/model/units/constants.js +1 -1
  171. package/dist/model/units/constants.js.map +1 -1
  172. package/dist/model/units/decimal.d.ts +2 -2
  173. package/dist/model/units/decimal.d.ts.map +1 -1
  174. package/dist/model/units/decimal.js +22 -19
  175. package/dist/model/units/decimal.js.map +1 -1
  176. package/dist/model/units/percent.d.ts +1 -1
  177. package/dist/model/units/percent.d.ts.map +1 -1
  178. package/dist/model/units/percent.js +14 -21
  179. package/dist/model/units/percent.js.map +1 -1
  180. package/dist/model/units/time.d.ts +1 -1
  181. package/dist/model/units/time.d.ts.map +1 -1
  182. package/dist/model/units/time.js +24 -20
  183. package/dist/model/units/time.js.map +1 -1
  184. package/dist/model/units/units.js +2 -2
  185. package/dist/model/units/units.js.map +1 -1
  186. package/dist/model/units/utils.d.ts +4 -0
  187. package/dist/model/units/utils.d.ts.map +1 -0
  188. package/dist/model/units/utils.js +32 -0
  189. package/dist/model/units/utils.js.map +1 -0
  190. package/dist/theme/palette/grey.d.ts.map +1 -1
  191. package/dist/theme/palette/grey.js +6 -2
  192. package/dist/theme/palette/grey.js.map +1 -1
  193. package/package.json +6 -6
  194. package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
  195. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
  196. package/dist/TimeSeriesTooltip/focused-series.js +0 -111
  197. package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
  198. package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -117
@@ -20,18 +20,25 @@ 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"));
23
25
  const _material = require("@mui/material");
24
26
  const _timeZoneProvider = require("../context/TimeZoneProvider");
25
27
  const _seriesInfo = require("./SeriesInfo");
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
26
33
  function TooltipContent(props) {
27
- const { focusedSeries , wrapLabels } = props;
34
+ const { series , wrapLabels , isTooltipPinned , onUnpinClick } = props;
28
35
  const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
29
- const seriesTime = focusedSeries && focusedSeries[0] && focusedSeries[0].date ? focusedSeries[0].date : null;
30
- const formatTimeSeriesHeader = (timeString)=>{
31
- const date = new Date(timeString);
36
+ const seriesTime = series && series[0] && series[0].date ? series[0].date : null;
37
+ const formatTimeSeriesHeader = (timeMs)=>{
38
+ const date = new Date(timeMs);
32
39
  const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
33
40
  const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');
34
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
41
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
35
42
  children: [
36
43
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
37
44
  variant: "caption",
@@ -50,46 +57,81 @@ function TooltipContent(props) {
50
57
  });
51
58
  };
52
59
  const sortedFocusedSeries = (0, _react.useMemo)(()=>{
53
- if (focusedSeries === null) return null;
54
- return focusedSeries.sort((a, b)=>a.y > b.y ? -1 : 1);
60
+ if (series === null) return null;
61
+ return series.sort((a, b)=>a.y > b.y ? -1 : 1);
55
62
  }, [
56
- focusedSeries
63
+ series
57
64
  ]);
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);
65
+ if (sortedFocusedSeries === null || seriesTime === null) {
66
+ return null;
67
+ }
68
+ // 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']
88
115
  })
116
+ }),
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);
89
133
  })
90
- ]
91
- });
92
- } else {
93
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {});
94
- }
134
+ })
135
+ ]
136
+ });
95
137
  }
@@ -19,7 +19,7 @@ _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("./nearby-series"), exports);
23
23
  _exportStar(require("./tooltip-model"), exports);
24
24
  _exportStar(require("./utils"), exports);
25
25
  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
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
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,28 @@ 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,
28
32
  TOOLTIP_DATE_FORMAT: ()=>TOOLTIP_DATE_FORMAT,
29
33
  defaultCursorData: ()=>defaultCursorData,
30
34
  emptyTooltipData: ()=>emptyTooltipData,
31
35
  useMousePosition: ()=>useMousePosition
32
36
  });
33
37
  const _react = require("react");
38
+ const TOOLTIP_MIN_WIDTH = 375;
34
39
  const TOOLTIP_MAX_WIDTH = 650;
35
- const TOOLTIP_MAX_HEIGHT = 400;
40
+ const TOOLTIP_MAX_HEIGHT = 600;
36
41
  const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;
37
- const TOOLTIP_MAX_ITEMS = 50;
42
+ const TOOLTIP_ADJUST_Y_POS_MULTIPLIER = 0.75;
43
+ const FALLBACK_CHART_WIDTH = 750;
44
+ const NEARBY_SERIES_DESCRIPTION = 'nearby series showing in tooltip';
45
+ const EMPHASIZED_SERIES_DESCRIPTION = 'emphasized series showing as bold in tooltip';
38
46
  const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
39
47
  year: 'numeric',
40
48
  month: 'short',
@@ -71,6 +79,10 @@ const useMousePosition = ()=>{
71
79
  x: e.pageX,
72
80
  y: e.pageY
73
81
  },
82
+ client: {
83
+ x: e.clientX,
84
+ y: e.clientY
85
+ },
74
86
  plotCanvas: {
75
87
  x: e.offsetX,
76
88
  y: e.offsetY
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "assembleTransform", {
19
19
  get: ()=>assembleTransform
20
20
  });
21
21
  const _tooltipModel = require("./tooltip-model");
22
- function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedPos) {
22
+ function assembleTransform(mousePos, chartWidth, pinnedPos, tooltipHeight, tooltipWidth) {
23
23
  if (mousePos === null) {
24
24
  return 'translate3d(0, 0)';
25
25
  }
@@ -33,20 +33,12 @@ function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedP
33
33
  // absolutely positioned correctly as the user scrolls
34
34
  const x = mousePos.page.x;
35
35
  let y = mousePos.page.y + cursorPaddingY;
36
- const isCloseToBottom = mousePos.page.y > window.innerHeight * 0.8;
37
- const yPosAdjustThreshold = chartHeight * 0.75;
38
- // adjust so tooltip does not get cut off at bottom of chart, reduce multiplier to move up
39
- if (isCloseToBottom === true) {
40
- if (seriesNum > 6) {
41
- y = mousePos.page.y * 0.75;
42
- } else {
43
- y = mousePos.page.y * 0.9;
44
- }
45
- } else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
46
- y = mousePos.page.y * 0.95;
36
+ // adjust so tooltip does not get cut off at bottom of chart
37
+ if (mousePos.client.y + tooltipHeight + cursorPaddingY > window.innerHeight) {
38
+ // multiplier ensures tooltip isn't overly adjusted and gets cut off at the top of the viewport
39
+ y = mousePos.page.y - tooltipHeight * _tooltipModel.TOOLTIP_ADJUST_Y_POS_MULTIPLIER;
47
40
  }
48
- // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)
49
- const tooltipWidth = seriesNum > 1 ? _tooltipModel.TOOLTIP_MAX_WIDTH : _tooltipModel.TOOLTIP_MAX_WIDTH / 2;
41
+ // use tooltip width to determine when to repos from right to left
50
42
  const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;
51
43
  // reposition so tooltip is never too close to right side of chart or left side of browser window
52
44
  return mousePos.plotCanvas.x > xPosAdjustThreshold && x > _tooltipModel.TOOLTIP_MAX_WIDTH ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)` : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;
@@ -21,6 +21,7 @@ Object.defineProperty(exports, "UnitSelector", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
23
  const _model = require("../model");
24
+ const _utils = require("../model/units/utils");
24
25
  const _optionsEditorLayout = require("../OptionsEditorLayout");
25
26
  const KIND_OPTIONS = Object.entries(_model.UNIT_CONFIG).map(([id, config])=>{
26
27
  return {
@@ -28,13 +29,35 @@ const KIND_OPTIONS = Object.entries(_model.UNIT_CONFIG).map(([id, config])=>{
28
29
  ...config
29
30
  };
30
31
  }).filter((config)=>!config.disableSelectorOption);
31
- const DECIMAL_OPTIONS = [
32
- 0,
33
- 1,
34
- 2,
35
- 3,
36
- 4
32
+ const DECIMAL_PLACES_OPTIONS = [
33
+ {
34
+ label: 'Default',
35
+ decimal_places: undefined
36
+ },
37
+ {
38
+ label: '0',
39
+ decimal_places: 0
40
+ },
41
+ {
42
+ label: '1',
43
+ decimal_places: 1
44
+ },
45
+ {
46
+ label: '2',
47
+ decimal_places: 2
48
+ },
49
+ {
50
+ label: '3',
51
+ decimal_places: 3
52
+ },
53
+ {
54
+ label: '4',
55
+ decimal_places: 4
56
+ }
37
57
  ];
58
+ function getOptionByDecimalPlaces(decimal_places) {
59
+ return DECIMAL_PLACES_OPTIONS.find((o)=>o.decimal_places === decimal_places);
60
+ }
38
61
  function UnitSelector({ value , onChange }) {
39
62
  const hasDecimalPlaces = (0, _model.isUnitWithDecimalPlaces)(value);
40
63
  const hasAbbreviate = (0, _model.isUnitWithAbbreviate)(value);
@@ -43,11 +66,11 @@ function UnitSelector({ value , onChange }) {
43
66
  kind: newValue.id
44
67
  });
45
68
  };
46
- const handleDecimalChange = (_, newValue)=>{
69
+ const handleDecimalPlacesChange = (_, { decimal_places })=>{
47
70
  if (hasDecimalPlaces) {
48
71
  onChange({
49
72
  ...value,
50
- decimal_places: newValue
73
+ decimal_places: decimal_places
51
74
  });
52
75
  }
53
76
  };
@@ -60,19 +83,18 @@ function UnitSelector({ value , onChange }) {
60
83
  }
61
84
  };
62
85
  const kindConfig = _model.UNIT_CONFIG[value.kind];
63
- var _decimal_places;
64
86
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
65
87
  children: [
66
88
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
67
89
  label: "Abbreviate",
68
90
  control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
69
- checked: hasAbbreviate ? !!value.abbreviate : false,
91
+ checked: hasAbbreviate ? (0, _utils.shouldAbbreviate)(value.abbreviate) : false,
70
92
  onChange: handleAbbreviateChange,
71
93
  disabled: !hasAbbreviate
72
94
  })
73
95
  }),
74
96
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
75
- label: "Units",
97
+ label: "Unit",
76
98
  control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
77
99
  value: {
78
100
  id: value.kind,
@@ -100,15 +122,16 @@ function UnitSelector({ value , onChange }) {
100
122
  })
101
123
  }),
102
124
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorLayout.OptionsEditorControl, {
103
- label: "Decimal",
125
+ label: "Decimals",
104
126
  control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
105
- value: hasDecimalPlaces ? (_decimal_places = value.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _model.DEFAULT_DECIMAL_PLACES : 0,
106
- options: DECIMAL_OPTIONS,
107
- getOptionLabel: (option)=>`${option}`,
127
+ value: getOptionByDecimalPlaces(value.decimal_places),
128
+ options: DECIMAL_PLACES_OPTIONS,
129
+ getOptionLabel: (o)=>o.label,
130
+ isOptionEqualToValue: (option, value)=>option.label === value.label,
108
131
  renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
109
132
  ...params
110
133
  }),
111
- onChange: handleDecimalChange,
134
+ onChange: handleDecimalPlacesChange,
112
135
  disabled: !hasDecimalPlaces,
113
136
  disableClearable: true
114
137
  })
@@ -0,0 +1,66 @@
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
+ SnackbarProvider: ()=>_notistack.SnackbarProvider,
25
+ useSnackbar: ()=>useSnackbar
26
+ });
27
+ const _react = require("react");
28
+ const _notistack = require("notistack");
29
+ function useSnackbar() {
30
+ const { enqueueSnackbar , closeSnackbar } = (0, _notistack.useSnackbar)();
31
+ // Create variant-specific callbacks
32
+ const errorSnackbar = useEnqueueFunction(enqueueSnackbar, 'error');
33
+ const infoSnackbar = useEnqueueFunction(enqueueSnackbar, 'info');
34
+ const warningSnackbar = useEnqueueFunction(enqueueSnackbar, 'warning');
35
+ const successSnackbar = useEnqueueFunction(enqueueSnackbar, 'success');
36
+ const exceptionSnackbar = (0, _react.useCallback)((error, options)=>{
37
+ // Try to use message prop, but fallback to a default message that
38
+ // will just stringify the error provided
39
+ const message = error instanceof Error ? error.message : `An unexpected error occurred: ${error}`;
40
+ return errorSnackbar(message, options);
41
+ }, [
42
+ errorSnackbar
43
+ ]);
44
+ return {
45
+ enqueueSnackbar,
46
+ closeSnackbar,
47
+ errorSnackbar,
48
+ infoSnackbar,
49
+ warningSnackbar,
50
+ successSnackbar,
51
+ exceptionSnackbar
52
+ };
53
+ }
54
+ // Helper to create a variant-specific enqueue function
55
+ function useEnqueueFunction(enqueueSnackbar, variant) {
56
+ return (0, _react.useCallback)((message, options)=>{
57
+ const allOptions = {
58
+ ...options,
59
+ variant
60
+ };
61
+ return enqueueSnackbar(message, allOptions);
62
+ }, [
63
+ enqueueSnackbar,
64
+ variant
65
+ ]);
66
+ }
package/dist/cjs/index.js CHANGED
@@ -29,12 +29,14 @@ _exportStar(require("./LegendOptionsEditor"), exports);
29
29
  _exportStar(require("./LineChart"), exports);
30
30
  _exportStar(require("./OptionsEditorLayout"), exports);
31
31
  _exportStar(require("./StatChart"), exports);
32
+ _exportStar(require("./Table"), exports);
32
33
  _exportStar(require("./ThresholdsEditor"), exports);
33
34
  _exportStar(require("./TimeSeriesTooltip"), exports);
34
35
  _exportStar(require("./UnitSelector"), exports);
35
36
  _exportStar(require("./YAxisLabel"), exports);
36
37
  _exportStar(require("./context/ChartsThemeProvider"), exports);
37
38
  _exportStar(require("./context/TimeZoneProvider"), exports);
39
+ _exportStar(require("./context/SnackbarProvider"), exports);
38
40
  _exportStar(require("./utils"), exports);
39
41
  _exportStar(require("./model"), exports);
40
42
  _exportStar(require("./test-utils"), exports);
@@ -26,7 +26,8 @@ _export(exports, {
26
26
  DEFAULT_LEGEND: ()=>DEFAULT_LEGEND,
27
27
  getLegendPosition: ()=>getLegendPosition,
28
28
  isValidLegendPosition: ()=>isValidLegendPosition,
29
- validateLegendSpec: ()=>validateLegendSpec
29
+ validateLegendSpec: ()=>validateLegendSpec,
30
+ isLegendItemVisuallySelected: ()=>isLegendItemVisuallySelected
30
31
  });
31
32
  const legendPositions = [
32
33
  'Bottom',
@@ -65,3 +66,8 @@ function validateLegendSpec(legend) {
65
66
  }
66
67
  return true;
67
68
  }
69
+ function isLegendItemVisuallySelected(item, selectedItems) {
70
+ // In the "ALL" case, technically all legend items are selected, but we do
71
+ // not render them differently.
72
+ return selectedItems !== 'ALL' && !!selectedItems[item.id];
73
+ }