@perses-dev/components 0.31.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.d.ts +11 -0
  2. package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -0
  3. package/dist/ContentWithLegend/ContentWithLegend.js +65 -0
  4. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -0
  5. package/dist/ContentWithLegend/index.d.ts +2 -0
  6. package/dist/ContentWithLegend/index.d.ts.map +1 -0
  7. package/dist/ContentWithLegend/index.js +15 -0
  8. package/dist/ContentWithLegend/index.js.map +1 -0
  9. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +68 -0
  10. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -0
  11. package/dist/ContentWithLegend/model/content-with-legend-model.js +90 -0
  12. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -0
  13. package/dist/EChart/EChart.d.ts.map +1 -1
  14. package/dist/EChart/EChart.js +9 -1
  15. package/dist/EChart/EChart.js.map +1 -1
  16. package/dist/Legend/Legend.d.ts.map +1 -1
  17. package/dist/Legend/Legend.js +30 -15
  18. package/dist/Legend/Legend.js.map +1 -1
  19. package/dist/Legend/ListLegend.d.ts.map +1 -1
  20. package/dist/Legend/ListLegend.js +2 -23
  21. package/dist/Legend/ListLegend.js.map +1 -1
  22. package/dist/Legend/ListLegendItem.d.ts +1 -1
  23. package/dist/Legend/TableLegend.d.ts +12 -0
  24. package/dist/Legend/TableLegend.d.ts.map +1 -0
  25. package/dist/Legend/TableLegend.js +61 -0
  26. package/dist/Legend/TableLegend.js.map +1 -0
  27. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  28. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +35 -3
  29. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  30. package/dist/LineChart/LineChart.d.ts.map +1 -1
  31. package/dist/LineChart/LineChart.js +60 -22
  32. package/dist/LineChart/LineChart.js.map +1 -1
  33. package/dist/StatChart/StatChart.d.ts.map +1 -1
  34. package/dist/StatChart/StatChart.js +8 -1
  35. package/dist/StatChart/StatChart.js.map +1 -1
  36. package/dist/Table/InnerTable.js +1 -1
  37. package/dist/Table/InnerTable.js.map +1 -1
  38. package/dist/Table/TableCell.js +1 -1
  39. package/dist/Table/TableCell.js.map +1 -1
  40. package/dist/Table/TableRow.d.ts.map +1 -1
  41. package/dist/Table/TableRow.js +3 -3
  42. package/dist/Table/TableRow.js.map +1 -1
  43. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +5 -5
  44. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  45. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +36 -54
  46. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  47. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +0 -2
  48. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  49. package/dist/TimeSeriesTooltip/TooltipContent.js +21 -97
  50. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  51. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +12 -0
  52. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -0
  53. package/dist/TimeSeriesTooltip/TooltipHeader.js +163 -0
  54. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -0
  55. package/dist/TimeSeriesTooltip/index.d.ts +1 -0
  56. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  57. package/dist/TimeSeriesTooltip/index.js +1 -0
  58. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  59. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
  60. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  61. package/dist/TimeSeriesTooltip/nearby-series.js +2 -2
  62. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  63. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +10 -14
  64. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  65. package/dist/TimeSeriesTooltip/tooltip-model.js +2 -1
  66. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  67. package/dist/TimeSeriesTooltip/utils.js +2 -2
  68. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  69. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
  70. package/dist/cjs/ContentWithLegend/index.js +28 -0
  71. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
  72. package/dist/cjs/EChart/EChart.js +9 -1
  73. package/dist/cjs/Legend/Legend.js +30 -15
  74. package/dist/cjs/Legend/ListLegend.js +2 -23
  75. package/dist/cjs/Legend/TableLegend.js +67 -0
  76. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
  77. package/dist/cjs/LineChart/LineChart.js +60 -22
  78. package/dist/cjs/StatChart/StatChart.js +8 -1
  79. package/dist/cjs/Table/InnerTable.js +1 -1
  80. package/dist/cjs/Table/TableCell.js +1 -1
  81. package/dist/cjs/Table/TableRow.js +2 -2
  82. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +34 -91
  83. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +19 -100
  84. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +174 -0
  85. package/dist/cjs/TimeSeriesTooltip/index.js +1 -0
  86. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -2
  87. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +3 -1
  88. package/dist/cjs/TimeSeriesTooltip/utils.js +2 -2
  89. package/dist/cjs/index.js +1 -0
  90. package/dist/cjs/model/legend.js +30 -1
  91. package/dist/cjs/theme/component-overrides/paper.js +27 -0
  92. package/dist/cjs/theme/palette/background.js +2 -2
  93. package/dist/cjs/theme/theme.js +2 -0
  94. package/dist/index.d.ts +1 -0
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +1 -0
  97. package/dist/index.js.map +1 -1
  98. package/dist/model/legend.d.ts +9 -3
  99. package/dist/model/legend.d.ts.map +1 -1
  100. package/dist/model/legend.js +26 -1
  101. package/dist/model/legend.js.map +1 -1
  102. package/dist/theme/component-overrides/paper.d.ts +3 -0
  103. package/dist/theme/component-overrides/paper.d.ts.map +1 -0
  104. package/dist/theme/component-overrides/paper.js +21 -0
  105. package/dist/theme/component-overrides/paper.js.map +1 -0
  106. package/dist/theme/palette/background.js +2 -2
  107. package/dist/theme/palette/background.js.map +1 -1
  108. package/dist/theme/theme.d.ts.map +1 -1
  109. package/dist/theme/theme.js +2 -0
  110. package/dist/theme/theme.js.map +1 -1
  111. package/package.json +4 -7
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { ContentWithLegendProps } from './model/content-with-legend-model';
3
+ /**
4
+ * Component to help lay out content alongside a `Legend` component based on the
5
+ * configuration of the legend.
6
+ *
7
+ * See the documentation for the `Legend` component for more details about the
8
+ * features and configuration of the legend.
9
+ */
10
+ export declare function ContentWithLegend({ children, legendProps, width, height, spacing, minChildrenWidth, minChildrenHeight, }: ContentWithLegendProps): JSX.Element;
11
+ //# sourceMappingURL=ContentWithLegend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContentWithLegend.d.ts","sourceRoot":"","sources":["../../src/ContentWithLegend/ContentWithLegend.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,sBAAsB,EAA8B,MAAM,mCAAmC,CAAC;AAEvG;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,WAAW,EACX,KAAK,EACL,MAAM,EACN,OAAW,EACX,gBAAsB,EACtB,iBAAuB,GACxB,EAAE,sBAAsB,eAmCxB"}
@@ -0,0 +1,65 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import React from 'react';
15
+ import { Box, useTheme } from '@mui/material';
16
+ import { Legend } from '../Legend';
17
+ import { getContentWithLegendLayout } from './model/content-with-legend-model';
18
+ /**
19
+ * Component to help lay out content alongside a `Legend` component based on the
20
+ * configuration of the legend.
21
+ *
22
+ * See the documentation for the `Legend` component for more details about the
23
+ * features and configuration of the legend.
24
+ */ export function ContentWithLegend({ children , legendProps , width , height , spacing =0 , minChildrenWidth =100 , minChildrenHeight =100 }) {
25
+ const theme = useTheme();
26
+ const { content , legend , margin } = getContentWithLegendLayout({
27
+ width,
28
+ height,
29
+ legendOptions: legendProps === null || legendProps === void 0 ? void 0 : legendProps.options,
30
+ minChildrenHeight,
31
+ minChildrenWidth,
32
+ spacing,
33
+ theme
34
+ });
35
+ return /*#__PURE__*/ _jsxs(Box, {
36
+ sx: {
37
+ width,
38
+ height,
39
+ position: 'relative',
40
+ overflow: 'hidden'
41
+ },
42
+ children: [
43
+ /*#__PURE__*/ _jsx(Box, {
44
+ sx: {
45
+ width: content.width,
46
+ height: content.height,
47
+ marginRight: `${margin.right}px`,
48
+ marginBottom: `${margin.bottom}px`,
49
+ overflow: 'hidden'
50
+ },
51
+ children: typeof children === 'function' ? children({
52
+ width: content.width,
53
+ height: content.height
54
+ }) : children
55
+ }),
56
+ legendProps && legend.show && /*#__PURE__*/ _jsx(Legend, {
57
+ ...legendProps,
58
+ height: legend.height,
59
+ width: legend.width
60
+ })
61
+ ]
62
+ });
63
+ }
64
+
65
+ //# sourceMappingURL=ContentWithLegend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ContentWithLegend/ContentWithLegend.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, useTheme } from '@mui/material';\nimport { Legend } from '../Legend';\nimport { ContentWithLegendProps, getContentWithLegendLayout } from './model/content-with-legend-model';\n\n/**\n * Component to help lay out content alongside a `Legend` component based on the\n * configuration of the legend.\n *\n * See the documentation for the `Legend` component for more details about the\n * features and configuration of the legend.\n */\nexport function ContentWithLegend({\n children,\n legendProps,\n width,\n height,\n spacing = 0,\n minChildrenWidth = 100,\n minChildrenHeight = 100,\n}: ContentWithLegendProps) {\n const theme = useTheme();\n const { content, legend, margin } = getContentWithLegendLayout({\n width,\n height,\n legendOptions: legendProps?.options,\n minChildrenHeight,\n minChildrenWidth,\n spacing,\n theme,\n });\n\n return (\n <Box\n sx={{\n width,\n height,\n position: 'relative',\n overflow: 'hidden',\n }}\n >\n <Box\n sx={{\n width: content.width,\n height: content.height,\n marginRight: `${margin.right}px`,\n marginBottom: `${margin.bottom}px`,\n overflow: 'hidden',\n }}\n >\n {typeof children === 'function' ? children({ width: content.width, height: content.height }) : children}\n </Box>\n {legendProps && legend.show && <Legend {...legendProps} height={legend.height} width={legend.width} />}\n </Box>\n );\n}\n"],"names":["React","Box","useTheme","Legend","getContentWithLegendLayout","ContentWithLegend","children","legendProps","width","height","spacing","minChildrenWidth","minChildrenHeight","theme","content","legend","margin","legendOptions","options","sx","position","overflow","marginRight","right","marginBottom","bottom","show"],"mappings":"AAAA,oCAAoC;AACpC,kEAAk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AAC,EAAER,MAAM,CAACS,MAAM,CAAC,EAAE,CAAC;oBAClCJ,QAAQ,EAAE,QAAQ;iBACnB;0BAEA,OAAOf,QAAQ,KAAK,UAAU,GAAGA,QAAQ,CAAC;oBAAEE,KAAK,EAAEM,OAAO,CAACN,KAAK;oBAAEC,MAAM,EAAEK,OAAO,CAACL,MAAM;iBAAE,CAAC,GAAGH,QAAQ;cACnG;YACLC,WAAW,IAAIQ,MAAM,CAACW,IAAI,kBAAI,KAACvB,MAAM;gBAAE,GAAGI,WAAW;gBAAEE,MAAM,EAAEM,MAAM,CAACN,MAAM;gBAAED,KAAK,EAAEO,MAAM,CAACP,KAAK;cAAI;;MAClG,CACN;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './ContentWithLegend';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ContentWithLegend/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './ContentWithLegend';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ContentWithLegend/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './ContentWithLegend';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,68 @@
1
+ /// <reference types="react" />
2
+ import { Theme } from '@mui/material';
3
+ import { LegendProps } from '../../Legend';
4
+ import { LegendPositions } from '../../model/legend';
5
+ declare type Dimensions = {
6
+ width: number;
7
+ height: number;
8
+ };
9
+ export interface ContentWithLegendProps {
10
+ /**
11
+ * Width of the overall component layout in pixels.
12
+ */
13
+ width: number;
14
+ /**
15
+ * Height of overall component layout in pixels.
16
+ */
17
+ height: number;
18
+ /**
19
+ * Child content to render next to the legend. May be a react node or a
20
+ * function that returns a react node. The function provides the expected
21
+ * height and width for the content, which can be useful for passing down
22
+ * to chart components.
23
+ */
24
+ children: React.ReactNode | (({ width, height }: Dimensions) => React.ReactNode);
25
+ /**
26
+ * Props to configure the legend. If not set, the content is rendered without
27
+ * a legend.
28
+ */
29
+ legendProps?: Omit<LegendProps, 'width' | 'height'>;
30
+ /**
31
+ * Space to put between the children and the legend in pixels.
32
+ */
33
+ spacing?: number;
34
+ /**
35
+ * Minimum width required for the content specified by the `children` prop.
36
+ * If this width cannot be maintained with a right positioned legend, the
37
+ * legend will not be shown.
38
+ */
39
+ minChildrenWidth?: number;
40
+ /**
41
+ * Minimum height required for the content specified by the `children` prop.
42
+ * If this width cannot be maintained with a bottom positioned legend, the
43
+ * legend will not be shown.
44
+ */
45
+ minChildrenHeight?: number;
46
+ }
47
+ export interface ContentWithLegendLayoutOpts extends Required<Omit<ContentWithLegendProps, 'children' | 'legendProps'>> {
48
+ legendOptions?: LegendProps['options'];
49
+ theme: Theme;
50
+ }
51
+ export interface ContentWithLegendLayout {
52
+ legend: Dimensions & {
53
+ show: boolean;
54
+ };
55
+ content: Dimensions;
56
+ margin: {
57
+ right: number;
58
+ bottom: number;
59
+ };
60
+ }
61
+ declare type LegendSizeConfig = Record<LegendPositions, number>;
62
+ export declare const TABLE_LEGEND_SIZE: LegendSizeConfig;
63
+ /**
64
+ * Returns information for laying out content alongside a legend.
65
+ */
66
+ export declare function getContentWithLegendLayout({ width, height, legendOptions, minChildrenHeight, minChildrenWidth, spacing, theme, }: ContentWithLegendLayoutOpts): ContentWithLegendLayout;
67
+ export {};
68
+ //# sourceMappingURL=content-with-legend-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-with-legend-model.d.ts","sourceRoot":"","sources":["../../../src/ContentWithLegend/model/content-with-legend-model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAiB,MAAM,oBAAoB,CAAC;AAEpE,aAAK,UAAU,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,QAAQ,EAAE,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,KAAK,KAAK,CAAC,SAAS,CAAC,CAAC;IACjF;;;OAGG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC;IACpD;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,2BACf,SAAQ,QAAQ,CAAC,IAAI,CAAC,sBAAsB,EAAE,UAAU,GAAG,aAAa,CAAC,CAAC;IAC1E,aAAa,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC;IACvC,KAAK,EAAE,KAAK,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,UAAU,GAAG;QACnB,IAAI,EAAE,OAAO,CAAC;KACf,CAAC;IACF,OAAO,EAAE,UAAU,CAAC;IACpB,MAAM,EAAE;QACN,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH;AAED,aAAK,gBAAgB,GAAG,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;AAExD,eAAO,MAAM,iBAAiB,EAAE,gBAM/B,CAAC;AAMF;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,KAAK,EACL,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,OAAO,EACP,KAAK,GACN,EAAE,2BAA2B,GAAG,uBAAuB,CA4EvD"}
@@ -0,0 +1,90 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { getTableCellLayout } from '../../Table';
14
+ import { getLegendMode } from '../../model/legend';
15
+ export const TABLE_LEGEND_SIZE = {
16
+ // 5 rows plus header. Value to be multiplied by row height in pixels.
17
+ Bottom: 6,
18
+ // Pixel value
19
+ Right: 250
20
+ };
21
+ const PANEL_HEIGHT_LG_BREAKPOINT = 300;
22
+ const LEGEND_HEIGHT_SM = 40;
23
+ const LEGEND_HEIGHT_LG = 100;
24
+ /**
25
+ * Returns information for laying out content alongside a legend.
26
+ */ export function getContentWithLegendLayout({ width , height , legendOptions , minChildrenHeight , minChildrenWidth , spacing , theme }) {
27
+ const hasLegend = !!legendOptions;
28
+ const noLegendLayout = {
29
+ legend: {
30
+ show: false,
31
+ width: 0,
32
+ height: 0
33
+ },
34
+ content: {
35
+ width,
36
+ height
37
+ },
38
+ margin: {
39
+ right: 0,
40
+ bottom: 0
41
+ }
42
+ };
43
+ if (!hasLegend) {
44
+ return noLegendLayout;
45
+ }
46
+ const { position } = legendOptions;
47
+ const mode = getLegendMode(legendOptions.mode);
48
+ let legendWidth;
49
+ let legendHeight;
50
+ if (mode === 'List') {
51
+ // TODO: normalize list to share similar height options as the table
52
+ // when we add more size options.
53
+ legendWidth = position === 'Right' ? 200 : width;
54
+ // TODO: account for number of legend items returned when adjusting legend spacing
55
+ legendHeight = LEGEND_HEIGHT_SM;
56
+ if (position === 'Right') {
57
+ legendHeight = height;
58
+ } else if (height >= PANEL_HEIGHT_LG_BREAKPOINT) {
59
+ legendHeight = LEGEND_HEIGHT_LG;
60
+ }
61
+ } else {
62
+ // Table mode
63
+ const tableLayout = getTableCellLayout(theme, 'compact');
64
+ legendWidth = position === 'Right' ? TABLE_LEGEND_SIZE['Right'] : width;
65
+ legendHeight = position === 'Bottom' ? TABLE_LEGEND_SIZE['Bottom'] * tableLayout.height : height;
66
+ }
67
+ const contentWidth = position === 'Right' ? width - legendWidth - spacing : width;
68
+ const contentHeight = position === 'Bottom' ? height - legendHeight - spacing : height;
69
+ if (position === 'Right' && contentWidth < minChildrenWidth || position === 'Bottom' && contentHeight < minChildrenHeight) {
70
+ // Legend does not fit. Just show the content.
71
+ return noLegendLayout;
72
+ }
73
+ return {
74
+ legend: {
75
+ width: legendWidth,
76
+ height: legendHeight,
77
+ show: true
78
+ },
79
+ content: {
80
+ width: contentWidth,
81
+ height: contentHeight
82
+ },
83
+ margin: {
84
+ right: position === 'Right' ? spacing : 0,
85
+ bottom: position === 'Bottom' ? spacing : 0
86
+ }
87
+ };
88
+ }
89
+
90
+ //# sourceMappingURL=content-with-legend-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ContentWithLegend/model/content-with-legend-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Theme } from '@mui/material';\nimport { LegendProps } from '../../Legend';\nimport { getTableCellLayout } from '../../Table';\nimport { LegendPositions, getLegendMode } from '../../model/legend';\n\ntype Dimensions = {\n width: number;\n height: number;\n};\n\nexport interface ContentWithLegendProps {\n /**\n * Width of the overall component layout in pixels.\n */\n width: number;\n /**\n * Height of overall component layout in pixels.\n */\n height: number;\n /**\n * Child content to render next to the legend. May be a react node or a\n * function that returns a react node. The function provides the expected\n * height and width for the content, which can be useful for passing down\n * to chart components.\n */\n children: React.ReactNode | (({ width, height }: Dimensions) => React.ReactNode);\n /**\n * Props to configure the legend. If not set, the content is rendered without\n * a legend.\n */\n legendProps?: Omit<LegendProps, 'width' | 'height'>;\n /**\n * Space to put between the children and the legend in pixels.\n */\n spacing?: number;\n\n /**\n * Minimum width required for the content specified by the `children` prop.\n * If this width cannot be maintained with a right positioned legend, the\n * legend will not be shown.\n */\n minChildrenWidth?: number;\n\n /**\n * Minimum height required for the content specified by the `children` prop.\n * If this width cannot be maintained with a bottom positioned legend, the\n * legend will not be shown.\n */\n minChildrenHeight?: number;\n}\n\nexport interface ContentWithLegendLayoutOpts\n extends Required<Omit<ContentWithLegendProps, 'children' | 'legendProps'>> {\n legendOptions?: LegendProps['options'];\n theme: Theme;\n}\n\nexport interface ContentWithLegendLayout {\n legend: Dimensions & {\n show: boolean;\n };\n content: Dimensions;\n margin: {\n right: number;\n bottom: number;\n };\n}\n\ntype LegendSizeConfig = Record<LegendPositions, number>;\n\nexport const TABLE_LEGEND_SIZE: LegendSizeConfig = {\n // 5 rows plus header. Value to be multiplied by row height in pixels.\n Bottom: 6,\n\n // Pixel value\n Right: 250,\n};\n\nconst PANEL_HEIGHT_LG_BREAKPOINT = 300;\nconst LEGEND_HEIGHT_SM = 40;\nconst LEGEND_HEIGHT_LG = 100;\n\n/**\n * Returns information for laying out content alongside a legend.\n */\nexport function getContentWithLegendLayout({\n width,\n height,\n legendOptions,\n minChildrenHeight,\n minChildrenWidth,\n spacing,\n theme,\n}: ContentWithLegendLayoutOpts): ContentWithLegendLayout {\n const hasLegend = !!legendOptions;\n\n const noLegendLayout: ContentWithLegendLayout = {\n legend: {\n show: false,\n width: 0,\n height: 0,\n },\n content: {\n width,\n height,\n },\n margin: {\n right: 0,\n bottom: 0,\n },\n };\n\n if (!hasLegend) {\n return noLegendLayout;\n }\n\n const { position } = legendOptions;\n const mode = getLegendMode(legendOptions.mode);\n\n let legendWidth;\n let legendHeight;\n\n if (mode === 'List') {\n // TODO: normalize list to share similar height options as the table\n // when we add more size options.\n legendWidth = position === 'Right' ? 200 : width;\n\n // TODO: account for number of legend items returned when adjusting legend spacing\n legendHeight = LEGEND_HEIGHT_SM;\n if (position === 'Right') {\n legendHeight = height;\n } else if (height >= PANEL_HEIGHT_LG_BREAKPOINT) {\n legendHeight = LEGEND_HEIGHT_LG;\n }\n } else {\n // Table mode\n\n const tableLayout = getTableCellLayout(theme, 'compact');\n\n legendWidth = position === 'Right' ? TABLE_LEGEND_SIZE['Right'] : width;\n legendHeight = position === 'Bottom' ? TABLE_LEGEND_SIZE['Bottom'] * tableLayout.height : height;\n }\n\n const contentWidth = position === 'Right' ? width - legendWidth - spacing : width;\n const contentHeight = position === 'Bottom' ? height - legendHeight - spacing : height;\n\n if (\n (position === 'Right' && contentWidth < minChildrenWidth) ||\n (position === 'Bottom' && contentHeight < minChildrenHeight)\n ) {\n // Legend does not fit. Just show the content.\n return noLegendLayout;\n }\n\n return {\n legend: {\n width: legendWidth,\n height: legendHeight,\n show: true,\n },\n content: {\n width: contentWidth,\n height: contentHeight,\n },\n margin: {\n right: position === 'Right' ? spacing : 0,\n bottom: position === 'Bottom' ? spacing : 0,\n },\n };\n}\n"],"names":["getTableCellLayout","getLegendMode","TABLE_LEGEND_SIZE","Bottom","Right","PANEL_HEIGHT_LG_BREAKPOINT","LEGEND_HEIGHT_SM","LEGEND_HEIGHT_LG","getContentWithLegendLayout","width","height","legendOptions","minChildrenHeight","minChildrenWidth","spacing","theme","hasLegend","noLegendLayout","legend","show","content","margin","right","bottom","position","mode","legendWidth","legendHeight","tableLayout","contentWidth","contentHeight"],"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;AAIjC,SAASA,kBAAkB,QAAQ,aAAa,CAAC;AACjD,SAA0BC,aAAa,QAAQ,oBAAoB,CAAC;AAmEpE,OAAO,MAAMC,iBAAiB,GAAqB;IACjD,sEAAsE;IACtEC,MAAM,EAAE,CAAC;IAET,cAAc;IACdC,KAAK,EAAE,GAAG;CACX,CAAC;AAEF,MAAMC,0BAA0B,GAAG,GAAG,AAAC;AACvC,MAAMC,gBAAgB,GAAG,EAAE,AAAC;AAC5B,MAAMC,gBAAgB,GAAG,GAAG,AAAC;AAE7B;;CAEC,GACD,OAAO,SAASC,0BAA0B,CAA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ACjE;AAED,aAAK,oBAAoB,GAAG,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;AAEpE,QAAA,MAAM,WAAW,gDAAiD,CAAC;AAEnE,oBAAY,cAAc,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1D,aAAK,cAAc,GAAG,UAAU,CAAC;AAIjC,oBAAY,YAAY,CAAC,CAAC,IAAI;KAC3B,cAAc,IAAI,cAAc,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;CACxD,GAAG;KACD,cAAc,IAAI,cAAc,CAAC,CAAC,EAAE,oBAAoB;CAC1D,GAAG;KACD,SAAS,IAAI,cAAc,CAAC,CAAC,EAAE,MAAM,IAAI;CAC3C,CAAC;AAEF,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAC9B,QAAQ,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC;IAC5B,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IACxD,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,MAAM,6IAuFjB,CAAC"}
@@ -95,11 +95,19 @@ export const EChart = /*#__PURE__*/ React.memo(function EChart({ option , theme
95
95
  }, [
96
96
  onEvents
97
97
  ]);
98
+ // TODO: re-evaluate how this is triggered. It's technically working right
99
+ // now because the sx prop is an object that gets re-created, but that also
100
+ // means it runs unnecessarily some of the time and theoretically might
101
+ // not run in some other cases. Maybe it should use a resize observer?
98
102
  useEffect(()=>{
103
+ // TODO: fix this debouncing. This likely isn't working as intended because
104
+ // the debounced function is re-created every time this useEffect is called.
99
105
  const updateSize = debounce(()=>{
100
106
  if (!chartElement.current) return;
101
107
  chartElement.current.resize();
102
- }, 200);
108
+ }, 200, {
109
+ leading: true
110
+ });
103
111
  updateSize();
104
112
  }, [
105
113
  sx
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/EChart/EChart.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, { useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport { isEqual, debounce } from 'lodash-es';\nimport { EChartsTheme } from '../model';\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = React.memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n onEvents,\n _instance,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return () => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return () => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n useEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n updateSize();\n }, [sx]);\n\n return <Box ref={containerRef} sx={sx}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>) {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown) {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["React","useEffect","useLayoutEffect","useRef","init","Box","isEqual","debounce","mouseEvents","batchEvents","EChart","memo","option","theme","renderer","sx","onEvents","_instance","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"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,SAAS,EAAEC,eAAe,EAAEC,MAAM,QAAQ,OAAO,CAAC;AAClE,SAAqCC,IAAI,QAAQ,cAAc,CAAC;AAChE,SAASC,GAAG,QAAwB,eAAe,CAAC;AACpD,SAASC,OAAO,EAAEC,QAAQ,QAAQ,WAAW,CAAC;AAwB9C,MAAMC,WAAW,GAAG;IAClB,OAAO;IACP,UAAU;IACV,WAAW;IACX,WAAW;IACX,SAAS;IACT,WAAW;IACX,UAAU;IACV,WAAW;IACX,aAAa;CACd,AAAS,AAAC;AAkCX,MAAMC,WAAW,GAAG;IAAC,UAAU;IAAE,UAAU;IAAE,WAAW;CAAC,AAAS,AAAC;AA0BnE,OAAO,MAAMC,MAAM,iBAAGV,KAAK,CAACW,IAAI,CAAC,SAASD,MAAM,CAAI,EAClDE,MAAM,CAAA,EACNC,KAAK,CAAA,EACLC,QAAQ,CAAA,EACRC,EAAE,CAAA,EACFC,QAAQ,CAAA,EACRC,SAAS,CAAA,EACTC,kBAAkB,CAAA,EACF,EAAE;IAClB,MAAMC,aAAa,GAAGhB,MAAM,CAAoBS,MAAM,CAAC,AAAC;IACxD,MAAMQ,UAAU,GAAGjB,MAAM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UAA8B,GAA9BA,MAAM,CAACE,SAAS,CAAc,cAA9BF,UAA8B,cAA9BA,UAA8B,GAAI,IAAI,AAAC;YAC3D,IAAIY,WAAW,EAAE;gBACfX,SAAS,CAACC,SAAS,EAAeU,WAAW,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAED,SAASR,YAAY,CAACF,SAAoB,EAA+B;IACvE,OAAO,AAACjC,WAAW,CAAuB4C,QAAQ,CAACX,SAAS,CAAC,CAAC;AAChE,CAAC;AAED,SAASK,YAAY,CAACL,SAAoB,EAA+B;IACvE,OAAO,AAAChC,WAAW,CAAuB2C,QAAQ,CAACX,SAAS,CAAC,CAAC;AAChE,CAAC"}
1
+ {"version":3,"sources":["../../src/EChart/EChart.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, { useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport { isEqual, debounce } from 'lodash-es';\nimport { EChartsTheme } from '../model';\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = React.memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n onEvents,\n _instance,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return () => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return () => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return () => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n // TODO: re-evaluate how this is triggered. It's technically working right\n // now because the sx prop is an object that gets re-created, but that also\n // means it runs unnecessarily some of the time and theoretically might\n // not run in some other cases. Maybe it should use a resize observer?\n useEffect(() => {\n // TODO: fix this debouncing. This likely isn't working as intended because\n // the debounced function is re-created every time this useEffect is called.\n const updateSize = debounce(\n () => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n },\n 200,\n {\n leading: true,\n }\n );\n updateSize();\n }, [sx]);\n\n return <Box ref={containerRef} sx={sx}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>) {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown) {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["React","useEffect","useLayoutEffect","useRef","init","Box","isEqual","debounce","mouseEvents","batchEvents","EChart","memo","option","theme","renderer","sx","onEvents","_instance","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","leading","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"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,SAAS,EAAEC,eAAe,EAAEC,MAAM,QAAQ,OAAO,CAAC;AAClE,SAAqCC,IAAI,QAAQ,cAAc,CAAC;AAChE,SAASC,GAAG,QAAwB,eAAe,CAAC;AACpD,SAASC,OAAO,EAAEC,QAAQ,QAAQ,WAAW,CAAC;AAwB9C,MAAMC,WAAW,GAAG;IAClB,OAAO;IACP,UAAU;IACV,WAAW;IACX,WAAW;IACX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K,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"}
1
+ {"version":3,"file":"Legend.d.ts","sourceRoot":"","sources":["../../src/Legend/Legend.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,uBAAuB,EAAiB,MAAM,UAAU,CAAC;AAK7F,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,eA0FzG"}
@@ -13,8 +13,10 @@
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { Box } from '@mui/material';
15
15
  import { produce } from 'immer';
16
+ import { getLegendMode } from '../model';
16
17
  import { ListLegend } from './ListLegend';
17
18
  import { CompactLegend } from './CompactLegend';
19
+ import { TableLegend } from './TableLegend';
18
20
  // When the number of items to display is above this number, it is likely to
19
21
  // cause performance issues in the browser. The legend will be displayed in a
20
22
  // format (list) that allows for virtualization to minimize the performance impact.
@@ -54,12 +56,37 @@ export function Legend({ width , height , options , data , selectedItems , onSel
54
56
  });
55
57
  onSelectedItemsChange(newSelected);
56
58
  };
59
+ const mode = getLegendMode(options.mode);
60
+ // The bottom legend is displayed as a list when the number of items is too
61
+ // large and requires virtualization. Otherwise, it is rendered more compactly.
62
+ // We do not need this check for the right-side legend because it is always
63
+ // a virtualized list.
64
+ const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
57
65
  const commonLegendProps = {
58
66
  height,
59
67
  items: data,
60
68
  selectedItems,
61
69
  onLegendItemClick
62
70
  };
71
+ let legendContent;
72
+ if (mode === 'Table') {
73
+ legendContent = /*#__PURE__*/ _jsx(TableLegend, {
74
+ ...commonLegendProps,
75
+ onSelectedItemsChange: onSelectedItemsChange,
76
+ width: width
77
+ });
78
+ } else if (options.position === 'Right' || needsVirtualization) {
79
+ legendContent = /*#__PURE__*/ _jsx(ListLegend, {
80
+ ...commonLegendProps,
81
+ width: width,
82
+ onLegendItemClick: onLegendItemClick
83
+ });
84
+ } else {
85
+ legendContent = /*#__PURE__*/ _jsx(CompactLegend, {
86
+ ...commonLegendProps,
87
+ onLegendItemClick: onLegendItemClick
88
+ });
89
+ }
63
90
  if (options.position === 'Right') {
64
91
  return /*#__PURE__*/ _jsx(Box, {
65
92
  sx: {
@@ -69,17 +96,10 @@ export function Legend({ width , height , options , data , selectedItems , onSel
69
96
  top: 0,
70
97
  right: 0
71
98
  },
72
- children: /*#__PURE__*/ _jsx(ListLegend, {
73
- ...commonLegendProps,
74
- width: width
75
- })
99
+ children: legendContent
76
100
  });
77
101
  }
78
- // The bottom legend is displayed as a list when the number of items is too
79
- // large and requires virtualization. Otherwise, it is rendered more compactly.
80
- // We do not need this check for the right-side legend because it is always
81
- // a virtualized list.
82
- const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;
102
+ // Position bottom
83
103
  return /*#__PURE__*/ _jsx(Box, {
84
104
  sx: {
85
105
  width: width,
@@ -87,12 +107,7 @@ export function Legend({ width , height , options , data , selectedItems , onSel
87
107
  position: 'absolute',
88
108
  bottom: 0
89
109
  },
90
- children: needsVirtualization ? /*#__PURE__*/ _jsx(ListLegend, {
91
- ...commonLegendProps,
92
- width: width
93
- }) : /*#__PURE__*/ _jsx(CompactLegend, {
94
- ...commonLegendProps
95
- })
110
+ children: legendContent
96
111
  });
97
112
  }
98
113
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Legend/Legend.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box } from '@mui/material';\nimport { 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,sEAA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xB,CAAC;YAED,uBAAuB;YACvB,OAAO;gBAAE,CAACN,QAAQ,CAAC,EAAE,IAAI;aAAE,CAAC;QAC9B,CAAC,CAAC,AAAC;QACHH,qBAAqB,CAACO,WAAW,CAAC,CAAC;IACrC,CAAC,AAAC;IAEF,MAAMG,iBAAiB,GAAyC;QAC9Dd,MAAM;QACNe,KAAK,EAAEb,IAAI;QACXC,aAAa;QACbE,iBAAiB;KAClB,AAAC;IAEF,IAAIJ,OAAO,CAACe,QAAQ,KAAK,OAAO,EAAE;QAChC,qBACE,KAACvB,GAAG;YACFwB,EAAE,EAAE;gBACFlB,KAAK,EAAEA,KAAK;gBACZC,MAAM,EAAEA,MAAM;gBACdgB,QAAQ,EAAE,UAAU;gBACpBE,GAAG,EAAE,CAAC;gBACNC,KAAK,EAAE,CAAC;aACT;sBAED,cAAA,KAACxB,UAAU;gBAAE,GAAGmB,iBAAiB;gBAAEf,KAAK,EAAEA,KAAK;cAAI;UAC/C,CACN;IACJ,CAAC;IAED,2EAA2E;IAC3E,+EAA+E;IAC/E,2EAA2E;IAC3E,sBAAsB;IACtB,MAAMqB,mBAAmB,GAAGlB,IAAI,CAACmB,MAAM,IAAIxB,yBAAyB,AAAC;IACrE,qBACE,KAACJ,GAAG;QACFwB,EAAE,EAAE;YACFlB,KAAK,EAAEA,KAAK;YACZC,MAAM,EAAEA,MAAM;YACdgB,QAAQ,EAAE,UAAU;YACpBM,MAAM,EAAE,CAAC;SACV;kBAEAF,mBAAmB,iBAClB,KAACzB,UAAU;YAAE,GAAGmB,iBAAiB;YAAEf,KAAK,EAAEA,KAAK;UAAI,iBAEnD,KAACH,aAAa;YAAE,GAAGkB,iBAAiB;UAAI,AACzC;MACG,CACN;AACJ,CAAC"}
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 { ReactNode } from 'react';\nimport { LegendOptions, LegendItem, SelectedLegendItemState, getLegendMode } from '../model';\nimport { ListLegend } from './ListLegend';\nimport { CompactLegend } from './CompactLegend';\nimport { TableLegend } from './TableLegend';\n\nexport interface LegendProps {\n width: number;\n height: number;\n data: LegendItem[];\n options: LegendOptions;\n\n /**\n * State of selected items in the legend.\n *\n * Selected legend item state is a controlled value that should be managed using a\n * combination of this prop and `onSelectedChange`.\n */\n selectedItems: SelectedLegendItemState;\n\n /**\n * Callback fired when the selected items in the legend changes.\n */\n onSelectedItemsChange: (newSelected: SelectedLegendItemState) => void;\n}\n\n// When the number of items to display is above this number, it is likely to\n// cause performance issues in the browser. The legend will be displayed in a\n// format (list) that allows for virtualization to minimize the performance impact.\n// Set this number based on testing, but it may need to be tuned a bit on the\n// future as people test this out on different machines.\nconst NEED_VIRTUALIZATION_LIMIT = 500;\n\nexport function Legend({ width, height, options, data, selectedItems, onSelectedItemsChange }: LegendProps) {\n const onLegendItemClick = (e: React.MouseEvent<HTMLElement, MouseEvent>, seriesId: string) => {\n const isModifiedClick = e.metaKey || e.shiftKey;\n\n const newSelected = produce(selectedItems, (draft) => {\n if (draft === 'ALL') {\n return {\n [seriesId]: true,\n };\n }\n\n const isSelected = !!draft[seriesId];\n\n // Clicks with modifier key can select multiple items.\n if (isModifiedClick) {\n if (isSelected) {\n // Modified click on already selected item. Remove that item.\n delete draft[seriesId];\n } else {\n // Modified click on not-selected item. Add it.\n draft[seriesId] = true;\n }\n return draft;\n }\n\n if (isSelected) {\n // Clicked item was already selected. Unselect it and return to\n // ALL state.\n return 'ALL' as const;\n }\n\n // Select clicked item.\n return { [seriesId]: true };\n });\n onSelectedItemsChange(newSelected);\n };\n\n const mode = getLegendMode(options.mode);\n\n // The bottom legend is displayed as a list when the number of items is too\n // large and requires virtualization. Otherwise, it is rendered more compactly.\n // We do not need this check for the right-side legend because it is always\n // a virtualized list.\n const needsVirtualization = data.length >= NEED_VIRTUALIZATION_LIMIT;\n\n const commonLegendProps = {\n height,\n items: data,\n selectedItems,\n onLegendItemClick,\n };\n\n let legendContent: ReactNode;\n if (mode === 'Table') {\n legendContent = <TableLegend {...commonLegendProps} onSelectedItemsChange={onSelectedItemsChange} width={width} />;\n } else if (options.position === 'Right' || needsVirtualization) {\n legendContent = <ListLegend {...commonLegendProps} width={width} onLegendItemClick={onLegendItemClick} />;\n } else {\n legendContent = <CompactLegend {...commonLegendProps} onLegendItemClick={onLegendItemClick} />;\n }\n\n if (options.position === 'Right') {\n return (\n <Box\n sx={{\n width: width,\n height: height,\n position: 'absolute',\n top: 0,\n right: 0,\n }}\n >\n {legendContent}\n </Box>\n );\n }\n\n // Position bottom\n return (\n <Box\n sx={{\n width: width,\n height: height,\n position: 'absolute',\n bottom: 0,\n }}\n >\n {legendContent}\n </Box>\n );\n}\n"],"names":["Box","produce","getLegendMode","ListLegend","CompactLegend","TableLegend","NEED_VIRTUALIZATION_LIMIT","Legend","width","height","options","data","selectedItems","onSelectedItemsChange","onLegendItemClick","e","seriesId","isModifiedClick","metaKey","shiftKey","newSelected","draft","isSelected","mode","needsVirtualization","length","commonLegendProps","items","legendContent","position","sx","top","right","bottom"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,GAAG,QAAQ,eAAe,CAAC;AACpC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAEhC,SAA6DC,aAAa,QAAQ,UAAU,CAAC;AA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AAK,EAAEA,KAAK;YACZC,MAAM,EAAEA,MAAM;YACdoB,QAAQ,EAAE,UAAU;YACpBI,MAAM,EAAE,CAAC;SACV;kBAEAL,aAAa;MACV,CACN;AACJ,CAAC"}
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"ListLegend.d.ts","sourceRoot":"","sources":["../../src/Legend/ListLegend.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAgC,MAAM,UAAU,CAAC;AAC7F,OAAO,EAAkB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,uBAAuB,CAAC;IACvC,iBAAiB,EAAE,mBAAmB,CAAC,SAAS,CAAC,CAAC;CACnD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,EAAE,eAAe,eA6BrG"}
@@ -11,7 +11,6 @@
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, Box } from '@mui/material';
15
14
  import { Virtuoso } from 'react-virtuoso';
16
15
  import { isLegendItemVisuallySelected } from '../model';
17
16
  import { ListLegendItem } from './ListLegendItem';
@@ -21,18 +20,6 @@ import { ListLegendItem } from './ListLegendItem';
21
20
  * large number of items because it is virtualized and easier to visually scan
22
21
  * large numbers of items when there is a single item per row.
23
22
  */ export function ListLegend({ items , height , width , selectedItems , onLegendItemClick }) {
24
- const theme = useTheme();
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
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
- });
36
23
  // show full labels on hover when there are many total series
37
24
  const truncateLabels = items.length > 5;
38
25
  return /*#__PURE__*/ _jsx(Virtuoso, {
@@ -50,21 +37,13 @@ import { ListLegendItem } from './ListLegendItem';
50
37
  sx: {
51
38
  // Having an explicit width is important for the ellipsizing to
52
39
  // work correctly. Subtract padding to simulate padding.
53
- width: width - LIST_PADDING,
40
+ width: width,
54
41
  wordBreak: 'break-word',
55
42
  overflow: 'hidden'
56
43
  }
57
44
  }, item.id);
58
45
  },
59
- role: "list",
60
- components: {
61
- Header: ()=>{
62
- return mockPadding;
63
- },
64
- Footer: ()=>{
65
- return mockPadding;
66
- }
67
- }
46
+ role: "list"
68
47
  });
69
48
  }
70
49
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Legend/ListLegend.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useTheme, 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;AAC1C,SAA8CC,4BAA4B,QAAQ,UAAU,CAAC;AAC7F,SAASC,cAAc,QAA6B,kBAAkB,CAAC;AAUvE;;;;;CAKC,GACD,OAAO,SAASC,UAAU,CAAC,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,KAAK,CAAA,EAAEC,aAAa,CAAA,EAAEC,iBAAiB,CAAA,EAAmB,EAAE;IACtG,MAAMC,KAAK,GAAGX,QAAQ,EAAE,AAAC;IACzB,uEAAuE;IACvE,8DAA8D;IAC9D,SAAS;IACT,uDAAuD;IACvD,MAAMY,YAAY,GAAGC,QAAQ,CAACF,KAAK,CAACG,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,AAAC;IACpD,MAAMC,WAAW,iBAAG,KAACd,GAAG;QAACe,EAAE,EAAE;YAAER,KAAK,EAAE,MAAM;YAAED,MAAM,EAAE,CAAC,EAAEK,YAAY,CAAC,EAAE,CAAC;SAAE;MAAQ,AAAC;IAEpF,6DAA6D;IAC7D,MAAMK,cAAc,GAAGX,KAAK,CAACY,MAAM,GAAG,CAAC,AAAC;IAExC,qBACE,KAAChB,QAAQ;QACPiB,KAAK,EAAE;YAAEZ,MAAM;YAAEC,KAAK;SAAE;QACxBY,IAAI,EAAEd,KAAK;QACXe,WAAW,EAAE,CAACC,KAAK,EAAEC,IAAI,GAAK;YAC5B,qBACE,KAACnB,cAAc;gBAEbmB,IAAI,EAAEA,IAAI;gBACVC,aAAa,EAAEP,cAAc;gBAC7BQ,kBAAkB,EAAEtB,4BAA4B,CAACoB,IAAI,EAAEd,aAAa,CAAC;gBACrEiB,OAAO,EAAEhB,iBAAiB;gBAC1BM,EAAE,EAAE;oBACF,+DAA+D;oBAC/D,wDAAwD;oBACxDR,KAAK,EAAEA,KAAK,GAAGI,YAAY;oBAC3Be,SAAS,EAAE,YAAY;oBACvBC,QAAQ,EAAE,QAAQ;iBACnB;eAXIL,IAAI,CAACM,EAAE,CAYZ,CACF;QACJ,CAAC;QACDC,IAAI,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
+ {"version":3,"sources":["../../src/Legend/ListLegend.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Virtuoso } from 'react-virtuoso';\nimport { LegendItem, SelectedLegendItemState, isLegendItemVisuallySelected } from '../model';\nimport { ListLegendItem, ListLegendItemProps } from './ListLegendItem';\n\nexport interface ListLegendProps {\n items: LegendItem[];\n height: number;\n width: number;\n selectedItems: SelectedLegendItemState;\n onLegendItemClick: ListLegendItemProps['onClick'];\n}\n\n/**\n * ListLegend is used when legend.position is 'right' since legend items are\n * stacked. It is also used for `bottom` positioned legends when there are a\n * large number of items because it is virtualized and easier to visually scan\n * large numbers of items when there is a single item per row.\n */\nexport function ListLegend({ items, height, width, selectedItems, onLegendItemClick }: ListLegendProps) {\n // show full labels on hover when there are many total series\n const truncateLabels = items.length > 5;\n\n return (\n <Virtuoso\n style={{ height, width }}\n data={items}\n itemContent={(index, item) => {\n return (\n <ListLegendItem\n key={item.id}\n item={item}\n truncateLabel={truncateLabels}\n isVisuallySelected={isLegendItemVisuallySelected(item, selectedItems)}\n onClick={onLegendItemClick}\n sx={{\n // Having an explicit width is important for the ellipsizing to\n // work correctly. Subtract padding to simulate padding.\n width: width,\n wordBreak: 'break-word',\n overflow: 'hidden',\n }}\n />\n );\n }}\n role=\"list\"\n />\n );\n}\n"],"names":["Virtuoso","isLegendItemVisuallySelected","ListLegendItem","ListLegend","items","height","width","selectedItems","onLegendItemClick","truncateLabels","length","style","data","itemContent","index","item","truncateLabel","isVisuallySelected","onClick","sx","wordBreak","overflow","id","role"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,gBAAgB,CAAC;AAC1C,SAA8CC,4BAA4B,QAAQ,UAAU,CAAC;AAC7F,SAASC,cAAc,QAA6B,kBAAkB,CAAC;AAUvE;;;;;CAKC,GACD,OAAO,SAASC,UAAU,CAAC,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,KAAK,CAAA,EAAEC,aAAa,CAAA,EAAEC,iBAAiB,CAAA,EAAmB,EAAE;IACtG,6DAA6D;IAC7D,MAAMC,cAAc,GAAGL,KAAK,CAACM,MAAM,GAAG,CAAC,AAAC;IAExC,qBACE,KAACV,QAAQ;QACPW,KAAK,EAAE;YAAEN,MAAM;YAAEC,KAAK;SAAE;QACxBM,IAAI,EAAER,KAAK;QACXS,WAAW,EAAE,CAACC,KAAK,EAAEC,IAAI,GAAK;YAC5B,qBACE,KAACb,cAAc;gBAEba,IAAI,EAAEA,IAAI;gBACVC,aAAa,EAAEP,cAAc;gBAC7BQ,kBAAkB,EAAEhB,4BAA4B,CAACc,IAAI,EAAER,aAAa,CAAC;gBACrEW,OAAO,EAAEV,iBAAiB;gBAC1BW,EAAE,EAAE;oBACF,+DAA+D;oBAC/D,wDAAwD;oBACxDb,KAAK,EAAEA,KAAK;oBACZc,SAAS,EAAE,YAAY;oBACvBC,QAAQ,EAAE,QAAQ;iBACnB;eAXIN,IAAI,CAACO,EAAE,CAYZ,CACF;QACJ,CAAC;QACDC,IAAI,EAAC,MAAM;MACX,CACF;AACJ,CAAC"}