@perses-dev/components 0.34.0 → 0.35.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 (47) hide show
  1. package/dist/Drawer/Drawer.js +1 -1
  2. package/dist/Drawer/Drawer.js.map +1 -1
  3. package/dist/GaugeChart/GaugeChart.d.ts +1 -1
  4. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  5. package/dist/GaugeChart/GaugeChart.js +6 -3
  6. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  7. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  8. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  9. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts +36 -0
  10. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -0
  11. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +65 -0
  12. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -0
  13. package/dist/SettingsAutocomplete/index.d.ts +2 -0
  14. package/dist/SettingsAutocomplete/index.d.ts.map +1 -0
  15. package/dist/SettingsAutocomplete/index.js +15 -0
  16. package/dist/SettingsAutocomplete/index.js.map +1 -0
  17. package/dist/StatChart/StatChart.d.ts +2 -1
  18. package/dist/StatChart/StatChart.d.ts.map +1 -1
  19. package/dist/StatChart/StatChart.js +73 -20
  20. package/dist/StatChart/StatChart.js.map +1 -1
  21. package/dist/StatChart/calculateFontSize.d.ts +14 -0
  22. package/dist/StatChart/calculateFontSize.d.ts.map +1 -0
  23. package/dist/StatChart/calculateFontSize.js +47 -0
  24. package/dist/StatChart/calculateFontSize.js.map +1 -0
  25. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  26. package/dist/UnitSelector/UnitSelector.js +10 -22
  27. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  28. package/dist/YAxisLabel.js +1 -1
  29. package/dist/YAxisLabel.js.map +1 -1
  30. package/dist/cjs/Drawer/Drawer.js +1 -1
  31. package/dist/cjs/GaugeChart/GaugeChart.js +6 -3
  32. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  33. package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +66 -0
  34. package/dist/cjs/SettingsAutocomplete/index.js +28 -0
  35. package/dist/cjs/StatChart/StatChart.js +72 -19
  36. package/dist/cjs/StatChart/calculateFontSize.js +51 -0
  37. package/dist/cjs/UnitSelector/UnitSelector.js +9 -21
  38. package/dist/cjs/YAxisLabel.js +1 -1
  39. package/dist/cjs/index.js +1 -0
  40. package/dist/index.d.ts +1 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +1 -0
  43. package/dist/index.js.map +1 -1
  44. package/dist/model/theme.d.ts +3 -2
  45. package/dist/model/theme.d.ts.map +1 -1
  46. package/dist/model/theme.js.map +1 -1
  47. package/package.json +3 -3
@@ -13,7 +13,7 @@
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { Drawer as MuiDrawer } from '@mui/material';
15
15
  import { combineSx } from '../utils';
16
- const DRAWER_DEFAULT_WIDTH = 900;
16
+ const DRAWER_DEFAULT_WIDTH = 1080;
17
17
  export const Drawer = ({ anchor ='right' , isOpen , onClose , PaperProps , children , ...rest })=>{
18
18
  return /*#__PURE__*/ _jsx(MuiDrawer, {
19
19
  ...rest,
@@ -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 } from '@mui/material';\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 = 900;\n\nexport const Drawer = ({ anchor = 'right', isOpen, onClose, PaperProps, children, ...rest }: DrawerProps) => {\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: `${DRAWER_DEFAULT_WIDTH}px`,\n overflow: 'hidden',\n },\n PaperProps?.sx\n ),\n }}\n >\n {children}\n </MuiDrawer>\n );\n};\n"],"names":["Drawer","MuiDrawer","combineSx","DRAWER_DEFAULT_WIDTH","anchor","isOpen","onClose","PaperProps","children","rest","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;AAAA,SAASA,MAAM,IAAIC,SAAS,QAAuC,eAAe,CAAC;AACnF,SAASC,SAAS,QAAQ,UAAU,CAAC;AAQrC,MAAMC,oBAAoB,GAAG,GAAG,AAAC;AAEjC,OAAO,MAAMH,MAAM,GAAG,CAAC,EAAEI,MAAM,EAAG,OAAO,CAAA,EAAEC,MAAM,CAAA,EAAEC,OAAO,CAAA,EAAEC,UAAU,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAGC,IAAI,EAAe,GAAK;IAC3G,qBACE,KAACR,SAAS;QACP,GAAGQ,IAAI;QACRC,IAAI,EAAEL,MAAM;QACZC,OAAO,EAAEA,OAAO;QAChBF,MAAM,EAAEA,MAAM;QACdG,UAAU,EAAE;YACV,GAAGA,UAAU;YACbI,EAAE,EAAET,SAAS,CACX;gBACEU,KAAK,EAAE,CAAC,EAAET,oBAAoB,CAAC,EAAE,CAAC;gBAClCU,QAAQ,EAAE,QAAQ;aACnB,EACDN,UAAU,aAAVA,UAAU,WAAI,GAAdA,KAAAA,CAAc,GAAdA,UAAU,CAAEI,EAAE,CACf;SACF;kBAEAH,QAAQ;MACC,CACZ;AACJ,CAAC,CAAC"}
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 } from '@mui/material';\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 = ({ anchor = 'right', isOpen, onClose, PaperProps, children, ...rest }: DrawerProps) => {\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: `${DRAWER_DEFAULT_WIDTH}px`,\n overflow: 'hidden',\n },\n PaperProps?.sx\n ),\n }}\n >\n {children}\n </MuiDrawer>\n );\n};\n"],"names":["Drawer","MuiDrawer","combineSx","DRAWER_DEFAULT_WIDTH","anchor","isOpen","onClose","PaperProps","children","rest","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;AAAA,SAASA,MAAM,IAAIC,SAAS,QAAuC,eAAe,CAAC;AACnF,SAASC,SAAS,QAAQ,UAAU,CAAC;AAQrC,MAAMC,oBAAoB,GAAG,IAAI,AAAC;AAElC,OAAO,MAAMH,MAAM,GAAG,CAAC,EAAEI,MAAM,EAAG,OAAO,CAAA,EAAEC,MAAM,CAAA,EAAEC,OAAO,CAAA,EAAEC,UAAU,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAGC,IAAI,EAAe,GAAK;IAC3G,qBACE,KAACR,SAAS;QACP,GAAGQ,IAAI;QACRC,IAAI,EAAEL,MAAM;QACZC,OAAO,EAAEA,OAAO;QAChBF,MAAM,EAAEA,MAAM;QACdG,UAAU,EAAE;YACV,GAAGA,UAAU;YACbI,EAAE,EAAET,SAAS,CACX;gBACEU,KAAK,EAAE,CAAC,EAAET,oBAAoB,CAAC,EAAE,CAAC;gBAClCU,QAAQ,EAAE,QAAQ;aACnB,EACDN,UAAU,aAAVA,UAAU,WAAI,GAAdA,KAAAA,CAAc,GAAdA,UAAU,CAAEI,EAAE,CACf;SACF;kBAEAH,QAAQ;MACC,CACZ;AACJ,CAAC,CAAC"}
@@ -19,5 +19,5 @@ export declare function GaugeChart(props: GaugeChartProps): JSX.Element;
19
19
  * Responsive font size depending on number of characters, clamp used
20
20
  * to ensure size stays within given range
21
21
  */
22
- export declare function getResponsiveValueSize(value: number, unit: UnitOptions, width: number, height: number): string;
22
+ export declare function getResponsiveValueSize(value: number | null, unit: UnitOptions, width: number, height: number): string;
23
23
  //# sourceMappingURL=GaugeChart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GaugeChart.d.ts","sourceRoot":"","sources":["../../src/GaugeChart/GaugeChart.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAmC,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIpF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU1D,oBAAY,eAAe,GAAG,MAAM,GAAG,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AK,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAQ5G"}
@@ -35,7 +35,7 @@ export function GaugeChart(props) {
35
35
  // useDeepMemo ensures value size util does not rerun everytime you hover on the chart
36
36
  const option = useDeepMemo(()=>{
37
37
  var ref;
38
- if (data.value === undefined || data.value === null) return chartsTheme.noDataOption;
38
+ if (data.value === undefined) return chartsTheme.noDataOption;
39
39
  // adjusts fontSize depending on number of characters
40
40
  const valueSizeClamp = getResponsiveValueSize(data.value, unit, width, height);
41
41
  var ref1;
@@ -153,7 +153,10 @@ export function GaugeChart(props) {
153
153
  ],
154
154
  color: 'inherit',
155
155
  fontSize: valueSizeClamp,
156
- formatter: (value)=>{
156
+ formatter: data.value === null ? // at this level because the `formatter` function argument is `NaN`
157
+ // when the value is `null`, making it difficult to differentiate
158
+ // `null` from a true `NaN` case.
159
+ ()=>'null' : (value)=>{
157
160
  return formatValue(value, unit);
158
161
  }
159
162
  },
@@ -205,7 +208,7 @@ export function GaugeChart(props) {
205
208
  const MIN_SIZE = 3;
206
209
  const MAX_SIZE = 24;
207
210
  const SIZE_MULTIPLIER = 0.7;
208
- const formattedValue = formatValue(value, unit);
211
+ const formattedValue = typeof value === 'number' ? formatValue(value, unit) : `${value}`;
209
212
  var _length;
210
213
  const valueCharacters = (_length = formattedValue.length) !== null && _length !== void 0 ? _length : 2;
211
214
  const valueSize = Math.min(width, height) / valueCharacters * SIZE_MULTIPLIER;
@@ -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 { useDeepMemo } 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 { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\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 unit: UnitOptions;\n axisLine: GaugeSeriesOption['axisLine'];\n max?: number;\n}\n\nexport function GaugeChart(props: GaugeChartProps) {\n const { width, height, data, unit, 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 || data.value === null) return chartsTheme.noDataOption;\n\n // adjusts fontSize depending on number of characters\n const valueSizeClamp = getResponsiveValueSize(data.value, unit, 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, '#e1e5e9']], // 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: (value: number) => {\n return formatValue(value, unit);\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, unit, 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(value: number, unit: UnitOptions, width: number, height: number) {\n const MIN_SIZE = 3;\n const MAX_SIZE = 24;\n const SIZE_MULTIPLIER = 0.7;\n const formattedValue = formatValue(value, unit);\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":["useDeepMemo","use","GaugeChart","EChartsGaugeChart","GridComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","PROGRESS_WIDTH","GAUGE_SMALL_BREAKPOINT","props","width","height","data","unit","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;AAAA,SAASA,WAAW,QAAQ,kBAAkB,CAAC;AAC/C,SAASC,GAAG,QAA2B,cAAc,CAAC;AACtD,SAASC,UAAU,IAAIC,iBAAiB,QAA2B,gBAAgB,CAAC;AACpF,SAASC,aAAa,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,oBAAoB,CAAC;AACrF,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SAASC,WAAW,QAAqB,gBAAgB,CAAC;AAC1D,SAASC,MAAM,QAAQ,WAAW,CAAC;AAEnCT,GAAG,CAAC;IAACE,iBAAiB;IAAEC,aAAa;IAAEC,cAAc;IAAEC,gBAAgB;IAA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ACLkD,EAAE,EAAE;YACF9C,KAAK,EAAEA,KAAK;YACZC,MAAM,EAAEA,MAAM;YACd8C,OAAO,EAAE,CAAC,EAAEzC,WAAW,CAAC0C,SAAS,CAACD,OAAO,CAACE,OAAO,CAAC,EAAE,CAAC;SACtD;QACD1C,MAAM,EAAEA,MAAM;QACd2C,KAAK,EAAE5C,WAAW,CAACqC,YAAY;MAC/B,CACF;AACJ,CAAC;AAED;;;CAGC,GACD,OAAO,SAAS/B,sBAAsB,CAACJ,KAAa,EAAEL,IAAiB,EAAEH,KAAa,EAAEC,MAAc,EAAE;IACtG,MAAMkD,QAAQ,GAAG,CAAC,AAAC;IACnB,MAAMC,QAAQ,GAAG,EAAE,AAAC;IACpB,MAAMC,eAAe,GAAG,GAAG,AAAC;IAC5B,MAAMC,cAAc,GAAG3D,WAAW,CAACa,KAAK,EAAEL,IAAI,CAAC,AAAC;QACxBmD,OAAqB;IAA7C,MAAMC,eAAe,GAAGD,CAAAA,OAAqB,GAArBA,cAAc,CAACjB,MAAM,cAArBiB,OAAqB,cAArBA,OAAqB,GAAI,CAAC,AAAC;IACnD,MAAME,SAAS,GAAG,AAACC,IAAI,CAACnC,GAAG,CAACtB,KAAK,EAAEC,MAAM,CAAC,GAAGsD,eAAe,GAAIF,eAAe,AAAC;IAChF,OAAO,CAAC,MAAM,EAAEF,QAAQ,CAAC,IAAI,EAAEK,SAAS,CAAC,IAAI,EAAEJ,QAAQ,CAAC,GAAG,CAAC,CAAC;AAC/D,CAAC"}
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 { useDeepMemo } 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 { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\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 unit: UnitOptions;\n axisLine: GaugeSeriesOption['axisLine'];\n max?: number;\n}\n\nexport function GaugeChart(props: GaugeChartProps) {\n const { width, height, data, unit, 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, unit, 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, '#e1e5e9']], // 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 () => 'null'\n : (value: number) => {\n return formatValue(value, unit);\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, unit, 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(value: number | null, unit: UnitOptions, width: number, height: number) {\n const MIN_SIZE = 3;\n const MAX_SIZE = 24;\n const SIZE_MULTIPLIER = 0.7;\n const formattedValue = typeof value === 'number' ? formatValue(value, unit) : `${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":["useDeepMemo","use","GaugeChart","EChartsGaugeChart","GridComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","PROGRESS_WIDTH","GAUGE_SMALL_BREAKPOINT","props","width","height","data","unit","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;AAAA,SAASA,WAAW,QAAQ,kBAAkB,CAAC;AAC/C,SAASC,GAAG,QAA2B,cAAc,CAAC;AACtD,SAASC,UAAU,IAAIC,iBAAiB,QAA2B,gBAAgB,CAAC;AACpF,SAASC,aAAa,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,oBAAoB,CAAC;AACrF,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SAASC,WAAW,QAAqB,gBAAgB,CAAC;AAC1D,SAASC,MAA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  /*#__PURE__*/ _jsxs(Box, {
65
65
  sx: {
66
- width: '150px',
66
+ width: '180px',
67
67
  textAlign: 'right'
68
68
  },
69
69
  children: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/OptionsEditorLayout/OptionsEditorControl.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 { FormControl, FormLabel, FormControlLabelProps, Stack, Box, IconButton } from '@mui/material';\nimport React from 'react';\nimport InformationOutlineIcon from 'mdi-material-ui/InformationOutline';\nimport { useId } from '../utils';\nimport { InfoTooltip } from '../InfoTooltip';\n\nexport type OptionsEditorControlProps = Pick<FormControlLabelProps, 'label' | 'control'> & {\n description?: string;\n};\n\nexport const OptionsEditorControl = ({ label, control, description }: OptionsEditorControlProps) => {\n // Make sure we have a unique ID we can use for associating labels and\n // controls for a11y.\n const generatedControlId = useId('EditorSectionControl');\n const controlId = `${generatedControlId}-control`;\n\n const controlProps = {\n id: controlId,\n };\n\n return (\n <FormControl>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\">\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"center\">\n <FormLabel htmlFor={controlId}>{label}</FormLabel>\n {description && (\n <InfoTooltip description={description} enterDelay={100}>\n <IconButton\n size=\"small\"\n sx={(theme) => ({ borderRadius: theme.shape.borderRadius, padding: '4x', margin: '0 2px' })}\n >\n <InformationOutlineIcon\n aria-describedby=\"info-tooltip\"\n aria-hidden={false}\n fontSize=\"inherit\"\n sx={{ color: (theme) => theme.palette.grey[700] }}\n />\n </IconButton>\n </InfoTooltip>\n )}\n </Stack>\n <Box sx={{ width: '150px', textAlign: 'right' }}> {React.cloneElement(control, controlProps)}</Box>\n </Stack>\n </FormControl>\n );\n};\n"],"names":["FormControl","FormLabel","Stack","Box","IconButton","React","InformationOutlineIcon","useId","InfoTooltip","OptionsEditorControl","label","control","description","generatedControlId","controlId","controlProps","id","direction","alignItems","justifyContent","htmlFor","enterDelay","size","sx","theme","borderRadius","shape","padding","margin","aria-describedby","aria-hidden","fontSize","color","palette","grey","width","textAlign","cloneElement"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAyBC,KAAK,EAAEC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACtG,OAAOC,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAOC,sBAAsB,MAAM,oCAAoC,CAAC;AACxE,SAASC,KAAK,QAAQ,UAAU,CAAC;AACjC,SAASC,WAAW,QAAQ,gBAAgB,CAAC;AAM7C,OAAO,MAAMC,oBAAoB,GAAG,CAAC,EAAEC,KAAK,CAAA,EAAEC,OAAO,CAAA,EAAEC,WAAW,CAAA,EAA6B,GAAK;IAClG,sEAAsE;IACtE,qBAAqB;IACrB,MAAMC,kBAAkB,GAAGN,KAAK,CAAC,sBAAsB,CAAC,AAAC;IACzD,MAAMO,SAAS,GAAG,CAAC,EAAED,kBAAkB,CAAC,QAAQ,CAAC,AAAC;IAElD,MAAME,YAAY,GAAG;QACnBC,EAAE,EAAEF,SAAS;KACd,AAAC;IAEF,qBACE,KAACd,WAAW;kBACV,cAAA,MAACE,KAAK;YAACe,SAAS,EAAC,KAAK;YAACC,UAAU,EAAC,QAAQ;YAACC,cAAc,EAAC,eAAe;;8BACvE,MAACjB,KAAK;oBAACe,SAAS,EAAC,KAAK;oBAACC,UAAU,EAAC,QAAQ;oBAACC,cAAc,EAAC,QAAQ;;sCAChE,KAAClB,SAAS;4BAACmB,OAAO,EAAEN,SAAS;sCAAGJ,KAAK;0BAAa;wBACjDE,WAAW,kBACV,KAACJ,WAAW;4BAACI,WAAW,EAAEA,WAAW;4BAAES,UAAU,EAAE,GAAG;sCACpD,cAAA,KAACjB,UAAU;gCACTkB,IAAI,EAAC,OAAO;gCACZC,EAAE,EAAE,CAACC,KAAK,GAAM,CAAA;wCAAEC,YAAY,EAAED,KAAK,CAACE,KAAK,CAACD,YAAY;wCAAEE,OAAO,EAAE,IAAI;wCAAEC,MAAM,EAAE,OAAO;qCAAE,CAAA,AAAC;0CAE3F,cAAA,KAACtB,sBAAsB;oCACrBuB,kBAAgB,EAAC,cAAc;oCAC/BC,aAAW,EAAE,KAAK;oCAClBC,QAAQ,EAAC,SAAS;oCAClBR,EAAE,EAAE;wCAAES,KAAK,EAAE,CAACR,KAAK,GAAKA,KAAK,CAACS,OAAO,CAACC,IAAI,CAAC,GAAG,CAAC;qCAAE;kCACjD;8BACS;0BACD,AACf;;kBACK;8BACR,MAAC/B,GAAG;oBAACoB,EAAE,EAAE;wBAAEY,KAAK,EAAE,OAAO;wBAAEC,SAAS,EAAE,OAAO;qBAAE;;wBAAE,GAAC;sCAAC/B,KAAK,CAACgC,YAAY,CAAC1B,OAAO,EAAEI,YAAY,CAAC;;kBAAO;;UAC7F;MACI,CACd;AACJ,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../src/OptionsEditorLayout/OptionsEditorControl.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 { FormControl, FormLabel, FormControlLabelProps, Stack, Box, IconButton } from '@mui/material';\nimport React from 'react';\nimport InformationOutlineIcon from 'mdi-material-ui/InformationOutline';\nimport { useId } from '../utils';\nimport { InfoTooltip } from '../InfoTooltip';\n\nexport type OptionsEditorControlProps = Pick<FormControlLabelProps, 'label' | 'control'> & {\n description?: string;\n};\n\nexport const OptionsEditorControl = ({ label, control, description }: OptionsEditorControlProps) => {\n // Make sure we have a unique ID we can use for associating labels and\n // controls for a11y.\n const generatedControlId = useId('EditorSectionControl');\n const controlId = `${generatedControlId}-control`;\n\n const controlProps = {\n id: controlId,\n };\n\n return (\n <FormControl>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\">\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"center\">\n <FormLabel htmlFor={controlId}>{label}</FormLabel>\n {description && (\n <InfoTooltip description={description} enterDelay={100}>\n <IconButton\n size=\"small\"\n sx={(theme) => ({ borderRadius: theme.shape.borderRadius, padding: '4x', margin: '0 2px' })}\n >\n <InformationOutlineIcon\n aria-describedby=\"info-tooltip\"\n aria-hidden={false}\n fontSize=\"inherit\"\n sx={{ color: (theme) => theme.palette.grey[700] }}\n />\n </IconButton>\n </InfoTooltip>\n )}\n </Stack>\n <Box sx={{ width: '180px', textAlign: 'right' }}> {React.cloneElement(control, controlProps)}</Box>\n </Stack>\n </FormControl>\n );\n};\n"],"names":["FormControl","FormLabel","Stack","Box","IconButton","React","InformationOutlineIcon","useId","InfoTooltip","OptionsEditorControl","label","control","description","generatedControlId","controlId","controlProps","id","direction","alignItems","justifyContent","htmlFor","enterDelay","size","sx","theme","borderRadius","shape","padding","margin","aria-describedby","aria-hidden","fontSize","color","palette","grey","width","textAlign","cloneElement"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,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AA,AAAC;0CAE3F,cAAA,KAACtB,sBAAsB;oCACrBuB,kBAAgB,EAAC,cAAc;oCAC/BC,aAAW,EAAE,KAAK;oCAClBC,QAAQ,EAAC,SAAS;oCAClBR,EAAE,EAAE;wCAAES,KAAK,EAAE,CAACR,KAAK,GAAKA,KAAK,CAACS,OAAO,CAACC,IAAI,CAAC,GAAG,CAAC;qCAAE;kCACjD;8BACS;0BACD,AACf;;kBACK;8BACR,MAAC/B,GAAG;oBAACoB,EAAE,EAAE;wBAAEY,KAAK,EAAE,OAAO;wBAAEC,SAAS,EAAE,OAAO;qBAAE;;wBAAE,GAAC;sCAAC/B,KAAK,CAACgC,YAAY,CAAC1B,OAAO,EAAEI,YAAY,CAAC;;kBAAO;;UAC7F;MACI,CACd;AACJ,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { AutocompleteProps } from '@mui/material';
2
+ import { ReactNode } from 'react';
3
+ /**
4
+ * Interface to extend from for `options` when using `SettingsAutocomplete`.
5
+ */
6
+ export interface SettingsAutocompleteOption {
7
+ /**
8
+ * Unique identifier for the option.
9
+ */
10
+ id: string;
11
+ /**
12
+ * Optional value that is presented to the user for each option. If not set,
13
+ * the `id` will be used instead.
14
+ */
15
+ label?: string;
16
+ /**
17
+ * Optional description that will be rendered below the `label` to provide the
18
+ * user with additional information about the option.
19
+ */
20
+ description?: ReactNode;
21
+ /**
22
+ * When `true`, the option will be disabled.
23
+ */
24
+ disabled?: boolean;
25
+ }
26
+ export interface SettingsAutocompleteProps<OptionType extends SettingsAutocompleteOption, Multiple extends boolean | undefined, DisableClearable extends boolean | undefined> extends Omit<AutocompleteProps<OptionType, Multiple, DisableClearable, false>, 'renderInput'> {
27
+ renderInput?: AutocompleteProps<OptionType, Multiple, DisableClearable, false>['renderInput'];
28
+ }
29
+ /**
30
+ * Opinionated autocomplete component useful for providing users with a dropdown
31
+ * for settings that require selecting one or more options from a list.
32
+ *
33
+ * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
34
+ */
35
+ export declare function SettingsAutocomplete<OptionType extends SettingsAutocompleteOption, Multiple extends boolean | undefined = false, DisableClearable extends boolean | undefined = false>({ options, renderInput, ...otherProps }: SettingsAutocompleteProps<OptionType, Multiple, DisableClearable>): JSX.Element;
36
+ //# sourceMappingURL=SettingsAutocomplete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SettingsAutocomplete.d.ts","sourceRoot":"","sources":["../../src/SettingsAutocomplete/SettingsAutocomplete.tsx"],"names":[],"mappings":"AAaA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IAEX;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,yBAAyB,CACxC,UAAU,SAAS,0BAA0B,EAC7C,QAAQ,SAAS,OAAO,GAAG,SAAS,EACpC,gBAAgB,SAAS,OAAO,GAAG,SAAS,CAI5C,SAAQ,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,aAAa,CAAC;IAG7F,WAAW,CAAC,EAAE,iBAAiB,CAAC,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC,aAAa,CAAC,CAAC;CAC/F;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,SAAS,0BAA0B,EAC7C,QAAQ,SAAS,OAAO,GAAG,SAAS,GAAG,KAAK,EAC5C,gBAAgB,SAAS,OAAO,GAAG,SAAS,GAAG,KAAK,EACpD,EACA,OAAO,EACP,WAAmD,EACnD,GAAG,UAAU,EACd,EAAE,yBAAyB,CAAC,UAAU,EAAE,QAAQ,EAAE,gBAAgB,CAAC,eAyCnE"}
@@ -0,0 +1,65 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { Autocomplete, TextField, Typography, createFilterOptions } from '@mui/material';
15
+ /**
16
+ * Opinionated autocomplete component useful for providing users with a dropdown
17
+ * for settings that require selecting one or more options from a list.
18
+ *
19
+ * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
20
+ */ export function SettingsAutocomplete({ options , renderInput =(params)=>/*#__PURE__*/ _jsx(TextField, {
21
+ ...params
22
+ }) , ...otherProps }) {
23
+ const getOptionLabel = (option)=>{
24
+ var _label;
25
+ return (_label = option.label) !== null && _label !== void 0 ? _label : option.id;
26
+ };
27
+ // Note: this component currently is not virtualized because it is specific
28
+ // to being used for settings, which generally have a pretty small list of
29
+ // options. If this changes to include values with many options, virtualization
30
+ // should be added using react-virtuoso.
31
+ return /*#__PURE__*/ _jsx(Autocomplete, {
32
+ isOptionEqualToValue: (option, value)=>option.id === value.id,
33
+ getOptionDisabled: (option)=>!!option.disabled,
34
+ getOptionLabel: getOptionLabel,
35
+ options: options,
36
+ renderInput: renderInput,
37
+ renderOption: (props, option)=>{
38
+ return /*#__PURE__*/ _jsx("li", {
39
+ ...props,
40
+ children: /*#__PURE__*/ _jsxs("div", {
41
+ children: [
42
+ /*#__PURE__*/ _jsx(Typography, {
43
+ variant: "body1",
44
+ component: "div",
45
+ children: getOptionLabel(option)
46
+ }),
47
+ option.description && /*#__PURE__*/ _jsx(Typography, {
48
+ variant: "body2",
49
+ component: "div",
50
+ color: (theme)=>theme.palette.text.secondary,
51
+ children: option.description
52
+ })
53
+ ]
54
+ })
55
+ });
56
+ },
57
+ filterOptions: createFilterOptions({
58
+ // Include the label and the description in search.
59
+ stringify: (option)=>`${getOptionLabel(option)} ${option.description || ''}`
60
+ }),
61
+ ...otherProps
62
+ });
63
+ }
64
+
65
+ //# sourceMappingURL=SettingsAutocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/SettingsAutocomplete/SettingsAutocomplete.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 {\n Autocomplete,\n AutocompleteProps,\n TextField,\n Typography,\n UseAutocompleteProps,\n createFilterOptions,\n} from '@mui/material';\nimport { ReactNode } from 'react';\n\n/**\n * Interface to extend from for `options` when using `SettingsAutocomplete`.\n */\nexport interface SettingsAutocompleteOption {\n /**\n * Unique identifier for the option.\n */\n id: string;\n\n /**\n * Optional value that is presented to the user for each option. If not set,\n * the `id` will be used instead.\n */\n label?: string;\n\n /**\n * Optional description that will be rendered below the `label` to provide the\n * user with additional information about the option.\n */\n description?: ReactNode;\n\n /**\n * When `true`, the option will be disabled.\n */\n disabled?: boolean;\n}\n\nexport interface SettingsAutocompleteProps<\n OptionType extends SettingsAutocompleteOption,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined\n // Note that the last `false` in the generic arguments sets the `freeSolo` option to `false`.\n // This component is intended to be used with a discrete list of options, so `freeSolo` never\n // needs to be `true`.\n> extends Omit<AutocompleteProps<OptionType, Multiple, DisableClearable, false>, 'renderInput'> {\n // Modifying this to optional, so we can define a sensible default below that\n // is used in many of the simple cases.\n renderInput?: AutocompleteProps<OptionType, Multiple, DisableClearable, false>['renderInput'];\n}\n\n/**\n * Opinionated autocomplete component useful for providing users with a dropdown\n * for settings that require selecting one or more options from a list.\n *\n * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**\n */\nexport function SettingsAutocomplete<\n OptionType extends SettingsAutocompleteOption,\n Multiple extends boolean | undefined = false,\n DisableClearable extends boolean | undefined = false\n>({\n options,\n renderInput = (params) => <TextField {...params} />,\n ...otherProps\n}: SettingsAutocompleteProps<OptionType, Multiple, DisableClearable>) {\n const getOptionLabel: UseAutocompleteProps<OptionType, undefined, boolean, undefined>['getOptionLabel'] = (\n option\n ) => {\n return option.label ?? option.id;\n };\n\n // Note: this component currently is not virtualized because it is specific\n // to being used for settings, which generally have a pretty small list of\n // options. If this changes to include values with many options, virtualization\n // should be added using react-virtuoso.\n return (\n <Autocomplete\n isOptionEqualToValue={(option, value) => option.id === value.id}\n getOptionDisabled={(option) => !!option.disabled}\n getOptionLabel={getOptionLabel}\n options={options}\n renderInput={renderInput}\n renderOption={(props, option) => {\n return (\n <li {...props}>\n <div>\n <Typography variant=\"body1\" component=\"div\">\n {getOptionLabel(option)}\n </Typography>\n {option.description && (\n <Typography variant=\"body2\" component=\"div\" color={(theme) => theme.palette.text.secondary}>\n {option.description}\n </Typography>\n )}\n </div>\n </li>\n );\n }}\n filterOptions={createFilterOptions({\n // Include the label and the description in search.\n stringify: (option) => `${getOptionLabel(option)} ${option.description || ''}`,\n })}\n {...otherProps}\n />\n );\n}\n"],"names":["Autocomplete","TextField","Typography","createFilterOptions","SettingsAutocomplete","options","renderInput","params","otherProps","getOptionLabel","option","label","id","isOptionEqualToValue","value","getOptionDisabled","disabled","renderOption","props","li","div","variant","component","description","color","theme","palette","text","secondary","filterOptions","stringify"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SACEA,YAAY,EAEZC,SAAS,EACTC,UAAU,EAEVC,mBAAmB,QACd,eAAe,CAAC;AA2CvB;;;;;CAKC,GACD,OAAO,SAASC,oBAAoB,CAIlC,EACAC,OAAO,CAAA,EACPC,WAAW,EAAG,CAACC,MAAM,iBAAK,KAACN,SAAS;QAAE,GAAGM,MAAM;MAAI,CAAA,EACnD,GAAGC,UAAU,EACqD,EAAE;IACpE,MAAMC,cAAc,GAAsF,CACxGC,MAAM,GACH;YACIA,MAAY;QAAnB,OAAOA,CAAAA,MAAY,GAAZA,MAAM,CAACC,KAAK,cAAZD,MAAY,cAAZA,MAAY,GAAIA,MAAM,CAACE,EAAE,CAAC;IACnC,CAAC,AAAC;IAEF,2EAA2E;IAC3E,0EAA0E;IAC1E,+EAA+E;IAC/E,wCAAwC;IACxC,qBACE,KAACZ,YAAY;QACXa,oBAAoB,EAAE,CAACH,MAAM,EAAEI,KAAK,GAAKJ,MAAM,CAACE,EAAE,KAAKE,KAAK,CAACF,EAAE;QAC/DG,iBAAiB,EAAE,CAACL,MAAM,GAAK,CAAC,CAACA,MAAM,CAACM,QAAQ;QAChDP,cAAc,EAAEA,cAAc;QAC9BJ,OAAO,EAAEA,OAAO;QAChBC,WAAW,EAAEA,WAAW;QACxBW,YAAY,EAAE,CAACC,KAAK,EAAER,MAAM,GAAK;YAC/B,qBACE,KAACS,IAAE;gBAAE,GAAGD,KAAK;0BACX,cAAA,MAACE,KAAG;;sCACF,KAAClB,UAAU;4BAACmB,OAAO,EAAC,OAAO;4BAACC,SAAS,EAAC,KAAK;sCACxCb,cAAc,CAACC,MAAM,CAAC;0BACZ;wBACZA,MAAM,CAACa,WAAW,kBACjB,KAACrB,UAAU;4BAACmB,OAAO,EAAC,OAAO;4BAACC,SAAS,EAAC,KAAK;4BAACE,KAAK,EAAE,CAACC,KAAK,GAAKA,KAAK,CAACC,OAAO,CAACC,IAAI,CAACC,SAAS;sCACvFlB,MAAM,CAACa,WAAW;0BACR,AACd;;kBACG;cACH,CACL;QACJ,CAAC;QACDM,aAAa,EAAE1B,mBAAmB,CAAC;YACjC,mDAAmD;YACnD2B,SAAS,EAAE,CAACpB,MAAM,GAAK,CAAC,EAAED,cAAc,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEA,MAAM,CAACa,WAAW,IAAI,EAAE,CAAC,CAAC;SAC/E,CAAC;QACD,GAAGf,UAAU;MACd,CACF;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './SettingsAutocomplete';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/SettingsAutocomplete/index.ts"],"names":[],"mappings":"AAaA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './SettingsAutocomplete';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/SettingsAutocomplete/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './SettingsAutocomplete';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,wBAAwB,CAAC"}
@@ -3,7 +3,7 @@ import { LineSeriesOption } from 'echarts/charts';
3
3
  import { UnitOptions } from '../model/units';
4
4
  import { GraphSeries } from '../model/graph';
5
5
  export interface StatChartData {
6
- calculatedValue?: number;
6
+ calculatedValue?: number | null;
7
7
  seriesData?: GraphSeries;
8
8
  }
9
9
  export interface StatChartProps {
@@ -13,6 +13,7 @@ export interface StatChartProps {
13
13
  unit: UnitOptions;
14
14
  color?: string;
15
15
  sparkline?: LineSeriesOption;
16
+ showSeriesName?: boolean;
16
17
  }
17
18
  export declare function StatChart(props: StatChartProps): JSX.Element;
18
19
  //# sourceMappingURL=StatChart.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../../src/StatChart/StatChart.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIjF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAO7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAwG9C"}
1
+ {"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../../src/StatChart/StatChart.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIjF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAU7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAkI9C"}
@@ -12,7 +12,7 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useMemo } from 'react';
15
- import { Box, Typography } from '@mui/material';
15
+ import { Box, Typography, styled } from '@mui/material';
16
16
  import merge from 'lodash/merge';
17
17
  import { use } from 'echarts/core';
18
18
  import { LineChart as EChartsLineChart } from 'echarts/charts';
@@ -21,6 +21,7 @@ import { CanvasRenderer } from 'echarts/renderers';
21
21
  import { useChartsTheme } from '../context/ChartsThemeProvider';
22
22
  import { formatValue } from '../model/units';
23
23
  import { EChart } from '../EChart';
24
+ import { useOptimalFontSize } from './calculateFontSize';
24
25
  use([
25
26
  EChartsLineChart,
26
27
  GridComponent,
@@ -29,12 +30,48 @@ use([
29
30
  TooltipComponent,
30
31
  CanvasRenderer
31
32
  ]);
32
- const MIN_VALUE_SIZE = 12;
33
- const MAX_VALUE_SIZE = 36;
33
+ const LINE_HEIGHT = 1.2;
34
+ const SERIES_NAME_MAX_FONT_SIZE = 30;
35
+ const SERIES_NAME_FONT_WEIGHT = 400;
36
+ const VALUE_FONT_WEIGHT = 700;
34
37
  export function StatChart(props) {
35
- const { width , height , data , unit , color , sparkline } = props;
38
+ var ref, ref1;
39
+ const { width , height , data , unit , color , sparkline , showSeriesName } = props;
36
40
  const chartsTheme = useChartsTheme();
37
- const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);
41
+ let formattedValue = '';
42
+ if (data.calculatedValue === null) {
43
+ formattedValue = 'null';
44
+ } else if (typeof data.calculatedValue === 'number') {
45
+ formattedValue = formatValue(data.calculatedValue, unit);
46
+ }
47
+ const containerPadding = chartsTheme.container.padding.default;
48
+ var ref2;
49
+ // calculate series name font size and height
50
+ let seriesNameFontSize = useOptimalFontSize({
51
+ text: (ref2 = data === null || data === void 0 ? void 0 : (ref = data.seriesData) === null || ref === void 0 ? void 0 : ref.name) !== null && ref2 !== void 0 ? ref2 : '',
52
+ fontWeight: SERIES_NAME_FONT_WEIGHT,
53
+ width,
54
+ height: height * 0.125,
55
+ lineHeight: LINE_HEIGHT,
56
+ maxSize: SERIES_NAME_MAX_FONT_SIZE
57
+ });
58
+ const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;
59
+ // calculate value font size and height
60
+ const availableWidth = width - containerPadding * 2;
61
+ const availableHeight = height - seriesNameHeight;
62
+ const valueFontSize = useOptimalFontSize({
63
+ text: formattedValue,
64
+ fontWeight: VALUE_FONT_WEIGHT,
65
+ // without sparkline, use only 50% of the available width so it looks better for multiseries
66
+ width: sparkline ? availableWidth : availableWidth * 0.5,
67
+ // with sparkline, use only 25% of available height to leave room for chart
68
+ // without sparkline, value should take up 90% of available space
69
+ height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,
70
+ lineHeight: LINE_HEIGHT
71
+ });
72
+ const valueFontHeight = valueFontSize * LINE_HEIGHT;
73
+ // make sure the series name font size is slightly smaller than value font size
74
+ seriesNameFontSize = Math.min(valueFontSize * 0.7, seriesNameFontSize);
38
75
  const option = useMemo(()=>{
39
76
  if (data.seriesData === undefined) return chartsTheme.noDataOption;
40
77
  const series = data.seriesData;
@@ -42,9 +79,8 @@ export function StatChart(props) {
42
79
  if (sparkline !== undefined) {
43
80
  const lineSeries = {
44
81
  type: 'line',
45
- data: [
46
- ...series.values
47
- ],
82
+ name: series.name,
83
+ data: series.values,
48
84
  zlevel: 1,
49
85
  symbol: 'none',
50
86
  animation: false,
@@ -92,11 +128,6 @@ export function StatChart(props) {
92
128
  chartsTheme,
93
129
  sparkline
94
130
  ]);
95
- const isLargePanel = width > 250 && height > 180;
96
- // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
97
- const charactersAdjust = formattedValue.length;
98
- const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
99
- const containerPadding = `${chartsTheme.container.padding.default}px`;
100
131
  const textAlignment = sparkline ? 'auto' : 'center';
101
132
  const textStyles = {
102
133
  display: 'flex',
@@ -111,19 +142,22 @@ export function StatChart(props) {
111
142
  ...textStyles
112
143
  },
113
144
  children: [
114
- /*#__PURE__*/ _jsx(Typography, {
145
+ showSeriesName && /*#__PURE__*/ _jsx(SeriesName, {
146
+ padding: containerPadding,
147
+ fontSize: seriesNameFontSize,
148
+ children: (ref1 = data.seriesData) === null || ref1 === void 0 ? void 0 : ref1.name
149
+ }),
150
+ /*#__PURE__*/ _jsx(Value, {
115
151
  variant: "h3",
116
- sx: (theme)=>({
117
- color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
118
- fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
119
- padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
120
- }),
152
+ color: color,
153
+ fontSize: valueFontSize,
154
+ padding: containerPadding,
121
155
  children: formattedValue
122
156
  }),
123
157
  sparkline !== undefined && /*#__PURE__*/ _jsx(EChart, {
124
158
  sx: {
125
159
  width: '100%',
126
- height: '100%'
160
+ height: height - seriesNameHeight - valueFontHeight
127
161
  },
128
162
  option: option,
129
163
  theme: chartsTheme.echartsTheme,
@@ -132,5 +166,24 @@ export function StatChart(props) {
132
166
  ]
133
167
  });
134
168
  }
169
+ const SeriesName = styled(Typography, {
170
+ shouldForwardProp: (prop)=>prop !== 'padding' && prop !== 'fontSize'
171
+ })(({ theme , padding , fontSize })=>({
172
+ color: theme.palette.text.secondary,
173
+ padding: `${padding}px`,
174
+ fontSize: `${fontSize}px`,
175
+ overflow: 'hidden',
176
+ textOverflow: 'ellipsis',
177
+ whiteSpace: 'nowrap'
178
+ }));
179
+ const Value = styled(Typography, {
180
+ shouldForwardProp: (prop)=>prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline'
181
+ })(({ theme , color , padding , fontSize , sparkline })=>({
182
+ color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
183
+ fontSize: `${fontSize}px`,
184
+ padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,
185
+ whiteSpace: 'nowrap',
186
+ lineHeight: LINE_HEIGHT
187
+ }));
135
188
 
136
189
  //# sourceMappingURL=StatChart.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/StatChart/StatChart.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 { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport merge from 'lodash/merge';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n color?: string;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, color, sparkline } = props;\n const chartsTheme = useChartsTheme();\n\n const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\n const lineSeries = {\n type: 'line',\n data: [...series.values],\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n min: (value: { min: number; max: number }) => {\n if (value.min >= 0 && value.min <= 1) {\n // helps with PercentDecimal units, or datasets that return 0 or 1 booleans\n return 0;\n }\n return value.min;\n },\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const isLargePanel = width > 250 && height > 180;\n // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute\n const charactersAdjust = formattedValue.length;\n const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;\n\n const containerPadding = `${chartsTheme.container.padding.default}px`;\n\n const textAlignment = sparkline ? 'auto' : 'center';\n const textStyles = {\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n };\n\n return (\n <Box sx={{ height: '100%', width: '100%', ...textStyles }}>\n <Typography\n variant=\"h3\"\n sx={(theme) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,\n padding: sparkline\n ? `${containerPadding} ${containerPadding} 0 ${containerPadding}`\n : ` 0 ${containerPadding}`,\n })}\n >\n {formattedValue}\n </Typography>\n {sparkline !== undefined && (\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n}\n"],"names":["useMemo","Box","Typography","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","MIN_VALUE_SIZE","MAX_VALUE_SIZE","StatChart","props","width","height","data","unit","color","sparkline","chartsTheme","formattedValue","calculatedValue","undefined","option","seriesData","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","min","value","tooltip","isLargePanel","charactersAdjust","length","valueSize","Math","containerPadding","container","padding","default","textAlignment","textStyles","display","flexDirection","justifyContent","alignItems","sx","variant","theme","palette","text","primary","fontSize","echartsTheme","renderer"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAChD,OAAOC,KAAK,MAAM,cAAc,CAAC;AACjC,SAASC,GAAG,QAA2B,cAAc,CAAC;AACtD,SAASC,SAAS,IAAIC,gBAAgB,QAA0B,gBAAgB,CAAC;AACjF,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,gBAAgB,QAAQ,oBAAoB,CAAC;AACvG,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,cAAc,QAAQ,gCAAgC,CAAC;AAChE,SAASC,WAAW,QAAqB,gBAAgB,CAAC;AAC1D,SAASC,MAAM,QAAQ,WAAW,CAAC;AAGnCV,GAAG,CAAC;IAACE,gBAAgB;IAAEC,aAAa;IAAEC,gBAAgB;IAAEC,cAAc;IAAEC,gBAAgB;IAAEC,cAAc;CAAC,CAAC,CAAC;AAE3G,MAAMI,cAAc,GAAG,EAAE,AAAC;AAC1B,MAAMC,cAAc,GAAG,EAAE,AAAC;AAgB1B,OAAO,SAASC,SAAS,CAACC,KAAqB,EAAE;IAC/C,MAAM,EAAEC,KAAK,CAAA,EAAEC,MAAM,CAAA,EAAEC,IAAI,CAAA,EAAEC,IAAI,CAAA,EAAEC,KAAK,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAGN,KAAK,AAAC;IAC9D,MAAMO,WA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KAAK,EAAEA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAImD,KAAK,CAACC,OAAO,CAACC,IAAI,CAACC,OAAO;wBAC1CC,QAAQ,EAAE,CAAC,MAAM,EAAE/D,cAAc,CAAC,IAAI,EAAE6C,SAAS,CAAC,IAAI,EAAE5C,cAAc,CAAC,GAAG,CAAC;wBAC3EgD,OAAO,EAAExC,SAAS,GACd,CAAC,EAAEsC,gBAAgB,CAAC,CAAC,EAAEA,gBAAgB,CAAC,GAAG,EAAEA,gBAAgB,CAAC,CAAC,GAC/D,CAAC,GAAG,EAAEA,gBAAgB,CAAC,CAAC;qBAC7B,CAAA,AAAC;0BAEDpC,cAAc;cACJ;YACZF,SAAS,KAAKI,SAAS,kBACtB,KAACd,MAAM;gBACL0D,EAAE,EAAE;oBACFrD,KAAK,EAAE,MAAM;oBACbC,MAAM,EAAE,MAAM;iBACf;gBACDS,MAAM,EAAEA,MAAM;gBACd6C,KAAK,EAAEjD,WAAW,CAACsD,YAAY;gBAC/BC,QAAQ,EAAC,KAAK;cACd,AACH;;MACG,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/StatChart/StatChart.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 { useMemo } from 'react';\nimport { Box, Typography, styled } from '@mui/material';\nimport merge from 'lodash/merge';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { LineChart as EChartsLineChart, LineSeriesOption } from 'echarts/charts';\nimport { GridComponent, DatasetComponent, TitleComponent, TooltipComponent } from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { formatValue, UnitOptions } from '../model/units';\nimport { EChart } from '../EChart';\nimport { GraphSeries } from '../model/graph';\nimport { useOptimalFontSize } from './calculateFontSize';\n\nuse([EChartsLineChart, GridComponent, DatasetComponent, TitleComponent, TooltipComponent, CanvasRenderer]);\n\nconst LINE_HEIGHT = 1.2;\nconst SERIES_NAME_MAX_FONT_SIZE = 30;\nconst SERIES_NAME_FONT_WEIGHT = 400;\nconst VALUE_FONT_WEIGHT = 700;\n\nexport interface StatChartData {\n calculatedValue?: number | null;\n seriesData?: GraphSeries;\n}\n\nexport interface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n color?: string;\n sparkline?: LineSeriesOption;\n showSeriesName?: boolean;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, color, sparkline, showSeriesName } = props;\n const chartsTheme = useChartsTheme();\n\n let formattedValue = '';\n if (data.calculatedValue === null) {\n formattedValue = 'null';\n } else if (typeof data.calculatedValue === 'number') {\n formattedValue = formatValue(data.calculatedValue, unit);\n }\n\n const containerPadding = chartsTheme.container.padding.default;\n\n // calculate series name font size and height\n let seriesNameFontSize = useOptimalFontSize({\n text: data?.seriesData?.name ?? '',\n fontWeight: SERIES_NAME_FONT_WEIGHT,\n width,\n height: height * 0.125, // assume series name will take 12.5% of available height\n lineHeight: LINE_HEIGHT,\n maxSize: SERIES_NAME_MAX_FONT_SIZE,\n });\n const seriesNameHeight = showSeriesName ? seriesNameFontSize * LINE_HEIGHT + containerPadding : 0;\n\n // calculate value font size and height\n const availableWidth = width - containerPadding * 2;\n const availableHeight = height - seriesNameHeight;\n const valueFontSize = useOptimalFontSize({\n text: formattedValue,\n fontWeight: VALUE_FONT_WEIGHT,\n // without sparkline, use only 50% of the available width so it looks better for multiseries\n width: sparkline ? availableWidth : availableWidth * 0.5,\n // with sparkline, use only 25% of available height to leave room for chart\n // without sparkline, value should take up 90% of available space\n height: sparkline ? availableHeight * 0.25 : availableHeight * 0.9,\n lineHeight: LINE_HEIGHT,\n });\n const valueFontHeight = valueFontSize * LINE_HEIGHT;\n\n // make sure the series name font size is slightly smaller than value font size\n seriesNameFontSize = Math.min(valueFontSize * 0.7, seriesNameFontSize);\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.seriesData === undefined) return chartsTheme.noDataOption;\n\n const series = data.seriesData;\n const statSeries: LineSeriesOption[] = [];\n\n if (sparkline !== undefined) {\n const lineSeries = {\n type: 'line',\n name: series.name,\n data: series.values,\n zlevel: 1,\n symbol: 'none',\n animation: false,\n silent: true,\n };\n const mergedSeries = merge(lineSeries, sparkline);\n statSeries.push(mergedSeries);\n }\n\n const option = {\n title: {\n show: false,\n },\n grid: {\n show: false,\n top: '35%', // adds space above sparkline\n right: 0,\n bottom: 0,\n left: 0,\n containLabel: false,\n },\n xAxis: {\n type: 'time',\n show: false,\n boundaryGap: false,\n },\n yAxis: {\n type: 'value',\n show: false,\n min: (value: { min: number; max: number }) => {\n if (value.min >= 0 && value.min <= 1) {\n // helps with PercentDecimal units, or datasets that return 0 or 1 booleans\n return 0;\n }\n return value.min;\n },\n },\n tooltip: {\n show: false,\n },\n series: statSeries,\n };\n\n return option;\n }, [data, chartsTheme, sparkline]);\n\n const textAlignment = sparkline ? 'auto' : 'center';\n const textStyles = {\n display: 'flex',\n flexDirection: 'column',\n justifyContent: textAlignment,\n alignItems: textAlignment,\n };\n\n return (\n <Box sx={{ height: '100%', width: '100%', ...textStyles }}>\n {showSeriesName && (\n <SeriesName padding={containerPadding} fontSize={seriesNameFontSize}>\n {data.seriesData?.name}\n </SeriesName>\n )}\n <Value variant=\"h3\" color={color} fontSize={valueFontSize} padding={containerPadding}>\n {formattedValue}\n </Value>\n {sparkline !== undefined && (\n <EChart\n sx={{\n width: '100%',\n height: height - seriesNameHeight - valueFontHeight,\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n}\n\nconst SeriesName = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'padding' && prop !== 'fontSize',\n})<{ padding?: number; fontSize?: number; textAlignment?: string }>(({ theme, padding, fontSize }) => ({\n color: theme.palette.text.secondary,\n padding: `${padding}px`,\n fontSize: `${fontSize}px`,\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n whiteSpace: 'nowrap',\n}));\n\nconst Value = styled(Typography, {\n shouldForwardProp: (prop) => prop !== 'color' && prop !== 'padding' && prop !== 'fontSize' && prop !== 'sparkline',\n})<{ color?: string; padding?: number; fontSize?: number; sparkline?: boolean }>(\n ({ theme, color, padding, fontSize, sparkline }) => ({\n color: color ?? theme.palette.text.primary,\n fontSize: `${fontSize}px`,\n padding: sparkline ? `${padding}px ${padding}px 0 ${padding}px` : ` 0 ${padding}px`,\n whiteSpace: 'nowrap',\n lineHeight: LINE_HEIGHT,\n })\n);\n"],"names":["useMemo","Box","Typography","styled","merge","use","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","useOptimalFontSize","LINE_HEIGHT","SERIES_NAME_MAX_FONT_SIZE","SERIES_NAME_FONT_WEIGHT","VALUE_FONT_WEIGHT","StatChart","props","data","width","height","unit","color","sparkline","showSeriesName","chartsTheme","formattedValue","calculatedValue","containerPadding","container","padding","default","seriesNameFontSize","text","seriesData","name","fontWeight","lineHeight","maxSize","seriesNameHeight","availableWidth","availableHeight","valueFontSize","valueFontHeight","Math","min","option","undefined","noDataOption","series","statSeries","lineSeries","type","values","zlevel","symbol","animation","silent","mergedSeries","push","title","show","grid","top","right","bottom","left","containLabel","xAxis","boundaryGap","yAxis","value","tooltip","textAlignment","textStyles","display","flexDirection","justifyContent","alignItems","sx","SeriesName","fontSize","Value","variant","theme","echartsTheme","renderer","shouldForwardProp","prop","palette","secondary","overflow","textOverflow","whiteSpace","primary"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0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mD,QAAQ,CAAA,EAAE1D,SAAS,CAAA,EAAE,GAAM,CAAA;QACnDD,KAAK,EAAEA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI8D,KAAK,CAACK,OAAO,CAACxD,IAAI,CAAC6D,OAAO;QAC1Cb,QAAQ,EAAE,CAAC,EAAEA,QAAQ,CAAC,EAAE,CAAC;QACzBnD,OAAO,EAAEP,SAAS,GAAG,CAAC,EAAEO,OAAO,CAAC,GAAG,EAAEA,OAAO,CAAC,KAAK,EAAEA,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,EAAEA,OAAO,CAAC,EAAE,CAAC;QACnF+D,UAAU,EAAE,QAAQ;QACpBxD,UAAU,EAAEzB,WAAW;KACxB,CAAA,AAAC,CACH,AAAC"}
@@ -0,0 +1,14 @@
1
+ interface CalculateFontSize {
2
+ text: string;
3
+ fontWeight: number;
4
+ width: number;
5
+ height: number;
6
+ lineHeight: number;
7
+ maxSize?: number;
8
+ }
9
+ /**
10
+ * Find the optimal font size given available space
11
+ */
12
+ export declare function useOptimalFontSize({ text, fontWeight, width, height, lineHeight, maxSize }: CalculateFontSize): number;
13
+ export {};
14
+ //# sourceMappingURL=calculateFontSize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculateFontSize.d.ts","sourceRoot":"","sources":["../../src/StatChart/calculateFontSize.ts"],"names":[],"mappings":"AAeA,UAAU,iBAAiB;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAcD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,iBAAiB,UAqB7G"}