@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
@@ -1,96 +0,0 @@
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
- const _jsxRuntime = require("react/jsx-runtime");
18
- const _react = require("@testing-library/react");
19
- const _chartsThemeProvider = require("../context/ChartsThemeProvider");
20
- const _testUtils = require("../test-utils");
21
- const _statChart = require("./StatChart");
22
- describe('StatChart', ()=>{
23
- const renderChart = (unit)=>{
24
- const contentDimensions = {
25
- width: 200,
26
- height: 200
27
- };
28
- (0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_chartsThemeProvider.ChartsThemeProvider, {
29
- chartsTheme: _testUtils.testChartsTheme,
30
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_statChart.StatChart, {
31
- width: contentDimensions.width,
32
- height: contentDimensions.height,
33
- data: mockStatData,
34
- unit: unit
35
- })
36
- }));
37
- };
38
- const mockStatData = {
39
- calculatedValue: 7.72931659687181,
40
- name: 'Example Stat Chart',
41
- seriesData: {
42
- name: '(((count(count(node_cpu_seconds_total{job="example"}) by (cpu))',
43
- values: [
44
- [
45
- 1654006170000,
46
- 7.736401673473903
47
- ],
48
- [
49
- 1654006185000,
50
- 7.733891213538757
51
- ],
52
- [
53
- 1654006200000,
54
- 7.731101813010433
55
- ],
56
- [
57
- 1654006215000,
58
- 7.722454672079215
59
- ],
60
- [
61
- 1654006230000,
62
- 7.722733612256738
63
- ]
64
- ]
65
- }
66
- };
67
- it('render default options (no sparkline)', ()=>{
68
- const unit = {
69
- kind: 'Decimal',
70
- decimal_places: 2
71
- };
72
- renderChart(unit);
73
- expect(_react.screen.getByText('7.73')).toBeInTheDocument();
74
- });
75
- it('show value with bytes unit formatting', ()=>{
76
- const unit = {
77
- kind: 'Bytes'
78
- };
79
- renderChart(unit);
80
- expect(_react.screen.getByText('7.73 bytes')).toBeInTheDocument();
81
- });
82
- it('show value with seconds time unit formatting', ()=>{
83
- const unit = {
84
- kind: 'Seconds'
85
- };
86
- renderChart(unit);
87
- expect(_react.screen.getByText('7.73 seconds')).toBeInTheDocument();
88
- });
89
- it('show value with months time unit formatting', ()=>{
90
- const unit = {
91
- kind: 'Months'
92
- };
93
- renderChart(unit);
94
- expect(_react.screen.getByText('7.73 months')).toBeInTheDocument();
95
- });
96
- });
@@ -1,54 +0,0 @@
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
- const _jsxRuntime = require("react/jsx-runtime");
18
- const _react = require("@testing-library/react");
19
- const _dom = require("@testing-library/dom");
20
- const _seriesInfo = require("./SeriesInfo");
21
- describe('SeriesInfo', ()=>{
22
- const renderComponent = (props)=>{
23
- (0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_seriesInfo.SeriesInfo, {
24
- ...props
25
- }));
26
- };
27
- it('render metric __name__ beside formattedY value', ()=>{
28
- const seriesInfo = {
29
- seriesName: 'node_load1{env="demo",instance="demo.do.prometheus.io:9100",job="node"}',
30
- y: 0.28,
31
- formattedY: '28.0%',
32
- markerColor: 'hsla(1016196180,50%,50%,0.8)',
33
- totalSeries: 1,
34
- wrapLabels: true
35
- };
36
- renderComponent(seriesInfo);
37
- expect(_dom.screen.getByText('node_load1:')).toBeInTheDocument();
38
- expect(_dom.screen.getByText('28.0%')).toBeInTheDocument();
39
- expect(_dom.screen.getByText('demo.do.prometheus.io:9100')).toBeInTheDocument(); // TODO: remove quotes
40
- });
41
- it('render preformatted series name beside formattedY value', ()=>{
42
- const seriesInfo = {
43
- seriesName: 'Node memory total',
44
- y: 552341504,
45
- formattedY: '526.75 MB',
46
- markerColor: 'hsla(-1756459732,50%,50%,0.8)',
47
- totalSeries: 2,
48
- wrapLabels: true
49
- };
50
- renderComponent(seriesInfo);
51
- expect(_dom.screen.getByText('Node memory total')).toBeInTheDocument();
52
- expect(_dom.screen.getByText('526.75 MB')).toBeInTheDocument();
53
- });
54
- });
@@ -1,80 +0,0 @@
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
- const _jsxRuntime = require("react/jsx-runtime");
18
- const _react = require("@testing-library/react");
19
- const _dom = require("@testing-library/dom");
20
- const _tooltipContent = require("./TooltipContent");
21
- describe('TooltipContent', ()=>{
22
- const renderComponent = (props)=>{
23
- (0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipContent.TooltipContent, {
24
- ...props
25
- }));
26
- };
27
- it('render tooltip content with a single series name', ()=>{
28
- const tooltipContent = {
29
- focusedSeries: [
30
- {
31
- seriesIdx: 0,
32
- datumIdx: 84,
33
- seriesName: 'Test node demo.do.prometheus.io:9100',
34
- date: 'Dec 23, 2022, 1:53:00 PM',
35
- x: 1671821580000,
36
- y: 0.1,
37
- formattedY: '0.1',
38
- markerColor: 'hsla(19838016,50%,50%,0.8)'
39
- }
40
- ],
41
- wrapLabels: true
42
- };
43
- renderComponent(tooltipContent);
44
- expect(_dom.screen.getByText('Test node demo.do.prometheus.io:9100')).toBeInTheDocument();
45
- expect(_dom.screen.getByText('Dec 23, 2022 -')).toBeInTheDocument();
46
- expect(_dom.screen.getByText('13:53:00')).toBeInTheDocument();
47
- expect(_dom.screen.getByText('0.1')).toBeInTheDocument();
48
- });
49
- it('render tooltip content with multiple series data', ()=>{
50
- const tooltipContent = {
51
- focusedSeries: [
52
- {
53
- seriesIdx: 2,
54
- datumIdx: 48,
55
- seriesName: 'node_memory_MemFree_bytes{env="demo",instance="demo.do.prometheus.io:9100",job="node"}',
56
- date: 'Dec 23, 2022, 1:44:00 PM',
57
- x: 1671821040000,
58
- y: 84635648,
59
- formattedY: '84.64M',
60
- markerColor: 'hsla(1887856572,50%,50%,0.8)'
61
- },
62
- {
63
- seriesIdx: 1,
64
- datumIdx: 48,
65
- seriesName: 'node_memory_Buffers_bytes{env="demo",instance="demo.do.prometheus.io:9100",job="node"}',
66
- date: 'Dec 23, 2022, 1:44:00 PM',
67
- x: 1671821040000,
68
- y: 33771520,
69
- formattedY: '33.77M',
70
- markerColor: 'hsla(158479636,50%,50%,0.8)'
71
- }
72
- ],
73
- wrapLabels: true
74
- };
75
- renderComponent(tooltipContent);
76
- expect(_dom.screen.getByText('84.64M')).toBeInTheDocument();
77
- expect(_dom.screen.getByText('33.77M')).toBeInTheDocument();
78
- expect(_dom.screen.getAllByText('env="demo", instance="demo.do.prometheus.io:9100", job="node"')).toHaveLength(2);
79
- });
80
- });
@@ -1,95 +0,0 @@
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
- const _focusedSeries = require("./focused-series");
18
- describe('getNearbySeries', ()=>{
19
- const chartData = {
20
- timeSeries: [
21
- {
22
- type: 'line',
23
- name: 'env="demo", instance="demo.do.prometheus", job="node", mode="test"',
24
- color: 'hsla(-1365438424,50%,50%,0.8)',
25
- data: [
26
- 0.0002315202231525094,
27
- 0.00022873082287300112,
28
- 0.00023152022315149463,
29
- 0.00023152022315149463,
30
- 0.00022873082287300112
31
- ],
32
- symbol: 'circle'
33
- },
34
- {
35
- type: 'line',
36
- name: 'env="demo", instance="demo.do.prometheus", job="node", mode="test alt"',
37
- color: 'hsla(286664040,50%,50%,0.8)',
38
- data: [
39
- 0.05245188284519867,
40
- 0.0524463040446356,
41
- 0.0524463040446356,
42
- 0.05247140864723438,
43
- 0.052482566248230646
44
- ],
45
- symbol: 'circle'
46
- }
47
- ],
48
- xAxis: [
49
- 1654007865000,
50
- 1654007880000,
51
- 1654007895000,
52
- 1654007910000,
53
- 1654007925000
54
- ],
55
- rangeMs: 60000
56
- };
57
- // https://echarts.apache.org/en/api.html#echartsInstance.convertFromPixel
58
- const pointInGrid = [
59
- 2,
60
- 0.0560655737704918
61
- ]; // converted from chart.getZr() mousemove coordinates
62
- const yBuffer = 0.02; // calculated from y axis interval
63
- const focusedSeriesOutput = [
64
- {
65
- date: 'May 31, 2022, 2:38:15 PM',
66
- datumIdx: 2,
67
- markerColor: 'hsla(286664040,50%,50%,0.8)',
68
- seriesName: 'env="demo", instance="demo.do.prometheus", job="node", mode="test alt"',
69
- seriesIdx: 1,
70
- x: 1654007895000,
71
- y: 0.0524463040446356,
72
- formattedY: '0.05'
73
- }
74
- ];
75
- it('should return focused series data for points nearby the cursor', ()=>{
76
- const decimalUnit = {
77
- kind: 'Decimal',
78
- decimal_places: 2
79
- };
80
- expect((0, _focusedSeries.getNearbySeries)(chartData, pointInGrid, yBuffer, decimalUnit)).toEqual(focusedSeriesOutput);
81
- });
82
- it('should return series values formatted as a percent', ()=>{
83
- const percentFormattedOutput = [
84
- ...focusedSeriesOutput
85
- ];
86
- if (percentFormattedOutput[0]) {
87
- percentFormattedOutput[0].formattedY = '5%';
88
- }
89
- const percentFormattedUnit = {
90
- kind: 'PercentDecimal',
91
- decimal_places: 0
92
- };
93
- expect((0, _focusedSeries.getNearbySeries)(chartData, pointInGrid, yBuffer, percentFormattedUnit)).toEqual(percentFormattedOutput);
94
- });
95
- });
@@ -1,211 +0,0 @@
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
- const _jsxRuntime = require("react/jsx-runtime");
18
- const _react = require("@testing-library/react");
19
- const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
20
- const _unitSelector = require("./UnitSelector");
21
- function _interopRequireDefault(obj) {
22
- return obj && obj.__esModule ? obj : {
23
- default: obj
24
- };
25
- }
26
- describe('UnitSelector', ()=>{
27
- const renderUnitSelector = (value, onChange = jest.fn())=>{
28
- (0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
29
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_unitSelector.UnitSelector, {
30
- value: value,
31
- onChange: onChange
32
- })
33
- }));
34
- };
35
- const getUnitSelector = ()=>{
36
- return _react.screen.getByRole('combobox', {
37
- name: 'Units'
38
- });
39
- };
40
- const getDecimalSelector = ()=>{
41
- return _react.screen.getByRole('combobox', {
42
- name: 'Decimal'
43
- });
44
- };
45
- const getAbbreviateSwitch = ()=>{
46
- return _react.screen.getByRole('checkbox', {
47
- name: 'Abbreviate'
48
- });
49
- };
50
- it('can change the unit kind by clicking', ()=>{
51
- const onChange = jest.fn();
52
- renderUnitSelector({
53
- kind: 'Minutes'
54
- }, onChange);
55
- const unitSelector = getUnitSelector();
56
- _userEvent.default.click(unitSelector);
57
- const decimalOption = _react.screen.getByRole('option', {
58
- name: 'Decimal'
59
- });
60
- _userEvent.default.click(decimalOption);
61
- expect(onChange).toHaveBeenCalledWith({
62
- kind: 'Decimal'
63
- });
64
- });
65
- it('can change the unit kind using a keyboard', ()=>{
66
- const onChange = jest.fn();
67
- renderUnitSelector({
68
- kind: 'Bytes'
69
- }, onChange);
70
- const unitSelector = getUnitSelector();
71
- _userEvent.default.tab();
72
- _userEvent.default.tab();
73
- expect(unitSelector).toHaveFocus();
74
- _userEvent.default.clear(unitSelector);
75
- _userEvent.default.keyboard('years');
76
- _react.screen.getByRole('option', {
77
- name: 'Years'
78
- });
79
- _userEvent.default.keyboard('{arrowup}{enter}');
80
- expect(onChange).toHaveBeenCalledWith({
81
- kind: 'Years'
82
- });
83
- });
84
- it('can change the decimal places by clicking', ()=>{
85
- const onChange = jest.fn();
86
- renderUnitSelector({
87
- kind: 'Decimal',
88
- decimal_places: 0,
89
- abbreviate: true
90
- }, onChange);
91
- _userEvent.default.click(getDecimalSelector());
92
- const decimalOption = _react.screen.getByRole('option', {
93
- name: '1'
94
- });
95
- _userEvent.default.click(decimalOption);
96
- expect(onChange).toHaveBeenCalledWith({
97
- kind: 'Decimal',
98
- decimal_places: 1,
99
- abbreviate: true
100
- });
101
- });
102
- it('can change the decimal places using a keyboard', ()=>{
103
- const onChange = jest.fn();
104
- renderUnitSelector({
105
- kind: 'Percent'
106
- }, onChange);
107
- const decimalSelector = getDecimalSelector();
108
- _userEvent.default.tab();
109
- _userEvent.default.tab();
110
- expect(decimalSelector).toHaveFocus();
111
- _userEvent.default.clear(decimalSelector);
112
- _userEvent.default.keyboard('3');
113
- _react.screen.getByRole('option', {
114
- name: '3'
115
- });
116
- _userEvent.default.keyboard('{arrowup}{enter}');
117
- expect(onChange).toHaveBeenCalledWith({
118
- kind: 'Percent',
119
- decimal_places: 3
120
- });
121
- });
122
- it('can change abbreviate by clicking', ()=>{
123
- const onChange = jest.fn();
124
- renderUnitSelector({
125
- kind: 'Decimal',
126
- decimal_places: 3,
127
- abbreviate: true
128
- }, onChange);
129
- _userEvent.default.click(getAbbreviateSwitch());
130
- expect(onChange).toHaveBeenCalledWith({
131
- kind: 'Decimal',
132
- decimal_places: 3,
133
- abbreviate: false
134
- });
135
- });
136
- it('can change abbreviate using a keyboard', ()=>{
137
- const onChange = jest.fn();
138
- renderUnitSelector({
139
- kind: 'Decimal',
140
- decimal_places: 0
141
- }, onChange);
142
- _userEvent.default.tab();
143
- _userEvent.default.keyboard('{space}');
144
- expect(onChange).toHaveBeenCalledWith({
145
- kind: 'Decimal',
146
- decimal_places: 0,
147
- abbreviate: true
148
- });
149
- });
150
- describe('with a time unit selected', ()=>{
151
- it('does not allow the user to set abbreviate', ()=>{
152
- renderUnitSelector({
153
- kind: 'Minutes'
154
- });
155
- expect(getAbbreviateSwitch()).toBeDisabled();
156
- });
157
- });
158
- describe('with a percent unit selected', ()=>{
159
- it('allows the user to modify the decimal places', ()=>{
160
- renderUnitSelector({
161
- kind: 'Percent'
162
- });
163
- expect(getDecimalSelector()).toBeEnabled();
164
- });
165
- it('does not allow the user to set abbreviate', ()=>{
166
- renderUnitSelector({
167
- kind: 'PercentDecimal'
168
- });
169
- expect(getAbbreviateSwitch()).toBeDisabled();
170
- });
171
- });
172
- describe('with a decimal unit selected', ()=>{
173
- it('allows the user to modify the decimal places', ()=>{
174
- renderUnitSelector({
175
- kind: 'Decimal'
176
- });
177
- expect(getDecimalSelector()).toBeEnabled();
178
- });
179
- it('allows the user to set abbreviate', ()=>{
180
- renderUnitSelector({
181
- kind: 'Decimal'
182
- });
183
- expect(getAbbreviateSwitch()).toBeEnabled();
184
- });
185
- });
186
- describe('with a bytes unit selected', ()=>{
187
- it('allows the user to modify the decimal places', ()=>{
188
- renderUnitSelector({
189
- kind: 'Bytes'
190
- });
191
- expect(getDecimalSelector()).toBeEnabled();
192
- });
193
- it('allows the user to set abbreviate', ()=>{
194
- renderUnitSelector({
195
- kind: 'Bytes'
196
- });
197
- expect(getAbbreviateSwitch()).toBeEnabled();
198
- });
199
- });
200
- it('should not show an option for disabled units', ()=>{
201
- const onChange = jest.fn();
202
- renderUnitSelector({
203
- kind: 'Decimal'
204
- }, onChange);
205
- _userEvent.default.click(getUnitSelector());
206
- const percentShorthandOption = _react.screen.queryByRole('option', {
207
- name: '%'
208
- });
209
- expect(percentShorthandOption).not.toBeInTheDocument();
210
- });
211
- });