@perses-dev/components 0.0.0-snapshot-datasource-create-transform-e9f8493 → 0.0.0-snapshot-color-palette-gen-test-0ebddd6

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 (82) hide show
  1. package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
  2. package/dist/InfoTooltip/InfoTooltip.js +8 -5
  3. package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
  4. package/dist/Legend/CompactLegend.d.ts +3 -1
  5. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  6. package/dist/Legend/CompactLegend.js +3 -1
  7. package/dist/Legend/CompactLegend.js.map +1 -1
  8. package/dist/Legend/Legend.d.ts +10 -1
  9. package/dist/Legend/Legend.d.ts.map +1 -1
  10. package/dist/Legend/Legend.js +24 -7
  11. package/dist/Legend/Legend.js.map +1 -1
  12. package/dist/Legend/ListLegend.d.ts +14 -4
  13. package/dist/Legend/ListLegend.d.ts.map +1 -1
  14. package/dist/Legend/ListLegend.js +111 -15
  15. package/dist/Legend/ListLegend.js.map +1 -1
  16. package/dist/Legend/ListLegendItem.d.ts +14 -2
  17. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  18. package/dist/Legend/ListLegendItem.js +31 -3
  19. package/dist/Legend/ListLegendItem.js.map +1 -1
  20. package/dist/LineChart/LineChart.d.ts +8 -2
  21. package/dist/LineChart/LineChart.d.ts.map +1 -1
  22. package/dist/LineChart/LineChart.js +11 -4
  23. package/dist/LineChart/LineChart.js.map +1 -1
  24. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +4 -2
  25. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -1
  26. package/dist/OptionsEditorLayout/OptionsEditorControl.js +34 -5
  27. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  28. package/dist/StatChart/StatChart.d.ts +1 -0
  29. package/dist/StatChart/StatChart.d.ts.map +1 -1
  30. package/dist/StatChart/StatChart.js +2 -2
  31. package/dist/StatChart/StatChart.js.map +1 -1
  32. package/dist/ThresholdsEditor/ThresholdInput.d.ts +3 -1
  33. package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
  34. package/dist/ThresholdsEditor/ThresholdInput.js +9 -3
  35. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
  36. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
  37. package/dist/ThresholdsEditor/ThresholdsEditor.js +57 -35
  38. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  39. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  40. package/dist/TimeSeriesTooltip/SeriesInfo.js +4 -4
  41. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  42. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +1 -9
  43. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  44. package/dist/TimeSeriesTooltip/tooltip-model.js +3 -7
  45. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  46. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  47. package/dist/TimeSeriesTooltip/utils.js +9 -6
  48. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  49. package/dist/cjs/InfoTooltip/InfoTooltip.js +8 -5
  50. package/dist/cjs/Legend/Legend.js +24 -7
  51. package/dist/cjs/Legend/ListLegend.js +106 -13
  52. package/dist/cjs/Legend/ListLegendItem.js +30 -2
  53. package/dist/cjs/LineChart/LineChart.js +11 -4
  54. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +33 -4
  55. package/dist/cjs/StatChart/StatChart.js +2 -2
  56. package/dist/cjs/ThresholdsEditor/ThresholdInput.js +8 -2
  57. package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +56 -34
  58. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +4 -4
  59. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +3 -7
  60. package/dist/cjs/TimeSeriesTooltip/utils.js +9 -6
  61. package/dist/cjs/model/units/bytes.js +33 -39
  62. package/dist/cjs/model/units/decimal.js +15 -26
  63. package/dist/cjs/model/units/time.js +2 -3
  64. package/dist/cjs/utils/theme-gen.js +13 -5
  65. package/dist/model/legend.d.ts +1 -1
  66. package/dist/model/legend.d.ts.map +1 -1
  67. package/dist/model/legend.js.map +1 -1
  68. package/dist/model/units/bytes.d.ts +1 -5
  69. package/dist/model/units/bytes.d.ts.map +1 -1
  70. package/dist/model/units/bytes.js +28 -42
  71. package/dist/model/units/bytes.js.map +1 -1
  72. package/dist/model/units/decimal.d.ts +1 -12
  73. package/dist/model/units/decimal.d.ts.map +1 -1
  74. package/dist/model/units/decimal.js +14 -30
  75. package/dist/model/units/decimal.js.map +1 -1
  76. package/dist/model/units/time.d.ts.map +1 -1
  77. package/dist/model/units/time.js +2 -3
  78. package/dist/model/units/time.js.map +1 -1
  79. package/dist/utils/theme-gen.d.ts.map +1 -1
  80. package/dist/utils/theme-gen.js +13 -5
  81. package/dist/utils/theme-gen.js.map +1 -1
  82. package/package.json +11 -5
@@ -36,7 +36,10 @@ use([
36
36
  LegendComponent,
37
37
  CanvasRenderer
38
38
  ]);
39
- export function LineChart({ height , data , yAxis , unit , grid , legend , onDataZoom , onDoubleClick }) {
39
+ export function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
40
+ wrapLabels: true
41
+ } , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
42
+ var ref;
40
43
  const chartsTheme = useChartsTheme();
41
44
  const chartRef = useRef();
42
45
  const [showTooltip, setShowTooltip] = useState(true);
@@ -130,6 +133,9 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , onDat
130
133
  grid,
131
134
  legend
132
135
  };
136
+ if (__experimentalEChartsOptionsOverride) {
137
+ return __experimentalEChartsOptionsOverride(option);
138
+ }
133
139
  return option;
134
140
  }, [
135
141
  data,
@@ -138,7 +144,8 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , onDat
138
144
  grid,
139
145
  legend,
140
146
  noDataOption,
141
- timeZone
147
+ timeZone,
148
+ __experimentalEChartsOptionsOverride
142
149
  ]);
143
150
  return /*#__PURE__*/ _jsxs(Box, {
144
151
  sx: {
@@ -168,10 +175,10 @@ export function LineChart({ height , data , yAxis , unit , grid , legend , onDat
168
175
  },
169
176
  onDoubleClick: handleOnDoubleClick,
170
177
  children: [
171
- showTooltip === true && /*#__PURE__*/ _jsx(TimeSeriesTooltip, {
178
+ showTooltip === true && ((ref = option.tooltip) === null || ref === void 0 ? void 0 : ref.showContent) === false && tooltipConfig.hidden !== true && /*#__PURE__*/ _jsx(TimeSeriesTooltip, {
172
179
  chartRef: chartRef,
173
180
  chartData: data,
174
- wrapLabels: true,
181
+ wrapLabels: tooltipConfig.wrapLabels,
175
182
  pinTooltip: pinTooltip,
176
183
  unit: unit
177
184
  }),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/LineChart/LineChart.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, { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\n YAXisComponentOption,\n} from 'echarts';\nimport { ECharts as EChartsInstance, use } from 'echarts/core';\nimport { LineChart as EChartsLineChart } from 'echarts/charts';\nimport {\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, OnEventsType } from '../EChart';\nimport { EChartsDataFormat, OPTIMIZED_MODE_SERIES_LIMIT } from '../model/graph';\nimport { UnitOptions } from '../model/units';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { TimeSeriesTooltip } from '../TimeSeriesTooltip';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { enableDataZoom, getDateRange, getFormattedDate, getYAxes, restoreChart, ZoomEventData } from './utils';\n\nuse([\n EChartsLineChart,\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n CanvasRenderer,\n]);\n\nexport interface LineChartProps {\n /**\n * Height of the chart\n */\n height: number;\n data: EChartsDataFormat;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n}\n\nexport function LineChart({ height, data, yAxis, unit, grid, legend, onDataZoom, onDoubleClick }: LineChartProps) {\n const chartsTheme = useChartsTheme();\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [pinTooltip, setPinTooltip] = useState<boolean>(false);\n const { timeZone } = useTimeZone();\n\n const handleEvents: OnEventsType<LineSeriesOption['data'] | unknown> = useMemo(() => {\n return {\n datazoom: (params) => {\n if (onDataZoom === undefined) {\n setTimeout(() => {\n // workaround so unpin happens after click event\n setPinTooltip(false);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const startIndex = params.batch[0].startValue ?? 0;\n const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;\n const xAxisStartValue = data.xAxis[startIndex];\n const xAxisEndValue = data.xAxis[endIndex];\n\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n startIndex,\n endIndex,\n };\n onDataZoom(zoomEvent);\n }\n },\n // TODO: use legendselectchanged event to fix tooltip when legend selected\n };\n }, [data, onDataZoom, setPinTooltip]);\n\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n\n const handleOnDoubleClick = (e: MouseEvent) => {\n setPinTooltip(false);\n // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior\n if (onDoubleClick === undefined) {\n if (chartRef.current !== undefined) {\n restoreChart(chartRef.current);\n }\n } else {\n onDoubleClick(e);\n }\n };\n\n const { noDataOption } = chartsTheme;\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.timeSeries === undefined) return {};\n if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;\n\n // show symbols and axisPointer dashed line on hover\n const isOptimizedMode = data.timeSeries.length > OPTIMIZED_MODE_SERIES_LIMIT;\n\n const rangeMs = data.rangeMs ?? getDateRange(data.xAxis);\n\n const option: EChartsCoreOption = {\n series: data.timeSeries,\n xAxis: {\n type: 'category',\n data: data.xAxis,\n max: data.xAxisMax,\n axisLabel: {\n formatter: (value: number) => {\n return getFormattedDate(value, rangeMs, timeZone);\n },\n },\n },\n yAxis: getYAxes(yAxis, unit),\n animation: false,\n tooltip: {\n show: !isOptimizedMode,\n trigger: 'axis',\n showContent: false, // echarts tooltip content hidden since we use custom tooltip instead\n axisPointer: {\n type: isOptimizedMode ? 'none' : 'line',\n z: 0, // ensure point symbol shows on top of dashed line\n },\n },\n toolbox: {\n feature: {\n dataZoom: {\n icon: null, // https://stackoverflow.com/a/67684076/17575201\n yAxisIndex: 'none',\n },\n },\n },\n grid,\n legend,\n };\n\n return option;\n }, [data, yAxis, unit, grid, legend, noDataOption, timeZone]);\n\n return (\n <Box\n sx={{ height }}\n onClick={() => {\n setPinTooltip((current) => !current);\n }}\n onMouseDown={(e) => {\n // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels\n if (e.target instanceof HTMLCanvasElement) {\n setShowTooltip(false);\n }\n }}\n onMouseUp={() => {\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n setPinTooltip(false);\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n }}\n onDoubleClick={handleOnDoubleClick}\n >\n {showTooltip === true && (\n <TimeSeriesTooltip chartRef={chartRef} chartData={data} wrapLabels={true} pinTooltip={pinTooltip} unit={unit} />\n )}\n\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n onEvents={handleEvents}\n _instance={chartRef}\n />\n </Box>\n );\n}\n"],"names":["React","useMemo","useRef","useState","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","CanvasRenderer","EChart","OPTIMIZED_MODE_SERIES_LIMIT","useChartsTheme","TimeSeriesTooltip","useTimeZone","enableDataZoom","getDateRange","getFormattedDate","getYAxes","restoreChart","height","data","yAxis","unit","grid","legend","onDataZoom","onDoubleClick","chartsTheme","chartRef","showTooltip","setShowTooltip","pinTooltip","setPinTooltip","timeZone","handleEvents","datazoom","params","undefined","setTimeout","batch","startIndex","startValue","endIndex","endValue","xAxis","length","xAxisStartValue","xAxisEndValue","zoomEvent","start","end","current","handleOnDoubleClick","e","noDataOption","option","timeSeries","isOptimizedMode","rangeMs","series","type","max","xAxisMax","axisLabel","formatter","value","animation","tooltip","show","trigger","showContent","axisPointer","z","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","onMouseDown","target","HTMLCanvasElement","onMouseUp","onMouseLeave","onMouseEnter","chartData","wrapLabels","width","theme","echartsTheme","onEvents","_instance"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC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AAC;QACD6B,WAAW,EAAE,CAAC3B,CAAC,GAAK;YAClB,yFAAyF;YACzF,IAAIA,CAAC,CAAC4B,MAAM,YAAYC,iBAAiB,EAAE;gBACzCpD,cAAc,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACDqD,SAAS,EAAE,IAAM;YACfrD,cAAc,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACDsD,YAAY,EAAE,IAAM;YAClBtD,cAAc,CAAC,KAAK,CAAC,CAAC;YACtBE,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACDqD,YAAY,EAAE,IAAM;YAClBvD,cAAc,CAAC,IAAI,CAAC,CAAC;YACrB,IAAIF,QAAQ,CAACuB,OAAO,KAAKd,SAAS,EAAE;gBAClCvB,cAAc,CAACc,QAAQ,CAACuB,OAAO,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACDzB,aAAa,EAAE0B,mBAAmB;;YAEjCvB,WAAW,KAAK,IAAI,kBACnB,KAACjB,iBAAiB;gBAACgB,QAAQ,EAAEA,QAAQ;gBAAE0D,SAAS,EAAElE,IAAI;gBAAEmE,UAAU,EAAE,IAAI;gBAAExD,UAAU,EAAEA,UAAU;gBAAET,IAAI,EAAEA,IAAI;cAAI,AACjH;0BAED,KAACb,MAAM;gBACLqE,EAAE,EAAE;oBACFU,KAAK,EAAE,MAAM;oBACbrE,MAAM,EAAE,MAAM;iBACf;gBACDoC,MAAM,EAAEA,MAAM;gBACdkC,KAAK,EAAE9D,WAAW,CAAC+D,YAAY;gBAC/BC,QAAQ,EAAEzD,YAAY;gBACtB0D,SAAS,EAAEhE,QAAQ;cACnB;;MACE,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/LineChart/LineChart.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, { MouseEvent, useMemo, useRef, useState } from 'react';\nimport { Box } from '@mui/material';\nimport type {\n EChartsCoreOption,\n GridComponentOption,\n LineSeriesOption,\n LegendComponentOption,\n YAXisComponentOption,\n TooltipComponentOption,\n} from 'echarts';\nimport { ECharts as EChartsInstance, use } from 'echarts/core';\nimport { LineChart as EChartsLineChart } from 'echarts/charts';\nimport {\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChart, OnEventsType } from '../EChart';\nimport { EChartsDataFormat, OPTIMIZED_MODE_SERIES_LIMIT } from '../model/graph';\nimport { UnitOptions } from '../model/units';\nimport { useChartsTheme } from '../context/ChartsThemeProvider';\nimport { TimeSeriesTooltip } from '../TimeSeriesTooltip';\nimport { useTimeZone } from '../context/TimeZoneProvider';\nimport { enableDataZoom, getDateRange, getFormattedDate, getYAxes, restoreChart, ZoomEventData } from './utils';\n\nuse([\n EChartsLineChart,\n GridComponent,\n DataZoomComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n LegendComponent,\n CanvasRenderer,\n]);\n\nexport type TooltipConfig = {\n wrapLabels: boolean;\n hidden?: boolean;\n};\n\nexport interface LineChartProps {\n /**\n * Height of the chart\n */\n height: number;\n data: EChartsDataFormat;\n yAxis?: YAXisComponentOption;\n unit?: UnitOptions;\n grid?: GridComponentOption;\n legend?: LegendComponentOption;\n tooltipConfig?: TooltipConfig;\n onDataZoom?: (e: ZoomEventData) => void;\n onDoubleClick?: (e: MouseEvent) => void;\n __experimentalEChartsOptionsOverride?: (options: EChartsCoreOption) => EChartsCoreOption;\n}\n\nexport function LineChart({\n height,\n data,\n yAxis,\n unit,\n grid,\n legend,\n tooltipConfig = { wrapLabels: true },\n onDataZoom,\n onDoubleClick,\n __experimentalEChartsOptionsOverride,\n}: LineChartProps) {\n const chartsTheme = useChartsTheme();\n const chartRef = useRef<EChartsInstance>();\n const [showTooltip, setShowTooltip] = useState<boolean>(true);\n const [pinTooltip, setPinTooltip] = useState<boolean>(false);\n const { timeZone } = useTimeZone();\n\n const handleEvents: OnEventsType<LineSeriesOption['data'] | unknown> = useMemo(() => {\n return {\n datazoom: (params) => {\n if (onDataZoom === undefined) {\n setTimeout(() => {\n // workaround so unpin happens after click event\n setPinTooltip(false);\n }, 10);\n }\n if (onDataZoom === undefined || params.batch[0] === undefined) return;\n const startIndex = params.batch[0].startValue ?? 0;\n const endIndex = params.batch[0].endValue ?? data.xAxis.length - 1;\n const xAxisStartValue = data.xAxis[startIndex];\n const xAxisEndValue = data.xAxis[endIndex];\n\n if (xAxisStartValue !== undefined && xAxisEndValue !== undefined) {\n const zoomEvent: ZoomEventData = {\n start: xAxisStartValue,\n end: xAxisEndValue,\n startIndex,\n endIndex,\n };\n onDataZoom(zoomEvent);\n }\n },\n // TODO: use legendselectchanged event to fix tooltip when legend selected\n };\n }, [data, onDataZoom, setPinTooltip]);\n\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n\n const handleOnDoubleClick = (e: MouseEvent) => {\n setPinTooltip(false);\n // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior\n if (onDoubleClick === undefined) {\n if (chartRef.current !== undefined) {\n restoreChart(chartRef.current);\n }\n } else {\n onDoubleClick(e);\n }\n };\n\n const { noDataOption } = chartsTheme;\n\n const option: EChartsCoreOption = useMemo(() => {\n if (data.timeSeries === undefined) return {};\n if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;\n\n // show symbols and axisPointer dashed line on hover\n const isOptimizedMode = data.timeSeries.length > OPTIMIZED_MODE_SERIES_LIMIT;\n\n const rangeMs = data.rangeMs ?? getDateRange(data.xAxis);\n\n const option: EChartsCoreOption = {\n series: data.timeSeries,\n xAxis: {\n type: 'category',\n data: data.xAxis,\n max: data.xAxisMax,\n axisLabel: {\n formatter: (value: number) => {\n return getFormattedDate(value, rangeMs, timeZone);\n },\n },\n },\n yAxis: getYAxes(yAxis, unit),\n animation: false,\n tooltip: {\n show: !isOptimizedMode,\n trigger: 'axis',\n showContent: false, // echarts tooltip content hidden since we use custom tooltip instead\n axisPointer: {\n type: isOptimizedMode ? 'none' : 'line',\n z: 0, // ensure point symbol shows on top of dashed line\n },\n },\n toolbox: {\n feature: {\n dataZoom: {\n icon: null, // https://stackoverflow.com/a/67684076/17575201\n yAxisIndex: 'none',\n },\n },\n },\n grid,\n legend,\n };\n\n if (__experimentalEChartsOptionsOverride) {\n return __experimentalEChartsOptionsOverride(option);\n }\n return option;\n }, [data, yAxis, unit, grid, legend, noDataOption, timeZone, __experimentalEChartsOptionsOverride]);\n\n return (\n <Box\n sx={{ height }}\n onClick={() => {\n setPinTooltip((current) => !current);\n }}\n onMouseDown={(e) => {\n // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels\n if (e.target instanceof HTMLCanvasElement) {\n setShowTooltip(false);\n }\n }}\n onMouseUp={() => {\n setShowTooltip(true);\n }}\n onMouseLeave={() => {\n setShowTooltip(false);\n setPinTooltip(false);\n }}\n onMouseEnter={() => {\n setShowTooltip(true);\n if (chartRef.current !== undefined) {\n enableDataZoom(chartRef.current);\n }\n }}\n onDoubleClick={handleOnDoubleClick}\n >\n {/* Allows overrides prop to hide custom tooltip and use the ECharts option.tooltip instead */}\n {showTooltip === true &&\n (option.tooltip as TooltipComponentOption)?.showContent === false &&\n tooltipConfig.hidden !== true && (\n <TimeSeriesTooltip\n chartRef={chartRef}\n chartData={data}\n wrapLabels={tooltipConfig.wrapLabels}\n pinTooltip={pinTooltip}\n unit={unit}\n />\n )}\n <EChart\n sx={{\n width: '100%',\n height: '100%',\n }}\n option={option}\n theme={chartsTheme.echartsTheme}\n onEvents={handleEvents}\n _instance={chartRef}\n />\n </Box>\n );\n}\n"],"names":["React","useMemo","useRef","useState","Box","use","LineChart","EChartsLineChart","GridComponent","DataZoomComponent","MarkAreaComponent","MarkLineComponent","MarkPointComponent","TitleComponent","ToolboxComponent","TooltipComponent","LegendComponent","CanvasRenderer","EChart","OPTIMIZED_MODE_SERIES_LIMIT","useChartsTheme","TimeSeriesTooltip","useTimeZone","enableDataZoom","getDateRange","getFormattedDate","getYAxes","restoreChart","height","data","yAxis","unit","grid","legend","tooltipConfig","wrapLabels","onDataZoom","onDoubleClick","__experimentalEChartsOptionsOverride","option","chartsTheme","chartRef","showTooltip","setShowTooltip","pinTooltip","setPinTooltip","timeZone","handleEvents","datazoom","params","undefined","setTimeout","batch","startIndex","startValue","endIndex","endValue","xAxis","length","xAxisStartValue","xAxisEndValue","zoomEvent","start","end","current","handleOnDoubleClick","e","noDataOption","timeSeries","isOptimizedMode","rangeMs","series","type","max","xAxisMax","axisLabel","formatter","value","animation","tooltip","show","trigger","showContent","axisPointer","z","toolbox","feature","dataZoom","icon","yAxisIndex","sx","onClick","onMouseDown","target","HTMLCanvasElement","onMouseUp","onMouseLeave","onMouseEnter","hidden","chartData","width","theme","echartsTheme","onEvents","_instance"],"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,IAAgBC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrE,SAASC,GAAG,QAAQ,eAAe,CAAC;AASpC,SAAqCC,GAAG,QAAQ,cAAc,CAAC;AAC/D,SAASC,SAAS,IAAIC,gBAAgB,QAAQ,gBAAgB,CA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nD,cAAc,CAAC,KAAK,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACDoD,SAAS,EAAE,IAAM;YACfpD,cAAc,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACDqD,YAAY,EAAE,IAAM;YAClBrD,cAAc,CAAC,KAAK,CAAC,CAAC;YACtBE,aAAa,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACDoD,YAAY,EAAE,IAAM;YAClBtD,cAAc,CAAC,IAAI,CAAC,CAAC;YACrB,IAAIF,QAAQ,CAACuB,OAAO,KAAKd,SAAS,EAAE;gBAClC3B,cAAc,CAACkB,QAAQ,CAACuB,OAAO,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACD3B,aAAa,EAAE4B,mBAAmB;;YAGjCvB,WAAW,KAAK,IAAI,IACnB,CAAA,CAACH,GAAc,GAAdA,MAAM,CAACwC,OAAO,cAAdxC,GAAc,WAAwC,GAAvD,KAAA,CAAuD,GAAtDA,GAAc,CAA6B2C,WAAW,CAAA,KAAK,KAAK,IACjEhD,aAAa,CAACgE,MAAM,KAAK,IAAI,kBAC3B,KAAC7E,iBAAiB;gBAChBoB,QAAQ,EAAEA,QAAQ;gBAClB0D,SAAS,EAAEtE,IAAI;gBACfM,UAAU,EAAED,aAAa,CAACC,UAAU;gBACpCS,UAAU,EAAEA,UAAU;gBACtBb,IAAI,EAAEA,IAAI;cACV,AACH;0BACH,KAACb,MAAM;gBACLwE,EAAE,EAAE;oBACFU,KAAK,EAAE,MAAM;oBACbxE,MAAM,EAAE,MAAM;iBACf;gBACDW,MAAM,EAAEA,MAAM;gBACd8D,KAAK,EAAE7D,WAAW,CAAC8D,YAAY;gBAC/BC,QAAQ,EAAExD,YAAY;gBACtByD,SAAS,EAAE/D,QAAQ;cACnB;;MACE,CACN;AACJ,CAAC"}
@@ -1,5 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { FormControlLabelProps } from '@mui/material';
3
- export declare type OptionsEditorControlProps = Pick<FormControlLabelProps, 'label' | 'control'>;
4
- export declare const OptionsEditorControl: ({ label, control }: OptionsEditorControlProps) => JSX.Element;
3
+ export declare type OptionsEditorControlProps = Pick<FormControlLabelProps, 'label' | 'control'> & {
4
+ description?: string;
5
+ };
6
+ export declare const OptionsEditorControl: ({ label, control, description }: OptionsEditorControlProps) => JSX.Element;
5
7
  //# sourceMappingURL=OptionsEditorControl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"OptionsEditorControl.d.ts","sourceRoot":"","sources":["../../src/OptionsEditorLayout/OptionsEditorControl.tsx"],"names":[],"mappings":";AAaA,OAAO,EAA0B,qBAAqB,EAAc,MAAM,eAAe,CAAC;AAI1F,oBAAY,yBAAyB,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;AAEzF,eAAO,MAAM,oBAAoB,uBAAwB,yBAAyB,gBAkBjF,CAAC"}
1
+ {"version":3,"file":"OptionsEditorControl.d.ts","sourceRoot":"","sources":["../../src/OptionsEditorLayout/OptionsEditorControl.tsx"],"names":[],"mappings":";AAaA,OAAO,EAA0B,qBAAqB,EAA0B,MAAM,eAAe,CAAC;AAMtG,oBAAY,yBAAyB,GAAG,IAAI,CAAC,qBAAqB,EAAE,OAAO,GAAG,SAAS,CAAC,GAAG;IACzF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,oBAAoB,oCAAqC,yBAAyB,gBAmC9F,CAAC"}
@@ -11,10 +11,12 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- import { FormControl, FormLabel, Stack, Box } from '@mui/material';
14
+ import { FormControl, FormLabel, Stack, Box, IconButton } from '@mui/material';
15
15
  import React from 'react';
16
+ import InformationOutlineIcon from 'mdi-material-ui/InformationOutline';
16
17
  import { useId } from '../utils';
17
- export const OptionsEditorControl = ({ label , control })=>{
18
+ import { InfoTooltip } from '../InfoTooltip';
19
+ export const OptionsEditorControl = ({ label , control , description })=>{
18
20
  // Make sure we have a unique ID we can use for associating labels and
19
21
  // controls for a11y.
20
22
  const generatedControlId = useId('EditorSectionControl');
@@ -28,9 +30,36 @@ export const OptionsEditorControl = ({ label , control })=>{
28
30
  alignItems: "center",
29
31
  justifyContent: "space-between",
30
32
  children: [
31
- /*#__PURE__*/ _jsx(FormLabel, {
32
- htmlFor: controlId,
33
- children: label
33
+ /*#__PURE__*/ _jsxs(Stack, {
34
+ direction: "row",
35
+ alignItems: "center",
36
+ justifyContent: "center",
37
+ children: [
38
+ /*#__PURE__*/ _jsx(FormLabel, {
39
+ htmlFor: controlId,
40
+ children: label
41
+ }),
42
+ description && /*#__PURE__*/ _jsx(InfoTooltip, {
43
+ description: description,
44
+ enterDelay: 100,
45
+ children: /*#__PURE__*/ _jsx(IconButton, {
46
+ size: "small",
47
+ sx: (theme)=>({
48
+ borderRadius: theme.shape.borderRadius,
49
+ padding: '4x',
50
+ margin: '0 2px'
51
+ }),
52
+ children: /*#__PURE__*/ _jsx(InformationOutlineIcon, {
53
+ "aria-describedby": "info-tooltip",
54
+ "aria-hidden": false,
55
+ fontSize: "inherit",
56
+ sx: {
57
+ color: (theme)=>theme.palette.grey[700]
58
+ }
59
+ })
60
+ })
61
+ })
62
+ ]
34
63
  }),
35
64
  /*#__PURE__*/ _jsxs(Box, {
36
65
  sx: {
@@ -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 } from '@mui/material';\nimport React from 'react';\nimport { useId } from '../utils';\n\nexport type OptionsEditorControlProps = Pick<FormControlLabelProps, 'label' | 'control'>;\n\nexport const OptionsEditorControl = ({ label, control }: 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 <FormLabel htmlFor={controlId}>{label}</FormLabel>\n <Box sx={{ width: '150px', textAlign: 'right' }}> {React.cloneElement(control, controlProps)}</Box>\n </Stack>\n </FormControl>\n );\n};\n"],"names":["FormControl","FormLabel","Stack","Box","React","useId","OptionsEditorControl","label","control","generatedControlId","controlId","controlProps","id","direction","alignItems","justifyContent","htmlFor","sx","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,QAAQ,eAAe,CAAC;AAC1F,OAAOC,KAAK,MAAM,OAAO,CAAC;AAC1B,SAASC,KAAK,QAAQ,UAAU,CAAC;AAIjC,OAAO,MAAMC,oBAAoB,GAAG,CAAC,EAAEC,KAAK,CAAA,EAAEC,OAAO,CAAA,EAA6B,GAAK;IACrF,sEAAsE;IACtE,qBAAqB;IACrB,MAAMC,kBAAkB,GAAGJ,KAAK,CAAC,sBAAsB,CAAC,AAAC;IACzD,MAAMK,SAAS,GAAG,CAAC,EAAED,kBAAkB,CAAC,QAAQ,CAAC,AAAC;IAElD,MAAME,YAAY,GAAG;QACnBC,EAAE,EAAEF,SAAS;KACd,AAAC;IAEF,qBACE,KAACV,WAAW;kBACV,cAAA,MAACE,KAAK;YAACW,SAAS,EAAC,KAAK;YAACC,UAAU,EAAC,QAAQ;YAACC,cAAc,EAAC,eAAe;;8BACvE,KAACd,SAAS;oBAACe,OAAO,EAAEN,SAAS;8BAAGH,KAAK;kBAAa;8BAClD,MAACJ,GAAG;oBAACc,EAAE,EAAE;wBAAEC,KAAK,EAAE,OAAO;wBAAEC,SAAS,EAAE,OAAO;qBAAE;;wBAAE,GAAC;sCAACf,KAAK,CAACgB,YAAY,CAACZ,OAAO,EAAEG,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: '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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 +11,7 @@ export interface StatChartProps {
11
11
  height: number;
12
12
  data: StatChartData;
13
13
  unit: UnitOptions;
14
+ color?: string;
14
15
  sparkline?: LineSeriesOption;
15
16
  }
16
17
  export declare function StatChart(props: StatChartProps): JSX.Element;
@@ -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,SAAS,CAAC,EAAE,gBAAgB,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAyF9C"}
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,eAyF9C"}
@@ -32,7 +32,7 @@ use([
32
32
  const MIN_VALUE_SIZE = 12;
33
33
  const MAX_VALUE_SIZE = 36;
34
34
  export function StatChart(props) {
35
- const { width , height , data , unit , sparkline } = props;
35
+ const { width , height , data , unit , color , sparkline } = props;
36
36
  const chartsTheme = useChartsTheme();
37
37
  const formattedValue = data.calculatedValue === undefined ? '' : formatValue(data.calculatedValue, unit);
38
38
  const option = useMemo(()=>{
@@ -101,7 +101,7 @@ export function StatChart(props) {
101
101
  /*#__PURE__*/ _jsx(Typography, {
102
102
  variant: "h3",
103
103
  sx: (theme)=>({
104
- color: theme.palette.text.primary,
104
+ color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
105
105
  fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
106
106
  padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`
107
107
  }),
@@ -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-es';\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 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 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 },\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":["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","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,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAChD,SAASC,KAAK,QAAQ,WAAW,CAAC;AAClC,SAASC,GAAG,QAA2B,cAAc,CAAC;AACtD,SAASC,SAAS,IAAIC,gBAAgB,QAA0B,gBAAgB,CAAC;AACjF,SAASC,aAAa,EAAEC,gBAAgB,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5C,MAAM,EAAE,MAAM;YAAED,KAAK,EAAE,MAAM;YAAE8C,OAAO,EAAE,MAAM;YAAEC,aAAa,EAAE,QAAQ;SAAE;;0BAClF,KAAChE,UAAU;gBACTiE,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,KAAC1B,GAAG;gBAAC+D,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"}
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-es';\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 },\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: 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":["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","tooltip","isLargePanel","charactersAdjust","length","valueSize","Math","min","containerPadding","container","padding","default","sx","display","flexDirection","variant","theme","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,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,GAAG,EAAEC,UAAU,QA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AM,CAAC,GAAGoC,gBAAgB,AAAC;IAEtG,MAAMK,gBAAgB,GAAG,CAAC,EAAEpC,WAAW,CAACqC,SAAS,CAACC,OAAO,CAACC,OAAO,CAAC,EAAE,CAAC,AAAC;IAEtE,qBACE,MAAC/D,GAAG;QAACgE,EAAE,EAAE;YAAE7C,MAAM,EAAE,MAAM;YAAED,KAAK,EAAE,MAAM;YAAE+C,OAAO,EAAE,MAAM;YAAEC,aAAa,EAAE,QAAQ;SAAE;;0BAClF,KAACjE,UAAU;gBACTkE,OAAO,EAAC,IAAI;gBACZH,EAAE,EAAE,CAACI,KAAK,GAAM,CAAA;wBACd9C,KAAK,EAAEA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI8C,KAAK,CAACC,OAAO,CAACC,IAAI,CAACC,OAAO;wBAC1CC,QAAQ,EAAE,CAAC,MAAM,EAAE1D,cAAc,CAAC,IAAI,EAAE2C,SAAS,CAAC,IAAI,EAAE1C,cAAc,CAAC,GAAG,CAAC;wBAC3E+C,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,KAAC3B,GAAG;gBAACgE,EAAE,EAAE;oBAAES,IAAI,EAAE,CAAC;iBAAE;0BAClB,cAAA,KAAC5D,MAAM;oBACLmD,EAAE,EAAE;wBACF9C,KAAK,EAAE,MAAM;wBACbC,MAAM,EAAE,MAAM;qBACf;oBACDS,MAAM,EAAEA,MAAM;oBACdwC,KAAK,EAAE5C,WAAW,CAACkD,YAAY;oBAC/BC,QAAQ,EAAC,KAAK;kBACd;cACE,AACP;;MACG,CACN;AACJ,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { RefObject } from 'react';
2
+ import { ThresholdOptions } from '@perses-dev/core';
2
3
  export interface ThresholdInputProps {
3
4
  label: string;
4
5
  color: string;
@@ -8,6 +9,7 @@ export interface ThresholdInputProps {
8
9
  onBlur: () => void;
9
10
  onDelete: () => void;
10
11
  inputRef?: RefObject<HTMLInputElement | null>;
12
+ mode?: ThresholdOptions['mode'];
11
13
  }
12
- export declare function ThresholdInput({ inputRef, label, color, value, onChange, onColorChange, onBlur, onDelete, }: ThresholdInputProps): JSX.Element;
14
+ export declare function ThresholdInput({ inputRef, label, color, value, mode, onChange, onColorChange, onBlur, onDelete, }: ThresholdInputProps): JSX.Element;
13
15
  //# sourceMappingURL=ThresholdInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ThresholdInput.d.ts","sourceRoot":"","sources":["../../src/ThresholdsEditor/ThresholdInput.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAK5C,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAC3D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CAC/C;AAED,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,QAAQ,EACR,aAAa,EACb,MAAM,EACN,QAAQ,GACT,EAAE,mBAAmB,eA2BrB"}
1
+ {"version":3,"file":"ThresholdInput.d.ts","sourceRoot":"","sources":["../../src/ThresholdsEditor/ThresholdInput.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAY,MAAM,OAAO,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAGpD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAC3D,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACvC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;IAC9C,IAAI,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;CACjC;AAED,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,KAAK,EACL,KAAK,EACL,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,MAAM,EACN,QAAQ,GACT,EAAE,mBAAmB,eA8BrB"}
@@ -12,10 +12,10 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { useState } from 'react';
15
- import { Stack, FormLabel, TextField, IconButton } from '@mui/material';
15
+ import { Stack, FormLabel, TextField, IconButton, Box } from '@mui/material';
16
16
  import DeleteIcon from 'mdi-material-ui/DeleteOutline';
17
17
  import { ThresholdColorPicker } from './ThresholdColorPicker';
18
- export function ThresholdInput({ inputRef , label , color , value , onChange , onColorChange , onBlur , onDelete }) {
18
+ export function ThresholdInput({ inputRef , label , color , value , mode , onChange , onColorChange , onBlur , onDelete }) {
19
19
  const [key, setKey] = useState(0); // use key to cause input to lose focus when pressing enter
20
20
  return /*#__PURE__*/ _jsxs(Stack, {
21
21
  flex: 1,
@@ -37,7 +37,7 @@ export function ThresholdInput({ inputRef , label , color , value , onChange , o
37
37
  id: label,
38
38
  inputRef: inputRef,
39
39
  type: "number",
40
- value: value === 0 ? undefined : value,
40
+ value: value === 0 ? '' : value,
41
41
  placeholder: "0",
42
42
  onChange: onChange,
43
43
  onBlur: onBlur,
@@ -46,6 +46,12 @@ export function ThresholdInput({ inputRef , label , color , value , onChange , o
46
46
  onBlur();
47
47
  setKey(key + 1);
48
48
  }
49
+ },
50
+ InputProps: {
51
+ endAdornment: mode === 'Percent' ? /*#__PURE__*/ _jsx(Box, {
52
+ paddingX: 1,
53
+ children: "%"
54
+ }) : undefined
49
55
  }
50
56
  }, key),
51
57
  /*#__PURE__*/ _jsx(IconButton, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ThresholdsEditor/ThresholdInput.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 { RefObject, useState } from 'react';\nimport { Stack, FormLabel, TextField, IconButton } from '@mui/material';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport { ThresholdColorPicker } from './ThresholdColorPicker';\n\nexport interface ThresholdInputProps {\n label: string;\n color: string;\n value: number;\n onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;\n onColorChange: (color: string) => void;\n onBlur: () => void;\n onDelete: () => void;\n inputRef?: RefObject<HTMLInputElement | null>;\n}\n\nexport function ThresholdInput({\n inputRef,\n label,\n color,\n value,\n onChange,\n onColorChange,\n onBlur,\n onDelete,\n}: ThresholdInputProps) {\n const [key, setKey] = useState(0); // use key to cause input to lose focus when pressing enter\n return (\n <Stack flex={1} direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" spacing={1}>\n <ThresholdColorPicker label={label} color={color} onColorChange={onColorChange} />\n <FormLabel htmlFor={label}>{label}</FormLabel>\n <TextField\n id={label}\n key={key}\n inputRef={inputRef}\n type=\"number\"\n value={value === 0 ? undefined : value}\n placeholder=\"0\"\n onChange={onChange}\n onBlur={onBlur}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onBlur();\n setKey(key + 1);\n }\n }}\n />\n <IconButton aria-label={`delete threshold ${label}`} size=\"small\" onClick={onDelete}>\n <DeleteIcon />\n </IconButton>\n </Stack>\n );\n}\n"],"names":["useState","Stack","FormLabel","TextField","IconButton","DeleteIcon","ThresholdColorPicker","ThresholdInput","inputRef","label","color","value","onChange","onColorChange","onBlur","onDelete","key","setKey","flex","direction","alignItems","justifyContent","spacing","htmlFor","id","type","undefined","placeholder","onKeyDown","e","aria-label","size","onClick"],"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,SAAoBA,QAAQ,QAAQ,OAAO,CAAC;AAC5C,SAASC,KAAK,EAAEC,SAAS,EAAEC,SAAS,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACxE,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,SAASC,oBAAoB,QAAQ,wBAAwB,CAAC;AAa9D,OAAO,SAASC,cAAc,CAAC,EAC7BC,QAAQ,CAAA,EACRC,KAAK,CAAA,EACLC,KAAK,CAAA,EACLC,KAAK,CAAA,EACLC,QAAQ,CAAA,EACRC,aAAa,CAAA,EACbC,MAAM,CAAA,EACNC,QAAQ,CAAA,EACY,EAAE;IACtB,MAAM,CAACC,GAAG,EAAEC,MAAM,CAAC,GAAGjB,QAAQ,CAAC,CAAC,CAAC,AAAC,EAAC,2DAA2D;IAC9F,qBACE,MAACC,KAAK;QAACiB,IAAI,EAAE,CAAC;QAAEC,SAAS,EAAC,KAAK;QAACC,UAAU,EAAC,QAAQ;QAACC,cAAc,EAAC,eAAe;QAACC,OAAO,EAAE,CAAC;;0BAC3F,KAAChB,oBAAoB;gBAACG,KAAK,EAAEA,KAAK;gBAAEC,KAAK,EAAEA,KAAK;gBAAEG,aAAa,EAAEA,aAAa;cAAI;0BAClF,KAACX,SAAS;gBAACqB,OAAO,EAAEd,KAAK;0BAAGA,KAAK;cAAa;0BAC9C,KAACN,SAAS;gBACRqB,EAAE,EAAEf,KAAK;gBAETD,QAAQ,EAAEA,QAAQ;gBAClBiB,IAAI,EAAC,QAAQ;gBACbd,KAAK,EAAEA,KAAK,KAAK,CAAC,GAAGe,SAAS,GAAGf,KAAK;gBACtCgB,WAAW,EAAC,GAAG;gBACff,QAAQ,EAAEA,QAAQ;gBAClBE,MAAM,EAAEA,MAAM;gBACdc,SAAS,EAAE,CAACC,CAAC,GAAK;oBAChB,IAAIA,CAAC,CAACb,GAAG,KAAK,OAAO,EAAE;wBACrBF,MAAM,EAAE,CAAC;wBACTG,MAAM,CAACD,GAAG,GAAG,CAAC,CAAC,CAAC;oBAClB,CAAC;gBACH,CAAC;eAZIA,GAAG,CAaR;0BACF,KAACZ,UAAU;gBAAC0B,YAAU,EAAE,CAAC,iBAAiB,EAAErB,KAAK,CAAC,CAAC;gBAAEsB,IAAI,EAAC,OAAO;gBAACC,OAAO,EAAEjB,QAAQ;0BACjF,cAAA,KAACV,UAAU,KAAG;cACH;;MACP,CACR;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/ThresholdsEditor/ThresholdInput.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 { RefObject, useState } from 'react';\nimport { Stack, FormLabel, TextField, IconButton, Box } from '@mui/material';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport { ThresholdOptions } from '@perses-dev/core';\nimport { ThresholdColorPicker } from './ThresholdColorPicker';\n\nexport interface ThresholdInputProps {\n label: string;\n color: string;\n value: number;\n onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;\n onColorChange: (color: string) => void;\n onBlur: () => void;\n onDelete: () => void;\n inputRef?: RefObject<HTMLInputElement | null>;\n mode?: ThresholdOptions['mode'];\n}\n\nexport function ThresholdInput({\n inputRef,\n label,\n color,\n value,\n mode,\n onChange,\n onColorChange,\n onBlur,\n onDelete,\n}: ThresholdInputProps) {\n const [key, setKey] = useState(0); // use key to cause input to lose focus when pressing enter\n return (\n <Stack flex={1} direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" spacing={1}>\n <ThresholdColorPicker label={label} color={color} onColorChange={onColorChange} />\n <FormLabel htmlFor={label}>{label}</FormLabel>\n <TextField\n id={label}\n key={key}\n inputRef={inputRef}\n type=\"number\"\n value={value === 0 ? '' : value}\n placeholder=\"0\"\n onChange={onChange}\n onBlur={onBlur}\n onKeyDown={(e) => {\n if (e.key === 'Enter') {\n onBlur();\n setKey(key + 1);\n }\n }}\n InputProps={{\n endAdornment: mode === 'Percent' ? <Box paddingX={1}>%</Box> : undefined,\n }}\n />\n <IconButton aria-label={`delete threshold ${label}`} size=\"small\" onClick={onDelete}>\n <DeleteIcon />\n </IconButton>\n </Stack>\n );\n}\n"],"names":["useState","Stack","FormLabel","TextField","IconButton","Box","DeleteIcon","ThresholdColorPicker","ThresholdInput","inputRef","label","color","value","mode","onChange","onColorChange","onBlur","onDelete","key","setKey","flex","direction","alignItems","justifyContent","spacing","htmlFor","id","type","placeholder","onKeyDown","e","InputProps","endAdornment","paddingX","undefined","aria-label","size","onClick"],"mappings":"AAAA,oCAAoC;AACpC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,QAAQ;gBAClBE,MAAM,EAAEA,MAAM;gBACda,SAAS,EAAE,CAACC,CAAC,GAAK;oBAChB,IAAIA,CAAC,CAACZ,GAAG,KAAK,OAAO,EAAE;wBACrBF,MAAM,EAAE,CAAC;wBACTG,MAAM,CAACD,GAAG,GAAG,CAAC,CAAC,CAAC;oBAClB,CAAC;gBACH,CAAC;gBACDa,UAAU,EAAE;oBACVC,YAAY,EAAEnB,IAAI,KAAK,SAAS,iBAAG,KAACR,GAAG;wBAAC4B,QAAQ,EAAE,CAAC;kCAAE,GAAC;sBAAM,GAAGC,SAAS;iBACzE;eAfIhB,GAAG,CAgBR;0BACF,KAACd,UAAU;gBAAC+B,YAAU,EAAE,CAAC,iBAAiB,EAAEzB,KAAK,CAAC,CAAC;gBAAE0B,IAAI,EAAC,OAAO;gBAACC,OAAO,EAAEpB,QAAQ;0BACjF,cAAA,KAACX,UAAU,KAAG;cACH;;MACP,CACR;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ThresholdsEditor.d.ts","sourceRoot":"","sources":["../../src/ThresholdsEditor/ThresholdsEditor.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAOpD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACjD,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAID,wBAAgB,gBAAgB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,EAAE,qBAAqB,eA4KhH"}
1
+ {"version":3,"file":"ThresholdsEditor.d.ts","sourceRoot":"","sources":["../../src/ThresholdsEditor/ThresholdsEditor.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAOpD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,CAAC,UAAU,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACjD,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAID,wBAAgB,gBAAgB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE,EAAE,qBAAqB,eA+LhH"}
@@ -16,9 +16,9 @@ import produce from 'immer';
16
16
  import { IconButton, ToggleButton, ToggleButtonGroup, Typography } from '@mui/material';
17
17
  import PlusIcon from 'mdi-material-ui/Plus';
18
18
  import { Stack } from '@mui/system';
19
- import { InfoTooltip } from '../InfoTooltip';
20
19
  import { useChartsTheme } from '../context/ChartsThemeProvider';
21
- import { OptionsEditorGroup } from '../OptionsEditorLayout';
20
+ import { OptionsEditorControl, OptionsEditorGroup } from '../OptionsEditorLayout';
21
+ import { InfoTooltip } from '../InfoTooltip';
22
22
  import { ThresholdColorPicker } from './ThresholdColorPicker';
23
23
  import { ThresholdInput } from './ThresholdInput';
24
24
  const DEFAULT_STEP = 10;
@@ -68,6 +68,10 @@ export function ThresholdsEditor({ thresholds , onChange , hideDefault , disable
68
68
  onChange(produce(thresholds, (draft)=>{
69
69
  draft.default_color = color;
70
70
  }));
71
+ } else {
72
+ onChange({
73
+ default_color: color
74
+ });
71
75
  }
72
76
  };
73
77
  // sort thresholds in ascending order every time an input blurs
@@ -104,6 +108,14 @@ export function ThresholdsEditor({ thresholds , onChange , hideDefault , disable
104
108
  }
105
109
  ]
106
110
  });
111
+ } else if (thresholds && thresholds.steps === undefined) {
112
+ onChange(produce(thresholds, (draft)=>{
113
+ draft.steps = [
114
+ {
115
+ value: DEFAULT_STEP
116
+ }
117
+ ];
118
+ }));
107
119
  } else {
108
120
  onChange(produce(thresholds, (draft)=>{
109
121
  const steps = draft.steps;
@@ -139,46 +151,55 @@ export function ThresholdsEditor({ thresholds , onChange , hideDefault , disable
139
151
  var ref1, _color, ref2;
140
152
  return /*#__PURE__*/ _jsxs(OptionsEditorGroup, {
141
153
  title: "Thresholds",
142
- icon: /*#__PURE__*/ _jsx(IconButton, {
143
- size: "small",
144
- "aria-label": "add threshold",
145
- onClick: addThresholdInput,
146
- children: /*#__PURE__*/ _jsx(PlusIcon, {})
154
+ icon: /*#__PURE__*/ _jsx(InfoTooltip, {
155
+ description: 'Add threshold',
156
+ children: /*#__PURE__*/ _jsx(IconButton, {
157
+ size: "small",
158
+ "aria-label": "add threshold",
159
+ onClick: addThresholdInput,
160
+ children: /*#__PURE__*/ _jsx(PlusIcon, {})
161
+ })
147
162
  }),
148
163
  children: [
149
- /*#__PURE__*/ _jsxs(ToggleButtonGroup, {
150
- exclusive: true,
151
- disabled: disablePercentMode,
152
- value: (ref1 = thresholds === null || thresholds === void 0 ? void 0 : thresholds.mode) !== null && ref1 !== void 0 ? ref1 : 'Absolute',
153
- onChange: handleModeChange,
154
- sx: {
155
- height: '36px',
156
- marginLeft: 'auto'
157
- },
158
- children: [
159
- /*#__PURE__*/ _jsx(ToggleButton, {
160
- "aria-label": "absolute",
161
- value: "Absolute",
162
- children: /*#__PURE__*/ _jsx(InfoTooltip, {
163
- description: "Absolute",
164
- children: "#"
165
- })
166
- }),
167
- /*#__PURE__*/ _jsx(ToggleButton, {
168
- "aria-label": "percent",
169
- value: "Percent",
170
- children: /*#__PURE__*/ _jsx(InfoTooltip, {
171
- description: "Percentage means thresholds relative to min & max",
172
- children: "%"
164
+ /*#__PURE__*/ _jsx(OptionsEditorControl, {
165
+ label: "Mode",
166
+ description: "Percentage means thresholds relative to min & max",
167
+ control: /*#__PURE__*/ _jsxs(ToggleButtonGroup, {
168
+ exclusive: true,
169
+ disabled: disablePercentMode,
170
+ value: (ref1 = thresholds === null || thresholds === void 0 ? void 0 : thresholds.mode) !== null && ref1 !== void 0 ? ref1 : 'Absolute',
171
+ onChange: handleModeChange,
172
+ sx: {
173
+ height: '36px',
174
+ marginLeft: 'auto'
175
+ },
176
+ children: [
177
+ /*#__PURE__*/ _jsx(ToggleButton, {
178
+ "aria-label": "absolute",
179
+ value: "Absolute",
180
+ sx: {
181
+ fontWeight: 500
182
+ },
183
+ children: "Absolute"
184
+ }),
185
+ /*#__PURE__*/ _jsx(ToggleButton, {
186
+ "aria-label": "percent",
187
+ value: "Percent",
188
+ sx: {
189
+ fontWeight: 500
190
+ },
191
+ children: "Percent"
173
192
  })
174
- })
175
- ]
193
+ ]
194
+ })
176
195
  }),
177
- steps && steps.map((step, i)=>/*#__PURE__*/ _jsx(ThresholdInput, {
196
+ steps && steps.map((step, i)=>{
197
+ /*#__PURE__*/ return _jsx(ThresholdInput, {
178
198
  inputRef: i === steps.length - 1 ? recentlyAddedInputRef : undefined,
179
199
  label: `T${i + 1}`,
180
200
  color: (ref2 = (_color = step.color) !== null && _color !== void 0 ? _color : palette[i]) !== null && ref2 !== void 0 ? ref2 : defaultThresholdColor,
181
201
  value: step.value,
202
+ mode: thresholds === null || thresholds === void 0 ? void 0 : thresholds.mode,
182
203
  onColorChange: (color)=>handleThresholdColorChange(color, i),
183
204
  onChange: (e)=>{
184
205
  handleThresholdValueChange(e, i);
@@ -187,7 +208,8 @@ export function ThresholdsEditor({ thresholds , onChange , hideDefault , disable
187
208
  deleteThreshold(i);
188
209
  },
189
210
  onBlur: handleThresholdBlur
190
- }, i)).reverse(),
211
+ }, i);
212
+ }).reverse(),
191
213
  !hideDefault && /*#__PURE__*/ _jsxs(Stack, {
192
214
  flex: 1,
193
215
  direction: "row",