@perses-dev/core 0.53.0 → 0.53.1
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/model/units/bits.js +10 -2
- package/dist/cjs/model/units/bytes.js +12 -2
- package/dist/cjs/model/units/currency.js +10 -2
- package/dist/cjs/model/units/decimal.js +9 -2
- package/dist/cjs/model/units/formatterCache.js +120 -0
- package/dist/cjs/model/units/percent.js +9 -2
- package/dist/cjs/model/units/temperature.js +9 -1
- package/dist/cjs/model/units/throughput.js +11 -2
- package/dist/cjs/model/units/time.js +10 -2
- package/dist/cjs/schema/panel.js +1 -0
- package/dist/model/query.d.ts +1 -0
- package/dist/model/query.d.ts.map +1 -1
- package/dist/model/query.js.map +1 -1
- package/dist/model/units/bits.d.ts.map +1 -1
- package/dist/model/units/bits.js +10 -2
- package/dist/model/units/bits.js.map +1 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +12 -2
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/currency.d.ts.map +1 -1
- package/dist/model/units/currency.js +10 -2
- package/dist/model/units/currency.js.map +1 -1
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +9 -2
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/formatterCache.d.ts +11 -0
- package/dist/model/units/formatterCache.d.ts.map +1 -0
- package/dist/model/units/formatterCache.js +104 -0
- package/dist/model/units/formatterCache.js.map +1 -0
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +9 -2
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/temperature.d.ts.map +1 -1
- package/dist/model/units/temperature.js +9 -1
- package/dist/model/units/temperature.js.map +1 -1
- package/dist/model/units/throughput.d.ts.map +1 -1
- package/dist/model/units/throughput.js +11 -2
- package/dist/model/units/throughput.js.map +1 -1
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +10 -2
- package/dist/model/units/time.js.map +1 -1
- package/dist/schema/panel.d.ts.map +1 -1
- package/dist/schema/panel.js +1 -0
- package/dist/schema/panel.js.map +1 -1
- package/package.json +1 -1
|
@@ -34,6 +34,7 @@ _export(exports, {
|
|
|
34
34
|
const _numbro = /*#__PURE__*/ _interop_require_default(require("numbro"));
|
|
35
35
|
const _constants = require("./constants");
|
|
36
36
|
const _utils = require("./utils");
|
|
37
|
+
const _formatterCache = require("./formatterCache");
|
|
37
38
|
function _interop_require_default(obj) {
|
|
38
39
|
return obj && obj.__esModule ? obj : {
|
|
39
40
|
default: obj
|
|
@@ -85,8 +86,15 @@ function formatBits(bits, { unit = 'bits', shortValues, decimalPlaces }) {
|
|
|
85
86
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
|
-
const
|
|
89
|
-
|
|
89
|
+
const key = [
|
|
90
|
+
formatterOptions.style,
|
|
91
|
+
formatterOptions.useGrouping,
|
|
92
|
+
formatterOptions.maximumSignificantDigits,
|
|
93
|
+
decimalPlaces,
|
|
94
|
+
shortValues,
|
|
95
|
+
unit
|
|
96
|
+
];
|
|
97
|
+
return `${(0, _formatterCache.getFormatterFromCache)(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;
|
|
90
98
|
}
|
|
91
99
|
// If we're showing the shorten value, we use numbro.
|
|
92
100
|
// numbro is able to add units like Kb, Mb, Gb, etc. correctly.
|
|
@@ -34,6 +34,7 @@ _export(exports, {
|
|
|
34
34
|
const _numbro = /*#__PURE__*/ _interop_require_default(require("numbro"));
|
|
35
35
|
const _constants = require("./constants");
|
|
36
36
|
const _utils = require("./utils");
|
|
37
|
+
const _formatterCache = require("./formatterCache");
|
|
37
38
|
function _interop_require_default(obj) {
|
|
38
39
|
return obj && obj.__esModule ? obj : {
|
|
39
40
|
default: obj
|
|
@@ -87,8 +88,17 @@ function formatBytes(bytes, { unit = 'bytes', shortValues, decimalPlaces }) {
|
|
|
87
88
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
const
|
|
91
|
-
|
|
91
|
+
const key = [
|
|
92
|
+
formatterOptions.style,
|
|
93
|
+
formatterOptions.unit,
|
|
94
|
+
formatterOptions.unitDisplay,
|
|
95
|
+
formatterOptions.useGrouping,
|
|
96
|
+
formatterOptions.maximumSignificantDigits,
|
|
97
|
+
decimalPlaces,
|
|
98
|
+
shortValues,
|
|
99
|
+
unit
|
|
100
|
+
];
|
|
101
|
+
return (0, _formatterCache.getFormatterFromCache)(key, 'bytes', formatterOptions, 'en-US')(bytes);
|
|
92
102
|
}
|
|
93
103
|
// If we're showing the shorten value, we use numbro.
|
|
94
104
|
// numbro is able to add units like KB, MB, GB, etc. correctly.
|
|
@@ -34,6 +34,7 @@ _export(exports, {
|
|
|
34
34
|
const _lodash = require("lodash");
|
|
35
35
|
const _constants = require("./constants");
|
|
36
36
|
const _utils = require("./utils");
|
|
37
|
+
const _formatterCache = require("./formatterCache");
|
|
37
38
|
const CURRENCY_GROUP = 'Currency';
|
|
38
39
|
const CURRENCY_GROUP_CONFIG = {
|
|
39
40
|
label: 'Currency',
|
|
@@ -113,6 +114,13 @@ function formatCurrency(value, { unit, decimalPlaces }) {
|
|
|
113
114
|
} else {
|
|
114
115
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
115
116
|
}
|
|
116
|
-
const
|
|
117
|
-
|
|
117
|
+
const key = [
|
|
118
|
+
formatterOptions.style,
|
|
119
|
+
formatterOptions.currency,
|
|
120
|
+
formatterOptions.currencyDisplay,
|
|
121
|
+
formatterOptions.maximumSignificantDigits,
|
|
122
|
+
decimalPlaces,
|
|
123
|
+
unit
|
|
124
|
+
];
|
|
125
|
+
return (0, _formatterCache.getFormatterFromCache)(key, 'currency', formatterOptions, 'en-US')(value);
|
|
118
126
|
}
|
|
@@ -32,6 +32,7 @@ _export(exports, {
|
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
const _constants = require("./constants");
|
|
35
|
+
const _formatterCache = require("./formatterCache");
|
|
35
36
|
const _utils = require("./utils");
|
|
36
37
|
const DECIMAL_GROUP_CONFIG = {
|
|
37
38
|
label: 'Decimal',
|
|
@@ -60,6 +61,12 @@ function formatDecimal(value, { shortValues, decimalPlaces }) {
|
|
|
60
61
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
|
-
const
|
|
64
|
-
|
|
64
|
+
const key = [
|
|
65
|
+
formatterOptions.style,
|
|
66
|
+
formatterOptions.useGrouping,
|
|
67
|
+
formatterOptions.notation,
|
|
68
|
+
formatterOptions.maximumSignificantDigits,
|
|
69
|
+
decimalPlaces
|
|
70
|
+
];
|
|
71
|
+
return (0, _formatterCache.getFormatterFromCache)(key, 'decimal', formatterOptions, 'en-US')(value);
|
|
65
72
|
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Copyright 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
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
getFormatterFromCache: function() {
|
|
25
|
+
return getFormatterFromCache;
|
|
26
|
+
},
|
|
27
|
+
getFormatterStats: function() {
|
|
28
|
+
return getFormatterStats;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* REASONING FOR CLUSTERING (Map-of-Maps):
|
|
33
|
+
*
|
|
34
|
+
* 1. PERSISTENCE & REUSE: Intl.NumberFormat instantiation is CPU-heavy due to
|
|
35
|
+
* locale/data lookups. Clustering allows 100x faster reuse via caching.
|
|
36
|
+
*
|
|
37
|
+
*
|
|
38
|
+
* 2. LOOKUP PERFORMANCE: Smaller, specialized Maps reduce the risk of hash
|
|
39
|
+
* collisions, ensuring O(1) retrieval time remains consistent even as
|
|
40
|
+
* the total number of formatters across the app grows.
|
|
41
|
+
*
|
|
42
|
+
* 3. GARBAGE COLLECTION & STATS: Categorization allows for targeted memory
|
|
43
|
+
* monitoring and easier debugging of which specific data types are
|
|
44
|
+
* consuming the most resources.
|
|
45
|
+
*/ const TIME_FORMATTER_CACHE = new Map();
|
|
46
|
+
const DECIMAL_FORMATTER_CACHE = new Map();
|
|
47
|
+
const BITS_FORMATTER_CACHE = new Map();
|
|
48
|
+
const BYTES_FORMATTER_CACHE = new Map();
|
|
49
|
+
const CURRENCY_FORMATTER_CACHE = new Map();
|
|
50
|
+
const PERCENT_FORMATTER_CACHE = new Map();
|
|
51
|
+
const TEMPERATURE_FORMATTER_CACHE = new Map();
|
|
52
|
+
const THROUGHPUT_FORMATTER_CACHE = new Map();
|
|
53
|
+
const ALL_FORMATTERS = new Map([
|
|
54
|
+
[
|
|
55
|
+
'time',
|
|
56
|
+
TIME_FORMATTER_CACHE
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
'decimal',
|
|
60
|
+
DECIMAL_FORMATTER_CACHE
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
'bits',
|
|
64
|
+
BITS_FORMATTER_CACHE
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
'bytes',
|
|
68
|
+
BYTES_FORMATTER_CACHE
|
|
69
|
+
],
|
|
70
|
+
[
|
|
71
|
+
'currency',
|
|
72
|
+
CURRENCY_FORMATTER_CACHE
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
'percent',
|
|
76
|
+
PERCENT_FORMATTER_CACHE
|
|
77
|
+
],
|
|
78
|
+
[
|
|
79
|
+
'temperature',
|
|
80
|
+
TEMPERATURE_FORMATTER_CACHE
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
'throughput',
|
|
84
|
+
THROUGHPUT_FORMATTER_CACHE
|
|
85
|
+
]
|
|
86
|
+
]);
|
|
87
|
+
function getFormatterFromCache(key, inputType, formatterOptions, locals = 'en-US') {
|
|
88
|
+
const compoundKey = `${key.filter((k)=>![
|
|
89
|
+
undefined,
|
|
90
|
+
null,
|
|
91
|
+
'',
|
|
92
|
+
NaN
|
|
93
|
+
].includes(k)).join('|')}|${locals}`;
|
|
94
|
+
const inputTypeFormatters = ALL_FORMATTERS.get(inputType);
|
|
95
|
+
if (!inputTypeFormatters) throw new Error('No formatter found for the input type');
|
|
96
|
+
const formatter = inputTypeFormatters.get(compoundKey);
|
|
97
|
+
if (formatter) {
|
|
98
|
+
return formatter.format;
|
|
99
|
+
}
|
|
100
|
+
const newFormatter = Intl.NumberFormat(locals, formatterOptions);
|
|
101
|
+
inputTypeFormatters?.set(`${compoundKey}`, newFormatter);
|
|
102
|
+
return newFormatter.format;
|
|
103
|
+
}
|
|
104
|
+
const getFormatterStats = ()=>{
|
|
105
|
+
const countCacheItems = (inputType)=>{
|
|
106
|
+
if (inputType !== 'all') {
|
|
107
|
+
return ALL_FORMATTERS.get(inputType)?.size ?? 0;
|
|
108
|
+
}
|
|
109
|
+
return Array.from(ALL_FORMATTERS.values()).reduce((acc, map)=>acc + (map?.size ?? 0), 0);
|
|
110
|
+
};
|
|
111
|
+
const getKeys = (inputType)=>{
|
|
112
|
+
return [
|
|
113
|
+
...ALL_FORMATTERS.get(inputType)?.keys() || []
|
|
114
|
+
];
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
countCacheItems,
|
|
118
|
+
getKeys
|
|
119
|
+
};
|
|
120
|
+
};
|
|
@@ -32,6 +32,7 @@ _export(exports, {
|
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
const _constants = require("./constants");
|
|
35
|
+
const _formatterCache = require("./formatterCache");
|
|
35
36
|
const _utils = require("./utils");
|
|
36
37
|
const PERCENT_GROUP_CONFIG = {
|
|
37
38
|
label: 'percent',
|
|
@@ -70,6 +71,12 @@ function formatPercent(value, { unit, decimalPlaces }) {
|
|
|
70
71
|
if (unit === 'percent') {
|
|
71
72
|
value = value / 100;
|
|
72
73
|
}
|
|
73
|
-
const
|
|
74
|
-
|
|
74
|
+
const key = [
|
|
75
|
+
formatterOptions.style,
|
|
76
|
+
formatterOptions.useGrouping,
|
|
77
|
+
formatterOptions.maximumSignificantDigits,
|
|
78
|
+
decimalPlaces,
|
|
79
|
+
unit
|
|
80
|
+
];
|
|
81
|
+
return (0, _formatterCache.getFormatterFromCache)(key, 'percent', formatterOptions, 'en-US')(value);
|
|
75
82
|
}
|
|
@@ -32,6 +32,7 @@ _export(exports, {
|
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
const _constants = require("./constants");
|
|
35
|
+
const _formatterCache = require("./formatterCache");
|
|
35
36
|
const _utils = require("./utils");
|
|
36
37
|
const TEMPERATURE_GROUP = 'Temperature';
|
|
37
38
|
const TEMPERATURE_GROUP_CONFIG = {
|
|
@@ -60,5 +61,12 @@ const formatTemperature = (value, { unit, decimalPlaces })=>{
|
|
|
60
61
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
61
62
|
}
|
|
62
63
|
const locals = unit === 'celsius' ? 'en-GB' : 'en-US';
|
|
63
|
-
|
|
64
|
+
const key = [
|
|
65
|
+
formatterOptions.style,
|
|
66
|
+
formatterOptions.unit,
|
|
67
|
+
formatterOptions.maximumSignificantDigits,
|
|
68
|
+
decimalPlaces,
|
|
69
|
+
locals
|
|
70
|
+
];
|
|
71
|
+
return (0, _formatterCache.getFormatterFromCache)(key, 'temperature', formatterOptions, locals)(value);
|
|
64
72
|
};
|
|
@@ -35,6 +35,7 @@ const _bytes = require("./bytes");
|
|
|
35
35
|
const _bits = require("./bits");
|
|
36
36
|
const _constants = require("./constants");
|
|
37
37
|
const _utils = require("./utils");
|
|
38
|
+
const _formatterCache = require("./formatterCache");
|
|
38
39
|
const THROUGHPUT_GROUP_CONFIG = {
|
|
39
40
|
label: 'Throughput',
|
|
40
41
|
decimalPlaces: true
|
|
@@ -147,6 +148,14 @@ function formatThroughput(value, { unit, shortValues, decimalPlaces }) {
|
|
|
147
148
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
|
-
const
|
|
151
|
-
|
|
151
|
+
const key = [
|
|
152
|
+
formatterOptions.style,
|
|
153
|
+
formatterOptions.useGrouping,
|
|
154
|
+
formatterOptions.notation,
|
|
155
|
+
formatterOptions.maximumSignificantDigits,
|
|
156
|
+
decimalPlaces,
|
|
157
|
+
shortValues,
|
|
158
|
+
unit
|
|
159
|
+
];
|
|
160
|
+
return `${(0, _formatterCache.getFormatterFromCache)(key, 'throughput', formatterOptions, 'en-US')(value)} ${unit}`;
|
|
152
161
|
}
|
|
@@ -35,6 +35,7 @@ _export(exports, {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
const _constants = require("./constants");
|
|
38
|
+
const _formatterCache = require("./formatterCache");
|
|
38
39
|
const _utils = require("./utils");
|
|
39
40
|
const TIME_GROUP = 'Time';
|
|
40
41
|
const TIME_GROUP_CONFIG = {
|
|
@@ -165,6 +166,13 @@ function formatTime(value, { unit, decimalPlaces }) {
|
|
|
165
166
|
} else {
|
|
166
167
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
167
168
|
}
|
|
168
|
-
const
|
|
169
|
-
|
|
169
|
+
const key = [
|
|
170
|
+
formatterOptions.style,
|
|
171
|
+
formatterOptions.unit,
|
|
172
|
+
formatterOptions.unitDisplay,
|
|
173
|
+
formatterOptions.maximumSignificantDigits,
|
|
174
|
+
decimalPlaces,
|
|
175
|
+
unit ?? 'seconds'
|
|
176
|
+
];
|
|
177
|
+
return (0, _formatterCache.getFormatterFromCache)(key, 'time', formatterOptions, 'en-US')(results.value);
|
|
170
178
|
}
|
package/dist/cjs/schema/panel.js
CHANGED
package/dist/model/query.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/model/query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,UAAU,SAAS,CAAC,UAAU;IAC5B,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AACD;;GAEG;AAGH,MAAM,WAAW,eAAe,CAAC,IAAI,GAAG,GAAG,EAAE,UAAU,GAAG,WAAW;IACnE,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,eAAe,EAAE,cAAc,CAAC;IAChC,UAAU,EAAE,SAAS,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;IAC1B,QAAQ,EAAE,OAAO,CAAC;CAGnB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAE5E;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,SAAS,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/model/query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,UAAU,SAAS,CAAC,UAAU;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC;CAChC;AACD;;GAEG;AAGH,MAAM,WAAW,eAAe,CAAC,IAAI,GAAG,GAAG,EAAE,UAAU,GAAG,WAAW;IACnE,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,eAAe,EAAE,cAAc,CAAC;IAChC,UAAU,EAAE,SAAS,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;IAC1B,QAAQ,EAAE,OAAO,CAAC;CAGnB;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAE5E;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,CAAC,MAAM,SAAS,CAAC,CAAC"}
|
package/dist/model/query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/query.ts"],"sourcesContent":["// Copyright 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 { Definition, UnknownSpec } from './definitions';\nimport { TimeSeriesData } from './time-series-data';\nimport { TraceData } from './trace-data';\nimport { ProfileData } from './profile-data';\nimport { LogData } from './log-data';\n\ninterface QuerySpec<PluginSpec> {\n plugin: Definition<PluginSpec>;\n}\n/**\n * A generic query definition interface that can be extended to support more than just TimeSeriesQuery\n */\n// Kind needs to be `any` because otherwise typescript will complain 'unknown' is not assignable to type '\"TimeSeriesQuery\"' in a few places\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface QueryDefinition<Kind = any, PluginSpec = UnknownSpec> {\n kind: Kind;\n spec: QuerySpec<PluginSpec>;\n}\n\n/**\n * Mapping the query plugin to the data type it returns\n */\nexport interface QueryType {\n TimeSeriesQuery: TimeSeriesData;\n TraceQuery: TraceData;\n ProfileQuery: ProfileData;\n LogQuery: LogData;\n // in the future we can add other query plugin and data types\n // for example: we can add something like `LogsQuery: LogsData;`\n}\n\n/**\n * Check if the given type is a valid {@link QueryPluginType} with compile time safety\n * @param type\n */\nexport function isValidQueryPluginType(type: string): type is QueryPluginType {\n return ['TimeSeriesQuery', 'TraceQuery', 'ProfileQuery'].includes(type as QueryPluginType);\n}\n\n/**\n * Extract the keys of QueryType\n * ex: 'TimeSeriesQuery'\n */\nexport type QueryPluginType = keyof QueryType;\n\n/**\n * Values of QueryType\n * ex: 'TimeSeriesData'\n */\nexport type QueryDataType = QueryType[keyof QueryType];\n"],"names":["isValidQueryPluginType","type","includes"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;
|
|
1
|
+
{"version":3,"sources":["../../src/model/query.ts"],"sourcesContent":["// Copyright 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 { Definition, UnknownSpec } from './definitions';\nimport { TimeSeriesData } from './time-series-data';\nimport { TraceData } from './trace-data';\nimport { ProfileData } from './profile-data';\nimport { LogData } from './log-data';\n\ninterface QuerySpec<PluginSpec> {\n name?: string;\n plugin: Definition<PluginSpec>;\n}\n/**\n * A generic query definition interface that can be extended to support more than just TimeSeriesQuery\n */\n// Kind needs to be `any` because otherwise typescript will complain 'unknown' is not assignable to type '\"TimeSeriesQuery\"' in a few places\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface QueryDefinition<Kind = any, PluginSpec = UnknownSpec> {\n kind: Kind;\n spec: QuerySpec<PluginSpec>;\n}\n\n/**\n * Mapping the query plugin to the data type it returns\n */\nexport interface QueryType {\n TimeSeriesQuery: TimeSeriesData;\n TraceQuery: TraceData;\n ProfileQuery: ProfileData;\n LogQuery: LogData;\n // in the future we can add other query plugin and data types\n // for example: we can add something like `LogsQuery: LogsData;`\n}\n\n/**\n * Check if the given type is a valid {@link QueryPluginType} with compile time safety\n * @param type\n */\nexport function isValidQueryPluginType(type: string): type is QueryPluginType {\n return ['TimeSeriesQuery', 'TraceQuery', 'ProfileQuery'].includes(type as QueryPluginType);\n}\n\n/**\n * Extract the keys of QueryType\n * ex: 'TimeSeriesQuery'\n */\nexport type QueryPluginType = keyof QueryType;\n\n/**\n * Values of QueryType\n * ex: 'TimeSeriesData'\n */\nexport type QueryDataType = QueryType[keyof QueryType];\n"],"names":["isValidQueryPluginType","type","includes"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAkCjC;;;CAGC,GACD,OAAO,SAASA,uBAAuBC,IAAY;IACjD,OAAO;QAAC;QAAmB;QAAc;KAAe,CAACC,QAAQ,CAACD;AACpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bits.d.ts","sourceRoot":"","sources":["../../../src/model/units/bits.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"bits.d.ts","sourceRoot":"","sources":["../../../src/model/units/bits.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoBtD,KAAK,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAI/B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,CASnE,CAAC;AAEF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAa,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,iBAAiB,GAAG,MAAM,CA4DjH"}
|
package/dist/model/units/bits.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import numbro from 'numbro';
|
|
14
14
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
15
|
import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
|
|
16
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
16
17
|
/**
|
|
17
18
|
* We support both SI (decimal) and IEC (binary) units for bits:
|
|
18
19
|
*
|
|
@@ -59,8 +60,15 @@ export function formatBits(bits, { unit = 'bits', shortValues, decimalPlaces })
|
|
|
59
60
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
const
|
|
63
|
-
|
|
63
|
+
const key = [
|
|
64
|
+
formatterOptions.style,
|
|
65
|
+
formatterOptions.useGrouping,
|
|
66
|
+
formatterOptions.maximumSignificantDigits,
|
|
67
|
+
decimalPlaces,
|
|
68
|
+
shortValues,
|
|
69
|
+
unit
|
|
70
|
+
];
|
|
71
|
+
return `${getFormatterFromCache(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;
|
|
64
72
|
}
|
|
65
73
|
// If we're showing the shorten value, we use numbro.
|
|
66
74
|
// numbro is able to add units like Kb, Mb, Gb, etc. correctly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/bits.ts"],"sourcesContent":["// Copyright 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 numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bits:\n *\n * SI/decimal (unit: 'decbits'):\n * 1 Kb = 1000 bits (1000^1 bits)\n * 1 Mb = 1,000,000 bits (1000^2 bits)\n * etc.\n *\n * IEC/binary (unit: 'bits'):\n * 1 Kib = 1024 bits (1024^1 bits)\n * 1 Mib = 1,048,576 bits (1024^2 bits)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BitsUnit = 'bits' | 'decbits';\n\nexport type BitsFormatOptions = {\n unit?: BitsUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\n\nexport const BITS_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bits',\n decimalPlaces: true,\n shortValues: true,\n};\n\nexport const BITS_UNIT_CONFIG: Readonly<Record<BitsUnit, UnitConfig>> = {\n bits: {\n group: 'Bits',\n label: 'Bits (IEC)',\n },\n decbits: {\n group: 'Bits',\n label: 'Bits (SI)',\n },\n};\n\nexport function formatBits(bits: number, { unit = 'bits', shortValues, decimalPlaces }: BitsFormatOptions): string {\n const isDecimal = unit === 'decbits';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bits) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bits is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/bits.ts"],"sourcesContent":["// Copyright 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 numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bits:\n *\n * SI/decimal (unit: 'decbits'):\n * 1 Kb = 1000 bits (1000^1 bits)\n * 1 Mb = 1,000,000 bits (1000^2 bits)\n * etc.\n *\n * IEC/binary (unit: 'bits'):\n * 1 Kib = 1024 bits (1024^1 bits)\n * 1 Mib = 1,048,576 bits (1024^2 bits)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BitsUnit = 'bits' | 'decbits';\n\nexport type BitsFormatOptions = {\n unit?: BitsUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\n\nexport const BITS_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bits',\n decimalPlaces: true,\n shortValues: true,\n};\n\nexport const BITS_UNIT_CONFIG: Readonly<Record<BitsUnit, UnitConfig>> = {\n bits: {\n group: 'Bits',\n label: 'Bits (IEC)',\n },\n decbits: {\n group: 'Bits',\n label: 'Bits (SI)',\n },\n};\n\nexport function formatBits(bits: number, { unit = 'bits', shortValues, decimalPlaces }: BitsFormatOptions): string {\n const isDecimal = unit === 'decbits';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bits) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bits is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n shortValues,\n unit,\n ];\n\n return `${getFormatterFromCache(key, 'bits', formatterOptions, 'en-US')(bits)} bits`;\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like Kb, Mb, Gb, etc. correctly.\n const formatted = numbro(bits).format({\n output: 'byte', // numbro uses 'byte' output for bit formatting\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n\n // Replace byte units with bit units\n return formatted\n .replace(/KB/g, 'Kb')\n .replace(/MB/g, 'Mb')\n .replace(/GB/g, 'Gb')\n .replace(/TB/g, 'Tb')\n .replace(/PB/g, 'Pb')\n .replace(/EB/g, 'Eb')\n .replace(/KiB/g, 'Kib')\n .replace(/MiB/g, 'Mib')\n .replace(/GiB/g, 'Gib')\n .replace(/TiB/g, 'Tib')\n .replace(/PiB/g, 'Pib')\n .replace(/EiB/g, 'Eib');\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","getFormatterFromCache","DEFAULT_NUMBRO_MANTISSA","BITS_GROUP_CONFIG","label","decimalPlaces","shortValues","BITS_UNIT_CONFIG","bits","group","decbits","formatBits","unit","isDecimal","threshold","Math","abs","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key","formatted","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa","replace"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AACpF,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAUhC,OAAO,MAAMC,oBAAqC;IAChDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AAEF,OAAO,MAAMC,mBAA2D;IACtEC,MAAM;QACJC,OAAO;QACPL,OAAO;IACT;IACAM,SAAS;QACPD,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,WAAWH,IAAY,EAAE,EAAEI,OAAO,MAAM,EAAEN,WAAW,EAAED,aAAa,EAAqB;IACvG,MAAMQ,YAAYD,SAAS;IAC3B,MAAME,YAAYD,YAAY,OAAO;IAErC,mEAAmE;IACnE,IAAI,CAACb,oBAAoBM,gBAAgBS,KAAKC,GAAG,CAACR,QAAQM,WAAW;QACnE,MAAMG,mBAA6C;YACjDC,OAAO;YACPC,aAAa;QACf;QAEA,IAAIrB,iBAAiBO,gBAAgB;YACnCY,iBAAiBG,qBAAqB,GAAGrB,mBAAmBM;YAC5DY,iBAAiBI,qBAAqB,GAAGtB,mBAAmBM;QAC9D,OAAO;YACL,0FAA0F;YAC1F,IAAIL,oBAAoBM,cAAc;gBACpCW,iBAAiBK,wBAAwB,GAAGzB;YAC9C;QACF;QAEA,MAAM0B,MAAM;YACVN,iBAAiBC,KAAK;YACtBD,iBAAiBE,WAAW;YAC5BF,iBAAiBK,wBAAwB;YACzCjB;YACAC;YACAM;SACD;QAED,OAAO,GAAGX,sBAAsBsB,KAAK,QAAQN,kBAAkB,SAAST,MAAM,KAAK,CAAC;IACtF;IAEA,qDAAqD;IACrD,+DAA+D;IAC/D,MAAMgB,YAAY5B,OAAOY,MAAMiB,MAAM,CAAC;QACpCC,QAAQ;QACRC,MAAMd,YAAY,YAAY;QAC9Be,gBAAgB;QAChBC,UAAU/B,iBAAiBO,iBAAiBA,gBAAgBH;QAC5D,iCAAiC;QACjC4B,cAAc,CAAChC,iBAAiBO;QAChC,wEAAwE;QACxE0B,kBAAkB,CAACjC,iBAAiBO;IACtC;IAEA,oCAAoC;IACpC,OAAOmB,UACJQ,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,OAAO,MACfA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ,OAChBA,OAAO,CAAC,QAAQ;AACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoBtD,KAAK,SAAS,GAAG,OAAO,GAAG,UAAU,CAAC;AAEtC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CASrE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAc,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAiDrH"}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import numbro from 'numbro';
|
|
14
14
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
15
|
import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
|
|
16
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
16
17
|
/**
|
|
17
18
|
* We support both SI (decimal) and IEC (binary) units for bytes:
|
|
18
19
|
*
|
|
@@ -61,8 +62,17 @@ export function formatBytes(bytes, { unit = 'bytes', shortValues, decimalPlaces
|
|
|
61
62
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
|
-
const
|
|
65
|
-
|
|
65
|
+
const key = [
|
|
66
|
+
formatterOptions.style,
|
|
67
|
+
formatterOptions.unit,
|
|
68
|
+
formatterOptions.unitDisplay,
|
|
69
|
+
formatterOptions.useGrouping,
|
|
70
|
+
formatterOptions.maximumSignificantDigits,
|
|
71
|
+
decimalPlaces,
|
|
72
|
+
shortValues,
|
|
73
|
+
unit
|
|
74
|
+
];
|
|
75
|
+
return getFormatterFromCache(key, 'bytes', formatterOptions, 'en-US')(bytes);
|
|
66
76
|
}
|
|
67
77
|
// If we're showing the shorten value, we use numbro.
|
|
68
78
|
// numbro is able to add units like KB, MB, GB, etc. correctly.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 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 numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bytes:\n *\n * SI/decimal (unit: 'decbytes'):\n * 1 KB = 1000 bytes (1000^1 bytes)\n * 1 MB = 1,000,000 bytes (1000^2 bytes)\n * etc.\n *\n * IEC/binary (unit: 'bytes'):\n * 1 KiB = 1024 bytes (1024^1 bytes)\n * 1 MiB = 1,048,576 bytes (1024^2 bytes)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BytesUnit = 'bytes' | 'decbytes';\n\nexport type BytesFormatOptions = {\n unit?: BytesUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>> = {\n bytes: {\n group: 'Bytes',\n label: 'Bytes (IEC)',\n },\n decbytes: {\n group: 'Bytes',\n label: 'Bytes (SI)',\n },\n};\n\nexport function formatBytes(bytes: number, { unit = 'bytes', shortValues, decimalPlaces }: BytesFormatOptions): string {\n const isDecimal = unit === 'decbytes';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bytes) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 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 numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n/**\n * We support both SI (decimal) and IEC (binary) units for bytes:\n *\n * SI/decimal (unit: 'decbytes'):\n * 1 KB = 1000 bytes (1000^1 bytes)\n * 1 MB = 1,000,000 bytes (1000^2 bytes)\n * etc.\n *\n * IEC/binary (unit: 'bytes'):\n * 1 KiB = 1024 bytes (1024^1 bytes)\n * 1 MiB = 1,048,576 bytes (1024^2 bytes)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\ntype BytesUnit = 'bytes' | 'decbytes';\n\nexport type BytesFormatOptions = {\n unit?: BytesUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>> = {\n bytes: {\n group: 'Bytes',\n label: 'Bytes (IEC)',\n },\n decbytes: {\n group: 'Bytes',\n label: 'Bytes (SI)',\n },\n};\n\nexport function formatBytes(bytes: number, { unit = 'bytes', shortValues, decimalPlaces }: BytesFormatOptions): string {\n const isDecimal = unit === 'decbytes';\n const threshold = isDecimal ? 1000 : 1024;\n\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bytes) < threshold) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bytes is between -threshold and threshold (1000 for SI, 1024 for IEC)\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.unit,\n formatterOptions.unitDisplay,\n formatterOptions.useGrouping,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n shortValues,\n unit,\n ];\n\n return getFormatterFromCache(key, 'bytes', formatterOptions, 'en-US')(bytes);\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like KB, MB, GB, etc. correctly.\n return numbro(bytes).format({\n output: 'byte',\n base: isDecimal ? 'decimal' : 'binary',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","getFormatterFromCache","DEFAULT_NUMBRO_MANTISSA","BYTES_GROUP_CONFIG","label","decimalPlaces","shortValues","BYTES_UNIT_CONFIG","bytes","group","decbytes","formatBytes","unit","isDecimal","threshold","Math","abs","formatterOptions","style","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AACpF,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD;;;;;;;;;;;;CAYC,GAED,MAAMC,0BAA0B;AAShC,OAAO,MAAMC,qBAAsC;IACjDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,oBAA6D;IACxEC,OAAO;QACLC,OAAO;QACPL,OAAO;IACT;IACAM,UAAU;QACRD,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,YAAYH,KAAa,EAAE,EAAEI,OAAO,OAAO,EAAEN,WAAW,EAAED,aAAa,EAAsB;IAC3G,MAAMQ,YAAYD,SAAS;IAC3B,MAAME,YAAYD,YAAY,OAAO;IAErC,mEAAmE;IACnE,IAAI,CAACb,oBAAoBM,gBAAgBS,KAAKC,GAAG,CAACR,SAASM,WAAW;QACpE,MAAMG,mBAA6C;YACjDC,OAAO;YACPN,MAAM;YACNO,aAAa;YACbC,aAAa;QACf;QAEA,IAAItB,iBAAiBO,gBAAgB;YACnCY,iBAAiBI,qBAAqB,GAAGtB,mBAAmBM;YAC5DY,iBAAiBK,qBAAqB,GAAGvB,mBAAmBM;QAC9D,OAAO;YACL,2FAA2F;YAC3F,IAAIL,oBAAoBM,cAAc;gBACpCW,iBAAiBM,wBAAwB,GAAG1B;YAC9C;QACF;QAEA,MAAM2B,MAAM;YACVP,iBAAiBC,KAAK;YACtBD,iBAAiBL,IAAI;YACrBK,iBAAiBE,WAAW;YAC5BF,iBAAiBG,WAAW;YAC5BH,iBAAiBM,wBAAwB;YACzClB;YACAC;YACAM;SACD;QAED,OAAOX,sBAAsBuB,KAAK,SAASP,kBAAkB,SAAST;IACxE;IAEA,qDAAqD;IACrD,+DAA+D;IAC/D,OAAOZ,OAAOY,OAAOiB,MAAM,CAAC;QAC1BC,QAAQ;QACRC,MAAMd,YAAY,YAAY;QAC9Be,gBAAgB;QAChBC,UAAU/B,iBAAiBO,iBAAiBA,gBAAgBH;QAC5D,iCAAiC;QACjC4B,cAAc,CAAChC,iBAAiBO;QAChC,wEAAwE;QACxE0B,kBAAkB,CAACjC,iBAAiBO;IACtC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/model/units/currency.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/model/units/currency.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAMtD,KAAK,aAAa,GACd,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AACV,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAGF,eAAO,MAAM,qBAAqB,EAAE,eAGnC,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CA6D5E,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,qBAAqB,GAAG,MAAM,CAwBpG"}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { toUpper } from 'lodash';
|
|
14
14
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
15
|
import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
|
|
16
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
16
17
|
const CURRENCY_GROUP = 'Currency';
|
|
17
18
|
export const CURRENCY_GROUP_CONFIG = {
|
|
18
19
|
label: 'Currency',
|
|
@@ -92,8 +93,15 @@ export function formatCurrency(value, { unit, decimalPlaces }) {
|
|
|
92
93
|
} else {
|
|
93
94
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
94
95
|
}
|
|
95
|
-
const
|
|
96
|
-
|
|
96
|
+
const key = [
|
|
97
|
+
formatterOptions.style,
|
|
98
|
+
formatterOptions.currency,
|
|
99
|
+
formatterOptions.currencyDisplay,
|
|
100
|
+
formatterOptions.maximumSignificantDigits,
|
|
101
|
+
decimalPlaces,
|
|
102
|
+
unit
|
|
103
|
+
];
|
|
104
|
+
return getFormatterFromCache(key, 'currency', formatterOptions, 'en-US')(value);
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
//# sourceMappingURL=currency.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/currency.ts"],"sourcesContent":["// Copyright 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 { toUpper } from 'lodash';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitConfig, UnitGroupConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\n// See Intl.supportedValuesOf(\"currency\") for valid options, key names will\n// be converted to uppercase to match the expectation of Intl.NumberFormat\ntype CurrencyUnits =\n | 'aud'\n | 'cad'\n | 'chf'\n | 'cny'\n | 'eur'\n | 'gbp'\n | 'hkd'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'nok'\n | 'nzd'\n | 'sek'\n | 'sgd'\n | 'usd';\nexport type CurrencyFormatOptions = {\n unit: CurrencyUnits;\n decimalPlaces?: number;\n};\n\nconst CURRENCY_GROUP = 'Currency';\nexport const CURRENCY_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Currency',\n decimalPlaces: true,\n};\nexport const CURRENCY_UNIT_CONFIG: Readonly<Record<CurrencyUnits, UnitConfig>> = {\n aud: {\n group: CURRENCY_GROUP,\n label: 'Australian Dollar (A$)',\n },\n cad: {\n group: CURRENCY_GROUP,\n label: 'Canadian Dollar (CA$)',\n },\n chf: {\n group: CURRENCY_GROUP,\n label: 'Swiss Franc (CHF)',\n },\n cny: {\n group: CURRENCY_GROUP,\n label: 'Renminbi (CN¥)',\n },\n eur: {\n group: CURRENCY_GROUP,\n label: 'Euro (€)',\n },\n gbp: {\n group: CURRENCY_GROUP,\n label: 'Pound (£)',\n },\n hkd: {\n group: CURRENCY_GROUP,\n label: 'Hong Kong Dollar (HK$)',\n },\n inr: {\n group: CURRENCY_GROUP,\n label: 'Indian Rupee (₹)',\n },\n jpy: {\n group: CURRENCY_GROUP,\n label: 'Yen (¥)',\n },\n krw: {\n group: CURRENCY_GROUP,\n label: 'South Korean Won (₩)',\n },\n nok: {\n group: CURRENCY_GROUP,\n label: 'Norwegian Krone (NOK)',\n },\n nzd: {\n group: CURRENCY_GROUP,\n label: 'New Zealand Dollar (NZ$)',\n },\n sek: {\n group: CURRENCY_GROUP,\n label: 'Swedish Krona (SEK)',\n },\n sgd: {\n group: CURRENCY_GROUP,\n label: 'Singapore Dollar (S$)',\n },\n usd: {\n group: CURRENCY_GROUP,\n label: 'US Dollar ($)',\n },\n};\n\nexport function formatCurrency(value: number, { unit, decimalPlaces }: CurrencyFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'currency',\n currency: toUpper(unit),\n currencyDisplay: 'symbol',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/currency.ts"],"sourcesContent":["// Copyright 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 { toUpper } from 'lodash';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitConfig, UnitGroupConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\n// See Intl.supportedValuesOf(\"currency\") for valid options, key names will\n// be converted to uppercase to match the expectation of Intl.NumberFormat\ntype CurrencyUnits =\n | 'aud'\n | 'cad'\n | 'chf'\n | 'cny'\n | 'eur'\n | 'gbp'\n | 'hkd'\n | 'inr'\n | 'jpy'\n | 'krw'\n | 'nok'\n | 'nzd'\n | 'sek'\n | 'sgd'\n | 'usd';\nexport type CurrencyFormatOptions = {\n unit: CurrencyUnits;\n decimalPlaces?: number;\n};\n\nconst CURRENCY_GROUP = 'Currency';\nexport const CURRENCY_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Currency',\n decimalPlaces: true,\n};\nexport const CURRENCY_UNIT_CONFIG: Readonly<Record<CurrencyUnits, UnitConfig>> = {\n aud: {\n group: CURRENCY_GROUP,\n label: 'Australian Dollar (A$)',\n },\n cad: {\n group: CURRENCY_GROUP,\n label: 'Canadian Dollar (CA$)',\n },\n chf: {\n group: CURRENCY_GROUP,\n label: 'Swiss Franc (CHF)',\n },\n cny: {\n group: CURRENCY_GROUP,\n label: 'Renminbi (CN¥)',\n },\n eur: {\n group: CURRENCY_GROUP,\n label: 'Euro (€)',\n },\n gbp: {\n group: CURRENCY_GROUP,\n label: 'Pound (£)',\n },\n hkd: {\n group: CURRENCY_GROUP,\n label: 'Hong Kong Dollar (HK$)',\n },\n inr: {\n group: CURRENCY_GROUP,\n label: 'Indian Rupee (₹)',\n },\n jpy: {\n group: CURRENCY_GROUP,\n label: 'Yen (¥)',\n },\n krw: {\n group: CURRENCY_GROUP,\n label: 'South Korean Won (₩)',\n },\n nok: {\n group: CURRENCY_GROUP,\n label: 'Norwegian Krone (NOK)',\n },\n nzd: {\n group: CURRENCY_GROUP,\n label: 'New Zealand Dollar (NZ$)',\n },\n sek: {\n group: CURRENCY_GROUP,\n label: 'Swedish Krona (SEK)',\n },\n sgd: {\n group: CURRENCY_GROUP,\n label: 'Singapore Dollar (S$)',\n },\n usd: {\n group: CURRENCY_GROUP,\n label: 'US Dollar ($)',\n },\n};\n\nexport function formatCurrency(value: number, { unit, decimalPlaces }: CurrencyFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'currency',\n currency: toUpper(unit),\n currencyDisplay: 'symbol',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.currency,\n formatterOptions.currencyDisplay,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n unit,\n ];\n\n return getFormatterFromCache(key, 'currency', formatterOptions, 'en-US')(value);\n}\n"],"names":["toUpper","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","getFormatterFromCache","CURRENCY_GROUP","CURRENCY_GROUP_CONFIG","label","decimalPlaces","CURRENCY_UNIT_CONFIG","aud","group","cad","chf","cny","eur","gbp","hkd","inr","jpy","krw","nok","nzd","sek","sgd","usd","formatCurrency","value","unit","formatterOptions","style","currency","currencyDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,OAAO,QAAQ,SAAS;AACjC,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAC/D,SAASC,qBAAqB,QAAQ,mBAAmB;AAyBzD,MAAMC,iBAAiB;AACvB,OAAO,MAAMC,wBAAyC;IACpDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,OAAO,MAAMC,uBAAoE;IAC/EC,KAAK;QACHC,OAAON;QACPE,OAAO;IACT;IACAK,KAAK;QACHD,OAAON;QACPE,OAAO;IACT;IACAM,KAAK;QACHF,OAAON;QACPE,OAAO;IACT;IACAO,KAAK;QACHH,OAAON;QACPE,OAAO;IACT;IACAQ,KAAK;QACHJ,OAAON;QACPE,OAAO;IACT;IACAS,KAAK;QACHL,OAAON;QACPE,OAAO;IACT;IACAU,KAAK;QACHN,OAAON;QACPE,OAAO;IACT;IACAW,KAAK;QACHP,OAAON;QACPE,OAAO;IACT;IACAY,KAAK;QACHR,OAAON;QACPE,OAAO;IACT;IACAa,KAAK;QACHT,OAAON;QACPE,OAAO;IACT;IACAc,KAAK;QACHV,OAAON;QACPE,OAAO;IACT;IACAe,KAAK;QACHX,OAAON;QACPE,OAAO;IACT;IACAgB,KAAK;QACHZ,OAAON;QACPE,OAAO;IACT;IACAiB,KAAK;QACHb,OAAON;QACPE,OAAO;IACT;IACAkB,KAAK;QACHd,OAAON;QACPE,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASmB,eAAeC,KAAa,EAAE,EAAEC,IAAI,EAAEpB,aAAa,EAAyB;IAC1F,MAAMqB,mBAA6C;QACjDC,OAAO;QACPC,UAAU/B,QAAQ4B;QAClBI,iBAAiB;IACnB;IAEA,IAAI9B,iBAAiBM,gBAAgB;QACnCqB,iBAAiBI,qBAAqB,GAAG9B,mBAAmBK;QAC5DqB,iBAAiBK,qBAAqB,GAAG/B,mBAAmBK;IAC9D,OAAO;QACLqB,iBAAiBM,wBAAwB,GAAGlC;IAC9C;IAEA,MAAMmC,MAAM;QACVP,iBAAiBC,KAAK;QACtBD,iBAAiBE,QAAQ;QACzBF,iBAAiBG,eAAe;QAChCH,iBAAiBM,wBAAwB;QACzC3B;QACAoB;KACD;IAED,OAAOxB,sBAAsBgC,KAAK,YAAYP,kBAAkB,SAASF;AAC3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"
|
|
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;AAGtD,KAAK,WAAW,GAAG,SAAS,CAAC;AAC7B,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CA4BzG"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
14
15
|
import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
|
|
15
16
|
export const DECIMAL_GROUP_CONFIG = {
|
|
16
17
|
label: 'Decimal',
|
|
@@ -39,8 +40,14 @@ export function formatDecimal(value, { shortValues, decimalPlaces }) {
|
|
|
39
40
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
const
|
|
43
|
-
|
|
43
|
+
const key = [
|
|
44
|
+
formatterOptions.style,
|
|
45
|
+
formatterOptions.useGrouping,
|
|
46
|
+
formatterOptions.notation,
|
|
47
|
+
formatterOptions.maximumSignificantDigits,
|
|
48
|
+
decimalPlaces
|
|
49
|
+
];
|
|
50
|
+
return getFormatterFromCache(key, 'decimal', formatterOptions, 'en-US')(value);
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
//# sourceMappingURL=decimal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\ntype DecimalUnit = 'decimal';\nexport type DecimalFormatOptions = {\n unit?: DecimalUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>> = {\n decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { getFormatterFromCache } from './formatterCache';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\ntype DecimalUnit = 'decimal';\nexport type DecimalFormatOptions = {\n unit?: DecimalUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>> = {\n decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.notation,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n ];\n\n return getFormatterFromCache(key, 'decimal', formatterOptions, 'en-US')(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","getFormatterFromCache","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DECIMAL_GROUP_CONFIG","label","decimalPlaces","shortValues","DECIMAL_UNIT_CONFIG","decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,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,cAAc;AACrD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAQpF,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASM,cAAcC,KAAa,EAAE,EAAEL,WAAW,EAAED,aAAa,EAAwB;IAC/F,MAAMO,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIZ,oBAAoBI,cAAc;QACpCM,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAIf,iBAAiBK,gBAAgB;QACnCO,iBAAiBI,qBAAqB,GAAGf,mBAAmBI;QAC5DO,iBAAiBK,qBAAqB,GAAGhB,mBAAmBI;IAC9D,OAAO;QACL,IAAIH,oBAAoBI,cAAc;YACpCM,iBAAiBM,wBAAwB,GAAGpB;QAC9C;IACF;IAEA,MAAMqB,MAAM;QACVP,iBAAiBC,KAAK;QACtBD,iBAAiBE,WAAW;QAC5BF,iBAAiBG,QAAQ;QACzBH,iBAAiBM,wBAAwB;QACzCb;KACD;IAED,OAAON,sBAAsBoB,KAAK,WAAWP,kBAAkB,SAASD;AAC1E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type FormatFn = (value: number | bigint) => string;
|
|
2
|
+
type InputType = 'time' | 'temperature' | 'bytes' | 'bits' | 'decimal' | 'currency' | 'percent' | 'throughput';
|
|
3
|
+
type Locals = 'en-US' | 'en-GB';
|
|
4
|
+
export declare function getFormatterFromCache(key: Array<string | number | boolean | undefined>, inputType: InputType, formatterOptions: Intl.NumberFormatOptions, locals?: Locals): FormatFn;
|
|
5
|
+
export interface IFormatterStats {
|
|
6
|
+
countCacheItems: (inputType: InputType | 'all') => number;
|
|
7
|
+
getKeys: (inputType: InputType) => string[];
|
|
8
|
+
}
|
|
9
|
+
export declare const getFormatterStats: () => IFormatterStats;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=formatterCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatterCache.d.ts","sourceRoot":"","sources":["../../../src/model/units/formatterCache.ts"],"names":[],"mappings":"AAaA,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;AACnD,KAAK,SAAS,GAAG,MAAM,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,CAAC;AAC/G,KAAK,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAqChC,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,EACjD,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,IAAI,CAAC,mBAAmB,EAC1C,MAAM,GAAE,MAAgB,GACvB,QAAQ,CAcV;AAGD,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,KAAK,KAAK,MAAM,CAAC;IAC1D,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,MAAM,EAAE,CAAC;CAC7C;AAED,eAAO,MAAM,iBAAiB,QAAO,eAcpC,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Copyright 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
|
+
/**
|
|
14
|
+
* REASONING FOR CLUSTERING (Map-of-Maps):
|
|
15
|
+
*
|
|
16
|
+
* 1. PERSISTENCE & REUSE: Intl.NumberFormat instantiation is CPU-heavy due to
|
|
17
|
+
* locale/data lookups. Clustering allows 100x faster reuse via caching.
|
|
18
|
+
*
|
|
19
|
+
*
|
|
20
|
+
* 2. LOOKUP PERFORMANCE: Smaller, specialized Maps reduce the risk of hash
|
|
21
|
+
* collisions, ensuring O(1) retrieval time remains consistent even as
|
|
22
|
+
* the total number of formatters across the app grows.
|
|
23
|
+
*
|
|
24
|
+
* 3. GARBAGE COLLECTION & STATS: Categorization allows for targeted memory
|
|
25
|
+
* monitoring and easier debugging of which specific data types are
|
|
26
|
+
* consuming the most resources.
|
|
27
|
+
*/ const TIME_FORMATTER_CACHE = new Map();
|
|
28
|
+
const DECIMAL_FORMATTER_CACHE = new Map();
|
|
29
|
+
const BITS_FORMATTER_CACHE = new Map();
|
|
30
|
+
const BYTES_FORMATTER_CACHE = new Map();
|
|
31
|
+
const CURRENCY_FORMATTER_CACHE = new Map();
|
|
32
|
+
const PERCENT_FORMATTER_CACHE = new Map();
|
|
33
|
+
const TEMPERATURE_FORMATTER_CACHE = new Map();
|
|
34
|
+
const THROUGHPUT_FORMATTER_CACHE = new Map();
|
|
35
|
+
const ALL_FORMATTERS = new Map([
|
|
36
|
+
[
|
|
37
|
+
'time',
|
|
38
|
+
TIME_FORMATTER_CACHE
|
|
39
|
+
],
|
|
40
|
+
[
|
|
41
|
+
'decimal',
|
|
42
|
+
DECIMAL_FORMATTER_CACHE
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
'bits',
|
|
46
|
+
BITS_FORMATTER_CACHE
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
'bytes',
|
|
50
|
+
BYTES_FORMATTER_CACHE
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
'currency',
|
|
54
|
+
CURRENCY_FORMATTER_CACHE
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
'percent',
|
|
58
|
+
PERCENT_FORMATTER_CACHE
|
|
59
|
+
],
|
|
60
|
+
[
|
|
61
|
+
'temperature',
|
|
62
|
+
TEMPERATURE_FORMATTER_CACHE
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
'throughput',
|
|
66
|
+
THROUGHPUT_FORMATTER_CACHE
|
|
67
|
+
]
|
|
68
|
+
]);
|
|
69
|
+
export function getFormatterFromCache(key, inputType, formatterOptions, locals = 'en-US') {
|
|
70
|
+
const compoundKey = `${key.filter((k)=>![
|
|
71
|
+
undefined,
|
|
72
|
+
null,
|
|
73
|
+
'',
|
|
74
|
+
NaN
|
|
75
|
+
].includes(k)).join('|')}|${locals}`;
|
|
76
|
+
const inputTypeFormatters = ALL_FORMATTERS.get(inputType);
|
|
77
|
+
if (!inputTypeFormatters) throw new Error('No formatter found for the input type');
|
|
78
|
+
const formatter = inputTypeFormatters.get(compoundKey);
|
|
79
|
+
if (formatter) {
|
|
80
|
+
return formatter.format;
|
|
81
|
+
}
|
|
82
|
+
const newFormatter = Intl.NumberFormat(locals, formatterOptions);
|
|
83
|
+
inputTypeFormatters?.set(`${compoundKey}`, newFormatter);
|
|
84
|
+
return newFormatter.format;
|
|
85
|
+
}
|
|
86
|
+
export const getFormatterStats = ()=>{
|
|
87
|
+
const countCacheItems = (inputType)=>{
|
|
88
|
+
if (inputType !== 'all') {
|
|
89
|
+
return ALL_FORMATTERS.get(inputType)?.size ?? 0;
|
|
90
|
+
}
|
|
91
|
+
return Array.from(ALL_FORMATTERS.values()).reduce((acc, map)=>acc + (map?.size ?? 0), 0);
|
|
92
|
+
};
|
|
93
|
+
const getKeys = (inputType)=>{
|
|
94
|
+
return [
|
|
95
|
+
...ALL_FORMATTERS.get(inputType)?.keys() || []
|
|
96
|
+
];
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
countCacheItems,
|
|
100
|
+
getKeys
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
//# sourceMappingURL=formatterCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/formatterCache.ts"],"sourcesContent":["// Copyright 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\ntype FormatFn = (value: number | bigint) => string;\ntype InputType = 'time' | 'temperature' | 'bytes' | 'bits' | 'decimal' | 'currency' | 'percent' | 'throughput';\ntype Locals = 'en-US' | 'en-GB';\n\n/**\n * REASONING FOR CLUSTERING (Map-of-Maps):\n *\n * 1. PERSISTENCE & REUSE: Intl.NumberFormat instantiation is CPU-heavy due to\n * locale/data lookups. Clustering allows 100x faster reuse via caching.\n *\n *\n * 2. LOOKUP PERFORMANCE: Smaller, specialized Maps reduce the risk of hash\n * collisions, ensuring O(1) retrieval time remains consistent even as\n * the total number of formatters across the app grows.\n *\n * 3. GARBAGE COLLECTION & STATS: Categorization allows for targeted memory\n * monitoring and easier debugging of which specific data types are\n * consuming the most resources.\n */\nconst TIME_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst DECIMAL_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst BITS_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst BYTES_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst CURRENCY_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst PERCENT_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst TEMPERATURE_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst THROUGHPUT_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\n\nconst ALL_FORMATTERS: Map<InputType, Map<string, Intl.NumberFormat>> = new Map([\n ['time', TIME_FORMATTER_CACHE],\n ['decimal', DECIMAL_FORMATTER_CACHE],\n ['bits', BITS_FORMATTER_CACHE],\n ['bytes', BYTES_FORMATTER_CACHE],\n ['currency', CURRENCY_FORMATTER_CACHE],\n ['percent', PERCENT_FORMATTER_CACHE],\n ['temperature', TEMPERATURE_FORMATTER_CACHE],\n ['throughput', THROUGHPUT_FORMATTER_CACHE],\n]);\n\nexport function getFormatterFromCache(\n key: Array<string | number | boolean | undefined>,\n inputType: InputType,\n formatterOptions: Intl.NumberFormatOptions,\n locals: Locals = 'en-US'\n): FormatFn {\n const compoundKey = `${key.filter((k) => !([undefined, null, '', NaN] as unknown[]).includes(k)).join('|')}|${locals}`;\n const inputTypeFormatters = ALL_FORMATTERS.get(inputType);\n if (!inputTypeFormatters) throw new Error('No formatter found for the input type');\n\n const formatter = inputTypeFormatters.get(compoundKey);\n if (formatter) {\n return formatter.format;\n }\n\n const newFormatter = Intl.NumberFormat(locals, formatterOptions);\n inputTypeFormatters?.set(`${compoundKey}`, newFormatter);\n\n return newFormatter.format;\n}\n\n/* This is a small utility for unit tests */\nexport interface IFormatterStats {\n countCacheItems: (inputType: InputType | 'all') => number;\n getKeys: (inputType: InputType) => string[];\n}\n\nexport const getFormatterStats = (): IFormatterStats => {\n const countCacheItems = (inputType: InputType | 'all'): number => {\n if (inputType !== 'all') {\n return ALL_FORMATTERS.get(inputType)?.size ?? 0;\n }\n\n return Array.from(ALL_FORMATTERS.values()).reduce((acc, map) => acc + (map?.size ?? 0), 0);\n };\n\n const getKeys = (inputType: InputType): string[] => {\n return [...(ALL_FORMATTERS.get(inputType)?.keys() || [])];\n };\n\n return { countCacheItems, getKeys };\n};\n"],"names":["TIME_FORMATTER_CACHE","Map","DECIMAL_FORMATTER_CACHE","BITS_FORMATTER_CACHE","BYTES_FORMATTER_CACHE","CURRENCY_FORMATTER_CACHE","PERCENT_FORMATTER_CACHE","TEMPERATURE_FORMATTER_CACHE","THROUGHPUT_FORMATTER_CACHE","ALL_FORMATTERS","getFormatterFromCache","key","inputType","formatterOptions","locals","compoundKey","filter","k","undefined","NaN","includes","join","inputTypeFormatters","get","Error","formatter","format","newFormatter","Intl","NumberFormat","set","getFormatterStats","countCacheItems","size","Array","from","values","reduce","acc","map","getKeys","keys"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAMjC;;;;;;;;;;;;;;CAcC,GACD,MAAMA,uBAAuB,IAAIC;AACjC,MAAMC,0BAA0B,IAAID;AACpC,MAAME,uBAAuB,IAAIF;AACjC,MAAMG,wBAAwB,IAAIH;AAClC,MAAMI,2BAA2B,IAAIJ;AACrC,MAAMK,0BAA0B,IAAIL;AACpC,MAAMM,8BAA8B,IAAIN;AACxC,MAAMO,6BAA6B,IAAIP;AAEvC,MAAMQ,iBAAiE,IAAIR,IAAI;IAC7E;QAAC;QAAQD;KAAqB;IAC9B;QAAC;QAAWE;KAAwB;IACpC;QAAC;QAAQC;KAAqB;IAC9B;QAAC;QAASC;KAAsB;IAChC;QAAC;QAAYC;KAAyB;IACtC;QAAC;QAAWC;KAAwB;IACpC;QAAC;QAAeC;KAA4B;IAC5C;QAAC;QAAcC;KAA2B;CAC3C;AAED,OAAO,SAASE,sBACdC,GAAiD,EACjDC,SAAoB,EACpBC,gBAA0C,EAC1CC,SAAiB,OAAO;IAExB,MAAMC,cAAc,GAAGJ,IAAIK,MAAM,CAAC,CAACC,IAAM,CAAC,AAAC;YAACC;YAAW;YAAM;YAAIC;SAAI,CAAeC,QAAQ,CAACH,IAAII,IAAI,CAAC,KAAK,CAAC,EAAEP,QAAQ;IACtH,MAAMQ,sBAAsBb,eAAec,GAAG,CAACX;IAC/C,IAAI,CAACU,qBAAqB,MAAM,IAAIE,MAAM;IAE1C,MAAMC,YAAYH,oBAAoBC,GAAG,CAACR;IAC1C,IAAIU,WAAW;QACb,OAAOA,UAAUC,MAAM;IACzB;IAEA,MAAMC,eAAeC,KAAKC,YAAY,CAACf,QAAQD;IAC/CS,qBAAqBQ,IAAI,GAAGf,aAAa,EAAEY;IAE3C,OAAOA,aAAaD,MAAM;AAC5B;AAQA,OAAO,MAAMK,oBAAoB;IAC/B,MAAMC,kBAAkB,CAACpB;QACvB,IAAIA,cAAc,OAAO;YACvB,OAAOH,eAAec,GAAG,CAACX,YAAYqB,QAAQ;QAChD;QAEA,OAAOC,MAAMC,IAAI,CAAC1B,eAAe2B,MAAM,IAAIC,MAAM,CAAC,CAACC,KAAKC,MAAQD,MAAOC,CAAAA,KAAKN,QAAQ,CAAA,GAAI;IAC1F;IAEA,MAAMO,UAAU,CAAC5B;QACf,OAAO;eAAKH,eAAec,GAAG,CAACX,YAAY6B,UAAU,EAAE;SAAE;IAC3D;IAEA,OAAO;QAAET;QAAiBQ;IAAQ;AACpC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,KAAK,WAAW,GAAG,SAAS,GAAG,iBAAiB,GAAG,GAAG,CAAC;AACvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAgBzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CA2BlG"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
14
15
|
import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
|
|
15
16
|
export const PERCENT_GROUP_CONFIG = {
|
|
16
17
|
label: 'percent',
|
|
@@ -49,8 +50,14 @@ export function formatPercent(value, { unit, decimalPlaces }) {
|
|
|
49
50
|
if (unit === 'percent') {
|
|
50
51
|
value = value / 100;
|
|
51
52
|
}
|
|
52
|
-
const
|
|
53
|
-
|
|
53
|
+
const key = [
|
|
54
|
+
formatterOptions.style,
|
|
55
|
+
formatterOptions.useGrouping,
|
|
56
|
+
formatterOptions.maximumSignificantDigits,
|
|
57
|
+
decimalPlaces,
|
|
58
|
+
unit
|
|
59
|
+
];
|
|
60
|
+
return getFormatterFromCache(key, 'percent', formatterOptions, 'en-US')(value);
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
//# sourceMappingURL=percent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\ntype PercentUnit = 'percent' | 'percent-decimal' | '%';\nexport type PercentFormatOptions = {\n unit?: PercentUnit;\n decimalPlaces?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'percent',\n decimalPlaces: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnit, UnitConfig>> = {\n percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n 'percent-decimal': {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nexport function formatPercent(value: number, { unit, decimalPlaces }: PercentFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.\n if (unit === 'percent') {\n value = value / 100;\n }\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { getFormatterFromCache } from './formatterCache';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\ntype PercentUnit = 'percent' | 'percent-decimal' | '%';\nexport type PercentFormatOptions = {\n unit?: PercentUnit;\n decimalPlaces?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'percent',\n decimalPlaces: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnit, UnitConfig>> = {\n percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n 'percent-decimal': {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nexport function formatPercent(value: number, { unit, decimalPlaces }: PercentFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.\n if (unit === 'percent') {\n value = value / 100;\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n unit,\n ];\n\n return getFormatterFromCache(key, 'percent', formatterOptions, 'en-US')(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","getFormatterFromCache","hasDecimalPlaces","limitDecimalPlaces","PERCENT_GROUP_CONFIG","label","decimalPlaces","PERCENT_GROUP","PERCENT_UNIT_CONFIG","percent","group","disableSelectorOption","formatPercent","value","unit","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,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,cAAc;AACrD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAO/D,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,MAAMC,gBAAgB;AACtB,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAOH;QACPF,OAAO;IACT;IACA,mBAAmB;QACjBK,OAAOH;QACPF,OAAO;IACT;IACA,KAAK;QACH,qEAAqE;QACrE,0BAA0B;QAC1BM,uBAAuB;QACvBD,OAAOH;QACPF,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,cAAcC,KAAa,EAAE,EAAEC,IAAI,EAAER,aAAa,EAAwB;IACxF,MAAMS,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIf,iBAAiBI,gBAAgB;QACnCS,iBAAiBG,qBAAqB,GAAGf,mBAAmBG;QAC5DS,iBAAiBI,qBAAqB,GAAGhB,mBAAmBG;IAC9D,OAAO;QACLS,iBAAiBK,wBAAwB,GAAGpB;IAC9C;IAEA,oEAAoE;IACpE,IAAIc,SAAS,WAAW;QACtBD,QAAQA,QAAQ;IAClB;IAEA,MAAMQ,MAAM;QACVN,iBAAiBC,KAAK;QACtBD,iBAAiBE,WAAW;QAC5BF,iBAAiBK,wBAAwB;QACzCd;QACAQ;KACD;IAED,OAAOb,sBAAsBoB,KAAK,WAAWN,kBAAkB,SAASF;AAC1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"temperature.d.ts","sourceRoot":"","sources":["../../../src/model/units/temperature.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"temperature.d.ts","sourceRoot":"","sources":["../../../src/model/units/temperature.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAKtD,KAAK,gBAAgB,GAAG,SAAS,GAAG,YAAY,CAAC;AAEjD,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,gBAAgB,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,eAGtC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,MAAM,CAAC,gBAAgB,EAAE,UAAU,CAAC,CASlF,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAAW,MAAM,2BAA2B,wBAAwB,KAAG,MAwBpG,CAAC"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
14
15
|
import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
|
|
15
16
|
const TEMPERATURE_GROUP = 'Temperature';
|
|
16
17
|
export const TEMPERATURE_GROUP_CONFIG = {
|
|
@@ -39,7 +40,14 @@ export const formatTemperature = (value, { unit, decimalPlaces })=>{
|
|
|
39
40
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
40
41
|
}
|
|
41
42
|
const locals = unit === 'celsius' ? 'en-GB' : 'en-US';
|
|
42
|
-
|
|
43
|
+
const key = [
|
|
44
|
+
formatterOptions.style,
|
|
45
|
+
formatterOptions.unit,
|
|
46
|
+
formatterOptions.maximumSignificantDigits,
|
|
47
|
+
decimalPlaces,
|
|
48
|
+
locals
|
|
49
|
+
];
|
|
50
|
+
return getFormatterFromCache(key, 'temperature', formatterOptions, locals)(value);
|
|
43
51
|
};
|
|
44
52
|
|
|
45
53
|
//# sourceMappingURL=temperature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/temperature.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitConfig, UnitGroupConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst TEMPERATURE_GROUP = 'Temperature';\n\ntype TemperatureUnits = 'celsius' | 'fahrenheit';\n\nexport type TemperatureFormatOptions = {\n unit: TemperatureUnits;\n decimalPlaces?: number;\n};\n\nexport const TEMPERATURE_GROUP_CONFIG: UnitGroupConfig = {\n label: TEMPERATURE_GROUP,\n decimalPlaces: true,\n};\n\nexport const TEMPERATURE_UNIT_CONFIG: Readonly<Record<TemperatureUnits, UnitConfig>> = {\n celsius: {\n group: TEMPERATURE_GROUP,\n label: 'Celsius (°C)',\n },\n fahrenheit: {\n group: TEMPERATURE_GROUP,\n label: 'Fahrenheit (°F)',\n },\n};\n\nexport const formatTemperature = (value: number, { unit, decimalPlaces }: TemperatureFormatOptions): string => {\n const formatterOptions: Intl.NumberFormatOptions = {\n unit,\n style: 'unit',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const locals = unit === 'celsius' ? 'en-GB' : 'en-US';\n return
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/temperature.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { getFormatterFromCache } from './formatterCache';\nimport { UnitConfig, UnitGroupConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst TEMPERATURE_GROUP = 'Temperature';\n\ntype TemperatureUnits = 'celsius' | 'fahrenheit';\n\nexport type TemperatureFormatOptions = {\n unit: TemperatureUnits;\n decimalPlaces?: number;\n};\n\nexport const TEMPERATURE_GROUP_CONFIG: UnitGroupConfig = {\n label: TEMPERATURE_GROUP,\n decimalPlaces: true,\n};\n\nexport const TEMPERATURE_UNIT_CONFIG: Readonly<Record<TemperatureUnits, UnitConfig>> = {\n celsius: {\n group: TEMPERATURE_GROUP,\n label: 'Celsius (°C)',\n },\n fahrenheit: {\n group: TEMPERATURE_GROUP,\n label: 'Fahrenheit (°F)',\n },\n};\n\nexport const formatTemperature = (value: number, { unit, decimalPlaces }: TemperatureFormatOptions): string => {\n const formatterOptions: Intl.NumberFormatOptions = {\n unit,\n style: 'unit',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const locals = unit === 'celsius' ? 'en-GB' : 'en-US';\n\n const key = [\n formatterOptions.style,\n formatterOptions.unit,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n locals,\n ];\n\n return getFormatterFromCache(key, 'temperature', formatterOptions, locals)(value);\n};\n"],"names":["MAX_SIGNIFICANT_DIGITS","getFormatterFromCache","hasDecimalPlaces","limitDecimalPlaces","TEMPERATURE_GROUP","TEMPERATURE_GROUP_CONFIG","label","decimalPlaces","TEMPERATURE_UNIT_CONFIG","celsius","group","fahrenheit","formatTemperature","value","unit","formatterOptions","style","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","locals","key"],"mappings":"AAAA,+BAA+B;AAC/B,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,cAAc;AACrD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAE/D,MAAMC,oBAAoB;AAS1B,OAAO,MAAMC,2BAA4C;IACvDC,OAAOF;IACPG,eAAe;AACjB,EAAE;AAEF,OAAO,MAAMC,0BAA0E;IACrFC,SAAS;QACPC,OAAON;QACPE,OAAO;IACT;IACAK,YAAY;QACVD,OAAON;QACPE,OAAO;IACT;AACF,EAAE;AAEF,OAAO,MAAMM,oBAAoB,CAACC,OAAe,EAAEC,IAAI,EAAEP,aAAa,EAA4B;IAChG,MAAMQ,mBAA6C;QACjDD;QACAE,OAAO;IACT;IAEA,IAAId,iBAAiBK,gBAAgB;QACnCQ,iBAAiBE,qBAAqB,GAAGd,mBAAmBI;QAC5DQ,iBAAiBG,qBAAqB,GAAGf,mBAAmBI;IAC9D,OAAO;QACLQ,iBAAiBI,wBAAwB,GAAGnB;IAC9C;IAEA,MAAMoB,SAASN,SAAS,YAAY,UAAU;IAE9C,MAAMO,MAAM;QACVN,iBAAiBC,KAAK;QACtBD,iBAAiBD,IAAI;QACrBC,iBAAiBI,wBAAwB;QACzCZ;QACAa;KACD;IAED,OAAOnB,sBAAsBoB,KAAK,eAAeN,kBAAkBK,QAAQP;AAC7E,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throughput.d.ts","sourceRoot":"","sources":["../../../src/model/units/throughput.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"throughput.d.ts","sourceRoot":"","sources":["../../../src/model/units/throughput.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAItD,KAAK,cAAc,GACf,UAAU,GACV,aAAa,GACb,WAAW,GACX,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,cAAc,GACd,SAAS,GACT,aAAa,GACb,WAAW,GACX,aAAa,GACb,cAAc,GACd,UAAU,GACV,YAAY,CAAC;AACjB,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,uBAAuB,EAAE,eAGrC,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CA0D/E,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,uBAAuB,GAAG,MAAM,CAmDrH"}
|
|
@@ -14,6 +14,7 @@ import { formatBytes } from './bytes';
|
|
|
14
14
|
import { formatBits } from './bits';
|
|
15
15
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
16
16
|
import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
|
|
17
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
17
18
|
export const THROUGHPUT_GROUP_CONFIG = {
|
|
18
19
|
label: 'Throughput',
|
|
19
20
|
decimalPlaces: true
|
|
@@ -126,8 +127,16 @@ export function formatThroughput(value, { unit, shortValues, decimalPlaces }) {
|
|
|
126
127
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
|
-
const
|
|
130
|
-
|
|
130
|
+
const key = [
|
|
131
|
+
formatterOptions.style,
|
|
132
|
+
formatterOptions.useGrouping,
|
|
133
|
+
formatterOptions.notation,
|
|
134
|
+
formatterOptions.maximumSignificantDigits,
|
|
135
|
+
decimalPlaces,
|
|
136
|
+
shortValues,
|
|
137
|
+
unit
|
|
138
|
+
];
|
|
139
|
+
return `${getFormatterFromCache(key, 'throughput', formatterOptions, 'en-US')(value)} ${unit}`;
|
|
131
140
|
}
|
|
132
141
|
|
|
133
142
|
//# sourceMappingURL=throughput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/throughput.ts"],"sourcesContent":["// Copyright 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 { formatBytes } from './bytes';\nimport { formatBits } from './bits';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\ntype ThroughputUnit =\n | 'bits/sec'\n | 'decbits/sec'\n | 'bytes/sec'\n | 'decbytes/sec'\n | 'counts/sec'\n | 'events/sec'\n | 'messages/sec'\n | 'ops/sec'\n | 'packets/sec'\n | 'reads/sec'\n | 'records/sec'\n | 'requests/sec'\n | 'rows/sec'\n | 'writes/sec';\nexport type ThroughputFormatOptions = {\n unit?: ThroughputUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const THROUGHPUT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Throughput',\n decimalPlaces: true,\n};\nconst THROUGHPUT_GROUP = 'Throughput';\nexport const THROUGHPUT_UNIT_CONFIG: Readonly<Record<ThroughputUnit, UnitConfig>> = {\n 'bits/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bits/sec (IEC)',\n },\n 'decbits/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bits/sec (SI)',\n },\n 'bytes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bytes/sec (IEC)',\n },\n 'decbytes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bytes/sec (SI)',\n },\n\n 'counts/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Counts/sec',\n },\n 'events/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Events/sec',\n },\n 'messages/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Messages/sec',\n },\n 'ops/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Ops/sec',\n },\n 'packets/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Packets/sec',\n },\n 'reads/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Reads/sec',\n },\n 'requests/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Requests/sec',\n },\n 'records/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Records/sec',\n },\n 'rows/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Rows/sec',\n },\n 'writes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Writes/sec',\n },\n};\n\nexport function formatThroughput(value: number, { unit, shortValues, decimalPlaces }: ThroughputFormatOptions): string {\n // special case for data throughput\n if (unit === 'bits/sec') {\n const denominator = Math.abs(value) < 1024 ? 'sec' : 's';\n return formatBits(value, { unit: 'bits', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n if (unit === 'decbits/sec') {\n const denominator = Math.abs(value) < 1000 ? 'sec' : 's';\n return formatBits(value, { unit: 'decbits', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n if (unit === 'decbytes/sec') {\n const denominator = Math.abs(value) < 1000 ? 'sec' : 's';\n return formatBytes(value, { unit: 'decbytes', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n if (unit === 'bytes/sec') {\n const denominator = Math.abs(value) < 1024 ? 'sec' : 's';\n return formatBytes(value, { unit: 'bytes', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/throughput.ts"],"sourcesContent":["// Copyright 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 { formatBytes } from './bytes';\nimport { formatBits } from './bits';\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\nimport { getFormatterFromCache } from './formatterCache';\n\ntype ThroughputUnit =\n | 'bits/sec'\n | 'decbits/sec'\n | 'bytes/sec'\n | 'decbytes/sec'\n | 'counts/sec'\n | 'events/sec'\n | 'messages/sec'\n | 'ops/sec'\n | 'packets/sec'\n | 'reads/sec'\n | 'records/sec'\n | 'requests/sec'\n | 'rows/sec'\n | 'writes/sec';\nexport type ThroughputFormatOptions = {\n unit?: ThroughputUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const THROUGHPUT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Throughput',\n decimalPlaces: true,\n};\nconst THROUGHPUT_GROUP = 'Throughput';\nexport const THROUGHPUT_UNIT_CONFIG: Readonly<Record<ThroughputUnit, UnitConfig>> = {\n 'bits/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bits/sec (IEC)',\n },\n 'decbits/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bits/sec (SI)',\n },\n 'bytes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bytes/sec (IEC)',\n },\n 'decbytes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Bytes/sec (SI)',\n },\n\n 'counts/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Counts/sec',\n },\n 'events/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Events/sec',\n },\n 'messages/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Messages/sec',\n },\n 'ops/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Ops/sec',\n },\n 'packets/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Packets/sec',\n },\n 'reads/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Reads/sec',\n },\n 'requests/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Requests/sec',\n },\n 'records/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Records/sec',\n },\n 'rows/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Rows/sec',\n },\n 'writes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Writes/sec',\n },\n};\n\nexport function formatThroughput(value: number, { unit, shortValues, decimalPlaces }: ThroughputFormatOptions): string {\n // special case for data throughput\n if (unit === 'bits/sec') {\n const denominator = Math.abs(value) < 1024 ? 'sec' : 's';\n return formatBits(value, { unit: 'bits', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n if (unit === 'decbits/sec') {\n const denominator = Math.abs(value) < 1000 ? 'sec' : 's';\n return formatBits(value, { unit: 'decbits', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n if (unit === 'decbytes/sec') {\n const denominator = Math.abs(value) < 1000 ? 'sec' : 's';\n return formatBytes(value, { unit: 'decbytes', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n if (unit === 'bytes/sec') {\n const denominator = Math.abs(value) < 1024 ? 'sec' : 's';\n return formatBytes(value, { unit: 'bytes', shortValues, decimalPlaces }) + '/' + denominator;\n }\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.notation,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n shortValues,\n unit,\n ];\n\n return `${getFormatterFromCache(key, 'throughput', formatterOptions, 'en-US')(value)} ${unit}`;\n}\n"],"names":["formatBytes","formatBits","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","getFormatterFromCache","THROUGHPUT_GROUP_CONFIG","label","decimalPlaces","THROUGHPUT_GROUP","THROUGHPUT_UNIT_CONFIG","group","formatThroughput","value","unit","shortValues","denominator","Math","abs","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,QAAQ,UAAU;AACtC,SAASC,UAAU,QAAQ,SAAS;AACpC,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AACpF,SAASC,qBAAqB,QAAQ,mBAAmB;AAsBzD,OAAO,MAAMC,0BAA2C;IACtDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,MAAMC,mBAAmB;AACzB,OAAO,MAAMC,yBAAuE;IAClF,YAAY;QACVC,OAAOF;QACPF,OAAO;IACT;IACA,eAAe;QACbI,OAAOF;QACPF,OAAO;IACT;IACA,aAAa;QACXI,OAAOF;QACPF,OAAO;IACT;IACA,gBAAgB;QACdI,OAAOF;QACPF,OAAO;IACT;IAEA,cAAc;QACZI,OAAOF;QACPF,OAAO;IACT;IACA,cAAc;QACZI,OAAOF;QACPF,OAAO;IACT;IACA,gBAAgB;QACdI,OAAOF;QACPF,OAAO;IACT;IACA,WAAW;QACTI,OAAOF;QACPF,OAAO;IACT;IACA,eAAe;QACbI,OAAOF;QACPF,OAAO;IACT;IACA,aAAa;QACXI,OAAOF;QACPF,OAAO;IACT;IACA,gBAAgB;QACdI,OAAOF;QACPF,OAAO;IACT;IACA,eAAe;QACbI,OAAOF;QACPF,OAAO;IACT;IACA,YAAY;QACVI,OAAOF;QACPF,OAAO;IACT;IACA,cAAc;QACZI,OAAOF;QACPF,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASK,iBAAiBC,KAAa,EAAE,EAAEC,IAAI,EAAEC,WAAW,EAAEP,aAAa,EAA2B;IAC3G,mCAAmC;IACnC,IAAIM,SAAS,YAAY;QACvB,MAAME,cAAcC,KAAKC,GAAG,CAACL,SAAS,OAAO,QAAQ;QACrD,OAAOb,WAAWa,OAAO;YAAEC,MAAM;YAAQC;YAAaP;QAAc,KAAK,MAAMQ;IACjF;IAEA,IAAIF,SAAS,eAAe;QAC1B,MAAME,cAAcC,KAAKC,GAAG,CAACL,SAAS,OAAO,QAAQ;QACrD,OAAOb,WAAWa,OAAO;YAAEC,MAAM;YAAWC;YAAaP;QAAc,KAAK,MAAMQ;IACpF;IAEA,IAAIF,SAAS,gBAAgB;QAC3B,MAAME,cAAcC,KAAKC,GAAG,CAACL,SAAS,OAAO,QAAQ;QACrD,OAAOd,YAAYc,OAAO;YAAEC,MAAM;YAAYC;YAAaP;QAAc,KAAK,MAAMQ;IACtF;IAEA,IAAIF,SAAS,aAAa;QACxB,MAAME,cAAcC,KAAKC,GAAG,CAACL,SAAS,OAAO,QAAQ;QACrD,OAAOd,YAAYc,OAAO;YAAEC,MAAM;YAASC;YAAaP;QAAc,KAAK,MAAMQ;IACnF;IAEA,MAAMG,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIjB,oBAAoBW,cAAc;QACpCI,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAIpB,iBAAiBM,gBAAgB;QACnCW,iBAAiBI,qBAAqB,GAAGpB,mBAAmBK;QAC5DW,iBAAiBK,qBAAqB,GAAGrB,mBAAmBK;IAC9D,OAAO;QACL,IAAIJ,oBAAoBW,cAAc;YACpCI,iBAAiBM,wBAAwB,GAAGxB;QAC9C;IACF;IAEA,MAAMyB,MAAM;QACVP,iBAAiBC,KAAK;QACtBD,iBAAiBE,WAAW;QAC5BF,iBAAiBG,QAAQ;QACzBH,iBAAiBM,wBAAwB;QACzCjB;QACAO;QACAD;KACD;IAED,OAAO,GAAGT,sBAAsBqB,KAAK,cAAcP,kBAAkB,SAASN,OAAO,CAAC,EAAEC,MAAM;AAChG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,KAAK,SAAS,GACV,aAAa,GACb,cAAc,GACd,cAAc,GACd,SAAS,GACT,SAAS,GACT,OAAO,GACP,MAAM,GACN,OAAO,GACP,QAAQ,GACR,OAAO,CAAC;AACZ,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAyCpE,CAAC;AAIF,oBAAY,oBAAoB;IAC9B,WAAW,eAAe;IAC1B,YAAY,gBAAgB;IAC5B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AA4DD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,iBAAiB,GAAG,MAAM,CA4B5F"}
|
package/dist/model/units/time.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { getFormatterFromCache } from './formatterCache';
|
|
14
15
|
import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
|
|
15
16
|
const TIME_GROUP = 'Time';
|
|
16
17
|
export const TIME_GROUP_CONFIG = {
|
|
@@ -143,8 +144,15 @@ export function formatTime(value, { unit, decimalPlaces }) {
|
|
|
143
144
|
} else {
|
|
144
145
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
145
146
|
}
|
|
146
|
-
const
|
|
147
|
-
|
|
147
|
+
const key = [
|
|
148
|
+
formatterOptions.style,
|
|
149
|
+
formatterOptions.unit,
|
|
150
|
+
formatterOptions.unitDisplay,
|
|
151
|
+
formatterOptions.maximumSignificantDigits,
|
|
152
|
+
decimalPlaces,
|
|
153
|
+
unit ?? 'seconds'
|
|
154
|
+
];
|
|
155
|
+
return getFormatterFromCache(key, 'time', formatterOptions, 'en-US')(results.value);
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
//# sourceMappingURL=time.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\ntype TimeUnits =\n | 'nanoseconds'\n | 'microseconds'\n | 'milliseconds'\n | 'seconds'\n | 'minutes'\n | 'hours'\n | 'days'\n | 'weeks'\n | 'months'\n | 'years';\nexport type TimeFormatOptions = {\n unit?: TimeUnits;\n decimalPlaces?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimalPlaces: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnits, UnitConfig>> = {\n nanoseconds: {\n group: TIME_GROUP,\n label: 'Nanoseconds',\n },\n microseconds: {\n group: TIME_GROUP,\n label: 'Microseconds',\n },\n milliseconds: {\n group: TIME_GROUP,\n label: 'Milliseconds',\n },\n seconds: {\n group: TIME_GROUP,\n label: 'Seconds',\n },\n minutes: {\n group: TIME_GROUP,\n label: 'Minutes',\n },\n hours: {\n group: TIME_GROUP,\n label: 'Hours',\n },\n days: {\n group: TIME_GROUP,\n label: 'Days',\n },\n weeks: {\n group: TIME_GROUP,\n label: 'Weeks',\n },\n months: {\n group: TIME_GROUP,\n label: 'Months',\n },\n years: {\n group: TIME_GROUP,\n label: 'Years',\n },\n};\n\n// Mapping of time units to what Intl.NumberFormat formatter expects\n// https://v8.dev/features/intl-numberformat#units\nexport enum PersesTimeToIntlTime {\n nanoseconds = 'nanosecond',\n microseconds = 'microsecond',\n milliseconds = 'millisecond',\n seconds = 'second',\n minutes = 'minute',\n hours = 'hour',\n days = 'day',\n weeks = 'week',\n months = 'month',\n years = 'year',\n}\n\n/**\n * Note: This conversion will not be exactly accurate for months and years,\n * due variations in the lengths of months (i.e. 28 - 31 days) and years (i.e. leap years).\n * For precision with months and years, we would need more complex algorithms and/or external libraries.\n * However, we expect that measurements in months and years will be rare.\n */\nconst TIME_UNITS_IN_SECONDS: Record<TimeUnits, number> = {\n years: 31536000, // 365 days\n months: 2592000, // 30 days\n weeks: 604800, // 7 days\n days: 86400,\n hours: 3600,\n minutes: 60,\n seconds: 1,\n milliseconds: 0.001,\n microseconds: 0.000001,\n nanoseconds: 0.000000001,\n};\n\nconst LARGEST_TO_SMALLEST_TIME_UNITS: TimeUnits[] = [\n 'years',\n 'months',\n 'weeks',\n 'days',\n 'hours',\n 'minutes',\n 'seconds',\n 'milliseconds',\n 'microseconds',\n 'nanoseconds',\n];\n\n/**\n * Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.\n */\nfunction getValueAndKindForNaturalNumbers(value: number, unit: TimeUnits): { value: number; unit: TimeUnits } {\n const valueInSeconds = value * TIME_UNITS_IN_SECONDS[unit];\n\n // Initialize for TS\n const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'years';\n let timeUnit: TimeUnits = largestTimeUnit;\n let valueInTimeUnit: number = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];\n\n for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS) {\n valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];\n if (valueInTimeUnit >= 1) {\n return { value: valueInTimeUnit, unit: timeUnit };\n }\n }\n\n // If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).\n return { value: valueInTimeUnit, unit: timeUnit };\n}\n\nfunction isMonthOrYear(unit: TimeUnits): boolean {\n return unit === 'months' || unit === 'years';\n}\n\nexport function formatTime(value: number, { unit, decimalPlaces }: TimeFormatOptions): string {\n if (value === 0) return '0s';\n\n const results = getValueAndKindForNaturalNumbers(value, unit ?? 'seconds');\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: PersesTimeToIntlTime[results.unit],\n unitDisplay: isMonthOrYear(results.unit) ? 'long' : 'narrow',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { getFormatterFromCache } from './formatterCache';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\ntype TimeUnits =\n | 'nanoseconds'\n | 'microseconds'\n | 'milliseconds'\n | 'seconds'\n | 'minutes'\n | 'hours'\n | 'days'\n | 'weeks'\n | 'months'\n | 'years';\nexport type TimeFormatOptions = {\n unit?: TimeUnits;\n decimalPlaces?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimalPlaces: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnits, UnitConfig>> = {\n nanoseconds: {\n group: TIME_GROUP,\n label: 'Nanoseconds',\n },\n microseconds: {\n group: TIME_GROUP,\n label: 'Microseconds',\n },\n milliseconds: {\n group: TIME_GROUP,\n label: 'Milliseconds',\n },\n seconds: {\n group: TIME_GROUP,\n label: 'Seconds',\n },\n minutes: {\n group: TIME_GROUP,\n label: 'Minutes',\n },\n hours: {\n group: TIME_GROUP,\n label: 'Hours',\n },\n days: {\n group: TIME_GROUP,\n label: 'Days',\n },\n weeks: {\n group: TIME_GROUP,\n label: 'Weeks',\n },\n months: {\n group: TIME_GROUP,\n label: 'Months',\n },\n years: {\n group: TIME_GROUP,\n label: 'Years',\n },\n};\n\n// Mapping of time units to what Intl.NumberFormat formatter expects\n// https://v8.dev/features/intl-numberformat#units\nexport enum PersesTimeToIntlTime {\n nanoseconds = 'nanosecond',\n microseconds = 'microsecond',\n milliseconds = 'millisecond',\n seconds = 'second',\n minutes = 'minute',\n hours = 'hour',\n days = 'day',\n weeks = 'week',\n months = 'month',\n years = 'year',\n}\n\n/**\n * Note: This conversion will not be exactly accurate for months and years,\n * due variations in the lengths of months (i.e. 28 - 31 days) and years (i.e. leap years).\n * For precision with months and years, we would need more complex algorithms and/or external libraries.\n * However, we expect that measurements in months and years will be rare.\n */\nconst TIME_UNITS_IN_SECONDS: Record<TimeUnits, number> = {\n years: 31536000, // 365 days\n months: 2592000, // 30 days\n weeks: 604800, // 7 days\n days: 86400,\n hours: 3600,\n minutes: 60,\n seconds: 1,\n milliseconds: 0.001,\n microseconds: 0.000001,\n nanoseconds: 0.000000001,\n};\n\nconst LARGEST_TO_SMALLEST_TIME_UNITS: TimeUnits[] = [\n 'years',\n 'months',\n 'weeks',\n 'days',\n 'hours',\n 'minutes',\n 'seconds',\n 'milliseconds',\n 'microseconds',\n 'nanoseconds',\n];\n\n/**\n * Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.\n */\nfunction getValueAndKindForNaturalNumbers(value: number, unit: TimeUnits): { value: number; unit: TimeUnits } {\n const valueInSeconds = value * TIME_UNITS_IN_SECONDS[unit];\n\n // Initialize for TS\n const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'years';\n let timeUnit: TimeUnits = largestTimeUnit;\n let valueInTimeUnit: number = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];\n\n for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS) {\n valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];\n if (valueInTimeUnit >= 1) {\n return { value: valueInTimeUnit, unit: timeUnit };\n }\n }\n\n // If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).\n return { value: valueInTimeUnit, unit: timeUnit };\n}\n\nfunction isMonthOrYear(unit: TimeUnits): boolean {\n return unit === 'months' || unit === 'years';\n}\n\nexport function formatTime(value: number, { unit, decimalPlaces }: TimeFormatOptions): string {\n if (value === 0) return '0s';\n\n const results = getValueAndKindForNaturalNumbers(value, unit ?? 'seconds');\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: PersesTimeToIntlTime[results.unit],\n unitDisplay: isMonthOrYear(results.unit) ? 'long' : 'narrow',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.unit,\n formatterOptions.unitDisplay,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n unit ?? 'seconds',\n ];\n\n return getFormatterFromCache(key, 'time', formatterOptions, 'en-US')(results.value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","getFormatterFromCache","hasDecimalPlaces","limitDecimalPlaces","TIME_GROUP","TIME_GROUP_CONFIG","label","decimalPlaces","TIME_UNIT_CONFIG","nanoseconds","group","microseconds","milliseconds","seconds","minutes","hours","days","weeks","months","years","PersesTimeToIntlTime","TIME_UNITS_IN_SECONDS","LARGEST_TO_SMALLEST_TIME_UNITS","getValueAndKindForNaturalNumbers","value","unit","valueInSeconds","largestTimeUnit","timeUnit","valueInTimeUnit","isMonthOrYear","formatTime","results","formatterOptions","style","unitDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,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,cAAc;AACrD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAiB/D,MAAMC,aAAa;AACnB,OAAO,MAAMC,oBAAqC;IAChDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,OAAO,MAAMC,mBAA4D;IACvEC,aAAa;QACXC,OAAON;QACPE,OAAO;IACT;IACAK,cAAc;QACZD,OAAON;QACPE,OAAO;IACT;IACAM,cAAc;QACZF,OAAON;QACPE,OAAO;IACT;IACAO,SAAS;QACPH,OAAON;QACPE,OAAO;IACT;IACAQ,SAAS;QACPJ,OAAON;QACPE,OAAO;IACT;IACAS,OAAO;QACLL,OAAON;QACPE,OAAO;IACT;IACAU,MAAM;QACJN,OAAON;QACPE,OAAO;IACT;IACAW,OAAO;QACLP,OAAON;QACPE,OAAO;IACT;IACAY,QAAQ;QACNR,OAAON;QACPE,OAAO;IACT;IACAa,OAAO;QACLT,OAAON;QACPE,OAAO;IACT;AACF,EAAE;AAEF,oEAAoE;AACpE,kDAAkD;AAClD,OAAO,IAAA,AAAKc,8CAAAA;;;;;;;;;;;WAAAA;MAWX;AAED;;;;;CAKC,GACD,MAAMC,wBAAmD;IACvDF,OAAO;IACPD,QAAQ;IACRD,OAAO;IACPD,MAAM;IACND,OAAO;IACPD,SAAS;IACTD,SAAS;IACTD,cAAc;IACdD,cAAc;IACdF,aAAa;AACf;AAEA,MAAMa,iCAA8C;IAClD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;CAEC,GACD,SAASC,iCAAiCC,KAAa,EAAEC,IAAe;IACtE,MAAMC,iBAAiBF,QAAQH,qBAAqB,CAACI,KAAK;IAE1D,oBAAoB;IACpB,MAAME,kBAAkBL,8BAA8B,CAAC,EAAE,IAAI;IAC7D,IAAIM,WAAsBD;IAC1B,IAAIE,kBAA0BH,iBAAiBL,qBAAqB,CAACM,gBAAgB;IAErF,KAAKC,YAAYN,+BAAgC;QAC/CO,kBAAkBH,iBAAiBL,qBAAqB,CAACO,SAAS;QAClE,IAAIC,mBAAmB,GAAG;YACxB,OAAO;gBAAEL,OAAOK;gBAAiBJ,MAAMG;YAAS;QAClD;IACF;IAEA,6GAA6G;IAC7G,OAAO;QAAEJ,OAAOK;QAAiBJ,MAAMG;IAAS;AAClD;AAEA,SAASE,cAAcL,IAAe;IACpC,OAAOA,SAAS,YAAYA,SAAS;AACvC;AAEA,OAAO,SAASM,WAAWP,KAAa,EAAE,EAAEC,IAAI,EAAElB,aAAa,EAAqB;IAClF,IAAIiB,UAAU,GAAG,OAAO;IAExB,MAAMQ,UAAUT,iCAAiCC,OAAOC,QAAQ;IAEhE,MAAMQ,mBAA6C;QACjDC,OAAO;QACPT,MAAML,oBAAoB,CAACY,QAAQP,IAAI,CAAC;QACxCU,aAAaL,cAAcE,QAAQP,IAAI,IAAI,SAAS;IACtD;IAEA,IAAIvB,iBAAiBK,gBAAgB;QACnC0B,iBAAiBG,qBAAqB,GAAGjC,mBAAmBI;QAC5D0B,iBAAiBI,qBAAqB,GAAGlC,mBAAmBI;IAC9D,OAAO;QACL0B,iBAAiBK,wBAAwB,GAAGtC;IAC9C;IAEA,MAAMuC,MAAM;QACVN,iBAAiBC,KAAK;QACtBD,iBAAiBR,IAAI;QACrBQ,iBAAiBE,WAAW;QAC5BF,iBAAiBK,wBAAwB;QACzC/B;QACAkB,QAAQ;KACT;IAED,OAAOxB,sBAAsBsC,KAAK,QAAQN,kBAAkB,SAASD,QAAQR,KAAK;AACpF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../../src/schema/panel.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC9G,OAAO,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AAEtD,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,SAAS,CAAC,YAAY,CAGrD,CAAC;AAEH,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC,eAAe,
|
|
1
|
+
{"version":3,"file":"panel.d.ts","sourceRoot":"","sources":["../../src/schema/panel.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC9G,OAAO,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AAEtD,eAAO,MAAM,gBAAgB,EAAE,CAAC,CAAC,SAAS,CAAC,YAAY,CAGrD,CAAC;AAEH,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC,eAAe,CAMvD,CAAC;AAEH,eAAO,MAAM,UAAU,EAAE,CAAC,CAAC,SAAS,CAAC,IAAI,CAMvC,CAAC;AAEH,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,SAAS,CAAC,SAAS,CAKjD,CAAC;AAEH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,YAAY,GAAG,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAOvF;AAED,eAAO,MAAM,qBAAqB,EAAE,CAAC,CAAC,SAAS,CAAC,eAAe,CAG7D,CAAC;AAEH,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,YAAY,GAAG,CAAC,CAAC,SAAS,CAAC,eAAe,CAAC,CAKnG;AAED,eAAO,MAAM,iBAAiB,EAAE,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAG3D,CAAC;AAEH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,YAAY,GAAG,CAAC,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAKjG"}
|
package/dist/schema/panel.js
CHANGED
package/dist/schema/panel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/schema/panel.ts"],"sourcesContent":["// Copyright 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 { z } from 'zod';\nimport { Link, PanelDefinition, PanelDisplay, PanelEditorValues, PanelSpec, QueryDefinition } from '../model';\nimport { PluginSchema, pluginSchema } from './plugin';\n\nexport const panelDisplaySpec: z.ZodSchema<PanelDisplay> = z.object({\n name: z.string().optional(),\n description: z.string().optional(),\n});\n\nexport const querySpecSchema: z.ZodSchema<QueryDefinition> = z.object({\n kind: z.string().min(1),\n spec: z.object({\n plugin: pluginSchema,\n }),\n});\n\nexport const linkSchema: z.ZodSchema<Link> = z.object({\n name: z.string().optional(),\n url: z.string().min(1),\n tooltip: z.string().optional(),\n renderVariables: z.boolean().optional(),\n targetBlank: z.boolean().optional(),\n});\n\nexport const panelSpecSchema: z.ZodSchema<PanelSpec> = z.object({\n display: panelDisplaySpec.optional(),\n plugin: pluginSchema,\n queries: z.array(querySpecSchema).optional(),\n links: z.array(linkSchema).optional(),\n});\n\nexport function buildPanelSpecSchema(pluginSchema: PluginSchema): z.ZodSchema<PanelSpec> {\n return z.object({\n display: panelDisplaySpec.optional(),\n plugin: pluginSchema,\n queries: z.array(querySpecSchema).optional(),\n links: z.array(linkSchema).optional(),\n });\n}\n\nexport const panelDefinitionSchema: z.ZodSchema<PanelDefinition> = z.object({\n kind: z.literal('Panel'),\n spec: panelSpecSchema,\n});\n\nexport function buildPanelDefinitionSchema(pluginSchema: PluginSchema): z.ZodSchema<PanelDefinition> {\n return z.object({\n kind: z.literal('Panel'),\n spec: buildPanelSpecSchema(pluginSchema),\n });\n}\n\nexport const panelEditorSchema: z.ZodSchema<PanelEditorValues> = z.object({\n groupId: z.number(),\n panelDefinition: panelDefinitionSchema,\n});\n\nexport function buildPanelEditorSchema(pluginSchema: PluginSchema): z.ZodSchema<PanelEditorValues> {\n return z.object({\n groupId: z.number(),\n panelDefinition: buildPanelDefinitionSchema(pluginSchema),\n });\n}\n"],"names":["z","pluginSchema","panelDisplaySpec","object","name","string","optional","description","querySpecSchema","kind","min","spec","plugin","linkSchema","url","tooltip","renderVariables","boolean","targetBlank","panelSpecSchema","display","queries","array","links","buildPanelSpecSchema","panelDefinitionSchema","literal","buildPanelDefinitionSchema","panelEditorSchema","groupId","number","panelDefinition","buildPanelEditorSchema"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,CAAC,QAAQ,MAAM;AAExB,SAAuBC,YAAY,QAAQ,WAAW;AAEtD,OAAO,MAAMC,mBAA8CF,EAAEG,MAAM,CAAC;IAClEC,MAAMJ,EAAEK,MAAM,GAAGC,QAAQ;IACzBC,aAAaP,EAAEK,MAAM,GAAGC,QAAQ;AAClC,GAAG;AAEH,OAAO,MAAME,kBAAgDR,EAAEG,MAAM,CAAC;IACpEM,MAAMT,EAAEK,MAAM,GAAGK,GAAG,CAAC;IACrBC,MAAMX,EAAEG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"sources":["../../src/schema/panel.ts"],"sourcesContent":["// Copyright 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 { z } from 'zod';\nimport { Link, PanelDefinition, PanelDisplay, PanelEditorValues, PanelSpec, QueryDefinition } from '../model';\nimport { PluginSchema, pluginSchema } from './plugin';\n\nexport const panelDisplaySpec: z.ZodSchema<PanelDisplay> = z.object({\n name: z.string().optional(),\n description: z.string().optional(),\n});\n\nexport const querySpecSchema: z.ZodSchema<QueryDefinition> = z.object({\n kind: z.string().min(1),\n spec: z.object({\n name: z.string().optional(),\n plugin: pluginSchema,\n }),\n});\n\nexport const linkSchema: z.ZodSchema<Link> = z.object({\n name: z.string().optional(),\n url: z.string().min(1),\n tooltip: z.string().optional(),\n renderVariables: z.boolean().optional(),\n targetBlank: z.boolean().optional(),\n});\n\nexport const panelSpecSchema: z.ZodSchema<PanelSpec> = z.object({\n display: panelDisplaySpec.optional(),\n plugin: pluginSchema,\n queries: z.array(querySpecSchema).optional(),\n links: z.array(linkSchema).optional(),\n});\n\nexport function buildPanelSpecSchema(pluginSchema: PluginSchema): z.ZodSchema<PanelSpec> {\n return z.object({\n display: panelDisplaySpec.optional(),\n plugin: pluginSchema,\n queries: z.array(querySpecSchema).optional(),\n links: z.array(linkSchema).optional(),\n });\n}\n\nexport const panelDefinitionSchema: z.ZodSchema<PanelDefinition> = z.object({\n kind: z.literal('Panel'),\n spec: panelSpecSchema,\n});\n\nexport function buildPanelDefinitionSchema(pluginSchema: PluginSchema): z.ZodSchema<PanelDefinition> {\n return z.object({\n kind: z.literal('Panel'),\n spec: buildPanelSpecSchema(pluginSchema),\n });\n}\n\nexport const panelEditorSchema: z.ZodSchema<PanelEditorValues> = z.object({\n groupId: z.number(),\n panelDefinition: panelDefinitionSchema,\n});\n\nexport function buildPanelEditorSchema(pluginSchema: PluginSchema): z.ZodSchema<PanelEditorValues> {\n return z.object({\n groupId: z.number(),\n panelDefinition: buildPanelDefinitionSchema(pluginSchema),\n });\n}\n"],"names":["z","pluginSchema","panelDisplaySpec","object","name","string","optional","description","querySpecSchema","kind","min","spec","plugin","linkSchema","url","tooltip","renderVariables","boolean","targetBlank","panelSpecSchema","display","queries","array","links","buildPanelSpecSchema","panelDefinitionSchema","literal","buildPanelDefinitionSchema","panelEditorSchema","groupId","number","panelDefinition","buildPanelEditorSchema"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,CAAC,QAAQ,MAAM;AAExB,SAAuBC,YAAY,QAAQ,WAAW;AAEtD,OAAO,MAAMC,mBAA8CF,EAAEG,MAAM,CAAC;IAClEC,MAAMJ,EAAEK,MAAM,GAAGC,QAAQ;IACzBC,aAAaP,EAAEK,MAAM,GAAGC,QAAQ;AAClC,GAAG;AAEH,OAAO,MAAME,kBAAgDR,EAAEG,MAAM,CAAC;IACpEM,MAAMT,EAAEK,MAAM,GAAGK,GAAG,CAAC;IACrBC,MAAMX,EAAEG,MAAM,CAAC;QACbC,MAAMJ,EAAEK,MAAM,GAAGC,QAAQ;QACzBM,QAAQX;IACV;AACF,GAAG;AAEH,OAAO,MAAMY,aAAgCb,EAAEG,MAAM,CAAC;IACpDC,MAAMJ,EAAEK,MAAM,GAAGC,QAAQ;IACzBQ,KAAKd,EAAEK,MAAM,GAAGK,GAAG,CAAC;IACpBK,SAASf,EAAEK,MAAM,GAAGC,QAAQ;IAC5BU,iBAAiBhB,EAAEiB,OAAO,GAAGX,QAAQ;IACrCY,aAAalB,EAAEiB,OAAO,GAAGX,QAAQ;AACnC,GAAG;AAEH,OAAO,MAAMa,kBAA0CnB,EAAEG,MAAM,CAAC;IAC9DiB,SAASlB,iBAAiBI,QAAQ;IAClCM,QAAQX;IACRoB,SAASrB,EAAEsB,KAAK,CAACd,iBAAiBF,QAAQ;IAC1CiB,OAAOvB,EAAEsB,KAAK,CAACT,YAAYP,QAAQ;AACrC,GAAG;AAEH,OAAO,SAASkB,qBAAqBvB,YAA0B;IAC7D,OAAOD,EAAEG,MAAM,CAAC;QACdiB,SAASlB,iBAAiBI,QAAQ;QAClCM,QAAQX;QACRoB,SAASrB,EAAEsB,KAAK,CAACd,iBAAiBF,QAAQ;QAC1CiB,OAAOvB,EAAEsB,KAAK,CAACT,YAAYP,QAAQ;IACrC;AACF;AAEA,OAAO,MAAMmB,wBAAsDzB,EAAEG,MAAM,CAAC;IAC1EM,MAAMT,EAAE0B,OAAO,CAAC;IAChBf,MAAMQ;AACR,GAAG;AAEH,OAAO,SAASQ,2BAA2B1B,YAA0B;IACnE,OAAOD,EAAEG,MAAM,CAAC;QACdM,MAAMT,EAAE0B,OAAO,CAAC;QAChBf,MAAMa,qBAAqBvB;IAC7B;AACF;AAEA,OAAO,MAAM2B,oBAAoD5B,EAAEG,MAAM,CAAC;IACxE0B,SAAS7B,EAAE8B,MAAM;IACjBC,iBAAiBN;AACnB,GAAG;AAEH,OAAO,SAASO,uBAAuB/B,YAA0B;IAC/D,OAAOD,EAAEG,MAAM,CAAC;QACd0B,SAAS7B,EAAE8B,MAAM;QACjBC,iBAAiBJ,2BAA2B1B;IAC9C;AACF"}
|
package/package.json
CHANGED