@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.
- 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/ephemeraldashboard.js +16 -0
- package/dist/cjs/model/http-proxy.js +16 -0
- package/dist/cjs/model/index.js +35 -26
- package/dist/cjs/model/kind.js +39 -0
- package/dist/cjs/model/legend.js +39 -19
- package/dist/cjs/model/resource.js +9 -0
- package/dist/cjs/model/rolebindings.js +16 -0
- package/dist/cjs/model/roles.js +60 -0
- package/dist/cjs/model/secrets.js +16 -0
- package/dist/cjs/model/time-series-queries.js +3 -1
- package/dist/cjs/model/time.js +151 -65
- package/dist/cjs/model/trace-data.js +16 -0
- 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/throughput.js +113 -0
- package/dist/cjs/model/units/time.js +99 -38
- package/dist/cjs/model/units/types.js +5 -2
- package/dist/cjs/model/units/units.js +81 -45
- 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 +32 -7
- package/dist/cjs/utils/index.js +17 -14
- package/dist/cjs/utils/is-empty-object.js +3 -1
- package/dist/cjs/utils/mathjs.js +4 -2
- package/dist/cjs/utils/memo.js +10 -6
- package/dist/cjs/utils/panel-refs.js +9 -3
- package/dist/cjs/utils/text.js +33 -21
- 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 +12 -12
- 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/dashboard.js.map +1 -1
- package/dist/model/datasource.d.ts +17 -3
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js +3 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/definitions.d.ts +1 -1
- package/dist/model/definitions.d.ts.map +1 -1
- package/dist/model/definitions.js +3 -0
- package/dist/model/definitions.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/ephemeraldashboard.d.ts +15 -0
- package/dist/model/ephemeraldashboard.d.ts.map +1 -0
- package/dist/model/ephemeraldashboard.js +15 -0
- package/dist/model/ephemeraldashboard.js.map +1 -0
- package/dist/model/http-proxy.d.ts +16 -0
- package/dist/model/http-proxy.d.ts.map +1 -0
- package/dist/model/http-proxy.js +15 -0
- package/dist/model/http-proxy.js.map +1 -0
- package/dist/model/http.d.ts +1 -1
- package/dist/model/http.d.ts.map +1 -1
- package/dist/model/index.d.ts +7 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +7 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/kind.d.ts +3 -0
- package/dist/model/kind.d.ts.map +1 -0
- package/dist/model/kind.js +31 -0
- package/dist/model/kind.js.map +1 -0
- package/dist/model/layout.d.ts +1 -1
- package/dist/model/layout.d.ts.map +1 -1
- package/dist/model/layout.js.map +1 -1
- package/dist/model/legend.d.ts +9 -9
- package/dist/model/legend.d.ts.map +1 -1
- 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 +3 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/project.js.map +1 -1
- package/dist/model/query.d.ts +15 -2
- package/dist/model/query.d.ts.map +1 -1
- package/dist/model/query.js +4 -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/rolebindings.d.ts +27 -0
- package/dist/model/rolebindings.d.ts.map +1 -0
- package/dist/model/rolebindings.js +15 -0
- package/dist/model/rolebindings.js.map +1 -0
- package/dist/model/roles.d.ts +32 -0
- package/dist/model/roles.d.ts.map +1 -0
- package/dist/model/roles.js +41 -0
- package/dist/model/roles.js.map +1 -0
- package/dist/model/secrets.d.ts +44 -0
- package/dist/model/secrets.d.ts.map +1 -0
- package/dist/model/secrets.js +15 -0
- package/dist/model/secrets.js.map +1 -0
- 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.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +3 -3
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/time.d.ts +15 -11
- package/dist/model/time.d.ts.map +1 -1
- package/dist/model/time.js +117 -57
- package/dist/model/time.js.map +1 -1
- package/dist/model/trace-data.d.ts +20 -0
- package/dist/model/trace-data.d.ts.map +1 -0
- package/dist/model/trace-data.js +18 -0
- package/dist/model/trace-data.js.map +1 -0
- 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/throughput.d.ts +13 -0
- package/dist/model/units/throughput.d.ts.map +1 -0
- package/dist/model/units/throughput.js +94 -0
- package/dist/model/units/throughput.js.map +1 -0
- 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 +18 -9
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js +2 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.d.ts +50 -31
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +52 -37
- 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 +28 -9
- 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.d.ts +3 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +21 -4
- 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 +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 +7 -7
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +17 -17
- 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,47 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
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
|
|
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
|
|
41
|
-
const end = (
|
|
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,
|
|
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
|
|
85
|
+
var _matches_, _matches_1, _matches_2, _matches_3, _matches_4, _matches_5, _matches_6;
|
|
54
86
|
return {
|
|
55
|
-
years: parseInt((
|
|
87
|
+
years: parseInt((_matches_ = matches[1]) !== null && _matches_ !== void 0 ? _matches_ : '0'),
|
|
56
88
|
months: 0,
|
|
57
|
-
weeks: parseInt((
|
|
58
|
-
days: parseInt((
|
|
59
|
-
hours: parseInt((
|
|
60
|
-
minutes: parseInt((
|
|
61
|
-
seconds: parseInt((
|
|
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:
|
|
109
|
-
roundedStepMs:
|
|
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:
|
|
115
|
-
roundedStepMs:
|
|
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:
|
|
121
|
-
roundedStepMs:
|
|
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:
|
|
127
|
-
roundedStepMs:
|
|
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:
|
|
133
|
-
roundedStepMs:
|
|
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:
|
|
139
|
-
roundedStepMs:
|
|
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:
|
|
145
|
-
roundedStepMs:
|
|
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:
|
|
151
|
-
roundedStepMs:
|
|
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:
|
|
157
|
-
roundedStepMs:
|
|
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:
|
|
163
|
-
roundedStepMs:
|
|
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:
|
|
169
|
-
roundedStepMs:
|
|
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:
|
|
175
|
-
roundedStepMs:
|
|
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:
|
|
181
|
-
roundedStepMs:
|
|
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:
|
|
187
|
-
roundedStepMs:
|
|
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:
|
|
193
|
-
roundedStepMs:
|
|
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:
|
|
199
|
-
roundedStepMs:
|
|
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:
|
|
205
|
-
roundedStepMs:
|
|
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:
|
|
211
|
-
roundedStepMs:
|
|
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:
|
|
217
|
-
roundedStepMs:
|
|
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:
|
|
223
|
-
roundedStepMs:
|
|
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:
|
|
229
|
-
roundedStepMs:
|
|
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:
|
|
235
|
-
roundedStepMs:
|
|
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:
|
|
241
|
-
roundedStepMs:
|
|
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
|
|
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: ()
|
|
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
|
}
|