@perses-dev/components 0.23.1 → 0.24.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 (152) 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/EChart.d.ts +2 -2
  10. package/dist/EChart.d.ts.map +1 -1
  11. package/dist/EChart.js.map +1 -1
  12. package/dist/Legend/Legend.js +6 -9
  13. package/dist/Legend/Legend.js.map +1 -1
  14. package/dist/LineChart/LineChart.d.ts +4 -2
  15. package/dist/LineChart/LineChart.d.ts.map +1 -1
  16. package/dist/LineChart/LineChart.js +1 -1
  17. package/dist/LineChart/LineChart.js.map +1 -1
  18. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  19. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  20. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +3 -2
  21. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -1
  22. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +17 -5
  23. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -1
  24. package/dist/StatChart/StatChart.d.ts +0 -1
  25. package/dist/StatChart/StatChart.d.ts.map +1 -1
  26. package/dist/StatChart/StatChart.js +1 -3
  27. package/dist/StatChart/StatChart.js.map +1 -1
  28. package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts +4 -0
  29. package/dist/ThresholdsEditor/ThresholdColorPicker.d.ts.map +1 -0
  30. package/dist/ThresholdsEditor/ThresholdColorPicker.js +76 -0
  31. package/dist/ThresholdsEditor/ThresholdColorPicker.js.map +1 -0
  32. package/dist/ThresholdsEditor/ThresholdInput.d.ts +13 -0
  33. package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -0
  34. package/dist/ThresholdsEditor/ThresholdInput.js +61 -0
  35. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -0
  36. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +10 -0
  37. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -0
  38. package/dist/ThresholdsEditor/ThresholdsEditor.js +215 -0
  39. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -0
  40. package/dist/ThresholdsEditor/index.d.ts +2 -0
  41. package/dist/ThresholdsEditor/index.d.ts.map +1 -0
  42. package/dist/ThresholdsEditor/index.js +15 -0
  43. package/dist/ThresholdsEditor/index.js.map +1 -0
  44. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +1 -1
  45. package/dist/TimeSeriesTooltip/focused-series.js +3 -3
  46. package/dist/TimeSeriesTooltip/focused-series.js.map +1 -1
  47. package/dist/cjs/ColorPicker/ColorPicker.js +128 -0
  48. package/dist/cjs/{model/legend.test.js → ColorPicker/index.js} +11 -12
  49. package/dist/cjs/Legend/Legend.js +5 -8
  50. package/dist/cjs/LineChart/LineChart.js +40 -1
  51. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  52. package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +22 -5
  53. package/dist/cjs/StatChart/StatChart.js +1 -41
  54. package/dist/cjs/ThresholdsEditor/ThresholdColorPicker.js +87 -0
  55. package/dist/cjs/ThresholdsEditor/ThresholdInput.js +72 -0
  56. package/dist/cjs/ThresholdsEditor/ThresholdsEditor.js +265 -0
  57. package/dist/{model/legend.test.js → cjs/ThresholdsEditor/index.js} +15 -14
  58. package/dist/cjs/TimeSeriesTooltip/focused-series.js +3 -3
  59. package/dist/cjs/index.js +2 -0
  60. package/dist/cjs/test-utils/theme.js +8 -0
  61. package/dist/cjs/theme/theme.js +5 -0
  62. package/dist/cjs/utils/theme-gen.js +8 -0
  63. package/dist/index.d.ts +2 -0
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +2 -0
  66. package/dist/index.js.map +1 -1
  67. package/dist/model/graph.d.ts +2 -2
  68. package/dist/model/graph.d.ts.map +1 -1
  69. package/dist/model/graph.js.map +1 -1
  70. package/dist/model/legend.d.ts +1 -1
  71. package/dist/model/legend.d.ts.map +1 -1
  72. package/dist/model/legend.js.map +1 -1
  73. package/dist/model/theme.d.ts +5 -0
  74. package/dist/model/theme.d.ts.map +1 -1
  75. package/dist/model/theme.js.map +1 -1
  76. package/dist/model/units/bytes.d.ts +1 -1
  77. package/dist/model/units/bytes.d.ts.map +1 -1
  78. package/dist/model/units/bytes.js.map +1 -1
  79. package/dist/model/units/decimal.d.ts +1 -1
  80. package/dist/model/units/decimal.d.ts.map +1 -1
  81. package/dist/model/units/decimal.js.map +1 -1
  82. package/dist/model/units/percent.d.ts +1 -1
  83. package/dist/model/units/percent.d.ts.map +1 -1
  84. package/dist/model/units/percent.js.map +1 -1
  85. package/dist/model/units/time.d.ts +1 -1
  86. package/dist/model/units/time.d.ts.map +1 -1
  87. package/dist/model/units/time.js.map +1 -1
  88. package/dist/model/units/types.d.ts +1 -1
  89. package/dist/model/units/types.d.ts.map +1 -1
  90. package/dist/model/units/types.js.map +1 -1
  91. package/dist/test-utils/theme.d.ts.map +1 -1
  92. package/dist/test-utils/theme.js +8 -0
  93. package/dist/test-utils/theme.js.map +1 -1
  94. package/dist/theme/theme.js +5 -0
  95. package/dist/theme/theme.js.map +1 -1
  96. package/dist/utils/theme-gen.d.ts.map +1 -1
  97. package/dist/utils/theme-gen.js +8 -0
  98. package/dist/utils/theme-gen.js.map +1 -1
  99. package/package.json +5 -3
  100. package/dist/InfoTooltip/InfoTooltip.test.d.ts +0 -2
  101. package/dist/InfoTooltip/InfoTooltip.test.d.ts.map +0 -1
  102. package/dist/InfoTooltip/InfoTooltip.test.js +0 -36
  103. package/dist/InfoTooltip/InfoTooltip.test.js.map +0 -1
  104. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +0 -2
  105. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +0 -1
  106. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +0 -62
  107. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +0 -1
  108. package/dist/StatChart/StatChart.test.d.ts +0 -2
  109. package/dist/StatChart/StatChart.test.d.ts.map +0 -1
  110. package/dist/StatChart/StatChart.test.js +0 -94
  111. package/dist/StatChart/StatChart.test.js.map +0 -1
  112. package/dist/TimeSeriesTooltip/SeriesInfo.test.d.ts +0 -2
  113. package/dist/TimeSeriesTooltip/SeriesInfo.test.d.ts.map +0 -1
  114. package/dist/TimeSeriesTooltip/SeriesInfo.test.js +0 -52
  115. package/dist/TimeSeriesTooltip/SeriesInfo.test.js.map +0 -1
  116. package/dist/TimeSeriesTooltip/TooltipContent.test.d.ts +0 -2
  117. package/dist/TimeSeriesTooltip/TooltipContent.test.d.ts.map +0 -1
  118. package/dist/TimeSeriesTooltip/TooltipContent.test.js +0 -78
  119. package/dist/TimeSeriesTooltip/TooltipContent.test.js.map +0 -1
  120. package/dist/TimeSeriesTooltip/focused-series.test.d.ts +0 -2
  121. package/dist/TimeSeriesTooltip/focused-series.test.d.ts.map +0 -1
  122. package/dist/TimeSeriesTooltip/focused-series.test.js +0 -93
  123. package/dist/TimeSeriesTooltip/focused-series.test.js.map +0 -1
  124. package/dist/UnitSelector/UnitSelector.test.d.ts +0 -2
  125. package/dist/UnitSelector/UnitSelector.test.d.ts.map +0 -1
  126. package/dist/UnitSelector/UnitSelector.test.js +0 -204
  127. package/dist/UnitSelector/UnitSelector.test.js.map +0 -1
  128. package/dist/cjs/InfoTooltip/InfoTooltip.test.js +0 -43
  129. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +0 -69
  130. package/dist/cjs/StatChart/StatChart.test.js +0 -96
  131. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.test.js +0 -54
  132. package/dist/cjs/TimeSeriesTooltip/TooltipContent.test.js +0 -80
  133. package/dist/cjs/TimeSeriesTooltip/focused-series.test.js +0 -95
  134. package/dist/cjs/UnitSelector/UnitSelector.test.js +0 -211
  135. package/dist/cjs/model/units/units.test.js +0 -206
  136. package/dist/cjs/utils/format.test.js +0 -47
  137. package/dist/cjs/utils/theme-gen.test.js +0 -202
  138. package/dist/model/legend.test.d.ts +0 -2
  139. package/dist/model/legend.test.d.ts.map +0 -1
  140. package/dist/model/legend.test.js.map +0 -1
  141. package/dist/model/units/units.test.d.ts +0 -2
  142. package/dist/model/units/units.test.d.ts.map +0 -1
  143. package/dist/model/units/units.test.js +0 -204
  144. package/dist/model/units/units.test.js.map +0 -1
  145. package/dist/utils/format.test.d.ts +0 -2
  146. package/dist/utils/format.test.d.ts.map +0 -1
  147. package/dist/utils/format.test.js +0 -45
  148. package/dist/utils/format.test.js.map +0 -1
  149. package/dist/utils/theme-gen.test.d.ts +0 -2
  150. package/dist/utils/theme-gen.test.d.ts.map +0 -1
  151. package/dist/utils/theme-gen.test.js +0 -200
  152. package/dist/utils/theme-gen.test.js.map +0 -1
@@ -0,0 +1,128 @@
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, "ColorPicker", {
18
+ enumerable: true,
19
+ get: ()=>ColorPicker
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
24
+ const _reactColorful = require("react-colorful");
25
+ const _circle = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Circle"));
26
+ function _interopRequireDefault(obj) {
27
+ return obj && obj.__esModule ? obj : {
28
+ default: obj
29
+ };
30
+ }
31
+ function _getRequireWildcardCache(nodeInterop) {
32
+ if (typeof WeakMap !== "function") return null;
33
+ var cacheBabelInterop = new WeakMap();
34
+ var cacheNodeInterop = new WeakMap();
35
+ return (_getRequireWildcardCache = function(nodeInterop) {
36
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
37
+ })(nodeInterop);
38
+ }
39
+ function _interopRequireWildcard(obj, nodeInterop) {
40
+ if (!nodeInterop && obj && obj.__esModule) {
41
+ return obj;
42
+ }
43
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
44
+ return {
45
+ default: obj
46
+ };
47
+ }
48
+ var cache = _getRequireWildcardCache(nodeInterop);
49
+ if (cache && cache.has(obj)) {
50
+ return cache.get(obj);
51
+ }
52
+ var newObj = {};
53
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
54
+ for(var key in obj){
55
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
56
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
57
+ if (desc && (desc.get || desc.set)) {
58
+ Object.defineProperty(newObj, key, desc);
59
+ } else {
60
+ newObj[key] = obj[key];
61
+ }
62
+ }
63
+ }
64
+ newObj.default = obj;
65
+ if (cache) {
66
+ cache.set(obj, newObj);
67
+ }
68
+ return newObj;
69
+ }
70
+ const ColorPicker = ({ color , onChange , palette })=>{
71
+ // value is the visible value for the controlled text input
72
+ const [value, setValue] = (0, _react.useState)(color);
73
+ const handleColorChange = (color)=>{
74
+ setValue(color);
75
+ onChange && onChange(color);
76
+ };
77
+ // we should update this if https://github.com/omgovich/react-colorful/issues/157 is resolved
78
+ const handleInputChange = (e)=>{
79
+ const inputValue = e.target.value.replace(/([^0-9A-F]+)/gi, '').substring(0, 8);
80
+ setValue(`#${inputValue}`); // always prefix input value with # to indicate hex format
81
+ // only set color if input value is a valid hex color
82
+ if (isValidHex(e.target.value)) {
83
+ onChange && onChange(e.target.value);
84
+ }
85
+ };
86
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
87
+ spacing: 1,
88
+ children: [
89
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactColorful.HexColorPicker, {
90
+ color: color,
91
+ onChange: handleColorChange
92
+ }),
93
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
94
+ direction: "row",
95
+ flexWrap: "wrap",
96
+ justifyContent: "space-evenly",
97
+ width: '200px',
98
+ children: palette && palette.map((color, i)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
99
+ size: "small",
100
+ "aria-label": `change color to ${color}`,
101
+ sx: {
102
+ color
103
+ },
104
+ onClick: ()=>handleColorChange(color),
105
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_circle.default, {})
106
+ }, i))
107
+ }),
108
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
109
+ inputProps: {
110
+ 'aria-label': 'enter hex color'
111
+ },
112
+ fullWidth: true,
113
+ value: value,
114
+ onChange: handleInputChange
115
+ })
116
+ ]
117
+ });
118
+ };
119
+ const isValidHex = (value, alpha)=>{
120
+ const matcher = /^#?([0-9A-F]{3,8})$/i;
121
+ const match = matcher.exec(value);
122
+ const length = match && match[1] ? match[1].length : 0;
123
+ return length === 3 || // '#rgb' format
124
+ length === 6 || // '#rrggbb' format
125
+ !!alpha && length === 4 || // '#rgba' format
126
+ !!alpha && length === 8 // '#rrggbbaa' format
127
+ ;
128
+ };
@@ -14,16 +14,15 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- const _legend = require("./legend");
18
- describe('validateLegendSpec', ()=>{
19
- it('should check if a legend spec is valid', ()=>{
20
- const invalidLegend = {
21
- position: 'bottom'
22
- };
23
- expect((0, _legend.validateLegendSpec)(invalidLegend)).toEqual(false);
24
- expect((0, _legend.validateLegendSpec)({
25
- position: 'Bottom'
26
- })).toEqual(true);
27
- expect((0, _legend.validateLegendSpec)(undefined)).toEqual(true);
17
+ _exportStar(require("./ColorPicker"), 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
+ });
28
26
  });
29
- });
27
+ return from;
28
+ }
@@ -39,19 +39,16 @@ function Legend({ width , height , options , data }) {
39
39
  })
40
40
  });
41
41
  }
42
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
42
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
43
43
  sx: {
44
44
  width: width,
45
45
  height: height,
46
46
  position: 'absolute',
47
47
  bottom: 0
48
48
  },
49
- children: [
50
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
51
- items: data,
52
- height: height
53
- }),
54
- ";"
55
- ]
49
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_compactLegend.CompactLegend, {
50
+ items: data,
51
+ height: height
52
+ })
56
53
  });
57
54
  }
@@ -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
+ }