@perses-dev/components 0.26.1 → 0.28.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/InfoTooltip/InfoTooltip.d.ts.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +8 -5
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/Legend/CompactLegend.d.ts +3 -1
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +3 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +10 -1
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +24 -7
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +14 -4
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +111 -15
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +14 -2
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js +31 -3
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +0 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +1 -3
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +4 -2
- package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -1
- package/dist/OptionsEditorLayout/OptionsEditorControl.js +34 -5
- package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
- package/dist/StatChart/StatChart.d.ts +1 -0
- package/dist/StatChart/StatChart.d.ts.map +1 -1
- package/dist/StatChart/StatChart.js +2 -2
- package/dist/StatChart/StatChart.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts +3 -1
- package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdInput.js +9 -3
- package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
- package/dist/ThresholdsEditor/ThresholdsEditor.js +57 -35
- package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +0 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +3 -4
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +0 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -3
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts +0 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +1 -2
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +2 -10
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +4 -8
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +9 -6
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/cjs/InfoTooltip/InfoTooltip.js +8 -5
- package/dist/cjs/Legend/Legend.js +24 -7
- package/dist/cjs/Legend/ListLegend.js +106 -13
- package/dist/cjs/Legend/ListLegendItem.js +30 -2
- package/dist/cjs/LineChart/LineChart.js +1 -3
- package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +33 -4
- package/dist/cjs/StatChart/StatChart.js +2 -2
- package/dist/cjs/ThresholdsEditor/ThresholdInput.js +8 -2
- package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +56 -34
- package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +3 -4
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -3
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +1 -2
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +4 -8
- package/dist/cjs/TimeSeriesTooltip/utils.js +9 -6
- package/dist/cjs/model/units/bytes.js +33 -39
- package/dist/cjs/model/units/decimal.js +15 -26
- package/dist/cjs/model/units/time.js +2 -3
- package/dist/cjs/utils/theme-gen.js +1 -1
- package/dist/model/legend.d.ts +1 -1
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/units/bytes.d.ts +1 -5
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +28 -42
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/decimal.d.ts +1 -12
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +14 -30
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +2 -3
- package/dist/model/units/time.js.map +1 -1
- package/dist/utils/theme-gen.js +1 -1
- package/dist/utils/theme-gen.js.map +1 -1
- package/package.json +11 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InfoTooltip.d.ts","sourceRoot":"","sources":["../../src/InfoTooltip/InfoTooltip.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,oBAAY,gBAAgB,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEnE,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,WAAW,iFAQrB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"InfoTooltip.d.ts","sourceRoot":"","sources":["../../src/InfoTooltip/InfoTooltip.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,oBAAY,gBAAgB,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEnE,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,eAAO,MAAM,WAAW,iFAQrB,gBAAgB,gBAqBlB,CAAC"}
|
|
@@ -14,10 +14,13 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
14
14
|
import React from 'react';
|
|
15
15
|
import { styled, Tooltip as MuiTooltip, tooltipClasses, Typography } from '@mui/material';
|
|
16
16
|
export const InfoTooltip = ({ id , title , description , placement , children , enterDelay , enterNextDelay })=>{
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
// children
|
|
20
|
-
|
|
17
|
+
// Wrap children in a span to cover the following use cases:
|
|
18
|
+
// - Disabled buttons. MUI console.errors on putting these inside a tooltip.
|
|
19
|
+
// - Non-element tooltip children (e.g. text). The tooltip needs something that
|
|
20
|
+
// can have a ref as a child.
|
|
21
|
+
// We wrap in a `span` and not a `div` to minimize the impact on page layout
|
|
22
|
+
// and styles.
|
|
23
|
+
const wrappedChildren = /*#__PURE__*/ _jsx("span", {
|
|
21
24
|
children: children
|
|
22
25
|
});
|
|
23
26
|
return /*#__PURE__*/ _jsx(StyledTooltip, {
|
|
@@ -30,7 +33,7 @@ export const InfoTooltip = ({ id , title , description , placement , children ,
|
|
|
30
33
|
}),
|
|
31
34
|
enterDelay: enterDelay !== null && enterDelay !== void 0 ? enterDelay : 500,
|
|
32
35
|
enterNextDelay: enterNextDelay !== null && enterNextDelay !== void 0 ? enterNextDelay : 500,
|
|
33
|
-
children:
|
|
36
|
+
children: wrappedChildren
|
|
34
37
|
});
|
|
35
38
|
};
|
|
36
39
|
const TooltipContent = ({ title , description })=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/InfoTooltip/InfoTooltip.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 from 'react';\nimport {\n styled,\n TooltipProps as MuiTooltipProps,\n Tooltip as MuiTooltip,\n tooltipClasses,\n Typography,\n} from '@mui/material';\n\nexport type TooltipPlacement = 'top' | 'left' | 'right' | 'bottom';\n\ninterface InfoTooltipProps {\n description: string;\n children: React.ReactNode;\n id?: string;\n title?: string;\n placement?: TooltipPlacement;\n enterDelay?: number; // default is 500ms\n enterNextDelay?: number; // default is 500ms\n}\n\nexport const InfoTooltip = ({\n id,\n title,\n description,\n placement,\n children,\n enterDelay,\n enterNextDelay,\n}: InfoTooltipProps) => {\n //
|
|
1
|
+
{"version":3,"sources":["../../src/InfoTooltip/InfoTooltip.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 from 'react';\nimport {\n styled,\n TooltipProps as MuiTooltipProps,\n Tooltip as MuiTooltip,\n tooltipClasses,\n Typography,\n} from '@mui/material';\n\nexport type TooltipPlacement = 'top' | 'left' | 'right' | 'bottom';\n\ninterface InfoTooltipProps {\n description: string;\n children: React.ReactNode;\n id?: string;\n title?: string;\n placement?: TooltipPlacement;\n enterDelay?: number; // default is 500ms\n enterNextDelay?: number; // default is 500ms\n}\n\nexport const InfoTooltip = ({\n id,\n title,\n description,\n placement,\n children,\n enterDelay,\n enterNextDelay,\n}: InfoTooltipProps) => {\n // Wrap children in a span to cover the following use cases:\n // - Disabled buttons. MUI console.errors on putting these inside a tooltip.\n // - Non-element tooltip children (e.g. text). The tooltip needs something that\n // can have a ref as a child.\n // We wrap in a `span` and not a `div` to minimize the impact on page layout\n // and styles.\n const wrappedChildren = <span>{children}</span>;\n\n return (\n <StyledTooltip\n arrow\n id={id}\n placement={placement ?? 'top'}\n title={<TooltipContent title={title} description={description} />}\n enterDelay={enterDelay ?? 500}\n enterNextDelay={enterNextDelay ?? 500}\n >\n {wrappedChildren}\n </StyledTooltip>\n );\n};\n\nconst TooltipContent = ({ title, description }: Pick<InfoTooltipProps, 'title' | 'description'>) => {\n return (\n <>\n {title && (\n <Typography\n variant=\"body2\"\n sx={(theme) => ({\n color: theme.palette.text.primary,\n fontWeight: theme.typography.fontWeightMedium,\n })}\n >\n {title}\n </Typography>\n )}\n <Typography\n variant=\"caption\"\n sx={(theme) => ({\n color: theme.palette.text.primary,\n })}\n >\n {description}\n </Typography>\n </>\n );\n};\n\nconst StyledTooltip = styled(({ className, ...props }: MuiTooltipProps) => (\n <MuiTooltip {...props} classes={{ popper: className }} />\n))(({ theme }) => ({\n [`& .${tooltipClasses.tooltip}`]: {\n backgroundColor: theme.palette.background.tooltip,\n color: theme.palette.text.primary,\n maxWidth: '300px',\n padding: theme.spacing(1),\n boxShadow: theme.shadows[1],\n },\n [`& .${tooltipClasses.arrow}`]: {\n color: theme.palette.background.tooltip,\n },\n}));\n"],"names":["React","styled","Tooltip","MuiTooltip","tooltipClasses","Typography","InfoTooltip","id","title","description","placement","children","enterDelay","enterNextDelay","wrappedChildren","span","StyledTooltip","arrow","TooltipContent","variant","sx","theme","color","palette","text","primary","fontWeight","typography","fontWeightMedium","className","props","classes","popper","tooltip","backgroundColor","background","maxWidth","padding","spacing","boxShadow","shadows"],"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,MAAM,OAAO,CAAC;AAC1B,SACEC,MAAM,EAENC,OAAO,IAAIC,UAAU,EACrBC,cAAc,EACdC,UAAU,QACL,eAAe,CAAC;AAcvB,OAAO,MAAMC,WAAW,GAAG,CAAC,EAC1BC,EAAE,CAAA,EACFC,KAAK,CAAA,EACLC,WAAW,CAAA,EACXC,SAAS,CAAA,EACTC,QAAQ,CAAA,EACRC,UAAU,CAAA,EACVC,cAAc,CAAA,EACG,GAAK;IACtB,4DAA4D;IAC5D,6EAA6E;IAC7E,gFAAgF;IAChF,+BAA+B;IAC/B,4EAA4E;IAC5E,cAAc;IACd,MAAMC,eAAe,iBAAG,KAACC,MAAI;kBAAEJ,QAAQ;MAAQ,AAAC;IAEhD,qBACE,KAACK,aAAa;QACZC,KAAK;QACLV,EAAE,EAAEA,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C,EAAE;YAChCC,eAAe,EAAEb,KAAK,CAACE,OAAO,CAACY,UAAU,CAACF,OAAO;YACjDX,KAAK,EAAED,KAAK,CAACE,OAAO,CAACC,IAAI,CAACC,OAAO;YACjCW,QAAQ,EAAE,OAAO;YACjBC,OAAO,EAAEhB,KAAK,CAACiB,OAAO,CAAC,CAAC,CAAC;YACzBC,SAAS,EAAElB,KAAK,CAACmB,OAAO,CAAC,CAAC,CAAC;SAC5B;QACD,CAAC,CAAC,GAAG,EAAEpC,cAAc,CAACa,KAAK,CAAC,CAAC,CAAC,EAAE;YAC9BK,KAAK,EAAED,KAAK,CAACE,OAAO,CAACY,UAAU,CAACF,OAAO;SACxC;KACF,CAAA,AAAC,CAAC,AAAC"}
|
|
@@ -6,7 +6,9 @@ interface CompactLegendProps {
|
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* CompactLegend is default and used when legend items need to show side by side
|
|
9
|
-
* which corresponds to when legend.position is `bottom`
|
|
9
|
+
* which corresponds to when legend.position is `bottom` with a relatively small
|
|
10
|
+
* number of items. The `ListLegend` is used for cases with large numbers of items
|
|
11
|
+
* because it is virtualized.
|
|
10
12
|
*/
|
|
11
13
|
export declare function CompactLegend({ height, items }: CompactLegendProps): JSX.Element;
|
|
12
14
|
export {};
|
|
@@ -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;AAGtC,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED
|
|
1
|
+
{"version":3,"file":"CompactLegend.d.ts","sourceRoot":"","sources":["../../src/Legend/CompactLegend.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,UAAU,EAAE,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,kBAAkB,eAgBlE"}
|
|
@@ -15,7 +15,9 @@ import { Box } from '@mui/material';
|
|
|
15
15
|
import { ListLegendItem } from './ListLegendItem';
|
|
16
16
|
/**
|
|
17
17
|
* CompactLegend is default and used when legend items need to show side by side
|
|
18
|
-
* which corresponds to when legend.position is `bottom`
|
|
18
|
+
* which corresponds to when legend.position is `bottom` with a relatively small
|
|
19
|
+
* number of items. The `ListLegend` is used for cases with large numbers of items
|
|
20
|
+
* because it is virtualized.
|
|
19
21
|
*/ export function CompactLegend({ height , items }) {
|
|
20
22
|
return /*#__PURE__*/ _jsx(Box, {
|
|
21
23
|
component: "ul",
|
|
@@ -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\ninterface CompactLegendProps {\n height: number;\n items: LegendItem[];\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
|
|
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\ninterface CompactLegendProps {\n height: number;\n items: LegendItem[];\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 }: 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 sx={{\n width: 'auto',\n float: 'left',\n paddingRight: 1.5,\n }}\n />\n ))}\n </Box>\n );\n}\n"],"names":["Box","ListLegendItem","CompactLegend","height","items","component","sx","width","padding","overflowY","margin","map","item","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;AAEpC,SAASC,cAAc,QAAQ,kBAAkB,CAAC;AAOlD;;;;;CAKC,GACD,OAAO,SAASC,aAAa,CAAC,EAAEC,MAAM,CAAA,EAAEC,KAAK,CAAA,EAAsB,EAAE;IACnE,qBACE,KAACJ,GAAG;QAACK,SAAS,EAAC,IAAI;QAACC,EAAE,EAAE;YAAEC,KAAK,EAAE,MAAM;YAAEJ,MAAM;YAAEK,OAAO,EAAE;AAAC,iBAAC;AAAE,iBAAC;AAAE,iBAAC;AAAE,iBAAC;aAAC;YAAEC,SAAS,EAAE,QAAQ;YAAEC,MAAM,EAAE,CAAC;SAAE;kBACrGN,KAAK,CAACO,GAAG,CAAC,CAACC,IAAI,iBACd,KAACX,cAAc;gBAEbW,IAAI,EAAEA,IAAI;gBACVN,EAAE,EAAE;oBACFC,KAAK,EAAE,MAAM;oBACbM,KAAK,EAAE,MAAM;oBACbC,YAAY,EAAE,GAAG;iBAClB;eANIF,IAAI,CAACG,EAAE,CAOZ,AACH,CAAC;MACE,CACN;AACJ,CAAC"}
|
package/dist/Legend/Legend.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LegendOptions, LegendItem } from '../model';
|
|
3
|
+
import { ListLegendProps } from './ListLegend';
|
|
3
4
|
export interface LegendProps {
|
|
4
5
|
width: number;
|
|
5
6
|
height: number;
|
|
6
7
|
data: LegendItem[];
|
|
7
8
|
options: LegendOptions;
|
|
9
|
+
/**
|
|
10
|
+
* Additional props that will be passed to the list variation of the legend
|
|
11
|
+
* that is used when:
|
|
12
|
+
* - The legend is positioned on the right.
|
|
13
|
+
* - The legend has a large number of items to display and requires virtualization
|
|
14
|
+
* to render performantly.
|
|
15
|
+
*/
|
|
16
|
+
listProps?: Pick<ListLegendProps, 'initialRowHeight'>;
|
|
8
17
|
}
|
|
9
|
-
export declare function Legend({ width, height, options, data }: LegendProps): JSX.Element;
|
|
18
|
+
export declare function Legend({ width, height, options, data, listProps }: LegendProps): JSX.Element;
|
|
10
19
|
//# sourceMappingURL=Legend.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["../../src/Legend/Legend.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["../../src/Legend/Legend.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAc,eAAe,EAAE,MAAM,cAAc,CAAC;AAG3D,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;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;CACvD;AASD,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,WAAW,eAsC9E"}
|
package/dist/Legend/Legend.js
CHANGED
|
@@ -14,23 +14,35 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
14
14
|
import { Box } from '@mui/material';
|
|
15
15
|
import { ListLegend } from './ListLegend';
|
|
16
16
|
import { CompactLegend } from './CompactLegend';
|
|
17
|
-
|
|
17
|
+
// When the number of items to display is above this number, it is likely to
|
|
18
|
+
// cause performance issues in the browser. The legend will be displayed in a
|
|
19
|
+
// format (list) that allows for virtualization to minimize the performance impact.
|
|
20
|
+
// Set this number based on testing, but it may need to be tuned a bit on the
|
|
21
|
+
// future as people test this out on different machines.
|
|
22
|
+
const NEED_VIRTUALIZATION_LIMIT = 500;
|
|
23
|
+
export function Legend({ width , height , options , data , listProps }) {
|
|
18
24
|
if (options.position === 'Right') {
|
|
19
25
|
return /*#__PURE__*/ _jsx(Box, {
|
|
20
26
|
sx: {
|
|
21
27
|
width: width,
|
|
22
|
-
height:
|
|
28
|
+
height: height,
|
|
23
29
|
position: 'absolute',
|
|
24
30
|
top: 0,
|
|
25
|
-
right: 0
|
|
26
|
-
overflowX: 'hidden',
|
|
27
|
-
overflowY: 'scroll'
|
|
31
|
+
right: 0
|
|
28
32
|
},
|
|
29
33
|
children: /*#__PURE__*/ _jsx(ListLegend, {
|
|
30
|
-
items: data
|
|
34
|
+
items: data,
|
|
35
|
+
width: width,
|
|
36
|
+
height: height,
|
|
37
|
+
...listProps
|
|
31
38
|
})
|
|
32
39
|
});
|
|
33
40
|
}
|
|
41
|
+
// The bottom legend is displayed as a list when the number of items is too
|
|
42
|
+
// large and requires virtualization. Otherwise, it is rendered more compactly.
|
|
43
|
+
// We do not need this check for the right-side legend because it is always
|
|
44
|
+
// a virtualized list.
|
|
45
|
+
const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
|
|
34
46
|
return /*#__PURE__*/ _jsx(Box, {
|
|
35
47
|
sx: {
|
|
36
48
|
width: width,
|
|
@@ -38,7 +50,12 @@ export function Legend({ width , height , options , data }) {
|
|
|
38
50
|
position: 'absolute',
|
|
39
51
|
bottom: 0
|
|
40
52
|
},
|
|
41
|
-
children: /*#__PURE__*/ _jsx(
|
|
53
|
+
children: needsVirtualization ? /*#__PURE__*/ _jsx(ListLegend, {
|
|
54
|
+
items: data,
|
|
55
|
+
width: width,
|
|
56
|
+
height: height,
|
|
57
|
+
...listProps
|
|
58
|
+
}) : /*#__PURE__*/ _jsx(CompactLegend, {
|
|
42
59
|
items: data,
|
|
43
60
|
height: height
|
|
44
61
|
})
|
|
@@ -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 } from './ListLegend';\nimport { CompactLegend } from './CompactLegend';\n\nexport interface LegendProps {\n width: number;\n height: number;\n data: LegendItem[];\n options: LegendOptions;\n}\n\nexport function Legend({ width, height, options, data }: LegendProps) {\n if (options.position === 'Right') {\n return (\n <Box\n sx={{\n width: width,\n height:
|
|
1
|
+
{"version":3,"sources":["../../src/Legend/Legend.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box } from '@mui/material';\nimport { LegendOptions, LegendItem } from '../model';\nimport { ListLegend, ListLegendProps } from './ListLegend';\nimport { CompactLegend } from './CompactLegend';\n\nexport interface LegendProps {\n width: number;\n height: number;\n data: LegendItem[];\n options: LegendOptions;\n\n /**\n * Additional props that will be passed to the list variation of the legend\n * that is used when:\n * - The legend is positioned on the right.\n * - The legend has a large number of items to display and requires virtualization\n * to render performantly.\n */\n listProps?: Pick<ListLegendProps, 'initialRowHeight'>;\n}\n\n// When the number of items to display is above this number, it is likely to\n// cause performance issues in the browser. The legend will be displayed in a\n// format (list) that allows for virtualization to minimize the performance impact.\n// Set this number based on testing, but it may need to be tuned a bit on the\n// future as people test this out on different machines.\nconst NEED_VIRTUALIZATION_LIMIT = 500;\n\nexport function Legend({ width, height, options, data, listProps }: LegendProps) {\n if (options.position === 'Right') {\n return (\n <Box\n sx={{\n width: width,\n height: height,\n position: 'absolute',\n top: 0,\n right: 0,\n }}\n >\n <ListLegend items={data} width={width} height={height} {...listProps} />\n </Box>\n );\n }\n\n // The bottom legend is displayed as a list when the number of items is too\n // large and requires virtualization. Otherwise, it is rendered more compactly.\n // We do not need this check for the right-side legend because it is always\n // a virtualized list.\n const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;\n return (\n <Box\n sx={{\n width: width,\n height: height,\n position: 'absolute',\n bottom: 0,\n }}\n >\n {needsVirtualization ? (\n <ListLegend items={data} width={width} height={height} {...listProps} />\n ) : (\n <CompactLegend items={data} height={height} />\n )}\n </Box>\n );\n}\n"],"names":["Box","ListLegend","CompactLegend","NEED_VIRTUALIZATION_LIMIT","Legend","width","height","options","data","listProps","position","sx","top","right","items","needsVirtualization","length","bottom"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,GAAG,QAAQ,eAAe,CAAC;AAEpC,SAASC,UAAU,QAAyB,cAAc,CAAC;AAC3D,SAASC,aAAa,QAAQ,iBAAiB,CAAC;AAkBhD,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,SAAS,CAAA,EAAe,EAAE;IAC/E,IAAIF,OAAO,CAACG,QAAQ,KAAK,OAAO,EAAE;QAChC,qBACE,KAACV,GAAG;YACFW,EAAE,EAAE;gBACFN,KAAK,EAAEA,KAAK;gBACZC,MAAM,EAAEA,MAAM;gBACdI,QAAQ,EAAE,UAAU;gBACpBE,GAAG,EAAE,CAAC;gBACNC,KAAK,EAAE,CAAC;aACT;sBAED,cAAA,KAACZ,UAAU;gBAACa,KAAK,EAAEN,IAAI;gBAAEH,KAAK,EAAEA,KAAK;gBAAEC,MAAM,EAAEA,MAAM;gBAAG,GAAGG,SAAS;cAAI;UACpE,CACN;IACJ,CAAC;IAED,2EAA2E;IAC3E,+EAA+E;IAC/E,2EAA2E;IAC3E,sBAAsB;IACtB,MAAMM,mBAAmB,GAAGP,IAAI,CAACQ,MAAM,IAAIb,yBAAyB,AAAC;IACrE,qBACE,KAACH,GAAG;QACFW,EAAE,EAAE;YACFN,KAAK,EAAEA,KAAK;YACZC,MAAM,EAAEA,MAAM;YACdI,QAAQ,EAAE,UAAU;YACpBO,MAAM,EAAE,CAAC;SACV;kBAEAF,mBAAmB,iBAClB,KAACd,UAAU;YAACa,KAAK,EAAEN,IAAI;YAAEH,KAAK,EAAEA,KAAK;YAAEC,MAAM,EAAEA,MAAM;YAAG,GAAGG,SAAS;UAAI,iBAExE,KAACP,aAAa;YAACY,KAAK,EAAEN,IAAI;YAAEF,MAAM,EAAEA,MAAM;UAAI,AAC/C;MACG,CACN;AACJ,CAAC"}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { LegendItem } from '../model';
|
|
3
|
-
interface ListLegendProps {
|
|
3
|
+
export interface ListLegendProps {
|
|
4
4
|
items: LegendItem[];
|
|
5
|
+
height: number;
|
|
6
|
+
width: number;
|
|
7
|
+
/**
|
|
8
|
+
* The height used when initially laying out items in the list. Once items
|
|
9
|
+
* render, the height is determined based on the content. This is needed
|
|
10
|
+
* because the list is virtualized.
|
|
11
|
+
*/
|
|
12
|
+
initialRowHeight?: number;
|
|
5
13
|
}
|
|
6
14
|
/**
|
|
7
|
-
* ListLegend is used when legend.position is 'right' since legend items are
|
|
15
|
+
* ListLegend is used when legend.position is 'right' since legend items are
|
|
16
|
+
* stacked. It is also used for `bottom` positioned legends when there are a
|
|
17
|
+
* large number of items because it is virtualized and easier to visually scan
|
|
18
|
+
* large numbers of items when there is a single item per row.
|
|
8
19
|
*/
|
|
9
|
-
export declare function ListLegend({ items }: ListLegendProps): JSX.Element;
|
|
10
|
-
export {};
|
|
20
|
+
export declare function ListLegend({ items, height, width, initialRowHeight }: ListLegendProps): JSX.Element;
|
|
11
21
|
//# 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":";AAgBA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAID;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,gBAA6C,EAAE,EAAE,eAAe,eAgIlH"}
|
|
@@ -11,29 +11,125 @@
|
|
|
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 {
|
|
14
|
+
import { useTheme } from '@mui/material';
|
|
15
|
+
import { VariableSizeList } from 'react-window';
|
|
16
|
+
import { useRef, useEffect, forwardRef, useCallback } from 'react';
|
|
15
17
|
import { ListLegendItem } from './ListLegendItem';
|
|
18
|
+
const DEFAULT_INITIAL_ROW_HEIGHT = 26;
|
|
16
19
|
/**
|
|
17
|
-
* ListLegend is used when legend.position is 'right' since legend items are
|
|
18
|
-
|
|
20
|
+
* ListLegend is used when legend.position is 'right' since legend items are
|
|
21
|
+
* stacked. It is also used for `bottom` positioned legends when there are a
|
|
22
|
+
* large number of items because it is virtualized and easier to visually scan
|
|
23
|
+
* large numbers of items when there is a single item per row.
|
|
24
|
+
*/ export function ListLegend({ items , height , width , initialRowHeight =DEFAULT_INITIAL_ROW_HEIGHT }) {
|
|
25
|
+
// Storing a ref to the react-window `VariableSizeList`, so we can call
|
|
26
|
+
// `resetAfterIndex` to resize the list after mouseover/out events to account
|
|
27
|
+
// for the change in list items on hover.
|
|
28
|
+
const listRef = useRef(null);
|
|
29
|
+
// Storing row heights, so we can use dynamic heights, which enables the
|
|
30
|
+
// user the hover to show the full label, while still having a virtualized
|
|
31
|
+
// list.
|
|
32
|
+
const rowHeights = useRef({});
|
|
33
|
+
const theme = useTheme();
|
|
34
|
+
// Padding value used throughout to adjust the react-window virtual layouts
|
|
35
|
+
// to simulate padding per the guidance from:
|
|
36
|
+
// https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
|
|
37
|
+
const LIST_PADDING = parseInt(theme.spacing(1), 10);
|
|
19
38
|
// show full labels on hover when there are many total series
|
|
20
39
|
const truncateLabels = items.length > 5;
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
// Gets the row height for a given item to enable the virtualized list to
|
|
41
|
+
// render the row properly.
|
|
42
|
+
function getRowHeight(index) {
|
|
43
|
+
const currentHeight = rowHeights.current[index];
|
|
44
|
+
return currentHeight !== null && currentHeight !== void 0 ? currentHeight : initialRowHeight;
|
|
45
|
+
}
|
|
46
|
+
// Set the height for a given item to enable the virtualized list to
|
|
47
|
+
// adjust to size changes.
|
|
48
|
+
function setRowHeight(index, size) {
|
|
49
|
+
var // Tell the virtualized list that items changed size and need to be
|
|
50
|
+
// re-evaluated.
|
|
51
|
+
ref;
|
|
52
|
+
(ref = listRef.current) === null || ref === void 0 ? void 0 : ref.resetAfterIndex(0);
|
|
53
|
+
rowHeights.current = {
|
|
54
|
+
...rowHeights.current,
|
|
55
|
+
[index]: size
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Renderer for virtualized rows in `VariableSizeList`.
|
|
59
|
+
function ListLegendRow({ index , style }) {
|
|
60
|
+
// Storing a ref to the row's `ListLegendItem`, so we can get the "real"
|
|
61
|
+
// height and adjust the height of the row based on it, enabling the dynamic
|
|
62
|
+
// heights on hover.
|
|
63
|
+
const rowRef = useRef(null);
|
|
64
|
+
// useCallback is important here to avoid constantly running the useEffect
|
|
65
|
+
// that calls this in `ListLegendItem`.
|
|
66
|
+
const handleRowLayoutChange = useCallback(()=>{
|
|
67
|
+
// Handle size changes from hovering on a list item.
|
|
68
|
+
if (rowRef.current) {
|
|
69
|
+
setRowHeight(index, rowRef.current.clientHeight);
|
|
70
|
+
}
|
|
71
|
+
}, [
|
|
72
|
+
index
|
|
73
|
+
]);
|
|
74
|
+
// Adjust row heights when the row being rendered changes.
|
|
75
|
+
useEffect(()=>{
|
|
76
|
+
handleRowLayoutChange();
|
|
77
|
+
}, [
|
|
78
|
+
handleRowLayoutChange
|
|
79
|
+
]);
|
|
80
|
+
const item = items[index];
|
|
81
|
+
if (!item) {
|
|
82
|
+
// This shouldn't happen if configured correctly, but covering
|
|
83
|
+
// the case to appease the type checking and to cover any edge
|
|
84
|
+
// cases.
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const originalTop = parseFloat(`${style.top}`);
|
|
88
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
89
|
+
style: {
|
|
90
|
+
...style,
|
|
91
|
+
// Adjust the top position to simulate top padding on the list.
|
|
92
|
+
top: `${originalTop + LIST_PADDING}px`
|
|
93
|
+
},
|
|
94
|
+
children: /*#__PURE__*/ _jsx(ListLegendItem, {
|
|
95
|
+
ref: rowRef,
|
|
23
96
|
item: item,
|
|
97
|
+
truncateLabel: truncateLabels,
|
|
98
|
+
onLayoutChange: handleRowLayoutChange,
|
|
24
99
|
sx: {
|
|
25
|
-
width
|
|
26
|
-
|
|
100
|
+
// Having an explicit width is important for the ellipsizing to
|
|
101
|
+
// work correctly. Subtract padding to simulate padding.
|
|
102
|
+
width: width - LIST_PADDING,
|
|
27
103
|
wordBreak: 'break-word',
|
|
28
|
-
overflow:
|
|
29
|
-
whiteSpace: truncateLabels ? 'nowrap' : 'normal',
|
|
30
|
-
// TODO: add optional hover effect to show unformatted label
|
|
31
|
-
'&:hover': {
|
|
32
|
-
overflow: 'visible',
|
|
33
|
-
whiteSpace: 'normal'
|
|
34
|
-
}
|
|
104
|
+
overflow: 'hidden'
|
|
35
105
|
}
|
|
36
|
-
}, item.id)
|
|
106
|
+
}, item.id)
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
// Renderer for the inner container element of the `VariableSizeList` used
|
|
110
|
+
// to adjust styles to simulate padding on the list per:
|
|
111
|
+
// https://github.com/bvaughn/react-window#can-i-add-padding-to-the-top-and-bottom-of-a-list
|
|
112
|
+
const InnerElementType = /*#__PURE__*/ forwardRef(function InnerElementType({ style , ...rest }, ref) {
|
|
113
|
+
const originalHeight = (style === null || style === void 0 ? void 0 : style.height) ? parseFloat(`${style === null || style === void 0 ? void 0 : style.height}`) : 0;
|
|
114
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
115
|
+
ref: ref,
|
|
116
|
+
role: "list",
|
|
117
|
+
style: {
|
|
118
|
+
...style,
|
|
119
|
+
// Adjust height to account for simulated padding.
|
|
120
|
+
height: `${originalHeight + LIST_PADDING * 2}px`
|
|
121
|
+
},
|
|
122
|
+
...rest
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return /*#__PURE__*/ _jsx(VariableSizeList, {
|
|
126
|
+
height: height,
|
|
127
|
+
width: width,
|
|
128
|
+
itemCount: items.length,
|
|
129
|
+
itemSize: getRowHeight,
|
|
130
|
+
innerElementType: InnerElementType,
|
|
131
|
+
ref: listRef,
|
|
132
|
+
children: ListLegendRow
|
|
37
133
|
});
|
|
38
134
|
}
|
|
39
135
|
|
|
@@ -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 { List } from '@mui/material';\nimport { LegendItem } from '../model';\nimport { ListLegendItem } from './ListLegendItem';\n\ninterface ListLegendProps {\n items: LegendItem[];\n}\n\n/**\n * ListLegend is used when legend.position is 'right' since legend items are stacked\n */\nexport function ListLegend({ items }: ListLegendProps) {\n // show full labels on hover when there are many total series\n const truncateLabels = items.length > 5;\n return (\n <List>\n {items.map((item) => (\n <ListLegendItem\n key={item.id}\n item={item}\n sx={{\n width: 190,\n textOverflow: 'ellipsis',\n wordBreak: 'break-word',\n overflow: truncateLabels ? 'hidden' : 'visible',\n whiteSpace: truncateLabels ? 'nowrap' : 'normal',\n // TODO: add optional hover effect to show unformatted label\n '&:hover': {\n overflow: 'visible',\n whiteSpace: 'normal', // this allow you to see the full label on hover\n },\n }}\n />\n ))}\n </List>\n );\n}\n"],"names":["List","ListLegendItem","ListLegend","items","truncateLabels","length","map","item","sx","width","textOverflow","wordBreak","overflow","whiteSpace","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,IAAI,QAAQ,eAAe,CAAC;AAErC,SAASC,cAAc,QAAQ,kBAAkB,CAAC;AAMlD;;CAEC,GACD,OAAO,SAASC,UAAU,CAAC,EAAEC,KAAK,CAAA,EAAmB,EAAE;IACrD,6DAA6D;IAC7D,MAAMC,cAAc,GAAGD,KAAK,CAACE,MAAM,GAAG,CAAC,AAAC;IACxC,qBACE,KAACL,IAAI;kBACFG,KAAK,CAACG,GAAG,CAAC,CAACC,IAAI,iBACd,KAACN,cAAc;gBAEbM,IAAI,EAAEA,IAAI;gBACVC,EAAE,EAAE;oBACFC,KAAK,EAAE,GAAG;oBACVC,YAAY,EAAE,UAAU;oBACxBC,SAAS,EAAE,YAAY;oBACvBC,QAAQ,EAAER,cAAc,GAAG,QAAQ,GAAG,SAAS;oBAC/CS,UAAU,EAAET,cAAc,GAAG,QAAQ,GAAG,QAAQ;oBAChD,4DAA4D;oBAC5D,SAAS,EAAE;wBACTQ,QAAQ,EAAE,SAAS;wBACnBC,UAAU,EAAE,QAAQ;qBACrB;iBACF;eAbIN,IAAI,CAACO,EAAE,CAcZ,AACH,CAAC;MACG,CACP;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 } 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,iCAA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gBAAgB,EAAEN,gBAAgB;QAClCP,GAAG,EAAEzB,OAAO;kBAEXe,aAAa;MACG,CACnB;AACJ,CAAC"}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ListItemProps } from '@mui/material';
|
|
3
3
|
import { LegendItem } from '../model';
|
|
4
|
-
interface ListLegendItemProps extends ListItemProps {
|
|
4
|
+
interface ListLegendItemProps extends ListItemProps<'div'> {
|
|
5
5
|
item: LegendItem;
|
|
6
|
+
/**
|
|
7
|
+
* When `true`, will keep labels to a single line with overflow ellipsized. The
|
|
8
|
+
* full content will be shown on hover.
|
|
9
|
+
*
|
|
10
|
+
* When `false` or unset, will show the full label.
|
|
11
|
+
*/
|
|
12
|
+
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;
|
|
6
18
|
}
|
|
7
|
-
export declare const ListLegendItem: React.
|
|
19
|
+
export declare const ListLegendItem: React.MemoExoticComponent<React.ForwardRefExoticComponent<Pick<ListLegendItemProps, "classes" | "className" | "style" | "children" | "sx" | "slot" | "title" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "autoFocus" | "alignItems" | "disabled" | "selected" | "divider" | "components" | "componentsProps" | "slotProps" | "slots" | "dense" | "disableGutters" | "ContainerComponent" | "ContainerProps" | "disablePadding" | "secondaryAction" | "item" | "truncateLabel" | "onLayoutChange"> & React.RefAttributes<HTMLDivElement>>>;
|
|
8
20
|
export {};
|
|
9
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,KAA0C,MAAM,OAAO,CAAC;AAC/D,OAAO,EAA+B,aAAa,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAItC,UAAU,mBAAoB,SAAQ,aAAa,CAAC,KAAK,CAAC;IACxD,IAAI,EAAE,UAAU,CAAC;IAEjB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B;AAyDD,eAAO,MAAM,cAAc,g6JAAiC,CAAC"}
|
|
@@ -12,13 +12,34 @@
|
|
|
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 from 'react';
|
|
15
|
+
import React, { forwardRef, useState, useEffect } from 'react';
|
|
16
16
|
import { Box, ListItemText, ListItem } from '@mui/material';
|
|
17
17
|
import { combineSx } from '../utils';
|
|
18
18
|
import { LegendColorBadge } from './LegendColorBadge';
|
|
19
|
-
|
|
19
|
+
const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ item , sx , truncateLabel , onLayoutChange , ...others }, ref) {
|
|
20
|
+
const [noWrap, setNoWrap] = useState(truncateLabel);
|
|
21
|
+
function handleMouseOver() {
|
|
22
|
+
if (truncateLabel) {
|
|
23
|
+
setNoWrap(false);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function handleMouseOut() {
|
|
27
|
+
if (truncateLabel) {
|
|
28
|
+
setNoWrap(true);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
useEffect(()=>{
|
|
32
|
+
// When `noWrap` changes, so does the layout of the component. Notifies the
|
|
33
|
+
// parent, so it can handle those changes.
|
|
34
|
+
onLayoutChange === null || onLayoutChange === void 0 ? void 0 : onLayoutChange();
|
|
35
|
+
}, [
|
|
36
|
+
noWrap,
|
|
37
|
+
onLayoutChange
|
|
38
|
+
]);
|
|
20
39
|
return /*#__PURE__*/ _createElement(ListItem, {
|
|
21
40
|
...others,
|
|
41
|
+
component: "div",
|
|
42
|
+
role: "listitem",
|
|
22
43
|
sx: combineSx({
|
|
23
44
|
padding: 0,
|
|
24
45
|
cursor: 'pointer'
|
|
@@ -27,6 +48,7 @@ export const ListLegendItem = /*#__PURE__*/ React.memo(function ListLegendItem({
|
|
|
27
48
|
key: item.id,
|
|
28
49
|
onClick: item.onClick,
|
|
29
50
|
selected: item.isSelected,
|
|
51
|
+
ref: ref,
|
|
30
52
|
children: [
|
|
31
53
|
/*#__PURE__*/ _jsx(Box, {
|
|
32
54
|
sx: {
|
|
@@ -38,10 +60,16 @@ export const ListLegendItem = /*#__PURE__*/ React.memo(function ListLegendItem({
|
|
|
38
60
|
})
|
|
39
61
|
}),
|
|
40
62
|
/*#__PURE__*/ _jsx(ListItemText, {
|
|
41
|
-
primary: item.label
|
|
63
|
+
primary: item.label,
|
|
64
|
+
primaryTypographyProps: {
|
|
65
|
+
noWrap: noWrap
|
|
66
|
+
},
|
|
67
|
+
onMouseOver: handleMouseOver,
|
|
68
|
+
onMouseOut: handleMouseOut
|
|
42
69
|
})
|
|
43
70
|
]
|
|
44
71
|
});
|
|
45
72
|
});
|
|
73
|
+
export const ListLegendItem = /*#__PURE__*/ React.memo(ListLegendItemBase);
|
|
46
74
|
|
|
47
75
|
//# sourceMappingURL=ListLegendItem.js.map
|
|
@@ -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 from 'react';\nimport { Box, ListItemText, ListItem, ListItemProps } from '@mui/material';\nimport { LegendItem } from '../model';\nimport { combineSx } from '../utils';\nimport { LegendColorBadge } from './LegendColorBadge';\n\ninterface ListLegendItemProps extends ListItemProps {\n item: LegendItem;\n}\n\
|
|
1
|
+
{"version":3,"sources":["../../src/Legend/ListLegendItem.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { forwardRef, useState, useEffect } from 'react';\nimport { Box, ListItemText, ListItem, ListItemProps } from '@mui/material';\nimport { LegendItem } from '../model';\nimport { combineSx } from '../utils';\nimport { LegendColorBadge } from './LegendColorBadge';\n\ninterface ListLegendItemProps extends ListItemProps<'div'> {\n item: LegendItem;\n\n /**\n * When `true`, will keep labels to a single line with overflow ellipsized. The\n * full content will be shown on hover.\n *\n * When `false` or unset, will show the full label.\n */\n truncateLabel?: boolean;\n\n /**\n * Called when the layout of the legend item changes as a result of the hover\n * behavior when `truncateLabel` is `true`.\n */\n onLayoutChange?: () => void;\n}\n\nconst ListLegendItemBase = forwardRef<HTMLDivElement, ListLegendItemProps>(function ListLegendItem(\n { item, sx, truncateLabel, onLayoutChange, ...others },\n ref\n) {\n const [noWrap, setNoWrap] = useState(truncateLabel);\n\n function handleMouseOver() {\n if (truncateLabel) {\n setNoWrap(false);\n }\n }\n\n function handleMouseOut() {\n if (truncateLabel) {\n setNoWrap(true);\n }\n }\n\n useEffect(() => {\n // When `noWrap` changes, so does the layout of the component. Notifies the\n // parent, so it can handle those changes.\n onLayoutChange?.();\n }, [noWrap, onLayoutChange]);\n\n return (\n <ListItem\n {...others}\n component=\"div\"\n role=\"listitem\"\n sx={combineSx(\n {\n padding: 0,\n cursor: 'pointer',\n },\n sx\n )}\n dense={true}\n key={item.id}\n onClick={item.onClick}\n selected={item.isSelected}\n ref={ref}\n >\n <Box sx={{ display: 'flex', alignItems: 'center' }}>\n <LegendColorBadge color={item.color} />\n </Box>\n <ListItemText\n primary={item.label}\n primaryTypographyProps={{ noWrap: noWrap }}\n onMouseOver={handleMouseOver}\n onMouseOut={handleMouseOut}\n ></ListItemText>\n </ListItem>\n );\n});\n\nexport const ListLegendItem = React.memo(ListLegendItemBase);\n"],"names":["React","forwardRef","useState","useEffect","Box","ListItemText","ListItem","combineSx","LegendColorBadge","ListLegendItemBase","ListLegendItem","item","sx","truncateLabel","onLayoutChange","others","ref","noWrap","setNoWrap","handleMouseOver","handleMouseOut","component","role","padding","cursor","dense","key","id","onClick","selected","isSelected","display","alignItems","color","primary","label","primaryTypographyProps","onMouseOver","onMouseOut","memo"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,QAAQ,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AER,KAACZ,GAAG;gBAACQ,EAAE,EAAE;oBAAEmB,OAAO,EAAE,MAAM;oBAAEC,UAAU,EAAE,QAAQ;iBAAE;0BAChD,cAAA,KAACxB,gBAAgB;oBAACyB,KAAK,EAAEtB,IAAI,CAACsB,KAAK;kBAAI;cACnC;0BACN,KAAC5B,YAAY;gBACX6B,OAAO,EAAEvB,IAAI,CAACwB,KAAK;gBACnBC,sBAAsB,EAAE;oBAAEnB,MAAM,EAAEA,MAAM;iBAAE;gBAC1CoB,WAAW,EAAElB,eAAe;gBAC5BmB,UAAU,EAAElB,cAAc;cACZ;;MACP,CACX;AACJ,CAAC,CAAC,AAAC;AAEH,OAAO,MAAMV,cAAc,iBAAGV,KAAK,CAACuC,IAAI,CAAC9B,kBAAkB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/LineChart/LineChart.tsx"],"names":[],"mappings":"AAaA,OAAc,EAAE,UAAU,EAA6B,MAAM,OAAO,CAAC;AAErE,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EAEnB,qBAAqB,EACrB,oBAAoB,EAErB,MAAM,SAAS,CAAC;AAgBjB,OAAO,EAAE,iBAAiB,EAA+B,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAA0E,aAAa,EAAE,MAAM,SAAS,CAAC;AAgBhH,oBAAY,aAAa,GAAG;IAC1B,
|
|
1
|
+
{"version":3,"file":"LineChart.d.ts","sourceRoot":"","sources":["../../src/LineChart/LineChart.tsx"],"names":[],"mappings":"AAaA,OAAc,EAAE,UAAU,EAA6B,MAAM,OAAO,CAAC;AAErE,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EAEnB,qBAAqB,EACrB,oBAAoB,EAErB,MAAM,SAAS,CAAC;AAgBjB,OAAO,EAAE,iBAAiB,EAA+B,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAI7C,OAAO,EAA0E,aAAa,EAAE,MAAM,SAAS,CAAC;AAgBhH,oBAAY,aAAa,GAAG;IAC1B,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,IAAI,CAAC,EAAE,mBAAmB,CAAC;IAC3B,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IACxC,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,oCAAoC,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,iBAAiB,CAAC;CAC1F;AAED,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,aAAoC,EACpC,UAAU,EACV,aAAa,EACb,oCAAoC,GACrC,EAAE,cAAc,eA2JhB"}
|
|
@@ -37,8 +37,7 @@ use([
|
|
|
37
37
|
CanvasRenderer
|
|
38
38
|
]);
|
|
39
39
|
export function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
|
|
40
|
-
wrapLabels: true
|
|
41
|
-
showQuery: true
|
|
40
|
+
wrapLabels: true
|
|
42
41
|
} , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
|
|
43
42
|
var ref;
|
|
44
43
|
const chartsTheme = useChartsTheme();
|
|
@@ -179,7 +178,6 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , toolt
|
|
|
179
178
|
showTooltip === true && ((ref = option.tooltip) === null || ref === void 0 ? void 0 : ref.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ _jsx(TimeSeriesTooltip, {
|
|
180
179
|
chartRef: chartRef,
|
|
181
180
|
chartData: data,
|
|
182
|
-
showQuery: tooltipConfig.showQuery,
|
|
183
181
|
wrapLabels: tooltipConfig.wrapLabels,
|
|
184
182
|
pinTooltip: pinTooltip,
|
|
185
183
|
unit: unit
|