@perses-dev/components 0.23.1 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/dist/ColorPicker/ColorPicker.d.ts +12 -0
  2. package/dist/ColorPicker/ColorPicker.d.ts.map +1 -0
  3. package/dist/ColorPicker/ColorPicker.js +78 -0
  4. package/dist/ColorPicker/ColorPicker.js.map +1 -0
  5. package/dist/ColorPicker/index.d.ts +2 -0
  6. package/dist/ColorPicker/index.d.ts.map +1 -0
  7. package/dist/ColorPicker/index.js +15 -0
  8. package/dist/ColorPicker/index.js.map +1 -0
  9. package/dist/Dialog/Dialog.d.ts +2 -1
  10. package/dist/Dialog/Dialog.d.ts.map +1 -1
  11. package/dist/Dialog/Dialog.js +12 -1
  12. package/dist/Dialog/Dialog.js.map +1 -1
  13. package/dist/{EChart.d.ts → EChart/EChart.d.ts} +3 -3
  14. package/dist/EChart/EChart.d.ts.map +1 -0
  15. package/dist/EChart/EChart.js.map +1 -0
  16. package/dist/EChart/index.d.ts +2 -0
  17. package/dist/EChart/index.d.ts.map +1 -0
  18. package/dist/EChart/index.js +15 -0
  19. package/dist/EChart/index.js.map +1 -0
  20. package/dist/GaugeChart/GaugeChart.d.ts +1 -2
  21. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  22. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  23. package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
  24. package/dist/InfoTooltip/InfoTooltip.js +7 -3
  25. package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
  26. package/dist/Legend/Legend.d.ts +1 -2
  27. package/dist/Legend/Legend.d.ts.map +1 -1
  28. package/dist/Legend/Legend.js +6 -9
  29. package/dist/Legend/Legend.js.map +1 -1
  30. package/dist/LineChart/LineChart.d.ts +4 -2
  31. package/dist/LineChart/LineChart.d.ts.map +1 -1
  32. package/dist/LineChart/LineChart.js +1 -1
  33. package/dist/LineChart/LineChart.js.map +1 -1
  34. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  35. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  36. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +3 -2
  37. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -1
  38. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +17 -5
  39. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
  40. package/dist/StatChart/StatChart.d.ts +1 -3
  41. package/dist/StatChart/StatChart.d.ts.map +1 -1
  42. package/dist/StatChart/StatChart.js +1 -3
  43. package/dist/StatChart/StatChart.js.map +1 -1
  44. package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts +4 -0
  45. package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts.map +1 -0
  46. package/dist/ThresholdsEditor/ThresholdColorPicker.js +76 -0
  47. package/dist/ThresholdsEditor/ThresholdColorPicker.js.map +1 -0
  48. package/dist/ThresholdsEditor/ThresholdInput.d.ts +13 -0
  49. package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -0
  50. package/dist/ThresholdsEditor/ThresholdInput.js +61 -0
  51. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -0
  52. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +10 -0
  53. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -0
  54. package/dist/ThresholdsEditor/ThresholdsEditor.js +215 -0
  55. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -0
  56. package/dist/ThresholdsEditor/index.d.ts +2 -0
  57. package/dist/ThresholdsEditor/index.d.ts.map +1 -0
  58. package/dist/ThresholdsEditor/index.js +15 -0
  59. package/dist/ThresholdsEditor/index.js.map +1 -0
  60. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +1 -1
  61. package/dist/TimeSeriesTooltip/focused-series.js +3 -3
  62. package/dist/TimeSeriesTooltip/focused-series.js.map +1 -1
  63. package/dist/cjs/ColorPicker/ColorPicker.js +128 -0
  64. package/dist/cjs/{model/legend.test.js → ColorPicker/index.js} +11 -12
  65. package/dist/cjs/Dialog/Dialog.js +11 -0
  66. package/dist/{model/legend.test.js → cjs/EChart/index.js} +15 -14
  67. package/dist/cjs/InfoTooltip/InfoTooltip.js +7 -3
  68. package/dist/cjs/Legend/Legend.js +5 -8
  69. package/dist/cjs/LineChart/LineChart.js +40 -1
  70. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  71. package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +22 -5
  72. package/dist/cjs/StatChart/StatChart.js +1 -41
  73. package/dist/cjs/ThresholdsEditor/ThresholdColorPicker.js +87 -0
  74. package/dist/cjs/ThresholdsEditor/ThresholdInput.js +72 -0
  75. package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +265 -0
  76. package/dist/cjs/ThresholdsEditor/index.js +28 -0
  77. package/dist/cjs/TimeSeriesTooltip/focused-series.js +3 -3
  78. package/dist/cjs/index.js +2 -0
  79. package/dist/cjs/test-utils/theme.js +8 -0
  80. package/dist/cjs/theme/component-overrides/alert.js +102 -0
  81. package/dist/cjs/theme/theme.js +4 -8
  82. package/dist/cjs/utils/theme-gen.js +8 -0
  83. package/dist/index.d.ts +2 -0
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -0
  86. package/dist/index.js.map +1 -1
  87. package/dist/model/graph.d.ts +2 -2
  88. package/dist/model/graph.d.ts.map +1 -1
  89. package/dist/model/graph.js.map +1 -1
  90. package/dist/model/legend.d.ts +1 -1
  91. package/dist/model/legend.d.ts.map +1 -1
  92. package/dist/model/legend.js.map +1 -1
  93. package/dist/model/theme.d.ts +5 -0
  94. package/dist/model/theme.d.ts.map +1 -1
  95. package/dist/model/theme.js.map +1 -1
  96. package/dist/model/units/bytes.d.ts +1 -1
  97. package/dist/model/units/bytes.d.ts.map +1 -1
  98. package/dist/model/units/bytes.js.map +1 -1
  99. package/dist/model/units/decimal.d.ts +1 -1
  100. package/dist/model/units/decimal.d.ts.map +1 -1
  101. package/dist/model/units/decimal.js.map +1 -1
  102. package/dist/model/units/percent.d.ts +1 -1
  103. package/dist/model/units/percent.d.ts.map +1 -1
  104. package/dist/model/units/percent.js.map +1 -1
  105. package/dist/model/units/time.d.ts +1 -1
  106. package/dist/model/units/time.d.ts.map +1 -1
  107. package/dist/model/units/time.js.map +1 -1
  108. package/dist/model/units/types.d.ts +1 -1
  109. package/dist/model/units/types.d.ts.map +1 -1
  110. package/dist/model/units/types.js.map +1 -1
  111. package/dist/test-utils/theme.d.ts.map +1 -1
  112. package/dist/test-utils/theme.js +8 -0
  113. package/dist/test-utils/theme.js.map +1 -1
  114. package/dist/theme/component-overrides/alert.d.ts +3 -0
  115. package/dist/theme/component-overrides/alert.d.ts.map +1 -0
  116. package/dist/theme/component-overrides/alert.js +96 -0
  117. package/dist/theme/component-overrides/alert.js.map +1 -0
  118. package/dist/theme/theme.d.ts.map +1 -1
  119. package/dist/theme/theme.js +5 -9
  120. package/dist/theme/theme.js.map +1 -1
  121. package/dist/utils/theme-gen.d.ts.map +1 -1
  122. package/dist/utils/theme-gen.js +8 -0
  123. package/dist/utils/theme-gen.js.map +1 -1
  124. package/package.json +8 -3
  125. package/dist/EChart.d.ts.map +0 -1
  126. package/dist/EChart.js.map +0 -1
  127. package/dist/InfoTooltip/InfoTooltip.test.d.ts +0 -2
  128. package/dist/InfoTooltip/InfoTooltip.test.d.ts.map +0 -1
  129. package/dist/InfoTooltip/InfoTooltip.test.js +0 -36
  130. package/dist/InfoTooltip/InfoTooltip.test.js.map +0 -1
  131. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +0 -2
  132. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +0 -1
  133. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +0 -62
  134. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +0 -1
  135. package/dist/StatChart/StatChart.test.d.ts +0 -2
  136. package/dist/StatChart/StatChart.test.d.ts.map +0 -1
  137. package/dist/StatChart/StatChart.test.js +0 -94
  138. package/dist/StatChart/StatChart.test.js.map +0 -1
  139. package/dist/TimeSeriesTooltip/SeriesInfo.test.d.ts +0 -2
  140. package/dist/TimeSeriesTooltip/SeriesInfo.test.d.ts.map +0 -1
  141. package/dist/TimeSeriesTooltip/SeriesInfo.test.js +0 -52
  142. package/dist/TimeSeriesTooltip/SeriesInfo.test.js.map +0 -1
  143. package/dist/TimeSeriesTooltip/TooltipContent.test.d.ts +0 -2
  144. package/dist/TimeSeriesTooltip/TooltipContent.test.d.ts.map +0 -1
  145. package/dist/TimeSeriesTooltip/TooltipContent.test.js +0 -78
  146. package/dist/TimeSeriesTooltip/TooltipContent.test.js.map +0 -1
  147. package/dist/TimeSeriesTooltip/focused-series.test.d.ts +0 -2
  148. package/dist/TimeSeriesTooltip/focused-series.test.d.ts.map +0 -1
  149. package/dist/TimeSeriesTooltip/focused-series.test.js +0 -93
  150. package/dist/TimeSeriesTooltip/focused-series.test.js.map +0 -1
  151. package/dist/UnitSelector/UnitSelector.test.d.ts +0 -2
  152. package/dist/UnitSelector/UnitSelector.test.d.ts.map +0 -1
  153. package/dist/UnitSelector/UnitSelector.test.js +0 -204
  154. package/dist/UnitSelector/UnitSelector.test.js.map +0 -1
  155. package/dist/cjs/InfoTooltip/InfoTooltip.test.js +0 -43
  156. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +0 -69
  157. package/dist/cjs/StatChart/StatChart.test.js +0 -96
  158. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.test.js +0 -54
  159. package/dist/cjs/TimeSeriesTooltip/TooltipContent.test.js +0 -80
  160. package/dist/cjs/TimeSeriesTooltip/focused-series.test.js +0 -95
  161. package/dist/cjs/UnitSelector/UnitSelector.test.js +0 -211
  162. package/dist/cjs/model/units/units.test.js +0 -206
  163. package/dist/cjs/utils/format.test.js +0 -47
  164. package/dist/cjs/utils/theme-gen.test.js +0 -202
  165. package/dist/model/legend.test.d.ts +0 -2
  166. package/dist/model/legend.test.d.ts.map +0 -1
  167. package/dist/model/legend.test.js.map +0 -1
  168. package/dist/model/units/units.test.d.ts +0 -2
  169. package/dist/model/units/units.test.d.ts.map +0 -1
  170. package/dist/model/units/units.test.js +0 -204
  171. package/dist/model/units/units.test.js.map +0 -1
  172. package/dist/utils/format.test.d.ts +0 -2
  173. package/dist/utils/format.test.d.ts.map +0 -1
  174. package/dist/utils/format.test.js +0 -45
  175. package/dist/utils/format.test.js.map +0 -1
  176. package/dist/utils/theme-gen.test.d.ts +0 -2
  177. package/dist/utils/theme-gen.test.d.ts.map +0 -1
  178. package/dist/utils/theme-gen.test.js +0 -200
  179. package/dist/utils/theme-gen.test.js.map +0 -1
  180. /package/dist/{EChart.js → EChart/EChart.js} +0 -0
  181. /package/dist/cjs/{EChart.js → EChart/EChart.js} +0 -0
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "LineChart", {
19
19
  get: ()=>LineChart
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
- const _react = require("react");
22
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
23
  const _material = require("@mui/material");
24
24
  const _core = require("echarts/core");
25
25
  const _charts = require("echarts/charts");
@@ -31,6 +31,45 @@ const _chartsThemeProvider = require("../context/ChartsThemeProvider");
31
31
  const _timeSeriesTooltip = require("../TimeSeriesTooltip");
32
32
  const _timeZoneProvider = require("../context/TimeZoneProvider");
33
33
  const _utils = require("./utils");
34
+ function _getRequireWildcardCache(nodeInterop) {
35
+ if (typeof WeakMap !== "function") return null;
36
+ var cacheBabelInterop = new WeakMap();
37
+ var cacheNodeInterop = new WeakMap();
38
+ return (_getRequireWildcardCache = function(nodeInterop) {
39
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
40
+ })(nodeInterop);
41
+ }
42
+ function _interopRequireWildcard(obj, nodeInterop) {
43
+ if (!nodeInterop && obj && obj.__esModule) {
44
+ return obj;
45
+ }
46
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
47
+ return {
48
+ default: obj
49
+ };
50
+ }
51
+ var cache = _getRequireWildcardCache(nodeInterop);
52
+ if (cache && cache.has(obj)) {
53
+ return cache.get(obj);
54
+ }
55
+ var newObj = {};
56
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
57
+ for(var key in obj){
58
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
59
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
60
+ if (desc && (desc.get || desc.set)) {
61
+ Object.defineProperty(newObj, key, desc);
62
+ } else {
63
+ newObj[key] = obj[key];
64
+ }
65
+ }
66
+ }
67
+ newObj.default = obj;
68
+ if (cache) {
69
+ cache.set(obj, newObj);
70
+ }
71
+ return newObj;
72
+ }
34
73
  (0, _core.use)([
35
74
  _charts.LineChart,
36
75
  _components.GridComponent,
@@ -47,7 +47,7 @@ const OptionsEditorControl = ({ label , control })=>{
47
47
  }),
48
48
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
49
49
  sx: {
50
- width: '160px',
50
+ width: '150px',
51
51
  textAlign: 'right'
52
52
  },
53
53
  children: [
@@ -20,16 +20,33 @@ Object.defineProperty(exports, "OptionsEditorGroup", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
- const OptionsEditorGroup = ({ title , children })=>{
23
+ const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
24
+ function _interopRequireDefault(obj) {
25
+ return obj && obj.__esModule ? obj : {
26
+ default: obj
27
+ };
28
+ }
29
+ const OptionsEditorGroup = ({ title , children , icon })=>{
24
30
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
25
31
  children: [
26
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
27
- variant: "overline",
28
- component: "h4",
32
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
33
+ display: "flex",
29
34
  borderBottom: 1,
30
35
  borderColor: "grey.300",
31
36
  marginBottom: (theme)=>theme.spacing(1),
32
- children: title
37
+ children: [
38
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
39
+ variant: "overline",
40
+ component: "h4",
41
+ children: title
42
+ }),
43
+ icon && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
44
+ sx: {
45
+ marginLeft: 'auto'
46
+ },
47
+ children: icon
48
+ })
49
+ ]
33
50
  }),
34
51
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
35
52
  spacing: 1,
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "StatChart", {
19
19
  get: ()=>StatChart
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
22
+ const _react = require("react");
23
23
  const _material = require("@mui/material");
24
24
  const _lodashEs = require("lodash-es");
25
25
  const _core = require("echarts/core");
@@ -29,47 +29,7 @@ const _renderers = require("echarts/renderers");
29
29
  const _chartsThemeProvider = require("../context/ChartsThemeProvider");
30
30
  const _units = require("../model/units");
31
31
  const _echart = require("../EChart");
32
- function _getRequireWildcardCache(nodeInterop) {
33
- if (typeof WeakMap !== "function") return null;
34
- var cacheBabelInterop = new WeakMap();
35
- var cacheNodeInterop = new WeakMap();
36
- return (_getRequireWildcardCache = function(nodeInterop) {
37
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
38
- })(nodeInterop);
39
- }
40
- function _interopRequireWildcard(obj, nodeInterop) {
41
- if (!nodeInterop && obj && obj.__esModule) {
42
- return obj;
43
- }
44
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
45
- return {
46
- default: obj
47
- };
48
- }
49
- var cache = _getRequireWildcardCache(nodeInterop);
50
- if (cache && cache.has(obj)) {
51
- return cache.get(obj);
52
- }
53
- var newObj = {};
54
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
55
- for(var key in obj){
56
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
57
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
58
- if (desc && (desc.get || desc.set)) {
59
- Object.defineProperty(newObj, key, desc);
60
- } else {
61
- newObj[key] = obj[key];
62
- }
63
- }
64
- }
65
- newObj.default = obj;
66
- if (cache) {
67
- cache.set(obj, newObj);
68
- }
69
- return newObj;
70
- }
71
32
  (0, _core.use)([
72
- _charts.GaugeChart,
73
33
  _charts.LineChart,
74
34
  _components.GridComponent,
75
35
  _components.DatasetComponent,
@@ -0,0 +1,87 @@
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, "ThresholdColorPicker", {
18
+ enumerable: true,
19
+ get: ()=>ThresholdColorPicker
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
23
+ const _material = require("@mui/material");
24
+ const _circle = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Circle"));
25
+ const _chartsThemeProvider = require("../context/ChartsThemeProvider");
26
+ const _colorPicker = require("../ColorPicker");
27
+ function _interopRequireDefault(obj) {
28
+ return obj && obj.__esModule ? obj : {
29
+ default: obj
30
+ };
31
+ }
32
+ function ThresholdColorPicker({ color , onColorChange , label }) {
33
+ const [anchorEl, setAnchorEl] = _react.default.useState(null);
34
+ const isOpen = Boolean(anchorEl);
35
+ const openColorPicker = (event)=>{
36
+ setAnchorEl(event.currentTarget);
37
+ };
38
+ const closeColorPicker = ()=>{
39
+ setAnchorEl(null);
40
+ };
41
+ const { thresholds: { defaultColor , palette } , } = (0, _chartsThemeProvider.useChartsTheme)();
42
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
43
+ children: [
44
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(ColorIconButton, {
45
+ size: "small",
46
+ "aria-label": `change threshold ${label} color`,
47
+ isSelected: isOpen,
48
+ iconColor: color,
49
+ onClick: openColorPicker,
50
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_circle.default, {})
51
+ }),
52
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Popover, {
53
+ "data-testid": "threshold color picker",
54
+ open: isOpen,
55
+ anchorEl: anchorEl,
56
+ onClose: closeColorPicker,
57
+ PaperProps: {
58
+ sx: {
59
+ padding: (theme)=>theme.spacing(2)
60
+ }
61
+ },
62
+ anchorOrigin: {
63
+ vertical: 'top',
64
+ horizontal: 'left'
65
+ },
66
+ transformOrigin: {
67
+ vertical: 'top',
68
+ horizontal: 'right'
69
+ },
70
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_colorPicker.ColorPicker, {
71
+ color: color,
72
+ onChange: onColorChange,
73
+ palette: [
74
+ defaultColor,
75
+ ...palette
76
+ ]
77
+ })
78
+ })
79
+ ]
80
+ });
81
+ }
82
+ const ColorIconButton = (0, _material.styled)(_material.IconButton, {
83
+ shouldForwardProp: (props)=>props !== 'isSelected' && props !== 'iconColor'
84
+ })(({ iconColor , isSelected })=>({
85
+ backgroundColor: isSelected && iconColor ? `${iconColor}3F` : 'undefined',
86
+ color: iconColor
87
+ }));
@@ -0,0 +1,72 @@
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, "ThresholdInput", {
18
+ enumerable: true,
19
+ get: ()=>ThresholdInput
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ const _deleteOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/DeleteOutline"));
25
+ const _thresholdColorPicker = require("./ThresholdColorPicker");
26
+ function _interopRequireDefault(obj) {
27
+ return obj && obj.__esModule ? obj : {
28
+ default: obj
29
+ };
30
+ }
31
+ function ThresholdInput({ inputRef , label , color , value , onChange , onColorChange , onBlur , onDelete }) {
32
+ const [key, setKey] = (0, _react.useState)(0); // use key to cause input to lose focus when pressing enter
33
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
34
+ flex: 1,
35
+ direction: "row",
36
+ alignItems: "center",
37
+ justifyContent: "space-between",
38
+ spacing: 1,
39
+ children: [
40
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_thresholdColorPicker.ThresholdColorPicker, {
41
+ label: label,
42
+ color: color,
43
+ onColorChange: onColorChange
44
+ }),
45
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormLabel, {
46
+ htmlFor: label,
47
+ children: label
48
+ }),
49
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
50
+ id: label,
51
+ inputRef: inputRef,
52
+ type: "number",
53
+ value: value === 0 ? undefined : value,
54
+ placeholder: "0",
55
+ onChange: onChange,
56
+ onBlur: onBlur,
57
+ onKeyDown: (e)=>{
58
+ if (e.key === 'Enter') {
59
+ onBlur();
60
+ setKey(key + 1);
61
+ }
62
+ }
63
+ }, key),
64
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
65
+ "aria-label": `delete threshold ${label}`,
66
+ size: "small",
67
+ onClick: onDelete,
68
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_deleteOutline.default, {})
69
+ })
70
+ ]
71
+ });
72
+ }
@@ -0,0 +1,265 @@
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, "ThresholdsEditor", {
18
+ enumerable: true,
19
+ get: ()=>ThresholdsEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
+ const _immer = /*#__PURE__*/ _interopRequireDefault(require("immer"));
24
+ const _material = require("@mui/material");
25
+ const _plus = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Plus"));
26
+ const _system = require("@mui/system");
27
+ const _infoTooltip = require("../InfoTooltip");
28
+ const _chartsThemeProvider = require("../context/ChartsThemeProvider");
29
+ const _optionsEditorLayout = require("../OptionsEditorLayout");
30
+ const _thresholdColorPicker = require("./ThresholdColorPicker");
31
+ const _thresholdInput = require("./ThresholdInput");
32
+ function _interopRequireDefault(obj) {
33
+ return obj && obj.__esModule ? obj : {
34
+ default: obj
35
+ };
36
+ }
37
+ function _getRequireWildcardCache(nodeInterop) {
38
+ if (typeof WeakMap !== "function") return null;
39
+ var cacheBabelInterop = new WeakMap();
40
+ var cacheNodeInterop = new WeakMap();
41
+ return (_getRequireWildcardCache = function(nodeInterop) {
42
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
43
+ })(nodeInterop);
44
+ }
45
+ function _interopRequireWildcard(obj, nodeInterop) {
46
+ if (!nodeInterop && obj && obj.__esModule) {
47
+ return obj;
48
+ }
49
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
50
+ return {
51
+ default: obj
52
+ };
53
+ }
54
+ var cache = _getRequireWildcardCache(nodeInterop);
55
+ if (cache && cache.has(obj)) {
56
+ return cache.get(obj);
57
+ }
58
+ var newObj = {};
59
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
60
+ for(var key in obj){
61
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
62
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
63
+ if (desc && (desc.get || desc.set)) {
64
+ Object.defineProperty(newObj, key, desc);
65
+ } else {
66
+ newObj[key] = obj[key];
67
+ }
68
+ }
69
+ }
70
+ newObj.default = obj;
71
+ if (cache) {
72
+ cache.set(obj, newObj);
73
+ }
74
+ return newObj;
75
+ }
76
+ const DEFAULT_STEP = 10;
77
+ function ThresholdsEditor({ thresholds , onChange , hideDefault , disablePercentMode }) {
78
+ const { thresholds: { defaultColor , palette } , } = (0, _chartsThemeProvider.useChartsTheme)();
79
+ var ref;
80
+ const defaultThresholdColor = (ref = thresholds === null || thresholds === void 0 ? void 0 : thresholds.default_color) !== null && ref !== void 0 ? ref : defaultColor;
81
+ const [steps, setSteps] = (0, _react.useState)(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps);
82
+ (0, _react.useEffect)(()=>{
83
+ setSteps(thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps);
84
+ }, [
85
+ thresholds === null || thresholds === void 0 ? void 0 : thresholds.steps
86
+ ]);
87
+ // every time a new threshold is added, we want to focus the recently added input
88
+ const recentlyAddedInputRef = (0, _react.useRef)(null);
89
+ const focusRef = (0, _react.useRef)(false);
90
+ (0, _react.useEffect)(()=>{
91
+ var ref;
92
+ if (!recentlyAddedInputRef.current || !focusRef.current) return;
93
+ (ref = recentlyAddedInputRef.current) === null || ref === void 0 ? void 0 : ref.focus();
94
+ focusRef.current = false;
95
+ }, [
96
+ steps === null || steps === void 0 ? void 0 : steps.length
97
+ ]);
98
+ const handleThresholdValueChange = (e, i)=>{
99
+ setSteps((0, _immer.default)(steps, (draft)=>{
100
+ const step = draft === null || draft === void 0 ? void 0 : draft[i];
101
+ if (step) {
102
+ step.value = Number(e.target.value);
103
+ }
104
+ }));
105
+ };
106
+ const handleThresholdColorChange = (color, i)=>{
107
+ if (thresholds !== undefined) {
108
+ onChange((0, _immer.default)(thresholds, (draft)=>{
109
+ if (draft.steps !== undefined) {
110
+ const step = draft.steps[i];
111
+ if (step) {
112
+ step.color = color;
113
+ }
114
+ }
115
+ }));
116
+ }
117
+ };
118
+ const handleDefaultColorChange = (color)=>{
119
+ if (thresholds !== undefined) {
120
+ onChange((0, _immer.default)(thresholds, (draft)=>{
121
+ draft.default_color = color;
122
+ }));
123
+ }
124
+ };
125
+ // sort thresholds in ascending order every time an input blurs
126
+ const handleThresholdBlur = ()=>{
127
+ if (steps !== undefined) {
128
+ const sortedSteps = [
129
+ ...steps
130
+ ];
131
+ sortedSteps.sort((a, b)=>a.value - b.value);
132
+ if (thresholds !== undefined) {
133
+ onChange((0, _immer.default)(thresholds, (draft)=>{
134
+ draft.steps = sortedSteps;
135
+ }));
136
+ }
137
+ }
138
+ };
139
+ const deleteThreshold = (i)=>{
140
+ if (thresholds !== undefined) {
141
+ const updatedThresholds = (0, _immer.default)(thresholds, (draft)=>{
142
+ if (draft.steps) {
143
+ draft.steps.splice(i, 1);
144
+ }
145
+ });
146
+ onChange(updatedThresholds);
147
+ }
148
+ };
149
+ const addThresholdInput = ()=>{
150
+ focusRef.current = true;
151
+ if (thresholds === undefined) {
152
+ onChange({
153
+ steps: [
154
+ {
155
+ value: DEFAULT_STEP
156
+ }
157
+ ]
158
+ });
159
+ } else {
160
+ onChange((0, _immer.default)(thresholds, (draft)=>{
161
+ const steps = draft.steps;
162
+ if (steps === null || steps === void 0 ? void 0 : steps.length) {
163
+ const lastStep = steps[steps.length - 1];
164
+ var _length;
165
+ const color = (_length = palette[steps.length]) !== null && _length !== void 0 ? _length : getRandomColor(); // we will assign color from the palette first, then generate random color
166
+ var ref;
167
+ steps.push({
168
+ color,
169
+ value: ((ref = lastStep === null || lastStep === void 0 ? void 0 : lastStep.value) !== null && ref !== void 0 ? ref : 0) + DEFAULT_STEP
170
+ }); // set new threshold value to last step value + 10
171
+ } else if (steps) {
172
+ steps.push({
173
+ value: DEFAULT_STEP
174
+ });
175
+ }
176
+ }));
177
+ }
178
+ };
179
+ const handleModeChange = (event, value)=>{
180
+ const mode = value === 'Percent' ? 'Percent' : undefined;
181
+ if (thresholds !== undefined) {
182
+ onChange((0, _immer.default)(thresholds, (draft)=>{
183
+ draft.mode = mode;
184
+ }));
185
+ } else {
186
+ onChange({
187
+ mode
188
+ });
189
+ }
190
+ };
191
+ var ref1, _color, ref2;
192
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_optionsEditorLayout.OptionsEditorGroup, {
193
+ title: "Thresholds",
194
+ icon: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
195
+ size: "small",
196
+ "aria-label": "add threshold",
197
+ onClick: addThresholdInput,
198
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_plus.default, {})
199
+ }),
200
+ children: [
201
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.ToggleButtonGroup, {
202
+ exclusive: true,
203
+ disabled: disablePercentMode,
204
+ value: (ref1 = thresholds === null || thresholds === void 0 ? void 0 : thresholds.mode) !== null && ref1 !== void 0 ? ref1 : 'Absolute',
205
+ onChange: handleModeChange,
206
+ sx: {
207
+ height: '36px',
208
+ marginLeft: 'auto'
209
+ },
210
+ children: [
211
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ToggleButton, {
212
+ "aria-label": "absolute",
213
+ value: "Absolute",
214
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_infoTooltip.InfoTooltip, {
215
+ description: "Absolute",
216
+ children: "#"
217
+ })
218
+ }),
219
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.ToggleButton, {
220
+ "aria-label": "percent",
221
+ value: "Percent",
222
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_infoTooltip.InfoTooltip, {
223
+ description: "Percentage means thresholds relative to min & max",
224
+ children: "%"
225
+ })
226
+ })
227
+ ]
228
+ }),
229
+ steps && steps.map((step, i)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_thresholdInput.ThresholdInput, {
230
+ inputRef: i === steps.length - 1 ? recentlyAddedInputRef : undefined,
231
+ label: `T${i + 1}`,
232
+ color: (ref2 = (_color = step.color) !== null && _color !== void 0 ? _color : palette[i]) !== null && ref2 !== void 0 ? ref2 : defaultThresholdColor,
233
+ value: step.value,
234
+ onColorChange: (color)=>handleThresholdColorChange(color, i),
235
+ onChange: (e)=>{
236
+ handleThresholdValueChange(e, i);
237
+ },
238
+ onDelete: ()=>{
239
+ deleteThreshold(i);
240
+ },
241
+ onBlur: handleThresholdBlur
242
+ }, i)).reverse(),
243
+ !hideDefault && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_system.Stack, {
244
+ flex: 1,
245
+ direction: "row",
246
+ alignItems: "center",
247
+ spacing: 1,
248
+ children: [
249
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_thresholdColorPicker.ThresholdColorPicker, {
250
+ label: "default",
251
+ color: defaultThresholdColor,
252
+ onColorChange: handleDefaultColorChange
253
+ }),
254
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
255
+ children: "Default"
256
+ })
257
+ ]
258
+ })
259
+ ]
260
+ });
261
+ }
262
+ // https://www.paulirish.com/2009/random-hex-color-code-snippets/
263
+ const getRandomColor = ()=>{
264
+ return '#' + Math.floor(Math.random() * 16777216).toString(16).padStart(6, '0');
265
+ };
@@ -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("./ThresholdsEditor"), 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
+ }
@@ -47,9 +47,9 @@ function getNearbySeries(data, pointInGrid, yBuffer, unit) {
47
47
  for(let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++){
48
48
  var _datumIdx;
49
49
  const xValue = (_datumIdx = data.xAxis[datumIdx]) !== null && _datumIdx !== void 0 ? _datumIdx : 0;
50
- var _datumIdx1;
51
- const yValue = (_datumIdx1 = currentSeries.data[datumIdx]) !== null && _datumIdx1 !== void 0 ? _datumIdx1 : 0;
52
- if (focusedX === datumIdx) {
50
+ const yValue = currentSeries.data[datumIdx];
51
+ // ensure null values not displayed in tooltip
52
+ if (yValue !== undefined && yValue !== null && focusedX === datumIdx) {
53
53
  if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {
54
54
  // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
55
55
  const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
package/dist/cjs/index.js CHANGED
@@ -14,6 +14,7 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
+ _exportStar(require("./ColorPicker"), exports);
17
18
  _exportStar(require("./DateTimeRangePicker"), exports);
18
19
  _exportStar(require("./Dialog"), exports);
19
20
  _exportStar(require("./Drawer"), exports);
@@ -28,6 +29,7 @@ _exportStar(require("./LegendOptionsEditor"), exports);
28
29
  _exportStar(require("./LineChart"), exports);
29
30
  _exportStar(require("./OptionsEditorLayout"), exports);
30
31
  _exportStar(require("./StatChart"), exports);
32
+ _exportStar(require("./ThresholdsEditor"), exports);
31
33
  _exportStar(require("./TimeSeriesTooltip"), exports);
32
34
  _exportStar(require("./UnitSelector"), exports);
33
35
  _exportStar(require("./YAxisLabel"), exports);
@@ -29,5 +29,13 @@ const testChartsTheme = {
29
29
  padding: {
30
30
  default: 12
31
31
  }
32
+ },
33
+ thresholds: {
34
+ defaultColor: '#59CC8D',
35
+ palette: [
36
+ '#438FEB',
37
+ '#FFB249',
38
+ '#EE6C6C'
39
+ ]
32
40
  }
33
41
  };