@perses-dev/components 0.30.0 → 0.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.d.ts +11 -0
  2. package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -0
  3. package/dist/ContentWithLegend/ContentWithLegend.js +65 -0
  4. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -0
  5. package/dist/ContentWithLegend/index.d.ts +2 -0
  6. package/dist/ContentWithLegend/index.d.ts.map +1 -0
  7. package/dist/ContentWithLegend/index.js +15 -0
  8. package/dist/ContentWithLegend/index.js.map +1 -0
  9. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +68 -0
  10. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -0
  11. package/dist/ContentWithLegend/model/content-with-legend-model.js +90 -0
  12. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -0
  13. package/dist/EChart/EChart.d.ts.map +1 -1
  14. package/dist/EChart/EChart.js +9 -1
  15. package/dist/EChart/EChart.js.map +1 -1
  16. package/dist/Legend/CompactLegend.d.ts +6 -4
  17. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  18. package/dist/Legend/CompactLegend.js +4 -1
  19. package/dist/Legend/CompactLegend.js.map +1 -1
  20. package/dist/Legend/Legend.d.ts +11 -9
  21. package/dist/Legend/Legend.d.ts.map +1 -1
  22. package/dist/Legend/Legend.js +70 -21
  23. package/dist/Legend/Legend.js.map +1 -1
  24. package/dist/Legend/ListLegend.d.ts +5 -8
  25. package/dist/Legend/ListLegend.d.ts.map +1 -1
  26. package/dist/Legend/ListLegend.js +17 -103
  27. package/dist/Legend/ListLegend.js.map +1 -1
  28. package/dist/Legend/ListLegendItem.d.ts +8 -8
  29. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  30. package/dist/Legend/ListLegendItem.js +9 -12
  31. package/dist/Legend/ListLegendItem.js.map +1 -1
  32. package/dist/Legend/TableLegend.d.ts +12 -0
  33. package/dist/Legend/TableLegend.d.ts.map +1 -0
  34. package/dist/Legend/TableLegend.js +61 -0
  35. package/dist/Legend/TableLegend.js.map +1 -0
  36. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  37. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +35 -3
  38. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  39. package/dist/LineChart/LineChart.d.ts +2 -1
  40. package/dist/LineChart/LineChart.d.ts.map +1 -1
  41. package/dist/LineChart/LineChart.js +83 -36
  42. package/dist/LineChart/LineChart.js.map +1 -1
  43. package/dist/StatChart/StatChart.d.ts.map +1 -1
  44. package/dist/StatChart/StatChart.js +8 -1
  45. package/dist/StatChart/StatChart.js.map +1 -1
  46. package/dist/Table/InnerTable.d.ts +9 -0
  47. package/dist/Table/InnerTable.d.ts.map +1 -0
  48. package/dist/Table/InnerTable.js +38 -0
  49. package/dist/Table/InnerTable.js.map +1 -0
  50. package/dist/Table/Table.d.ts +10 -0
  51. package/dist/Table/Table.d.ts.map +1 -0
  52. package/dist/Table/Table.js +101 -0
  53. package/dist/Table/Table.js.map +1 -0
  54. package/dist/Table/TableBody.d.ts +6 -0
  55. package/dist/Table/TableBody.d.ts.map +1 -0
  56. package/dist/Table/TableBody.js +23 -0
  57. package/dist/Table/TableBody.js.map +1 -0
  58. package/dist/Table/TableCell.d.ts +18 -0
  59. package/dist/Table/TableCell.d.ts.map +1 -0
  60. package/dist/Table/TableCell.js +91 -0
  61. package/dist/Table/TableCell.js.map +1 -0
  62. package/dist/Table/TableCheckbox.d.ts +9 -0
  63. package/dist/Table/TableCheckbox.d.ts.map +1 -0
  64. package/dist/Table/TableCheckbox.js +49 -0
  65. package/dist/Table/TableCheckbox.js.map +1 -0
  66. package/dist/Table/TableHead.d.ts +6 -0
  67. package/dist/Table/TableHead.d.ts.map +1 -0
  68. package/dist/Table/TableHead.js +23 -0
  69. package/dist/Table/TableHead.js.map +1 -0
  70. package/dist/Table/TableRow.d.ts +9 -0
  71. package/dist/Table/TableRow.d.ts.map +1 -0
  72. package/dist/Table/TableRow.js +29 -0
  73. package/dist/Table/TableRow.js.map +1 -0
  74. package/dist/Table/VirtualizedTable.d.ts +11 -0
  75. package/dist/Table/VirtualizedTable.d.ts.map +1 -0
  76. package/dist/Table/VirtualizedTable.js +152 -0
  77. package/dist/Table/VirtualizedTable.js.map +1 -0
  78. package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
  79. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
  80. package/dist/Table/VirtualizedTableContainer.js +24 -0
  81. package/dist/Table/VirtualizedTableContainer.js.map +1 -0
  82. package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
  83. package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
  84. package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
  85. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
  86. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
  87. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
  88. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
  89. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
  90. package/dist/Table/index.d.ts +4 -0
  91. package/dist/Table/index.d.ts.map +1 -0
  92. package/dist/Table/index.js +16 -0
  93. package/dist/Table/index.js.map +1 -0
  94. package/dist/Table/model/table-model.d.ts +83 -0
  95. package/dist/Table/model/table-model.d.ts.map +1 -0
  96. package/dist/Table/model/table-model.js +73 -0
  97. package/dist/Table/model/table-model.js.map +1 -0
  98. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
  99. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  100. package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
  101. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  102. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +6 -5
  103. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  104. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +48 -21
  105. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  106. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +3 -3
  107. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  108. package/dist/TimeSeriesTooltip/TooltipContent.js +28 -67
  109. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  110. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +12 -0
  111. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -0
  112. package/dist/TimeSeriesTooltip/TooltipHeader.js +163 -0
  113. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -0
  114. package/dist/TimeSeriesTooltip/index.d.ts +2 -1
  115. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  116. package/dist/TimeSeriesTooltip/index.js +2 -1
  117. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  118. package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
  119. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
  120. package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
  121. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
  122. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +17 -17
  123. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  124. package/dist/TimeSeriesTooltip/tooltip-model.js +7 -2
  125. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  126. package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
  127. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  128. package/dist/TimeSeriesTooltip/utils.js +6 -5
  129. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  130. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
  131. package/dist/cjs/ContentWithLegend/index.js +28 -0
  132. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
  133. package/dist/cjs/EChart/EChart.js +9 -1
  134. package/dist/cjs/Legend/CompactLegend.js +4 -1
  135. package/dist/cjs/Legend/Legend.js +70 -21
  136. package/dist/cjs/Legend/ListLegend.js +17 -103
  137. package/dist/cjs/Legend/ListLegendItem.js +8 -11
  138. package/dist/cjs/Legend/TableLegend.js +67 -0
  139. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
  140. package/dist/cjs/LineChart/LineChart.js +83 -36
  141. package/dist/cjs/StatChart/StatChart.js +8 -1
  142. package/dist/cjs/Table/InnerTable.js +44 -0
  143. package/dist/cjs/Table/Table.js +102 -0
  144. package/dist/cjs/Table/TableBody.js +29 -0
  145. package/dist/cjs/Table/TableCell.js +97 -0
  146. package/dist/cjs/Table/TableCheckbox.js +55 -0
  147. package/dist/cjs/Table/TableHead.js +29 -0
  148. package/dist/cjs/Table/TableRow.js +35 -0
  149. package/dist/cjs/Table/VirtualizedTable.js +155 -0
  150. package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
  151. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
  152. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
  153. package/dist/cjs/Table/index.js +33 -0
  154. package/dist/cjs/Table/model/table-model.js +80 -0
  155. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
  156. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +45 -57
  157. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +26 -65
  158. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +174 -0
  159. package/dist/cjs/TimeSeriesTooltip/index.js +2 -1
  160. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
  161. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +13 -3
  162. package/dist/cjs/TimeSeriesTooltip/utils.js +5 -4
  163. package/dist/cjs/context/SnackbarProvider.js +66 -0
  164. package/dist/cjs/index.js +3 -0
  165. package/dist/cjs/model/legend.js +37 -2
  166. package/dist/cjs/theme/palette/grey.js +6 -2
  167. package/dist/context/SnackbarProvider.d.ts +23 -0
  168. package/dist/context/SnackbarProvider.d.ts.map +1 -0
  169. package/dist/context/SnackbarProvider.js +59 -0
  170. package/dist/context/SnackbarProvider.js.map +1 -0
  171. package/dist/index.d.ts +3 -0
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +3 -0
  174. package/dist/index.js.map +1 -1
  175. package/dist/model/legend.d.ts +19 -5
  176. package/dist/model/legend.d.ts.map +1 -1
  177. package/dist/model/legend.js +31 -1
  178. package/dist/model/legend.js.map +1 -1
  179. package/dist/theme/palette/grey.d.ts.map +1 -1
  180. package/dist/theme/palette/grey.js +6 -2
  181. package/dist/theme/palette/grey.js.map +1 -1
  182. package/package.json +6 -6
  183. package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
  184. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
  185. package/dist/TimeSeriesTooltip/focused-series.js +0 -110
  186. package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
  187. package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -116
@@ -12,15 +12,81 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { Box } from '@mui/material';
15
+ import { produce } from 'immer';
16
+ import { getLegendMode } from '../model';
15
17
  import { ListLegend } from './ListLegend';
16
18
  import { CompactLegend } from './CompactLegend';
19
+ import { TableLegend } from './TableLegend';
17
20
  // When the number of items to display is above this number, it is likely to
18
21
  // cause performance issues in the browser. The legend will be displayed in a
19
22
  // format (list) that allows for virtualization to minimize the performance impact.
20
23
  // Set this number based on testing, but it may need to be tuned a bit on the
21
24
  // future as people test this out on different machines.
22
25
  const NEED_VIRTUALIZATION_LIMIT = 500;
23
- export function Legend({ width , height , options , data , listProps }) {
26
+ export function Legend({ width , height , options , data , selectedItems , onSelectedItemsChange }) {
27
+ const onLegendItemClick = (e, seriesId)=>{
28
+ const isModifiedClick = e.metaKey || e.shiftKey;
29
+ const newSelected = produce(selectedItems, (draft)=>{
30
+ if (draft === 'ALL') {
31
+ return {
32
+ [seriesId]: true
33
+ };
34
+ }
35
+ const isSelected = !!draft[seriesId];
36
+ // Clicks with modifier key can select multiple items.
37
+ if (isModifiedClick) {
38
+ if (isSelected) {
39
+ // Modified click on already selected item. Remove that item.
40
+ delete draft[seriesId];
41
+ } else {
42
+ // Modified click on not-selected item. Add it.
43
+ draft[seriesId] = true;
44
+ }
45
+ return draft;
46
+ }
47
+ if (isSelected) {
48
+ // Clicked item was already selected. Unselect it and return to
49
+ // ALL state.
50
+ return 'ALL';
51
+ }
52
+ // Select clicked item.
53
+ return {
54
+ [seriesId]: true
55
+ };
56
+ });
57
+ onSelectedItemsChange(newSelected);
58
+ };
59
+ const mode = getLegendMode(options.mode);
60
+ // The bottom legend is displayed as a list when the number of items is too
61
+ // large and requires virtualization. Otherwise, it is rendered more compactly.
62
+ // We do not need this check for the right-side legend because it is always
63
+ // a virtualized list.
64
+ const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
65
+ const commonLegendProps = {
66
+ height,
67
+ items: data,
68
+ selectedItems,
69
+ onLegendItemClick
70
+ };
71
+ let legendContent;
72
+ if (mode === 'Table') {
73
+ legendContent = /*#__PURE__*/ _jsx(TableLegend, {
74
+ ...commonLegendProps,
75
+ onSelectedItemsChange: onSelectedItemsChange,
76
+ width: width
77
+ });
78
+ } else if (options.position === 'Right' || needsVirtualization) {
79
+ legendContent = /*#__PURE__*/ _jsx(ListLegend, {
80
+ ...commonLegendProps,
81
+ width: width,
82
+ onLegendItemClick: onLegendItemClick
83
+ });
84
+ } else {
85
+ legendContent = /*#__PURE__*/ _jsx(CompactLegend, {
86
+ ...commonLegendProps,
87
+ onLegendItemClick: onLegendItemClick
88
+ });
89
+ }
24
90
  if (options.position === 'Right') {
25
91
  return /*#__PURE__*/ _jsx(Box, {
26
92
  sx: {
@@ -30,19 +96,10 @@ export function Legend({ width , height , options , data , listProps }) {
30
96
  top: 0,
31
97
  right: 0
32
98
  },
33
- children: /*#__PURE__*/ _jsx(ListLegend, {
34
- items: data,
35
- width: width,
36
- height: height,
37
- ...listProps
38
- })
99
+ children: legendContent
39
100
  });
40
101
  }
41
- // The bottom legend is displayed as a list when the number of items is too
42
- // large and requires virtualization. Otherwise, it is rendered more compactly.
43
- // We do not need this check for the right-side legend because it is always
44
- // a virtualized list.
45
- const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
102
+ // Position bottom
46
103
  return /*#__PURE__*/ _jsx(Box, {
47
104
  sx: {
48
105
  width: width,
@@ -50,15 +107,7 @@ export function Legend({ width , height , options , data , listProps }) {
50
107
  position: 'absolute',
51
108
  bottom: 0
52
109
  },
53
- children: needsVirtualization ? /*#__PURE__*/ _jsx(ListLegend, {
54
- items: data,
55
- width: width,
56
- height: height,
57
- ...listProps
58
- }) : /*#__PURE__*/ _jsx(CompactLegend, {
59
- items: data,
60
- height: height
61
- })
110
+ children: legendContent
62
111
  });
63
112
  }
64
113
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Legend/Legend.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box } from '@mui/material';\nimport { LegendOptions, LegendItem } from '../model';\nimport { ListLegend, ListLegendProps } from './ListLegend';\nimport { CompactLegend } from './CompactLegend';\n\nexport interface LegendProps {\n width: number;\n height: number;\n data: LegendItem[];\n options: LegendOptions;\n\n /**\n * Additional props that will be passed to the list variation of the legend\n * that is used when:\n * - The legend is positioned on the right.\n * - The legend has a large number of items to display and requires virtualization\n * to render performantly.\n */\n listProps?: Pick<ListLegendProps, 'initialRowHeight'>;\n}\n\n// When the number of items to display is above this number, it is likely to\n// cause performance issues in the browser. The legend will be displayed in a\n// format (list) that allows for virtualization to minimize the performance impact.\n// Set this number based on testing, but it may need to be tuned a bit on the\n// future as people test this out on different machines.\nconst NEED_VIRTUALIZATION_LIMIT = 500;\n\nexport function Legend({ width, height, options, data, listProps }: LegendProps) {\n if (options.position === 'Right') {\n return (\n <Box\n sx={{\n width: width,\n height: height,\n position: 'absolute',\n top: 0,\n right: 0,\n }}\n >\n <ListLegend items={data} width={width} height={height} {...listProps} />\n </Box>\n );\n }\n\n // The bottom legend is displayed as a list when the number of items is too\n // large and requires virtualization. Otherwise, it is rendered more compactly.\n // We do not need this check for the right-side legend because it is always\n // a virtualized list.\n const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;\n return (\n <Box\n sx={{\n width: width,\n height: height,\n position: 'absolute',\n bottom: 0,\n }}\n >\n {needsVirtualization ? (\n <ListLegend items={data} width={width} height={height} {...listProps} />\n ) : (\n <CompactLegend items={data} height={height} />\n )}\n </Box>\n );\n}\n"],"names":["Box","ListLegend","CompactLegend","NEED_VIRTUALIZATION_LIMIT","Legend","width","height","options","data","listProps","position","sx","top","right","items","needsVirtualization","length","bottom"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,GAAG,QAAQ,eAAe,CAAC;AAEpC,SAASC,UAAU,QAAyB,cAAc,CAAC;AAC3D,SAASC,aAAa,QAAQ,iBAAiB,CAAC;AAkBhD,4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Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box } from '@mui/material';\nimport { produce } from 'immer';\nimport { ReactNode } from 'react';\nimport { LegendOptions, LegendItem, SelectedLegendItemState, getLegendMode } from '../model';\nimport { ListLegend } from './ListLegend';\nimport { CompactLegend } from './CompactLegend';\nimport { TableLegend } from './TableLegend';\n\nexport interface LegendProps {\n width: number;\n height: number;\n data: LegendItem[];\n options: LegendOptions;\n\n /**\n * State of selected items in the legend.\n *\n * Selected legend item state is a controlled value that should be managed using a\n * combination of this prop and `onSelectedChange`.\n */\n selectedItems: SelectedLegendItemState;\n\n /**\n * Callback fired when the selected items in the legend changes.\n */\n onSelectedItemsChange: (newSelected: SelectedLegendItemState) => void;\n}\n\n// When the number of items to display is above this number, it is likely to\n// cause performance issues in the browser. The legend will be displayed in a\n// format (list) that allows for virtualization to minimize the performance impact.\n// Set this number based on testing, but it may need to be tuned a bit on the\n// future as people test this out on different machines.\nconst NEED_VIRTUALIZATION_LIMIT = 500;\n\nexport function Legend({ width, height, options, data, selectedItems, onSelectedItemsChange }: LegendProps) {\n const onLegendItemClick = (e: React.MouseEvent<HTMLElement, MouseEvent>, seriesId: string) => {\n const isModifiedClick = e.metaKey || e.shiftKey;\n\n const newSelected = produce(selectedItems, (draft) => {\n if (draft === 'ALL') {\n return {\n [seriesId]: true,\n };\n }\n\n const isSelected = !!draft[seriesId];\n\n // Clicks with modifier key can select multiple items.\n if (isModifiedClick) {\n if (isSelected) {\n // Modified click on already selected item. Remove that item.\n delete draft[seriesId];\n } else {\n // Modified click on not-selected item. Add it.\n draft[seriesId] = true;\n }\n return draft;\n }\n\n if (isSelected) {\n // Clicked item was already selected. Unselect it and return to\n // ALL state.\n return 'ALL' as const;\n }\n\n // Select clicked item.\n return { [seriesId]: true };\n });\n onSelectedItemsChange(newSelected);\n };\n\n const mode = getLegendMode(options.mode);\n\n // The bottom legend is displayed as a list when the number of items is too\n // large and requires virtualization. Otherwise, it is rendered more compactly.\n // We do not need this check for the right-side legend because it is always\n // a virtualized list.\n const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;\n\n const commonLegendProps = {\n height,\n items: data,\n selectedItems,\n onLegendItemClick,\n };\n\n let legendContent: ReactNode;\n if (mode === 'Table') {\n legendContent = <TableLegend {...commonLegendProps} onSelectedItemsChange={onSelectedItemsChange} width={width} />;\n } else if (options.position === 'Right' || needsVirtualization) {\n legendContent = <ListLegend {...commonLegendProps} width={width} onLegendItemClick={onLegendItemClick} />;\n } else {\n legendContent = <CompactLegend {...commonLegendProps} onLegendItemClick={onLegendItemClick} />;\n }\n\n if (options.position === 'Right') {\n return (\n <Box\n sx={{\n width: width,\n height: height,\n position: 'absolute',\n top: 0,\n right: 0,\n }}\n >\n {legendContent}\n </Box>\n );\n }\n\n // Position bottom\n return (\n <Box\n sx={{\n width: width,\n height: height,\n position: 'absolute',\n bottom: 0,\n }}\n >\n {legendContent}\n </Box>\n );\n}\n"],"names":["Box","produce","getLegendMode","ListLegend","CompactLegend","TableLegend","NEED_VIRTUALIZATION_LIMIT","Legend","width","height","options","data","selectedItems","onSelectedItemsChange","onLegendItemClick","e","seriesId","isModifiedClick","metaKey","shiftKey","newSelected","draft","isSelected","mode","needsVirtualization","length","commonLegendProps","items","legendContent","position","sx","top","right","bottom"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,GAAG,QAAQ,eAAe,CA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CACN;IACJ,CAAC;IAED,kBAAkB;IAClB,qBACE,KAAC5B,GAAG;QACF8B,EAAE,EAAE;YACFtB,KAAK,EAAEA,KAAK;YACZC,MAAM,EAAEA,MAAM;YACdoB,QAAQ,EAAE,UAAU;YACpBI,MAAM,EAAE,CAAC;SACV;kBAEAL,aAAa;MACV,CACN;AACJ,CAAC"}
@@ -1,15 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { LegendItem } from '../model';
2
+ import { LegendItem, SelectedLegendItemState } from '../model';
3
+ import { ListLegendItemProps } from './ListLegendItem';
3
4
  export interface ListLegendProps {
4
5
  items: LegendItem[];
5
6
  height: number;
6
7
  width: number;
7
- /**
8
- * The height used when initially laying out items in the list. Once items
9
- * render, the height is determined based on the content. This is needed
10
- * because the list is virtualized.
11
- */
12
- initialRowHeight?: number;
8
+ selectedItems: SelectedLegendItemState;
9
+ onLegendItemClick: ListLegendItemProps['onClick'];
13
10
  }
14
11
  /**
15
12
  * ListLegend is used when legend.position is 'right' since legend items are
@@ -17,5 +14,5 @@ export interface ListLegendProps {
17
14
  * large number of items because it is virtualized and easier to visually scan
18
15
  * large numbers of items when there is a single item per row.
19
16
  */
20
- export declare function ListLegend({ items, height, width, initialRowHeight }: ListLegendProps): JSX.Element;
17
+ export declare function ListLegend({ items, height, width, selectedItems, onLegendItemClick }: ListLegendProps): JSX.Element;
21
18
  //# sourceMappingURL=ListLegend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ListLegend.d.ts","sourceRoot":"","sources":["../../src/Legend/ListLegend.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAID;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAA6C,EAAE,EAAE,eAAe,eAgIlH"}
1
+ {"version":3,"file":"ListLegend.d.ts","sourceRoot":"","sources":["../../src/Legend/ListLegend.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAgC,MAAM,UAAU,CAAC;AAC7F,OAAO,EAAkB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,uBAAuB,CAAC;IACvC,iBAAiB,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CACnD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,EAAE,eAAe,eA6BrG"}
@@ -11,125 +11,39 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { useTheme } from '@mui/material';
15
- import { VariableSizeList } from 'react-window';
16
- import { useRef, useEffect, forwardRef, useCallback } from 'react';
14
+ import { Virtuoso } from 'react-virtuoso';
15
+ import { isLegendItemVisuallySelected } from '../model';
17
16
  import { ListLegendItem } from './ListLegendItem';
18
- const DEFAULT_INITIAL_ROW_HEIGHT = 26;
19
17
  /**
20
18
  * ListLegend is used when legend.position is 'right' since legend items are
21
19
  * stacked. It is also used for `bottom` positioned legends when there are a
22
20
  * large number of items because it is virtualized and easier to visually scan
23
21
  * large numbers of items when there is a single item per row.
24
- */ export function ListLegend({ items , height , width , initialRowHeight =DEFAULT_INITIAL_ROW_HEIGHT }) {
25
- // Storing a ref to the react-window `VariableSizeList`, so we can call
26
- // `resetAfterIndex` to resize the list after mouseover/out events to account
27
- // for the change in list items on hover.
28
- const listRef = useRef(null);
29
- // Storing row heights, so we can use dynamic heights, which enables the
30
- // user the hover to show the full label, while still having a virtualized
31
- // list.
32
- const rowHeights = useRef({});
33
- const theme = useTheme();
34
- // Padding value used throughout to adjust the react-window virtual layouts
35
- // to simulate padding per the guidance from:
36
- // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
37
- const LIST_PADDING = parseInt(theme.spacing(1), 10);
22
+ */ export function ListLegend({ items , height , width , selectedItems , onLegendItemClick }) {
38
23
  // show full labels on hover when there are many total series
39
24
  const truncateLabels = items.length > 5;
40
- // Gets the row height for a given item to enable the virtualized list to
41
- // render the row properly.
42
- function getRowHeight(index) {
43
- const currentHeight = rowHeights.current[index];
44
- return currentHeight !== null && currentHeight !== void 0 ? currentHeight : initialRowHeight;
45
- }
46
- // Set the height for a given item to enable the virtualized list to
47
- // adjust to size changes.
48
- function setRowHeight(index, size) {
49
- var // Tell the virtualized list that items changed size and need to be
50
- // re-evaluated.
51
- ref;
52
- (ref = listRef.current) === null || ref === void 0 ? void 0 : ref.resetAfterIndex(0);
53
- rowHeights.current = {
54
- ...rowHeights.current,
55
- [index]: size
56
- };
57
- }
58
- // Renderer for virtualized rows in `VariableSizeList`.
59
- function ListLegendRow({ index , style }) {
60
- // Storing a ref to the row's `ListLegendItem`, so we can get the "real"
61
- // height and adjust the height of the row based on it, enabling the dynamic
62
- // heights on hover.
63
- const rowRef = useRef(null);
64
- // useCallback is important here to avoid constantly running the useEffect
65
- // that calls this in `ListLegendItem`.
66
- const handleRowLayoutChange = useCallback(()=>{
67
- // Handle size changes from hovering on a list item.
68
- if (rowRef.current) {
69
- setRowHeight(index, rowRef.current.clientHeight);
70
- }
71
- }, [
72
- index
73
- ]);
74
- // Adjust row heights when the row being rendered changes.
75
- useEffect(()=>{
76
- handleRowLayoutChange();
77
- }, [
78
- handleRowLayoutChange
79
- ]);
80
- const item = items[index];
81
- if (!item) {
82
- // This shouldn't happen if configured correctly, but covering
83
- // the case to appease the type checking and to cover any edge
84
- // cases.
85
- return null;
86
- }
87
- const originalTop = parseFloat(`${style.top}`);
88
- return /*#__PURE__*/ _jsx("div", {
89
- style: {
90
- ...style,
91
- // Adjust the top position to simulate top padding on the list.
92
- top: `${originalTop + LIST_PADDING}px`
93
- },
94
- children: /*#__PURE__*/ _jsx(ListLegendItem, {
95
- ref: rowRef,
25
+ return /*#__PURE__*/ _jsx(Virtuoso, {
26
+ style: {
27
+ height,
28
+ width
29
+ },
30
+ data: items,
31
+ itemContent: (index, item)=>{
32
+ return /*#__PURE__*/ _jsx(ListLegendItem, {
96
33
  item: item,
97
34
  truncateLabel: truncateLabels,
98
- onLayoutChange: handleRowLayoutChange,
35
+ isVisuallySelected: isLegendItemVisuallySelected(item, selectedItems),
36
+ onClick: onLegendItemClick,
99
37
  sx: {
100
38
  // Having an explicit width is important for the ellipsizing to
101
39
  // work correctly. Subtract padding to simulate padding.
102
- width: width - LIST_PADDING,
40
+ width: width,
103
41
  wordBreak: 'break-word',
104
42
  overflow: 'hidden'
105
43
  }
106
- }, item.id)
107
- });
108
- }
109
- // Renderer for the inner container element of the `VariableSizeList` used
110
- // to adjust styles to simulate padding on the list per:
111
- // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
112
- const InnerElementType = /*#__PURE__*/ forwardRef(function InnerElementType({ style , ...rest }, ref) {
113
- const originalHeight = (style === null || style === void 0 ? void 0 : style.height) ? parseFloat(`${style === null || style === void 0 ? void 0 : style.height}`) : 0;
114
- return /*#__PURE__*/ _jsx("div", {
115
- ref: ref,
116
- role: "list",
117
- style: {
118
- ...style,
119
- // Adjust height to account for simulated padding.
120
- height: `${originalHeight + LIST_PADDING * 2}px`
121
- },
122
- ...rest
123
- });
124
- });
125
- return /*#__PURE__*/ _jsx(VariableSizeList, {
126
- height: height,
127
- width: width,
128
- itemCount: items.length,
129
- itemSize: getRowHeight,
130
- innerElementType: InnerElementType,
131
- ref: listRef,
132
- children: ListLegendRow
44
+ }, item.id);
45
+ },
46
+ role: "list"
133
47
  });
134
48
  }
135
49
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Legend/ListLegend.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useTheme } from '@mui/material';\nimport { VariableSizeList, ListChildComponentProps } from 'react-window';\nimport { useRef, useEffect, forwardRef, useCallback } from 'react';\nimport { LegendItem } from '../model';\nimport { ListLegendItem } from './ListLegendItem';\n\nexport interface ListLegendProps {\n items: LegendItem[];\n height: number;\n width: number;\n\n /**\n * The height used when initially laying out items in the list. Once items\n * render, the height is determined based on the content. This is needed\n * because the list is virtualized.\n */\n initialRowHeight?: number;\n}\n\nconst DEFAULT_INITIAL_ROW_HEIGHT = 26;\n\n/**\n * ListLegend is used when legend.position is 'right' since legend items are\n * stacked. It is also used for `bottom` positioned legends when there are a\n * large number of items because it is virtualized and easier to visually scan\n * large numbers of items when there is a single item per row.\n */\nexport function ListLegend({ items, height, width, initialRowHeight = DEFAULT_INITIAL_ROW_HEIGHT }: ListLegendProps) {\n // Storing a ref to the react-window `VariableSizeList`, so we can call\n // `resetAfterIndex` to resize the list after mouseover/out events to account\n // for the change in list items on hover.\n const listRef = useRef<VariableSizeList>(null);\n // Storing row heights, so we can use dynamic heights, which enables the\n // user the hover to show the full label, while still having a virtualized\n // list.\n const rowHeights = useRef<Record<number, number>>({});\n\n const theme = useTheme();\n // Padding value used throughout to adjust the react-window virtual layouts\n // to simulate padding per the guidance from:\n // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list\n const LIST_PADDING = parseInt(theme.spacing(1), 10);\n\n // show full labels on hover when there are many total series\n const truncateLabels = items.length > 5;\n\n // Gets the row height for a given item to enable the virtualized list to\n // render the row properly.\n function getRowHeight(index: number) {\n const currentHeight = rowHeights.current[index];\n return currentHeight ?? initialRowHeight;\n }\n\n // Set the height for a given item to enable the virtualized list to\n // adjust to size changes.\n function setRowHeight(index: number, size: number) {\n // Tell the virtualized list that items changed size and need to be\n // re-evaluated.\n listRef.current?.resetAfterIndex(0);\n rowHeights.current = { ...rowHeights.current, [index]: size };\n }\n\n // Renderer for virtualized rows in `VariableSizeList`.\n function ListLegendRow({ index, style }: ListChildComponentProps) {\n // Storing a ref to the row's `ListLegendItem`, so we can get the \"real\"\n // height and adjust the height of the row based on it, enabling the dynamic\n // heights on hover.\n const rowRef = useRef<HTMLDivElement | null>(null);\n\n // useCallback is important here to avoid constantly running the useEffect\n // that calls this in `ListLegendItem`.\n const handleRowLayoutChange = useCallback(() => {\n // Handle size changes from hovering on a list item.\n if (rowRef.current) {\n setRowHeight(index, rowRef.current.clientHeight);\n }\n }, [index]);\n\n // Adjust row heights when the row being rendered changes.\n useEffect(() => {\n handleRowLayoutChange();\n }, [handleRowLayoutChange]);\n\n const item = items[index];\n\n if (!item) {\n // This shouldn't happen if configured correctly, but covering\n // the case to appease the type checking and to cover any edge\n // cases.\n return null;\n }\n\n const originalTop = parseFloat(`${style.top}`);\n\n return (\n <div\n style={{\n ...style,\n // Adjust the top position to simulate top padding on the list.\n top: `${originalTop + LIST_PADDING}px`,\n }}\n >\n <ListLegendItem\n ref={rowRef}\n key={item.id}\n item={item}\n truncateLabel={truncateLabels}\n onLayoutChange={handleRowLayoutChange}\n sx={{\n // Having an explicit width is important for the ellipsizing to\n // work correctly. Subtract padding to simulate padding.\n width: width - LIST_PADDING,\n wordBreak: 'break-word',\n overflow: 'hidden',\n }}\n />\n </div>\n );\n }\n\n // Renderer for the inner container element of the `VariableSizeList` used\n // to adjust styles to simulate padding on the list per:\n // https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list\n const InnerElementType = forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>(function InnerElementType(\n { style, ...rest },\n ref\n ) {\n const originalHeight = style?.height ? parseFloat(`${style?.height}`) : 0;\n\n return (\n <div\n ref={ref}\n role=\"list\"\n style={{\n ...style,\n // Adjust height to account for simulated padding.\n height: `${originalHeight + LIST_PADDING * 2}px`,\n }}\n {...rest}\n />\n );\n });\n\n return (\n <VariableSizeList\n height={height}\n width={width}\n itemCount={items.length}\n itemSize={getRowHeight}\n innerElementType={InnerElementType}\n ref={listRef}\n >\n {ListLegendRow}\n </VariableSizeList>\n );\n}\n"],"names":["useTheme","VariableSizeList","useRef","useEffect","forwardRef","useCallback","ListLegendItem","DEFAULT_INITIAL_ROW_HEIGHT","ListLegend","items","height","width","initialRowHeight","listRef","rowHeights","theme","LIST_PADDING","parseInt","spacing","truncateLabels","length","getRowHeight","index","currentHeight","current","setRowHeight","size","resetAfterIndex","ListLegendRow","style","rowRef","handleRowLayoutChange","clientHeight","item","originalTop","parseFloat","top","div","ref","truncateLabel","onLayoutChange","sx","wordBreak","overflow","id","InnerElementType","rest","originalHeight","role","itemCount","itemSize","innerElementType"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,eAAe,CAAC;AACzC,SAASC,gBAAgB,QAAiC,cAAc,CAAC;AACzE,SAASC,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAEC,WAAW,QAAQ,OAAO,CAAC;AAEnE,SAASC,cAAc,QAAQ,kBAAkB,CAAC;AAelD,MAAMC,0BAA0B,GAAG,EAAE,AAAC;AAEtC;;;;;CAKC,GACD,OAAO,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Y;oBACvBC,QAAQ,EAAE,QAAQ;iBACnB;eAVIV,IAAI,CAACW,EAAE,CAWZ;UACE,CACN;IACJ,CAAC;IAED,0EAA0E;IAC1E,wDAAwD;IACxD,4FAA4F;IAC5F,MAAMC,gBAAgB,iBAAGzC,UAAU,CAAwD,SAASyC,gBAAgB,CAClH,EAAEhB,KAAK,CAAA,EAAE,GAAGiB,IAAI,EAAE,EAClBR,GAAG,EACH;QACA,MAAMS,cAAc,GAAGlB,CAAAA,KAAK,aAALA,KAAK,WAAQ,GAAbA,KAAAA,CAAa,GAAbA,KAAK,CAAEnB,MAAM,CAAA,GAAGyB,UAAU,CAAC,CAAC,EAAEN,KAAK,aAALA,KAAK,WAAQ,GAAbA,KAAAA,CAAa,GAAbA,KAAK,CAAEnB,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,AAAC;QAE1E,qBACE,KAAC2B,KAAG;YACFC,GAAG,EAAEA,GAAG;YACRU,IAAI,EAAC,MAAM;YACXnB,KAAK,EAAE;gBACL,GAAGA,KAAK;gBACR,kDAAkD;gBAClDnB,MAAM,EAAE,CAAC,EAAEqC,cAAc,GAAG/B,YAAY,GAAG,CAAC,CAAC,EAAE,CAAC;aACjD;YACA,GAAG8B,IAAI;UACR,CACF;IACJ,CAAC,CAAC,AAAC;IAEH,qBACE,KAAC7C,gBAAgB;QACfS,MAAM,EAAEA,MAAM;QACdC,KAAK,EAAEA,KAAK;QACZsC,SAAS,EAAExC,KAAK,CAACW,MAAM;QACvB8B,QAAQ,EAAE7B,YAAY;QACtB8B,gBAAgB,EAAEN,gBAAgB;QAClCP,GAAG,EAAEzB,OAAO;kBAEXe,aAAa;MACG,CACnB;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/Legend/ListLegend.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Virtuoso } from 'react-virtuoso';\nimport { LegendItem, SelectedLegendItemState, isLegendItemVisuallySelected } from '../model';\nimport { ListLegendItem, ListLegendItemProps } from './ListLegendItem';\n\nexport interface ListLegendProps {\n items: LegendItem[];\n height: number;\n width: number;\n selectedItems: SelectedLegendItemState;\n onLegendItemClick: ListLegendItemProps['onClick'];\n}\n\n/**\n * ListLegend is used when legend.position is 'right' since legend items are\n * stacked. It is also used for `bottom` positioned legends when there are a\n * large number of items because it is virtualized and easier to visually scan\n * large numbers of items when there is a single item per row.\n */\nexport function ListLegend({ items, height, width, selectedItems, onLegendItemClick }: ListLegendProps) {\n // show full labels on hover when there are many total series\n const truncateLabels = items.length > 5;\n\n return (\n <Virtuoso\n style={{ height, width }}\n data={items}\n itemContent={(index, item) => {\n return (\n <ListLegendItem\n key={item.id}\n item={item}\n truncateLabel={truncateLabels}\n isVisuallySelected={isLegendItemVisuallySelected(item, selectedItems)}\n onClick={onLegendItemClick}\n sx={{\n // Having an explicit width is important for the ellipsizing to\n // work correctly. Subtract padding to simulate padding.\n width: width,\n wordBreak: 'break-word',\n overflow: 'hidden',\n }}\n />\n );\n }}\n role=\"list\"\n />\n );\n}\n"],"names":["Virtuoso","isLegendItemVisuallySelected","ListLegendItem","ListLegend","items","height","width","selectedItems","onLegendItemClick","truncateLabels","length","style","data","itemContent","index","item","truncateLabel","isVisuallySelected","onClick","sx","wordBreak","overflow","id","role"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,gBAAgB,CAAC;AAC1C,SAA8CC,4BAA4B,QAAQ,UAAU,CAAC;AAC7F,SAASC,cAAc,QAA6B,kBAAkB,CAAC;AAUvE;;;;;CAKC,GACD,OAAO,SAASC,UAAU,CAAC,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,KAAK,CAAA,EAAEC,aAAa,CAAA,EAAEC,iBAAiB,CAAA,EAAmB,EAAE;IACtG,6DAA6D;IAC7D,MAAMC,cAAc,GAAGL,KAAK,CAACM,MAAM,GAAG,CAAC,AAAC;IAExC,qBACE,KAACV,QAAQ;QACPW,KAAK,EAAE;YAAEN,MAAM;YAAEC,KAAK;SAAE;QACxBM,IAAI,EAAER,KAAK;QACXS,WAAW,EAAE,CAACC,KAAK,EAAEC,IAAI,GAAK;YAC5B,qBACE,KAACb,cAAc;gBAEba,IAAI,EAAEA,IAAI;gBACVC,aAAa,EAAEP,cAAc;gBAC7BQ,kBAAkB,EAAEhB,4BAA4B,CAACc,IAAI,EAAER,aAAa,CAAC;gBACrEW,OAAO,EAAEV,iBAAiB;gBAC1BW,EAAE,EAAE;oBACF,+DAA+D;oBAC/D,wDAAwD;oBACxDb,KAAK,EAAEA,KAAK;oBACZc,SAAS,EAAE,YAAY;oBACvBC,QAAQ,EAAE,QAAQ;iBACnB;eAXIN,IAAI,CAACO,EAAE,CAYZ,CACF;QACJ,CAAC;QACDC,IAAI,EAAC,MAAM;MACX,CACF;AACJ,CAAC"}
@@ -1,8 +1,14 @@
1
1
  import React from 'react';
2
2
  import { ListItemProps } from '@mui/material';
3
3
  import { LegendItem } from '../model';
4
- interface ListLegendItemProps extends ListItemProps<'div'> {
4
+ export interface ListLegendItemProps extends Omit<ListItemProps<'div'>, 'onClick'> {
5
5
  item: LegendItem;
6
+ /**
7
+ * When true, the item is rendered differently to visually communicate it is
8
+ * selected.
9
+ */
10
+ isVisuallySelected?: boolean;
11
+ onClick: (e: React.MouseEvent<HTMLElement, MouseEvent>, seriesId: string) => void;
6
12
  /**
7
13
  * When `true`, will keep labels to a single line with overflow ellipsized. The
8
14
  * full content will be shown on hover.
@@ -10,12 +16,6 @@ interface ListLegendItemProps extends ListItemProps<'div'> {
10
16
  * When `false` or unset, will show the full label.
11
17
  */
12
18
  truncateLabel?: boolean;
13
- /**
14
- * Called when the layout of the legend item changes as a result of the hover
15
- * behavior when `truncateLabel` is `true`.
16
- */
17
- onLayoutChange?: () => void;
18
19
  }
19
- export declare const ListLegendItem: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<ListLegendItemProps, "classes" | "className" | "style" | "children" | "sx" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "alignItems" | "disabled" | "selected" | "divider" | "components" | "componentsProps" | "slotProps" | "slots" | "dense" | "disableGutters" | "ContainerComponent" | "ContainerProps" | "disablePadding" | "secondaryAction" | "item" | "truncateLabel" | "onLayoutChange"> & React.RefAttributes<HTMLDivElement>>>;
20
- export {};
20
+ export declare const ListLegendItem: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<ListLegendItemProps, "classes" | "className" | "style" | "children" | "sx" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "alignItems" | "disabled" | "selected" | "divider" | "components" | "componentsProps" | "slotProps" | "slots" | "dense" | "ContainerComponent" | "ContainerProps" | "disableGutters" | "disablePadding" | "secondaryAction" | "item" | "isVisuallySelected" | "truncateLabel"> & React.RefAttributes<HTMLDivElement>>>;
21
21
  //# sourceMappingURL=ListLegendItem.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ListLegendItem.d.ts","sourceRoot":"","sources":["../../src/Legend/ListLegendItem.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAC/D,OAAO,EAA+B,aAAa,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAItC,UAAU,mBAAoB,SAAQ,aAAa,CAAC,KAAK,CAAC;IACxD,IAAI,EAAE,UAAU,CAAC;IAEjB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAyDD,eAAO,MAAM,cAAc,g6JAAiC,CAAC"}
1
+ {"version":3,"file":"ListLegendItem.d.ts","sourceRoot":"","sources":["../../src/Legend/ListLegendItem.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA+B,MAAM,OAAO,CAAC;AACpD,OAAO,EAA+B,aAAa,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAItC,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC;IAChF,IAAI,EAAE,UAAU,CAAC;IAEjB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B,OAAO,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAElF;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAwDD,eAAO,MAAM,cAAc,o6JAAiC,CAAC"}
@@ -12,11 +12,11 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { createElement as _createElement } from "react";
15
- import React, { forwardRef, useState, useEffect } from 'react';
15
+ import React, { forwardRef, useState } from 'react';
16
16
  import { Box, ListItemText, ListItem } from '@mui/material';
17
17
  import { combineSx } from '../utils';
18
18
  import { LegendColorBadge } from './LegendColorBadge';
19
- const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ item , sx , truncateLabel , onLayoutChange , ...others }, ref) {
19
+ const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ item , sx , truncateLabel , onClick , isVisuallySelected , ...others }, ref) {
20
20
  const [noWrap, setNoWrap] = useState(truncateLabel);
21
21
  function handleMouseOver() {
22
22
  if (truncateLabel) {
@@ -28,14 +28,11 @@ const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ it
28
28
  setNoWrap(true);
29
29
  }
30
30
  }
31
- useEffect(()=>{
32
- // When `noWrap` changes, so does the layout of the component. Notifies the
33
- // parent, so it can handle those changes.
34
- onLayoutChange === null || onLayoutChange === void 0 ? void 0 : onLayoutChange();
35
- }, [
36
- noWrap,
37
- onLayoutChange
38
- ]);
31
+ const handleClick = (e)=>{
32
+ var ref;
33
+ onClick(e, item.id);
34
+ (ref = item.onClick) === null || ref === void 0 ? void 0 : ref.call(item, e);
35
+ };
39
36
  return /*#__PURE__*/ _createElement(ListItem, {
40
37
  ...others,
41
38
  component: "div",
@@ -46,8 +43,8 @@ const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ it
46
43
  }, sx),
47
44
  dense: true,
48
45
  key: item.id,
49
- onClick: item.onClick,
50
- selected: item.isSelected,
46
+ onClick: handleClick,
47
+ selected: isVisuallySelected,
51
48
  ref: ref,
52
49
  children: [
53
50
  /*#__PURE__*/ _jsx(Box, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Legend/ListLegendItem.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { forwardRef, useState, useEffect } from 'react';\nimport { Box, ListItemText, ListItem, ListItemProps } from '@mui/material';\nimport { LegendItem } from '../model';\nimport { combineSx } from '../utils';\nimport { LegendColorBadge } from './LegendColorBadge';\n\ninterface ListLegendItemProps extends ListItemProps<'div'> {\n item: LegendItem;\n\n /**\n * When `true`, will keep labels to a single line with overflow ellipsized. The\n * full content will be shown on hover.\n *\n * When `false` or unset, will show the full label.\n */\n truncateLabel?: boolean;\n\n /**\n * Called when the layout of the legend item changes as a result of the hover\n * behavior when `truncateLabel` is `true`.\n */\n onLayoutChange?: () => void;\n}\n\nconst ListLegendItemBase = forwardRef<HTMLDivElement, ListLegendItemProps>(function ListLegendItem(\n { item, sx, truncateLabel, onLayoutChange, ...others },\n ref\n) {\n const [noWrap, setNoWrap] = useState(truncateLabel);\n\n function handleMouseOver() {\n if (truncateLabel) {\n setNoWrap(false);\n }\n }\n\n function handleMouseOut() {\n if (truncateLabel) {\n setNoWrap(true);\n }\n }\n\n useEffect(() => {\n // When `noWrap` changes, so does the layout of the component. Notifies the\n // parent, so it can handle those changes.\n onLayoutChange?.();\n }, [noWrap, onLayoutChange]);\n\n return (\n <ListItem\n {...others}\n component=\"div\"\n role=\"listitem\"\n sx={combineSx(\n {\n padding: 0,\n cursor: 'pointer',\n },\n sx\n )}\n dense={true}\n key={item.id}\n onClick={item.onClick}\n selected={item.isSelected}\n ref={ref}\n >\n <Box sx={{ display: 'flex', alignItems: 'center' }}>\n <LegendColorBadge color={item.color} />\n </Box>\n <ListItemText\n primary={item.label}\n primaryTypographyProps={{ noWrap: noWrap }}\n onMouseOver={handleMouseOver}\n onMouseOut={handleMouseOut}\n ></ListItemText>\n </ListItem>\n );\n});\n\nexport const ListLegendItem = React.memo(ListLegendItemBase);\n"],"names":["React","forwardRef","useState","useEffect","Box","ListItemText","ListItem","combineSx","LegendColorBadge","ListLegendItemBase","ListLegendItem","item","sx","truncateLabel","onLayoutChange","others","ref","noWrap","setNoWrap","handleMouseOver","handleMouseOut","component","role","padding","cursor","dense","key","id","onClick","selected","isSelected","display","alignItems","color","primary","label","primaryTypographyProps","onMouseOver","onMouseOut","memo"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,OAAO,CAAC;AAC/D,SAASC,GAAG,EAAEC,YAAY,EAAEC,QAAQ,QAAuB,eAAe,CAAC;AAE3E,SAASC,SAAS,QAAQ,UAAU,CAAC;AACrC,SAASC,gBAAgB,QAAQ,oBAAoB,CAAC;AAoBtD,MAAMC,kBAAkB,iBAAGR,UAAU,CAAsC,SAASS,cAAc,CAChG,EAAEC,IAAI,CAAA,EAAEC,EAAE,CAAA,EAAEC,aAAa,CAAA,EAAEC,cAAc,CAAA,EAAE,GAAGC,MAAM,EAAE,EACtDC,GAAG,EACH;IACA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ACZ;;MACP,CACX;AACJ,CAAC,CAAC,AAAC;AAEH,OAAO,MAAMV,cAAc,iBAAGV,KAAK,CAACuC,IAAI,CAAC9B,kBAAkB,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../src/Legend/ListLegendItem.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { forwardRef, useState } from 'react';\nimport { Box, ListItemText, ListItem, ListItemProps } from '@mui/material';\nimport { LegendItem } from '../model';\nimport { combineSx } from '../utils';\nimport { LegendColorBadge } from './LegendColorBadge';\n\nexport interface ListLegendItemProps extends Omit<ListItemProps<'div'>, 'onClick'> {\n item: LegendItem;\n\n /**\n * When true, the item is rendered differently to visually communicate it is\n * selected.\n */\n isVisuallySelected?: boolean;\n\n onClick: (e: React.MouseEvent<HTMLElement, MouseEvent>, seriesId: string) => void;\n\n /**\n * When `true`, will keep labels to a single line with overflow ellipsized. The\n * full content will be shown on hover.\n *\n * When `false` or unset, will show the full label.\n */\n truncateLabel?: boolean;\n}\n\nconst ListLegendItemBase = forwardRef<HTMLDivElement, ListLegendItemProps>(function ListLegendItem(\n { item, sx, truncateLabel, onClick, isVisuallySelected, ...others },\n ref\n) {\n const [noWrap, setNoWrap] = useState(truncateLabel);\n\n function handleMouseOver() {\n if (truncateLabel) {\n setNoWrap(false);\n }\n }\n\n function handleMouseOut() {\n if (truncateLabel) {\n setNoWrap(true);\n }\n }\n\n const handleClick: React.MouseEventHandler<HTMLDivElement> = (e) => {\n onClick(e, item.id);\n item.onClick?.(e);\n };\n\n return (\n <ListItem\n {...others}\n component=\"div\"\n role=\"listitem\"\n sx={combineSx(\n {\n padding: 0,\n cursor: 'pointer',\n },\n sx\n )}\n dense={true}\n key={item.id}\n onClick={handleClick}\n selected={isVisuallySelected}\n ref={ref}\n >\n <Box sx={{ display: 'flex', alignItems: 'center' }}>\n <LegendColorBadge color={item.color} />\n </Box>\n <ListItemText\n primary={item.label}\n primaryTypographyProps={{ noWrap: noWrap }}\n onMouseOver={handleMouseOver}\n onMouseOut={handleMouseOut}\n ></ListItemText>\n </ListItem>\n );\n});\n\nexport const ListLegendItem = React.memo(ListLegendItemBase);\n"],"names":["React","forwardRef","useState","Box","ListItemText","ListItem","combineSx","LegendColorBadge","ListLegendItemBase","ListLegendItem","item","sx","truncateLabel","onClick","isVisuallySelected","others","ref","noWrap","setNoWrap","handleMouseOver","handleMouseOut","handleClick","e","id","component","role","padding","cursor","dense","key","selected","display","alignItems","color","primary","label","primaryTypographyProps","onMouseOver","onMouseOut","memo"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACpD,SAASC,GAAG,EAAEC,YAAY,EAAEC,QAAQ,QAAuB,eAAe,CAAC;AAE3E,SAASC,SAAS,QAAQ,UAAU,CAAC;AACrC,SAASC,gBAAgB,QAAQ,oBAAoB,CAAC;AAsBtD,MAAMC,kBAAkB,iBAAGP,UAAU,CAAsC,SAASQ,cAAc,CAChG,EAAEC,IAAI,CAAA,EAAEC,EAAE,CAAA,EAAEC,aAAa,CAAA,EAAEC,OAAO,CAAA,EAAEC,kBAAkB,CAAA,EAAE,GAAGC,MAAM,EAAE,EACnEC,GAAG,EACH;IACA,MAAM,CAACC,MAAM,EAAEC,SAAS,CAAC,GAAGhB,QA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BmB,UAAU,EAAElB,cAAc;cACZ;;MACP,CACX;AACJ,CAAC,CAAC,AAAC;AAEH,OAAO,MAAMX,cAAc,iBAAGT,KAAK,CAACuC,IAAI,CAAC/B,kBAAkB,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { TableProps } from '../Table';
3
+ import { LegendItem } from '../model';
4
+ export interface TableLegendProps {
5
+ items: LegendItem[];
6
+ height: number;
7
+ width: number;
8
+ selectedItems: TableProps<LegendItem>['rowSelection'] | 'ALL';
9
+ onSelectedItemsChange: TableProps<LegendItem>['onRowSelectionChange'];
10
+ }
11
+ export declare function TableLegend({ items, selectedItems: initRowSelection, onSelectedItemsChange, height, width, }: TableLegendProps): JSX.Element;
12
+ //# sourceMappingURL=TableLegend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TableLegend.d.ts","sourceRoot":"","sources":["../../src/Legend/TableLegend.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAS,UAAU,EAAqB,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,cAAc,CAAC,GAAG,KAAK,CAAC;IAC9D,qBAAqB,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,sBAAsB,CAAC,CAAC;CACvE;AAsBD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,aAAa,EAAE,gBAAgB,EAC/B,qBAAqB,EACrB,MAAM,EACN,KAAK,GACN,EAAE,gBAAgB,eA2BlB"}
@@ -0,0 +1,61 @@
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
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { useMemo } from 'react';
15
+ import { Table } from '../Table';
16
+ const COLUMNS = [
17
+ {
18
+ accessorKey: 'label',
19
+ header: 'Name',
20
+ // Starting with `title` attr instead of a tooltip because it is easier to
21
+ // implement. We should try adding a tooltip in the future, but we'll need
22
+ // to be very careful about performance when doing so with large tables.
23
+ cell: ({ getValue })=>/*#__PURE__*/ _jsx("span", {
24
+ title: getValue(),
25
+ children: getValue()
26
+ })
27
+ }
28
+ ];
29
+ const getRowId = (data)=>{
30
+ return data.id;
31
+ };
32
+ const getCheckboxColor = (data)=>{
33
+ return data.color;
34
+ };
35
+ export function TableLegend({ items , selectedItems: initRowSelection , onSelectedItemsChange , height , width }) {
36
+ const rowSelection = useMemo(()=>{
37
+ return typeof initRowSelection !== 'string' ? initRowSelection : // items for checkboxes.
38
+ // TODO: clean this up if we switch to also using checkboxes in list legend.
39
+ items.reduce((allRowSelection, item, index)=>{
40
+ allRowSelection[getRowId(item, index)] = true;
41
+ return allRowSelection;
42
+ }, {});
43
+ }, [
44
+ initRowSelection,
45
+ items
46
+ ]);
47
+ return /*#__PURE__*/ _jsx(Table, {
48
+ height: height,
49
+ width: width,
50
+ rowSelection: rowSelection,
51
+ onRowSelectionChange: onSelectedItemsChange,
52
+ data: items,
53
+ columns: COLUMNS,
54
+ density: "compact",
55
+ getRowId: getRowId,
56
+ getCheckboxColor: getCheckboxColor,
57
+ checkboxSelection: true
58
+ });
59
+ }
60
+
61
+ //# sourceMappingURL=TableLegend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Legend/TableLegend.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useMemo } from 'react';\nimport { Table, TableProps, TableColumnConfig } from '../Table';\nimport { LegendItem } from '../model';\n\nexport interface TableLegendProps {\n items: LegendItem[];\n height: number;\n width: number;\n selectedItems: TableProps<LegendItem>['rowSelection'] | 'ALL';\n onSelectedItemsChange: TableProps<LegendItem>['onRowSelectionChange'];\n}\n\nconst COLUMNS: Array<TableColumnConfig<LegendItem>> = [\n {\n accessorKey: 'label',\n header: 'Name',\n\n // Starting with `title` attr instead of a tooltip because it is easier to\n // implement. We should try adding a tooltip in the future, but we'll need\n // to be very careful about performance when doing so with large tables.\n cell: ({ getValue }) => <span title={getValue()}>{getValue()}</span>,\n },\n];\n\nconst getRowId: NonNullable<TableProps<LegendItem>['getRowId']> = (data) => {\n return data.id;\n};\n\nconst getCheckboxColor: TableProps<LegendItem>['getCheckboxColor'] = (data) => {\n return data.color;\n};\n\nexport function TableLegend({\n items,\n selectedItems: initRowSelection,\n onSelectedItemsChange,\n height,\n width,\n}: TableLegendProps) {\n const rowSelection = useMemo(() => {\n return typeof initRowSelection !== 'string'\n ? initRowSelection\n : // Turn \"ALL\" state into a table component friendly map of all of the selected\n // items for checkboxes.\n // TODO: clean this up if we switch to also using checkboxes in list legend.\n items.reduce((allRowSelection, item, index) => {\n allRowSelection[getRowId(item, index)] = true;\n return allRowSelection;\n }, {} as Record<string, boolean>);\n }, [initRowSelection, items]);\n\n return (\n <Table\n height={height}\n width={width}\n rowSelection={rowSelection}\n onRowSelectionChange={onSelectedItemsChange}\n data={items}\n columns={COLUMNS}\n density=\"compact\"\n getRowId={getRowId}\n getCheckboxColor={getCheckboxColor}\n checkboxSelection\n />\n );\n}\n"],"names":["useMemo","Table","COLUMNS","accessorKey","header","cell","getValue","span","title","getRowId","data","id","getCheckboxColor","color","TableLegend","items","selectedItems","initRowSelection","onSelectedItemsChange","height","width","rowSelection","reduce","allRowSelection","item","index","onRowSelectionChange","columns","density","checkboxSelection"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,KAAK,QAAuC,UAAU,CAAC;AAWhE,MAAMC,OAAO,GAAyC;IACpD;QACEC,WAAW,EAAE,OAAO;QACpBC,MAAM,EAAE,MAAM;QAEd,0EAA0E;QAC1E,0EAA0E;QAC1E,wEAAwE;QACxEC,IAAI,EAAE,CAAC,EAAEC,QAAQ,CAAA,EAAE,iBAAK,KAACC,MAAI;gBAACC,KAAK,EAAEF,QAAQ,EAAE;0BAAGA,QAAQ,EAAE;cAAQ;KACrE;CACF,AAAC;AAEF,MAAMG,QAAQ,GAAoD,CAACC,IAAI,GAAK;IAC1E,OAAOA,IAAI,CAACC,EAAE,CAAC;AACjB,CAAC,AAAC;AAEF,MAAMC,gBAAgB,GAA+C,CAACF,IAAI,GAAK;IAC7E,OAAOA,IAAI,CAACG,KAAK,CAAC;AACpB,CAAC,AAAC;AAEF,OAAO,SAASC,WAAW,CAAC,EAC1BC,KAAK,CAAA,EACLC,aAAa,EAAEC,gBAAgB,CAAA,EAC/BC,qBAAqB,CAAA,EACrBC,MAAM,CAAA,EACNC,KAAK,CAAA,EACY,EAAE;IACnB,MAAMC,YAAY,GAAGrB,OAAO,CAAC,IAAM;QACjC,OAAO,OAAOiB,gBAAgB,KAAK,QAAQ,GACvCA,gBAAgB,GAEhB,wBAAwB;QACxB,4EAA4E;QAC5EF,KAAK,CAACO,MAAM,CAAC,CAACC,eAAe,EAAEC,IAAI,EAAEC,KAAK,GAAK;YAC7CF,eAAe,CAACd,QAAQ,CAACe,IAAI,EAAEC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC;YAC9C,OAAOF,eAAe,CAAC;QACzB,CAAC,EAAE,EAAE,CAA4B,CAAC;IACxC,CAAC,EAAE;QAACN,gBAAgB;QAAEF,KAAK;KAAC,CAAC,AAAC;IAE9B,qBACE,KAACd,KAAK;QACJkB,MAAM,EAAEA,MAAM;QACdC,KAAK,EAAEA,KAAK;QACZC,YAAY,EAAEA,YAAY;QAC1BK,oBAAoB,EAAER,qBAAqB;QAC3CR,IAAI,EAAEK,KAAK;QACXY,OAAO,EAAEzB,OAAO;QAChB0B,OAAO,EAAC,SAAS;QACjBnB,QAAQ,EAAEA,QAAQ;QAClBG,gBAAgB,EAAEA,gBAAgB;QAClCiB,iBAAiB;MACjB,CACF;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../src/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":";AAeA,OAAO,EAKL,aAAa,EAEd,MAAM,UAAU,CAAC;AAYlB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eA2ChF"}
1
+ {"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../src/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":";AAeA,OAAO,EAKL,aAAa,EAId,MAAM,UAAU,CAAC;AAqBlB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CAC5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eAwEhF"}