@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.
- package/dist/Legend/CompactLegend.d.ts +6 -4
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +4 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +11 -9
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +45 -11
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +5 -8
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +34 -99
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +8 -8
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js +9 -12
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +2 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +31 -22
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/Table/InnerTable.d.ts +9 -0
- package/dist/Table/InnerTable.d.ts.map +1 -0
- package/dist/Table/InnerTable.js +38 -0
- package/dist/Table/InnerTable.js.map +1 -0
- package/dist/Table/Table.d.ts +10 -0
- package/dist/Table/Table.d.ts.map +1 -0
- package/dist/Table/Table.js +101 -0
- package/dist/Table/Table.js.map +1 -0
- package/dist/Table/TableBody.d.ts +6 -0
- package/dist/Table/TableBody.d.ts.map +1 -0
- package/dist/Table/TableBody.js +23 -0
- package/dist/Table/TableBody.js.map +1 -0
- package/dist/Table/TableCell.d.ts +18 -0
- package/dist/Table/TableCell.d.ts.map +1 -0
- package/dist/Table/TableCell.js +91 -0
- package/dist/Table/TableCell.js.map +1 -0
- package/dist/Table/TableCheckbox.d.ts +9 -0
- package/dist/Table/TableCheckbox.d.ts.map +1 -0
- package/dist/Table/TableCheckbox.js +49 -0
- package/dist/Table/TableCheckbox.js.map +1 -0
- package/dist/Table/TableHead.d.ts +6 -0
- package/dist/Table/TableHead.d.ts.map +1 -0
- package/dist/Table/TableHead.js +23 -0
- package/dist/Table/TableHead.js.map +1 -0
- package/dist/Table/TableRow.d.ts +9 -0
- package/dist/Table/TableRow.d.ts.map +1 -0
- package/dist/Table/TableRow.js +29 -0
- package/dist/Table/TableRow.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +11 -0
- package/dist/Table/VirtualizedTable.d.ts.map +1 -0
- package/dist/Table/VirtualizedTable.js +152 -0
- package/dist/Table/VirtualizedTable.js.map +1 -0
- package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
- package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
- package/dist/Table/VirtualizedTableContainer.js +24 -0
- package/dist/Table/VirtualizedTableContainer.js.map +1 -0
- package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
- package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
- package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
- package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
- package/dist/Table/index.d.ts +4 -0
- package/dist/Table/index.d.ts.map +1 -0
- package/dist/Table/index.js +16 -0
- package/dist/Table/index.js.map +1 -0
- package/dist/Table/model/table-model.d.ts +83 -0
- package/dist/Table/model/table-model.d.ts.map +1 -0
- package/dist/Table/model/table-model.js +73 -0
- package/dist/Table/model/table-model.js.map +1 -0
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +2 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +60 -15
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts +5 -3
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +79 -42
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +1 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +8 -4
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +6 -2
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +4 -3
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/cjs/Legend/CompactLegend.js +4 -1
- package/dist/cjs/Legend/Legend.js +45 -11
- package/dist/cjs/Legend/ListLegend.js +33 -98
- package/dist/cjs/Legend/ListLegendItem.js +8 -11
- package/dist/cjs/LineChart/LineChart.js +31 -22
- package/dist/cjs/Table/InnerTable.js +44 -0
- package/dist/cjs/Table/Table.js +102 -0
- package/dist/cjs/Table/TableBody.js +29 -0
- package/dist/cjs/Table/TableCell.js +97 -0
- package/dist/cjs/Table/TableCheckbox.js +55 -0
- package/dist/cjs/Table/TableHead.js +29 -0
- package/dist/cjs/Table/TableRow.js +35 -0
- package/dist/cjs/Table/VirtualizedTable.js +155 -0
- package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
- package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
- package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
- package/dist/cjs/Table/index.js +33 -0
- package/dist/cjs/Table/model/table-model.js +80 -0
- package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +57 -12
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +83 -41
- package/dist/cjs/TimeSeriesTooltip/index.js +1 -1
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +11 -3
- package/dist/cjs/TimeSeriesTooltip/utils.js +3 -2
- package/dist/cjs/context/SnackbarProvider.js +66 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/model/legend.js +7 -1
- package/dist/cjs/theme/palette/grey.js +6 -2
- package/dist/context/SnackbarProvider.d.ts +23 -0
- package/dist/context/SnackbarProvider.d.ts.map +1 -0
- package/dist/context/SnackbarProvider.js +59 -0
- package/dist/context/SnackbarProvider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/legend.d.ts +10 -2
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +5 -0
- package/dist/model/legend.js.map +1 -1
- package/dist/theme/palette/grey.d.ts.map +1 -1
- package/dist/theme/palette/grey.js +6 -2
- package/dist/theme/palette/grey.js.map +1 -1
- package/package.json +6 -6
- package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
- package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/focused-series.js +0 -110
- package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
- package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -116
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { LegendItem } from '../model';
|
|
3
|
-
|
|
2
|
+
import { LegendItem, SelectedLegendItemState } from '../model';
|
|
3
|
+
import { ListLegendItemProps } from './ListLegendItem';
|
|
4
|
+
export interface CompactLegendProps {
|
|
4
5
|
height: number;
|
|
5
6
|
items: LegendItem[];
|
|
7
|
+
selectedItems: SelectedLegendItemState;
|
|
8
|
+
onLegendItemClick: ListLegendItemProps['onClick'];
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* CompactLegend is default and used when legend items need to show side by side
|
|
@@ -10,6 +13,5 @@ interface CompactLegendProps {
|
|
|
10
13
|
* number of items. The `ListLegend` is used for cases with large numbers of items
|
|
11
14
|
* because it is virtualized.
|
|
12
15
|
*/
|
|
13
|
-
export declare function CompactLegend({ height, items }: CompactLegendProps): JSX.Element;
|
|
14
|
-
export {};
|
|
16
|
+
export declare function CompactLegend({ height, items, selectedItems, onLegendItemClick }: CompactLegendProps): JSX.Element;
|
|
15
17
|
//# sourceMappingURL=CompactLegend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompactLegend.d.ts","sourceRoot":"","sources":["../../src/Legend/CompactLegend.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"CompactLegend.d.ts","sourceRoot":"","sources":["../../src/Legend/CompactLegend.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAgC,MAAM,UAAU,CAAC;AAC7F,OAAO,EAAkB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,aAAa,EAAE,uBAAuB,CAAC;IACvC,iBAAiB,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CACnD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,EAAE,kBAAkB,eAkBpG"}
|
|
@@ -12,13 +12,14 @@
|
|
|
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 { isLegendItemVisuallySelected } from '../model';
|
|
15
16
|
import { ListLegendItem } from './ListLegendItem';
|
|
16
17
|
/**
|
|
17
18
|
* CompactLegend is default and used when legend items need to show side by side
|
|
18
19
|
* which corresponds to when legend.position is `bottom` with a relatively small
|
|
19
20
|
* number of items. The `ListLegend` is used for cases with large numbers of items
|
|
20
21
|
* because it is virtualized.
|
|
21
|
-
*/ export function CompactLegend({ height , items }) {
|
|
22
|
+
*/ export function CompactLegend({ height , items , selectedItems , onLegendItemClick }) {
|
|
22
23
|
return /*#__PURE__*/ _jsx(Box, {
|
|
23
24
|
component: "ul",
|
|
24
25
|
sx: {
|
|
@@ -35,6 +36,8 @@ import { ListLegendItem } from './ListLegendItem';
|
|
|
35
36
|
},
|
|
36
37
|
children: items.map((item)=>/*#__PURE__*/ _jsx(ListLegendItem, {
|
|
37
38
|
item: item,
|
|
39
|
+
isVisuallySelected: isLegendItemVisuallySelected(item, selectedItems),
|
|
40
|
+
onClick: onLegendItemClick,
|
|
38
41
|
sx: {
|
|
39
42
|
width: 'auto',
|
|
40
43
|
float: 'left',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Legend/CompactLegend.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 { LegendItem } from '../model';\nimport { ListLegendItem } from './ListLegendItem';\n\
|
|
1
|
+
{"version":3,"sources":["../../src/Legend/CompactLegend.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 { LegendItem, SelectedLegendItemState, isLegendItemVisuallySelected } from '../model';\nimport { ListLegendItem, ListLegendItemProps } from './ListLegendItem';\n\nexport interface CompactLegendProps {\n height: number;\n items: LegendItem[];\n selectedItems: SelectedLegendItemState;\n onLegendItemClick: ListLegendItemProps['onClick'];\n}\n\n/**\n * CompactLegend is default and used when legend items need to show side by side\n * which corresponds to when legend.position is `bottom` with a relatively small\n * number of items. The `ListLegend` is used for cases with large numbers of items\n * because it is virtualized.\n */\nexport function CompactLegend({ height, items, selectedItems, onLegendItemClick }: CompactLegendProps) {\n return (\n <Box component=\"ul\" sx={{ width: '100%', height, padding: [0, 1, 0, 0], overflowY: 'scroll', margin: 0 }}>\n {items.map((item) => (\n <ListLegendItem\n key={item.id}\n item={item}\n isVisuallySelected={isLegendItemVisuallySelected(item, selectedItems)}\n onClick={onLegendItemClick}\n sx={{\n width: 'auto',\n float: 'left',\n paddingRight: 1.5,\n }}\n />\n ))}\n </Box>\n );\n}\n"],"names":["Box","isLegendItemVisuallySelected","ListLegendItem","CompactLegend","height","items","selectedItems","onLegendItemClick","component","sx","width","padding","overflowY","margin","map","item","isVisuallySelected","onClick","float","paddingRight","id"],"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,SAA8CC,4BAA4B,QAAQ,UAAU,CAAC;AAC7F,SAASC,cAAc,QAA6B,kBAAkB,CAAC;AASvE;;;;;CAKC,GACD,OAAO,SAASC,aAAa,CAAC,EAAEC,MAAM,CAAA,EAAEC,KAAK,CAAA,EAAEC,aAAa,CAAA,EAAEC,iBAAiB,CAAA,EAAsB,EAAE;IACrG,qBACE,KAACP,GAAG;QAACQ,SAAS,EAAC,IAAI;QAACC,EAAE,EAAE;YAAEC,KAAK,EAAE,MAAM;YAAEN,MAAM;YAAEO,OAAO,EAAE;AAAC,iBAAC;AAAE,iBAAC;AAAE,iBAAC;AAAE,iBAAC;aAAC;YAAEC,SAAS,EAAE,QAAQ;YAAEC,MAAM,EAAE,CAAC;SAAE;kBACrGR,KAAK,CAACS,GAAG,CAAC,CAACC,IAAI,iBACd,KAACb,cAAc;gBAEba,IAAI,EAAEA,IAAI;gBACVC,kBAAkB,EAAEf,4BAA4B,CAACc,IAAI,EAAET,aAAa,CAAC;gBACrEW,OAAO,EAAEV,iBAAiB;gBAC1BE,EAAE,EAAE;oBACFC,KAAK,EAAE,MAAM;oBACbQ,KAAK,EAAE,MAAM;oBACbC,YAAY,EAAE,GAAG;iBAClB;eARIJ,IAAI,CAACK,EAAE,CASZ,AACH,CAAC;MACE,CACN;AACJ,CAAC"}
|
package/dist/Legend/Legend.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { LegendOptions, LegendItem } from '../model';
|
|
3
|
-
import { ListLegendProps } from './ListLegend';
|
|
2
|
+
import { LegendOptions, LegendItem, SelectedLegendItemState } from '../model';
|
|
4
3
|
export interface LegendProps {
|
|
5
4
|
width: number;
|
|
6
5
|
height: number;
|
|
7
6
|
data: LegendItem[];
|
|
8
7
|
options: LegendOptions;
|
|
9
8
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* to render performantly.
|
|
9
|
+
* State of selected items in the legend.
|
|
10
|
+
*
|
|
11
|
+
* Selected legend item state is a controlled value that should be managed using a
|
|
12
|
+
* combination of this prop and `onSelectedChange`.
|
|
15
13
|
*/
|
|
16
|
-
|
|
14
|
+
selectedItems: SelectedLegendItemState;
|
|
15
|
+
/**
|
|
16
|
+
* Callback fired when the selected items in the legend changes.
|
|
17
|
+
*/
|
|
18
|
+
onSelectedItemsChange: (newSelected: SelectedLegendItemState) => void;
|
|
17
19
|
}
|
|
18
|
-
export declare function Legend({ width, height, options, data,
|
|
20
|
+
export declare function Legend({ width, height, options, data, selectedItems, onSelectedItemsChange }: LegendProps): JSX.Element;
|
|
19
21
|
//# sourceMappingURL=Legend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["../../src/Legend/Legend.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["../../src/Legend/Legend.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAI9E,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,OAAO,EAAE,aAAa,CAAC;IAEvB;;;;;OAKG;IACH,aAAa,EAAE,uBAAuB,CAAC;IAEvC;;OAEG;IACH,qBAAqB,EAAE,CAAC,WAAW,EAAE,uBAAuB,KAAK,IAAI,CAAC;CACvE;AASD,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,qBAAqB,EAAE,EAAE,WAAW,eAiFzG"}
|
package/dist/Legend/Legend.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
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';
|
|
15
16
|
import { ListLegend } from './ListLegend';
|
|
16
17
|
import { CompactLegend } from './CompactLegend';
|
|
17
18
|
// When the number of items to display is above this number, it is likely to
|
|
@@ -20,7 +21,45 @@ import { CompactLegend } from './CompactLegend';
|
|
|
20
21
|
// Set this number based on testing, but it may need to be tuned a bit on the
|
|
21
22
|
// future as people test this out on different machines.
|
|
22
23
|
const NEED_VIRTUALIZATION_LIMIT = 500;
|
|
23
|
-
export function Legend({ width , height , options , data ,
|
|
24
|
+
export function Legend({ width , height , options , data , selectedItems , onSelectedItemsChange }) {
|
|
25
|
+
const onLegendItemClick = (e, seriesId)=>{
|
|
26
|
+
const isModifiedClick = e.metaKey || e.shiftKey;
|
|
27
|
+
const newSelected = produce(selectedItems, (draft)=>{
|
|
28
|
+
if (draft === 'ALL') {
|
|
29
|
+
return {
|
|
30
|
+
[seriesId]: true
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const isSelected = !!draft[seriesId];
|
|
34
|
+
// Clicks with modifier key can select multiple items.
|
|
35
|
+
if (isModifiedClick) {
|
|
36
|
+
if (isSelected) {
|
|
37
|
+
// Modified click on already selected item. Remove that item.
|
|
38
|
+
delete draft[seriesId];
|
|
39
|
+
} else {
|
|
40
|
+
// Modified click on not-selected item. Add it.
|
|
41
|
+
draft[seriesId] = true;
|
|
42
|
+
}
|
|
43
|
+
return draft;
|
|
44
|
+
}
|
|
45
|
+
if (isSelected) {
|
|
46
|
+
// Clicked item was already selected. Unselect it and return to
|
|
47
|
+
// ALL state.
|
|
48
|
+
return 'ALL';
|
|
49
|
+
}
|
|
50
|
+
// Select clicked item.
|
|
51
|
+
return {
|
|
52
|
+
[seriesId]: true
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
onSelectedItemsChange(newSelected);
|
|
56
|
+
};
|
|
57
|
+
const commonLegendProps = {
|
|
58
|
+
height,
|
|
59
|
+
items: data,
|
|
60
|
+
selectedItems,
|
|
61
|
+
onLegendItemClick
|
|
62
|
+
};
|
|
24
63
|
if (options.position === 'Right') {
|
|
25
64
|
return /*#__PURE__*/ _jsx(Box, {
|
|
26
65
|
sx: {
|
|
@@ -31,10 +70,8 @@ export function Legend({ width , height , options , data , listProps }) {
|
|
|
31
70
|
right: 0
|
|
32
71
|
},
|
|
33
72
|
children: /*#__PURE__*/ _jsx(ListLegend, {
|
|
34
|
-
|
|
35
|
-
width: width
|
|
36
|
-
height: height,
|
|
37
|
-
...listProps
|
|
73
|
+
...commonLegendProps,
|
|
74
|
+
width: width
|
|
38
75
|
})
|
|
39
76
|
});
|
|
40
77
|
}
|
|
@@ -51,13 +88,10 @@ export function Legend({ width , height , options , data , listProps }) {
|
|
|
51
88
|
bottom: 0
|
|
52
89
|
},
|
|
53
90
|
children: needsVirtualization ? /*#__PURE__*/ _jsx(ListLegend, {
|
|
54
|
-
|
|
55
|
-
width: width
|
|
56
|
-
height: height,
|
|
57
|
-
...listProps
|
|
91
|
+
...commonLegendProps,
|
|
92
|
+
width: width
|
|
58
93
|
}) : /*#__PURE__*/ _jsx(CompactLegend, {
|
|
59
|
-
|
|
60
|
-
height: height
|
|
94
|
+
...commonLegendProps
|
|
61
95
|
})
|
|
62
96
|
});
|
|
63
97
|
}
|
|
@@ -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 *
|
|
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 { produce } from 'immer';\nimport { LegendOptions, LegendItem, SelectedLegendItemState } from '../model';\nimport { ListLegend, ListLegendProps } from './ListLegend';\nimport { CompactLegend, CompactLegendProps } from './CompactLegend';\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 commonLegendProps: ListLegendProps | CompactLegendProps = {\n height,\n items: data,\n selectedItems,\n 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 <ListLegend {...commonLegendProps} width={width} />\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 {...commonLegendProps} width={width} />\n ) : (\n <CompactLegend {...commonLegendProps} />\n )}\n </Box>\n );\n}\n"],"names":["Box","produce","ListLegend","CompactLegend","NEED_VIRTUALIZATION_LIMIT","Legend","width","height","options","data","selectedItems","onSelectedItemsChange","onLegendItemClick","e","seriesId","isModifiedClick","metaKey","shiftKey","newSelected","draft","isSelected","commonLegendProps","items","position","sx","top","right","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;AACpC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAEhC,SAASC,UAAU,QAAyB,cAAc,CAAC;AAC3D,SAASC,aAAa,QAA4B,iBAAiB,CAAC;AAsBpE,4EAA4E;AAC5E,6EAA6E;AAC7E,mFAAmF;AACnF,6EAA6E;AAC7E,wDAAwD;AACxD,MAAMC,yBAAyB,GAAG,GAAG,AAAC;AAEtC,OAAO,SAASC,MAAM,CAAC,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,OAAO,CAAA,EAAEC,IAAI,CAAA,EAAEC,aAAa,CAAA,EAAEC,qBAAqB,CAAA,EAAe,EAAE;IAC1G,MAAMC,iBAAiB,GAAG,CAACC,CAA4C,EAAEC,QAAgB,GAAK;QAC5F,MAAMC,eAAe,GAAGF,CAAC,CAACG,OAAO,IAAIH,CAAC,CAACI,QAAQ,AAAC;QAEhD,MAAMC,WAAW,GAAGjB,OAAO,CAACS,aAAa,EAAE,CAACS,KAAK,GAAK;YACpD,IAAIA,KAAK,KAAK,KAAK,EAAE;gBACnB,OAAO;oBACL,CAACL,QAAQ,CAAC,EAAE,IAAI;iBACjB,CAAC;YACJ,CAAC;YAED,MAAMM,UAAU,GAAG,CAAC,CAACD,KAAK,CAACL,QAAQ,CAAC,AAAC;YAErC,sDAAsD;YACtD,IAAIC,eAAe,EAAE;gBACnB,IAAIK,UAA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B,iBAAiB;YAAEf,KAAK,EAAEA,KAAK;UAAI,iBAEnD,KAACH,aAAa;YAAE,GAAGkB,iBAAiB;UAAI,AACzC;MACG,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
|
-
|
|
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,
|
|
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":";
|
|
1
|
+
{"version":3,"file":"ListLegend.d.ts","sourceRoot":"","sources":["../../src/Legend/ListLegend.tsx"],"names":[],"mappings":";AAeA,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,eA6CrG"}
|
|
@@ -11,91 +11,42 @@
|
|
|
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 {
|
|
16
|
-
import {
|
|
14
|
+
import { useTheme, Box } from '@mui/material';
|
|
15
|
+
import { Virtuoso } from 'react-virtuoso';
|
|
16
|
+
import { isLegendItemVisuallySelected } from '../model';
|
|
17
17
|
import { ListLegendItem } from './ListLegendItem';
|
|
18
|
-
const DEFAULT_INITIAL_ROW_HEIGHT = 26;
|
|
19
18
|
/**
|
|
20
19
|
* ListLegend is used when legend.position is 'right' since legend items are
|
|
21
20
|
* stacked. It is also used for `bottom` positioned legends when there are a
|
|
22
21
|
* large number of items because it is virtualized and easier to visually scan
|
|
23
22
|
* large numbers of items when there is a single item per row.
|
|
24
|
-
*/ export function ListLegend({ items , height , width ,
|
|
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({});
|
|
23
|
+
*/ export function ListLegend({ items , height , width , selectedItems , onLegendItemClick }) {
|
|
33
24
|
const theme = useTheme();
|
|
34
|
-
// Padding value used
|
|
35
|
-
//
|
|
36
|
-
//
|
|
25
|
+
// Padding value used in the react virtuoso header/footer components to
|
|
26
|
+
// simulate top/bottom padding based on recommendation in this
|
|
27
|
+
// issue.
|
|
28
|
+
// https://github.com/petyosi/react-virtuoso/issues/238
|
|
37
29
|
const LIST_PADDING = parseInt(theme.spacing(1), 10);
|
|
30
|
+
const mockPadding = /*#__PURE__*/ _jsx(Box, {
|
|
31
|
+
sx: {
|
|
32
|
+
width: '100%',
|
|
33
|
+
height: `${LIST_PADDING}px`
|
|
34
|
+
}
|
|
35
|
+
});
|
|
38
36
|
// show full labels on hover when there are many total series
|
|
39
37
|
const truncateLabels = items.length > 5;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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,
|
|
38
|
+
return /*#__PURE__*/ _jsx(Virtuoso, {
|
|
39
|
+
style: {
|
|
40
|
+
height,
|
|
41
|
+
width
|
|
42
|
+
},
|
|
43
|
+
data: items,
|
|
44
|
+
itemContent: (index, item)=>{
|
|
45
|
+
return /*#__PURE__*/ _jsx(ListLegendItem, {
|
|
96
46
|
item: item,
|
|
97
47
|
truncateLabel: truncateLabels,
|
|
98
|
-
|
|
48
|
+
isVisuallySelected: isLegendItemVisuallySelected(item, selectedItems),
|
|
49
|
+
onClick: onLegendItemClick,
|
|
99
50
|
sx: {
|
|
100
51
|
// Having an explicit width is important for the ellipsizing to
|
|
101
52
|
// work correctly. Subtract padding to simulate padding.
|
|
@@ -103,33 +54,17 @@ const DEFAULT_INITIAL_ROW_HEIGHT = 26;
|
|
|
103
54
|
wordBreak: 'break-word',
|
|
104
55
|
overflow: 'hidden'
|
|
105
56
|
}
|
|
106
|
-
}, item.id)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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`
|
|
57
|
+
}, item.id);
|
|
58
|
+
},
|
|
59
|
+
role: "list",
|
|
60
|
+
components: {
|
|
61
|
+
Header: ()=>{
|
|
62
|
+
return mockPadding;
|
|
121
63
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
height: height,
|
|
127
|
-
width: width,
|
|
128
|
-
itemCount: items.length,
|
|
129
|
-
itemSize: getRowHeight,
|
|
130
|
-
innerElementType: InnerElementType,
|
|
131
|
-
ref: listRef,
|
|
132
|
-
children: ListLegendRow
|
|
64
|
+
Footer: ()=>{
|
|
65
|
+
return mockPadding;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
133
68
|
});
|
|
134
69
|
}
|
|
135
70
|
|
|
@@ -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,SAASC,UAAU,CAAC,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,KAAK,CAAA,EAAEC,gBAAgB,EAAGL,0BAA0B,CAAA,EAAmB,EAAE;IACnH,uEAAuE;IACvE,6EAA6E;IAC7E,yCAAyC;IACzC,MAAMM,OAAO,GAAGX,MAAM,CAAmB,IAAI,CAAC,AAAC;IAC/C,wEAAwE;IACxE,0EAA0E;IAC1E,QAAQ;IACR,MAAMY,UAAU,GAAGZ,MAAM,CAAyB,EAAE,CAAC,AAAC;IAEtD,MAAMa,KAAK,GAAGf,QAAQ,EAAE,AAAC;IACzB,2EAA2E;IAC3E,6CAA6C;IAC7C,4FAA4F;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ALA,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 { useTheme, Box } from '@mui/material';\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 const theme = useTheme();\n // Padding value used in the react virtuoso header/footer components to\n // simulate top/bottom padding based on recommendation in this\n // issue.\n // https://github.com/petyosi/react-virtuoso/issues/238\n const LIST_PADDING = parseInt(theme.spacing(1), 10);\n const mockPadding = <Box sx={{ width: '100%', height: `${LIST_PADDING}px` }}></Box>;\n\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 - LIST_PADDING,\n wordBreak: 'break-word',\n overflow: 'hidden',\n }}\n />\n );\n }}\n role=\"list\"\n components={{\n Header: () => {\n return mockPadding;\n },\n Footer: () => {\n return mockPadding;\n },\n }}\n />\n );\n}\n"],"names":["useTheme","Box","Virtuoso","isLegendItemVisuallySelected","ListLegendItem","ListLegend","items","height","width","selectedItems","onLegendItemClick","theme","LIST_PADDING","parseInt","spacing","mockPadding","sx","truncateLabels","length","style","data","itemContent","index","item","truncateLabel","isVisuallySelected","onClick","wordBreak","overflow","id","role","components","Header","Footer"],"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,EAAEC,GAAG,QAAQ,eAAe,CAAC;AAC9C,SAASC,QAAQ,QAAQ,gBAAgB,CAAC;A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I,EAAC,MAAM;QACXC,UAAU,EAAE;YACVC,MAAM,EAAE,IAAM;gBACZ,OAAOjB,WAAW,CAAC;YACrB,CAAC;YACDkB,MAAM,EAAE,IAAM;gBACZ,OAAOlB,WAAW,CAAC;YACrB,CAAC;SACF;MACD,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" | "
|
|
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" | "disableGutters" | "ContainerComponent" | "ContainerProps" | "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,
|
|
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
|
|
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 ,
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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:
|
|
50
|
-
selected:
|
|
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
|
|
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,QAAQ,CAACU,aAAa,CAAC,AAAC;IAEpD,SAASO,eAAe,GAAG;QACzB,IAAIP,aAAa,EAAE;YACjBM,SAAS,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IAED,SAASE,cAAc,GAAG;QACxB,IAAIR,aAAa,EAAE;YACjBM,SAAS,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,MAAMG,WAAW,GAA4C,CAACC,C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