@perses-dev/core 0.0.0-snapshot-panel-extra-content-3-17f9c42 → 0.0.0-snapshot-scatterplot-fix-imports-95e1b59

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 (190) hide show
  1. package/dist/cjs/constants/dashboard-defaults.js +6 -2
  2. package/dist/cjs/constants/dialog.js +3 -1
  3. package/dist/cjs/constants/index.js +11 -9
  4. package/dist/cjs/index.js +12 -10
  5. package/dist/cjs/model/calculations.js +61 -51
  6. package/dist/cjs/model/ephemeraldashboard.js +16 -0
  7. package/dist/cjs/model/http-proxy.js +16 -0
  8. package/dist/cjs/model/index.js +35 -26
  9. package/dist/cjs/model/kind.js +39 -0
  10. package/dist/cjs/model/legend.js +39 -19
  11. package/dist/cjs/model/resource.js +9 -0
  12. package/dist/cjs/model/rolebindings.js +16 -0
  13. package/dist/cjs/model/roles.js +60 -0
  14. package/dist/cjs/model/secrets.js +16 -0
  15. package/dist/cjs/model/time-series-queries.js +3 -1
  16. package/dist/cjs/model/time.js +151 -65
  17. package/dist/cjs/model/trace-data.js +16 -0
  18. package/dist/cjs/model/units/bytes.js +37 -25
  19. package/dist/cjs/model/units/constants.js +3 -1
  20. package/dist/cjs/model/units/decimal.js +22 -16
  21. package/dist/cjs/model/units/index.js +13 -11
  22. package/dist/cjs/model/units/percent.js +26 -19
  23. package/dist/cjs/model/units/throughput.js +113 -0
  24. package/dist/cjs/model/units/time.js +99 -38
  25. package/dist/cjs/model/units/types.js +5 -2
  26. package/dist/cjs/model/units/units.js +81 -45
  27. package/dist/cjs/model/units/utils.js +13 -7
  28. package/dist/cjs/model/variables.js +16 -3
  29. package/dist/cjs/utils/event.js +3 -1
  30. package/dist/cjs/utils/fetch.js +32 -7
  31. package/dist/cjs/utils/index.js +17 -14
  32. package/dist/cjs/utils/is-empty-object.js +3 -1
  33. package/dist/cjs/utils/mathjs.js +4 -2
  34. package/dist/cjs/utils/memo.js +10 -6
  35. package/dist/cjs/utils/panel-refs.js +9 -3
  36. package/dist/cjs/utils/text.js +33 -21
  37. package/dist/cjs/utils/time-series-data.js +21 -11
  38. package/dist/cjs/utils/types.js +16 -0
  39. package/dist/constants/dashboard-defaults.js.map +1 -1
  40. package/dist/constants/dialog.js.map +1 -1
  41. package/dist/constants/index.js.map +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/model/calculations.d.ts +12 -12
  44. package/dist/model/calculations.d.ts.map +1 -1
  45. package/dist/model/calculations.js +46 -46
  46. package/dist/model/calculations.js.map +1 -1
  47. package/dist/model/dashboard.js.map +1 -1
  48. package/dist/model/datasource.d.ts +17 -3
  49. package/dist/model/datasource.d.ts.map +1 -1
  50. package/dist/model/datasource.js +3 -1
  51. package/dist/model/datasource.js.map +1 -1
  52. package/dist/model/definitions.d.ts +1 -1
  53. package/dist/model/definitions.d.ts.map +1 -1
  54. package/dist/model/definitions.js +3 -0
  55. package/dist/model/definitions.js.map +1 -1
  56. package/dist/model/display.d.ts +1 -1
  57. package/dist/model/display.d.ts.map +1 -1
  58. package/dist/model/display.js.map +1 -1
  59. package/dist/model/ephemeraldashboard.d.ts +15 -0
  60. package/dist/model/ephemeraldashboard.d.ts.map +1 -0
  61. package/dist/model/ephemeraldashboard.js +15 -0
  62. package/dist/model/ephemeraldashboard.js.map +1 -0
  63. package/dist/model/http-proxy.d.ts +16 -0
  64. package/dist/model/http-proxy.d.ts.map +1 -0
  65. package/dist/model/http-proxy.js +15 -0
  66. package/dist/model/http-proxy.js.map +1 -0
  67. package/dist/model/http.d.ts +1 -1
  68. package/dist/model/http.d.ts.map +1 -1
  69. package/dist/model/index.d.ts +7 -0
  70. package/dist/model/index.d.ts.map +1 -1
  71. package/dist/model/index.js +7 -0
  72. package/dist/model/index.js.map +1 -1
  73. package/dist/model/kind.d.ts +3 -0
  74. package/dist/model/kind.d.ts.map +1 -0
  75. package/dist/model/kind.js +31 -0
  76. package/dist/model/kind.js.map +1 -0
  77. package/dist/model/layout.d.ts +1 -1
  78. package/dist/model/layout.d.ts.map +1 -1
  79. package/dist/model/layout.js.map +1 -1
  80. package/dist/model/legend.d.ts +9 -9
  81. package/dist/model/legend.d.ts.map +1 -1
  82. package/dist/model/legend.js +9 -9
  83. package/dist/model/legend.js.map +1 -1
  84. package/dist/model/panels.d.ts +5 -2
  85. package/dist/model/panels.d.ts.map +1 -1
  86. package/dist/model/panels.js +3 -1
  87. package/dist/model/panels.js.map +1 -1
  88. package/dist/model/project.js.map +1 -1
  89. package/dist/model/query.d.ts +15 -2
  90. package/dist/model/query.d.ts.map +1 -1
  91. package/dist/model/query.js +4 -1
  92. package/dist/model/query.js.map +1 -1
  93. package/dist/model/resource.d.ts +3 -2
  94. package/dist/model/resource.d.ts.map +1 -1
  95. package/dist/model/resource.js +3 -1
  96. package/dist/model/resource.js.map +1 -1
  97. package/dist/model/rolebindings.d.ts +27 -0
  98. package/dist/model/rolebindings.d.ts.map +1 -0
  99. package/dist/model/rolebindings.js +15 -0
  100. package/dist/model/rolebindings.js.map +1 -0
  101. package/dist/model/roles.d.ts +32 -0
  102. package/dist/model/roles.d.ts.map +1 -0
  103. package/dist/model/roles.js +41 -0
  104. package/dist/model/roles.js.map +1 -0
  105. package/dist/model/secrets.d.ts +44 -0
  106. package/dist/model/secrets.d.ts.map +1 -0
  107. package/dist/model/secrets.js +15 -0
  108. package/dist/model/secrets.js.map +1 -0
  109. package/dist/model/thresholds.d.ts +2 -2
  110. package/dist/model/thresholds.d.ts.map +1 -1
  111. package/dist/model/thresholds.js.map +1 -1
  112. package/dist/model/time-series-data.js.map +1 -1
  113. package/dist/model/time-series-queries.d.ts +3 -3
  114. package/dist/model/time-series-queries.d.ts.map +1 -1
  115. package/dist/model/time-series-queries.js.map +1 -1
  116. package/dist/model/time.d.ts +15 -11
  117. package/dist/model/time.d.ts.map +1 -1
  118. package/dist/model/time.js +117 -57
  119. package/dist/model/time.js.map +1 -1
  120. package/dist/model/trace-data.d.ts +20 -0
  121. package/dist/model/trace-data.d.ts.map +1 -0
  122. package/dist/model/trace-data.js +18 -0
  123. package/dist/model/trace-data.js.map +1 -0
  124. package/dist/model/units/bytes.d.ts +8 -8
  125. package/dist/model/units/bytes.d.ts.map +1 -1
  126. package/dist/model/units/bytes.js +27 -21
  127. package/dist/model/units/bytes.js.map +1 -1
  128. package/dist/model/units/constants.js.map +1 -1
  129. package/dist/model/units/decimal.d.ts +8 -8
  130. package/dist/model/units/decimal.d.ts.map +1 -1
  131. package/dist/model/units/decimal.js +14 -14
  132. package/dist/model/units/decimal.js.map +1 -1
  133. package/dist/model/units/index.js.map +1 -1
  134. package/dist/model/units/percent.d.ts +7 -7
  135. package/dist/model/units/percent.d.ts.map +1 -1
  136. package/dist/model/units/percent.js +17 -16
  137. package/dist/model/units/percent.js.map +1 -1
  138. package/dist/model/units/throughput.d.ts +13 -0
  139. package/dist/model/units/throughput.d.ts.map +1 -0
  140. package/dist/model/units/throughput.js +94 -0
  141. package/dist/model/units/throughput.js.map +1 -0
  142. package/dist/model/units/time.d.ts +15 -15
  143. package/dist/model/units/time.d.ts.map +1 -1
  144. package/dist/model/units/time.js +87 -34
  145. package/dist/model/units/time.js.map +1 -1
  146. package/dist/model/units/types.d.ts +18 -9
  147. package/dist/model/units/types.d.ts.map +1 -1
  148. package/dist/model/units/types.js +2 -1
  149. package/dist/model/units/types.js.map +1 -1
  150. package/dist/model/units/units.d.ts +50 -31
  151. package/dist/model/units/units.d.ts.map +1 -1
  152. package/dist/model/units/units.js +52 -37
  153. package/dist/model/units/units.js.map +1 -1
  154. package/dist/model/units/utils.d.ts +2 -2
  155. package/dist/model/units/utils.d.ts.map +1 -1
  156. package/dist/model/units/utils.js +4 -4
  157. package/dist/model/units/utils.js.map +1 -1
  158. package/dist/model/variables.d.ts +28 -9
  159. package/dist/model/variables.d.ts.map +1 -1
  160. package/dist/model/variables.js +3 -0
  161. package/dist/model/variables.js.map +1 -1
  162. package/dist/test/setup-tests.js.map +1 -1
  163. package/dist/utils/event.js.map +1 -1
  164. package/dist/utils/fetch.d.ts +3 -1
  165. package/dist/utils/fetch.d.ts.map +1 -1
  166. package/dist/utils/fetch.js +21 -4
  167. package/dist/utils/fetch.js.map +1 -1
  168. package/dist/utils/index.d.ts +2 -1
  169. package/dist/utils/index.d.ts.map +1 -1
  170. package/dist/utils/index.js +2 -1
  171. package/dist/utils/index.js.map +1 -1
  172. package/dist/utils/is-empty-object.js.map +1 -1
  173. package/dist/utils/mathjs.js +1 -1
  174. package/dist/utils/mathjs.js.map +1 -1
  175. package/dist/utils/memo.js +2 -2
  176. package/dist/utils/memo.js.map +1 -1
  177. package/dist/utils/panel-refs.js.map +1 -1
  178. package/dist/utils/text.d.ts +7 -7
  179. package/dist/utils/text.d.ts.map +1 -1
  180. package/dist/utils/text.js +17 -17
  181. package/dist/utils/text.js.map +1 -1
  182. package/dist/utils/time-series-data.d.ts +1 -1
  183. package/dist/utils/time-series-data.d.ts.map +1 -1
  184. package/dist/utils/time-series-data.js +7 -7
  185. package/dist/utils/time-series-data.js.map +1 -1
  186. package/dist/utils/types.d.ts +2 -0
  187. package/dist/utils/types.d.ts.map +1 -0
  188. package/dist/utils/types.js +15 -0
  189. package/dist/utils/types.js.map +1 -0
  190. package/package.json +5 -4
@@ -21,15 +21,47 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- isRelativeTimeRange: ()=>isRelativeTimeRange,
25
- isAbsoluteTimeRange: ()=>isAbsoluteTimeRange,
26
- toAbsoluteTimeRange: ()=>toAbsoluteTimeRange,
27
- parseDurationString: ()=>parseDurationString,
28
- isDurationString: ()=>isDurationString,
29
- roundStepInterval: ()=>roundStepInterval,
30
- getSuggestedStepMs: ()=>getSuggestedStepMs
24
+ DURATION_REGEX: function() {
25
+ return DURATION_REGEX;
26
+ },
27
+ formatDuration: function() {
28
+ return formatDuration;
29
+ },
30
+ getSuggestedStepMs: function() {
31
+ return getSuggestedStepMs;
32
+ },
33
+ intervalToPrometheusDuration: function() {
34
+ return intervalToPrometheusDuration;
35
+ },
36
+ isAbsoluteTimeRange: function() {
37
+ return isAbsoluteTimeRange;
38
+ },
39
+ isDurationString: function() {
40
+ return isDurationString;
41
+ },
42
+ isRelativeTimeRange: function() {
43
+ return isRelativeTimeRange;
44
+ },
45
+ msToPrometheusDuration: function() {
46
+ return msToPrometheusDuration;
47
+ },
48
+ parseDurationString: function() {
49
+ return parseDurationString;
50
+ },
51
+ roundStepInterval: function() {
52
+ return roundStepInterval;
53
+ },
54
+ toAbsoluteTimeRange: function() {
55
+ return toAbsoluteTimeRange;
56
+ }
31
57
  });
32
- const _dateFns = require("date-fns");
58
+ const _datefns = require("date-fns");
59
+ const ONE_SECOND_IN_MS = 1000;
60
+ const ONE_MINUTE_IN_MS = 60000;
61
+ const ONE_HOUR_IN_MS = 3600000;
62
+ const ONE_DAY_IN_MS = 86400000; // assuming a day has always 24h
63
+ const ONE_WEEK_IN_MS = 604800000; // assuming a week has always 7d
64
+ const ONE_YEAR_IN_MS = 31536000000; // assuming a year has always 365d
33
65
  function isRelativeTimeRange(timeRange) {
34
66
  return timeRange.pastDuration !== undefined;
35
67
  }
@@ -37,10 +69,10 @@ function isAbsoluteTimeRange(timeRange) {
37
69
  return timeRange.start !== undefined && timeRange.end !== undefined;
38
70
  }
39
71
  function toAbsoluteTimeRange(timeRange) {
40
- var _end;
41
- const end = (_end = timeRange.end) !== null && _end !== void 0 ? _end : new Date();
72
+ var _timeRange_end;
73
+ const end = (_timeRange_end = timeRange.end) !== null && _timeRange_end !== void 0 ? _timeRange_end : new Date();
42
74
  return {
43
- start: (0, _dateFns.sub)(end, parseDurationString(timeRange.pastDuration)),
75
+ start: (0, _datefns.sub)(end, parseDurationString(timeRange.pastDuration)),
44
76
  end
45
77
  };
46
78
  }
@@ -50,21 +82,75 @@ function parseDurationString(durationString) {
50
82
  if (matches === null) {
51
83
  throw new Error(`Invalid duration string '${durationString}'`);
52
84
  }
53
- var ref, ref1, ref2, ref3, ref4, ref5, ref6;
85
+ var _matches_, _matches_1, _matches_2, _matches_3, _matches_4, _matches_5, _matches_6;
54
86
  return {
55
- years: parseInt((ref = matches[1]) !== null && ref !== void 0 ? ref : '0'),
87
+ years: parseInt((_matches_ = matches[1]) !== null && _matches_ !== void 0 ? _matches_ : '0'),
56
88
  months: 0,
57
- weeks: parseInt((ref1 = matches[2]) !== null && ref1 !== void 0 ? ref1 : '0'),
58
- days: parseInt((ref2 = matches[3]) !== null && ref2 !== void 0 ? ref2 : '0'),
59
- hours: parseInt((ref3 = matches[4]) !== null && ref3 !== void 0 ? ref3 : '0'),
60
- minutes: parseInt((ref4 = matches[5]) !== null && ref4 !== void 0 ? ref4 : '0'),
61
- seconds: parseInt((ref5 = matches[6]) !== null && ref5 !== void 0 ? ref5 : '0') + parseInt((ref6 = matches[7]) !== null && ref6 !== void 0 ? ref6 : '0') / 1000
89
+ weeks: parseInt((_matches_1 = matches[2]) !== null && _matches_1 !== void 0 ? _matches_1 : '0'),
90
+ days: parseInt((_matches_2 = matches[3]) !== null && _matches_2 !== void 0 ? _matches_2 : '0'),
91
+ hours: parseInt((_matches_3 = matches[4]) !== null && _matches_3 !== void 0 ? _matches_3 : '0'),
92
+ minutes: parseInt((_matches_4 = matches[5]) !== null && _matches_4 !== void 0 ? _matches_4 : '0'),
93
+ seconds: parseInt((_matches_5 = matches[6]) !== null && _matches_5 !== void 0 ? _matches_5 : '0') + parseInt((_matches_6 = matches[7]) !== null && _matches_6 !== void 0 ? _matches_6 : '0') / 1000
62
94
  };
63
95
  }
64
96
  function isDurationString(maybeDuration) {
65
97
  if (maybeDuration === '') return false;
66
98
  return DURATION_REGEX.test(maybeDuration);
67
99
  }
100
+ function intervalToPrometheusDuration(timeRange) {
101
+ const durationInMs = timeRange.end.valueOf() - timeRange.start.valueOf();
102
+ return msToPrometheusDuration(durationInMs);
103
+ }
104
+ function msToPrometheusDuration(durationInMs) {
105
+ const years = Math.trunc(durationInMs / ONE_YEAR_IN_MS);
106
+ if (years > 0) durationInMs -= years * ONE_YEAR_IN_MS;
107
+ const weeks = Math.trunc(durationInMs / ONE_WEEK_IN_MS);
108
+ if (weeks > 0) durationInMs -= weeks * ONE_WEEK_IN_MS;
109
+ const days = Math.trunc(durationInMs / ONE_DAY_IN_MS);
110
+ if (days > 0) durationInMs -= days * ONE_DAY_IN_MS;
111
+ const hours = Math.trunc(durationInMs / ONE_HOUR_IN_MS);
112
+ if (hours > 0) durationInMs -= hours * ONE_HOUR_IN_MS;
113
+ const minutes = Math.trunc(durationInMs / ONE_MINUTE_IN_MS);
114
+ if (minutes > 0) durationInMs -= minutes * ONE_MINUTE_IN_MS;
115
+ return {
116
+ years: years,
117
+ months: 0,
118
+ weeks: weeks,
119
+ days: days,
120
+ hours: hours,
121
+ minutes: minutes,
122
+ seconds: durationInMs / 1000
123
+ };
124
+ }
125
+ function formatDuration(duration) {
126
+ const result = [];
127
+ if (duration.years) {
128
+ result.push(`${duration.years}y`);
129
+ }
130
+ if (duration.weeks) {
131
+ result.push(`${duration.weeks}w`);
132
+ }
133
+ if (duration.days) {
134
+ result.push(`${duration.days}d`);
135
+ }
136
+ if (duration.hours) {
137
+ result.push(`${duration.hours}h`);
138
+ }
139
+ if (duration.minutes) {
140
+ result.push(`${duration.minutes}m`);
141
+ }
142
+ if (duration.seconds) {
143
+ const seconds = Math.trunc(duration.seconds);
144
+ if (seconds) {
145
+ result.push(`${seconds}s`);
146
+ }
147
+ const ms = (duration.seconds - seconds) * 1000;
148
+ if (ms) {
149
+ result.push(`${ms}ms`);
150
+ }
151
+ }
152
+ return result.join('');
153
+ }
68
154
  const DEFAULT_STEP_MS = 15000;
69
155
  const ROUNDED_STEP_INTERVALS = [
70
156
  // max: 0.015s
@@ -105,145 +191,145 @@ const ROUNDED_STEP_INTERVALS = [
105
191
  },
106
192
  // max: 1.5s
107
193
  {
108
- maxMs: 1500,
109
- roundedStepMs: 1000,
194
+ maxMs: ONE_SECOND_IN_MS * 1.5,
195
+ roundedStepMs: ONE_SECOND_IN_MS,
110
196
  display: '1s'
111
197
  },
112
198
  // max: 3.5s
113
199
  {
114
- maxMs: 3500,
115
- roundedStepMs: 2000,
200
+ maxMs: ONE_SECOND_IN_MS * 3.5,
201
+ roundedStepMs: ONE_SECOND_IN_MS * 2,
116
202
  display: '2s'
117
203
  },
118
204
  // max: 7.5s
119
205
  {
120
- maxMs: 7500,
121
- roundedStepMs: 5000,
206
+ maxMs: ONE_SECOND_IN_MS * 7.5,
207
+ roundedStepMs: ONE_SECOND_IN_MS * 5,
122
208
  display: '5s'
123
209
  },
124
210
  // max: 12.5s
125
211
  {
126
- maxMs: 12500,
127
- roundedStepMs: 10000,
212
+ maxMs: ONE_SECOND_IN_MS * 12.5,
213
+ roundedStepMs: ONE_SECOND_IN_MS * 10,
128
214
  display: '10s'
129
215
  },
130
216
  // max: 17.5s
131
217
  {
132
- maxMs: 17500,
133
- roundedStepMs: 15000,
218
+ maxMs: ONE_SECOND_IN_MS * 17.5,
219
+ roundedStepMs: ONE_SECOND_IN_MS * 15,
134
220
  display: '15s'
135
221
  },
136
222
  // max: 25s
137
223
  {
138
- maxMs: 25000,
139
- roundedStepMs: 20000,
224
+ maxMs: ONE_SECOND_IN_MS * 25,
225
+ roundedStepMs: ONE_SECOND_IN_MS * 20,
140
226
  display: '20s'
141
227
  },
142
228
  // max: 45s
143
229
  {
144
- maxMs: 45000,
145
- roundedStepMs: 30000,
230
+ maxMs: ONE_SECOND_IN_MS * 45,
231
+ roundedStepMs: ONE_SECOND_IN_MS * 30,
146
232
  display: '30s'
147
233
  },
148
234
  // max: 1.5m
149
235
  {
150
- maxMs: 90000,
151
- roundedStepMs: 60000,
236
+ maxMs: ONE_MINUTE_IN_MS * 1.5,
237
+ roundedStepMs: ONE_MINUTE_IN_MS,
152
238
  display: '1m'
153
239
  },
154
240
  // max: 3.5m
155
241
  {
156
- maxMs: 210000,
157
- roundedStepMs: 120000,
242
+ maxMs: ONE_MINUTE_IN_MS * 3.5,
243
+ roundedStepMs: ONE_MINUTE_IN_MS * 2,
158
244
  display: '2m'
159
245
  },
160
246
  // max: 7.5m
161
247
  {
162
- maxMs: 450000,
163
- roundedStepMs: 300000,
248
+ maxMs: ONE_MINUTE_IN_MS * 7.5,
249
+ roundedStepMs: ONE_MINUTE_IN_MS * 5,
164
250
  display: '5m'
165
251
  },
166
252
  // max: 12.5m
167
253
  {
168
- maxMs: 750000,
169
- roundedStepMs: 600000,
254
+ maxMs: ONE_MINUTE_IN_MS * 12.5,
255
+ roundedStepMs: ONE_MINUTE_IN_MS * 10,
170
256
  display: '10m'
171
257
  },
172
258
  // max: 12.5m
173
259
  {
174
- maxMs: 1050000,
175
- roundedStepMs: 900000,
260
+ maxMs: ONE_MINUTE_IN_MS * 12.5,
261
+ roundedStepMs: ONE_MINUTE_IN_MS * 15,
176
262
  display: '15m'
177
263
  },
178
264
  // max: 25m
179
265
  {
180
- maxMs: 1500000,
181
- roundedStepMs: 1200000,
266
+ maxMs: ONE_MINUTE_IN_MS * 25,
267
+ roundedStepMs: ONE_MINUTE_IN_MS * 20,
182
268
  display: '20m'
183
269
  },
184
270
  // max: 45m
185
271
  {
186
- maxMs: 2700000,
187
- roundedStepMs: 1800000,
272
+ maxMs: ONE_MINUTE_IN_MS * 45,
273
+ roundedStepMs: ONE_MINUTE_IN_MS * 30,
188
274
  display: '30m'
189
275
  },
190
276
  // max: 1.5h
191
277
  {
192
- maxMs: 5400000,
193
- roundedStepMs: 3600000,
278
+ maxMs: ONE_HOUR_IN_MS * 1.5,
279
+ roundedStepMs: ONE_HOUR_IN_MS,
194
280
  display: '1h'
195
281
  },
196
282
  // max: 2.5h
197
283
  {
198
- maxMs: 9000000,
199
- roundedStepMs: 7200000,
284
+ maxMs: ONE_HOUR_IN_MS * 2.5,
285
+ roundedStepMs: ONE_HOUR_IN_MS * 2,
200
286
  display: '2h'
201
287
  },
202
288
  // max: 4.5h
203
289
  {
204
- maxMs: 16200000,
205
- roundedStepMs: 10800000,
290
+ maxMs: ONE_HOUR_IN_MS * 4.5,
291
+ roundedStepMs: ONE_HOUR_IN_MS * 3,
206
292
  display: '3h'
207
293
  },
208
294
  // max: 9h
209
295
  {
210
- maxMs: 32400000,
211
- roundedStepMs: 21600000,
296
+ maxMs: ONE_HOUR_IN_MS * 9,
297
+ roundedStepMs: ONE_HOUR_IN_MS * 6,
212
298
  display: '6h'
213
299
  },
214
300
  // max: 1d
215
301
  {
216
- maxMs: 86400000,
217
- roundedStepMs: 43200000,
302
+ maxMs: ONE_DAY_IN_MS,
303
+ roundedStepMs: ONE_HOUR_IN_MS * 12,
218
304
  display: '12h'
219
305
  },
220
306
  // max: 1w
221
307
  {
222
- maxMs: 604800000,
223
- roundedStepMs: 86400000,
308
+ maxMs: ONE_WEEK_IN_MS,
309
+ roundedStepMs: ONE_DAY_IN_MS,
224
310
  display: '1d'
225
311
  },
226
312
  // max: 3w
227
313
  {
228
- maxMs: 1814400000,
229
- roundedStepMs: 604800000,
314
+ maxMs: ONE_WEEK_IN_MS * 3,
315
+ roundedStepMs: ONE_WEEK_IN_MS,
230
316
  display: '1w'
231
317
  },
232
318
  // max: 6w
233
319
  {
234
- maxMs: 3628800000,
235
- roundedStepMs: 2592000000,
320
+ maxMs: ONE_WEEK_IN_MS * 6,
321
+ roundedStepMs: ONE_DAY_IN_MS * 30,
236
322
  display: '30d'
237
323
  },
238
324
  // max: 2y
239
325
  {
240
- maxMs: 63072000000,
241
- roundedStepMs: 31536000000,
326
+ maxMs: ONE_YEAR_IN_MS * 2,
327
+ roundedStepMs: ONE_YEAR_IN_MS,
242
328
  display: '1y'
243
329
  }
244
330
  ];
245
331
  function roundStepInterval(stepMs) {
246
- for (const { maxMs , roundedStepMs } of ROUNDED_STEP_INTERVALS){
332
+ for (const { maxMs, roundedStepMs } of ROUNDED_STEP_INTERVALS){
247
333
  if (stepMs < maxMs) {
248
334
  return roundedStepMs;
249
335
  }
@@ -0,0 +1,16 @@
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
+ });
@@ -21,64 +21,76 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- BYTES_GROUP_CONFIG: ()=>BYTES_GROUP_CONFIG,
25
- BYTES_UNIT_CONFIG: ()=>BYTES_UNIT_CONFIG,
26
- formatBytes: ()=>formatBytes
24
+ BYTES_GROUP_CONFIG: function() {
25
+ return BYTES_GROUP_CONFIG;
26
+ },
27
+ BYTES_UNIT_CONFIG: function() {
28
+ return BYTES_UNIT_CONFIG;
29
+ },
30
+ formatBytes: function() {
31
+ return formatBytes;
32
+ }
27
33
  });
28
- const _numbro = /*#__PURE__*/ _interopRequireDefault(require("numbro"));
34
+ const _numbro = /*#__PURE__*/ _interop_require_default(require("numbro"));
29
35
  const _constants = require("./constants");
30
36
  const _utils = require("./utils");
31
- function _interopRequireDefault(obj) {
37
+ function _interop_require_default(obj) {
32
38
  return obj && obj.__esModule ? obj : {
33
39
  default: obj
34
40
  };
35
41
  }
36
- const DEFAULT_NUMBRO_MANTISSA = 2;
37
- const bytesUnitKinds = [
38
- 'Bytes'
42
+ /**
43
+ * We consider the units for bytes to be powers of 1000.
44
+ * In other words:
45
+ * 1 KB = 1000 bytes (1000^1 bytes)
46
+ * 1 MB = 1,000,000 bytes (1000^2 bytes)
47
+ * etc.
48
+ */ const DEFAULT_NUMBRO_MANTISSA = 2;
49
+ const bytesUnits = [
50
+ 'bytes'
39
51
  ];
40
52
  const BYTES_GROUP_CONFIG = {
41
53
  label: 'Bytes',
42
- decimal_places: true,
43
- abbreviate: true
54
+ decimalPlaces: true,
55
+ shortValues: true
44
56
  };
45
57
  const BYTES_UNIT_CONFIG = {
46
- // These units are powers of 1000.
47
- // In other words, 1 KB = 1000 bytes.
48
- Bytes: {
58
+ bytes: {
49
59
  group: 'Bytes',
50
60
  label: 'Bytes'
51
61
  }
52
62
  };
53
- function formatBytes(bytes, options) {
54
- const { abbreviate , decimal_places } = options;
55
- if (!(0, _utils.shouldAbbreviate)(abbreviate) || Math.abs(bytes) < 1000) {
63
+ function formatBytes(bytes, { shortValues, decimalPlaces }) {
64
+ // If we're showing the entire value, we can use Intl.NumberFormat.
65
+ if (!(0, _utils.shouldShortenValues)(shortValues) || Math.abs(bytes) < 1000) {
56
66
  const formatterOptions = {
57
67
  style: 'unit',
58
68
  unit: 'byte',
59
69
  unitDisplay: 'long',
60
70
  useGrouping: true
61
71
  };
62
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
63
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
64
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
72
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
73
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
74
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
65
75
  } else {
66
76
  // This can happen if bytes is between -1000 and 1000
67
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
77
+ if ((0, _utils.shouldShortenValues)(shortValues)) {
68
78
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
69
79
  }
70
80
  }
71
- return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
81
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
82
+ return formatter.format(bytes);
72
83
  }
73
- // numbro is able to add units like KB, MB, GB, etc. correctly
84
+ // If we're showing the shorten value, we use numbro.
85
+ // numbro is able to add units like KB, MB, GB, etc. correctly.
74
86
  return (0, _numbro.default)(bytes).format({
75
87
  output: 'byte',
76
88
  base: 'decimal',
77
89
  spaceSeparated: true,
78
- mantissa: (0, _utils.hasDecimalPlaces)(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
90
+ mantissa: (0, _utils.hasDecimalPlaces)(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
79
91
  // trimMantissa trims trailing 0s
80
- trimMantissa: !(0, _utils.hasDecimalPlaces)(decimal_places),
92
+ trimMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces),
81
93
  // optionalMantissa excludes all the decimal places if they're all zeros
82
- optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimal_places)
94
+ optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces)
83
95
  });
84
96
  }
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "__esModule", {
18
18
  });
19
19
  Object.defineProperty(exports, "MAX_SIGNIFICANT_DIGITS", {
20
20
  enumerable: true,
21
- get: ()=>MAX_SIGNIFICANT_DIGITS
21
+ get: function() {
22
+ return MAX_SIGNIFICANT_DIGITS;
23
+ }
22
24
  });
23
25
  const MAX_SIGNIFICANT_DIGITS = 3;
@@ -21,42 +21,48 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- DECIMAL_GROUP_CONFIG: ()=>DECIMAL_GROUP_CONFIG,
25
- DECIMAL_UNIT_CONFIG: ()=>DECIMAL_UNIT_CONFIG,
26
- formatDecimal: ()=>formatDecimal
24
+ DECIMAL_GROUP_CONFIG: function() {
25
+ return DECIMAL_GROUP_CONFIG;
26
+ },
27
+ DECIMAL_UNIT_CONFIG: function() {
28
+ return DECIMAL_UNIT_CONFIG;
29
+ },
30
+ formatDecimal: function() {
31
+ return formatDecimal;
32
+ }
27
33
  });
28
34
  const _constants = require("./constants");
29
35
  const _utils = require("./utils");
30
- const decimalUnitKinds = [
31
- 'Decimal'
36
+ const decimalUnits = [
37
+ 'decimal'
32
38
  ];
33
39
  const DECIMAL_GROUP_CONFIG = {
34
40
  label: 'Decimal',
35
- decimal_places: true,
36
- abbreviate: true
41
+ decimalPlaces: true,
42
+ shortValues: true
37
43
  };
38
44
  const DECIMAL_UNIT_CONFIG = {
39
- Decimal: {
45
+ decimal: {
40
46
  group: 'Decimal',
41
47
  label: 'Decimal'
42
48
  }
43
49
  };
44
- function formatDecimal(value, options) {
45
- const { abbreviate , decimal_places } = options;
50
+ function formatDecimal(value, { shortValues, decimalPlaces }) {
46
51
  const formatterOptions = {
47
52
  style: 'decimal',
48
53
  useGrouping: true
49
54
  };
50
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
55
+ if ((0, _utils.shouldShortenValues)(shortValues)) {
51
56
  formatterOptions.notation = 'compact';
52
57
  }
53
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
54
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
55
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
58
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
59
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
60
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
56
61
  } else {
57
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
62
+ if ((0, _utils.shouldShortenValues)(shortValues)) {
58
63
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
59
64
  }
60
65
  }
61
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
66
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
67
+ return formatter.format(value);
62
68
  }
@@ -14,18 +14,20 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _exportStar(require("./utils"), exports);
18
- _exportStar(require("./units"), exports);
19
- _exportStar(require("./constants"), exports);
20
- _exportStar(require("./types"), exports);
21
- function _exportStar(from, to) {
17
+ _export_star(require("./utils"), exports);
18
+ _export_star(require("./units"), exports);
19
+ _export_star(require("./constants"), exports);
20
+ _export_star(require("./types"), exports);
21
+ function _export_star(from, to) {
22
22
  Object.keys(from).forEach(function(k) {
23
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
24
- enumerable: true,
25
- get: function() {
26
- return from[k];
27
- }
28
- });
23
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
24
+ Object.defineProperty(to, k, {
25
+ enumerable: true,
26
+ get: function() {
27
+ return from[k];
28
+ }
29
+ });
30
+ }
29
31
  });
30
32
  return from;
31
33
  }
@@ -21,28 +21,34 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- PERCENT_GROUP_CONFIG: ()=>PERCENT_GROUP_CONFIG,
25
- PERCENT_UNIT_CONFIG: ()=>PERCENT_UNIT_CONFIG,
26
- formatPercent: ()=>formatPercent
24
+ PERCENT_GROUP_CONFIG: function() {
25
+ return PERCENT_GROUP_CONFIG;
26
+ },
27
+ PERCENT_UNIT_CONFIG: function() {
28
+ return PERCENT_UNIT_CONFIG;
29
+ },
30
+ formatPercent: function() {
31
+ return formatPercent;
32
+ }
27
33
  });
28
34
  const _constants = require("./constants");
29
35
  const _utils = require("./utils");
30
- const percentUnitKinds = [
31
- 'Percent',
32
- 'PercentDecimal',
36
+ const percentUnits = [
37
+ 'percent',
38
+ 'percent-decimal',
33
39
  '%'
34
40
  ];
35
41
  const PERCENT_GROUP_CONFIG = {
36
- label: 'Percent',
37
- decimal_places: true
42
+ label: 'percent',
43
+ decimalPlaces: true
38
44
  };
39
45
  const PERCENT_GROUP = 'Percent';
40
46
  const PERCENT_UNIT_CONFIG = {
41
- Percent: {
47
+ percent: {
42
48
  group: PERCENT_GROUP,
43
49
  label: 'Percent (0-100)'
44
50
  },
45
- PercentDecimal: {
51
+ 'percent-decimal': {
46
52
  group: PERCENT_GROUP,
47
53
  label: 'Percent (0.0-1.0)'
48
54
  },
@@ -54,20 +60,21 @@ const PERCENT_UNIT_CONFIG = {
54
60
  label: '%'
55
61
  }
56
62
  };
57
- function formatPercent(value, { kind , decimal_places }) {
58
- // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
59
- if (kind === 'Percent') {
60
- value = value / 100;
61
- }
63
+ function formatPercent(value, { unit, decimalPlaces }) {
62
64
  const formatterOptions = {
63
65
  style: 'percent',
64
66
  useGrouping: true
65
67
  };
66
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
67
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
68
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
68
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
69
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
70
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
69
71
  } else {
70
72
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
71
73
  }
72
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
74
+ // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.
75
+ if (unit === 'percent') {
76
+ value = value / 100;
77
+ }
78
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
79
+ return formatter.format(value);
73
80
  }