@perses-dev/components 0.23.0 → 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,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
+ };
@@ -10,18 +10,19 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { validateLegendSpec } from './legend';
14
- describe('validateLegendSpec', ()=>{
15
- it('should check if a legend spec is valid', ()=>{
16
- const invalidLegend = {
17
- position: 'bottom'
18
- };
19
- expect(validateLegendSpec(invalidLegend)).toEqual(false);
20
- expect(validateLegendSpec({
21
- position: 'Bottom'
22
- })).toEqual(true);
23
- expect(validateLegendSpec(undefined)).toEqual(true);
24
- });
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
25
16
  });
26
-
27
- //# sourceMappingURL=legend.test.js.map
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
  };
@@ -61,6 +61,11 @@ const components = {
61
61
  paper: getModalBackgroundStyle
62
62
  }
63
63
  },
64
+ MuiPopover: {
65
+ styleOverrides: {
66
+ paper: getModalBackgroundStyle
67
+ }
68
+ },
64
69
  MuiAlert: {
65
70
  styleOverrides: {
66
71
  standardError: ({ theme })=>({
@@ -188,6 +188,14 @@ function generateChartsTheme(muiTheme, echartsTheme) {
188
188
  padding: {
189
189
  default: parseInt(muiTheme.spacing(1.5), 10)
190
190
  }
191
+ },
192
+ thresholds: {
193
+ defaultColor: muiTheme.palette.success.main,
194
+ palette: [
195
+ '#FFCC00',
196
+ muiTheme.palette.warning.main,
197
+ muiTheme.palette.error.main
198
+ ]
191
199
  }
192
200
  };
193
201
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './ColorPicker';
1
2
  export * from './DateTimeRangePicker';
2
3
  export * from './Dialog';
3
4
  export * from './Drawer';
@@ -12,6 +13,7 @@ export * from './LegendOptionsEditor';
12
13
  export * from './LineChart';
13
14
  export * from './OptionsEditorLayout';
14
15
  export * from './StatChart';
16
+ export * from './ThresholdsEditor';
15
17
  export * from './TimeSeriesTooltip';
16
18
  export * from './UnitSelector';
17
19
  export * from './YAxisLabel';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
+ export * from './ColorPicker';
13
14
  export * from './DateTimeRangePicker';
14
15
  export * from './Dialog';
15
16
  export * from './Drawer';
@@ -24,6 +25,7 @@ export * from './LegendOptionsEditor';
24
25
  export * from './LineChart';
25
26
  export * from './OptionsEditorLayout';
26
27
  export * from './StatChart';
28
+ export * from './ThresholdsEditor';
27
29
  export * from './TimeSeriesTooltip';
28
30
  export * from './UnitSelector';
29
31
  export * from './YAxisLabel';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"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\nexport * from './DateTimeRangePicker';\nexport * from './Dialog';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LegendOptionsEditor';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './TimeSeriesTooltip';\nexport * from './UnitSelector';\nexport * from './YAxisLabel';\nexport * from './context/ChartsThemeProvider';\nexport * from './context/TimeZoneProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\nexport * from './theme';\n"],"names":[],"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,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"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\nexport * from './ColorPicker';\nexport * from './DateTimeRangePicker';\nexport * from './Dialog';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LegendOptionsEditor';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './ThresholdsEditor';\nexport * from './TimeSeriesTooltip';\nexport * from './UnitSelector';\nexport * from './YAxisLabel';\nexport * from './context/ChartsThemeProvider';\nexport * from './context/TimeZoneProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\nexport * from './theme';\n"],"names":[],"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,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
@@ -1,11 +1,11 @@
1
+ import { TimeSeriesValueTuple } from '@perses-dev/core';
1
2
  import { LineSeriesOption } from 'echarts/charts';
2
3
  import { LegendItem } from './legend';
3
4
  export declare const OPTIMIZED_MODE_SERIES_LIMIT = 1000;
4
5
  export declare type UnixTimeMs = number;
5
- export declare type GraphSeriesValueTuple = [timestamp: UnixTimeMs, value: number];
6
6
  export interface GraphSeries {
7
7
  name: string;
8
- values: Iterable<GraphSeriesValueTuple>;
8
+ values: TimeSeriesValueTuple[];
9
9
  }
10
10
  export declare type EChartsValues = number | null | '-';
11
11
  export interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/model/graph.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,oBAAY,qBAAqB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;CACzC;AAED,oBAAY,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAEvE,IAAI,EAAE,aAAa,EAAE,CAAC;CACvB;AAED,oBAAY,iBAAiB,GAAG;IAC9B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/model/graph.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGtC,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;CAChC;AAED,oBAAY,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAEvE,IAAI,EAAE,aAAa,EAAE,CAAC;CACvB;AAED,oBAAY,iBAAiB,GAAG;IAC9B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/graph.ts"],"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 { LineSeriesOption } from 'echarts/charts';\nimport { LegendItem } from './legend';\n\n// adjust display when there are many time series to help with performance\nexport const OPTIMIZED_MODE_SERIES_LIMIT = 1000;\n\nexport type UnixTimeMs = number;\n\nexport type GraphSeriesValueTuple = [timestamp: UnixTimeMs, value: number];\n\nexport interface GraphSeries {\n name: string;\n values: Iterable<GraphSeriesValueTuple>;\n}\n\nexport type EChartsValues = number | null | '-';\n\nexport interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {\n // TODO: support dataset and both category / time xAxis types\n data: EChartsValues[];\n}\n\nexport type EChartsDataFormat = {\n timeSeries: EChartsTimeSeries[];\n xAxis: number[];\n legendItems?: LegendItem[];\n xAxisMax?: number | string;\n rangeMs?: number;\n};\n"],"names":["OPTIMIZED_MODE_SERIES_LIMIT"],"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;AAKjC,0EAA0E;AAC1E,OAAO,MAAMA,2BAA2B,GAAG,IAAI,CAAC"}
1
+ {"version":3,"sources":["../../src/model/graph.ts"],"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 { TimeSeriesValueTuple } from '@perses-dev/core';\nimport { LineSeriesOption } from 'echarts/charts';\nimport { LegendItem } from './legend';\n\n// adjust display when there are many time series to help with performance\nexport const OPTIMIZED_MODE_SERIES_LIMIT = 1000;\n\nexport type UnixTimeMs = number;\n\nexport interface GraphSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n}\n\nexport type EChartsValues = number | null | '-';\n\nexport interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {\n // TODO: support dataset and both category / time xAxis types\n data: EChartsValues[];\n}\n\nexport type EChartsDataFormat = {\n timeSeries: EChartsTimeSeries[];\n xAxis: number[];\n legendItems?: LegendItem[];\n xAxisMax?: number | string;\n rangeMs?: number;\n};\n"],"names":["OPTIMIZED_MODE_SERIES_LIMIT"],"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;AAMjC,0EAA0E;AAC1E,OAAO,MAAMA,2BAA2B,GAAG,IAAI,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { MouseEventHandler } from 'react';
2
2
  export declare const legendPositions: readonly ["Bottom", "Right"];
3
- export declare type LegendPositions = typeof legendPositions[number];
3
+ export declare type LegendPositions = (typeof legendPositions)[number];
4
4
  export interface LegendOptions {
5
5
  position: LegendPositions;
6
6
  }
@@ -1 +1 @@
1
- {"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,eAAO,MAAM,eAAe,8BAA+B,CAAC;AAE5D,oBAAY,eAAe,GAAG,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AAE7D,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CAC3C;AAED,oBAAY,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,oBAAoB,CAAC,CAG3F,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,aAE5B,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,eAAe,sBAQ3D;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,WAE9D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,aAAa,WASxD"}
1
+ {"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,eAAO,MAAM,eAAe,8BAA+B,CAAC;AAE5D,oBAAY,eAAe,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CAC3C;AAED,oBAAY,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,oBAAoB,CAAC,CAG3F,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,aAE5B,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,eAAe,sBAQ3D;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,eAAe,WAE9D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,aAAa,WASxD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/legend.ts"],"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 { MouseEventHandler } from 'react';\n\nexport const legendPositions = ['Bottom', 'Right'] as const;\n\nexport type LegendPositions = typeof legendPositions[number];\n\nexport interface LegendOptions {\n position: LegendPositions;\n}\n\nexport interface LegendItem {\n id: string;\n label: string;\n isSelected: boolean;\n color: string;\n onClick: MouseEventHandler<HTMLLIElement>;\n}\n\nexport type LegendPositionConfig = {\n label: string;\n};\n\nexport const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendPositionConfig>> = {\n Bottom: { label: 'Bottom' },\n Right: { label: 'Right' },\n};\n\nexport const DEFAULT_LEGEND: LegendOptions = {\n position: 'Bottom',\n};\n\nexport function getLegendPosition(position?: LegendPositions) {\n if (position === undefined) {\n return DEFAULT_LEGEND.position;\n }\n if (isValidLegendPosition(position)) {\n return position;\n }\n return DEFAULT_LEGEND.position;\n}\n\nexport function isValidLegendPosition(position: LegendPositions) {\n return (legendPositions as readonly string[]).includes(position);\n}\n\nexport function validateLegendSpec(legend?: LegendOptions) {\n if (legend === undefined) {\n // undefined is valid since this is how legend is hidden by default\n return true;\n }\n if (!isValidLegendPosition(legend.position)) {\n return false;\n }\n return true;\n}\n"],"names":["legendPositions","LEGEND_POSITIONS_CONFIG","Bottom","label","Right","DEFAULT_LEGEND","position","getLegendPosition","undefined","isValidLegendPosition","includes","validateLegendSpec","legend"],"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;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAAC,QAAQ;IAAE,OAAO;CAAC,AAAS,CAAC;AAoB5D,OAAO,MAAMC,uBAAuB,GAA4D;IAC9FC,MAAM,EAAE;QAAEC,KAAK,EAAE,QAAQ;KAAE;IAC3BC,KAAK,EAAE;QAAED,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAME,cAAc,GAAkB;IAC3CC,QAAQ,EAAE,QAAQ;CACnB,CAAC;AAEF,OAAO,SAASC,iBAAiB,CAACD,QAA0B,EAAE;IAC5D,IAAIA,QAAQ,KAAKE,SAAS,EAAE;QAC1B,OAAOH,cAAc,CAACC,QAAQ,CAAC;IACjC,CAAC;IACD,IAAIG,qBAAqB,CAACH,QAAQ,CAAC,EAAE;QACnC,OAAOA,QAAQ,CAAC;IAClB,CAAC;IACD,OAAOD,cAAc,CAACC,QAAQ,CAAC;AACjC,CAAC;AAED,OAAO,SAASG,qBAAqB,CAACH,QAAyB,EAAE;IAC/D,OAAO,AAACN,eAAe,CAAuBU,QAAQ,CAACJ,QAAQ,CAAC,CAAC;AACnE,CAAC;AAED,OAAO,SAASK,kBAAkB,CAACC,MAAsB,EAAE;IACzD,IAAIA,MAAM,KAAKJ,SAAS,EAAE;QACxB,mEAAmE;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAACC,qBAAqB,CAACG,MAAM,CAACN,QAAQ,CAAC,EAAE;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"sources":["../../src/model/legend.ts"],"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 { MouseEventHandler } from 'react';\n\nexport const legendPositions = ['Bottom', 'Right'] as const;\n\nexport type LegendPositions = (typeof legendPositions)[number];\n\nexport interface LegendOptions {\n position: LegendPositions;\n}\n\nexport interface LegendItem {\n id: string;\n label: string;\n isSelected: boolean;\n color: string;\n onClick: MouseEventHandler<HTMLLIElement>;\n}\n\nexport type LegendPositionConfig = {\n label: string;\n};\n\nexport const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendPositionConfig>> = {\n Bottom: { label: 'Bottom' },\n Right: { label: 'Right' },\n};\n\nexport const DEFAULT_LEGEND: LegendOptions = {\n position: 'Bottom',\n};\n\nexport function getLegendPosition(position?: LegendPositions) {\n if (position === undefined) {\n return DEFAULT_LEGEND.position;\n }\n if (isValidLegendPosition(position)) {\n return position;\n }\n return DEFAULT_LEGEND.position;\n}\n\nexport function isValidLegendPosition(position: LegendPositions) {\n return (legendPositions as readonly string[]).includes(position);\n}\n\nexport function validateLegendSpec(legend?: LegendOptions) {\n if (legend === undefined) {\n // undefined is valid since this is how legend is hidden by default\n return true;\n }\n if (!isValidLegendPosition(legend.position)) {\n return false;\n }\n return true;\n}\n"],"names":["legendPositions","LEGEND_POSITIONS_CONFIG","Bottom","label","Right","DEFAULT_LEGEND","position","getLegendPosition","undefined","isValidLegendPosition","includes","validateLegendSpec","legend"],"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;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAAC,QAAQ;IAAE,OAAO;CAAC,AAAS,CAAC;AAoB5D,OAAO,MAAMC,uBAAuB,GAA4D;IAC9FC,MAAM,EAAE;QAAEC,KAAK,EAAE,QAAQ;KAAE;IAC3BC,KAAK,EAAE;QAAED,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAME,cAAc,GAAkB;IAC3CC,QAAQ,EAAE,QAAQ;CACnB,CAAC;AAEF,OAAO,SAASC,iBAAiB,CAACD,QAA0B,EAAE;IAC5D,IAAIA,QAAQ,KAAKE,SAAS,EAAE;QAC1B,OAAOH,cAAc,CAACC,QAAQ,CAAC;IACjC,CAAC;IACD,IAAIG,qBAAqB,CAACH,QAAQ,CAAC,EAAE;QACnC,OAAOA,QAAQ,CAAC;IAClB,CAAC;IACD,OAAOD,cAAc,CAACC,QAAQ,CAAC;AACjC,CAAC;AAED,OAAO,SAASG,qBAAqB,CAACH,QAAyB,EAAE;IAC/D,OAAO,AAACN,eAAe,CAAuBU,QAAQ,CAACJ,QAAQ,CAAC,CAAC;AACnE,CAAC;AAED,OAAO,SAASK,kBAAkB,CAACC,MAAsB,EAAE;IACzD,IAAIA,MAAM,KAAKJ,SAAS,EAAE;QACxB,mEAAmE;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAACC,qBAAqB,CAACG,MAAM,CAACN,QAAQ,CAAC,EAAE;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -17,10 +17,15 @@ export interface PersesChartsTheme {
17
17
  default: number;
18
18
  };
19
19
  };
20
+ thresholds: ThresholdColorPalette;
20
21
  }
21
22
  export interface EChartsTheme extends EChartsOption {
22
23
  bar?: BarSeriesOption;
23
24
  line?: LineSeriesOption;
24
25
  gauge?: GaugeSeriesOption;
25
26
  }
27
+ export interface ThresholdColorPalette {
28
+ defaultColor: string;
29
+ palette: string[];
30
+ }
26
31
  //# sourceMappingURL=theme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/model/theme.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEtH,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,iBAAiB,CAAC;IAChC,SAAS,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF;;OAEG;IACH,SAAS,EAAE;QACT;;WAEG;QACH,OAAO,EAAE;YACP,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;CACH;AAGD,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B"}
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/model/theme.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEtH,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,iBAAiB,CAAC;IAChC,SAAS,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF;;OAEG;IACH,SAAS,EAAE;QACT;;WAEG;QACH,OAAO,EAAE;YACP,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;IACF,UAAU,EAAE,qBAAqB,CAAC;CACnC;AAGD,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/theme.ts"],"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 type { EChartsOption, EChartsCoreOption, BarSeriesOption, LineSeriesOption, GaugeSeriesOption } from 'echarts';\n\nexport interface PersesChartsTheme {\n echartsTheme: EChartsTheme;\n noDataOption: EChartsCoreOption;\n sparkline: {\n width: number;\n color: string;\n };\n /**\n * Theming for the container that wraps a chart.\n */\n container: {\n /**\n * Padding in pixels.\n */\n padding: {\n default: number;\n };\n };\n}\n\n// https://github.com/apache/echarts/issues/12489#issuecomment-643185207\nexport interface EChartsTheme extends EChartsOption {\n bar?: BarSeriesOption;\n line?: LineSeriesOption;\n gauge?: GaugeSeriesOption;\n}\n"],"names":[],"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,WA2BC"}
1
+ {"version":3,"sources":["../../src/model/theme.ts"],"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 type { EChartsOption, EChartsCoreOption, BarSeriesOption, LineSeriesOption, GaugeSeriesOption } from 'echarts';\n\nexport interface PersesChartsTheme {\n echartsTheme: EChartsTheme;\n noDataOption: EChartsCoreOption;\n sparkline: {\n width: number;\n color: string;\n };\n /**\n * Theming for the container that wraps a chart.\n */\n container: {\n /**\n * Padding in pixels.\n */\n padding: {\n default: number;\n };\n };\n thresholds: ThresholdColorPalette;\n}\n\n// https://github.com/apache/echarts/issues/12489#issuecomment-643185207\nexport interface EChartsTheme extends EChartsOption {\n bar?: BarSeriesOption;\n line?: LineSeriesOption;\n gauge?: GaugeSeriesOption;\n}\n\nexport interface ThresholdColorPalette {\n defaultColor: string;\n palette: string[];\n}\n"],"names":[],"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,WAiCC"}
@@ -1,6 +1,6 @@
1
1
  import { UnitGroupConfig, UnitConfig } from './types';
2
2
  declare const bytesUnitKinds: readonly ["Bytes"];
3
- declare type BytesUnitKind = typeof bytesUnitKinds[number];
3
+ declare type BytesUnitKind = (typeof bytesUnitKinds)[number];
4
4
  export declare type BytesUnitOptions = {
5
5
  kind: BytesUnitKind;
6
6
  decimal_places?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,UAmCvE"}
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,UAmCvE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/bytes.ts"],"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 { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = typeof bytesUnitKinds[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\n/**\n * Format value as bytes, use abbreviate option for more readable sizes (KB, MB, GB, etc.)\n * https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828\n */\nexport function formatBytes(bytes: number, unitOptions: BytesUnitOptions) {\n if (bytes === 0) return '0 bytes';\n\n // default to full 'Bytes' formatting\n const options = unitOptions.abbreviate === undefined ? { ...unitOptions, abbreviate: false } : unitOptions;\n\n let decimals = options.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n // avoids minimumFractionDigits value is out of range error, possible values are 0 to 20\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits\n if (decimals < 0) {\n decimals = 0;\n } else if (decimals > 20) {\n decimals = 20;\n }\n\n const formatParams: Intl.NumberFormatOptions = {\n style: 'decimal',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n };\n const formatter = new Intl.NumberFormat('en-US', formatParams);\n\n if (options.abbreviate === false) {\n return `${formatter.format(bytes)} bytes`;\n }\n\n const k = 1024;\n const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n // Math.max(0, ...) ensures that we don't return -1 as a value for the index.\n // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.\n const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));\n const abbreviatedValue = bytes / Math.pow(k, i);\n return `${formatter.format(abbreviatedValue)} ${sizes[i]}`;\n}\n"],"names":["DEFAULT_DECIMAL_PLACES","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","unitOptions","options","undefined","decimals","formatParams","style","minimumFractionDigits","maximumFractionDigits","useGrouping","formatter","Intl","NumberFormat","format","k","sizes","i","Math","max","floor","log","abbreviatedValue","pow"],"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,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAGrD,MAAMC,cAAc,GAAG;IAAC,OAAO;CAAC,AAAS,AAAC;AAO1C,OAAO,MAAMC,kBAAkB,GAAoB;IACjDC,KAAK,EAAE,OAAO;IACdC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,iBAAiB,GAAgD;IAC5EC,KAAK,EAAE;QACLC,KAAK,EAAE,OAAO;QACdL,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF;;;CAGC,GACD,OAAO,SAASM,WAAW,CAACC,KAAa,EAAEC,WAA6B,EAAE;IACxE,IAAID,KAAK,KAAK,CAAC,EAAE,OAAO,SAAS,CAAC;IAElC,qCAAqC;IACrC,MAAME,OAAO,GAAGD,WAAW,CAACN,UAAU,KAAKQ,SAAS,GAAG;QAAE,GAAGF,WAAW;QAAEN,UAAU,EAAE,KAAK;KAAE,GAAGM,WAAW,AAAC;QAE5FC,eAAsB;IAArC,IAAIE,QAAQ,GAAGF,CAAAA,eAAsB,GAAtBA,OAAO,CAACR,cAAc,cAAtBQ,eAAsB,cAAtBA,eAAsB,GAAIZ,sBAAsB,AAAC;IAChE,wFAAwF;IACxF,wIAAwI;IACxI,IAAIc,QAAQ,GAAG,CAAC,EAAE;QAChBA,QAAQ,GAAG,CAAC,CAAC;IACf,OAAO,IAAIA,QAAQ,GAAG,EAAE,EAAE;QACxBA,QAAQ,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,MAAMC,YAAY,GAA6B;QAC7CC,KAAK,EAAE,SAAS;QAChBC,qBAAqB,EAAEH,QAAQ;QAC/BI,qBAAqB,EAAEJ,QAAQ;QAC/BK,WAAW,EAAE,IAAI;KAClB,AAAC;IACF,MAAMC,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,YAAY,CAAC,AAAC;IAE/D,IAAIH,OAAO,CAACP,UAAU,KAAK,KAAK,EAAE;QAChC,OAAO,CAAC,EAAEe,SAAS,CAACG,MAAM,CAACb,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,MAAMc,CAAC,GAAG,IAAI,AAAC;IACf,MAAMC,KAAK,GAAG;QAAC,OAAO;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;KAAC,AAAC;IAExE,6EAA6E;IAC7E,6GAA6G;IAC7G,MAAMC,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAACF,IAAI,CAACG,GAAG,CAACpB,KAAK,CAAC,GAAGiB,IAAI,CAACG,GAAG,CAACN,CAAC,CAAC,CAAC,CAAC,AAAC;IACjE,MAAMO,gBAAgB,GAAGrB,KAAK,GAAGiB,IAAI,CAACK,GAAG,CAACR,CAAC,EAAEE,CAAC,CAAC,AAAC;IAChD,OAAO,CAAC,EAAEN,SAAS,CAACG,MAAM,CAACQ,gBAAgB,CAAC,CAAC,CAAC,EAAEN,KAAK,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/bytes.ts"],"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 { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = (typeof bytesUnitKinds)[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\n/**\n * Format value as bytes, use abbreviate option for more readable sizes (KB, MB, GB, etc.)\n * https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828\n */\nexport function formatBytes(bytes: number, unitOptions: BytesUnitOptions) {\n if (bytes === 0) return '0 bytes';\n\n // default to full 'Bytes' formatting\n const options = unitOptions.abbreviate === undefined ? { ...unitOptions, abbreviate: false } : unitOptions;\n\n let decimals = options.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n // avoids minimumFractionDigits value is out of range error, possible values are 0 to 20\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits\n if (decimals < 0) {\n decimals = 0;\n } else if (decimals > 20) {\n decimals = 20;\n }\n\n const formatParams: Intl.NumberFormatOptions = {\n style: 'decimal',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n };\n const formatter = new Intl.NumberFormat('en-US', formatParams);\n\n if (options.abbreviate === false) {\n return `${formatter.format(bytes)} bytes`;\n }\n\n const k = 1024;\n const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n // Math.max(0, ...) ensures that we don't return -1 as a value for the index.\n // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.\n const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));\n const abbreviatedValue = bytes / Math.pow(k, i);\n return `${formatter.format(abbreviatedValue)} ${sizes[i]}`;\n}\n"],"names":["DEFAULT_DECIMAL_PLACES","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","unitOptions","options","undefined","decimals","formatParams","style","minimumFractionDigits","maximumFractionDigits","useGrouping","formatter","Intl","NumberFormat","format","k","sizes","i","Math","max","floor","log","abbreviatedValue","pow"],"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,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAGrD,MAAMC,cAAc,GAAG;IAAC,OAAO;CAAC,AAAS,AAAC;AAO1C,OAAO,MAAMC,kBAAkB,GAAoB;IACjDC,KAAK,EAAE,OAAO;IACdC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,iBAAiB,GAAgD;IAC5EC,KAAK,EAAE;QACLC,KAAK,EAAE,OAAO;QACdL,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF;;;CAGC,GACD,OAAO,SAASM,WAAW,CAACC,KAAa,EAAEC,WAA6B,EAAE;IACxE,IAAID,KAAK,KAAK,CAAC,EAAE,OAAO,SAAS,CAAC;IAElC,qCAAqC;IACrC,MAAME,OAAO,GAAGD,WAAW,CAACN,UAAU,KAAKQ,SAAS,GAAG;QAAE,GAAGF,WAAW;QAAEN,UAAU,EAAE,KAAK;KAAE,GAAGM,WAAW,AAAC;QAE5FC,eAAsB;IAArC,IAAIE,QAAQ,GAAGF,CAAAA,eAAsB,GAAtBA,OAAO,CAACR,cAAc,cAAtBQ,eAAsB,cAAtBA,eAAsB,GAAIZ,sBAAsB,AAAC;IAChE,wFAAwF;IACxF,wIAAwI;IACxI,IAAIc,QAAQ,GAAG,CAAC,EAAE;QAChBA,QAAQ,GAAG,CAAC,CAAC;IACf,OAAO,IAAIA,QAAQ,GAAG,EAAE,EAAE;QACxBA,QAAQ,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,MAAMC,YAAY,GAA6B;QAC7CC,KAAK,EAAE,SAAS;QAChBC,qBAAqB,EAAEH,QAAQ;QAC/BI,qBAAqB,EAAEJ,QAAQ;QAC/BK,WAAW,EAAE,IAAI;KAClB,AAAC;IACF,MAAMC,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,YAAY,CAAC,AAAC;IAE/D,IAAIH,OAAO,CAACP,UAAU,KAAK,KAAK,EAAE;QAChC,OAAO,CAAC,EAAEe,SAAS,CAACG,MAAM,CAACb,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,MAAMc,CAAC,GAAG,IAAI,AAAC;IACf,MAAMC,KAAK,GAAG;QAAC,OAAO;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;KAAC,AAAC;IAExE,6EAA6E;IAC7E,6GAA6G;IAC7G,MAAMC,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAACF,IAAI,CAACG,GAAG,CAACpB,KAAK,CAAC,GAAGiB,IAAI,CAACG,GAAG,CAACN,CAAC,CAAC,CAAC,CAAC,AAAC;IACjE,MAAMO,gBAAgB,GAAGrB,KAAK,GAAGiB,IAAI,CAACK,GAAG,CAACR,CAAC,EAAEE,CAAC,CAAC,AAAC;IAChD,OAAO,CAAC,EAAEN,SAAS,CAACG,MAAM,CAACQ,gBAAgB,CAAC,CAAC,CAAC,EAAEN,KAAK,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { UnitGroupConfig, UnitConfig } from './types';
2
2
  declare const decimalUnitKinds: readonly ["Decimal"];
3
- declare type DecimalUnitKind = typeof decimalUnitKinds[number];
3
+ declare type DecimalUnitKind = (typeof decimalUnitKinds)[number];
4
4
  export declare type DecimalUnitOptions = {
5
5
  kind: DecimalUnitKind;
6
6
  decimal_places?: number;
@@ -1 +1 @@
1
- {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACvD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAmBpF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAI,UAG9D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAYlF"}
1
+ {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAmBpF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAI,UAG9D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAYlF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/decimal.ts"],"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 { round } from '../../utils/mathjs';\nimport { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst decimalUnitKinds = ['Decimal'] as const;\ntype DecimalUnitKind = typeof decimalUnitKinds[number];\nexport type DecimalUnitOptions = {\n kind: DecimalUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>> = {\n Decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, unitOptions: DecimalUnitOptions): string {\n const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n if (value === 0) {\n return value.toString();\n }\n\n if (unitOptions.abbreviate && value >= 1000) {\n return abbreviateLargeNumber(value, decimals);\n }\n\n const formatParams: Intl.NumberFormatOptions = {\n style: 'decimal',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n };\n const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);\n return decimalFormatter.format(value);\n}\n\n/**\n * Takes large numbers and abbreviates them with the appropriate suffix\n * 10123 -> 10.123k\n * 1000000 -> 1M\n */\nexport function abbreviateLargeNumber(num: number, decimals = 2) {\n const modifier = (n: number) => round(n, decimals);\n return formatNumber(num, modifier);\n}\n\n/**\n * Takes large numbers, rounds and abbreviates them with the appropriate suffix\n * Add modifier to run on output value prior to unit being added (defaults to rounding)\n */\nexport function formatNumber(num: number, modifier?: (n: number) => number): string {\n const fn = modifier ?? Math.round;\n\n return num >= 1e12\n ? fn(num / 1e12) + 'T'\n : num >= 1e9\n ? fn(num / 1e9) + 'B'\n : num >= 1e6\n ? fn(num / 1e6) + 'M'\n : num >= 1e3\n ? fn(num / 1e3) + 'K'\n : num.toString();\n}\n"],"names":["round","DEFAULT_DECIMAL_PLACES","decimalUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","unitOptions","decimals","toString","abbreviate","abbreviateLargeNumber","formatParams","style","minimumFractionDigits","maximumFractionDigits","useGrouping","decimalFormatter","Intl","NumberFormat","format","num","modifier","n","formatNumber","fn","Math"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,KAAK,QAAQ,oBAAoB,CAAC;AAC3C,SAASC,sBAAsB,QAAQ,aAAa,CAAC;AAGrD,MAAMC,gBAAgB,GAAG;IAAC,SAAS;CAAC,AAAS,AAAC;AAO9C,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;CACrB,CAAC;AACF,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAE,SAAS;QAChBJ,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,OAAO,SAASK,aAAa,CAACC,KAAa,EAAEC,WAA+B,EAAU;QACnEA,eAA0B;IAA3C,MAAMC,QAAQ,GAAGD,CAAAA,eAA0B,GAA1BA,WAAW,CAACN,cAAc,cAA1BM,eAA0B,cAA1BA,eAA0B,GAAIV,sBAAsB,AAAC;IAEtE,IAAIS,KAAK,KAAK,CAAC,EAAE;QACf,OAAOA,KAAK,CAACG,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAED,IAAIF,WAAW,CAACG,UAAU,IAAIJ,KAAK,IAAI,IAAI,EAAE;QAC3C,OAAOK,qBAAqB,CAACL,KAAK,EAAEE,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED,MAAMI,YAAY,GAA6B;QAC7CC,KAAK,EAAE,SAAS;QAChBC,qBAAqB,EAAEN,QAAQ;QAC/BO,qBAAqB,EAAEP,QAAQ;QAC/BQ,WAAW,EAAE,IAAI;KAClB,AAAC;IACF,MAAMC,gBAAgB,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,YAAY,CAAC,AAAC;IACtE,OAAOK,gBAAgB,CAACG,MAAM,CAACd,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;CAIC,GACD,OAAO,SAASK,qBAAqB,CAACU,GAAW,EAAEb,QAAQ,GAAG,CAAC,EAAE;IAC/D,MAAMc,QAAQ,GAAG,CAACC,CAAS,GAAK3B,KAAK,CAAC2B,CAAC,EAAEf,QAAQ,CAAC,AAAC;IACnD,OAAOgB,YAAY,CAACH,GAAG,EAAEC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;CAGC,GACD,OAAO,SAASE,YAAY,CAACH,GAAW,EAAEC,QAAgC,EAAU;IAClF,MAAMG,EAAE,GAAGH,QAAQ,aAARA,QAAQ,cAARA,QAAQ,GAAII,IAAI,CAAC9B,KAAK,AAAC;IAElC,OAAOyB,GAAG,IAAI,IAAI,GACdI,EAAE,CAACJ,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,GACpBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,CAACZ,QAAQ,EAAE,CAAC;AACrB,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/decimal.ts"],"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 { round } from '../../utils/mathjs';\nimport { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst decimalUnitKinds = ['Decimal'] as const;\ntype DecimalUnitKind = (typeof decimalUnitKinds)[number];\nexport type DecimalUnitOptions = {\n kind: DecimalUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>> = {\n Decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, unitOptions: DecimalUnitOptions): string {\n const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n if (value === 0) {\n return value.toString();\n }\n\n if (unitOptions.abbreviate && value >= 1000) {\n return abbreviateLargeNumber(value, decimals);\n }\n\n const formatParams: Intl.NumberFormatOptions = {\n style: 'decimal',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n };\n const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);\n return decimalFormatter.format(value);\n}\n\n/**\n * Takes large numbers and abbreviates them with the appropriate suffix\n * 10123 -> 10.123k\n * 1000000 -> 1M\n */\nexport function abbreviateLargeNumber(num: number, decimals = 2) {\n const modifier = (n: number) => round(n, decimals);\n return formatNumber(num, modifier);\n}\n\n/**\n * Takes large numbers, rounds and abbreviates them with the appropriate suffix\n * Add modifier to run on output value prior to unit being added (defaults to rounding)\n */\nexport function formatNumber(num: number, modifier?: (n: number) => number): string {\n const fn = modifier ?? Math.round;\n\n return num >= 1e12\n ? fn(num / 1e12) + 'T'\n : num >= 1e9\n ? fn(num / 1e9) + 'B'\n : num >= 1e6\n ? fn(num / 1e6) + 'M'\n : num >= 1e3\n ? fn(num / 1e3) + 'K'\n : num.toString();\n}\n"],"names":["round","DEFAULT_DECIMAL_PLACES","decimalUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","unitOptions","decimals","toString","abbreviate","abbreviateLargeNumber","formatParams","style","minimumFractionDigits","maximumFractionDigits","useGrouping","decimalFormatter","Intl","NumberFormat","format","num","modifier","n","formatNumber","fn","Math"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,KAAK,QAAQ,oBAAoB,CAAC;AAC3C,SAASC,sBAAsB,QAAQ,aAAa,CAAC;AAGrD,MAAMC,gBAAgB,GAAG;IAAC,SAAS;CAAC,AAAS,AAAC;AAO9C,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;CACrB,CAAC;AACF,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAE,SAAS;QAChBJ,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,OAAO,SAASK,aAAa,CAACC,KAAa,EAAEC,WAA+B,EAAU;QACnEA,eAA0B;IAA3C,MAAMC,QAAQ,GAAGD,CAAAA,eAA0B,GAA1BA,WAAW,CAACN,cAAc,cAA1BM,eAA0B,cAA1BA,eAA0B,GAAIV,sBAAsB,AAAC;IAEtE,IAAIS,KAAK,KAAK,CAAC,EAAE;QACf,OAAOA,KAAK,CAACG,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAED,IAAIF,WAAW,CAACG,UAAU,IAAIJ,KAAK,IAAI,IAAI,EAAE;QAC3C,OAAOK,qBAAqB,CAACL,KAAK,EAAEE,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED,MAAMI,YAAY,GAA6B;QAC7CC,KAAK,EAAE,SAAS;QAChBC,qBAAqB,EAAEN,QAAQ;QAC/BO,qBAAqB,EAAEP,QAAQ;QAC/BQ,WAAW,EAAE,IAAI;KAClB,AAAC;IACF,MAAMC,gBAAgB,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,YAAY,CAAC,AAAC;IACtE,OAAOK,gBAAgB,CAACG,MAAM,CAACd,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;CAIC,GACD,OAAO,SAASK,qBAAqB,CAACU,GAAW,EAAEb,QAAQ,GAAG,CAAC,EAAE;IAC/D,MAAMc,QAAQ,GAAG,CAACC,CAAS,GAAK3B,KAAK,CAAC2B,CAAC,EAAEf,QAAQ,CAAC,AAAC;IACnD,OAAOgB,YAAY,CAACH,GAAG,EAAEC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;CAGC,GACD,OAAO,SAASE,YAAY,CAACH,GAAW,EAAEC,QAAgC,EAAU;IAClF,MAAMG,EAAE,GAAGH,QAAQ,aAARA,QAAQ,cAARA,QAAQ,GAAII,IAAI,CAAC9B,KAAK,AAAC;IAElC,OAAOyB,GAAG,IAAI,IAAI,GACdI,EAAE,CAACJ,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,GACpBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,CAACZ,QAAQ,EAAE,CAAC;AACrB,CAAC"}