@perses-dev/components 0.0.0-snapshot-color-palette-gen-test-0ebddd6 → 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 (238) 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/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  14. package/dist/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  15. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  16. package/dist/EChart/EChart.d.ts.map +1 -1
  17. package/dist/EChart/EChart.js +9 -1
  18. package/dist/EChart/EChart.js.map +1 -1
  19. package/dist/Legend/CompactLegend.d.ts +6 -4
  20. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  21. package/dist/Legend/CompactLegend.js +4 -1
  22. package/dist/Legend/CompactLegend.js.map +1 -1
  23. package/dist/Legend/Legend.d.ts +11 -9
  24. package/dist/Legend/Legend.d.ts.map +1 -1
  25. package/dist/Legend/Legend.js +70 -21
  26. package/dist/Legend/Legend.js.map +1 -1
  27. package/dist/Legend/ListLegend.d.ts +5 -8
  28. package/dist/Legend/ListLegend.d.ts.map +1 -1
  29. package/dist/Legend/ListLegend.js +17 -103
  30. package/dist/Legend/ListLegend.js.map +1 -1
  31. package/dist/Legend/ListLegendItem.d.ts +8 -8
  32. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  33. package/dist/Legend/ListLegendItem.js +9 -12
  34. package/dist/Legend/ListLegendItem.js.map +1 -1
  35. package/dist/Legend/TableLegend.d.ts +12 -0
  36. package/dist/Legend/TableLegend.d.ts.map +1 -0
  37. package/dist/Legend/TableLegend.js +61 -0
  38. package/dist/Legend/TableLegend.js.map +1 -0
  39. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  40. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +35 -3
  41. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  42. package/dist/LineChart/LineChart.d.ts +2 -1
  43. package/dist/LineChart/LineChart.d.ts.map +1 -1
  44. package/dist/LineChart/LineChart.js +83 -36
  45. package/dist/LineChart/LineChart.js.map +1 -1
  46. package/dist/StatChart/StatChart.d.ts.map +1 -1
  47. package/dist/StatChart/StatChart.js +23 -15
  48. package/dist/StatChart/StatChart.js.map +1 -1
  49. package/dist/Table/InnerTable.d.ts +9 -0
  50. package/dist/Table/InnerTable.d.ts.map +1 -0
  51. package/dist/Table/InnerTable.js +38 -0
  52. package/dist/Table/InnerTable.js.map +1 -0
  53. package/dist/Table/Table.d.ts +10 -0
  54. package/dist/Table/Table.d.ts.map +1 -0
  55. package/dist/Table/Table.js +101 -0
  56. package/dist/Table/Table.js.map +1 -0
  57. package/dist/Table/TableBody.d.ts +6 -0
  58. package/dist/Table/TableBody.d.ts.map +1 -0
  59. package/dist/Table/TableBody.js +23 -0
  60. package/dist/Table/TableBody.js.map +1 -0
  61. package/dist/Table/TableCell.d.ts +18 -0
  62. package/dist/Table/TableCell.d.ts.map +1 -0
  63. package/dist/Table/TableCell.js +91 -0
  64. package/dist/Table/TableCell.js.map +1 -0
  65. package/dist/Table/TableCheckbox.d.ts +9 -0
  66. package/dist/Table/TableCheckbox.d.ts.map +1 -0
  67. package/dist/Table/TableCheckbox.js +49 -0
  68. package/dist/Table/TableCheckbox.js.map +1 -0
  69. package/dist/Table/TableHead.d.ts +6 -0
  70. package/dist/Table/TableHead.d.ts.map +1 -0
  71. package/dist/Table/TableHead.js +23 -0
  72. package/dist/Table/TableHead.js.map +1 -0
  73. package/dist/Table/TableRow.d.ts +9 -0
  74. package/dist/Table/TableRow.d.ts.map +1 -0
  75. package/dist/Table/TableRow.js +29 -0
  76. package/dist/Table/TableRow.js.map +1 -0
  77. package/dist/Table/VirtualizedTable.d.ts +11 -0
  78. package/dist/Table/VirtualizedTable.d.ts.map +1 -0
  79. package/dist/Table/VirtualizedTable.js +152 -0
  80. package/dist/Table/VirtualizedTable.js.map +1 -0
  81. package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
  82. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
  83. package/dist/Table/VirtualizedTableContainer.js +24 -0
  84. package/dist/Table/VirtualizedTableContainer.js.map +1 -0
  85. package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
  86. package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
  87. package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
  88. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
  89. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
  90. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
  91. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
  92. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
  93. package/dist/Table/index.d.ts +4 -0
  94. package/dist/Table/index.d.ts.map +1 -0
  95. package/dist/Table/index.js +16 -0
  96. package/dist/Table/index.js.map +1 -0
  97. package/dist/Table/model/table-model.d.ts +83 -0
  98. package/dist/Table/model/table-model.d.ts.map +1 -0
  99. package/dist/Table/model/table-model.js +73 -0
  100. package/dist/Table/model/table-model.js.map +1 -0
  101. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
  102. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  103. package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
  104. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  105. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +5 -4
  106. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  107. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +50 -22
  108. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  109. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +3 -3
  110. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  111. package/dist/TimeSeriesTooltip/TooltipContent.js +28 -67
  112. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  113. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +12 -0
  114. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -0
  115. package/dist/TimeSeriesTooltip/TooltipHeader.js +160 -0
  116. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -0
  117. package/dist/TimeSeriesTooltip/index.d.ts +2 -1
  118. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  119. package/dist/TimeSeriesTooltip/index.js +2 -1
  120. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  121. package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
  122. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
  123. package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
  124. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
  125. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +17 -13
  126. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  127. package/dist/TimeSeriesTooltip/tooltip-model.js +11 -2
  128. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  129. package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
  130. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  131. package/dist/TimeSeriesTooltip/utils.js +9 -17
  132. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  133. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  134. package/dist/UnitSelector/UnitSelector.js +40 -17
  135. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  136. package/dist/YAxisLabel.d.ts.map +1 -1
  137. package/dist/YAxisLabel.js +1 -0
  138. package/dist/YAxisLabel.js.map +1 -1
  139. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
  140. package/dist/cjs/ContentWithLegend/index.js +28 -0
  141. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
  142. package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  143. package/dist/cjs/EChart/EChart.js +9 -1
  144. package/dist/cjs/Legend/CompactLegend.js +4 -1
  145. package/dist/cjs/Legend/Legend.js +70 -21
  146. package/dist/cjs/Legend/ListLegend.js +17 -103
  147. package/dist/cjs/Legend/ListLegendItem.js +8 -11
  148. package/dist/cjs/Legend/TableLegend.js +67 -0
  149. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
  150. package/dist/cjs/LineChart/LineChart.js +83 -36
  151. package/dist/cjs/StatChart/StatChart.js +23 -15
  152. package/dist/cjs/Table/InnerTable.js +44 -0
  153. package/dist/cjs/Table/Table.js +102 -0
  154. package/dist/cjs/Table/TableBody.js +29 -0
  155. package/dist/cjs/Table/TableCell.js +97 -0
  156. package/dist/cjs/Table/TableCheckbox.js +55 -0
  157. package/dist/cjs/Table/TableHead.js +29 -0
  158. package/dist/cjs/Table/TableRow.js +35 -0
  159. package/dist/cjs/Table/VirtualizedTable.js +155 -0
  160. package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
  161. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
  162. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
  163. package/dist/cjs/Table/index.js +33 -0
  164. package/dist/cjs/Table/model/table-model.js +80 -0
  165. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
  166. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +54 -21
  167. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +26 -65
  168. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +171 -0
  169. package/dist/cjs/TimeSeriesTooltip/index.js +2 -1
  170. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
  171. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +17 -3
  172. package/dist/cjs/TimeSeriesTooltip/utils.js +8 -16
  173. package/dist/cjs/UnitSelector/UnitSelector.js +39 -16
  174. package/dist/cjs/YAxisLabel.js +1 -0
  175. package/dist/cjs/context/SnackbarProvider.js +66 -0
  176. package/dist/cjs/index.js +3 -0
  177. package/dist/cjs/model/legend.js +37 -2
  178. package/dist/cjs/model/units/bytes.js +25 -21
  179. package/dist/cjs/model/units/constants.js +3 -3
  180. package/dist/cjs/model/units/decimal.js +22 -19
  181. package/dist/cjs/model/units/percent.js +20 -11
  182. package/dist/cjs/model/units/time.js +26 -22
  183. package/dist/cjs/model/units/units.js +2 -2
  184. package/dist/cjs/model/units/utils.js +42 -0
  185. package/dist/cjs/theme/palette/grey.js +6 -2
  186. package/dist/cjs/utils/theme-gen.js +8 -13
  187. package/dist/context/SnackbarProvider.d.ts +23 -0
  188. package/dist/context/SnackbarProvider.d.ts.map +1 -0
  189. package/dist/context/SnackbarProvider.js +59 -0
  190. package/dist/context/SnackbarProvider.js.map +1 -0
  191. package/dist/index.d.ts +3 -0
  192. package/dist/index.d.ts.map +1 -1
  193. package/dist/index.js +3 -0
  194. package/dist/index.js.map +1 -1
  195. package/dist/model/legend.d.ts +19 -5
  196. package/dist/model/legend.d.ts.map +1 -1
  197. package/dist/model/legend.js +31 -1
  198. package/dist/model/legend.js.map +1 -1
  199. package/dist/model/units/bytes.d.ts +1 -1
  200. package/dist/model/units/bytes.d.ts.map +1 -1
  201. package/dist/model/units/bytes.js +26 -22
  202. package/dist/model/units/bytes.js.map +1 -1
  203. package/dist/model/units/constants.d.ts +1 -1
  204. package/dist/model/units/constants.js +1 -1
  205. package/dist/model/units/constants.js.map +1 -1
  206. package/dist/model/units/decimal.d.ts +2 -2
  207. package/dist/model/units/decimal.d.ts.map +1 -1
  208. package/dist/model/units/decimal.js +22 -19
  209. package/dist/model/units/decimal.js.map +1 -1
  210. package/dist/model/units/percent.d.ts +2 -2
  211. package/dist/model/units/percent.d.ts.map +1 -1
  212. package/dist/model/units/percent.js +20 -11
  213. package/dist/model/units/percent.js.map +1 -1
  214. package/dist/model/units/time.d.ts +2 -2
  215. package/dist/model/units/time.d.ts.map +1 -1
  216. package/dist/model/units/time.js +26 -22
  217. package/dist/model/units/time.js.map +1 -1
  218. package/dist/model/units/types.d.ts +9 -0
  219. package/dist/model/units/types.d.ts.map +1 -1
  220. package/dist/model/units/types.js.map +1 -1
  221. package/dist/model/units/units.js +2 -2
  222. package/dist/model/units/units.js.map +1 -1
  223. package/dist/model/units/utils.d.ts +4 -0
  224. package/dist/model/units/utils.d.ts.map +1 -0
  225. package/dist/model/units/utils.js +32 -0
  226. package/dist/model/units/utils.js.map +1 -0
  227. package/dist/theme/palette/grey.d.ts.map +1 -1
  228. package/dist/theme/palette/grey.js +6 -2
  229. package/dist/theme/palette/grey.js.map +1 -1
  230. package/dist/utils/theme-gen.d.ts.map +1 -1
  231. package/dist/utils/theme-gen.js +8 -13
  232. package/dist/utils/theme-gen.js.map +1 -1
  233. package/package.json +6 -6
  234. package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
  235. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
  236. package/dist/TimeSeriesTooltip/focused-series.js +0 -111
  237. package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
  238. package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -117
@@ -20,15 +20,81 @@ Object.defineProperty(exports, "Legend", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
+ const _immer = require("immer");
24
+ const _model = require("../model");
23
25
  const _listLegend = require("./ListLegend");
24
26
  const _compactLegend = require("./CompactLegend");
27
+ const _tableLegend = require("./TableLegend");
25
28
  // When the number of items to display is above this number, it is likely to
26
29
  // cause performance issues in the browser. The legend will be displayed in a
27
30
  // format (list) that allows for virtualization to minimize the performance impact.
28
31
  // Set this number based on testing, but it may need to be tuned a bit on the
29
32
  // future as people test this out on different machines.
30
33
  const NEED_VIRTUALIZATION_LIMIT = 500;
31
- function Legend({ width , height , options , data , listProps }) {
34
+ function Legend({ width , height , options , data , selectedItems , onSelectedItemsChange }) {
35
+ const onLegendItemClick = (e, seriesId)=>{
36
+ const isModifiedClick = e.metaKey || e.shiftKey;
37
+ const newSelected = (0, _immer.produce)(selectedItems, (draft)=>{
38
+ if (draft === 'ALL') {
39
+ return {
40
+ [seriesId]: true
41
+ };
42
+ }
43
+ const isSelected = !!draft[seriesId];
44
+ // Clicks with modifier key can select multiple items.
45
+ if (isModifiedClick) {
46
+ if (isSelected) {
47
+ // Modified click on already selected item. Remove that item.
48
+ delete draft[seriesId];
49
+ } else {
50
+ // Modified click on not-selected item. Add it.
51
+ draft[seriesId] = true;
52
+ }
53
+ return draft;
54
+ }
55
+ if (isSelected) {
56
+ // Clicked item was already selected. Unselect it and return to
57
+ // ALL state.
58
+ return 'ALL';
59
+ }
60
+ // Select clicked item.
61
+ return {
62
+ [seriesId]: true
63
+ };
64
+ });
65
+ onSelectedItemsChange(newSelected);
66
+ };
67
+ const mode = (0, _model.getLegendMode)(options.mode);
68
+ // The bottom legend is displayed as a list when the number of items is too
69
+ // large and requires virtualization. Otherwise, it is rendered more compactly.
70
+ // We do not need this check for the right-side legend because it is always
71
+ // a virtualized list.
72
+ const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
73
+ const commonLegendProps = {
74
+ height,
75
+ items: data,
76
+ selectedItems,
77
+ onLegendItemClick
78
+ };
79
+ let legendContent;
80
+ if (mode === 'Table') {
81
+ legendContent = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableLegend.TableLegend, {
82
+ ...commonLegendProps,
83
+ onSelectedItemsChange: onSelectedItemsChange,
84
+ width: width
85
+ });
86
+ } else if (options.position === 'Right' || needsVirtualization) {
87
+ legendContent = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegend.ListLegend, {
88
+ ...commonLegendProps,
89
+ width: width,
90
+ onLegendItemClick: onLegendItemClick
91
+ });
92
+ } else {
93
+ legendContent = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
94
+ ...commonLegendProps,
95
+ onLegendItemClick: onLegendItemClick
96
+ });
97
+ }
32
98
  if (options.position === 'Right') {
33
99
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
34
100
  sx: {
@@ -38,19 +104,10 @@ function Legend({ width , height , options , data , listProps }) {
38
104
  top: 0,
39
105
  right: 0
40
106
  },
41
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegend.ListLegend, {
42
- items: data,
43
- width: width,
44
- height: height,
45
- ...listProps
46
- })
107
+ children: legendContent
47
108
  });
48
109
  }
49
- // The bottom legend is displayed as a list when the number of items is too
50
- // large and requires virtualization. Otherwise, it is rendered more compactly.
51
- // We do not need this check for the right-side legend because it is always
52
- // a virtualized list.
53
- const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
110
+ // Position bottom
54
111
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
55
112
  sx: {
56
113
  width: width,
@@ -58,14 +115,6 @@ function Legend({ width , height , options , data , listProps }) {
58
115
  position: 'absolute',
59
116
  bottom: 0
60
117
  },
61
- children: needsVirtualization ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_listLegend.ListLegend, {
62
- items: data,
63
- width: width,
64
- height: height,
65
- ...listProps
66
- }) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
67
- items: data,
68
- height: height
69
- })
118
+ children: legendContent
70
119
  });
71
120
  }
@@ -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,17 @@ 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
- showContent: false,
167
- axisPointer: {
168
- type: isOptimizedMode ? 'none' : 'line',
169
- z: 0
170
- }
156
+ showContent: false
157
+ },
158
+ // https://echarts.apache.org/en/option.html#axisPointer
159
+ axisPointer: {
160
+ type: 'line',
161
+ z: 0,
162
+ triggerEmphasis: false,
163
+ triggerTooltip: false,
164
+ snap: true
171
165
  },
172
166
  toolbox: {
173
167
  feature: {
@@ -192,27 +186,67 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
192
186
  legend,
193
187
  noDataOption,
194
188
  timeZone,
195
- __experimentalEChartsOptionsOverride
189
+ __experimentalEChartsOptionsOverride,
190
+ noDataVariant
196
191
  ]);
197
192
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
198
193
  sx: {
199
194
  height
200
195
  },
201
- onClick: ()=>{
202
- 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
+ }
203
221
  },
204
222
  onMouseDown: (e)=>{
205
- // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
206
- if (e.target instanceof HTMLCanvasElement) {
207
- 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
+ }
208
239
  }
209
240
  },
210
241
  onMouseUp: ()=>{
242
+ setIsDragging(false);
243
+ setStartX(0);
211
244
  setShowTooltip(true);
212
245
  },
213
246
  onMouseLeave: ()=>{
214
- setShowTooltip(false);
215
- setPinTooltip(false);
247
+ if (tooltipPinnedCoords === null) {
248
+ setShowTooltip(false);
249
+ }
216
250
  },
217
251
  onMouseEnter: ()=>{
218
252
  setShowTooltip(true);
@@ -220,14 +254,27 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
220
254
  (0, _utils.enableDataZoom)(chartRef.current);
221
255
  }
222
256
  },
223
- 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
+ },
224
268
  children: [
225
269
  showTooltip === true && ((ref = option.tooltip) === null || ref === void 0 ? void 0 : ref.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesTooltip.TimeSeriesTooltip, {
226
270
  chartRef: chartRef,
227
271
  chartData: data,
228
272
  wrapLabels: tooltipConfig.wrapLabels,
229
- pinTooltip: pinTooltip,
230
- unit: unit
273
+ pinnedPos: tooltipPinnedCoords,
274
+ unit: unit,
275
+ onUnpinClick: ()=>{
276
+ setTooltipPinnedCoords(null);
277
+ }
231
278
  }),
232
279
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
233
280
  sx: {