@perses-dev/components 0.0.0-snapshot-tooltip-highlight-c995fc8 → 0.0.0-snapshot-saving-defaults-refinements-1b25cec

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 (204) 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 +10 -8
  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 +79 -32
  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 +13 -2
  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 +5 -4
  103. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  104. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +50 -22
  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 +160 -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 -13
  123. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  124. package/dist/TimeSeriesTooltip/tooltip-model.js +11 -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 +9 -17
  129. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  130. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  131. package/dist/UnitSelector/UnitSelector.js +2 -1
  132. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  133. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
  134. package/dist/cjs/ContentWithLegend/index.js +28 -0
  135. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
  136. package/dist/cjs/EChart/EChart.js +10 -8
  137. package/dist/cjs/Legend/CompactLegend.js +4 -1
  138. package/dist/cjs/Legend/Legend.js +70 -21
  139. package/dist/cjs/Legend/ListLegend.js +17 -103
  140. package/dist/cjs/Legend/ListLegendItem.js +8 -11
  141. package/dist/cjs/Legend/TableLegend.js +67 -0
  142. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
  143. package/dist/cjs/LineChart/LineChart.js +79 -32
  144. package/dist/cjs/StatChart/StatChart.js +13 -2
  145. package/dist/cjs/Table/InnerTable.js +44 -0
  146. package/dist/cjs/Table/Table.js +102 -0
  147. package/dist/cjs/Table/TableBody.js +29 -0
  148. package/dist/cjs/Table/TableCell.js +97 -0
  149. package/dist/cjs/Table/TableCheckbox.js +55 -0
  150. package/dist/cjs/Table/TableHead.js +29 -0
  151. package/dist/cjs/Table/TableRow.js +35 -0
  152. package/dist/cjs/Table/VirtualizedTable.js +155 -0
  153. package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
  154. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
  155. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
  156. package/dist/cjs/Table/index.js +33 -0
  157. package/dist/cjs/Table/model/table-model.js +80 -0
  158. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
  159. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +54 -21
  160. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +26 -65
  161. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +171 -0
  162. package/dist/cjs/TimeSeriesTooltip/index.js +2 -1
  163. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
  164. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +17 -3
  165. package/dist/cjs/TimeSeriesTooltip/utils.js +8 -16
  166. package/dist/cjs/UnitSelector/UnitSelector.js +2 -1
  167. package/dist/cjs/context/SnackbarProvider.js +66 -0
  168. package/dist/cjs/index.js +3 -0
  169. package/dist/cjs/model/legend.js +37 -2
  170. package/dist/cjs/model/units/bytes.js +9 -7
  171. package/dist/cjs/model/units/decimal.js +2 -2
  172. package/dist/cjs/model/units/percent.js +2 -2
  173. package/dist/cjs/model/units/time.js +2 -2
  174. package/dist/cjs/theme/palette/grey.js +6 -2
  175. package/dist/context/SnackbarProvider.d.ts +23 -0
  176. package/dist/context/SnackbarProvider.d.ts.map +1 -0
  177. package/dist/context/SnackbarProvider.js +59 -0
  178. package/dist/context/SnackbarProvider.js.map +1 -0
  179. package/dist/index.d.ts +3 -0
  180. package/dist/index.d.ts.map +1 -1
  181. package/dist/index.js +3 -0
  182. package/dist/index.js.map +1 -1
  183. package/dist/model/legend.d.ts +19 -5
  184. package/dist/model/legend.d.ts.map +1 -1
  185. package/dist/model/legend.js +31 -1
  186. package/dist/model/legend.js.map +1 -1
  187. package/dist/model/units/bytes.d.ts.map +1 -1
  188. package/dist/model/units/bytes.js +9 -7
  189. package/dist/model/units/bytes.js.map +1 -1
  190. package/dist/model/units/decimal.js +2 -2
  191. package/dist/model/units/decimal.js.map +1 -1
  192. package/dist/model/units/percent.js +2 -2
  193. package/dist/model/units/percent.js.map +1 -1
  194. package/dist/model/units/time.js +2 -2
  195. package/dist/model/units/time.js.map +1 -1
  196. package/dist/theme/palette/grey.d.ts.map +1 -1
  197. package/dist/theme/palette/grey.js +6 -2
  198. package/dist/theme/palette/grey.js.map +1 -1
  199. package/package.json +6 -6
  200. package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -28
  201. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
  202. package/dist/TimeSeriesTooltip/focused-series.js +0 -140
  203. package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
  204. package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -148
@@ -19,119 +19,33 @@ Object.defineProperty(exports, "ListLegend", {
19
19
  get: ()=>ListLegend
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
- const _material = require("@mui/material");
23
- const _reactWindow = require("react-window");
24
- const _react = require("react");
22
+ const _reactVirtuoso = require("react-virtuoso");
23
+ const _model = require("../model");
25
24
  const _listLegendItem = require("./ListLegendItem");
26
- const DEFAULT_INITIAL_ROW_HEIGHT = 26;
27
- function ListLegend({ items , height , width , initialRowHeight =DEFAULT_INITIAL_ROW_HEIGHT }) {
28
- // Storing a ref to the react-window `VariableSizeList`, so we can call
29
- // `resetAfterIndex` to resize the list after mouseover/out events to account
30
- // for the change in list items on hover.
31
- const listRef = (0, _react.useRef)(null);
32
- // Storing row heights, so we can use dynamic heights, which enables the
33
- // user the hover to show the full label, while still having a virtualized
34
- // list.
35
- const rowHeights = (0, _react.useRef)({});
36
- const theme = (0, _material.useTheme)();
37
- // Padding value used throughout to adjust the react-window virtual layouts
38
- // to simulate padding per the guidance from:
39
- // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
40
- const LIST_PADDING = parseInt(theme.spacing(1), 10);
25
+ function ListLegend({ items , height , width , selectedItems , onLegendItemClick }) {
41
26
  // show full labels on hover when there are many total series
42
27
  const truncateLabels = items.length > 5;
43
- // Gets the row height for a given item to enable the virtualized list to
44
- // render the row properly.
45
- function getRowHeight(index) {
46
- const currentHeight = rowHeights.current[index];
47
- return currentHeight !== null && currentHeight !== void 0 ? currentHeight : initialRowHeight;
48
- }
49
- // Set the height for a given item to enable the virtualized list to
50
- // adjust to size changes.
51
- function setRowHeight(index, size) {
52
- var // Tell the virtualized list that items changed size and need to be
53
- // re-evaluated.
54
- ref;
55
- (ref = listRef.current) === null || ref === void 0 ? void 0 : ref.resetAfterIndex(0);
56
- rowHeights.current = {
57
- ...rowHeights.current,
58
- [index]: size
59
- };
60
- }
61
- // Renderer for virtualized rows in `VariableSizeList`.
62
- function ListLegendRow({ index , style }) {
63
- // Storing a ref to the row's `ListLegendItem`, so we can get the "real"
64
- // height and adjust the height of the row based on it, enabling the dynamic
65
- // heights on hover.
66
- const rowRef = (0, _react.useRef)(null);
67
- // useCallback is important here to avoid constantly running the useEffect
68
- // that calls this in `ListLegendItem`.
69
- const handleRowLayoutChange = (0, _react.useCallback)(()=>{
70
- // Handle size changes from hovering on a list item.
71
- if (rowRef.current) {
72
- setRowHeight(index, rowRef.current.clientHeight);
73
- }
74
- }, [
75
- index
76
- ]);
77
- // Adjust row heights when the row being rendered changes.
78
- (0, _react.useEffect)(()=>{
79
- handleRowLayoutChange();
80
- }, [
81
- handleRowLayoutChange
82
- ]);
83
- const item = items[index];
84
- if (!item) {
85
- // This shouldn't happen if configured correctly, but covering
86
- // the case to appease the type checking and to cover any edge
87
- // cases.
88
- return null;
89
- }
90
- const originalTop = parseFloat(`${style.top}`);
91
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
92
- style: {
93
- ...style,
94
- // Adjust the top position to simulate top padding on the list.
95
- top: `${originalTop + LIST_PADDING}px`
96
- },
97
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegendItem.ListLegendItem, {
98
- ref: rowRef,
28
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactVirtuoso.Virtuoso, {
29
+ style: {
30
+ height,
31
+ width
32
+ },
33
+ data: items,
34
+ itemContent: (index, item)=>{
35
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegendItem.ListLegendItem, {
99
36
  item: item,
100
37
  truncateLabel: truncateLabels,
101
- onLayoutChange: handleRowLayoutChange,
38
+ isVisuallySelected: (0, _model.isLegendItemVisuallySelected)(item, selectedItems),
39
+ onClick: onLegendItemClick,
102
40
  sx: {
103
41
  // Having an explicit width is important for the ellipsizing to
104
42
  // work correctly. Subtract padding to simulate padding.
105
- width: width - LIST_PADDING,
43
+ width: width,
106
44
  wordBreak: 'break-word',
107
45
  overflow: 'hidden'
108
46
  }
109
- }, item.id)
110
- });
111
- }
112
- // Renderer for the inner container element of the `VariableSizeList` used
113
- // to adjust styles to simulate padding on the list per:
114
- // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
115
- const InnerElementType = /*#__PURE__*/ (0, _react.forwardRef)(function InnerElementType({ style , ...rest }, ref) {
116
- const originalHeight = (style === null || style === void 0 ? void 0 : style.height) ? parseFloat(`${style === null || style === void 0 ? void 0 : style.height}`) : 0;
117
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
118
- ref: ref,
119
- role: "list",
120
- style: {
121
- ...style,
122
- // Adjust height to account for simulated padding.
123
- height: `${originalHeight + LIST_PADDING * 2}px`
124
- },
125
- ...rest
126
- });
127
- });
128
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactWindow.VariableSizeList, {
129
- height: height,
130
- width: width,
131
- itemCount: items.length,
132
- itemSize: getRowHeight,
133
- innerElementType: InnerElementType,
134
- ref: listRef,
135
- children: ListLegendRow
47
+ }, item.id);
48
+ },
49
+ role: "list"
136
50
  });
137
51
  }
@@ -62,7 +62,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
62
62
  }
63
63
  return newObj;
64
64
  }
65
- const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLegendItem({ item , sx , truncateLabel , onLayoutChange , ...others }, ref) {
65
+ const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLegendItem({ item , sx , truncateLabel , onClick , isVisuallySelected , ...others }, ref) {
66
66
  const [noWrap, setNoWrap] = (0, _react.useState)(truncateLabel);
67
67
  function handleMouseOver() {
68
68
  if (truncateLabel) {
@@ -74,14 +74,11 @@ const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLeg
74
74
  setNoWrap(true);
75
75
  }
76
76
  }
77
- (0, _react.useEffect)(()=>{
78
- // When `noWrap` changes, so does the layout of the component. Notifies the
79
- // parent, so it can handle those changes.
80
- onLayoutChange === null || onLayoutChange === void 0 ? void 0 : onLayoutChange();
81
- }, [
82
- noWrap,
83
- onLayoutChange
84
- ]);
77
+ const handleClick = (e)=>{
78
+ var ref;
79
+ onClick(e, item.id);
80
+ (ref = item.onClick) === null || ref === void 0 ? void 0 : ref.call(item, e);
81
+ };
85
82
  return /*#__PURE__*/ (0, _react.createElement)(_material.ListItem, {
86
83
  ...others,
87
84
  component: "div",
@@ -92,8 +89,8 @@ const ListLegendItemBase = /*#__PURE__*/ (0, _react.forwardRef)(function ListLeg
92
89
  }, sx),
93
90
  dense: true,
94
91
  key: item.id,
95
- onClick: item.onClick,
96
- selected: item.isSelected,
92
+ onClick: handleClick,
93
+ selected: isVisuallySelected,
97
94
  ref: ref,
98
95
  children: [
99
96
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
@@ -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
  });
@@ -26,7 +26,6 @@ const _charts = require("echarts/charts");
26
26
  const _components = require("echarts/components");
27
27
  const _renderers = require("echarts/renderers");
28
28
  const _echart = require("../EChart");
29
- const _graph = require("../model/graph");
30
29
  const _chartsThemeProvider = require("../context/ChartsThemeProvider");
31
30
  const _timeSeriesTooltip = require("../TimeSeriesTooltip");
32
31
  const _timeZoneProvider = require("../context/TimeZoneProvider");
@@ -85,20 +84,22 @@ function _interopRequireWildcard(obj, nodeInterop) {
85
84
  ]);
86
85
  function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
87
86
  wrapLabels: true
88
- } , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
87
+ } , noDataVariant ='message' , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
89
88
  var ref;
90
89
  const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
91
90
  const chartRef = (0, _react.useRef)();
92
91
  const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
93
- const [pinTooltip, setPinTooltip] = (0, _react.useState)(false);
92
+ const [tooltipPinnedCoords, setTooltipPinnedCoords] = (0, _react.useState)(null);
94
93
  const { timeZone } = (0, _timeZoneProvider.useTimeZone)();
94
+ const [isDragging, setIsDragging] = (0, _react.useState)(false);
95
+ const [startX, setStartX] = (0, _react.useState)(0);
95
96
  const handleEvents = (0, _react.useMemo)(()=>{
96
97
  return {
97
98
  datazoom: (params)=>{
98
99
  if (onDataZoom === undefined) {
99
100
  setTimeout(()=>{
100
101
  // workaround so unpin happens after click event
101
- setPinTooltip(false);
102
+ setTooltipPinnedCoords(null);
102
103
  }, 10);
103
104
  }
104
105
  if (onDataZoom === undefined || params.batch[0] === undefined) return;
@@ -122,28 +123,17 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
122
123
  }, [
123
124
  data,
124
125
  onDataZoom,
125
- setPinTooltip
126
+ setTooltipPinnedCoords
126
127
  ]);
127
128
  if (chartRef.current !== undefined) {
128
129
  (0, _utils.enableDataZoom)(chartRef.current);
129
130
  }
130
- const handleOnDoubleClick = (e)=>{
131
- setPinTooltip(false);
132
- // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
133
- if (onDoubleClick === undefined) {
134
- if (chartRef.current !== undefined) {
135
- (0, _utils.restoreChart)(chartRef.current);
136
- }
137
- } else {
138
- onDoubleClick(e);
139
- }
140
- };
141
131
  const { noDataOption } = chartsTheme;
142
132
  const option = (0, _react.useMemo)(()=>{
143
133
  if (data.timeSeries === undefined) return {};
144
- if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;
145
- // show symbols and axisPointer dashed line on hover
146
- const isOptimizedMode = data.timeSeries.length > _graph.OPTIMIZED_MODE_SERIES_LIMIT;
134
+ // The "chart" `noDataVariant` is only used when the `timeSeries` is an
135
+ // empty array because a `null` value will throw an error.
136
+ if (data.timeSeries === null || data.timeSeries.length === 0 && noDataVariant === 'message') return noDataOption;
147
137
  var _rangeMs;
148
138
  const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : (0, _utils.getDateRange)(data.xAxis);
149
139
  const option = {
@@ -161,13 +151,13 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
161
151
  yAxis: (0, _utils.getYAxes)(yAxis, unit),
162
152
  animation: false,
163
153
  tooltip: {
164
- show: !isOptimizedMode,
154
+ show: true,
165
155
  trigger: 'axis',
166
156
  showContent: false
167
157
  },
168
158
  // https://echarts.apache.org/en/option.html#axisPointer
169
159
  axisPointer: {
170
- type: isOptimizedMode ? 'none' : 'line',
160
+ type: 'line',
171
161
  z: 0,
172
162
  triggerEmphasis: false,
173
163
  triggerTooltip: false,
@@ -196,27 +186,67 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
196
186
  legend,
197
187
  noDataOption,
198
188
  timeZone,
199
- __experimentalEChartsOptionsOverride
189
+ __experimentalEChartsOptionsOverride,
190
+ noDataVariant
200
191
  ]);
201
192
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
202
193
  sx: {
203
194
  height
204
195
  },
205
- onClick: ()=>{
206
- setPinTooltip((current)=>!current);
196
+ onClick: (e)=>{
197
+ // Pin and unpin when clicking on chart canvas but not tooltip text.
198
+ if (e.target instanceof HTMLCanvasElement) {
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
+ });
220
+ }
207
221
  },
208
222
  onMouseDown: (e)=>{
209
- // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
210
- if (e.target instanceof HTMLCanvasElement) {
211
- 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
+ }
212
239
  }
213
240
  },
214
241
  onMouseUp: ()=>{
242
+ setIsDragging(false);
243
+ setStartX(0);
215
244
  setShowTooltip(true);
216
245
  },
217
246
  onMouseLeave: ()=>{
218
- setShowTooltip(false);
219
- setPinTooltip(false);
247
+ if (tooltipPinnedCoords === null) {
248
+ setShowTooltip(false);
249
+ }
220
250
  },
221
251
  onMouseEnter: ()=>{
222
252
  setShowTooltip(true);
@@ -224,16 +254,33 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
224
254
  (0, _utils.enableDataZoom)(chartRef.current);
225
255
  }
226
256
  },
227
- 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
+ },
228
268
  children: [
229
269
  showTooltip === true && ((ref = option.tooltip) === null || ref === void 0 ? void 0 : ref.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesTooltip.TimeSeriesTooltip, {
230
270
  chartRef: chartRef,
231
271
  chartData: data,
232
272
  wrapLabels: tooltipConfig.wrapLabels,
233
- pinTooltip: pinTooltip,
234
- unit: unit
273
+ pinnedPos: tooltipPinnedCoords,
274
+ unit: unit,
275
+ onUnpinClick: ()=>{
276
+ setTooltipPinnedCoords(null);
277
+ }
235
278
  }),
236
279
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
280
+ sx: {
281
+ width: '100%',
282
+ height: '100%'
283
+ },
237
284
  option: option,
238
285
  theme: chartsTheme.echartsTheme,
239
286
  onEvents: handleEvents,
@@ -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
@@ -117,11 +124,15 @@ function StatChart(props) {
117
124
  sx: (theme)=>({
118
125
  color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
119
126
  fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
120
- padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`
127
+ padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
121
128
  }),
122
129
  children: formattedValue
123
130
  }),
124
131
  sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
132
+ sx: {
133
+ width: '100%',
134
+ height: '100%'
135
+ },
125
136
  option: option,
126
137
  theme: chartsTheme.echartsTheme,
127
138
  renderer: "svg"
@@ -0,0 +1,44 @@
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, "InnerTable", {
18
+ enumerable: true,
19
+ get: ()=>InnerTable
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _react = require("react");
24
+ const StyledMuiTable = (0, _material.styled)(_material.Table)(({ theme })=>({
25
+ // This value is needed to have a consistent table layout when scrolling.
26
+ tableLayout: 'fixed',
27
+ borderCollapse: 'separate',
28
+ backgroundColor: theme.palette.background.paper
29
+ }));
30
+ const TABLE_DENSITY_CONFIG = {
31
+ compact: 'small',
32
+ standard: 'medium'
33
+ };
34
+ const InnerTable = /*#__PURE__*/ (0, _react.forwardRef)(function InnerTable({ density , width , ...otherProps }, ref) {
35
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledMuiTable, {
36
+ ...otherProps,
37
+ tabIndex: -1,
38
+ size: TABLE_DENSITY_CONFIG[density],
39
+ ref: ref,
40
+ sx: {
41
+ width: width
42
+ }
43
+ });
44
+ });