@perses-dev/components 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/Legend/CompactLegend.d.ts +6 -4
  2. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  3. package/dist/Legend/CompactLegend.js +4 -1
  4. package/dist/Legend/CompactLegend.js.map +1 -1
  5. package/dist/Legend/Legend.d.ts +11 -9
  6. package/dist/Legend/Legend.d.ts.map +1 -1
  7. package/dist/Legend/Legend.js +45 -11
  8. package/dist/Legend/Legend.js.map +1 -1
  9. package/dist/Legend/ListLegend.d.ts +5 -8
  10. package/dist/Legend/ListLegend.d.ts.map +1 -1
  11. package/dist/Legend/ListLegend.js +34 -99
  12. package/dist/Legend/ListLegend.js.map +1 -1
  13. package/dist/Legend/ListLegendItem.d.ts +8 -8
  14. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  15. package/dist/Legend/ListLegendItem.js +9 -12
  16. package/dist/Legend/ListLegendItem.js.map +1 -1
  17. package/dist/LineChart/LineChart.d.ts +2 -1
  18. package/dist/LineChart/LineChart.d.ts.map +1 -1
  19. package/dist/LineChart/LineChart.js +31 -22
  20. package/dist/LineChart/LineChart.js.map +1 -1
  21. package/dist/Table/InnerTable.d.ts +9 -0
  22. package/dist/Table/InnerTable.d.ts.map +1 -0
  23. package/dist/Table/InnerTable.js +38 -0
  24. package/dist/Table/InnerTable.js.map +1 -0
  25. package/dist/Table/Table.d.ts +10 -0
  26. package/dist/Table/Table.d.ts.map +1 -0
  27. package/dist/Table/Table.js +101 -0
  28. package/dist/Table/Table.js.map +1 -0
  29. package/dist/Table/TableBody.d.ts +6 -0
  30. package/dist/Table/TableBody.d.ts.map +1 -0
  31. package/dist/Table/TableBody.js +23 -0
  32. package/dist/Table/TableBody.js.map +1 -0
  33. package/dist/Table/TableCell.d.ts +18 -0
  34. package/dist/Table/TableCell.d.ts.map +1 -0
  35. package/dist/Table/TableCell.js +91 -0
  36. package/dist/Table/TableCell.js.map +1 -0
  37. package/dist/Table/TableCheckbox.d.ts +9 -0
  38. package/dist/Table/TableCheckbox.d.ts.map +1 -0
  39. package/dist/Table/TableCheckbox.js +49 -0
  40. package/dist/Table/TableCheckbox.js.map +1 -0
  41. package/dist/Table/TableHead.d.ts +6 -0
  42. package/dist/Table/TableHead.d.ts.map +1 -0
  43. package/dist/Table/TableHead.js +23 -0
  44. package/dist/Table/TableHead.js.map +1 -0
  45. package/dist/Table/TableRow.d.ts +9 -0
  46. package/dist/Table/TableRow.d.ts.map +1 -0
  47. package/dist/Table/TableRow.js +29 -0
  48. package/dist/Table/TableRow.js.map +1 -0
  49. package/dist/Table/VirtualizedTable.d.ts +11 -0
  50. package/dist/Table/VirtualizedTable.d.ts.map +1 -0
  51. package/dist/Table/VirtualizedTable.js +152 -0
  52. package/dist/Table/VirtualizedTable.js.map +1 -0
  53. package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
  54. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
  55. package/dist/Table/VirtualizedTableContainer.js +24 -0
  56. package/dist/Table/VirtualizedTableContainer.js.map +1 -0
  57. package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
  58. package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
  59. package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
  60. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
  61. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
  62. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
  63. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
  64. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
  65. package/dist/Table/index.d.ts +4 -0
  66. package/dist/Table/index.d.ts.map +1 -0
  67. package/dist/Table/index.js +16 -0
  68. package/dist/Table/index.js.map +1 -0
  69. package/dist/Table/model/table-model.d.ts +83 -0
  70. package/dist/Table/model/table-model.d.ts.map +1 -0
  71. package/dist/Table/model/table-model.js +73 -0
  72. package/dist/Table/model/table-model.js.map +1 -0
  73. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
  74. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  75. package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
  76. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  77. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +2 -1
  78. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  79. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +60 -15
  80. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  81. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +5 -3
  82. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  83. package/dist/TimeSeriesTooltip/TooltipContent.js +79 -42
  84. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  85. package/dist/TimeSeriesTooltip/index.d.ts +1 -1
  86. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  87. package/dist/TimeSeriesTooltip/index.js +1 -1
  88. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  89. package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
  90. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
  91. package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
  92. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
  93. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +8 -4
  94. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  95. package/dist/TimeSeriesTooltip/tooltip-model.js +6 -2
  96. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  97. package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
  98. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  99. package/dist/TimeSeriesTooltip/utils.js +4 -3
  100. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  101. package/dist/cjs/Legend/CompactLegend.js +4 -1
  102. package/dist/cjs/Legend/Legend.js +45 -11
  103. package/dist/cjs/Legend/ListLegend.js +33 -98
  104. package/dist/cjs/Legend/ListLegendItem.js +8 -11
  105. package/dist/cjs/LineChart/LineChart.js +31 -22
  106. package/dist/cjs/Table/InnerTable.js +44 -0
  107. package/dist/cjs/Table/Table.js +102 -0
  108. package/dist/cjs/Table/TableBody.js +29 -0
  109. package/dist/cjs/Table/TableCell.js +97 -0
  110. package/dist/cjs/Table/TableCheckbox.js +55 -0
  111. package/dist/cjs/Table/TableHead.js +29 -0
  112. package/dist/cjs/Table/TableRow.js +35 -0
  113. package/dist/cjs/Table/VirtualizedTable.js +155 -0
  114. package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
  115. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
  116. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
  117. package/dist/cjs/Table/index.js +33 -0
  118. package/dist/cjs/Table/model/table-model.js +80 -0
  119. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
  120. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +57 -12
  121. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +83 -41
  122. package/dist/cjs/TimeSeriesTooltip/index.js +1 -1
  123. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
  124. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +11 -3
  125. package/dist/cjs/TimeSeriesTooltip/utils.js +3 -2
  126. package/dist/cjs/context/SnackbarProvider.js +66 -0
  127. package/dist/cjs/index.js +2 -0
  128. package/dist/cjs/model/legend.js +7 -1
  129. package/dist/cjs/theme/palette/grey.js +6 -2
  130. package/dist/context/SnackbarProvider.d.ts +23 -0
  131. package/dist/context/SnackbarProvider.d.ts.map +1 -0
  132. package/dist/context/SnackbarProvider.js +59 -0
  133. package/dist/context/SnackbarProvider.js.map +1 -0
  134. package/dist/index.d.ts +2 -0
  135. package/dist/index.d.ts.map +1 -1
  136. package/dist/index.js +2 -0
  137. package/dist/index.js.map +1 -1
  138. package/dist/model/legend.d.ts +10 -2
  139. package/dist/model/legend.d.ts.map +1 -1
  140. package/dist/model/legend.js +5 -0
  141. package/dist/model/legend.js.map +1 -1
  142. package/dist/theme/palette/grey.d.ts.map +1 -1
  143. package/dist/theme/palette/grey.js +6 -2
  144. package/dist/theme/palette/grey.js.map +1 -1
  145. package/package.json +6 -6
  146. package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
  147. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
  148. package/dist/TimeSeriesTooltip/focused-series.js +0 -110
  149. package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
  150. package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -116
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/Table/hooks/useTableKeyboardNav.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 { useCallback, useState } from 'react';\n\nexport interface UseTableKeyboardNavProps {\n maxRows: number;\n maxColumns: number;\n\n /**\n * Function used to modify the active table cell based on the keyboard event,\n * the current position, and the default recommended next position (this value\n * will be `undefined` in cases where there is no default handler like `PageUp`\n * and `PageDown`). This can be used to modify the next position that will be\n * used and/or to handle side effects related to the new position (e.g.\n * pagination, scrolling the active cell into view).\n */\n onActiveCellChange?: (\n e: React.KeyboardEvent<HTMLTableElement>,\n currentActiveCell: TableCellPosition,\n defaultNextActiveCell: TableCellPosition | undefined\n ) => TableCellPosition | undefined;\n}\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nconst DEFAULT_ACTIVE_CELL: TableCellPosition = {\n row: 0,\n column: 0,\n};\n\nconst ARROW_KEYS = ['ArrowRight', 'ArrowLeft', 'ArrowUp', 'ArrowDown'];\n\nfunction isArrowKey(key: string) {\n return ARROW_KEYS.includes(key);\n}\n\n/**\n * Hook for managing keyboard navigation for table components. It is intended\n * to be wrapped by implementation-specific tables to account for differences\n * like pagination, infinite scroll, and virtualization. See `useVirtualizedKeyboardNav`\n * for an example.\n */\nexport function useTableKeyboardNav({ maxRows, maxColumns, onActiveCellChange }: UseTableKeyboardNavProps) {\n const [activeCell, setActiveCell] = useState<TableCellPosition>(DEFAULT_ACTIVE_CELL);\n const [isActive, setIsActive] = useState(false);\n\n const handleCellFocus = (cellPosition: TableCellPosition) => {\n if (cellPosition.column === activeCell.column && cellPosition.row === activeCell.row && isActive) {\n return;\n }\n setIsActive(true);\n setActiveCell(cellPosition);\n };\n\n const handleKeyDown: React.KeyboardEventHandler<HTMLTableElement> = useCallback(\n (e) => {\n // Including some of the basic a11y keyboard interaction patterns from:\n // https://www.w3.org/WAI/ARIA/apg/patterns/grid/\n // TODO: add other keyboard combos.\n const key = e.key;\n\n if (isArrowKey(key) || key === 'Home' || key === 'End' || key === 'PageDown' || key === 'PageUp') {\n setActiveCell((curActiveCell) => {\n let nextRow: number = curActiveCell.row;\n let nextColumn: number = curActiveCell.column;\n\n if (key === 'ArrowRight' && nextColumn < maxColumns - 1) {\n e.preventDefault();\n nextColumn += 1;\n } else if (key === 'ArrowLeft' && nextColumn > 0) {\n e.preventDefault();\n nextColumn -= 1;\n } else if (key === 'ArrowDown' && nextRow < maxRows - 1) {\n e.preventDefault();\n nextRow += 1;\n } else if (key === 'ArrowUp' && nextRow > 0) {\n e.preventDefault();\n nextRow -= 1;\n } else if (key === 'Home') {\n e.preventDefault();\n nextRow = 0;\n nextColumn = 0;\n } else if (key === 'End') {\n e.preventDefault();\n nextRow = maxRows - 1;\n nextColumn = maxColumns - 1;\n }\n\n const defaultNewPosition = { column: nextColumn, row: nextRow };\n\n const newPosition = onActiveCellChange?.(e, curActiveCell, defaultNewPosition) || defaultNewPosition;\n\n if (newPosition.row === curActiveCell.row && newPosition.column === curActiveCell.column) {\n // Return original to avoid creating a new object if nothing\n // changed.\n return curActiveCell;\n }\n\n return newPosition;\n });\n }\n },\n [maxColumns, maxRows, onActiveCellChange]\n );\n\n return {\n activeCell,\n isActive,\n onTableKeyDown: handleKeyDown,\n onCellFocus: handleCellFocus,\n };\n}\n"],"names":["useCallback","useState","DEFAULT_ACTIVE_CELL","row","column","ARROW_KEYS","isArrowKey","key","includes","useTableKeyboardNav","maxRows","maxColumns","onActiveCellChange","activeCell","setActiveCell","isActive","setIsActive","handleCellFocus","cellPosition","handleKeyDown","e","curActiveCell","nextRow","nextColumn","preventDefault","defaultNewPosition","newPosition","onTableKeyDown","onCellFocus"],"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,SAASA,WAAW,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AA0B9C,MAAMC,mBAAmB,GAAsB;IAC7CC,GAAG,EAAE,CAAC;IACNC,MAAM,EAAE,CAAC;CACV,AAAC;AAEF,MAAMC,UAAU,GAAG;IAAC,YAAY;IAAE,WAAW;IAAE,SAAS;IAAE,WAAW;CAAC,AAAC;AAEvE,SAASC,UAAU,CAACC,GAAW,EAAE;IAC/B,OAAOF,UAAU,CAACG,QAAQ,CAACD,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;;;CAKC,GACD,OAAO,SAASE,mBAAmB,CAAC,EAAEC,OAAO,CAAA,EAAEC,U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kB;KAAC,CAC1C,AAAC;IAEF,OAAO;QACLC,UAAU;QACVE,QAAQ;QACRY,cAAc,EAAER,aAAa;QAC7BS,WAAW,EAAEX,eAAe;KAC7B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,29 @@
1
+ /// <reference types="react" />
2
+ import { TableVirtuosoHandle } from 'react-virtuoso';
3
+ import { UseTableKeyboardNavProps } from './useTableKeyboardNav';
4
+ interface UseVirtualizedTableKeyboardNavProps extends Omit<UseTableKeyboardNavProps, 'onActiveCellChange'> {
5
+ visibleRange: React.MutableRefObject<{
6
+ startIndex: number;
7
+ endIndex: number;
8
+ }>;
9
+ virtualTable: React.RefObject<TableVirtuosoHandle>;
10
+ maxRows: number;
11
+ maxColumns: number;
12
+ }
13
+ /**
14
+ * Hook for managing keyboard navigation when using a virtualized table.
15
+ */
16
+ export declare function useVirtualizedTableKeyboardNav({ visibleRange, virtualTable, maxRows, maxColumns, }: UseVirtualizedTableKeyboardNavProps): {
17
+ activeCell: {
18
+ row: number;
19
+ column: number;
20
+ };
21
+ isActive: boolean;
22
+ onTableKeyDown: import("react").KeyboardEventHandler<HTMLTableElement>;
23
+ onCellFocus: (cellPosition: {
24
+ row: number;
25
+ column: number;
26
+ }) => void;
27
+ };
28
+ export {};
29
+ //# sourceMappingURL=useVirtualizedTableKeyboardNav.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVirtualizedTableKeyboardNav.d.ts","sourceRoot":"","sources":["../../../src/Table/hooks/useVirtualizedTableKeyboardNav.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAuB,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtF,UAAU,mCAAoC,SAAQ,IAAI,CAAC,wBAAwB,EAAE,oBAAoB,CAAC;IACxG,YAAY,EAAE,KAAK,CAAC,gBAAgB,CAAC;QACnC,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC,CAAC;IACH,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IACnD,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,EAC7C,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,UAAU,GACX,EAAE,mCAAmC;;;;;;;;;;;EA4ErC"}
@@ -0,0 +1,89 @@
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 { useTableKeyboardNav } from './useTableKeyboardNav';
14
+ /**
15
+ * Hook for managing keyboard navigation when using a virtualized table.
16
+ */ export function useVirtualizedTableKeyboardNav({ visibleRange , virtualTable , maxRows , maxColumns }) {
17
+ const baseKeyboard = useTableKeyboardNav({
18
+ maxRows,
19
+ maxColumns,
20
+ onActiveCellChange: (e, currentPosition, defaultNewPosition)=>{
21
+ const key = e.key;
22
+ const defaultValueChanged = defaultNewPosition && (currentPosition.column !== defaultNewPosition.column || currentPosition.row !== defaultNewPosition.row);
23
+ var ref;
24
+ const nextRow = (ref = defaultNewPosition === null || defaultNewPosition === void 0 ? void 0 : defaultNewPosition.row) !== null && ref !== void 0 ? ref : currentPosition.row;
25
+ if (key === 'ArrowDown' && defaultValueChanged) {
26
+ // Use default cell position. Shift the virtual table scroll position
27
+ // when needed to make the active cell visible.
28
+ if (nextRow - 1 < visibleRange.current.startIndex || nextRow - 1 > visibleRange.current.endIndex) {
29
+ var ref1;
30
+ (ref1 = virtualTable.current) === null || ref1 === void 0 ? void 0 : ref1.scrollToIndex({
31
+ index: nextRow - 1,
32
+ align: 'end'
33
+ });
34
+ }
35
+ } else if (key === 'ArrowUp' && defaultValueChanged) {
36
+ // Use default cell position. Shift the virtual table scroll position
37
+ // when needed to make the active cell visible.
38
+ if (nextRow - 1 < visibleRange.current.startIndex || nextRow - 1 > visibleRange.current.endIndex) {
39
+ var ref2;
40
+ (ref2 = virtualTable.current) === null || ref2 === void 0 ? void 0 : ref2.scrollToIndex({
41
+ index: nextRow - 1,
42
+ align: 'start'
43
+ });
44
+ }
45
+ } else if (defaultValueChanged && (key === 'Home' || key === 'End')) {
46
+ var // Use default cell position. Shift the virtual table scroll position
47
+ // when needed to make the active cell visible.
48
+ ref3;
49
+ (ref3 = virtualTable.current) === null || ref3 === void 0 ? void 0 : ref3.scrollToIndex({
50
+ index: Math.max(nextRow - 1, 0),
51
+ align: 'start'
52
+ });
53
+ } else if (key === 'PageDown') {
54
+ var ref4;
55
+ // Full handling of logic for `PageDown` because there is no default.
56
+ e.preventDefault();
57
+ let nextRow1 = currentPosition.row;
58
+ // Add 1 to account for header
59
+ nextRow1 = Math.min(maxRows - 1, visibleRange.current.endIndex + 1);
60
+ (ref4 = virtualTable.current) === null || ref4 === void 0 ? void 0 : ref4.scrollToIndex({
61
+ index: nextRow1 - 1,
62
+ align: 'start'
63
+ });
64
+ return {
65
+ row: nextRow1,
66
+ column: currentPosition.column
67
+ };
68
+ } else if (key === 'PageUp') {
69
+ var ref5;
70
+ // Full handling of logic for `PageUp` because there is no default.
71
+ let nextRow2 = currentPosition.row;
72
+ // Minus 1 to account for header
73
+ nextRow2 = Math.max(0, visibleRange.current.startIndex - 1);
74
+ (ref5 = virtualTable.current) === null || ref5 === void 0 ? void 0 : ref5.scrollToIndex({
75
+ index: nextRow2 - 1,
76
+ align: 'end'
77
+ });
78
+ return {
79
+ row: nextRow2,
80
+ column: currentPosition.column
81
+ };
82
+ }
83
+ return defaultNewPosition;
84
+ }
85
+ });
86
+ return baseKeyboard;
87
+ }
88
+
89
+ //# sourceMappingURL=useVirtualizedTableKeyboardNav.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/Table/hooks/useVirtualizedTableKeyboardNav.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 { TableVirtuosoHandle } from 'react-virtuoso';\nimport { useTableKeyboardNav, UseTableKeyboardNavProps } from './useTableKeyboardNav';\n\ninterface UseVirtualizedTableKeyboardNavProps extends Omit<UseTableKeyboardNavProps, 'onActiveCellChange'> {\n visibleRange: React.MutableRefObject<{\n startIndex: number;\n endIndex: number;\n }>;\n virtualTable: React.RefObject<TableVirtuosoHandle>;\n maxRows: number;\n maxColumns: number;\n}\n\n/**\n * Hook for managing keyboard navigation when using a virtualized table.\n */\nexport function useVirtualizedTableKeyboardNav({\n visibleRange,\n virtualTable,\n maxRows,\n maxColumns,\n}: UseVirtualizedTableKeyboardNavProps) {\n const baseKeyboard = useTableKeyboardNav({\n maxRows,\n maxColumns,\n onActiveCellChange: (e, currentPosition, defaultNewPosition) => {\n const key = e.key;\n\n const defaultValueChanged =\n defaultNewPosition &&\n (currentPosition.column !== defaultNewPosition.column || currentPosition.row !== defaultNewPosition.row);\n const nextRow = defaultNewPosition?.row ?? currentPosition.row;\n\n if (key === 'ArrowDown' && defaultValueChanged) {\n // Use default cell position. Shift the virtual table scroll position\n // when needed to make the active cell visible.\n if (nextRow - 1 < visibleRange.current.startIndex || nextRow - 1 > visibleRange.current.endIndex) {\n virtualTable.current?.scrollToIndex({\n index: nextRow - 1,\n align: 'end',\n });\n }\n } else if (key === 'ArrowUp' && defaultValueChanged) {\n // Use default cell position. Shift the virtual table scroll position\n // when needed to make the active cell visible.\n if (nextRow - 1 < visibleRange.current.startIndex || nextRow - 1 > visibleRange.current.endIndex) {\n virtualTable.current?.scrollToIndex({\n index: nextRow - 1,\n align: 'start',\n });\n }\n } else if (defaultValueChanged && (key === 'Home' || key === 'End')) {\n // Use default cell position. Shift the virtual table scroll position\n // when needed to make the active cell visible.\n virtualTable.current?.scrollToIndex({\n index: Math.max(nextRow - 1, 0),\n align: 'start',\n });\n } else if (key === 'PageDown') {\n // Full handling of logic for `PageDown` because there is no default.\n e.preventDefault();\n\n let nextRow = currentPosition.row;\n // Add 1 to account for header\n\n nextRow = Math.min(maxRows - 1, visibleRange.current.endIndex + 1);\n\n virtualTable.current?.scrollToIndex({\n index: nextRow - 1,\n align: 'start',\n });\n\n return {\n row: nextRow,\n column: currentPosition.column,\n };\n } else if (key === 'PageUp') {\n // Full handling of logic for `PageUp` because there is no default.\n let nextRow = currentPosition.row;\n // Minus 1 to account for header\n nextRow = Math.max(0, visibleRange.current.startIndex - 1);\n virtualTable.current?.scrollToIndex({\n index: nextRow - 1,\n align: 'end',\n });\n\n return {\n row: nextRow,\n column: currentPosition.column,\n };\n }\n\n return defaultNewPosition;\n },\n });\n\n return baseKeyboard;\n}\n"],"names":["useTableKeyboardNav","useVirtualizedTableKeyboardNav","visibleRange","virtualTable","maxRows","maxColumns","baseKeyboard","onActiveCellChange","e","currentPosition","defaultNewPosition","key","defaultValueChanged","column","row","nextRow","current","startIndex","endIndex","scrollToIndex","index","align","Math","max","preventDefault","min"],"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;AAGjC,SAASA,mBAAmB,QAAkC,uBAAuB,CAAC;A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,CAAEgB,aAAa,CAAC;oBAClCC,KAAK,EAAEL,QAAO,GAAG,CAAC;oBAClBM,KAAK,EAAE,OAAO;iBACf,CAAC,CAAC;gBAEH,OAAO;oBACLP,GAAG,EAAEC,QAAO;oBACZF,MAAM,EAAEJ,eAAe,CAACI,MAAM;iBAC/B,CAAC;YACJ,OAAO,IAAIF,GAAG,KAAK,QAAQ,EAAE;oBAK3BR,IAAoB;gBAJpB,mEAAmE;gBACnE,IAAIY,QAAO,GAAGN,eAAe,CAACK,GAAG,AAAC;gBAClC,gCAAgC;gBAChCC,QAAO,GAAGO,IAAI,CAACC,GAAG,CAAC,CAAC,EAAErB,YAAY,CAACc,OAAO,CAACC,UAAU,GAAG,CAAC,CAAC,CAAC;gBAC3Dd,CAAAA,IAAoB,GAApBA,YAAY,CAACa,OAAO,cAApBb,IAAoB,WAAe,GAAnCA,KAAAA,CAAmC,GAAnCA,IAAoB,CAAEgB,aAAa,CAAC;oBAClCC,KAAK,EAAEL,QAAO,GAAG,CAAC;oBAClBM,KAAK,EAAE,KAAK;iBACb,CAAC,CAAC;gBAEH,OAAO;oBACLP,GAAG,EAAEC,QAAO;oBACZF,MAAM,EAAEJ,eAAe,CAACI,MAAM;iBAC/B,CAAC;YACJ,CAAC;YAED,OAAOH,kBAAkB,CAAC;QAC5B,CAAC;KACF,CAAC,AAAC;IAEH,OAAOJ,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './Table';
2
+ export { getTableCellLayout } from './model/table-model';
3
+ export type { TableColumnConfig, TableProps, TableDensity } from './model/table-model';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Table/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,16 @@
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
+ export * from './Table';
14
+ export { getTableCellLayout } from './model/table-model';
15
+
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Table/index.ts"],"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\nexport * from './Table';\nexport { getTableCellLayout } from './model/table-model';\nexport type { TableColumnConfig, TableProps, TableDensity } from './model/table-model';\n"],"names":["getTableCellLayout"],"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,cAAc,SAAS,CAAC;AACxB,SAASA,kBAAkB,QAAQ,qBAAqB,CAAC"}
@@ -0,0 +1,83 @@
1
+ /// <reference types="react" />
2
+ import { Theme } from '@mui/material';
3
+ import { AccessorKeyColumnDef, ColumnDef, CoreOptions, RowSelectionState } from '@tanstack/react-table';
4
+ export declare type TableDensity = 'compact' | 'standard';
5
+ export interface TableProps<TableData> {
6
+ /**
7
+ * Height of the table.
8
+ */
9
+ height: number;
10
+ /**
11
+ * Width of the table.
12
+ */
13
+ width: number;
14
+ /**
15
+ * Array of data to render in the table. Each entry in the array will be
16
+ * rendered as a row in the table.
17
+ */
18
+ data: TableData[];
19
+ /**
20
+ * Array of column configuration for the table. Each entry in the array will
21
+ * be rendered as a column header and impact the rendering of cells within
22
+ * table rows.
23
+ */
24
+ columns: Array<TableColumnConfig<TableData>>;
25
+ /**
26
+ * The density of the table layout. This impacts the size and space taken up
27
+ * by content in the table (e.g. font size, padding).
28
+ */
29
+ density?: TableDensity;
30
+ /**
31
+ * When `true`, the first column of the table will include checkboxes.
32
+ */
33
+ checkboxSelection?: boolean;
34
+ /**
35
+ * State of selected rows in the table when `checkboxSelection` is enabled.
36
+ *
37
+ * Selected row state is a controlled value that should be managed using a
38
+ * combination of this prop and `onRowSelectionChange`.
39
+ */
40
+ rowSelection?: RowSelectionState;
41
+ /**
42
+ * Callback fired when the selected rows in the table changes.
43
+ */
44
+ onRowSelectionChange?: (rowSelection: RowSelectionState) => void;
45
+ /**
46
+ * Function used to determine the unique identifier used for each row. This
47
+ * value is used to key `rowSelection`. If this value is not set, the index
48
+ * is used as the unique identifier.
49
+ */
50
+ getRowId?: CoreOptions<TableData>['getRowId'];
51
+ /**
52
+ * Function used to determine the color of the checkbox when `checkboxSelection`
53
+ * is enabled. If not set, a default color is used.
54
+ */
55
+ getCheckboxColor?: (rowData: TableData) => string;
56
+ }
57
+ declare type TableCellLayout = NonNullable<Pick<React.CSSProperties, 'padding' | 'fontSize' | 'lineHeight'>> & {
58
+ height: number;
59
+ };
60
+ /**
61
+ * Returns the properties to lay out the content of table cells based on the
62
+ * theme and density.
63
+ */
64
+ export declare function getTableCellLayout(theme: Theme, density: TableDensity): TableCellLayout;
65
+ export interface TableColumnConfig<TableData> extends Pick<AccessorKeyColumnDef<TableData, any>, 'accessorKey' | 'cell'> {
66
+ /**
67
+ * Text to display in the header for the column.
68
+ */
69
+ header: string;
70
+ /**
71
+ * Width of the column when rendered in a table. It should be a number in pixels
72
+ * or "auto" to allow the table to automatically adjust the width to fill
73
+ * space.
74
+ * @default 'auto'
75
+ */
76
+ width?: number | 'auto';
77
+ }
78
+ /**
79
+ * Takes in a perses table column and transforms it into a tanstack column.
80
+ */
81
+ export declare function persesColumnsToTanstackColumns<TableData>(columns: Array<TableColumnConfig<TableData>>): ColumnDef<TableData, unknown>[];
82
+ export {};
83
+ //# sourceMappingURL=table-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table-model.d.ts","sourceRoot":"","sources":["../../../src/Table/model/table-model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAGxG,oBAAY,YAAY,GAAG,SAAS,GAAG,UAAU,CAAC;AAElD,MAAM,WAAW,UAAU,CAAC,SAAS;IACnC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;OAGG;IACH,IAAI,EAAE,SAAS,EAAE,CAAC;IAElB;;;;OAIG;IACH,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC;IAE7C;;;OAGG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IAEvB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,oBAAoB,CAAC,EAAE,CAAC,YAAY,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEjE;;;;OAIG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,CAAC;IAE9C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,MAAM,CAAC;CACnD;AAWD,aAAK,eAAe,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,SAAS,GAAG,UAAU,GAAG,YAAY,CAAC,CAAC,GAAG;IACrG,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,GAAG,eAAe,CAyBvF;AAKD,MAAM,WAAW,iBAAiB,CAAC,SAAS,CAI1C,SAAQ,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,GAAG,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC;IAC1E;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAIf;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,mCA6BrG"}
@@ -0,0 +1,73 @@
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
+ function calculateTableCellHeight(lineHeight, paddingY) {
14
+ // Doing a bunch of math to enforce height to avoid weirdness with mismatched
15
+ // heights based on customization of cell contents.
16
+ const lineHeightNum = typeof lineHeight === 'string' ? parseInt(lineHeight, 10) : lineHeight !== null && lineHeight !== void 0 ? lineHeight : 0;
17
+ const verticalPaddingNum = typeof paddingY === 'string' ? parseInt(paddingY, 10) : paddingY;
18
+ return lineHeightNum + verticalPaddingNum * 2;
19
+ }
20
+ /**
21
+ * Returns the properties to lay out the content of table cells based on the
22
+ * theme and density.
23
+ */ export function getTableCellLayout(theme, density) {
24
+ if (density === 'compact') {
25
+ const paddingY = theme.spacing(0.5);
26
+ const paddingX = theme.spacing(0.25);
27
+ const lineHeight = theme.typography.body2.lineHeight;
28
+ return {
29
+ padding: `${paddingY} ${paddingX}`,
30
+ height: calculateTableCellHeight(lineHeight, paddingY),
31
+ fontSize: theme.typography.body2.fontSize,
32
+ lineHeight: lineHeight
33
+ };
34
+ }
35
+ // standard density
36
+ const paddingY1 = theme.spacing(1);
37
+ const paddingX1 = theme.spacing(1.25);
38
+ const lineHeight1 = theme.typography.body1.lineHeight;
39
+ return {
40
+ padding: `${paddingY1} ${paddingX1}`,
41
+ height: calculateTableCellHeight(lineHeight1, paddingY1),
42
+ fontSize: theme.typography.body1.fontSize,
43
+ lineHeight: lineHeight1
44
+ };
45
+ }
46
+ /**
47
+ * Takes in a perses table column and transforms it into a tanstack column.
48
+ */ export function persesColumnsToTanstackColumns(columns) {
49
+ const tableCols = columns.map(({ width , ...otherProps })=>{
50
+ // Tanstack Table does not support an "auto" value to naturally size to fit
51
+ // the space in a table. We translate our custom "auto" setting to 0 size
52
+ // for these columns, so it is easy to fall back to auto when rendering.
53
+ // Taking from a recommendation in this github discussion:
54
+ // https://github.com/TanStack/table/discussions/4179#discussioncomment-3631326
55
+ const sizeProps = width === 'auto' || width === undefined ? {
56
+ // All zero values are used as shorthand for "auto" when rendering
57
+ // because it makes it easy to fall back. (e.g. `row.size || "auto"`)
58
+ size: 0,
59
+ minSize: 0,
60
+ maxSize: 0
61
+ } : {
62
+ size: width
63
+ };
64
+ const result = {
65
+ ...otherProps,
66
+ ...sizeProps
67
+ };
68
+ return result;
69
+ });
70
+ return tableCols;
71
+ }
72
+
73
+ //# sourceMappingURL=table-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/Table/model/table-model.ts"],"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 { Theme } from '@mui/material';\nimport { AccessorKeyColumnDef, ColumnDef, CoreOptions, RowSelectionState } from '@tanstack/react-table';\nimport { CSSProperties } from 'react';\n\nexport type TableDensity = 'compact' | 'standard';\n\nexport interface TableProps<TableData> {\n /**\n * Height of the table.\n */\n height: number;\n\n /**\n * Width of the table.\n */\n width: number;\n\n /**\n * Array of data to render in the table. Each entry in the array will be\n * rendered as a row in the table.\n */\n data: TableData[];\n\n /**\n * Array of column configuration for the table. Each entry in the array will\n * be rendered as a column header and impact the rendering of cells within\n * table rows.\n */\n columns: Array<TableColumnConfig<TableData>>;\n\n /**\n * The density of the table layout. This impacts the size and space taken up\n * by content in the table (e.g. font size, padding).\n */\n density?: TableDensity;\n\n /**\n * When `true`, the first column of the table will include checkboxes.\n */\n checkboxSelection?: boolean;\n\n /**\n * State of selected rows in the table when `checkboxSelection` is enabled.\n *\n * Selected row state is a controlled value that should be managed using a\n * combination of this prop and `onRowSelectionChange`.\n */\n rowSelection?: RowSelectionState;\n\n /**\n * Callback fired when the selected rows in the table changes.\n */\n onRowSelectionChange?: (rowSelection: RowSelectionState) => void;\n\n /**\n * Function used to determine the unique identifier used for each row. This\n * value is used to key `rowSelection`. If this value is not set, the index\n * is used as the unique identifier.\n */\n getRowId?: CoreOptions<TableData>['getRowId'];\n\n /**\n * Function used to determine the color of the checkbox when `checkboxSelection`\n * is enabled. If not set, a default color is used.\n */\n getCheckboxColor?: (rowData: TableData) => string;\n}\n\nfunction calculateTableCellHeight(lineHeight: CSSProperties['lineHeight'], paddingY: string): number {\n // Doing a bunch of math to enforce height to avoid weirdness with mismatched\n // heights based on customization of cell contents.\n const lineHeightNum = typeof lineHeight === 'string' ? parseInt(lineHeight, 10) : lineHeight ?? 0;\n const verticalPaddingNum = typeof paddingY === 'string' ? parseInt(paddingY, 10) : paddingY;\n\n return lineHeightNum + verticalPaddingNum * 2;\n}\n\ntype TableCellLayout = NonNullable<Pick<React.CSSProperties, 'padding' | 'fontSize' | 'lineHeight'>> & {\n height: number;\n};\n\n/**\n * Returns the properties to lay out the content of table cells based on the\n * theme and density.\n */\nexport function getTableCellLayout(theme: Theme, density: TableDensity): TableCellLayout {\n if (density === 'compact') {\n const paddingY = theme.spacing(0.5);\n const paddingX = theme.spacing(0.25);\n const lineHeight = theme.typography.body2.lineHeight;\n\n return {\n padding: `${paddingY} ${paddingX}`,\n height: calculateTableCellHeight(lineHeight, paddingY),\n fontSize: theme.typography.body2.fontSize,\n lineHeight: lineHeight,\n };\n }\n\n // standard density\n const paddingY = theme.spacing(1);\n const paddingX = theme.spacing(1.25);\n const lineHeight = theme.typography.body1.lineHeight;\n\n return {\n padding: `${paddingY} ${paddingX}`,\n height: calculateTableCellHeight(lineHeight, paddingY),\n fontSize: theme.typography.body1.fontSize,\n lineHeight: lineHeight,\n };\n}\n\n// Only exposing a very simplified version of the very extensive column definitions\n// possible with tanstack table to make it easier for us to control rendering\n// and functionality.\nexport interface TableColumnConfig<TableData>\n // Any needed to work around some typing issues with tanstack query.\n // https://github.com/TanStack/table/issues/4241\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n extends Pick<AccessorKeyColumnDef<TableData, any>, 'accessorKey' | 'cell'> {\n /**\n * Text to display in the header for the column.\n */\n header: string;\n\n // Tanstack Table does not support an \"auto\" value to naturally size to fit\n // the space in a table. Adding a custom setting to manage this ourselves.\n /**\n * Width of the column when rendered in a table. It should be a number in pixels\n * or \"auto\" to allow the table to automatically adjust the width to fill\n * space.\n * @default 'auto'\n */\n width?: number | 'auto';\n}\n\n/**\n * Takes in a perses table column and transforms it into a tanstack column.\n */\nexport function persesColumnsToTanstackColumns<TableData>(columns: Array<TableColumnConfig<TableData>>) {\n const tableCols: Array<ColumnDef<TableData>> = columns.map(({ width, ...otherProps }) => {\n // Tanstack Table does not support an \"auto\" value to naturally size to fit\n // the space in a table. We translate our custom \"auto\" setting to 0 size\n // for these columns, so it is easy to fall back to auto when rendering.\n // Taking from a recommendation in this github discussion:\n // https://github.com/TanStack/table/discussions/4179#discussioncomment-3631326\n const sizeProps =\n width === 'auto' || width === undefined\n ? {\n // All zero values are used as shorthand for \"auto\" when rendering\n // because it makes it easy to fall back. (e.g. `row.size || \"auto\"`)\n size: 0,\n minSize: 0,\n maxSize: 0,\n }\n : {\n size: width,\n };\n\n const result = {\n ...otherProps,\n ...sizeProps,\n };\n\n return result;\n });\n\n return tableCols;\n}\n"],"names":["calculateTableCellHeight","lineHeight","paddingY","lineHeightNum","parseInt","verticalPaddingNum","getTableCellLayout","theme","density","spacing","paddingX","typography","body2","padding","height","fontSize","body1","persesColumnsToTanstackColumns","columns","tableCols","map","width","otherProps","sizeProps","undefined","size","minSize","maxSize","result"],"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;AAsEjC,SAASA,wBAAwB,CAACC,UAAuC,EAAEC,QAAgB,EAAU;IACnG,6EAA6E;IAC7E,mDAAmD;IACnD,MAAMC,aAAa,GAAG,OAAOF,UAAU,KAAK,QAAQ,GAAGG,QAAQ,CAACH,UAAU,EAAE,EAAE,CAAC,GAAGA,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAI,CAAC,AAAC;IAClG,MAAMI,kBAAkB,GAAG,OAAOH,QAAQ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A0BD;;CAEC,GACD,OAAO,SAASgB,8BAA8B,CAAYC,OAA4C,EAAE;IACtG,MAAMC,SAAS,GAAgCD,OAAO,CAACE,GAAG,CAAC,CAAC,EAAEC,KAAK,CAAA,EAAE,GAAGC,UAAU,EAAE,GAAK;QACvF,2EAA2E;QAC3E,yEAAyE;QACzE,wEAAwE;QACxE,0DAA0D;QAC1D,+EAA+E;QAC/E,MAAMC,SAAS,GACbF,KAAK,KAAK,MAAM,IAAIA,KAAK,KAAKG,SAAS,GACnC;YACE,kEAAkE;YAClE,qEAAqE;YACrEC,IAAI,EAAE,CAAC;YACPC,OAAO,EAAE,CAAC;YACVC,OAAO,EAAE,CAAC;SACX,GACD;YACEF,IAAI,EAAEJ,KAAK;SACZ,AAAC;QAER,MAAMO,MAAM,GAAG;YACb,GAAGN,UAAU;YACb,GAAGC,SAAS;SACb,AAAC;QAEF,OAAOK,MAAM,CAAC;IAChB,CAAC,CAAC,AAAC;IAEH,OAAOT,SAAS,CAAC;AACnB,CAAC"}
@@ -5,6 +5,7 @@ export interface SeriesInfoProps {
5
5
  formattedY: string;
6
6
  markerColor: string;
7
7
  totalSeries: number;
8
+ emphasizeText?: boolean;
8
9
  wrapLabels?: boolean;
9
10
  }
10
11
  export declare function SeriesInfo(props: SeriesInfoProps): JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"SeriesInfo.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/SeriesInfo.tsx"],"names":[],"mappings":";AAkBA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAwEhD"}
1
+ {"version":3,"file":"SeriesInfo.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/SeriesInfo.tsx"],"names":[],"mappings":";AAkBA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eA0EhD"}
@@ -14,9 +14,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { Box } from '@mui/material';
15
15
  import { SeriesMarker } from './SeriesMarker';
16
16
  import { SeriesLabelsStack } from './SeriesLabelsStack';
17
- import { TOOLTIP_LABELS_MAX_WIDTH } from './tooltip-model';
17
+ import { TOOLTIP_LABELS_MAX_WIDTH, EMPHASIZED_SERIES_DESCRIPTION, NEARBY_SERIES_DESCRIPTION } from './tooltip-model';
18
18
  export function SeriesInfo(props) {
19
- const { seriesName , formattedY , markerColor , totalSeries , wrapLabels =true } = props;
19
+ const { seriesName , formattedY , markerColor , totalSeries , emphasizeText =false , wrapLabels =true } = props;
20
20
  // metric __name__ comes before opening curly brace, ignore if not populated
21
21
  // ex with metric name: node_load15{env="demo",job="node"}
22
22
  // ex without metric name: {env="demo",job="node"}
@@ -65,21 +65,23 @@ export function SeriesInfo(props) {
65
65
  maxWidth: TOOLTIP_LABELS_MAX_WIDTH,
66
66
  overflow: 'hidden',
67
67
  color: theme.palette.common.white,
68
+ fontWeight: emphasizeText ? theme.typography.fontWeightBold : theme.typography.fontWeightRegular,
68
69
  textOverflow: 'ellipsis',
69
70
  whiteSpace: wrapLabels ? 'normal' : 'nowrap'
70
71
  }),
72
+ "aria-label": emphasizeText ? EMPHASIZED_SERIES_DESCRIPTION : NEARBY_SERIES_DESCRIPTION,
71
73
  children: formattedSeriesInfo
72
74
  })
73
75
  ]
74
76
  }),
75
77
  /*#__PURE__*/ _jsx(Box, {
76
- sx: {
77
- display: 'table-cell',
78
- paddingLeft: 1.5,
79
- textAlign: 'right',
80
- verticalAlign: 'top',
81
- fontWeight: '700'
82
- },
78
+ sx: (theme)=>({
79
+ display: 'table-cell',
80
+ paddingLeft: 1.5,
81
+ textAlign: 'right',
82
+ verticalAlign: 'top',
83
+ fontWeight: emphasizeText ? theme.typography.fontWeightBold : theme.typography.fontWeightRegular
84
+ }),
83
85
  children: formattedY
84
86
  })
85
87
  ]
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/TimeSeriesTooltip/SeriesInfo.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 { SeriesMarker } from './SeriesMarker';\nimport { SeriesLabelsStack } from './SeriesLabelsStack';\nimport { TOOLTIP_LABELS_MAX_WIDTH } from './tooltip-model';\n\nexport interface SeriesInfoProps {\n seriesName: string;\n y: number;\n formattedY: string;\n markerColor: string;\n totalSeries: number;\n wrapLabels?: boolean;\n}\n\nexport function SeriesInfo(props: SeriesInfoProps) {\n const { seriesName, formattedY, markerColor, totalSeries, wrapLabels = true } = props;\n\n // metric __name__ comes before opening curly brace, ignore if not populated\n // ex with metric name: node_load15{env=\"demo\",job=\"node\"}\n // ex without metric name: {env=\"demo\",job=\"node\"}\n const splitName = seriesName.split('{');\n const seriesLabels = splitName[1] ?? seriesName;\n\n // remove curly braces that wrap labels\n const formattedSeriesLabels = seriesLabels.replace(/[{}]/g, '');\n\n // determine whether to show labels on separate lines\n const splitLabels = formattedSeriesLabels.split(',');\n if (totalSeries === 1 && splitLabels.length > 1) {\n const metricName = splitName[0] ? `${splitName[0]}:` : 'value:';\n return (\n <SeriesLabelsStack\n formattedY={formattedY}\n metricName={metricName}\n metricLabels={splitLabels}\n markerColor={markerColor}\n />\n );\n }\n\n // add space after commas so wrapLabels works\n const formattedSeriesInfo = seriesName.replace(/[,]/g, ', ');\n\n return (\n <Box\n sx={{\n display: 'table-row',\n paddingTop: 0.5,\n }}\n >\n <Box\n sx={{\n display: 'table-cell',\n maxWidth: '520px',\n }}\n >\n <SeriesMarker markerColor={markerColor} sx={{ marginTop: 0.5 }} />\n <Box\n component=\"span\"\n sx={(theme) => ({\n display: 'inline-block',\n width: 'calc(100% - 20px)',\n minWidth: 150,\n maxWidth: TOOLTIP_LABELS_MAX_WIDTH,\n overflow: 'hidden',\n color: theme.palette.common.white,\n textOverflow: 'ellipsis',\n whiteSpace: wrapLabels ? 'normal' : 'nowrap',\n })}\n >\n {formattedSeriesInfo}\n </Box>\n </Box>\n <Box\n sx={{\n display: 'table-cell',\n paddingLeft: 1.5,\n textAlign: 'right',\n verticalAlign: 'top',\n fontWeight: '700',\n }}\n >\n {formattedY}\n </Box>\n </Box>\n );\n}\n"],"names":["Box","SeriesMarker","SeriesLabelsStack","TOOLTIP_LABELS_MAX_WIDTH","SeriesInfo","props","seriesName","formattedY","markerColor","totalSeries","wrapLabels","splitName","split","seriesLabels","formattedSeriesLabels","replace","splitLabels","length","metricName","metricLabels","formattedSeriesInfo","sx","display","paddingTop","maxWidth","marginTop","component","theme","width","minWidth","overflow","color","palette","common","white","textOverflow","whiteSpace","paddingLeft","textAlign","verticalAlign","fontWeight"],"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;AAE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BACE,MAACf,GAAG;QACFqB,EAAE,EAAE;YACFC,OAAO,EAAE,WAAW;YACpBC,UAAU,EAAE,GAAG;SAChB;;0BAED,MAACvB,GAAG;gBACFqB,EAAE,EAAE;oBACFC,OAAO,EAAE,YAAY;oBACrBE,QAAQ,EAAE,OAAO;iBAClB;;kCAED,KAACvB,YAAY;wBAACO,WAAW,EAAEA,WAAW;wBAAEa,EAAE,EAAE;4BAAEI,SAAS,EAAE,GAAG;yBAAE;sBAAI;kCAClE,KAACzB,GAAG;wBACF0B,SAAS,EAAC,MAAM;wBAChBL,EAAE,EAAE,CAACM,KAAK,GAAM,CAAA;gCACdL,OAAO,EAAE,cAAc;gCACvBM,KAAK,EAAE,mBAAmB;gCAC1BC,QAAQ,EAAE,GAAG;gCACbL,QAAQ,EAAErB,wBAAwB;gCAClC2B,QAAQ,EAAE,QAAQ;gCAClBC,KAAK,EAAEJ,KAAK,CAACK,OAAO,CAACC,MAAM,CAACC,KAAK;gCACjCC,YAAY,EAAE,UAAU;gCACxBC,UAAU,EAAE1B,UAAU,GAAG,QAAQ,GAAG,QAAQ;6BAC7C,CAAA,AAAC;kCAEDU,mBAAmB;sBAChB;;cACF;0BACN,KAACpB,GAAG;gBACFqB,EAAE,EAAE;oBACFC,OAAO,EAAE,YAAY;oBACrBe,WAAW,EAAE,GAAG;oBAChBC,SAAS,EAAE,OAAO;oBAClBC,aAAa,EAAE,KAAK;oBACpBC,UAAU,EAAE,KAAK;iBAClB;0BAEAjC,UAAU;cACP;;MACF,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/TimeSeriesTooltip/SeriesInfo.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 { SeriesMarker } from './SeriesMarker';\nimport { SeriesLabelsStack } from './SeriesLabelsStack';\nimport { TOOLTIP_LABELS_MAX_WIDTH, EMPHASIZED_SERIES_DESCRIPTION, NEARBY_SERIES_DESCRIPTION } from './tooltip-model';\n\nexport interface SeriesInfoProps {\n seriesName: string;\n y: number;\n formattedY: string;\n markerColor: string;\n totalSeries: number;\n emphasizeText?: boolean;\n wrapLabels?: boolean;\n}\n\nexport function SeriesInfo(props: SeriesInfoProps) {\n const { seriesName, formattedY, markerColor, totalSeries, emphasizeText = false, wrapLabels = true } = props;\n\n // metric __name__ comes before opening curly brace, ignore if not populated\n // ex with metric name: node_load15{env=\"demo\",job=\"node\"}\n // ex without metric name: {env=\"demo\",job=\"node\"}\n const splitName = seriesName.split('{');\n const seriesLabels = splitName[1] ?? seriesName;\n\n // remove curly braces that wrap labels\n const formattedSeriesLabels = seriesLabels.replace(/[{}]/g, '');\n\n // determine whether to show labels on separate lines\n const splitLabels = formattedSeriesLabels.split(',');\n if (totalSeries === 1 && splitLabels.length > 1) {\n const metricName = splitName[0] ? `${splitName[0]}:` : 'value:';\n return (\n <SeriesLabelsStack\n formattedY={formattedY}\n metricName={metricName}\n metricLabels={splitLabels}\n markerColor={markerColor}\n />\n );\n }\n\n // add space after commas so wrapLabels works\n const formattedSeriesInfo = seriesName.replace(/[,]/g, ', ');\n\n return (\n <Box\n sx={{\n display: 'table-row',\n paddingTop: 0.5,\n }}\n >\n <Box\n sx={{\n display: 'table-cell',\n maxWidth: '520px',\n }}\n >\n <SeriesMarker markerColor={markerColor} sx={{ marginTop: 0.5 }} />\n <Box\n component=\"span\"\n sx={(theme) => ({\n display: 'inline-block',\n width: 'calc(100% - 20px)',\n minWidth: 150,\n maxWidth: TOOLTIP_LABELS_MAX_WIDTH,\n overflow: 'hidden',\n color: theme.palette.common.white,\n fontWeight: emphasizeText ? theme.typography.fontWeightBold : theme.typography.fontWeightRegular,\n textOverflow: 'ellipsis',\n whiteSpace: wrapLabels ? 'normal' : 'nowrap',\n })}\n aria-label={emphasizeText ? EMPHASIZED_SERIES_DESCRIPTION : NEARBY_SERIES_DESCRIPTION}\n >\n {formattedSeriesInfo}\n </Box>\n </Box>\n <Box\n sx={(theme) => ({\n display: 'table-cell',\n paddingLeft: 1.5,\n textAlign: 'right',\n verticalAlign: 'top',\n fontWeight: emphasizeText ? theme.typography.fontWeightBold : theme.typography.fontWeightRegular,\n })}\n >\n {formattedY}\n </Box>\n </Box>\n );\n}\n"],"names":["Box","SeriesMarker","SeriesLabelsStack","TOOLTIP_LABELS_MAX_WIDTH","EMPHASIZED_SERIES_DESCRIPTION","NEARBY_SERIES_DESCRIPTION","SeriesInfo","props","seriesName","formattedY","markerColor","totalSeries","emphasizeText","wrapLabels","splitName","split","seriesLabels","formattedSeriesLabels","replace","splitLabels","length","metricName","metricLabels","formattedSeriesInfo","sx","display","paddingTop","maxWidth","marginTop","component","theme","width","minWidth","overflow","color","palette","common","white","fontWeight","typography","fontWeightBold","fontWeightRegular","textOverflow","whiteSpace","aria-label","paddingLeft","textAlign","verticalAlign"],"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;AACpC,SAASC,YAAY,QAAQ,gBAAgB,CAAC;AAC9C,SAASC,iBAAiB,QAAQ,qBAAqB,CAAC;AACxD,SAASC,wBAAwB,EAAEC,6BAA6B,EAAEC,yBAAyB,QAAQ,iBAAiB,CAAC;AAYrH,OAAO,SAASC,UAAU,CAACC,KAAsB,EAAE;IACjD,MAAM,EAAEC,UAAU,CAAA,EAAEC,UAAU,CAAA,EAAEC,W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,WAAW;wBAAEc,EAAE,EAAE;4BAAEI,SAAS,EAAE,GAAG;yBAAE;sBAAI;kCAClE,KAAC5B,GAAG;wBACF6B,SAAS,EAAC,MAAM;wBAChBL,EAAE,EAAE,CAACM,KAAK,GAAM,CAAA;gCACdL,OAAO,EAAE,cAAc;gCACvBM,KAAK,EAAE,mBAAmB;gCAC1BC,QAAQ,EAAE,GAAG;gCACbL,QAAQ,EAAExB,wBAAwB;gCAClC8B,QAAQ,EAAE,QAAQ;gCAClBC,KAAK,EAAEJ,KAAK,CAACK,OAAO,CAACC,MAAM,CAACC,KAAK;gCACjCC,UAAU,EAAE1B,aAAa,GAAGkB,KAAK,CAACS,UAAU,CAACC,cAAc,GAAGV,KAAK,CAACS,UAAU,CAACE,iBAAiB;gCAChGC,YAAY,EAAE,UAAU;gCACxBC,UAAU,EAAE9B,UAAU,GAAG,QAAQ,GAAG,QAAQ;6BAC7C,CAAA,AAAC;wBACF+B,YAAU,EAAEhC,aAAa,GAAGR,6BAA6B,GAAGC,yBAAyB;kCAEpFkB,mBAAmB;sBAChB;;cACF;0BACN,KAACvB,GAAG;gBACFwB,EAAE,EAAE,CAACM,KAAK,GAAM,CAAA;wBACdL,OAAO,EAAE,YAAY;wBACrBoB,WAAW,EAAE,GAAG;wBAChBC,SAAS,EAAE,OAAO;wBAClBC,aAAa,EAAE,KAAK;wBACpBT,UAAU,EAAE1B,aAAa,GAAGkB,KAAK,CAACS,UAAU,CAACC,cAAc,GAAGV,KAAK,CAACS,UAAU,CAACE,iBAAiB;qBACjG,CAAA,AAAC;0BAEDhC,UAAU;cACP;;MACF,CACN;AACJ,CAAC"}
@@ -4,9 +4,10 @@ import { EChartsDataFormat, UnitOptions } from '../model';
4
4
  interface TimeSeriesTooltipProps {
5
5
  chartRef: React.MutableRefObject<EChartsInstance | undefined>;
6
6
  chartData: EChartsDataFormat;
7
- pinTooltip: boolean;
7
+ isTooltipPinned: boolean;
8
8
  wrapLabels?: boolean;
9
9
  unit?: UnitOptions;
10
+ onUnpinClick?: () => void;
10
11
  }
11
12
  export declare const TimeSeriesTooltip: React.NamedExoticComponent<TimeSeriesTooltipProps>;
12
13
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"TimeSeriesTooltip.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/TimeSeriesTooltip.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAM1D,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC9D,SAAS,EAAE,iBAAiB,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,eAAO,MAAM,iBAAiB,oDAmE5B,CAAC"}
1
+ {"version":3,"file":"TimeSeriesTooltip.d.ts","sourceRoot":"","sources":["../../src/TimeSeriesTooltip/TimeSeriesTooltip.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAa1D,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,GAAG,SAAS,CAAC,CAAC;IAC9D,SAAS,EAAE,iBAAiB,CAAC;IAC7B,eAAe,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,eAAO,MAAM,iBAAiB,oDAwG5B,CAAC"}
@@ -10,38 +10,52 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
- import { Box, Portal } from '@mui/material';
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { Box, Portal, Typography, Stack, Switch } from '@mui/material';
15
15
  import React, { useState } from 'react';
16
16
  import useResizeObserver from 'use-resize-observer';
17
17
  import { TooltipContent } from './TooltipContent';
18
- import { getFocusedSeriesData } from './focused-series';
19
- import { TOOLTIP_MAX_HEIGHT, TOOLTIP_MAX_WIDTH, useMousePosition } from './tooltip-model';
18
+ import { getNearbySeriesData } from './nearby-series';
19
+ import { FALLBACK_CHART_WIDTH, TOOLTIP_MAX_HEIGHT, TOOLTIP_MIN_WIDTH, TOOLTIP_MAX_WIDTH, useMousePosition } from './tooltip-model';
20
20
  import { assembleTransform } from './utils';
21
- export const TimeSeriesTooltip = /*#__PURE__*/ React.memo(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , pinTooltip , unit }) {
21
+ export const TimeSeriesTooltip = /*#__PURE__*/ React.memo(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , isTooltipPinned , unit , onUnpinClick }) {
22
+ const [showAllSeries, setShowAllSeries] = useState(false);
22
23
  const [pinnedPos, setPinnedPos] = useState(null);
23
24
  const mousePos = useMousePosition();
24
25
  const { height , width , ref: tooltipRef } = useResizeObserver();
25
26
  if (mousePos === null || mousePos.target === null) return null;
26
- // ensure user is hovering over a chart before checking for nearby series
27
+ // Ensure user is hovering over a chart before checking for nearby series.
27
28
  if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
28
29
  const chart = chartRef.current;
29
- const focusedSeries = getFocusedSeriesData(mousePos, chartData, pinnedPos, chart, unit);
30
30
  var ref;
31
- const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : 750;
32
- const cursorTransform = assembleTransform(mousePos, focusedSeries.length, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
31
+ const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : FALLBACK_CHART_WIDTH; // Fallback width not likely to every be needed.
32
+ const cursorTransform = assembleTransform(mousePos, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
33
+ // Get series nearby the cursor and pass into tooltip content children.
34
+ const focusedSeries = getNearbySeriesData({
35
+ mousePos,
36
+ chartData,
37
+ pinnedPos,
38
+ chart,
39
+ unit,
40
+ showAllSeries
41
+ });
33
42
  if (focusedSeries.length === 0) {
34
43
  return null;
35
44
  }
36
- if (pinTooltip === true && pinnedPos === null) {
45
+ if (isTooltipPinned === true && pinnedPos === null) {
37
46
  setPinnedPos(mousePos);
38
47
  }
48
+ // Option for user to see all series instead of only the nearby focused series.
49
+ // Only relevant when there are more total series than are visible.
50
+ const showAllSeriesToggle = isTooltipPinned === true && showAllSeries === false && chartData.timeSeries.length > 1 && focusedSeries.length !== chartData.timeSeries.length;
39
51
  return /*#__PURE__*/ _jsx(Portal, {
40
- children: /*#__PURE__*/ _jsx(Box, {
52
+ children: /*#__PURE__*/ _jsxs(Box, {
41
53
  ref: tooltipRef,
42
54
  sx: (theme)=>({
55
+ minWidth: TOOLTIP_MIN_WIDTH,
43
56
  maxWidth: TOOLTIP_MAX_WIDTH,
44
57
  maxHeight: TOOLTIP_MAX_HEIGHT,
58
+ padding: theme.spacing(0.5, 2),
45
59
  position: 'absolute',
46
60
  top: 0,
47
61
  left: 0,
@@ -61,10 +75,41 @@ export const TimeSeriesTooltip = /*#__PURE__*/ React.memo(function TimeSeriesToo
61
75
  style: {
62
76
  transform: cursorTransform
63
77
  },
64
- children: /*#__PURE__*/ _jsx(TooltipContent, {
65
- focusedSeries: focusedSeries,
66
- wrapLabels: wrapLabels
67
- })
78
+ children: [
79
+ /*#__PURE__*/ _jsx(TooltipContent, {
80
+ series: focusedSeries,
81
+ wrapLabels: wrapLabels,
82
+ isTooltipPinned: isTooltipPinned,
83
+ onUnpinClick: ()=>{
84
+ setPinnedPos(null);
85
+ if (onUnpinClick !== undefined) {
86
+ onUnpinClick();
87
+ }
88
+ }
89
+ }),
90
+ showAllSeriesToggle && /*#__PURE__*/ _jsxs(Stack, {
91
+ direction: "row",
92
+ gap: 1,
93
+ alignItems: "center",
94
+ sx: {
95
+ textAlign: 'right'
96
+ },
97
+ children: [
98
+ /*#__PURE__*/ _jsx(Typography, {
99
+ children: "Show All?"
100
+ }),
101
+ /*#__PURE__*/ _jsx(Switch, {
102
+ checked: showAllSeries,
103
+ onChange: (_, checked)=>setShowAllSeries(checked),
104
+ sx: (theme)=>({
105
+ '& .MuiSwitch-switchBase': {
106
+ color: theme.palette.common.white
107
+ }
108
+ })
109
+ })
110
+ ]
111
+ })
112
+ ]
68
113
  })
69
114
  });
70
115
  });