@perses-dev/components 0.50.0 → 0.51.0-beta.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 (153) hide show
  1. package/dist/ColorPicker/ColorPicker.js +2 -2
  2. package/dist/ColorPicker/ColorPicker.js.map +1 -1
  3. package/dist/ContentWithLegend/model/content-with-legend-model.js +2 -3
  4. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  5. package/dist/DragAndDrop/DragButton.d.ts +2 -2
  6. package/dist/DragAndDrop/DragButton.d.ts.map +1 -1
  7. package/dist/DragAndDrop/DragButton.js +6 -4
  8. package/dist/DragAndDrop/DragButton.js.map +1 -1
  9. package/dist/Drawer/Drawer.js +1 -1
  10. package/dist/Drawer/Drawer.js.map +1 -1
  11. package/dist/EChart/EChart.js +3 -4
  12. package/dist/EChart/EChart.js.map +1 -1
  13. package/dist/GaugeChart/GaugeChart.js +2 -5
  14. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  15. package/dist/InfoTooltip/InfoTooltip.js +5 -4
  16. package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
  17. package/dist/Legend/ListLegendItem.js +3 -4
  18. package/dist/Legend/ListLegendItem.js.map +1 -1
  19. package/dist/LineChart/LineChart.js +4 -8
  20. package/dist/LineChart/LineChart.js.map +1 -1
  21. package/dist/LinksEditor/LinksEditor.js +9 -18
  22. package/dist/LinksEditor/LinksEditor.js.map +1 -1
  23. package/dist/Overlay/Overlay.js +1 -1
  24. package/dist/Overlay/Overlay.js.map +1 -1
  25. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +1 -2
  26. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -1
  27. package/dist/StatChart/StatChart.d.ts +4 -4
  28. package/dist/StatChart/StatChart.d.ts.map +1 -1
  29. package/dist/StatChart/StatChart.js +9 -15
  30. package/dist/StatChart/StatChart.js.map +1 -1
  31. package/dist/StatChart/calculateFontSize.js +2 -4
  32. package/dist/StatChart/calculateFontSize.js.map +1 -1
  33. package/dist/StatChart/utils/formatStatChartValue.d.ts +3 -0
  34. package/dist/StatChart/utils/formatStatChartValue.d.ts.map +1 -0
  35. package/dist/StatChart/utils/formatStatChartValue.js +26 -0
  36. package/dist/StatChart/utils/formatStatChartValue.js.map +1 -0
  37. package/dist/StatusHistoryChart/StatusHistoryChart.d.ts +16 -3
  38. package/dist/StatusHistoryChart/StatusHistoryChart.d.ts.map +1 -1
  39. package/dist/StatusHistoryChart/StatusHistoryChart.js +9 -26
  40. package/dist/StatusHistoryChart/StatusHistoryChart.js.map +1 -1
  41. package/dist/StatusHistoryChart/StatusHistoryTooltip.d.ts +2 -1
  42. package/dist/StatusHistoryChart/StatusHistoryTooltip.d.ts.map +1 -1
  43. package/dist/StatusHistoryChart/StatusHistoryTooltip.js +3 -3
  44. package/dist/StatusHistoryChart/StatusHistoryTooltip.js.map +1 -1
  45. package/dist/StatusHistoryChart/utils/get-color.d.ts +1 -1
  46. package/dist/StatusHistoryChart/utils/get-color.d.ts.map +1 -1
  47. package/dist/StatusHistoryChart/utils/get-color.js +5 -5
  48. package/dist/StatusHistoryChart/utils/get-color.js.map +1 -1
  49. package/dist/Table/Table.js +5 -5
  50. package/dist/Table/Table.js.map +1 -1
  51. package/dist/Table/TableCell.js +5 -6
  52. package/dist/Table/TableCell.js.map +1 -1
  53. package/dist/Table/VirtualizedTable.js +11 -14
  54. package/dist/Table/VirtualizedTable.js.map +1 -1
  55. package/dist/Table/hooks/useTableKeyboardNav.js +1 -1
  56. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -1
  57. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +7 -13
  58. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -1
  59. package/dist/Table/model/table-model.js +1 -1
  60. package/dist/Table/model/table-model.js.map +1 -1
  61. package/dist/ThresholdsEditor/ThresholdsEditor.js +15 -23
  62. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  63. package/dist/TimeChart/TimeChart.js +3 -6
  64. package/dist/TimeChart/TimeChart.js.map +1 -1
  65. package/dist/TimeSeriesTooltip/LineChartTooltip.js +6 -11
  66. package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +1 -1
  67. package/dist/TimeSeriesTooltip/SeriesInfo.js +1 -2
  68. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  69. package/dist/TimeSeriesTooltip/TimeChartTooltip.js +2 -3
  70. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  71. package/dist/TimeSeriesTooltip/TooltipHeader.js +4 -10
  72. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -1
  73. package/dist/TimeSeriesTooltip/nearby-series.js +13 -23
  74. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  75. package/dist/TimeSeriesTooltip/utils.js +2 -4
  76. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  77. package/dist/TransformsEditor/TransformEditor.js +4 -7
  78. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  79. package/dist/TransformsEditor/TransformEditorContainer.js +3 -5
  80. package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
  81. package/dist/TransformsEditor/TransformsEditor.js +3 -6
  82. package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
  83. package/dist/ValueMappingEditor/ValueMappingEditor.d.ts +10 -0
  84. package/dist/ValueMappingEditor/ValueMappingEditor.d.ts.map +1 -0
  85. package/dist/ValueMappingEditor/ValueMappingEditor.js +374 -0
  86. package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -0
  87. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts +8 -0
  88. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts.map +1 -0
  89. package/dist/ValueMappingEditor/ValueMappingsEditor.js +118 -0
  90. package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -0
  91. package/dist/ValueMappingEditor/index.d.ts +2 -0
  92. package/dist/ValueMappingEditor/index.d.ts.map +1 -0
  93. package/dist/ValueMappingEditor/index.js +15 -0
  94. package/dist/ValueMappingEditor/index.js.map +1 -0
  95. package/dist/cjs/ColorPicker/ColorPicker.js +2 -2
  96. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +2 -3
  97. package/dist/cjs/DragAndDrop/DragButton.js +5 -3
  98. package/dist/cjs/Drawer/Drawer.js +1 -1
  99. package/dist/cjs/EChart/EChart.js +3 -4
  100. package/dist/cjs/GaugeChart/GaugeChart.js +2 -5
  101. package/dist/cjs/InfoTooltip/InfoTooltip.js +5 -4
  102. package/dist/cjs/Legend/ListLegendItem.js +3 -4
  103. package/dist/cjs/LineChart/LineChart.js +4 -8
  104. package/dist/cjs/LinksEditor/LinksEditor.js +9 -18
  105. package/dist/cjs/Overlay/Overlay.js +1 -1
  106. package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +1 -2
  107. package/dist/cjs/StatChart/StatChart.js +11 -17
  108. package/dist/cjs/StatChart/calculateFontSize.js +2 -4
  109. package/dist/cjs/StatChart/utils/formatStatChartValue.js +34 -0
  110. package/dist/cjs/StatusHistoryChart/StatusHistoryChart.js +11 -28
  111. package/dist/cjs/StatusHistoryChart/StatusHistoryTooltip.js +3 -3
  112. package/dist/cjs/StatusHistoryChart/utils/get-color.js +7 -7
  113. package/dist/cjs/Table/Table.js +5 -5
  114. package/dist/cjs/Table/TableCell.js +5 -6
  115. package/dist/cjs/Table/VirtualizedTable.js +11 -14
  116. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +1 -1
  117. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +7 -13
  118. package/dist/cjs/Table/model/table-model.js +1 -1
  119. package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +15 -23
  120. package/dist/cjs/TimeChart/TimeChart.js +3 -6
  121. package/dist/cjs/TimeSeriesTooltip/LineChartTooltip.js +6 -11
  122. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +1 -2
  123. package/dist/cjs/TimeSeriesTooltip/TimeChartTooltip.js +2 -3
  124. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +4 -10
  125. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +13 -23
  126. package/dist/cjs/TimeSeriesTooltip/utils.js +2 -4
  127. package/dist/cjs/TransformsEditor/TransformEditor.js +4 -7
  128. package/dist/cjs/TransformsEditor/TransformEditorContainer.js +3 -5
  129. package/dist/cjs/TransformsEditor/TransformsEditor.js +3 -6
  130. package/dist/cjs/ValueMappingEditor/ValueMappingEditor.js +387 -0
  131. package/dist/cjs/ValueMappingEditor/ValueMappingsEditor.js +131 -0
  132. package/dist/cjs/ValueMappingEditor/index.js +30 -0
  133. package/dist/cjs/context/TimeZoneProvider.js +1 -1
  134. package/dist/cjs/controls/TextField.js +1 -1
  135. package/dist/cjs/index.js +1 -0
  136. package/dist/cjs/utils/chart-actions.js +1 -2
  137. package/dist/cjs/utils/format.js +1 -1
  138. package/dist/cjs/utils/theme-gen.js +5 -7
  139. package/dist/context/TimeZoneProvider.js +1 -1
  140. package/dist/context/TimeZoneProvider.js.map +1 -1
  141. package/dist/controls/TextField.js +1 -1
  142. package/dist/controls/TextField.js.map +1 -1
  143. package/dist/index.d.ts +1 -0
  144. package/dist/index.d.ts.map +1 -1
  145. package/dist/index.js +1 -0
  146. package/dist/index.js.map +1 -1
  147. package/dist/utils/chart-actions.js +1 -2
  148. package/dist/utils/chart-actions.js.map +1 -1
  149. package/dist/utils/format.js +1 -1
  150. package/dist/utils/format.js.map +1 -1
  151. package/dist/utils/theme-gen.js +5 -7
  152. package/dist/utils/theme-gen.js.map +1 -1
  153. package/package.json +3 -3
@@ -21,7 +21,7 @@ export const ColorPicker = ({ color, onChange, onClear, palette })=>{
21
21
  const [value, setValue] = useState(color);
22
22
  const handleColorChange = (color)=>{
23
23
  setValue(color);
24
- onChange === null || onChange === void 0 ? void 0 : onChange(color);
24
+ onChange?.(color);
25
25
  };
26
26
  // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved
27
27
  const handleInputChange = (e)=>{
@@ -29,7 +29,7 @@ export const ColorPicker = ({ color, onChange, onClear, palette })=>{
29
29
  setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format
30
30
  // only set color if input value is a valid hex color
31
31
  if (isValidHex(e.target.value)) {
32
- onChange === null || onChange === void 0 ? void 0 : onChange(e.target.value);
32
+ onChange?.(e.target.value);
33
33
  }
34
34
  };
35
35
  return /*#__PURE__*/ _jsxs(Stack, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ColorPicker/ColorPicker.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 { IconButton, Stack, TextField } from '@mui/material';\nimport { ChangeEvent, ReactElement, useState } from 'react';\nimport { HexColorPicker } from 'react-colorful';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport DeleteIcon from 'mdi-material-ui/Delete';\n\ninterface ColorPickerProps {\n color: string;\n onChange?: (color: string) => void;\n onClear?: () => void;\n /**\n * Preset color palette\n */\n palette?: string[];\n}\n\nexport const ColorPicker = ({ color, onChange, onClear, palette }: ColorPickerProps): ReactElement => {\n // value is the visible value for the controlled text input\n const [value, setValue] = useState(color);\n\n const handleColorChange = (color: string): void => {\n setValue(color);\n onChange?.(color);\n };\n\n // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>): void => {\n const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, '').substring(0, 8);\n setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format\n // only set color if input value is a valid hex color\n if (isValidHex(e.target.value)) {\n onChange?.(e.target.value);\n }\n };\n\n return (\n <Stack spacing={1}>\n <HexColorPicker color={color} onChange={handleColorChange} style={{ width: '100%' }} />\n <Stack direction=\"row\" flexWrap=\"wrap\" justifyContent=\"space-evenly\" width=\"200px\">\n {palette &&\n palette.map((color, i) => (\n <IconButton\n key={i}\n size=\"small\"\n aria-label={`change color to ${color}`}\n sx={{ color }}\n onClick={() => handleColorChange(color)}\n >\n <CircleIcon />\n </IconButton>\n ))}\n </Stack>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n <TextField\n inputProps={{ 'aria-label': 'enter hex color' }}\n fullWidth\n value={value}\n onChange={handleInputChange}\n />\n {onClear && (\n <IconButton onClick={onClear}>\n <DeleteIcon />\n </IconButton>\n )}\n </Stack>\n </Stack>\n );\n};\n\nconst isValidHex = (value: string, alpha?: boolean): boolean => {\n const matcher = /^#?([0-9A-F]{3,8})$/i;\n const match = matcher.exec(value);\n const length = match && match[1] ? match[1].length : 0;\n return (\n length === 3 || // '#rgb' format\n length === 6 || // '#rrggbb' format\n (!!alpha && length === 4) || // '#rgba' format\n (!!alpha && length === 8) // '#rrggbbaa' format\n );\n};\n"],"names":["IconButton","Stack","TextField","useState","HexColorPicker","CircleIcon","DeleteIcon","ColorPicker","color","onChange","onClear","palette","value","setValue","handleColorChange","handleInputChange","e","inputValue","target","replace","substring","isValidHex","spacing","style","width","direction","flexWrap","justifyContent","map","i","size","aria-label","sx","onClick","gap","alignItems","inputProps","fullWidth","alpha","matcher","match","exec","length"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC7D,SAAoCC,QAAQ,QAAQ,QAA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AAUM;;oBAEXL,yBACC,KAACV;wBAAWiC,SAASvB;kCACnB,cAAA,KAACJ;;;;;;AAMb,EAAE;AAEF,MAAMe,aAAa,CAACT,OAAe0B;IACjC,MAAMC,UAAU;IAChB,MAAMC,QAAQD,QAAQE,IAAI,CAAC7B;IAC3B,MAAM8B,SAASF,SAASA,KAAK,CAAC,EAAE,GAAGA,KAAK,CAAC,EAAE,CAACE,MAAM,GAAG;IACrD,OACEA,WAAW,KAAK,gBAAgB;IAChCA,WAAW,KAAK,mBAAmB;IAClC,CAAC,CAACJ,SAASI,WAAW,KAAM,iBAAiB;IAC7C,CAAC,CAACJ,SAASI,WAAW,EAAG,qBAAqB;;AAEnD"}
1
+ {"version":3,"sources":["../../src/ColorPicker/ColorPicker.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 { IconButton, Stack, TextField } from '@mui/material';\nimport { ChangeEvent, ReactElement, useState } from 'react';\nimport { HexColorPicker } from 'react-colorful';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport DeleteIcon from 'mdi-material-ui/Delete';\n\ninterface ColorPickerProps {\n color: string;\n onChange?: (color: string) => void;\n onClear?: () => void;\n /**\n * Preset color palette\n */\n palette?: string[];\n}\n\nexport const ColorPicker = ({ color, onChange, onClear, palette }: ColorPickerProps): ReactElement => {\n // value is the visible value for the controlled text input\n const [value, setValue] = useState(color);\n\n const handleColorChange = (color: string): void => {\n setValue(color);\n onChange?.(color);\n };\n\n // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved\n const handleInputChange = (e: ChangeEvent<HTMLInputElement>): void => {\n const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, '').substring(0, 8);\n setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format\n // only set color if input value is a valid hex color\n if (isValidHex(e.target.value)) {\n onChange?.(e.target.value);\n }\n };\n\n return (\n <Stack spacing={1}>\n <HexColorPicker color={color} onChange={handleColorChange} style={{ width: '100%' }} />\n <Stack direction=\"row\" flexWrap=\"wrap\" justifyContent=\"space-evenly\" width=\"200px\">\n {palette &&\n palette.map((color, i) => (\n <IconButton\n key={i}\n size=\"small\"\n aria-label={`change color to ${color}`}\n sx={{ color }}\n onClick={() => handleColorChange(color)}\n >\n <CircleIcon />\n </IconButton>\n ))}\n </Stack>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n <TextField\n inputProps={{ 'aria-label': 'enter hex color' }}\n fullWidth\n value={value}\n onChange={handleInputChange}\n />\n {onClear && (\n <IconButton onClick={onClear}>\n <DeleteIcon />\n </IconButton>\n )}\n </Stack>\n </Stack>\n );\n};\n\nconst isValidHex = (value: string, alpha?: boolean): boolean => {\n const matcher = /^#?([0-9A-F]{3,8})$/i;\n const match = matcher.exec(value);\n const length = match && match[1] ? match[1].length : 0;\n return (\n length === 3 || // '#rgb' format\n length === 6 || // '#rrggbb' format\n (!!alpha && length === 4) || // '#rgba' format\n (!!alpha && length === 8) // '#rrggbbaa' format\n );\n};\n"],"names":["IconButton","Stack","TextField","useState","HexColorPicker","CircleIcon","DeleteIcon","ColorPicker","color","onChange","onClear","palette","value","setValue","handleColorChange","handleInputChange","e","inputValue","target","replace","substring","isValidHex","spacing","style","width","direction","flexWrap","justifyContent","map","i","size","aria-label","sx","onClick","gap","alignItems","inputProps","fullWidth","alpha","matcher","match","exec","length"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AAC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BACCkC,YAAY;4BAAE,cAAc;wBAAkB;wBAC9CC,SAAS;wBACTzB,OAAOA;wBACPH,UAAUM;;oBAEXL,yBACC,KAACV;wBAAWiC,SAASvB;kCACnB,cAAA,KAACJ;;;;;;AAMb,EAAE;AAEF,MAAMe,aAAa,CAACT,OAAe0B;IACjC,MAAMC,UAAU;IAChB,MAAMC,QAAQD,QAAQE,IAAI,CAAC7B;IAC3B,MAAM8B,SAASF,SAASA,KAAK,CAAC,EAAE,GAAGA,KAAK,CAAC,EAAE,CAACE,MAAM,GAAG;IACrD,OACEA,WAAW,KAAK,gBAAgB;IAChCA,WAAW,KAAK,mBAAmB;IAClC,CAAC,CAACJ,SAASI,WAAW,KAAM,iBAAiB;IAC7C,CAAC,CAACJ,SAASI,WAAW,EAAG,qBAAqB;;AAEnD"}
@@ -32,7 +32,7 @@ const LEGEND_HEIGHT_LG = 100;
32
32
  /**
33
33
  * Returns information for laying out content alongside a legend.
34
34
  */ export function getContentWithLegendLayout({ width, height, legendProps, legendSize, minChildrenHeight, minChildrenWidth, spacing, theme }) {
35
- const legendOptions = legendProps === null || legendProps === void 0 ? void 0 : legendProps.options;
35
+ const legendOptions = legendProps?.options;
36
36
  const hasLegend = !!legendOptions;
37
37
  const noLegendLayout = {
38
38
  legend: {
@@ -68,10 +68,9 @@ const LEGEND_HEIGHT_LG = 100;
68
68
  legendHeight = LEGEND_HEIGHT_LG;
69
69
  }
70
70
  } else {
71
- var _legendProps_tableProps;
72
71
  // Table mode
73
72
  const tableLayout = getTableCellLayout(theme, 'compact');
74
- const tableColumns = (legendProps === null || legendProps === void 0 ? void 0 : (_legendProps_tableProps = legendProps.tableProps) === null || _legendProps_tableProps === void 0 ? void 0 : _legendProps_tableProps.columns) || [];
73
+ const tableColumns = legendProps?.tableProps?.columns || [];
75
74
  const columnsWidth = tableColumns.reduce((total, col)=>{
76
75
  if (typeof col.width === 'number') {
77
76
  total += col.width;
@@ -1 +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 { LegendPositions, getLegendMode, LegendSize } from '@perses-dev/core';\nimport { LegendProps } from '../../Legend';\nimport { getTableCellLayout } from '../../Table';\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 /**\n * Size used for the legend.\n *\n * @default 'medium'\n */\n legendSize?: LegendSize;\n\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 /**\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 legendProps?: ContentWithLegendProps['legendProps'];\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<LegendSize, Record<LegendPositions, number>>;\n\nexport const TABLE_LEGEND_SIZE: LegendSizeConfig = {\n medium: {\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 small: {\n // 3 rows plus header. Value to be multiplied by row height in pixels.\n bottom: 4,\n\n // Pixel value\n right: 150,\n },\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 legendProps,\n legendSize,\n minChildrenHeight,\n minChildrenWidth,\n spacing,\n theme,\n}: ContentWithLegendLayoutOpts): ContentWithLegendLayout {\n const legendOptions = legendProps?.options;\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 const tableColumns = legendProps?.tableProps?.columns || [];\n const columnsWidth = tableColumns.reduce((total, col) => {\n if (typeof col.width === 'number') {\n total += col.width;\n }\n return total;\n }, 0);\n\n legendWidth = position === 'right' ? TABLE_LEGEND_SIZE[legendSize]['right'] + columnsWidth : width;\n\n // Use the smaller of the size-based row count or the number of legend items + 1 for the header.\n const rowsToShow = Math.min(TABLE_LEGEND_SIZE[legendSize]['bottom'], legendProps.data.length + 1);\n legendHeight = position === 'bottom' ? rowsToShow * 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":["getLegendMode","getTableCellLayout","TABLE_LEGEND_SIZE","medium","bottom","right","small","PANEL_HEIGHT_LG_BREAKPOINT","LEGEND_HEIGHT_SM","LEGEND_HEIGHT_LG","getContentWithLegendLayout","width","height","legendProps","legendSize","minChildrenHeight","minChildrenWidth","spacing","theme","legendOptions","options","hasLegend","noLegendLayout","legend","show","content","margin","position","mode","legendWidth","legendHeight","tableLayout","tableColumns","tableProps","columns","columnsWidth","reduce","total","col","rowsToShow","Math","min","data","length","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;AAGjC,SAA0BA,aAAa,QAAoB,mBAAmB;AAE9E,SAASC,kBAAkB,QAAQ,cAAc;AA4EjD,OAAO,MAAMC,oBAAsC;IACjDC,QAAQ;QACN,sEAAsE;QACtEC,QAAQ;QAER,cAAc;QACdC,OAAO;IACT;IACAC,OAAO;QACL,sEAAsE;QACtEF,Q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cAAcF,aAAa,UAAUzB,iBAAiB,CAACY,WAAW,CAAC,QAAQ,GAAGqB,eAAexB;QAE7F,gGAAgG;QAChG,MAAM4B,aAAaC,KAAKC,GAAG,CAACvC,iBAAiB,CAACY,WAAW,CAAC,SAAS,EAAED,YAAY6B,IAAI,CAACC,MAAM,GAAG;QAC/Fb,eAAeH,aAAa,WAAWY,aAAaR,YAAYnB,MAAM,GAAGA;IAC3E;IAEA,MAAMgC,eAAejB,aAAa,UAAUhB,QAAQkB,cAAcZ,UAAUN;IAC5E,MAAMkC,gBAAgBlB,aAAa,WAAWf,SAASkB,eAAeb,UAAUL;IAEhF,IACE,AAACe,aAAa,WAAWiB,eAAe5B,oBACvCW,aAAa,YAAYkB,gBAAgB9B,mBAC1C;QACA,8CAA8C;QAC9C,OAAOO;IACT;IAEA,OAAO;QACLC,QAAQ;YACNZ,OAAOkB;YACPjB,QAAQkB;YACRN,MAAM;QACR;QACAC,SAAS;YACPd,OAAOiC;YACPhC,QAAQiC;QACV;QACAnB,QAAQ;YACNrB,OAAOsB,aAAa,UAAUV,UAAU;YACxCb,QAAQuB,aAAa,WAAWV,UAAU;QAC5C;IACF;AACF"}
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 { LegendPositions, getLegendMode, LegendSize } from '@perses-dev/core';\nimport { LegendProps } from '../../Legend';\nimport { getTableCellLayout } from '../../Table';\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 /**\n * Size used for the legend.\n *\n * @default 'medium'\n */\n legendSize?: LegendSize;\n\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 /**\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 legendProps?: ContentWithLegendProps['legendProps'];\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<LegendSize, Record<LegendPositions, number>>;\n\nexport const TABLE_LEGEND_SIZE: LegendSizeConfig = {\n medium: {\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 small: {\n // 3 rows plus header. Value to be multiplied by row height in pixels.\n bottom: 4,\n\n // Pixel value\n right: 150,\n },\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 legendProps,\n legendSize,\n minChildrenHeight,\n minChildrenWidth,\n spacing,\n theme,\n}: ContentWithLegendLayoutOpts): ContentWithLegendLayout {\n const legendOptions = legendProps?.options;\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 const tableColumns = legendProps?.tableProps?.columns || [];\n const columnsWidth = tableColumns.reduce((total, col) => {\n if (typeof col.width === 'number') {\n total += col.width;\n }\n return total;\n }, 0);\n\n legendWidth = position === 'right' ? TABLE_LEGEND_SIZE[legendSize]['right'] + columnsWidth : width;\n\n // Use the smaller of the size-based row count or the number of legend items + 1 for the header.\n const rowsToShow = Math.min(TABLE_LEGEND_SIZE[legendSize]['bottom'], legendProps.data.length + 1);\n legendHeight = position === 'bottom' ? rowsToShow * 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":["getLegendMode","getTableCellLayout","TABLE_LEGEND_SIZE","medium","bottom","right","small","PANEL_HEIGHT_LG_BREAKPOINT","LEGEND_HEIGHT_SM","LEGEND_HEIGHT_LG","getContentWithLegendLayout","width","height","legendProps","legendSize","minChildrenHeight","minChildrenWidth","spacing","theme","legendOptions","options","hasLegend","noLegendLayout","legend","show","content","margin","position","mode","legendWidth","legendHeight","tableLayout","tableColumns","tableProps","columns","columnsWidth","reduce","total","col","rowsToShow","Math","min","data","length","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;AAGjC,SAA0BA,aAAa,QAAoB,mBAAmB;AAE9E,SAASC,kBAAkB,QAAQ,cAAc;AA4EjD,OAAO,MAAMC,oBAAsC;IACjDC,QAAQ;QACN,sEAAsE;QACtEC,QAAQ;QAER,cAAc;QACdC,OAAO;IACT;IACAC,OAAO;QACL,sEAAsE;QACtEF,QAAQ;QAER,cAAc;QACdC,OAAO;IACT;AACF,EAAE;AAEF,MAAME,6BAA6B;AACnC,MAAMC,mBAAmB;AACzB,MAAMC,mBAAmB;AAEzB;;CAEC,GACD,OAAO,SAASC,2BAA2B,EACzCC,KAAK,EACLC,MAAM,EACNC,WAAW,EACXC,UAAU,EACVC,iBAAiB,EACjBC,gBAAgB,EAChBC,OAAO,EACPC,KAAK,EACuB;IAC5B,MAAMC,gBAAgBN,aAAaO;IACnC,MAAMC,YAAY,CAAC,CAACF;IAEpB,MAAMG,iBAA0C;QAC9CC,QAAQ;YACNC,MAAM;YACNb,OAAO;YACPC,QAAQ;QACV;QACAa,SAAS;YACPd;YACAC;QACF;QACAc,QAAQ;YACNrB,OAAO;YACPD,QAAQ;QACV;I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ACAC,SAAS;YACPd,OAAOiC;YACPhC,QAAQiC;QACV;QACAnB,QAAQ;YACNrB,OAAOsB,aAAa,UAAUV,UAAU;YACxCb,QAAQuB,aAAa,WAAWV,UAAU;QAC5C;IACF;AACF"}
@@ -1,5 +1,5 @@
1
+ /// <reference types="react" />
1
2
  import { IconButtonProps, MenuProps } from '@mui/material';
2
- import { ReactElement } from 'react';
3
3
  export declare function handleMoveUp<T>(element: T, elements: T[]): T[];
4
4
  export declare function handleMoveDown<T>(element: T, elements: T[]): T[];
5
5
  export interface DragButtonProps extends IconButtonProps {
@@ -9,5 +9,5 @@ export interface DragButtonProps extends IconButtonProps {
9
9
  onMoveRight?: () => void;
10
10
  menuSx?: MenuProps['sx'];
11
11
  }
12
- export declare function DragButton({ onMoveUp, onMoveDown, onMoveLeft, onMoveRight, menuSx }: DragButtonProps): ReactElement;
12
+ export declare const DragButton: import("react").ForwardRefExoticComponent<Omit<DragButtonProps, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
13
13
  //# sourceMappingURL=DragButton.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DragButton.d.ts","sourceRoot":"","sources":["../../src/DragAndDrop/DragButton.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAc,eAAe,EAAkB,SAAS,EAAE,MAAM,eAAe,CAAC;AAEvF,OAAO,EAAwB,YAAY,EAAE,MAAM,OAAO,CAAC;AAE3D,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAU9D;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAUhE;AAED,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,eAAe,GAAG,YAAY,CAsCnH"}
1
+ {"version":3,"file":"DragButton.d.ts","sourceRoot":"","sources":["../../src/DragAndDrop/DragButton.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAc,eAAe,EAAkB,SAAS,EAAE,MAAM,eAAe,CAAC;AAIvF,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAU9D;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAUhE;AAED,MAAM,WAAW,eAAgB,SAAQ,eAAe;IACtD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,MAAM,CAAC,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED,eAAO,MAAM,UAAU,4HAiDrB,CAAC"}
@@ -13,7 +13,7 @@
13
13
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
14
  import { IconButton, Menu, MenuItem } from '@mui/material';
15
15
  import DragIcon from 'mdi-material-ui/Drag';
16
- import { useState } from 'react';
16
+ import { useState, forwardRef } from 'react';
17
17
  export function handleMoveUp(element, elements) {
18
18
  const index = elements.indexOf(element);
19
19
  if (index === 0) {
@@ -38,7 +38,7 @@ export function handleMoveDown(element, elements) {
38
38
  newElements.splice(index + 1, 0, element);
39
39
  return newElements;
40
40
  }
41
- export function DragButton({ onMoveUp, onMoveDown, onMoveLeft, onMoveRight, menuSx }) {
41
+ export const DragButton = /*#__PURE__*/ forwardRef(function DragButton({ onMoveUp, onMoveDown, onMoveLeft, onMoveRight, menuSx, ...otherProps }, ref) {
42
42
  const [anchorEl, setAnchorEl] = useState(null);
43
43
  const open = Boolean(anchorEl);
44
44
  function handleClick(event) {
@@ -46,11 +46,13 @@ export function DragButton({ onMoveUp, onMoveDown, onMoveLeft, onMoveRight, menu
46
46
  }
47
47
  function handleMove(callback) {
48
48
  setAnchorEl(null);
49
- callback === null || callback === void 0 ? void 0 : callback();
49
+ callback?.();
50
50
  }
51
51
  return /*#__PURE__*/ _jsxs(_Fragment, {
52
52
  children: [
53
53
  /*#__PURE__*/ _jsx(IconButton, {
54
+ ...otherProps,
55
+ ref: ref,
54
56
  "aria-label": "move",
55
57
  "aria-haspopup": true,
56
58
  "aria-expanded": open,
@@ -92,6 +94,6 @@ export function DragButton({ onMoveUp, onMoveDown, onMoveLeft, onMoveRight, menu
92
94
  })
93
95
  ]
94
96
  });
95
- }
97
+ });
96
98
 
97
99
  //# sourceMappingURL=DragButton.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/DragAndDrop/DragButton.tsx"],"sourcesContent":["// Copyright 2024 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 { IconButton, IconButtonProps, Menu, MenuItem, MenuProps } from '@mui/material';\nimport DragIcon from 'mdi-material-ui/Drag';\nimport { useState, MouseEvent, ReactElement } from 'react';\n\nexport function handleMoveUp<T>(element: T, elements: T[]): T[] {\n const index = elements.indexOf(element);\n if (index === 0) {\n return elements;\n }\n\n const newElements = [...elements];\n newElements.splice(index, 1);\n newElements.splice(index - 1, 0, element);\n return newElements;\n}\n\nexport function handleMoveDown<T>(element: T, elements: T[]): T[] {\n const index = elements.indexOf(element);\n if (index === elements.length - 1) {\n return elements;\n }\n\n const newElements = [...elements];\n newElements.splice(index, 1);\n newElements.splice(index + 1, 0, element);\n return newElements;\n}\n\nexport interface DragButtonProps extends IconButtonProps {\n onMoveUp?: () => void;\n onMoveDown?: () => void;\n onMoveLeft?: () => void;\n onMoveRight?: () => void;\n menuSx?: MenuProps['sx'];\n}\n\nexport function DragButton({ onMoveUp, onMoveDown, onMoveLeft, onMoveRight, menuSx }: DragButtonProps): ReactElement {\n const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);\n const open = Boolean(anchorEl);\n\n function handleClick(event: MouseEvent<HTMLElement>): void {\n setAnchorEl(event.currentTarget);\n }\n\n function handleMove(callback?: () => void): void {\n setAnchorEl(null);\n callback?.();\n }\n\n return (\n <>\n <IconButton aria-label=\"move\" aria-haspopup={true} aria-expanded={open} size=\"small\" onClick={handleClick}>\n <DragIcon />\n </IconButton>\n {(onMoveUp || onMoveDown || onMoveLeft || onMoveRight) && (\n <Menu\n id=\"drag-button-menu\"\n MenuListProps={{\n 'aria-labelledby': 'drag-button-menu',\n }}\n anchorEl={anchorEl}\n open={open}\n onClose={() => handleMove(undefined)}\n sx={menuSx}\n >\n {onMoveUp && <MenuItem onClick={() => handleMove(onMoveUp)}>Move Up</MenuItem>}\n {onMoveDown && <MenuItem onClick={() => handleMove(onMoveDown)}>Move Down</MenuItem>}\n {onMoveLeft && <MenuItem onClick={() => handleMove(onMoveLeft)}>Move Left</MenuItem>}\n {onMoveRight && <MenuItem onClick={() => handleMove(onMoveRight)}>Move Right</MenuItem>}\n {onMoveRight && <MenuItem onClick={() => handleMove(onMoveRight)}>Move Right</MenuItem>}\n </Menu>\n )}\n </>\n );\n}\n"],"names":["IconButton","Menu","MenuItem","DragIcon","useState","handleMoveUp","element","elements","index","indexOf","newElements","splice","handleMoveDown","length","DragButton","onMoveUp","onMoveDown","onMoveLeft","onMoveRight","menuSx","anchorEl","setAnchorEl","open","Boolean","handleClick","event","currentTarget","handleMove","callback","aria-label","aria-haspopup","aria-expanded","size","onClick","id","MenuListProps","onClose","undefined","sx"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,EAAmBC,IAAI,EAAEC,QAAQ,QAAmB,gBAAgB;AACvF,OAAOC,cAAc,uBAAuB;AAC5C,SAASC,QAAQ,QAAkC,QAAQ;AAE3D,OAAO,SAASC,aAAgBC,OAAU,EAAEC,QAAa;IACvD,MAAMC,QAAQD,SAASE,OAAO,CAACH;IAC/B,IAAIE,UAAU,GAAG;QACf,OAAOD;IACT;IAEA,MAAMG,cAAc;WAAIH;KAAS;IACjCG,YAAYC,MAAM,CAACH,OAAO;IAC1BE,YAAYC,MAAM,CAACH,QAAQ,GAAG,GAAGF;IACjC,OAAOI;AACT;AAEA,OAAO,SAASE,eAAkBN,OAAU,EAAEC,QAAa;IACzD,MAAMC,QAAQD,SAASE,OAAO,CAACH;IAC/B,IAAIE,UAAUD,SAASM,MAAM,GAAG,GAAG;QACjC,OAAON;IACT;IAEA,MAAMG,cAAc;WAAIH;KAAS;IACjCG,YAAYC,MAAM,CAACH,OAAO;IAC1BE,YAAYC,MAAM,CAACH,QAAQ,GAAG,GAAGF;IACjC,OAAOI;AACT;AAUA,OAAO,SAASI,WAAW,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,EAAEC,MAAM,EAAmB;IACnG,MAAM,CAACC,UAAUC,YAAY,GAAGjB,SAA6B;IAC7D,MAAMkB,OAAOC,QAAQH;IAErB,SAASI,YAAYC,KAA8B;QACjDJ,YAAYI,MAAMC,aAAa;IACjC;IAEA,SAASC,WAAWC,QAAqB;QACvCP,YAAY;QACZO,qBAAAA,+BAAAA;IACF;IAEA,qBACE;;0BACE,KAAC5B;gBAAW6B,cAAW;gBAAOC,iBAAe;gBAAMC,iBAAeT;gBAAMU,MAAK;gBAAQC,SAAST;0BAC5F,cAAA,KAACrB;;YAEDY,CAAAA,YAAYC,cAAcC,cAAcC,WAAU,mBAClD,MAACjB;gBACCiC,IAAG;gBACHC,eAAe;oBACb,mBAAmB;gBACrB;gBACAf,UAAUA;gBACVE,MAAMA;gBACNc,SAAS,IAAMT,WAAWU;gBAC1BC,IAAInB;;oBAEHJ,0BAAY,KAACb;wBAAS+B,SAAS,IAAMN,WAAWZ;kCAAW;;oBAC3DC,4BAAc,KAACd;wBAAS+B,SAAS,IAAMN,WAAWX;kCAAa;;oBAC/DC,4BAAc,KAACf;wBAAS+B,SAAS,IAAMN,WAAWV;kCAAa;;oBAC/DC,6BAAe,KAAChB;wBAAS+B,SAAS,IAAMN,WAAWT;kCAAc;;oBACjEA,6BAAe,KAAChB;wBAAS+B,SAAS,IAAMN,WAAWT;kCAAc;;;;;;AAK5E"}
1
+ {"version":3,"sources":["../../src/DragAndDrop/DragButton.tsx"],"sourcesContent":["// Copyright 2024 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 { IconButton, IconButtonProps, Menu, MenuItem, MenuProps } from '@mui/material';\nimport DragIcon from 'mdi-material-ui/Drag';\nimport { useState, MouseEvent, ReactElement, forwardRef } from 'react';\n\nexport function handleMoveUp<T>(element: T, elements: T[]): T[] {\n const index = elements.indexOf(element);\n if (index === 0) {\n return elements;\n }\n\n const newElements = [...elements];\n newElements.splice(index, 1);\n newElements.splice(index - 1, 0, element);\n return newElements;\n}\n\nexport function handleMoveDown<T>(element: T, elements: T[]): T[] {\n const index = elements.indexOf(element);\n if (index === elements.length - 1) {\n return elements;\n }\n\n const newElements = [...elements];\n newElements.splice(index, 1);\n newElements.splice(index + 1, 0, element);\n return newElements;\n}\n\nexport interface DragButtonProps extends IconButtonProps {\n onMoveUp?: () => void;\n onMoveDown?: () => void;\n onMoveLeft?: () => void;\n onMoveRight?: () => void;\n menuSx?: MenuProps['sx'];\n}\n\nexport const DragButton = forwardRef<HTMLButtonElement, DragButtonProps>(function DragButton(\n { onMoveUp, onMoveDown, onMoveLeft, onMoveRight, menuSx, ...otherProps }: DragButtonProps,\n ref\n): ReactElement {\n const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);\n const open = Boolean(anchorEl);\n\n function handleClick(event: MouseEvent<HTMLElement>): void {\n setAnchorEl(event.currentTarget);\n }\n\n function handleMove(callback?: () => void): void {\n setAnchorEl(null);\n callback?.();\n }\n\n return (\n <>\n <IconButton\n {...otherProps}\n ref={ref}\n aria-label=\"move\"\n aria-haspopup={true}\n aria-expanded={open}\n size=\"small\"\n onClick={handleClick}\n >\n <DragIcon />\n </IconButton>\n {(onMoveUp || onMoveDown || onMoveLeft || onMoveRight) && (\n <Menu\n id=\"drag-button-menu\"\n MenuListProps={{\n 'aria-labelledby': 'drag-button-menu',\n }}\n anchorEl={anchorEl}\n open={open}\n onClose={() => handleMove(undefined)}\n sx={menuSx}\n >\n {onMoveUp && <MenuItem onClick={() => handleMove(onMoveUp)}>Move Up</MenuItem>}\n {onMoveDown && <MenuItem onClick={() => handleMove(onMoveDown)}>Move Down</MenuItem>}\n {onMoveLeft && <MenuItem onClick={() => handleMove(onMoveLeft)}>Move Left</MenuItem>}\n {onMoveRight && <MenuItem onClick={() => handleMove(onMoveRight)}>Move Right</MenuItem>}\n {onMoveRight && <MenuItem onClick={() => handleMove(onMoveRight)}>Move Right</MenuItem>}\n </Menu>\n )}\n </>\n );\n});\n"],"names":["IconButton","Menu","MenuItem","DragIcon","useState","forwardRef","handleMoveUp","element","elements","index","indexOf","newElements","splice","handleMoveDown","length","DragButton","onMoveUp","onMoveDown","onMoveLeft","onMoveRight","menuSx","otherProps","ref","anchorEl","setAnchorEl","open","Boolean","handleClick","event","currentTarget","handleMove","callback","aria-label","aria-haspopup","aria-expanded","size","onClick","id","MenuListProps","onClose","undefined","sx"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,EAAmBC,IAAI,EAAEC,QAAQ,QAAmB,gBAAgB;AACvF,OAAOC,cAAc,uBAAuB;AAC5C,SAASC,QAAQ,EAA4BC,UAAU,QAAQ,QAAQ;AAEvE,OAAO,SAASC,aAAgBC,OAAU,EAAEC,QAAa;IACvD,MAAMC,QAAQD,SAASE,OAAO,CAACH;IAC/B,IAAIE,UAAU,GAAG;QACf,OAAOD;IACT;IAEA,MAAMG,cAAc;WAAIH;KAAS;IACjCG,YAAYC,MAAM,CAACH,OAAO;IAC1BE,YAAYC,MAAM,CAACH,QAAQ,GAAG,GAAGF;IACjC,OAAOI;AACT;AAEA,OAAO,SAASE,eAAkBN,OAAU,EAAEC,QAAa;IACzD,MAAMC,QAAQD,SAASE,OAAO,CAACH;IAC/B,IAAIE,UAAUD,SAASM,MAAM,GAAG,GAAG;QACjC,OAAON;IACT;IAEA,MAAMG,cAAc;WAAIH;KAAS;IACjCG,YAAYC,MAAM,CAACH,OAAO;IAC1BE,YAAYC,MAAM,CAACH,QAAQ,GAAG,GAAGF;IACjC,OAAOI;AACT;AAUA,OAAO,MAAMI,2BAAaV,WAA+C,SAASU,WAChF,EAAEC,QAAQ,EAAEC,UAAU,EAAEC,UAAU,EAAEC,WAAW,EAAEC,MAAM,EAAE,GAAGC,YAA6B,EACzFC,GAAG;IAEH,MAAM,CAACC,UAAUC,YAAY,GAAGpB,SAA6B;IAC7D,MAAMqB,OAAOC,QAAQH;IAErB,SAASI,YAAYC,KAA8B;QACjDJ,YAAYI,MAAMC,aAAa;IACjC;IAEA,SAASC,WAAWC,QAAqB;QACvCP,YAAY;QACZO;IACF;IAEA,qBACE;;0BACE,KAAC/B;gBACE,GAAGqB,UAAU;gBACdC,KAAKA;gBACLU,cAAW;gBACXC,iBAAe;gBACfC,iBAAeT;gBACfU,MAAK;gBACLC,SAAST;0BAET,cAAA,KAACxB;;YAEDa,CAAAA,YAAYC,cAAcC,cAAcC,WAAU,mBAClD,MAAClB;gBACCoC,IAAG;gBACHC,eAAe;oBACb,mBAAmB;gBACrB;gBACAf,UAAUA;gBACVE,MAAMA;gBACNc,SAAS,IAAMT,WAAWU;gBAC1BC,IAAIrB;;oBAEHJ,0BAAY,KAACd;wBAASkC,SAAS,IAAMN,WAAWd;kCAAW;;oBAC3DC,4BAAc,KAACf;wBAASkC,SAAS,IAAMN,WAAWb;kCAAa;;oBAC/DC,4BAAc,KAAChB;wBAASkC,SAAS,IAAMN,WAAWZ;kCAAa;;oBAC/DC,6BAAe,KAACjB;wBAASkC,SAAS,IAAMN,WAAWX;kCAAc;;oBACjEA,6BAAe,KAACjB;wBAASkC,SAAS,IAAMN,WAAWX;kCAAc;;;;;;AAK5E,GAAG"}
@@ -26,7 +26,7 @@ export const Drawer = ({ anchor = 'right', isOpen, onClose, PaperProps, children
26
26
  sx: combineSx({
27
27
  width: isSmaller ? '100%' : `${DRAWER_DEFAULT_WIDTH}px`,
28
28
  overflow: 'hidden'
29
- }, PaperProps === null || PaperProps === void 0 ? void 0 : PaperProps.sx)
29
+ }, PaperProps?.sx)
30
30
  },
31
31
  children: children
32
32
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Drawer/Drawer.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 { Drawer as MuiDrawer, DrawerProps as MuiDrawerProps, useMediaQuery } from '@mui/material';\nimport { ReactElement } from 'react';\nimport { combineSx } from '../utils';\n\nexport interface DrawerProps extends MuiDrawerProps {\n isOpen: boolean;\n onClose: () => void;\n anchor?: 'left' | 'right';\n}\n\nconst DRAWER_DEFAULT_WIDTH = 1080;\n\nexport const Drawer = ({\n anchor = 'right',\n isOpen,\n onClose,\n PaperProps,\n children,\n ...rest\n}: DrawerProps): ReactElement => {\n const isSmaller = useMediaQuery(`(max-width:${DRAWER_DEFAULT_WIDTH}px)`);\n\n return (\n <MuiDrawer\n {...rest}\n open={isOpen}\n onClose={onClose}\n anchor={anchor}\n PaperProps={{\n ...PaperProps,\n sx: combineSx(\n {\n width: isSmaller ? '100%' : `${DRAWER_DEFAULT_WIDTH}px`,\n overflow: 'hidden',\n },\n PaperProps?.sx\n ),\n }}\n >\n {children}\n </MuiDrawer>\n );\n};\n"],"names":["Drawer","MuiDrawer","useMediaQuery","combineSx","DRAWER_DEFAULT_WIDTH","anchor","isOpen","onClose","PaperProps","children","rest","isSmaller","open","sx","width","overflow"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAUC,SAAS,EAAiCC,aAAa,QAAQ,gBAAgB;AAElG,SAASC,SAAS,QAAQ,WAAW;AAQrC,MAAMC,uBAAuB;AAE7B,OAAO,MAAMJ,SAAS,CAAC,EACrBK,SAAS,OAAO,EAChBC,MAAM,EACNC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACR,GAAGC,MACS;IACZ,MAAMC,YAAYT,cAAc,CAAC,WAAW,EAAEE,qBAAqB,GAAG,CAAC;IAEvE,qBACE,KAACH;QACE,GAAGS,IAAI;QACRE,MAAMN;QACNC,SAASA;QACTF,QAAQA;QACRG,YAAY;YACV,GAAGA,UAAU;YACbK,IAAIV,UACF;gBACEW,OAAOH,YAAY,SAAS,CAAC,EAAEP,qBAAqB,EAAE,CAAC;gBACvDW,UAAU;YACZ,GACAP,uBAAAA,iCAAAA,WAAYK,EAAE;QAElB;kBAECJ;;AAGP,EAAE"}
1
+ {"version":3,"sources":["../../src/Drawer/Drawer.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 { Drawer as MuiDrawer, DrawerProps as MuiDrawerProps, useMediaQuery } from '@mui/material';\nimport { ReactElement } from 'react';\nimport { combineSx } from '../utils';\n\nexport interface DrawerProps extends MuiDrawerProps {\n isOpen: boolean;\n onClose: () => void;\n anchor?: 'left' | 'right';\n}\n\nconst DRAWER_DEFAULT_WIDTH = 1080;\n\nexport const Drawer = ({\n anchor = 'right',\n isOpen,\n onClose,\n PaperProps,\n children,\n ...rest\n}: DrawerProps): ReactElement => {\n const isSmaller = useMediaQuery(`(max-width:${DRAWER_DEFAULT_WIDTH}px)`);\n\n return (\n <MuiDrawer\n {...rest}\n open={isOpen}\n onClose={onClose}\n anchor={anchor}\n PaperProps={{\n ...PaperProps,\n sx: combineSx(\n {\n width: isSmaller ? '100%' : `${DRAWER_DEFAULT_WIDTH}px`,\n overflow: 'hidden',\n },\n PaperProps?.sx\n ),\n }}\n >\n {children}\n </MuiDrawer>\n );\n};\n"],"names":["Drawer","MuiDrawer","useMediaQuery","combineSx","DRAWER_DEFAULT_WIDTH","anchor","isOpen","onClose","PaperProps","children","rest","isSmaller","open","sx","width","overflow"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAUC,SAAS,EAAiCC,aAAa,QAAQ,gBAAgB;AAElG,SAASC,SAAS,QAAQ,WAAW;AAQrC,MAAMC,uBAAuB;AAE7B,OAAO,MAAMJ,SAAS,CAAC,EACrBK,SAAS,OAAO,EAChBC,MAAM,EACNC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACR,GAAGC,MACS;IACZ,MAAMC,YAAYT,cAAc,CAAC,WAAW,EAAEE,qBAAqB,GAAG,CAAC;IAEvE,qBACE,KAACH;QACE,GAAGS,IAAI;QACRE,MAAMN;QACNC,SAASA;QACTF,QAAQA;QACRG,YAAY;YACV,GAAGA,UAAU;YACbK,IAAIV,UACF;gBACEW,OAAOH,YAAY,SAAS,CAAC,EAAEP,qBAAqB,EAAE,CAAC;gBACvDW,UAAU;YACZ,GACAP,YAAYK;QAEhB;kBAECJ;;AAGP,EAAE"}
@@ -41,11 +41,11 @@ export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, render
41
41
  useLayoutEffect(()=>{
42
42
  if (containerRef.current === null || chartElement.current !== null) return;
43
43
  chartElement.current = init(containerRef.current, theme, {
44
- renderer: renderer !== null && renderer !== void 0 ? renderer : 'canvas'
44
+ renderer: renderer ?? 'canvas'
45
45
  });
46
46
  if (chartElement.current === undefined) return;
47
47
  chartElement.current.setOption(initialOption.current, true);
48
- onChartInitialized === null || onChartInitialized === void 0 ? void 0 : onChartInitialized(chartElement.current);
48
+ onChartInitialized?.(chartElement.current);
49
49
  if (_instance !== undefined) {
50
50
  _instance.current = chartElement.current;
51
51
  }
@@ -145,8 +145,7 @@ function bindEvents(instance, events) {
145
145
  }
146
146
  for(const eventName in events){
147
147
  if (Object.prototype.hasOwnProperty.call(events, eventName)) {
148
- var _events_eventName;
149
- const customEvent = (_events_eventName = events[eventName]) !== null && _events_eventName !== void 0 ? _events_eventName : null;
148
+ const customEvent = events[eventName] ?? null;
150
149
  if (customEvent) {
151
150
  bindEvent(eventName, customEvent);
152
151
  }
@@ -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 { memo, useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init, connect } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport isEqual from 'lodash/isEqual';\nimport debounce from 'lodash/debounce';\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 syncGroup?: string;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n onEvents,\n _instance,\n syncGroup,\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 (): void => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // When syncGroup is explicitly set, charts within same group share interactions such as crosshair\n useEffect(() => {\n if (!chartElement.current || !syncGroup) return;\n chartElement.current.group = syncGroup;\n connect([chartElement.current]); // more info: https://echarts.apache.org/en/api.html#echarts.connect\n }, [syncGroup, chartElement]);\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 (): void => {\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 (): void => {\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>): void {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown): void {\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":["memo","useEffect","useLayoutEffect","useRef","init","connect","Box","isEqual","debounce","mouseEvents","batchEvents","EChart","option","theme","renderer","sx","onEvents","_instance","syncGroup","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","group","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;AAC3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G;QAACd;KAAG;IAEP,qBAAO,KAACT;QAAIkC,KAAKlB;QAAcP,IAAIA;;AACrC,GAAG;AAEH,+CAA+C;AAC/C,SAASoB,WAAcM,QAAiB,EAAEC,MAAwB;IAChE,IAAIA,WAAWjB,WAAW;IAE1B,SAASkB,UAAUC,SAAoB,EAAEC,eAAwB;QAC/D,IAAI,OAAOA,oBAAoB,YAAY;YACzC,IAAIC,aAAaF,YAAY;gBAC3BH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG,QAAQP;YAC7D,OAAO,IAAIQ,aAAaL,YAAY;gBAClCH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG;YACrD,OAAO;gBACLP,SAASM,EAAE,CAACH,WAAW,IAAMC,gBAAgB,MAAMJ;YACrD;QACF;IACF;IAEA,IAAK,MAAMG,aAAaF,OAAQ;QAC9B,IAAIQ,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACX,QAAQE,YAAY;gBACvCF;YAApB,MAAMY,cAAcZ,CAAAA,oBAAAA,MAAM,CAACE,UAAuB,cAA9BF,+BAAAA,oBAAkC;YACtD,IAAIY,aAAa;gBACfX,UAAUC,WAAwBU;YACpC;QACF;IACF;AACF;AAEA,SAASR,aAAaF,SAAoB;IACxC,OAAO,AAACnC,YAAkC8C,QAAQ,CAACX;AACrD;AAEA,SAASK,aAAaL,SAAoB;IACxC,OAAO,AAAClC,YAAkC6C,QAAQ,CAACX;AACrD"}
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 { memo, useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init, connect } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport isEqual from 'lodash/isEqual';\nimport debounce from 'lodash/debounce';\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 syncGroup?: string;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n onEvents,\n _instance,\n syncGroup,\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 (): void => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // When syncGroup is explicitly set, charts within same group share interactions such as crosshair\n useEffect(() => {\n if (!chartElement.current || !syncGroup) return;\n chartElement.current.group = syncGroup;\n connect([chartElement.current]); // more info: https://echarts.apache.org/en/api.html#echarts.connect\n }, [syncGroup, chartElement]);\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 (): void => {\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 (): void => {\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>): void {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown): void {\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":["memo","useEffect","useLayoutEffect","useRef","init","connect","Box","isEqual","debounce","mouseEvents","batchEvents","EChart","option","theme","renderer","sx","onEvents","_instance","syncGroup","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","group","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,SAASA,IAAI,EAAEC,SAAS,EAAEC,eAAe,EAAEC,MAAM,QAAQ,QAAQ;AACjE,SAAqCC,IAAI,EAAEC,OAAO,QAAQ,eAAe;AACzE,SAASC,GAAG,QAAwB,gBAAgB;AACpD,OAAOC,aAAa,iBAAiB;AACrC,OAAOC,cAAc,kBAAkB;AAwBvC,MAAMC,cAAc;IAClB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAkCD,MAAMC,cAAc;IAAC;IAAY;IAAY;CAAY;AA2BzD,OAAO,MAAMC,uBAASX,KAAK,SAASW,OAAU,EAC5CC,MAAM,EACNC,KAAK,EACLC,QAAQ,EACRC,EAAE,EACFC,QAAQ,EACRC,SAAS,EACTC,SAAS,EACTC,kBAAkB,EACF;IAChB,MAAMC,gBAAgBjB,OAA0BS;IAChD,MAAMS,aAAalB,OAA0BS;IAC7C,MAAMU,eAAenB,OAA8B;IACnD,MAAMoB,eAAepB,OAAuB;IAE5C,uCAAuC;IACvCD,gBAAgB;QACd,IAAIoB,aAAaE,OAAO,KAAK,QAAQD,aAAaC,OAAO,KAAK,MAAM;QACpED,aAAaC,OAAO,GAAGpB,KAAKkB,aAAaE,OAAO,EAAEX,OAAO;YAAEC,UAAUA,YAAY;QAAS;QAC1F,IAAIS,aAAaC,OAAO,KAAKC,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,11 +33,9 @@ export function GaugeChart(props) {
33
33
  const chartsTheme = useChartsTheme();
34
34
  // useDeepMemo ensures value size util does not rerun everytime you hover on the chart
35
35
  const option = useDeepMemo(()=>{
36
- var _chartsTheme_echartsTheme_textStyle;
37
36
  if (data.value === undefined) return chartsTheme.noDataOption;
38
37
  // adjusts fontSize depending on number of characters
39
38
  const valueSizeClamp = getResponsiveValueSize(data.value, format, width, height);
40
- var _chartsTheme_echartsTheme_textStyle_color;
41
39
  return {
42
40
  title: {
43
41
  show: false
@@ -167,7 +165,7 @@ export function GaugeChart(props) {
167
165
  // https://echarts.apache.org/en/option.html#series-gauge.data.title
168
166
  title: {
169
167
  show: true,
170
- color: (_chartsTheme_echartsTheme_textStyle_color = (_chartsTheme_echartsTheme_textStyle = chartsTheme.echartsTheme.textStyle) === null || _chartsTheme_echartsTheme_textStyle === void 0 ? void 0 : _chartsTheme_echartsTheme_textStyle.color) !== null && _chartsTheme_echartsTheme_textStyle_color !== void 0 ? _chartsTheme_echartsTheme_textStyle_color : 'inherit',
168
+ color: chartsTheme.echartsTheme.textStyle?.color ?? 'inherit',
171
169
  offsetCenter: [
172
170
  0,
173
171
  '55%'
@@ -208,8 +206,7 @@ export function GaugeChart(props) {
208
206
  const MAX_SIZE = 24;
209
207
  const SIZE_MULTIPLIER = 0.7;
210
208
  const formattedValue = typeof value === 'number' ? formatValue(value, format) : `${value}`;
211
- var _formattedValue_length;
212
- const valueCharacters = (_formattedValue_length = formattedValue.length) !== null && _formattedValue_length !== void 0 ? _formattedValue_length : 2;
209
+ const valueCharacters = formattedValue.length ?? 2;
213
210
  const valueSize = Math.min(width, height) / valueCharacters * SIZE_MULTIPLIER;
214
211
  return `clamp(${MIN_SIZE}px, ${valueSize}px, ${MAX_SIZE}px)`;
215
212
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/GaugeChart/GaugeChart.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 { formatValue, useDeepMemo, FormatOptions } from '@perses-dev/core';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { GaugeChart as EChartsGaugeChart, GaugeSeriesOption } from 'echarts/charts';\nimport { GridComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { ReactElement } from 'react';\nimport { useChartsTheme } from '../context';\nimport { EChart } from '../EChart';\n\nuse([EChartsGaugeChart, GridComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst PROGRESS_WIDTH = 16;\n\n// adjusts when to show pointer icon\nconst GAUGE_SMALL_BREAKPOINT = 170;\n\nexport type GaugeChartValue = number | null | undefined;\n\nexport type GaugeSeries = {\n value: GaugeChartValue;\n label: string;\n};\n\nexport interface GaugeChartProps {\n width: number;\n height: number;\n data: GaugeSeries;\n format: FormatOptions;\n axisLine: GaugeSeriesOption['axisLine'];\n max?: number;\n}\n\nexport function GaugeChart(props: GaugeChartProps): ReactElement {\n const { width, height, data, format, axisLine, max } = props;\n const chartsTheme = useChartsTheme();\n\n // useDeepMemo ensures value size util does not rerun everytime you hover on the chart\n const option: EChartsCoreOption = useDeepMemo(() => {\n if (data.value === undefined) return chartsTheme.noDataOption;\n\n // adjusts fontSize depending on number of characters\n const valueSizeClamp = getResponsiveValueSize(data.value, format, width, height);\n\n return {\n title: {\n show: false,\n },\n tooltip: {\n show: false,\n },\n series: [\n {\n type: 'gauge',\n center: ['50%', '65%'],\n radius: '86%',\n startAngle: 200,\n endAngle: -20,\n min: 0,\n max,\n silent: true,\n progress: {\n show: true,\n width: PROGRESS_WIDTH,\n itemStyle: {\n color: 'auto',\n },\n },\n pointer: {\n show: false,\n },\n axisLine: {\n lineStyle: {\n color: [[1, 'rgba(127,127,127,0.35)']], // TODO (sjcobb): use future chart theme colors\n width: PROGRESS_WIDTH,\n },\n },\n axisTick: {\n show: false,\n distance: 0,\n },\n splitLine: {\n show: false,\n },\n axisLabel: {\n show: false,\n distance: -18,\n color: '#999',\n fontSize: 12,\n },\n anchor: {\n show: false,\n },\n title: {\n show: false,\n },\n detail: {\n show: false,\n },\n data: [\n {\n value: data.value,\n },\n ],\n },\n {\n type: 'gauge',\n center: ['50%', '65%'],\n radius: '100%',\n startAngle: 200,\n endAngle: -20,\n min: 0,\n max,\n pointer: {\n show: true,\n // pointer hidden for small panels, path taken from ex: https://echarts.apache.org/examples/en/editor.html?c=gauge-grade\n icon: width > GAUGE_SMALL_BREAKPOINT ? 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z' : 'none',\n length: 10,\n width: 5,\n offsetCenter: [0, '-49%'],\n itemStyle: {\n color: 'auto',\n },\n },\n axisLine,\n axisTick: {\n show: false,\n },\n splitLine: {\n show: false,\n },\n axisLabel: {\n show: false,\n },\n detail: {\n show: true,\n width: '60%',\n borderRadius: 8,\n offsetCenter: [0, '-9%'],\n color: 'inherit', // allows value color to match active threshold color\n fontSize: valueSizeClamp,\n formatter:\n data.value === null\n ? // We use a different function when we *know* the value is null\n // at this level because the `formatter` function argument is `NaN`\n // when the value is `null`, making it difficult to differentiate\n // `null` from a true `NaN` case.\n (): string => 'null'\n : (value: number): string | undefined => {\n return formatValue(value, format);\n },\n },\n data: [\n {\n value: data.value,\n name: data.label,\n // TODO: new UX for series names, create separate React component or reuse ListLegendItem\n // https://echarts.apache.org/en/option.html#series-gauge.data.title\n title: {\n show: true,\n color: chartsTheme.echartsTheme.textStyle?.color ?? 'inherit', // series name font color\n offsetCenter: [0, '55%'],\n overflow: 'truncate',\n fontSize: 12,\n width: width * 0.8,\n },\n },\n ],\n },\n ],\n };\n }, [data, width, height, chartsTheme, format, axisLine, max]);\n\n return (\n <EChart\n sx={{\n width: width,\n height: height,\n padding: `${chartsTheme.container.padding.default}px`,\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n />\n );\n}\n\n/**\n * Responsive font size depending on number of characters, clamp used\n * to ensure size stays within given range\n */\nexport function getResponsiveValueSize(\n value: number | null,\n format: FormatOptions,\n width: number,\n height: number\n): string {\n const MIN_SIZE = 3;\n const MAX_SIZE = 24;\n const SIZE_MULTIPLIER = 0.7;\n const formattedValue = typeof value === 'number' ? formatValue(value, format) : `${value}`;\n const valueCharacters = formattedValue.length ?? 2;\n const valueSize = (Math.min(width, height) / valueCharacters) * SIZE_MULTIPLIER;\n return `clamp(${MIN_SIZE}px, ${valueSize}px, ${MAX_SIZE}px)`;\n}\n"],"names":["formatValue","useDeepMemo","use","GaugeChart","EChartsGaugeChart","GridComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","EChart","PROGRESS_WIDTH","GAUGE_SMALL_BREAKPOINT","props","width","height","data","format","axisLine","max","chartsTheme","option","value","undefined","noDataOption","valueSizeClamp","getResponsiveValueSize","title","show","tooltip","series","type","center","radius","startAngle","endAngle","min","silent","progress","itemStyle","color","pointer","lineStyle","axisTick","distance","splitLine","axisLabel","fontSize","anchor","detail","icon","length","offsetCenter","borderRadius","formatter","name","label","echartsTheme","textStyle","overflow","sx","padding","container","default","theme","MIN_SIZE","MAX_SIZE","SIZE_MULTIPLIER","formattedValue","valueCharacters","valueSize","Math"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,WAAW,EAAEC,WAAW,QAAuB,mBAAmB;AAC3E,SAASC,GAAG,QAA2B,eAAe;AACtD,SAASC,cAAcC,iBAAiB,QAA2B,iBAAiB;AACpF,SAASC,a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jC,OAAOA,QAAQ;4BACjB;wBACF;qBACD;gBACH;aACD;QACH;IACF,GAAG;QAACE;QAAMF;QAAOC;QAAQK;QAAaH;QAAQC;QAAUC;KAAI;IAE5D,qBACE,KAACT;QACCkD,IAAI;YACF9C,OAAOA;YACPC,QAAQA;YACR8C,SAAS,CAAC,EAAEzC,YAAY0C,SAAS,CAACD,OAAO,CAACE,OAAO,CAAC,EAAE,CAAC;QACvD;QACA1C,QAAQA;QACR2C,OAAO5C,YAAYqC,YAAY;;AAGrC;AAEA;;;CAGC,GACD,OAAO,SAAS/B,uBACdJ,KAAoB,EACpBL,MAAqB,EACrBH,KAAa,EACbC,MAAc;IAEd,MAAMkD,WAAW;IACjB,MAAMC,WAAW;IACjB,MAAMC,kBAAkB;IACxB,MAAMC,iBAAiB,OAAO9C,UAAU,WAAWtB,YAAYsB,OAAOL,UAAU,CAAC,EAAEK,MAAM,CAAC;QAClE8C;IAAxB,MAAMC,kBAAkBD,CAAAA,yBAAAA,eAAejB,MAAM,cAArBiB,oCAAAA,yBAAyB;IACjD,MAAME,YAAY,AAACC,KAAKnC,GAAG,CAACtB,OAAOC,UAAUsD,kBAAmBF;IAChE,OAAO,CAAC,MAAM,EAAEF,SAAS,IAAI,EAAEK,UAAU,IAAI,EAAEJ,SAAS,GAAG,CAAC;AAC9D"}
1
+ {"version":3,"sources":["../../src/GaugeChart/GaugeChart.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 { formatValue, useDeepMemo, FormatOptions } from '@perses-dev/core';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { GaugeChart as EChartsGaugeChart, GaugeSeriesOption } from 'echarts/charts';\nimport { GridComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { ReactElement } from 'react';\nimport { useChartsTheme } from '../context';\nimport { EChart } from '../EChart';\n\nuse([EChartsGaugeChart, GridComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst PROGRESS_WIDTH = 16;\n\n// adjusts when to show pointer icon\nconst GAUGE_SMALL_BREAKPOINT = 170;\n\nexport type GaugeChartValue = number | null | undefined;\n\nexport type GaugeSeries = {\n value: GaugeChartValue;\n label: string;\n};\n\nexport interface GaugeChartProps {\n width: number;\n height: number;\n data: GaugeSeries;\n format: FormatOptions;\n axisLine: GaugeSeriesOption['axisLine'];\n max?: number;\n}\n\nexport function GaugeChart(props: GaugeChartProps): ReactElement {\n const { width, height, data, format, axisLine, max } = props;\n const chartsTheme = useChartsTheme();\n\n // useDeepMemo ensures value size util does not rerun everytime you hover on the chart\n const option: EChartsCoreOption = useDeepMemo(() => {\n if (data.value === undefined) return chartsTheme.noDataOption;\n\n // adjusts fontSize depending on number of characters\n const valueSizeClamp = getResponsiveValueSize(data.value, format, width, height);\n\n return {\n title: {\n show: false,\n },\n tooltip: {\n show: false,\n },\n series: [\n {\n type: 'gauge',\n center: ['50%', '65%'],\n radius: '86%',\n startAngle: 200,\n endAngle: -20,\n min: 0,\n max,\n silent: true,\n progress: {\n show: true,\n width: PROGRESS_WIDTH,\n itemStyle: {\n color: 'auto',\n },\n },\n pointer: {\n show: false,\n },\n axisLine: {\n lineStyle: {\n color: [[1, 'rgba(127,127,127,0.35)']], // TODO (sjcobb): use future chart theme colors\n width: PROGRESS_WIDTH,\n },\n },\n axisTick: {\n show: false,\n distance: 0,\n },\n splitLine: {\n show: false,\n },\n axisLabel: {\n show: false,\n distance: -18,\n color: '#999',\n fontSize: 12,\n },\n anchor: {\n show: false,\n },\n title: {\n show: false,\n },\n detail: {\n show: false,\n },\n data: [\n {\n value: data.value,\n },\n ],\n },\n {\n type: 'gauge',\n center: ['50%', '65%'],\n radius: '100%',\n startAngle: 200,\n endAngle: -20,\n min: 0,\n max,\n pointer: {\n show: true,\n // pointer hidden for small panels, path taken from ex: https://echarts.apache.org/examples/en/editor.html?c=gauge-grade\n icon: width > GAUGE_SMALL_BREAKPOINT ? 'path://M12.8,0.7l12,40.1H0.7L12.8,0.7z' : 'none',\n length: 10,\n width: 5,\n offsetCenter: [0, '-49%'],\n itemStyle: {\n color: 'auto',\n },\n },\n axisLine,\n axisTick: {\n show: false,\n },\n splitLine: {\n show: false,\n },\n axisLabel: {\n show: false,\n },\n detail: {\n show: true,\n width: '60%',\n borderRadius: 8,\n offsetCenter: [0, '-9%'],\n color: 'inherit', // allows value color to match active threshold color\n fontSize: valueSizeClamp,\n formatter:\n data.value === null\n ? // We use a different function when we *know* the value is null\n // at this level because the `formatter` function argument is `NaN`\n // when the value is `null`, making it difficult to differentiate\n // `null` from a true `NaN` case.\n (): string => 'null'\n : (value: number): string | undefined => {\n return formatValue(value, format);\n },\n },\n data: [\n {\n value: data.value,\n name: data.label,\n // TODO: new UX for series names, create separate React component or reuse ListLegendItem\n // https://echarts.apache.org/en/option.html#series-gauge.data.title\n title: {\n show: true,\n color: chartsTheme.echartsTheme.textStyle?.color ?? 'inherit', // series name font color\n offsetCenter: [0, '55%'],\n overflow: 'truncate',\n fontSize: 12,\n width: width * 0.8,\n },\n },\n ],\n },\n ],\n };\n }, [data, width, height, chartsTheme, format, axisLine, max]);\n\n return (\n <EChart\n sx={{\n width: width,\n height: height,\n padding: `${chartsTheme.container.padding.default}px`,\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n />\n );\n}\n\n/**\n * Responsive font size depending on number of characters, clamp used\n * to ensure size stays within given range\n */\nexport function getResponsiveValueSize(\n value: number | null,\n format: FormatOptions,\n width: number,\n height: number\n): string {\n const MIN_SIZE = 3;\n const MAX_SIZE = 24;\n const SIZE_MULTIPLIER = 0.7;\n const formattedValue = typeof value === 'number' ? formatValue(value, format) : `${value}`;\n const valueCharacters = formattedValue.length ?? 2;\n const valueSize = (Math.min(width, height) / valueCharacters) * SIZE_MULTIPLIER;\n return `clamp(${MIN_SIZE}px, ${valueSize}px, ${MAX_SIZE}px)`;\n}\n"],"names":["formatValue","useDeepMemo","use","GaugeChart","EChartsGaugeChart","GridComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","EChart","PROGRESS_WIDTH","GAUGE_SMALL_BREAKPOINT","props","width","height","data","format","axisLine","max","chartsTheme","option","value","undefined","noDataOption","valueSizeClamp","getResponsiveValueSize","title","show","tooltip","series","type","center","radius","startAngle","endAngle","min","silent","progress","itemStyle","color","pointer","lineStyle","axisTick","distance","splitLine","axisLabel","fontSize","anchor","detail","icon","length","offsetCenter","borderRadius","formatter","name","label","echartsTheme","textStyle","overflow","sx","padding","container","default","theme","MIN_SIZE","MAX_SIZE","SIZE_MULTIPLIER","formattedValue","valueCharacters","valueSize","Math"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,WAAW,EAAEC,WAAW,QAAuB,mBAAmB;AAC3E,SAASC,GAAG,QAA2B,eAAe;AACtD,SAASC,cAAcC,iBAAiB,QAA2B,iBAAiB;AACpF,SAASC,aAAa,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,qBAAqB;AACrF,SAASC,cAAc,QAAQ,oBAAoB;AAEnD,SAASC,cAAc,QAAQ,aAAa;AAC5C,SAASC,MAAM,QAAQ,YAAY;AAEnCR,IAAI;IAACE;IAAmBC;IAAeC;IAAgBC;IAAkBC;CAAe;AAExF,MAAMG,iBAAiB;AAEvB,oCAAoC;AACpC,MAAMC,yBAAyB;AAkB/B,OAAO,SAAST,WAAWU,KAAs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AAa,EACbC,MAAc;IAEd,MAAMkD,WAAW;IACjB,MAAMC,WAAW;IACjB,MAAMC,kBAAkB;IACxB,MAAMC,iBAAiB,OAAO9C,UAAU,WAAWtB,YAAYsB,OAAOL,UAAU,CAAC,EAAEK,MAAM,CAAC;IAC1F,MAAM+C,kBAAkBD,eAAejB,MAAM,IAAI;IACjD,MAAMmB,YAAY,AAACC,KAAKnC,GAAG,CAACtB,OAAOC,UAAUsD,kBAAmBF;IAChE,OAAO,CAAC,MAAM,EAAEF,SAAS,IAAI,EAAEK,UAAU,IAAI,EAAEJ,SAAS,GAAG,CAAC;AAC9D"}
@@ -25,13 +25,13 @@ export const InfoTooltip = ({ id, title, description, placement, children, enter
25
25
  return /*#__PURE__*/ _jsx(StyledTooltip, {
26
26
  arrow: true,
27
27
  id: id,
28
- placement: placement !== null && placement !== void 0 ? placement : 'top',
28
+ placement: placement ?? 'top',
29
29
  title: /*#__PURE__*/ _jsx(TooltipContent, {
30
30
  title: title,
31
31
  description: description
32
32
  }),
33
- enterDelay: enterDelay !== null && enterDelay !== void 0 ? enterDelay : 500,
34
- enterNextDelay: enterNextDelay !== null && enterNextDelay !== void 0 ? enterNextDelay : 500,
33
+ enterDelay: enterDelay ?? 500,
34
+ enterNextDelay: enterNextDelay ?? 500,
35
35
  children: wrappedChildren
36
36
  });
37
37
  };
@@ -49,7 +49,8 @@ const TooltipContent = ({ title, description })=>{
49
49
  /*#__PURE__*/ _jsx(Typography, {
50
50
  variant: "caption",
51
51
  sx: (theme)=>({
52
- color: theme.palette.text.primary
52
+ color: theme.palette.text.primary,
53
+ whiteSpace: 'pre-line'
53
54
  }),
54
55
  children: description
55
56
  })
@@ -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 { ReactElement, ReactNode } 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: 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): ReactElement => {\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'>): ReactElement => {\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":["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;;AAGjC,SACEA,MAAM,EAENC,WAAWC,UAAU,EACrBC,cAAc,EACdC,UAAU,QACL,gBAAgB;AAcvB,OAAO,MAAMC,cAAc,CAAC,EAC1BC,EAAE,EACFC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,EACVC,cAAc,EACG;IACjB,4DAA4D;IAC5D,6EAA6E;IAC7E,gFAAgF;IAChF,+BAA+B;IAC/B,4EAA4E;IAC5E,cAAc;IACd,MAAMC,gCAAkB,KAACC;kBAAMJ;;IAE/B,qBACE,KAACK;QACCC,KAAK;QACLV,IAAIA;QACJG,WAAWA,sBAAAA,uBAAAA,YAAa;QACxBF,qBAAO,KAACU;YAAeV,OAAOA;YAAOC,aAAaA;;QAClDG,YAAYA,uBAAAA,wBAAAA,aAAc;QAC1BC,gBAAgBA,2BAAAA,4BAAAA,iBAAkB;kBAEjCC;;AAGP,EAAE;AAEF,MAAMI,iBAAiB,CAAC,EAAEV,KAAK,EAAEC,WAAW,EAAmD;IAC7F,qBACE;;YACGD,uBACC,KAACH;gBACCc,SAAQ;gBACRC,IAAI,CAACC,QAAW,CAAA;wBACdC,OAAOD,MAAME,OAAO,CAACC,IAAI,CAACC,OAAO;wBACjCC,YAAYL,MAAMM,UAAU,CAACC,gBAAgB;oBAC/C,CAAA;0BAECpB;;0BAGL,KAACH;gBACCc,SAAQ;gBACRC,IAAI,CAACC,QAAW,CAAA;wBACdC,OAAOD,MAAME,OAAO,CAACC,IAAI,CAACC,OAAO;oBACnC,CAAA;0BAEChB;;;;AAIT;AAEA,MAAMO,gBAAgBf,OAAO,CAAC,EAAE4B,SAAS,EAAE,GAAGC,OAAwB,iBACpE,KAAC3B;QAAY,GAAG2B,KAAK;QAAEC,SAAS;YAAEC,QAAQH;QAAU;QACnD,CAAC,EAAER,KAAK,EAAE,GAAM,CAAA;QACjB,CAAC,CAAC,GAAG,EAAEjB,eAAe6B,OAAO,CAAC,CAAC,CAAC,EAAE;YAChCC,iBAAiBb,MAAME,OAAO,CAACY,UAAU,CAACF,OAAO;YACjDX,OAAOD,MAAME,OAAO,CAACC,IAAI,CAACC,OAAO;YACjCW,UAAU;YACVC,SAAShB,MAAMiB,OAAO,CAAC;YACvBC,WAAWlB,MAAMmB,OAAO,CAAC,EAAE;QAC7B;QACA,CAAC,CAAC,GAAG,EAAEpC,eAAea,KAAK,CAAC,CAAC,CAAC,EAAE;YAC9BK,OAAOD,MAAME,OAAO,CAACY,UAAU,CAACF,OAAO;QACzC;IACF,CAAA"}
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 { ReactElement, ReactNode } 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: 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): ReactElement => {\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'>): ReactElement => {\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 whiteSpace: 'pre-line',\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":["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","whiteSpace","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;;AAGjC,SACEA,MAAM,EAENC,WAAWC,UAAU,EACrBC,cAAc,EACdC,UAAU,QACL,gBAAgB;AAcvB,OAAO,MAAMC,cAAc,CAAC,EAC1BC,EAAE,EACFC,KAAK,EACLC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,EACVC,cAAc,EACG;IACjB,4DAA4D;IAC5D,6EAA6E;IAC7E,gFAAgF;IAChF,+BAA+B;IAC/B,4EAA4E;IAC5E,cAAc;IACd,MAAMC,gCAAkB,KAACC;kBAAMJ;;IAE/B,qBACE,KAACK;QACCC,KAAK;QACLV,IAAIA;QACJG,WAAWA,aAAa;QACxBF,qBAAO,KAACU;YAAeV,OAAOA;YAAOC,aAAaA;;QAClDG,YAAYA,cAAc;QAC1BC,gBAAgBA,kBAAkB;kBAEjCC;;AAGP,EAAE;AAEF,MAAMI,iBAAiB,CAAC,EAAEV,KAAK,EAAEC,WAAW,EAAmD;IAC7F,qBACE;;YACGD,uBACC,KAACH;gBACCc,SAAQ;gBACRC,IAAI,CAACC,QAAW,CAAA;wBACdC,OAAOD,MAAME,OAAO,CAACC,IAAI,CAACC,OAAO;wBACjCC,YAAYL,MAAMM,UAAU,CAACC,gBAAgB;oBAC/C,CAAA;0BAECpB;;0BAGL,KAACH;gBACCc,SAAQ;gBACRC,IAAI,CAACC,QAAW,CAAA;wBACdC,OAAOD,MAAME,OAAO,CAACC,IAAI,CAACC,OAAO;wBACjCI,YAAY;oBACd,CAAA;0BAECpB;;;;AAIT;AAEA,MAAMO,gBAAgBf,OAAO,CAAC,EAAE6B,SAAS,EAAE,GAAGC,OAAwB,iBACpE,KAAC5B;QAAY,GAAG4B,KAAK;QAAEC,SAAS;YAAEC,QAAQH;QAAU;QACnD,CAAC,EAAET,KAAK,EAAE,GAAM,CAAA;QACjB,CAAC,CAAC,GAAG,EAAEjB,eAAe8B,OAAO,CAAC,CAAC,CAAC,EAAE;YAChCC,iBAAiBd,MAAME,OAAO,CAACa,UAAU,CAACF,OAAO;YACjDZ,OAAOD,MAAME,OAAO,CAACC,IAAI,CAACC,OAAO;YACjCY,UAAU;YACVC,SAASjB,MAAMkB,OAAO,CAAC;YACvBC,WAAWnB,MAAMoB,OAAO,CAAC,EAAE;QAC7B;QACA,CAAC,CAAC,GAAG,EAAErC,eAAea,KAAK,CAAC,CAAC,CAAC,EAAE;YAC9BK,OAAOD,MAAME,OAAO,CAACa,UAAU,CAACF,OAAO;QACzC;IACF,CAAA"}
@@ -28,9 +28,8 @@ const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ it
28
28
  }
29
29
  }
30
30
  const handleClick = (e)=>{
31
- var _item_onClick;
32
31
  onClick(e, item.id);
33
- (_item_onClick = item.onClick) === null || _item_onClick === void 0 ? void 0 : _item_onClick.call(item, e);
32
+ item.onClick?.(e);
34
33
  };
35
34
  return /*#__PURE__*/ _jsxs(ListItemButton, {
36
35
  ...others,
@@ -41,11 +40,11 @@ const ListLegendItemBase = /*#__PURE__*/ forwardRef(function ListLegendItem({ it
41
40
  }, sx),
42
41
  dense: true,
43
42
  onClick: handleClick,
44
- onMouseOver: (e)=>onMouseOver === null || onMouseOver === void 0 ? void 0 : onMouseOver(e, {
43
+ onMouseOver: (e)=>onMouseOver?.(e, {
45
44
  id: item.id,
46
45
  index
47
46
  }),
48
- onMouseOut: (e)=>onMouseOut === null || onMouseOut === void 0 ? void 0 : onMouseOut(e, {
47
+ onMouseOut: (e)=>onMouseOut?.(e, {
49
48
  id: item.id,
50
49
  index
51
50
  }),
@@ -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 { forwardRef, memo, MouseEvent, MouseEventHandler, ReactElement, useState } from 'react';\nimport { Box, ListItemText, ListItemProps, ListItemButton } from '@mui/material';\nimport { combineSx } from '../utils';\nimport { LegendColorBadge } from './LegendColorBadge';\nimport { LegendItem } from './legend-model';\n\nexport type LegendItemEventOpts = {\n /**\n * Unique identifier for the legend item.\n */\n id: string;\n\n /**\n * Index of the row in the original data.\n */\n index: number;\n};\n\nexport interface ListLegendItemProps extends Omit<ListItemProps<'div'>, 'onClick' | 'onMouseOver' | 'onMouseOut'> {\n item: LegendItem;\n\n index: number;\n\n /**\n * When true, the item is rendered differently to visually communicate it is\n * selected.\n */\n isVisuallySelected?: boolean;\n\n onClick: (e: MouseEvent<HTMLElement>, seriesId: string) => void;\n\n onMouseOver?: (e: MouseEvent, opts: LegendItemEventOpts) => void;\n onMouseOut?: (e: MouseEvent, opts: LegendItemEventOpts) => void;\n\n /**\n * When `true`, will keep labels to a single line with overflow ellipsized. The\n * full content will be shown on hover.\n *\n * When `false` or unset, will show the full label.\n */\n truncateLabel?: boolean;\n}\n\nconst ListLegendItemBase = forwardRef<HTMLDivElement, ListLegendItemProps>(function ListLegendItem(\n { item, sx, truncateLabel, onClick, isVisuallySelected, onMouseOver, onMouseOut, index, ...others },\n ref\n): ReactElement {\n const [noWrap, setNoWrap] = useState(truncateLabel);\n\n function handleTextMouseOver(): void {\n if (truncateLabel) {\n setNoWrap(false);\n }\n }\n\n function handleTextMouseOut(): void {\n if (truncateLabel) {\n setNoWrap(true);\n }\n }\n\n const handleClick: MouseEventHandler<HTMLDivElement> = (e) => {\n onClick(e, item.id);\n item.onClick?.(e);\n };\n\n return (\n <ListItemButton\n {...others}\n role=\"listitem\"\n sx={combineSx(\n {\n padding: 0,\n cursor: 'pointer',\n },\n sx\n )}\n dense={true}\n onClick={handleClick}\n onMouseOver={(e: MouseEvent) => onMouseOver?.(e, { id: item.id, index })}\n onMouseOut={(e: MouseEvent) => onMouseOut?.(e, { id: item.id, index })}\n selected={isVisuallySelected}\n ref={ref}\n >\n <Box sx={{ display: 'flex', alignItems: 'center' }}>\n <LegendColorBadge color={item.color} />\n </Box>\n <ListItemText\n primary={item.label}\n primaryTypographyProps={{ noWrap: noWrap }}\n onMouseOver={handleTextMouseOver}\n onMouseOut={handleTextMouseOut}\n ></ListItemText>\n </ListItemButton>\n );\n});\n\nexport const ListLegendItem = memo(ListLegendItemBase);\n"],"names":["forwardRef","memo","useState","Box","ListItemText","ListItemButton","combineSx","LegendColorBadge","ListLegendItemBase","ListLegendItem","item","sx","truncateLabel","onClick","isVisuallySelected","onMouseOver","onMouseOut","index","others","ref","noWrap","setNoWrap","handleTextMouseOver","handleTextMouseOut","handleClick","e","id","role","padding","cursor","dense","selected","display","alignItems","color","primary","label","primaryTypographyProps"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,EAAEC,IAAI,EAA+CC,QAAQ,QAA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IpB;AAEA,OAAO,MAAMd,+BAAiBR,KAAKO,oBAAoB"}
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 { forwardRef, memo, MouseEvent, MouseEventHandler, ReactElement, useState } from 'react';\nimport { Box, ListItemText, ListItemProps, ListItemButton } from '@mui/material';\nimport { combineSx } from '../utils';\nimport { LegendColorBadge } from './LegendColorBadge';\nimport { LegendItem } from './legend-model';\n\nexport type LegendItemEventOpts = {\n /**\n * Unique identifier for the legend item.\n */\n id: string;\n\n /**\n * Index of the row in the original data.\n */\n index: number;\n};\n\nexport interface ListLegendItemProps extends Omit<ListItemProps<'div'>, 'onClick' | 'onMouseOver' | 'onMouseOut'> {\n item: LegendItem;\n\n index: number;\n\n /**\n * When true, the item is rendered differently to visually communicate it is\n * selected.\n */\n isVisuallySelected?: boolean;\n\n onClick: (e: MouseEvent<HTMLElement>, seriesId: string) => void;\n\n onMouseOver?: (e: MouseEvent, opts: LegendItemEventOpts) => void;\n onMouseOut?: (e: MouseEvent, opts: LegendItemEventOpts) => void;\n\n /**\n * When `true`, will keep labels to a single line with overflow ellipsized. The\n * full content will be shown on hover.\n *\n * When `false` or unset, will show the full label.\n */\n truncateLabel?: boolean;\n}\n\nconst ListLegendItemBase = forwardRef<HTMLDivElement, ListLegendItemProps>(function ListLegendItem(\n { item, sx, truncateLabel, onClick, isVisuallySelected, onMouseOver, onMouseOut, index, ...others },\n ref\n): ReactElement {\n const [noWrap, setNoWrap] = useState(truncateLabel);\n\n function handleTextMouseOver(): void {\n if (truncateLabel) {\n setNoWrap(false);\n }\n }\n\n function handleTextMouseOut(): void {\n if (truncateLabel) {\n setNoWrap(true);\n }\n }\n\n const handleClick: MouseEventHandler<HTMLDivElement> = (e) => {\n onClick(e, item.id);\n item.onClick?.(e);\n };\n\n return (\n <ListItemButton\n {...others}\n role=\"listitem\"\n sx={combineSx(\n {\n padding: 0,\n cursor: 'pointer',\n },\n sx\n )}\n dense={true}\n onClick={handleClick}\n onMouseOver={(e: MouseEvent) => onMouseOver?.(e, { id: item.id, index })}\n onMouseOut={(e: MouseEvent) => onMouseOut?.(e, { id: item.id, index })}\n selected={isVisuallySelected}\n ref={ref}\n >\n <Box sx={{ display: 'flex', alignItems: 'center' }}>\n <LegendColorBadge color={item.color} />\n </Box>\n <ListItemText\n primary={item.label}\n primaryTypographyProps={{ noWrap: noWrap }}\n onMouseOver={handleTextMouseOver}\n onMouseOut={handleTextMouseOut}\n ></ListItemText>\n </ListItemButton>\n );\n});\n\nexport const ListLegendItem = memo(ListLegendItemBase);\n"],"names":["forwardRef","memo","useState","Box","ListItemText","ListItemButton","combineSx","LegendColorBadge","ListLegendItemBase","ListLegendItem","item","sx","truncateLabel","onClick","isVisuallySelected","onMouseOver","onMouseOut","index","others","ref","noWrap","setNoWrap","handleTextMouseOver","handleTextMouseOut","handleClick","e","id","role","padding","cursor","dense","selected","display","alignItems","color","primary","label","primaryTypographyProps"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,EAAEC,IAAI,EAA+CC,QAAQ,QAAQ,QAAQ;AAChG,SAASC,GAAG,EAAEC,YAAY,EAAiBC,cAAc,QAAQ,gBAAgB;AACjF,SAASC,SAAS,QAAQ,WAAW;AACrC,SAASC,gBAAgB,QAAQ,qBAAqB;AAwCtD,MAAMC,mCAAqBR,WAAgD,SAASS,eAClF,EAAEC,IAAI,EAAEC,EAAE,EAAEC,aAAa,EAAEC,OAAO,EAAEC,kBAAkB,EAAEC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAE,GAAGC,QAAQ,EACnGC,GAAG;IAEH,MAAM,CAACC,QAAQC,UAAU,GAAGnB,SAASU;IAErC,SAASU;QACP,IAAIV,eAAe;YACjBS,UAAU;QACZ;IACF;IAEA,SAASE;QACP,IAAIX,eAAe;YACjBS,UAAU;QACZ;IACF;IAEA,MAAMG,cAAiD,CAACC;QACtDZ,QAAQY,GAAGf,KAAKgB,EAAE;QAClBhB,KAAKG,OAAO,GAAGY;IACjB;IAEA,qBACE,MAACpB;QACE,GAAGa,MAAM;QACVS,MAAK;QACLhB,IAAIL,UACF;YACEsB,SAAS;YACTC,QAAQ;QACV,GACAlB;QAEFmB,OAAO;QACPjB,SAASW;QACTT,aAAa,CAACU,IAAkBV,cAAcU,GAAG;gBAAEC,IAAIhB,KAAKgB,EAAE;gBAAET;YAAM;QACtED,YAAY,CAACS,IAAkBT,aAAaS,GAAG;gBAAEC,IAAIhB,KAAKgB,EAAE;gBAAET;YAAM;QACpEc,UAAUjB;QACVK,KAAKA;;0BAEL,KAAChB;gBAAIQ,IAAI;oBAAEqB,SAAS;oBAAQC,YAAY;gBAAS;0BAC/C,cAAA,KAAC1B;oBAAiB2B,OAAOxB,KAAKwB,KAAK;;;0BAErC,KAAC9B;gBACC+B,SAASzB,KAAK0B,KAAK;gBACnBC,wBAAwB;oBAAEjB,QAAQA;gBAAO;gBACzCL,aAAaO;gBACbN,YAAYO;;;;AAIpB;AAEA,OAAO,MAAMd,+BAAiBR,KAAKO,oBAAoB"}
@@ -35,7 +35,6 @@ use([
35
35
  CanvasRenderer
36
36
  ]);
37
37
  export const LineChart = /*#__PURE__*/ forwardRef(function LineChart({ height, data, yAxis, format, grid, legend, tooltipConfig = DEFAULT_TOOLTIP_CONFIG, noDataVariant = 'message', syncGroup, onDataZoom, onDoubleClick, __experimentalEChartsOptionsOverride }, ref) {
38
- var _option_tooltip;
39
38
  const chartsTheme = useChartsTheme();
40
39
  const chartRef = useRef();
41
40
  const [showTooltip, setShowTooltip] = useState(true);
@@ -74,10 +73,8 @@ export const LineChart = /*#__PURE__*/ forwardRef(function LineChart({ height, d
74
73
  }, 10);
75
74
  }
76
75
  if (onDataZoom === undefined || params.batch[0] === undefined) return;
77
- var _params_batch__startValue;
78
- const startIndex = (_params_batch__startValue = params.batch[0].startValue) !== null && _params_batch__startValue !== void 0 ? _params_batch__startValue : 0;
79
- var _params_batch__endValue;
80
- const endIndex = (_params_batch__endValue = params.batch[0].endValue) !== null && _params_batch__endValue !== void 0 ? _params_batch__endValue : data.xAxis.length - 1;
76
+ const startIndex = params.batch[0].startValue ?? 0;
77
+ const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;
81
78
  const xAxisStartValue = data.xAxis[startIndex];
82
79
  const xAxisEndValue = data.xAxis[endIndex];
83
80
  if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {
@@ -105,8 +102,7 @@ export const LineChart = /*#__PURE__*/ forwardRef(function LineChart({ height, d
105
102
  // The "chart" `noDataVariant` is only used when the `timeSeries` is an
106
103
  // empty array because a `null` value will throw an error.
107
104
  if (data.timeSeries === null || data.timeSeries.length === 0 && noDataVariant === 'message') return noDataOption;
108
- var _data_rangeMs;
109
- const rangeMs = (_data_rangeMs = data.rangeMs) !== null && _data_rangeMs !== void 0 ? _data_rangeMs : getDateRange(data.xAxis);
105
+ const rangeMs = data.rangeMs ?? getDateRange(data.xAxis);
110
106
  const option = {
111
107
  series: data.timeSeries,
112
108
  xAxis: {
@@ -240,7 +236,7 @@ export const LineChart = /*#__PURE__*/ forwardRef(function LineChart({ height, d
240
236
  }
241
237
  },
242
238
  children: [
243
- showTooltip === true && ((_option_tooltip = option.tooltip) === null || _option_tooltip === void 0 ? void 0 : _option_tooltip.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ _jsx(LineChartTooltip, {
239
+ showTooltip === true && option.tooltip?.showContent === false && tooltipConfig.hidden !== true && /*#__PURE__*/ _jsx(LineChartTooltip, {
244
240
  chartRef: chartRef,
245
241
  chartData: data,
246
242
  wrapLabels: tooltipConfig.wrapLabels,