@perses-dev/components 0.22.0 → 0.23.1

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 (59) hide show
  1. package/README.md +2 -3
  2. package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts +2 -1
  3. package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts.map +1 -1
  4. package/dist/DateTimeRangePicker/AbsoluteTimePicker.js +87 -50
  5. package/dist/DateTimeRangePicker/AbsoluteTimePicker.js.map +1 -1
  6. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
  7. package/dist/DateTimeRangePicker/DateTimeRangePicker.js +2 -1
  8. package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
  9. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  10. package/dist/DateTimeRangePicker/TimeRangeSelector.js +3 -0
  11. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  12. package/dist/Dialog/Dialog.d.ts +24 -0
  13. package/dist/Dialog/Dialog.d.ts.map +1 -0
  14. package/dist/Dialog/Dialog.js +74 -0
  15. package/dist/Dialog/Dialog.js.map +1 -0
  16. package/dist/Dialog/index.d.ts +2 -0
  17. package/dist/Dialog/index.d.ts.map +1 -0
  18. package/dist/Dialog/index.js +15 -0
  19. package/dist/Dialog/index.js.map +1 -0
  20. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  21. package/dist/GaugeChart/GaugeChart.js +2 -1
  22. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  23. package/dist/StatChart/StatChart.d.ts.map +1 -1
  24. package/dist/StatChart/StatChart.js +20 -11
  25. package/dist/StatChart/StatChart.js.map +1 -1
  26. package/dist/cjs/DateTimeRangePicker/AbsoluteTimePicker.js +86 -49
  27. package/dist/cjs/DateTimeRangePicker/DateTimeRangePicker.js +2 -1
  28. package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +3 -0
  29. package/dist/cjs/Dialog/Dialog.js +85 -0
  30. package/dist/cjs/Dialog/index.js +28 -0
  31. package/dist/cjs/GaugeChart/GaugeChart.js +2 -1
  32. package/dist/cjs/StatChart/StatChart.js +20 -11
  33. package/dist/cjs/index.js +1 -0
  34. package/dist/cjs/model/units/decimal.js +4 -1
  35. package/dist/cjs/model/units/units.test.js +54 -0
  36. package/dist/cjs/test-utils/theme.js +5 -0
  37. package/dist/cjs/utils/theme-gen.js +5 -0
  38. package/dist/cjs/utils/theme-gen.test.js +5 -0
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +1 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/model/theme.d.ts +11 -0
  44. package/dist/model/theme.d.ts.map +1 -1
  45. package/dist/model/theme.js.map +1 -1
  46. package/dist/model/units/decimal.d.ts.map +1 -1
  47. package/dist/model/units/decimal.js +4 -1
  48. package/dist/model/units/decimal.js.map +1 -1
  49. package/dist/model/units/units.test.js +54 -0
  50. package/dist/model/units/units.test.js.map +1 -1
  51. package/dist/test-utils/theme.d.ts.map +1 -1
  52. package/dist/test-utils/theme.js +5 -0
  53. package/dist/test-utils/theme.js.map +1 -1
  54. package/dist/utils/theme-gen.d.ts.map +1 -1
  55. package/dist/utils/theme-gen.js +5 -0
  56. package/dist/utils/theme-gen.js.map +1 -1
  57. package/dist/utils/theme-gen.test.js +5 -0
  58. package/dist/utils/theme-gen.test.js.map +1 -1
  59. package/package.json +3 -3
@@ -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\ninterface 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 }}\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","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;IAAEC,cAAc;CAAC,CAAC,CAAC;AAE1F,MAAMI,cAAc,GAAG,EAAE,AAA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MAAM;SACf;QACDM,MAAM,EAAEA,MAAM;QACdwC,KAAK,EAAEzC,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,MAAM+C,QAAQ,GAAG,CAAC,AAAC;IACnB,MAAMC,QAAQ,GAAG,EAAE,AAAC;IACpB,MAAMC,eAAe,GAAG,GAAG,AAAC;IAC5B,MAAMC,cAAc,GAAGxD,WAAW,CAACa,KAAK,EAAEL,IAAI,CAAC,AAAC;QACxBgD,OAAqB;IAA7C,MAAMC,eAAe,GAAGD,CAAAA,OAAqB,GAArBA,cAAc,CAACd,MAAM,cAArBc,OAAqB,cAArBA,OAAqB,GAAI,CAAC,AAAC;IACnD,MAAME,SAAS,GAAG,AAACC,IAAI,CAAChC,GAAG,CAACtB,KAAK,EAAEC,MAAM,CAAC,GAAGmD,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\ninterface 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;IAAEC,cAAc;CAAC,CAAC,CAAC;AAE1F,MAAMI,cAAc,GAAG,EAAE,AAAC;AAE1B,oCAAoC;AACpC,MAAMC,sBAAsB,GAAG,GAAG,AAAC;AAkBnC,OAAO,SAASV,UAAU,CAACW,KAAsB,EAAE;IACjD,MAAM,EAAEC,KAAK,CAA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;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAwF9C"}
1
+ {"version":3,"file":"StatChart.d.ts","sourceRoot":"","sources":["../../src/StatChart/StatChart.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAiC,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIjF,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAe7C,MAAM,WAAW,aAAa;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,WAAW,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,UAAU,cAAc;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eA0F9C"}
@@ -31,7 +31,6 @@ use([
31
31
  TooltipComponent,
32
32
  CanvasRenderer
33
33
  ]);
34
- const PANEL_PADDING = 32;
35
34
  const MIN_VALUE_SIZE = 12;
36
35
  const MAX_VALUE_SIZE = 36;
37
36
  export function StatChart(props) {
@@ -92,27 +91,37 @@ export function StatChart(props) {
92
91
  // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
93
92
  const charactersAdjust = formattedValue.length;
94
93
  const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
94
+ const containerPadding = `${chartsTheme.container.padding.default}px`;
95
95
  return /*#__PURE__*/ _jsxs(Box, {
96
+ sx: {
97
+ height: '100%',
98
+ width: '100%',
99
+ display: 'flex',
100
+ flexDirection: 'column'
101
+ },
96
102
  children: [
97
103
  /*#__PURE__*/ _jsx(Typography, {
98
104
  variant: "h3",
99
105
  sx: (theme)=>({
100
106
  color: theme.palette.text.primary,
101
- fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`
107
+ fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
108
+ padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`
102
109
  }),
103
110
  children: formattedValue
104
111
  }),
105
- sparkline !== undefined && /*#__PURE__*/ _jsx(EChart, {
112
+ sparkline !== undefined && /*#__PURE__*/ _jsx(Box, {
106
113
  sx: {
107
- width: width + PANEL_PADDING,
108
- height: height,
109
- position: 'absolute',
110
- bottom: 0,
111
- left: 0
114
+ flex: 1
112
115
  },
113
- option: option,
114
- theme: chartsTheme.echartsTheme,
115
- renderer: "svg"
116
+ children: /*#__PURE__*/ _jsx(EChart, {
117
+ sx: {
118
+ width: '100%',
119
+ height: '100%'
120
+ },
121
+ option: option,
122
+ theme: chartsTheme.echartsTheme,
123
+ renderer: "svg"
124
+ })
116
125
  })
117
126
  ]
118
127
  });
@@ -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 React, { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { GaugeChart as EChartsGaugeChart, GaugeSeriesOption } from 'echarts/charts';\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([\n EChartsGaugeChart,\n EChartsLineChart,\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\nconst PANEL_PADDING = 32;\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n name?: string;\n}\n\ninterface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, 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\n const statSeries: Array<GaugeSeriesOption | LineSeriesOption> = [];\n\n if (sparkline !== undefined) {\n const lineSeries: LineSeriesOption = {\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 },\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 return (\n <Box>\n <Typography\n variant=\"h3\"\n sx={(theme) => ({\n color: theme.palette.text.primary,\n fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,\n })}\n >\n {formattedValue}\n </Typography>\n {sparkline !== undefined && (\n <EChart\n sx={{\n width: width + PANEL_PADDING, // allows sparkline to extend to edge of panel\n height: height,\n position: 'absolute',\n bottom: 0,\n left: 0,\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n )}\n </Box>\n );\n}\n"],"names":["React","useMemo","Box","Typography","merge","use","GaugeChart","EChartsGaugeChart","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","PANEL_PADDING","MIN_VALUE_SIZE","MAX_VALUE_SIZE","StatChart","props","width","height","data","unit","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","tooltip","isLargePanel","charactersAdjust","length","valueSize","Math","min","variant","sx","theme","color","palette","text","primary","fontSize","position","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,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO,CAAC;AACvC,SAASC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAChD,SAASC,KAAK,QAAQ,WAAW,CAAC;AAClC,SAASC,GAAG,QAA2B,cAAc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,MAAM,CAAC,GAAGmC,gBAAgB,AAAC;IAEtG,qBACE,MAACzD,GAAG;;0BACF,KAACC,UAAU;gBACT6D,OAAO,EAAC,IAAI;gBACZC,EAAE,EAAE,CAACC,KAAK,GAAM,CAAA;wBACdC,KAAK,EAAED,KAAK,CAACE,OAAO,CAACC,IAAI,CAACC,OAAO;wBACjCC,QAAQ,EAAE,CAAC,MAAM,EAAEpD,cAAc,CAAC,IAAI,EAAE0C,SAAS,CAAC,IAAI,EAAEzC,cAAc,CAAC,GAAG,CAAC;qBAC5E,CAAA,AAAC;0BAEDS,cAAc;cACJ;YACZF,SAAS,KAAKI,SAAS,kBACtB,KAACd,MAAM;gBACLgD,EAAE,EAAE;oBACF1C,KAAK,EAAEA,KAAK,GAAGL,aAAa;oBAC5BM,MAAM,EAAEA,MAAM;oBACdgD,QAAQ,EAAE,UAAU;oBACpBrB,MAAM,EAAE,CAAC;oBACTC,IAAI,EAAE,CAAC;iBACR;gBACDpB,MAAM,EAAEA,MAAM;gBACdkC,KAAK,EAAEtC,WAAW,CAAC6C,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 React, { useMemo } from 'react';\nimport { Box, Typography } from '@mui/material';\nimport { merge } from 'lodash-es';\nimport { use, EChartsCoreOption } from 'echarts/core';\nimport { GaugeChart as EChartsGaugeChart, GaugeSeriesOption } from 'echarts/charts';\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([\n EChartsGaugeChart,\n EChartsLineChart,\n GridComponent,\n DatasetComponent,\n TitleComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\nconst MIN_VALUE_SIZE = 12;\nconst MAX_VALUE_SIZE = 36;\n\nexport interface StatChartData {\n calculatedValue?: number;\n seriesData?: GraphSeries;\n name?: string;\n}\n\ninterface StatChartProps {\n width: number;\n height: number;\n data: StatChartData;\n unit: UnitOptions;\n sparkline?: LineSeriesOption;\n}\n\nexport function StatChart(props: StatChartProps) {\n const { width, height, data, unit, 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\n const statSeries: Array<GaugeSeriesOption | LineSeriesOption> = [];\n\n if (sparkline !== undefined) {\n const lineSeries: LineSeriesOption = {\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 },\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 return (\n <Box sx={{ height: '100%', width: '100%', display: 'flex', flexDirection: 'column' }}>\n <Typography\n variant=\"h3\"\n sx={(theme) => ({\n color: theme.palette.text.primary,\n fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,\n padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`,\n })}\n >\n {formattedValue}\n </Typography>\n {sparkline !== undefined && (\n <Box sx={{ flex: 1 }}>\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n renderer=\"svg\"\n />\n </Box>\n )}\n </Box>\n );\n}\n"],"names":["React","useMemo","Box","Typography","merge","use","GaugeChart","EChartsGaugeChart","LineChart","EChartsLineChart","GridComponent","DatasetComponent","TitleComponent","TooltipComponent","CanvasRenderer","useChartsTheme","formatValue","EChart","MIN_VALUE_SIZE","MAX_VALUE_SIZE","StatChart","props","width","height","data","unit","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","tooltip","isLargePanel","charactersAdjust","length","valueSize","Math","min","containerPadding","container","padding","default","sx","display","flexDirection","variant","theme","color","palette","text","primary","fontSize","flex","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,OAAOA,KAAK,IAAIC,OAAO,QAAQ,OAAO,CAAC;AACvC,SAASC,GAAG,EAAEC,UAAU,QA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Ac,GAAG0C,IAAI,CAACC,GAAG,CAACxC,KAAK,EAAEC,MAAM,CAAC,GAAGmC,gBAAgB,AAAC;IAEtG,MAAMK,gBAAgB,GAAG,CAAC,EAAEpC,WAAW,CAACqC,SAAS,CAACC,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC,AAAC;IAEtE,qBACE,MAAChE,GAAG;QAACiE,EAAE,EAAE;YAAE5C,MAAM,EAAE,MAAM;YAAED,KAAK,EAAE,MAAM;YAAE8C,OAAO,EAAE,MAAM;YAAEC,aAAa,EAAE,QAAQ;SAAE;;0BAClF,KAAClE,UAAU;gBACTmE,OAAO,EAAC,IAAI;gBACZH,EAAE,EAAE,CAACI,KAAK,GAAM,CAAA;wBACdC,KAAK,EAAED,KAAK,CAACE,OAAO,CAACC,IAAI,CAACC,OAAO;wBACjCC,QAAQ,EAAE,CAAC,MAAM,EAAE1D,cAAc,CAAC,IAAI,EAAE0C,SAAS,CAAC,IAAI,EAAEzC,cAAc,CAAC,GAAG,CAAC;wBAC3E8C,OAAO,EAAE,CAAC,EAAEF,gBAAgB,CAAC,CAAC,EAAEA,gBAAgB,CAAC,GAAG,EAAEA,gBAAgB,CAAC,CAAC;qBACzE,CAAA,AAAC;0BAEDnC,cAAc;cACJ;YACZF,SAAS,KAAKI,SAAS,kBACtB,KAAC5B,GAAG;gBAACiE,EAAE,EAAE;oBAAEU,IAAI,EAAE,CAAC;iBAAE;0BAClB,cAAA,KAAC5D,MAAM;oBACLkD,EAAE,EAAE;wBACF7C,KAAK,EAAE,MAAM;wBACbC,MAAM,EAAE,MAAM;qBACf;oBACDQ,MAAM,EAAEA,MAAM;oBACdwC,KAAK,EAAE5C,WAAW,CAACmD,YAAY;oBAC/BC,QAAQ,EAAC,KAAK;kBACd;cACE,AACP;;MACG,CACN;AACJ,CAAC"}
@@ -26,37 +26,60 @@ const _adapterDateFns = require("@mui/x-date-pickers/AdapterDateFns");
26
26
  const _timeZoneProvider = require("../context/TimeZoneProvider");
27
27
  const _utils = require("./utils");
28
28
  const DATE_TIME_FORMAT = 'yyyy-MM-dd HH:mm:ss';
29
- const AbsoluteTimePicker = ({ initialTimeRange , onChange })=>{
29
+ const AbsoluteTimePicker = ({ initialTimeRange , onChange , onCancel })=>{
30
+ const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
31
+ // Time range values as dates that can be used as a time range.
30
32
  const [timeRange, setTimeRange] = (0, _react.useState)(initialTimeRange);
33
+ // Time range values as strings used to populate the text inputs. May not
34
+ // be valid as dates when the user is typing.
35
+ const [timeRangeInputs, setTimeRangeInputs] = (0, _react.useState)({
36
+ start: formatWithUserTimeZone(initialTimeRange.start, DATE_TIME_FORMAT),
37
+ end: formatWithUserTimeZone(initialTimeRange.end, DATE_TIME_FORMAT)
38
+ });
31
39
  const [showStartCalendar, setShowStartCalendar] = (0, _react.useState)(true);
32
- const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
33
- // validate start and end time, propagate changes
34
- const updateDateRange = (input, isStartDate)=>{
35
- const newDate = new Date(input);
36
- if (isStartDate === true) {
37
- const isValidDateRange = (0, _utils.validateDateRange)(newDate, timeRange.end);
38
- if (isValidDateRange === true) {
39
- setTimeRange((current)=>{
40
- const updatedRange = {
41
- start: newDate,
42
- end: current.end
43
- };
44
- onChange(updatedRange);
45
- return updatedRange;
46
- });
47
- }
48
- } else {
49
- const isValidDateRange1 = (0, _utils.validateDateRange)(timeRange.start, newDate);
50
- if (isValidDateRange1 === true) {
51
- setTimeRange((current)=>{
52
- const updatedRange = {
53
- start: current.start,
54
- end: newDate
55
- };
56
- onChange(updatedRange);
57
- return updatedRange;
58
- });
59
- }
40
+ const changeTimeRange = (newTime, segment)=>{
41
+ const isInputChange = typeof newTime === 'string';
42
+ const newInputTime = isInputChange ? newTime : formatWithUserTimeZone(newTime, DATE_TIME_FORMAT);
43
+ setTimeRangeInputs((prevTimeRangeInputs)=>{
44
+ return {
45
+ ...prevTimeRangeInputs,
46
+ [segment]: newInputTime
47
+ };
48
+ });
49
+ // When the change is a string from an input, do not try to convert it to
50
+ // a date because there are likely to be interim stages of editing where it
51
+ // is not valid as a date. When the change is a Date from the calendar/clock
52
+ // interface, we can be sure it is a date.
53
+ if (!isInputChange) {
54
+ setTimeRange((prevTimeRange)=>{
55
+ return {
56
+ ...prevTimeRange,
57
+ [segment]: newTime
58
+ };
59
+ });
60
+ }
61
+ };
62
+ const onChangeStartTime = (newStartTime)=>{
63
+ changeTimeRange(newStartTime, 'start');
64
+ };
65
+ const onChangeEndTime = (newEndTime)=>{
66
+ changeTimeRange(newEndTime, 'end');
67
+ };
68
+ const updateDateRange = ()=>{
69
+ const newDates = {
70
+ start: new Date(timeRangeInputs.start),
71
+ end: new Date(timeRangeInputs.end)
72
+ };
73
+ const isValidDateRange = (0, _utils.validateDateRange)(newDates.start, newDates.end);
74
+ if (isValidDateRange) {
75
+ setTimeRange(newDates);
76
+ return newDates;
77
+ }
78
+ };
79
+ const onApply = ()=>{
80
+ const newDates = updateDateRange();
81
+ if (newDates) {
82
+ onChange(newDates);
60
83
  }
61
84
  };
62
85
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_xDatePickers.LocalizationProvider, {
@@ -93,12 +116,7 @@ const AbsoluteTimePicker = ({ initialTimeRange , onChange })=>{
93
116
  value: initialTimeRange.start,
94
117
  onChange: (newValue)=>{
95
118
  if (newValue === null) return;
96
- setTimeRange((current)=>{
97
- return {
98
- start: newValue,
99
- end: current.end
100
- };
101
- });
119
+ onChangeStartTime(newValue);
102
120
  },
103
121
  onAccept: ()=>{
104
122
  setShowStartCalendar(false);
@@ -135,16 +153,12 @@ const AbsoluteTimePicker = ({ initialTimeRange , onChange })=>{
135
153
  minDateTime: timeRange.start,
136
154
  onChange: (newValue)=>{
137
155
  if (newValue === null) return;
138
- setTimeRange((current)=>{
139
- return {
140
- start: current.start,
141
- end: newValue
142
- };
143
- });
156
+ onChangeEndTime(newValue);
144
157
  },
145
- onAccept: ()=>{
158
+ onAccept: (newValue)=>{
159
+ if (newValue === null) return;
146
160
  setShowStartCalendar(true);
147
- onChange(timeRange);
161
+ onChangeEndTime(newValue);
148
162
  },
149
163
  renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
150
164
  ...params
@@ -162,24 +176,47 @@ const AbsoluteTimePicker = ({ initialTimeRange , onChange })=>{
162
176
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
163
177
  onChange: (event)=>{
164
178
  // TODO: add helperText, fix validation after we decide on form state solution
165
- updateDateRange(event.target.value, true);
179
+ onChangeStartTime(event.target.value);
166
180
  },
167
- value: formatWithUserTimeZone(timeRange.start, DATE_TIME_FORMAT),
181
+ onBlur: ()=>updateDateRange(),
182
+ value: timeRangeInputs.start,
168
183
  label: "Start Time",
169
- placeholder: "mm/dd/yyyy hh:mm",
184
+ placeholder: DATE_TIME_FORMAT,
170
185
  // tel used to match MUI DateTimePicker, may change in future: https://github.com/mui/material-ui/issues/27590
171
186
  type: "tel"
172
187
  }),
173
188
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
174
189
  onChange: (event)=>{
175
- updateDateRange(event.target.value, false);
190
+ onChangeEndTime(event.target.value);
176
191
  },
177
- value: formatWithUserTimeZone(timeRange.end, DATE_TIME_FORMAT),
192
+ onBlur: ()=>updateDateRange(),
193
+ value: timeRangeInputs.end,
178
194
  label: "End Time",
179
- placeholder: "mm/dd/yyyy hh:mm",
195
+ placeholder: DATE_TIME_FORMAT,
180
196
  type: "tel"
181
197
  })
182
198
  ]
199
+ }),
200
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
201
+ direction: "row",
202
+ sx: {
203
+ padding: (theme)=>theme.spacing(0, 1)
204
+ },
205
+ gap: 1,
206
+ children: [
207
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
208
+ variant: "contained",
209
+ onClick: ()=>onApply(),
210
+ fullWidth: true,
211
+ children: "Apply"
212
+ }),
213
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
214
+ variant: "outlined",
215
+ onClick: ()=>onCancel(),
216
+ fullWidth: true,
217
+ children: "Cancel"
218
+ })
219
+ ]
183
220
  })
184
221
  ]
185
222
  })
@@ -54,7 +54,8 @@ function DateTimeRangePicker(props) {
54
54
  onChange: (value)=>{
55
55
  onChange(value);
56
56
  setShowCustomDateSelector(false);
57
- }
57
+ },
58
+ onCancel: ()=>setShowCustomDateSelector(false)
58
59
  })
59
60
  }),
60
61
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControl, {
@@ -38,6 +38,9 @@ function TimeRangeSelector(props) {
38
38
  value: formattedValue,
39
39
  onChange: onSelectChange,
40
40
  IconComponent: _calendar.default,
41
+ inputProps: {
42
+ 'aria-label': `Select time range. Currently set to ${formattedValue}`
43
+ },
41
44
  sx: {
42
45
  '.MuiSelect-icon': {
43
46
  marginTop: '1px'
@@ -0,0 +1,85 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "Dialog", {
18
+ enumerable: true,
19
+ get: ()=>Dialog
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
23
+ const _material = require("@mui/material");
24
+ const _close = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Close"));
25
+ const _utils = require("../utils");
26
+ function _interopRequireDefault(obj) {
27
+ return obj && obj.__esModule ? obj : {
28
+ default: obj
29
+ };
30
+ }
31
+ const Header = ({ children , onClose , ...props })=>{
32
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
33
+ children: [
34
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogTitle, {
35
+ ...props,
36
+ children: children
37
+ }),
38
+ onClose && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
39
+ "aria-label": "Close",
40
+ onClick: onClose,
41
+ sx: dialogCloseIconButtonStyle,
42
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_close.default, {})
43
+ })
44
+ ]
45
+ });
46
+ };
47
+ const Content = ({ children , width =500 , sx , ...props })=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogContent, {
48
+ dividers: true,
49
+ ...props,
50
+ sx: (0, _utils.combineSx)({
51
+ width: `${width}px`
52
+ }, sx),
53
+ children: children
54
+ });
55
+ const PrimaryButton = ({ children , ...props })=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
56
+ variant: "contained",
57
+ type: "submit",
58
+ ...props,
59
+ children: children
60
+ });
61
+ const SecondaryButton = ({ children , ...props })=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
62
+ variant: "outlined",
63
+ color: "secondary",
64
+ ...props,
65
+ children: children
66
+ });
67
+ /**
68
+ * Render the CSS of the dialog's close button, according to the given material theme.
69
+ * @param theme material theme
70
+ */ const dialogCloseIconButtonStyle = (theme)=>{
71
+ return {
72
+ position: 'absolute',
73
+ top: theme.spacing(0.5),
74
+ right: theme.spacing(0.5)
75
+ };
76
+ };
77
+ const Dialog = ({ children , ...props })=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Dialog, {
78
+ ...props,
79
+ children: children
80
+ });
81
+ Dialog.Header = Header;
82
+ Dialog.Content = Content;
83
+ Dialog.PrimaryButton = PrimaryButton;
84
+ Dialog.SecondaryButton = SecondaryButton;
85
+ Dialog.Actions = _material.DialogActions;
@@ -0,0 +1,28 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./Dialog"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -205,7 +205,8 @@ function GaugeChart(props) {
205
205
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
206
206
  sx: {
207
207
  width: width,
208
- height: height
208
+ height: height,
209
+ padding: `${chartsTheme.container.padding.default}px`
209
210
  },
210
211
  option: option,
211
212
  theme: chartsTheme.echartsTheme
@@ -77,7 +77,6 @@ function _interopRequireWildcard(obj, nodeInterop) {
77
77
  _components.TooltipComponent,
78
78
  _renderers.CanvasRenderer
79
79
  ]);
80
- const PANEL_PADDING = 32;
81
80
  const MIN_VALUE_SIZE = 12;
82
81
  const MAX_VALUE_SIZE = 36;
83
82
  function StatChart(props) {
@@ -138,27 +137,37 @@ function StatChart(props) {
138
137
  // adjusts fontSize depending on number of characters, clamp also used in fontSize attribute
139
138
  const charactersAdjust = formattedValue.length;
140
139
  const valueSize = isLargePanel === true ? MAX_VALUE_SIZE : Math.min(width, height) / charactersAdjust;
140
+ const containerPadding = `${chartsTheme.container.padding.default}px`;
141
141
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
142
+ sx: {
143
+ height: '100%',
144
+ width: '100%',
145
+ display: 'flex',
146
+ flexDirection: 'column'
147
+ },
142
148
  children: [
143
149
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
144
150
  variant: "h3",
145
151
  sx: (theme)=>({
146
152
  color: theme.palette.text.primary,
147
- fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`
153
+ fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
154
+ padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`
148
155
  }),
149
156
  children: formattedValue
150
157
  }),
151
- sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
158
+ sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
152
159
  sx: {
153
- width: width + PANEL_PADDING,
154
- height: height,
155
- position: 'absolute',
156
- bottom: 0,
157
- left: 0
160
+ flex: 1
158
161
  },
159
- option: option,
160
- theme: chartsTheme.echartsTheme,
161
- renderer: "svg"
162
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
163
+ sx: {
164
+ width: '100%',
165
+ height: '100%'
166
+ },
167
+ option: option,
168
+ theme: chartsTheme.echartsTheme,
169
+ renderer: "svg"
170
+ })
162
171
  })
163
172
  ]
164
173
  });
package/dist/cjs/index.js CHANGED
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _exportStar(require("./DateTimeRangePicker"), exports);
18
+ _exportStar(require("./Dialog"), exports);
18
19
  _exportStar(require("./Drawer"), exports);
19
20
  _exportStar(require("./EChart"), exports);
20
21
  _exportStar(require("./ErrorAlert"), exports);
@@ -45,7 +45,10 @@ const DECIMAL_UNIT_CONFIG = {
45
45
  function formatDecimal(value, unitOptions) {
46
46
  var _decimal_places;
47
47
  const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
48
- if (unitOptions.abbreviate === true) {
48
+ if (value === 0) {
49
+ return value.toString();
50
+ }
51
+ if (unitOptions.abbreviate && value >= 1000) {
49
52
  return abbreviateLargeNumber(value, decimals);
50
53
  }
51
54
  const formatParams = {
@@ -32,6 +32,60 @@ describe('formatValue', ()=>{
32
32
  },
33
33
  expected: '155,900.0000'
34
34
  },
35
+ {
36
+ value: 1000,
37
+ unit: {
38
+ kind: 'Decimal',
39
+ decimal_places: 2,
40
+ abbreviate: true
41
+ },
42
+ expected: '1K'
43
+ },
44
+ {
45
+ value: 1590.878787,
46
+ unit: {
47
+ kind: 'Decimal',
48
+ decimal_places: 3,
49
+ abbreviate: true
50
+ },
51
+ expected: '1.591K'
52
+ },
53
+ {
54
+ value: 0.123456789,
55
+ unit: {
56
+ kind: 'Decimal',
57
+ decimal_places: 2,
58
+ abbreviate: true
59
+ },
60
+ expected: '0.12'
61
+ },
62
+ {
63
+ value: 0.123456789,
64
+ unit: {
65
+ kind: 'Decimal',
66
+ decimal_places: 4,
67
+ abbreviate: false
68
+ },
69
+ expected: '0.1235'
70
+ },
71
+ {
72
+ value: -0.123456789,
73
+ unit: {
74
+ kind: 'Decimal',
75
+ decimal_places: 3,
76
+ abbreviate: true
77
+ },
78
+ expected: '-0.123'
79
+ },
80
+ {
81
+ value: 0,
82
+ unit: {
83
+ kind: 'Decimal',
84
+ decimal_places: 2,
85
+ abbreviate: true
86
+ },
87
+ expected: '0'
88
+ },
35
89
  {
36
90
  value: 10,
37
91
  unit: {