@perses-dev/core 0.38.0 → 0.40.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.
- package/dist/cjs/constants/dashboard-defaults.js +6 -2
- package/dist/cjs/constants/dialog.js +3 -1
- package/dist/cjs/constants/index.js +11 -9
- package/dist/cjs/index.js +12 -10
- package/dist/cjs/model/calculations.js +61 -51
- package/dist/cjs/model/index.js +28 -26
- package/dist/cjs/model/legend.js +39 -19
- package/dist/cjs/model/resource.js +9 -0
- package/dist/cjs/model/time-series-queries.js +3 -1
- package/dist/cjs/model/time.js +147 -64
- package/dist/cjs/model/units/bytes.js +37 -25
- package/dist/cjs/model/units/constants.js +3 -1
- package/dist/cjs/model/units/decimal.js +22 -16
- package/dist/cjs/model/units/index.js +13 -11
- package/dist/cjs/model/units/percent.js +26 -19
- package/dist/cjs/model/units/time.js +99 -38
- package/dist/cjs/model/units/types.js +3 -1
- package/dist/cjs/model/units/units.js +67 -43
- package/dist/cjs/model/units/utils.js +13 -7
- package/dist/cjs/model/variables.js +16 -3
- package/dist/cjs/utils/event.js +3 -1
- package/dist/cjs/utils/fetch.js +12 -4
- package/dist/cjs/utils/index.js +17 -14
- package/dist/cjs/utils/is-empty-object.js +3 -1
- package/dist/cjs/utils/mathjs.js +3 -1
- package/dist/cjs/utils/memo.js +10 -6
- package/dist/cjs/utils/panel-refs.js +9 -3
- package/dist/cjs/utils/text.js +39 -14
- package/dist/cjs/utils/time-series-data.js +21 -11
- package/dist/cjs/utils/types.js +16 -0
- package/dist/constants/dashboard-defaults.js.map +1 -1
- package/dist/constants/dialog.js.map +1 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/calculations.d.ts +9 -9
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +46 -46
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/datasource.d.ts +20 -4
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/display.d.ts +1 -1
- package/dist/model/display.d.ts.map +1 -1
- package/dist/model/display.js.map +1 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +6 -6
- package/dist/model/legend.js +9 -9
- package/dist/model/legend.js.map +1 -1
- package/dist/model/panels.d.ts +5 -2
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/query.d.ts +13 -2
- package/dist/model/query.d.ts.map +1 -1
- package/dist/model/query.js.map +1 -1
- package/dist/model/resource.d.ts +3 -2
- package/dist/model/resource.d.ts.map +1 -1
- package/dist/model/resource.js +3 -1
- package/dist/model/resource.js.map +1 -1
- package/dist/model/thresholds.d.ts +2 -2
- package/dist/model/thresholds.d.ts.map +1 -1
- package/dist/model/thresholds.js.map +1 -1
- package/dist/model/time-series-data.d.ts +6 -0
- package/dist/model/time-series-data.d.ts.map +1 -1
- package/dist/model/time-series-data.js.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/time.d.ts +3 -0
- package/dist/model/time.d.ts.map +1 -1
- package/dist/model/time.js +115 -55
- package/dist/model/time.js.map +1 -1
- package/dist/model/units/bytes.d.ts +8 -8
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +27 -21
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/constants.js.map +1 -1
- package/dist/model/units/decimal.d.ts +8 -8
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +14 -14
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/index.js.map +1 -1
- package/dist/model/units/percent.d.ts +7 -7
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +17 -16
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/time.d.ts +15 -15
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +87 -34
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +14 -5
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.d.ts +37 -30
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +41 -35
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/utils.d.ts +2 -2
- package/dist/model/units/utils.d.ts.map +1 -1
- package/dist/model/units/utils.js +4 -4
- package/dist/model/units/utils.js.map +1 -1
- package/dist/model/variables.d.ts +25 -7
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +3 -0
- package/dist/model/variables.js.map +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/event.js.map +1 -1
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/is-empty-object.js.map +1 -1
- package/dist/utils/mathjs.js.map +1 -1
- package/dist/utils/memo.js +2 -2
- package/dist/utils/memo.js.map +1 -1
- package/dist/utils/panel-refs.js.map +1 -1
- package/dist/utils/text.d.ts +15 -3
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +29 -10
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/time-series-data.d.ts +1 -1
- package/dist/utils/time-series-data.d.ts.map +1 -1
- package/dist/utils/time-series-data.js +7 -7
- package/dist/utils/time-series-data.js.map +1 -1
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +15 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +5 -4
package/dist/cjs/model/time.js
CHANGED
|
@@ -21,15 +21,44 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
isRelativeTimeRange: ()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
isRelativeTimeRange: function() {
|
|
25
|
+
return isRelativeTimeRange;
|
|
26
|
+
},
|
|
27
|
+
isAbsoluteTimeRange: function() {
|
|
28
|
+
return isAbsoluteTimeRange;
|
|
29
|
+
},
|
|
30
|
+
toAbsoluteTimeRange: function() {
|
|
31
|
+
return toAbsoluteTimeRange;
|
|
32
|
+
},
|
|
33
|
+
parseDurationString: function() {
|
|
34
|
+
return parseDurationString;
|
|
35
|
+
},
|
|
36
|
+
isDurationString: function() {
|
|
37
|
+
return isDurationString;
|
|
38
|
+
},
|
|
39
|
+
intervalToPrometheusDuration: function() {
|
|
40
|
+
return intervalToPrometheusDuration;
|
|
41
|
+
},
|
|
42
|
+
msToPrometheusDuration: function() {
|
|
43
|
+
return msToPrometheusDuration;
|
|
44
|
+
},
|
|
45
|
+
formatDuration: function() {
|
|
46
|
+
return formatDuration;
|
|
47
|
+
},
|
|
48
|
+
roundStepInterval: function() {
|
|
49
|
+
return roundStepInterval;
|
|
50
|
+
},
|
|
51
|
+
getSuggestedStepMs: function() {
|
|
52
|
+
return getSuggestedStepMs;
|
|
53
|
+
}
|
|
31
54
|
});
|
|
32
|
-
const
|
|
55
|
+
const _datefns = require("date-fns");
|
|
56
|
+
const ONE_SECOND_IN_MS = 1000;
|
|
57
|
+
const ONE_MINUTE_IN_MS = 60000;
|
|
58
|
+
const ONE_HOUR_IN_MS = 3600000;
|
|
59
|
+
const ONE_DAY_IN_MS = 86400000; // assuming a day has always 24h
|
|
60
|
+
const ONE_WEEK_IN_MS = 604800000; // assuming a week has always 7d
|
|
61
|
+
const ONE_YEAR_IN_MS = 31536000000; // assuming a year has always 365d
|
|
33
62
|
function isRelativeTimeRange(timeRange) {
|
|
34
63
|
return timeRange.pastDuration !== undefined;
|
|
35
64
|
}
|
|
@@ -37,10 +66,10 @@ function isAbsoluteTimeRange(timeRange) {
|
|
|
37
66
|
return timeRange.start !== undefined && timeRange.end !== undefined;
|
|
38
67
|
}
|
|
39
68
|
function toAbsoluteTimeRange(timeRange) {
|
|
40
|
-
var
|
|
41
|
-
const end = (
|
|
69
|
+
var _timeRange_end;
|
|
70
|
+
const end = (_timeRange_end = timeRange.end) !== null && _timeRange_end !== void 0 ? _timeRange_end : new Date();
|
|
42
71
|
return {
|
|
43
|
-
start: (0,
|
|
72
|
+
start: (0, _datefns.sub)(end, parseDurationString(timeRange.pastDuration)),
|
|
44
73
|
end
|
|
45
74
|
};
|
|
46
75
|
}
|
|
@@ -50,21 +79,75 @@ function parseDurationString(durationString) {
|
|
|
50
79
|
if (matches === null) {
|
|
51
80
|
throw new Error(`Invalid duration string '${durationString}'`);
|
|
52
81
|
}
|
|
53
|
-
var
|
|
82
|
+
var _matches_, _matches_1, _matches_2, _matches_3, _matches_4, _matches_5, _matches_6;
|
|
54
83
|
return {
|
|
55
|
-
years: parseInt((
|
|
84
|
+
years: parseInt((_matches_ = matches[1]) !== null && _matches_ !== void 0 ? _matches_ : '0'),
|
|
56
85
|
months: 0,
|
|
57
|
-
weeks: parseInt((
|
|
58
|
-
days: parseInt((
|
|
59
|
-
hours: parseInt((
|
|
60
|
-
minutes: parseInt((
|
|
61
|
-
seconds: parseInt((
|
|
86
|
+
weeks: parseInt((_matches_1 = matches[2]) !== null && _matches_1 !== void 0 ? _matches_1 : '0'),
|
|
87
|
+
days: parseInt((_matches_2 = matches[3]) !== null && _matches_2 !== void 0 ? _matches_2 : '0'),
|
|
88
|
+
hours: parseInt((_matches_3 = matches[4]) !== null && _matches_3 !== void 0 ? _matches_3 : '0'),
|
|
89
|
+
minutes: parseInt((_matches_4 = matches[5]) !== null && _matches_4 !== void 0 ? _matches_4 : '0'),
|
|
90
|
+
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
91
|
};
|
|
63
92
|
}
|
|
64
93
|
function isDurationString(maybeDuration) {
|
|
65
94
|
if (maybeDuration === '') return false;
|
|
66
95
|
return DURATION_REGEX.test(maybeDuration);
|
|
67
96
|
}
|
|
97
|
+
function intervalToPrometheusDuration(timeRange) {
|
|
98
|
+
const durationInMs = timeRange.end.valueOf() - timeRange.start.valueOf();
|
|
99
|
+
return msToPrometheusDuration(durationInMs);
|
|
100
|
+
}
|
|
101
|
+
function msToPrometheusDuration(durationInMs) {
|
|
102
|
+
const years = Math.trunc(durationInMs / ONE_YEAR_IN_MS);
|
|
103
|
+
if (years > 0) durationInMs -= years * ONE_YEAR_IN_MS;
|
|
104
|
+
const weeks = Math.trunc(durationInMs / ONE_WEEK_IN_MS);
|
|
105
|
+
if (weeks > 0) durationInMs -= weeks * ONE_WEEK_IN_MS;
|
|
106
|
+
const days = Math.trunc(durationInMs / ONE_DAY_IN_MS);
|
|
107
|
+
if (days > 0) durationInMs -= days * ONE_DAY_IN_MS;
|
|
108
|
+
const hours = Math.trunc(durationInMs / ONE_HOUR_IN_MS);
|
|
109
|
+
if (hours > 0) durationInMs -= hours * ONE_HOUR_IN_MS;
|
|
110
|
+
const minutes = Math.trunc(durationInMs / ONE_MINUTE_IN_MS);
|
|
111
|
+
if (minutes > 0) durationInMs -= minutes * ONE_MINUTE_IN_MS;
|
|
112
|
+
return {
|
|
113
|
+
years: years,
|
|
114
|
+
months: 0,
|
|
115
|
+
weeks: weeks,
|
|
116
|
+
days: days,
|
|
117
|
+
hours: hours,
|
|
118
|
+
minutes: minutes,
|
|
119
|
+
seconds: durationInMs / 1000
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function formatDuration(duration) {
|
|
123
|
+
const result = [];
|
|
124
|
+
if (duration.years) {
|
|
125
|
+
result.push(`${duration.years}y`);
|
|
126
|
+
}
|
|
127
|
+
if (duration.weeks) {
|
|
128
|
+
result.push(`${duration.weeks}w`);
|
|
129
|
+
}
|
|
130
|
+
if (duration.days) {
|
|
131
|
+
result.push(`${duration.days}d`);
|
|
132
|
+
}
|
|
133
|
+
if (duration.hours) {
|
|
134
|
+
result.push(`${duration.hours}h`);
|
|
135
|
+
}
|
|
136
|
+
if (duration.minutes) {
|
|
137
|
+
result.push(`${duration.minutes}m`);
|
|
138
|
+
}
|
|
139
|
+
if (duration.seconds) {
|
|
140
|
+
const seconds = Math.trunc(duration.seconds);
|
|
141
|
+
if (seconds) {
|
|
142
|
+
result.push(`${seconds}s`);
|
|
143
|
+
}
|
|
144
|
+
const ms = (duration.seconds - seconds) * 1000;
|
|
145
|
+
if (ms) {
|
|
146
|
+
result.push(`${ms}ms`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return result.join('');
|
|
150
|
+
}
|
|
68
151
|
const DEFAULT_STEP_MS = 15000;
|
|
69
152
|
const ROUNDED_STEP_INTERVALS = [
|
|
70
153
|
// max: 0.015s
|
|
@@ -105,140 +188,140 @@ const ROUNDED_STEP_INTERVALS = [
|
|
|
105
188
|
},
|
|
106
189
|
// max: 1.5s
|
|
107
190
|
{
|
|
108
|
-
maxMs:
|
|
109
|
-
roundedStepMs:
|
|
191
|
+
maxMs: ONE_SECOND_IN_MS * 1.5,
|
|
192
|
+
roundedStepMs: ONE_SECOND_IN_MS,
|
|
110
193
|
display: '1s'
|
|
111
194
|
},
|
|
112
195
|
// max: 3.5s
|
|
113
196
|
{
|
|
114
|
-
maxMs:
|
|
115
|
-
roundedStepMs:
|
|
197
|
+
maxMs: ONE_SECOND_IN_MS * 3.5,
|
|
198
|
+
roundedStepMs: ONE_SECOND_IN_MS * 2,
|
|
116
199
|
display: '2s'
|
|
117
200
|
},
|
|
118
201
|
// max: 7.5s
|
|
119
202
|
{
|
|
120
|
-
maxMs:
|
|
121
|
-
roundedStepMs:
|
|
203
|
+
maxMs: ONE_SECOND_IN_MS * 7.5,
|
|
204
|
+
roundedStepMs: ONE_SECOND_IN_MS * 5,
|
|
122
205
|
display: '5s'
|
|
123
206
|
},
|
|
124
207
|
// max: 12.5s
|
|
125
208
|
{
|
|
126
|
-
maxMs:
|
|
127
|
-
roundedStepMs:
|
|
209
|
+
maxMs: ONE_SECOND_IN_MS * 12.5,
|
|
210
|
+
roundedStepMs: ONE_SECOND_IN_MS * 10,
|
|
128
211
|
display: '10s'
|
|
129
212
|
},
|
|
130
213
|
// max: 17.5s
|
|
131
214
|
{
|
|
132
|
-
maxMs:
|
|
133
|
-
roundedStepMs:
|
|
215
|
+
maxMs: ONE_SECOND_IN_MS * 17.5,
|
|
216
|
+
roundedStepMs: ONE_SECOND_IN_MS * 15,
|
|
134
217
|
display: '15s'
|
|
135
218
|
},
|
|
136
219
|
// max: 25s
|
|
137
220
|
{
|
|
138
|
-
maxMs:
|
|
139
|
-
roundedStepMs:
|
|
221
|
+
maxMs: ONE_SECOND_IN_MS * 25,
|
|
222
|
+
roundedStepMs: ONE_SECOND_IN_MS * 20,
|
|
140
223
|
display: '20s'
|
|
141
224
|
},
|
|
142
225
|
// max: 45s
|
|
143
226
|
{
|
|
144
|
-
maxMs:
|
|
145
|
-
roundedStepMs:
|
|
227
|
+
maxMs: ONE_SECOND_IN_MS * 45,
|
|
228
|
+
roundedStepMs: ONE_SECOND_IN_MS * 30,
|
|
146
229
|
display: '30s'
|
|
147
230
|
},
|
|
148
231
|
// max: 1.5m
|
|
149
232
|
{
|
|
150
|
-
maxMs:
|
|
151
|
-
roundedStepMs:
|
|
233
|
+
maxMs: ONE_MINUTE_IN_MS * 1.5,
|
|
234
|
+
roundedStepMs: ONE_MINUTE_IN_MS,
|
|
152
235
|
display: '1m'
|
|
153
236
|
},
|
|
154
237
|
// max: 3.5m
|
|
155
238
|
{
|
|
156
|
-
maxMs:
|
|
157
|
-
roundedStepMs:
|
|
239
|
+
maxMs: ONE_MINUTE_IN_MS * 3.5,
|
|
240
|
+
roundedStepMs: ONE_MINUTE_IN_MS * 2,
|
|
158
241
|
display: '2m'
|
|
159
242
|
},
|
|
160
243
|
// max: 7.5m
|
|
161
244
|
{
|
|
162
|
-
maxMs:
|
|
163
|
-
roundedStepMs:
|
|
245
|
+
maxMs: ONE_MINUTE_IN_MS * 7.5,
|
|
246
|
+
roundedStepMs: ONE_MINUTE_IN_MS * 5,
|
|
164
247
|
display: '5m'
|
|
165
248
|
},
|
|
166
249
|
// max: 12.5m
|
|
167
250
|
{
|
|
168
|
-
maxMs:
|
|
169
|
-
roundedStepMs:
|
|
251
|
+
maxMs: ONE_MINUTE_IN_MS * 12.5,
|
|
252
|
+
roundedStepMs: ONE_MINUTE_IN_MS * 10,
|
|
170
253
|
display: '10m'
|
|
171
254
|
},
|
|
172
255
|
// max: 12.5m
|
|
173
256
|
{
|
|
174
|
-
maxMs:
|
|
175
|
-
roundedStepMs:
|
|
257
|
+
maxMs: ONE_MINUTE_IN_MS * 12.5,
|
|
258
|
+
roundedStepMs: ONE_MINUTE_IN_MS * 15,
|
|
176
259
|
display: '15m'
|
|
177
260
|
},
|
|
178
261
|
// max: 25m
|
|
179
262
|
{
|
|
180
|
-
maxMs:
|
|
181
|
-
roundedStepMs:
|
|
263
|
+
maxMs: ONE_MINUTE_IN_MS * 25,
|
|
264
|
+
roundedStepMs: ONE_MINUTE_IN_MS * 20,
|
|
182
265
|
display: '20m'
|
|
183
266
|
},
|
|
184
267
|
// max: 45m
|
|
185
268
|
{
|
|
186
|
-
maxMs:
|
|
187
|
-
roundedStepMs:
|
|
269
|
+
maxMs: ONE_MINUTE_IN_MS * 45,
|
|
270
|
+
roundedStepMs: ONE_MINUTE_IN_MS * 30,
|
|
188
271
|
display: '30m'
|
|
189
272
|
},
|
|
190
273
|
// max: 1.5h
|
|
191
274
|
{
|
|
192
|
-
maxMs:
|
|
193
|
-
roundedStepMs:
|
|
275
|
+
maxMs: ONE_HOUR_IN_MS * 1.5,
|
|
276
|
+
roundedStepMs: ONE_HOUR_IN_MS,
|
|
194
277
|
display: '1h'
|
|
195
278
|
},
|
|
196
279
|
// max: 2.5h
|
|
197
280
|
{
|
|
198
|
-
maxMs:
|
|
199
|
-
roundedStepMs:
|
|
281
|
+
maxMs: ONE_HOUR_IN_MS * 2.5,
|
|
282
|
+
roundedStepMs: ONE_HOUR_IN_MS * 2,
|
|
200
283
|
display: '2h'
|
|
201
284
|
},
|
|
202
285
|
// max: 4.5h
|
|
203
286
|
{
|
|
204
|
-
maxMs:
|
|
205
|
-
roundedStepMs:
|
|
287
|
+
maxMs: ONE_HOUR_IN_MS * 4.5,
|
|
288
|
+
roundedStepMs: ONE_HOUR_IN_MS * 3,
|
|
206
289
|
display: '3h'
|
|
207
290
|
},
|
|
208
291
|
// max: 9h
|
|
209
292
|
{
|
|
210
|
-
maxMs:
|
|
211
|
-
roundedStepMs:
|
|
293
|
+
maxMs: ONE_HOUR_IN_MS * 9,
|
|
294
|
+
roundedStepMs: ONE_HOUR_IN_MS * 6,
|
|
212
295
|
display: '6h'
|
|
213
296
|
},
|
|
214
297
|
// max: 1d
|
|
215
298
|
{
|
|
216
|
-
maxMs:
|
|
217
|
-
roundedStepMs:
|
|
299
|
+
maxMs: ONE_DAY_IN_MS,
|
|
300
|
+
roundedStepMs: ONE_HOUR_IN_MS * 12,
|
|
218
301
|
display: '12h'
|
|
219
302
|
},
|
|
220
303
|
// max: 1w
|
|
221
304
|
{
|
|
222
|
-
maxMs:
|
|
223
|
-
roundedStepMs:
|
|
305
|
+
maxMs: ONE_WEEK_IN_MS,
|
|
306
|
+
roundedStepMs: ONE_DAY_IN_MS,
|
|
224
307
|
display: '1d'
|
|
225
308
|
},
|
|
226
309
|
// max: 3w
|
|
227
310
|
{
|
|
228
|
-
maxMs:
|
|
229
|
-
roundedStepMs:
|
|
311
|
+
maxMs: ONE_WEEK_IN_MS * 3,
|
|
312
|
+
roundedStepMs: ONE_WEEK_IN_MS,
|
|
230
313
|
display: '1w'
|
|
231
314
|
},
|
|
232
315
|
// max: 6w
|
|
233
316
|
{
|
|
234
|
-
maxMs:
|
|
235
|
-
roundedStepMs:
|
|
317
|
+
maxMs: ONE_WEEK_IN_MS * 6,
|
|
318
|
+
roundedStepMs: ONE_DAY_IN_MS * 30,
|
|
236
319
|
display: '30d'
|
|
237
320
|
},
|
|
238
321
|
// max: 2y
|
|
239
322
|
{
|
|
240
|
-
maxMs:
|
|
241
|
-
roundedStepMs:
|
|
323
|
+
maxMs: ONE_YEAR_IN_MS * 2,
|
|
324
|
+
roundedStepMs: ONE_YEAR_IN_MS,
|
|
242
325
|
display: '1y'
|
|
243
326
|
}
|
|
244
327
|
];
|
|
@@ -21,64 +21,76 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
BYTES_GROUP_CONFIG: ()
|
|
25
|
-
|
|
26
|
-
|
|
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__*/
|
|
34
|
+
const _numbro = /*#__PURE__*/ _interop_require_default(require("numbro"));
|
|
29
35
|
const _constants = require("./constants");
|
|
30
36
|
const _utils = require("./utils");
|
|
31
|
-
function
|
|
37
|
+
function _interop_require_default(obj) {
|
|
32
38
|
return obj && obj.__esModule ? obj : {
|
|
33
39
|
default: obj
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
54
|
+
decimalPlaces: true,
|
|
55
|
+
shortValues: true
|
|
44
56
|
};
|
|
45
57
|
const BYTES_UNIT_CONFIG = {
|
|
46
|
-
|
|
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,
|
|
54
|
-
|
|
55
|
-
if (!(0, _utils.
|
|
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)(
|
|
63
|
-
formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(
|
|
64
|
-
formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(
|
|
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.
|
|
77
|
+
if ((0, _utils.shouldShortenValues)(shortValues)) {
|
|
68
78
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
69
79
|
}
|
|
70
80
|
}
|
|
71
|
-
|
|
81
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
82
|
+
return formatter.format(bytes);
|
|
72
83
|
}
|
|
73
|
-
//
|
|
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)(
|
|
90
|
+
mantissa: (0, _utils.hasDecimalPlaces)(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
|
|
79
91
|
// trimMantissa trims trailing 0s
|
|
80
|
-
trimMantissa: !(0, _utils.hasDecimalPlaces)(
|
|
92
|
+
trimMantissa: !(0, _utils.hasDecimalPlaces)(decimalPlaces),
|
|
81
93
|
// optionalMantissa excludes all the decimal places if they're all zeros
|
|
82
|
-
optionalMantissa: !(0, _utils.hasDecimalPlaces)(
|
|
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: ()
|
|
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: ()
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
31
|
-
'
|
|
36
|
+
const decimalUnits = [
|
|
37
|
+
'decimal'
|
|
32
38
|
];
|
|
33
39
|
const DECIMAL_GROUP_CONFIG = {
|
|
34
40
|
label: 'Decimal',
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
decimalPlaces: true,
|
|
42
|
+
shortValues: true
|
|
37
43
|
};
|
|
38
44
|
const DECIMAL_UNIT_CONFIG = {
|
|
39
|
-
|
|
45
|
+
decimal: {
|
|
40
46
|
group: 'Decimal',
|
|
41
47
|
label: 'Decimal'
|
|
42
48
|
}
|
|
43
49
|
};
|
|
44
|
-
function formatDecimal(value,
|
|
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.
|
|
55
|
+
if ((0, _utils.shouldShortenValues)(shortValues)) {
|
|
51
56
|
formatterOptions.notation = 'compact';
|
|
52
57
|
}
|
|
53
|
-
if ((0, _utils.hasDecimalPlaces)(
|
|
54
|
-
formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(
|
|
55
|
-
formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(
|
|
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.
|
|
62
|
+
if ((0, _utils.shouldShortenValues)(shortValues)) {
|
|
58
63
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function
|
|
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))
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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: ()
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
31
|
-
'
|
|
32
|
-
'
|
|
36
|
+
const percentUnits = [
|
|
37
|
+
'percent',
|
|
38
|
+
'percent-decimal',
|
|
33
39
|
'%'
|
|
34
40
|
];
|
|
35
41
|
const PERCENT_GROUP_CONFIG = {
|
|
36
|
-
label: '
|
|
37
|
-
|
|
42
|
+
label: 'percent',
|
|
43
|
+
decimalPlaces: true
|
|
38
44
|
};
|
|
39
45
|
const PERCENT_GROUP = 'Percent';
|
|
40
46
|
const PERCENT_UNIT_CONFIG = {
|
|
41
|
-
|
|
47
|
+
percent: {
|
|
42
48
|
group: PERCENT_GROUP,
|
|
43
49
|
label: 'Percent (0-100)'
|
|
44
50
|
},
|
|
45
|
-
|
|
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, {
|
|
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)(
|
|
67
|
-
formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(
|
|
68
|
-
formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(
|
|
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
|
-
|
|
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
|
}
|