@perses-dev/core 0.38.0 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/model/calculations.js +0 -2
- package/dist/cjs/model/units/bytes.js +13 -7
- package/dist/cjs/model/units/decimal.js +3 -3
- package/dist/cjs/model/units/percent.js +6 -5
- package/dist/cjs/model/units/time.js +57 -4
- package/dist/cjs/model/units/units.js +5 -5
- package/dist/cjs/utils/text.js +14 -1
- package/dist/model/calculations.d.ts +0 -1
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +0 -1
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/datasource.d.ts +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/query.d.ts +13 -2
- package/dist/model/query.d.ts.map +1 -1
- package/dist/model/query.js.map +1 -1
- package/dist/model/time-series-data.d.ts +6 -0
- package/dist/model/time-series-data.d.ts.map +1 -1
- package/dist/model/time-series-data.js.map +1 -1
- package/dist/model/units/bytes.d.ts +1 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +13 -7
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/decimal.d.ts +1 -1
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +3 -3
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +6 -5
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +57 -4
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/units.d.ts +7 -0
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +15 -9
- package/dist/model/units/units.js.map +1 -1
- package/dist/utils/text.d.ts +13 -1
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +19 -0
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/time-series-data.d.ts +1 -1
- package/dist/utils/time-series-data.d.ts.map +1 -1
- package/dist/utils/time-series-data.js +1 -1
- package/dist/utils/time-series-data.js.map +1 -1
- package/package.json +1 -1
|
@@ -23,7 +23,6 @@ function _export(target, all) {
|
|
|
23
23
|
_export(exports, {
|
|
24
24
|
CalculationsMap: ()=>CalculationsMap,
|
|
25
25
|
CALCULATIONS_CONFIG: ()=>CALCULATIONS_CONFIG,
|
|
26
|
-
DEFAULT_CALCULATION: ()=>DEFAULT_CALCULATION,
|
|
27
26
|
getCalculations: ()=>getCalculations,
|
|
28
27
|
getCalculation: ()=>getCalculation
|
|
29
28
|
});
|
|
@@ -71,7 +70,6 @@ const CALCULATIONS_CONFIG = {
|
|
|
71
70
|
description: 'Maximum value'
|
|
72
71
|
}
|
|
73
72
|
};
|
|
74
|
-
const DEFAULT_CALCULATION = 'Sum';
|
|
75
73
|
function getCalculations(values, includeCalculations) {
|
|
76
74
|
const calculations = includeCalculations.reduce((initResult, calculation)=>{
|
|
77
75
|
initResult[calculation] = undefined;
|
|
@@ -33,7 +33,13 @@ function _interopRequireDefault(obj) {
|
|
|
33
33
|
default: obj
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* We consider the units for bytes to be powers of 1000.
|
|
38
|
+
* In other words:
|
|
39
|
+
* 1 KB = 1000 bytes (1000^1 bytes)
|
|
40
|
+
* 1 MB = 1,000,000 bytes (1000^2 bytes)
|
|
41
|
+
* etc.
|
|
42
|
+
*/ const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
37
43
|
const bytesUnitKinds = [
|
|
38
44
|
'Bytes'
|
|
39
45
|
];
|
|
@@ -43,15 +49,13 @@ const BYTES_GROUP_CONFIG = {
|
|
|
43
49
|
abbreviate: true
|
|
44
50
|
};
|
|
45
51
|
const BYTES_UNIT_CONFIG = {
|
|
46
|
-
// These units are powers of 1000.
|
|
47
|
-
// In other words, 1 KB = 1000 bytes.
|
|
48
52
|
Bytes: {
|
|
49
53
|
group: 'Bytes',
|
|
50
54
|
label: 'Bytes'
|
|
51
55
|
}
|
|
52
56
|
};
|
|
53
|
-
function formatBytes(bytes,
|
|
54
|
-
|
|
57
|
+
function formatBytes(bytes, { abbreviate , decimal_places }) {
|
|
58
|
+
// If we're showing the entire value, we can use Intl.NumberFormat.
|
|
55
59
|
if (!(0, _utils.shouldAbbreviate)(abbreviate) || Math.abs(bytes) < 1000) {
|
|
56
60
|
const formatterOptions = {
|
|
57
61
|
style: 'unit',
|
|
@@ -68,9 +72,11 @@ function formatBytes(bytes, options) {
|
|
|
68
72
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
|
-
|
|
75
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
76
|
+
return formatter.format(bytes);
|
|
72
77
|
}
|
|
73
|
-
//
|
|
78
|
+
// If we're showing the "abbreviated" value, we use numbro.
|
|
79
|
+
// numbro is able to add units like KB, MB, GB, etc. correctly.
|
|
74
80
|
return (0, _numbro.default)(bytes).format({
|
|
75
81
|
output: 'byte',
|
|
76
82
|
base: 'decimal',
|
|
@@ -41,8 +41,7 @@ const DECIMAL_UNIT_CONFIG = {
|
|
|
41
41
|
label: 'Decimal'
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
-
function formatDecimal(value,
|
|
45
|
-
const { abbreviate , decimal_places } = options;
|
|
44
|
+
function formatDecimal(value, { abbreviate , decimal_places }) {
|
|
46
45
|
const formatterOptions = {
|
|
47
46
|
style: 'decimal',
|
|
48
47
|
useGrouping: true
|
|
@@ -58,5 +57,6 @@ function formatDecimal(value, options) {
|
|
|
58
57
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
|
-
|
|
60
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
61
|
+
return formatter.format(value);
|
|
62
62
|
}
|
|
@@ -55,10 +55,6 @@ const PERCENT_UNIT_CONFIG = {
|
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
function formatPercent(value, { kind , decimal_places }) {
|
|
58
|
-
// Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
|
|
59
|
-
if (kind === 'Percent') {
|
|
60
|
-
value = value / 100;
|
|
61
|
-
}
|
|
62
58
|
const formatterOptions = {
|
|
63
59
|
style: 'percent',
|
|
64
60
|
useGrouping: true
|
|
@@ -69,5 +65,10 @@ function formatPercent(value, { kind , decimal_places }) {
|
|
|
69
65
|
} else {
|
|
70
66
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
71
67
|
}
|
|
72
|
-
|
|
68
|
+
// Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.
|
|
69
|
+
if (kind === 'Percent') {
|
|
70
|
+
value = value / 100;
|
|
71
|
+
}
|
|
72
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
73
|
+
return formatter.format(value);
|
|
73
74
|
}
|
|
@@ -88,12 +88,64 @@ var PersesTimeToIntlTime;
|
|
|
88
88
|
PersesTimeToIntlTime["Months"] = 'month';
|
|
89
89
|
PersesTimeToIntlTime["Years"] = 'year';
|
|
90
90
|
})(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
|
|
91
|
+
/**
|
|
92
|
+
* Note: This conversion will not be exactly accurate for months and years,
|
|
93
|
+
* due variations in the lengths of months (i.e. 28 - 31 days) and years (i.e. leap years).
|
|
94
|
+
* For precision with months and years, we would need more complex algorithms and/or external libraries.
|
|
95
|
+
* However, we expect that measurements in months and years will be rare.
|
|
96
|
+
*/ const TIME_UNITS_IN_SECONDS = {
|
|
97
|
+
Years: 31536000,
|
|
98
|
+
Months: 2592000,
|
|
99
|
+
Weeks: 604800,
|
|
100
|
+
Days: 86400,
|
|
101
|
+
Hours: 3600,
|
|
102
|
+
Minutes: 60,
|
|
103
|
+
Seconds: 1,
|
|
104
|
+
Milliseconds: 0.001
|
|
105
|
+
};
|
|
106
|
+
const LARGEST_TO_SMALLEST_TIME_UNITS = [
|
|
107
|
+
'Years',
|
|
108
|
+
'Months',
|
|
109
|
+
'Weeks',
|
|
110
|
+
'Days',
|
|
111
|
+
'Hours',
|
|
112
|
+
'Minutes',
|
|
113
|
+
'Seconds',
|
|
114
|
+
'Milliseconds'
|
|
115
|
+
];
|
|
116
|
+
/**
|
|
117
|
+
* Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.
|
|
118
|
+
*/ function getValueAndKindForNaturalNumbers(value, kind) {
|
|
119
|
+
const valueInSeconds = value * TIME_UNITS_IN_SECONDS[kind];
|
|
120
|
+
// Initialize for TS
|
|
121
|
+
const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'Years';
|
|
122
|
+
let timeUnit = largestTimeUnit;
|
|
123
|
+
let valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];
|
|
124
|
+
for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS){
|
|
125
|
+
valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];
|
|
126
|
+
if (valueInTimeUnit >= 1) {
|
|
127
|
+
return {
|
|
128
|
+
value: valueInTimeUnit,
|
|
129
|
+
kind: timeUnit
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).
|
|
134
|
+
return {
|
|
135
|
+
value: valueInTimeUnit,
|
|
136
|
+
kind: timeUnit
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function isMonthOrYear(kind) {
|
|
140
|
+
return kind === 'Months' || kind === 'Years';
|
|
141
|
+
}
|
|
91
142
|
function formatTime(value, { kind , decimal_places }) {
|
|
92
|
-
|
|
143
|
+
if (value === 0) return '0s';
|
|
144
|
+
const results = getValueAndKindForNaturalNumbers(value, kind);
|
|
93
145
|
const formatterOptions = {
|
|
94
146
|
style: 'unit',
|
|
95
|
-
unit: PersesTimeToIntlTime[kind],
|
|
96
|
-
unitDisplay: isMonthOrYear ? 'long' : 'narrow'
|
|
147
|
+
unit: PersesTimeToIntlTime[results.kind],
|
|
148
|
+
unitDisplay: isMonthOrYear(results.kind) ? 'long' : 'narrow'
|
|
97
149
|
};
|
|
98
150
|
if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
|
|
99
151
|
formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
|
|
@@ -101,5 +153,6 @@ function formatTime(value, { kind , decimal_places }) {
|
|
|
101
153
|
} else {
|
|
102
154
|
formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
|
|
103
155
|
}
|
|
104
|
-
|
|
156
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
157
|
+
return formatter.format(results.value);
|
|
105
158
|
}
|
|
@@ -54,17 +54,17 @@ function formatValue(value, unitOptions) {
|
|
|
54
54
|
if (unitOptions === undefined) {
|
|
55
55
|
return value.toString();
|
|
56
56
|
}
|
|
57
|
+
if (isBytesUnit(unitOptions)) {
|
|
58
|
+
return (0, _bytes.formatBytes)(value, unitOptions);
|
|
59
|
+
}
|
|
57
60
|
if (isDecimalUnit(unitOptions)) {
|
|
58
61
|
return (0, _decimal.formatDecimal)(value, unitOptions);
|
|
59
62
|
}
|
|
60
|
-
if (isTimeUnit(unitOptions)) {
|
|
61
|
-
return (0, _time.formatTime)(value, unitOptions);
|
|
62
|
-
}
|
|
63
63
|
if (isPercentUnit(unitOptions)) {
|
|
64
64
|
return (0, _percent.formatPercent)(value, unitOptions);
|
|
65
65
|
}
|
|
66
|
-
if (
|
|
67
|
-
return (0,
|
|
66
|
+
if (isTimeUnit(unitOptions)) {
|
|
67
|
+
return (0, _time.formatTime)(value, unitOptions);
|
|
68
68
|
}
|
|
69
69
|
const exhaustive = unitOptions;
|
|
70
70
|
throw new Error(`Unknown unit options ${exhaustive}`);
|
package/dist/cjs/utils/text.js
CHANGED
|
@@ -23,8 +23,10 @@ function _export(target, all) {
|
|
|
23
23
|
_export(exports, {
|
|
24
24
|
getDashboardDisplayName: ()=>getDashboardDisplayName,
|
|
25
25
|
getVariableDisplayName: ()=>getVariableDisplayName,
|
|
26
|
+
getDatasourceDisplayName: ()=>getDatasourceDisplayName,
|
|
26
27
|
getDashboardExtendedDisplayName: ()=>getDashboardExtendedDisplayName,
|
|
27
|
-
getVariableExtendedDisplayName: ()=>getVariableExtendedDisplayName
|
|
28
|
+
getVariableExtendedDisplayName: ()=>getVariableExtendedDisplayName,
|
|
29
|
+
getDatasourceExtendedDisplayName: ()=>getDatasourceExtendedDisplayName
|
|
28
30
|
});
|
|
29
31
|
function getDashboardDisplayName(dashboard) {
|
|
30
32
|
var ref;
|
|
@@ -36,6 +38,10 @@ function getVariableDisplayName(variable) {
|
|
|
36
38
|
var ref1;
|
|
37
39
|
return (ref1 = (ref = variable.spec.spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : variable.metadata.name;
|
|
38
40
|
}
|
|
41
|
+
function getDatasourceDisplayName(datasource) {
|
|
42
|
+
var ref;
|
|
43
|
+
return ((ref = datasource.spec.display) === null || ref === void 0 ? void 0 : ref.name) || datasource.metadata.name;
|
|
44
|
+
}
|
|
39
45
|
function getDashboardExtendedDisplayName(dashboard) {
|
|
40
46
|
var ref;
|
|
41
47
|
if ((ref = dashboard.spec.display) === null || ref === void 0 ? void 0 : ref.name) {
|
|
@@ -50,3 +56,10 @@ function getVariableExtendedDisplayName(variable) {
|
|
|
50
56
|
}
|
|
51
57
|
return variable.metadata.name;
|
|
52
58
|
}
|
|
59
|
+
function getDatasourceExtendedDisplayName(datasource) {
|
|
60
|
+
var ref;
|
|
61
|
+
if ((ref = datasource.spec.display) === null || ref === void 0 ? void 0 : ref.name) {
|
|
62
|
+
return `${datasource.spec.display.name} (ID: ${datasource.metadata.name})`;
|
|
63
|
+
}
|
|
64
|
+
return datasource.metadata.name;
|
|
65
|
+
}
|
|
@@ -15,7 +15,6 @@ export declare type CalculationConfig = {
|
|
|
15
15
|
description: string;
|
|
16
16
|
};
|
|
17
17
|
export declare const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>>;
|
|
18
|
-
export declare const DEFAULT_CALCULATION: CalculationType;
|
|
19
18
|
declare type CalculationValue = number | null | undefined;
|
|
20
19
|
/**
|
|
21
20
|
* Calculate a multiple values for a set of time series data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,eAAO,MAAM,eAAe;;;;;;;;;CAS3B,CAAC;AAEF,oBAAY,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAiC3E,CAAC;AAEX,
|
|
1
|
+
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAExD,eAAO,MAAM,eAAe;;;;;;;;;CAS3B,CAAC;AAEF,oBAAY,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAiC3E,CAAC;AAEX,aAAK,gBAAgB,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAElD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,SAAS,eAAe,EAAE,EACpE,MAAM,EAAE,oBAAoB,EAAE,EAC9B,mBAAmB,EAAE,YAAY,GAChC,MAAM,CAGP,OAAO,CAAC,eAAe,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,EAC9C,gBAAgB,CACjB,CA2EA;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,oBAAoB,EAAE,EAAE,WAAW,EAAE,eAAe,oBAE1F;AAED,iBAAS,KAAK,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE/D;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE9D;AAED,iBAAS,WAAW,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAErE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAEpE;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE9D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAE7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const CalculationsMap = {\n First: first,\n Last: last,\n FirstNumber: firstNumber,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n Min: min,\n Max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n description: 'First value',\n },\n Last: {\n label: 'Last',\n description: 'Last value',\n },\n FirstNumber: {\n label: 'First *',\n description: 'First numeric value',\n },\n LastNumber: {\n label: 'Last *',\n description: 'Last numeric value',\n },\n Mean: {\n label: 'Avg',\n description: 'Average value excluding nulls',\n },\n Sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n Min: {\n label: 'Min',\n description: 'Minimum value',\n },\n Max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `Last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'First' in calculations) {\n calculations.First = value;\n }\n if (i === values.length - 1 && 'Last' in calculations) {\n calculations.Last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {\n // Save the first number we see.\n calculations.FirstNumber = value;\n }\n\n if ('LastNumber' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations.LastNumber = value;\n }\n\n if ('Min' in calculations) {\n if (typeof calculations.Min !== 'number') {\n // Init the first time we see a number\n calculations.Min = value;\n } else {\n // Use lowest value once initialized\n calculations.Min = Math.min(calculations.Min, value);\n }\n }\n\n if ('Max' in calculations) {\n if (typeof calculations.Max !== 'number') {\n // Init the first time we see a number\n calculations.Max = value;\n } else {\n // Use highest value once initialized\n calculations.Max = Math.max(calculations.Max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'Sum' in calculations) {\n calculations.Sum = sum;\n }\n\n if (nonNullCount > 0 && 'Mean' in calculations) {\n calculations.Mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'First');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'FirstNumber');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'LastNumber');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Max');\n}\n"],"names":["CalculationsMap","First","first","Last","last","FirstNumber","firstNumber","LastNumber","lastNumber","Mean","mean","Sum","sum","Min","min","Max","max","CALCULATIONS_CONFIG","label","description","DEFAULT_CALCULATION","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","getCalculation"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,WAAW,EAAEC,WAAW;IACxBC,UAAU,EAAEC,UAAU;IACtBC,IAAI,EAAEC,IAAI;IACVC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;CACT,CAAC;AASF,OAAO,MAAMC,mBAAmB,GAAyD;IACvFhB,KAAK,EAAE;QACLiB,KAAK,EAAE,OAAO;QACdC,WAAW,EAAE,aAAa;KAC3B;IACDhB,IAAI,EAAE;QACJe,KAAK,EAAE,MAAM;QACbC,WAAW,EAAE,YAAY;KAC1B;IACDd,WAAW,EAAE;QACXa,KAAK,EAAE,SAAS;QAChBC,WAAW,EAAE,qBAAqB;KACnC;IACDZ,UAAU,EAAE;QACV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
|
|
1
|
+
{"version":3,"sources":["../../src/model/calculations.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\nexport const CalculationsMap = {\n First: first,\n Last: last,\n FirstNumber: firstNumber,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n Min: min,\n Max: max,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n description: string;\n};\n\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n description: 'First value',\n },\n Last: {\n label: 'Last',\n description: 'Last value',\n },\n FirstNumber: {\n label: 'First *',\n description: 'First numeric value',\n },\n LastNumber: {\n label: 'Last *',\n description: 'Last numeric value',\n },\n Mean: {\n label: 'Avg',\n description: 'Average value excluding nulls',\n },\n Sum: {\n label: 'Sum',\n description: 'The sum of all values',\n },\n Min: {\n label: 'Min',\n description: 'Minimum value',\n },\n Max: {\n label: 'Max',\n description: 'Maximum value',\n },\n} as const;\n\ntype CalculationValue = number | null | undefined;\n\n/**\n * Calculate a multiple values for a set of time series data.\n *\n * @param values - Array of time series data.\n * @param includeCalculations - Array of calculations to include.\n */\nexport function getCalculations<IncludeCalcs extends CalculationType[]>(\n values: TimeSeriesValueTuple[],\n includeCalculations: IncludeCalcs\n): Record<\n // This extract combined with the generics above keeps the key of the returned\n // record to *just* the specified calculations.\n Extract<CalculationType, IncludeCalcs[number]>,\n CalculationValue\n> {\n const calculations = includeCalculations.reduce((initResult, calculation) => {\n initResult[calculation] = undefined;\n return initResult;\n }, {} as Record<string, CalculationValue>);\n\n // We save these values as separate values instead of directly setting them\n // in the calculations because they are needed by multiple calculations.\n let nonNullCount = 0;\n let sum = 0;\n\n // We use this large function capable of performing one or more calculations\n // in a single iteration of the data to minimize the performance impact of\n // generating multiple calculations for large timeseries values. This is\n // less optimized for certain single calculations when done in isolation (e.g.\n // `Last`), but will be more performant in the more expensive cases where\n // multiple values are being used (e.g. table legend).\n values.forEach((tuple, i) => {\n const value = tuple[1];\n\n if (i === 0 && 'First' in calculations) {\n calculations.First = value;\n }\n if (i === values.length - 1 && 'Last' in calculations) {\n calculations.Last = value;\n }\n\n // Handling specific to non-null values.\n if (typeof value === 'number') {\n nonNullCount += 1;\n sum += value;\n\n if ('FirstNumber' in calculations && calculations.FirstNumber === undefined) {\n // Save the first number we see.\n calculations.FirstNumber = value;\n }\n\n if ('LastNumber' in calculations) {\n // Keep setting the numbers we see, which will eventually be set to the\n // last number when finished iterating.\n calculations.LastNumber = value;\n }\n\n if ('Min' in calculations) {\n if (typeof calculations.Min !== 'number') {\n // Init the first time we see a number\n calculations.Min = value;\n } else {\n // Use lowest value once initialized\n calculations.Min = Math.min(calculations.Min, value);\n }\n }\n\n if ('Max' in calculations) {\n if (typeof calculations.Max !== 'number') {\n // Init the first time we see a number\n calculations.Max = value;\n } else {\n // Use highest value once initialized\n calculations.Max = Math.max(calculations.Max, value);\n }\n }\n }\n });\n\n // Set calculations that require iterating over all values.\n if (nonNullCount > 0 && 'Sum' in calculations) {\n calculations.Sum = sum;\n }\n\n if (nonNullCount > 0 && 'Mean' in calculations) {\n calculations.Mean = sum / nonNullCount;\n }\n\n return calculations;\n}\n\n/**\n * Calculate a single value for a set of time series data.\n *\n * Use `getCalculations` instead if you need multiple calculations.\n *\n * @param values - Array of time series data.\n * @param calculation - Name of the calculation to calculate.\n */\nexport function getCalculation(values: TimeSeriesValueTuple[], calculation: CalculationType) {\n return getCalculations(values, [calculation])[calculation];\n}\n\nfunction first(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'First');\n}\n\nfunction last(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Last');\n}\n\nfunction firstNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'FirstNumber');\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'LastNumber');\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Mean');\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Sum');\n}\n\nfunction min(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Min');\n}\n\nfunction max(values: TimeSeriesValueTuple[]): CalculationValue {\n return getCalculation(values, 'Max');\n}\n"],"names":["CalculationsMap","First","first","Last","last","FirstNumber","firstNumber","LastNumber","lastNumber","Mean","mean","Sum","sum","Min","min","Max","max","CALCULATIONS_CONFIG","label","description","getCalculations","values","includeCalculations","calculations","reduce","initResult","calculation","undefined","nonNullCount","forEach","tuple","i","value","length","Math","getCalculation"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,WAAW,EAAEC,WAAW;IACxBC,UAAU,EAAEC,UAAU;IACtBC,IAAI,EAAEC,IAAI;IACVC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;IACRC,GAAG,EAAEC,GAAG;CACT,CAAC;AASF,OAAO,MAAMC,mBAAmB,GAAyD;IACvFhB,KAAK,EAAE;QACLiB,KAAK,EAAE,OAAO;QACdC,WAAW,EAAE,aAAa;K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C,CAAC;AACvC,CAAC;AAED,SAASL,GAAG,CAACK,MAA8B,EAAoB;IAC7D,OAAOc,cAAc,CAACd,MAAM,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/datasource.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Metadata, ProjectMetadata } from './resource';\nimport { Display } from './display';\n\n/**\n * A Datasource that's available across all projects.\n */\nexport interface GlobalDatasource {\n kind: 'GlobalDatasource';\n metadata: Metadata;\n spec: DatasourceSpec;\n}\n\n/**\n * A Datasource that belongs to a project.\n */\nexport interface Datasource {\n kind: 'Datasource';\n metadata: ProjectMetadata;\n spec: DatasourceSpec;\n}\n\nexport interface DatasourceSpec<PluginSpec = UnknownSpec> {\n display?: Display;\n default: boolean;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A selector for pointing at a specific Datasource. If name is omitted, it's assumed that you want the default\n * Datasource for the specified kind.\n */\nexport interface DatasourceSelector {\n kind: string;\n name?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAmCC"}
|
|
1
|
+
{"version":3,"sources":["../../src/model/datasource.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { Metadata, ProjectMetadata } from './resource';\nimport { Display } from './display';\n\n/**\n * A Datasource that's available across all projects.\n */\nexport interface GlobalDatasource {\n kind: 'GlobalDatasource';\n metadata: Metadata;\n spec: DatasourceSpec;\n}\n\n/**\n * A Datasource resource, that belongs to a project.\n */\nexport interface Datasource {\n kind: 'Datasource';\n metadata: ProjectMetadata;\n spec: DatasourceSpec;\n}\n\nexport interface DatasourceSpec<PluginSpec = UnknownSpec> {\n display?: Display;\n default: boolean;\n plugin: Definition<PluginSpec>;\n}\n\n/**\n * A selector for pointing at a specific Datasource. If name is omitted, it's assumed that you want the default\n * Datasource for the specified kind.\n */\nexport interface DatasourceSelector {\n kind: string;\n name?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAmCC"}
|
package/dist/model/query.d.ts
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import { Definition, UnknownSpec } from './definitions';
|
|
2
|
+
import { TimeSeriesData } from './time-series-data';
|
|
2
3
|
interface QuerySpec<PluginSpec> {
|
|
3
4
|
plugin: Definition<PluginSpec>;
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
7
|
* A generic query definition interface that can be extended to support more than just TimeSeriesQuery
|
|
7
8
|
*/
|
|
8
|
-
export interface QueryDefinition<Kind =
|
|
9
|
+
export interface QueryDefinition<Kind = any, PluginSpec = UnknownSpec> {
|
|
9
10
|
kind: Kind;
|
|
10
11
|
spec: QuerySpec<PluginSpec>;
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Mapping the query plugin to the data type it returns
|
|
15
|
+
*/
|
|
16
|
+
export interface QueryType {
|
|
17
|
+
TimeSeriesQuery: TimeSeriesData;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Values of QueryType
|
|
21
|
+
* ex: 'TimeSeriesData'
|
|
22
|
+
*/
|
|
23
|
+
export declare type QueryDataType = QueryType[keyof QueryType];
|
|
13
24
|
export {};
|
|
14
25
|
//# sourceMappingURL=query.d.ts.map
|
|
@@ -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;
|
|
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;AAEpD,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;CAGjC;AAED;;;GAGG;AACH,oBAAY,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 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\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 */\nexport interface QueryDefinition<Kind =
|
|
1
|
+
{"version":3,"sources":["../../src/model/query.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, UnknownSpec } from './definitions';\nimport { TimeSeriesData } from './time-series-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 // 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 * Values of QueryType\n * ex: 'TimeSeriesData'\n */\nexport type QueryDataType = QueryType[keyof QueryType];\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WA6BuD"}
|
|
@@ -21,5 +21,11 @@ export interface TimeSeries {
|
|
|
21
21
|
}
|
|
22
22
|
export interface TimeSeriesMetadata {
|
|
23
23
|
notices?: Notice[];
|
|
24
|
+
/**
|
|
25
|
+
* The raw query that is executed to generate this data.
|
|
26
|
+
* Useful when needing to inspect the query that was executed
|
|
27
|
+
* after variables and other context modifications have been applied.
|
|
28
|
+
*/
|
|
29
|
+
executedQueryString?: string;
|
|
24
30
|
}
|
|
25
31
|
//# sourceMappingURL=time-series-data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/model/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAErE,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/model/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAErE,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Notice } from './notice';\nimport { AbsoluteTimeRange } from './time';\nimport { Labels, TimeSeriesValueTuple } from './time-series-queries';\n\nexport interface TimeScale {\n startMs: number;\n endMs: number;\n stepMs: number;\n rangeMs: number;\n}\n\nexport interface TimeSeriesData {\n timeRange?: AbsoluteTimeRange;\n stepMs?: number;\n series: TimeSeries[];\n metadata?: TimeSeriesMetadata;\n}\n\nexport interface TimeSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n formattedName?: string;\n labels?: Labels;\n}\n\nexport interface TimeSeriesMetadata {\n notices?: Notice[];\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,
|
|
1
|
+
{"version":3,"sources":["../../src/model/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Notice } from './notice';\nimport { AbsoluteTimeRange } from './time';\nimport { Labels, TimeSeriesValueTuple } from './time-series-queries';\n\nexport interface TimeScale {\n startMs: number;\n endMs: number;\n stepMs: number;\n rangeMs: number;\n}\n\nexport interface TimeSeriesData {\n timeRange?: AbsoluteTimeRange;\n stepMs?: number;\n series: TimeSeries[];\n metadata?: TimeSeriesMetadata;\n}\n\nexport interface TimeSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n formattedName?: string;\n labels?: Labels;\n}\n\nexport interface TimeSeriesMetadata {\n notices?: Notice[];\n\n /**\n * The raw query that is executed to generate this data.\n * Useful when needing to inspect the query that was executed\n * after variables and other context modifications have been applied.\n */\n executedQueryString?: string;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAkCC"}
|
|
@@ -8,6 +8,6 @@ export declare type BytesUnitOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
|
|
10
10
|
export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
|
|
11
|
-
export declare function formatBytes(bytes: number,
|
|
11
|
+
export declare function formatBytes(bytes: number, { abbreviate, decimal_places }: BytesUnitOptions): string;
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -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;AAatD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,gBAAgB,UAmC1F"}
|
|
@@ -13,7 +13,13 @@
|
|
|
13
13
|
import numbro from 'numbro';
|
|
14
14
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
15
15
|
import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* We consider the units for bytes to be powers of 1000.
|
|
18
|
+
* In other words:
|
|
19
|
+
* 1 KB = 1000 bytes (1000^1 bytes)
|
|
20
|
+
* 1 MB = 1,000,000 bytes (1000^2 bytes)
|
|
21
|
+
* etc.
|
|
22
|
+
*/ const DEFAULT_NUMBRO_MANTISSA = 2;
|
|
17
23
|
const bytesUnitKinds = [
|
|
18
24
|
'Bytes'
|
|
19
25
|
];
|
|
@@ -23,15 +29,13 @@ export const BYTES_GROUP_CONFIG = {
|
|
|
23
29
|
abbreviate: true
|
|
24
30
|
};
|
|
25
31
|
export const BYTES_UNIT_CONFIG = {
|
|
26
|
-
// These units are powers of 1000.
|
|
27
|
-
// In other words, 1 KB = 1000 bytes.
|
|
28
32
|
Bytes: {
|
|
29
33
|
group: 'Bytes',
|
|
30
34
|
label: 'Bytes'
|
|
31
35
|
}
|
|
32
36
|
};
|
|
33
|
-
export function formatBytes(bytes,
|
|
34
|
-
|
|
37
|
+
export function formatBytes(bytes, { abbreviate , decimal_places }) {
|
|
38
|
+
// If we're showing the entire value, we can use Intl.NumberFormat.
|
|
35
39
|
if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
|
|
36
40
|
const formatterOptions = {
|
|
37
41
|
style: 'unit',
|
|
@@ -48,9 +52,11 @@ export function formatBytes(bytes, options) {
|
|
|
48
52
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
56
|
+
return formatter.format(bytes);
|
|
52
57
|
}
|
|
53
|
-
//
|
|
58
|
+
// If we're showing the "abbreviated" value, we use numbro.
|
|
59
|
+
// numbro is able to add units like KB, MB, GB, etc. correctly.
|
|
54
60
|
return numbro(bytes).format({
|
|
55
61
|
output: 'byte',
|
|
56
62
|
base: 'decimal',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = (typeof bytesUnitKinds)[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\n/**\n * We consider the units for bytes to be powers of 1000.\n * In other words:\n * 1 KB = 1000 bytes (1000^1 bytes)\n * 1 MB = 1,000,000 bytes (1000^2 bytes)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = (typeof bytesUnitKinds)[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\nexport function formatBytes(bytes: number, { abbreviate, decimal_places }: BytesUnitOptions) {\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n // This can happen if bytes is between -1000 and 1000\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(bytes);\n }\n\n // If we're showing the \"abbreviated\" 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: 'decimal',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimal_places),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimal_places),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","DEFAULT_NUMBRO_MANTISSA","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","Math","abs","formatterOptions","style","unit","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,MAAM,MAAM,QAAQ,CAAC;AAE5B,SAASC,s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AC/D,OAAOQ,SAAS,CAACG,MAAM,CAACd,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,2DAA2D;IAC3D,+DAA+D;IAC/D,OAAOf,MAAM,CAACe,KAAK,CAAC,CAACc,MAAM,CAAC;QAC1BC,MAAM,EAAE,MAAM;QACdC,IAAI,EAAE,SAAS;QACfC,cAAc,EAAE,IAAI;QACpBC,QAAQ,EAAE/B,gBAAgB,CAACO,cAAc,CAAC,GAAGA,cAAc,GAAGJ,uBAAuB;QACrF,iCAAiC;QACjC6B,YAAY,EAAE,CAAChC,gBAAgB,CAACO,cAAc,CAAC;QAC/C,wEAAwE;QACxE0B,gBAAgB,EAAE,CAACjC,gBAAgB,CAACO,cAAc,CAAC;KACpD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -8,6 +8,6 @@ export declare type DecimalUnitOptions = {
|
|
|
8
8
|
};
|
|
9
9
|
export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
|
|
10
10
|
export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>>;
|
|
11
|
-
export declare function formatDecimal(value: number,
|
|
11
|
+
export declare function formatDecimal(value: number, { abbreviate, decimal_places }: DecimalUnitOptions): string;
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=decimal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAqBvG"}
|
|
@@ -26,8 +26,7 @@ export const DECIMAL_UNIT_CONFIG = {
|
|
|
26
26
|
label: 'Decimal'
|
|
27
27
|
}
|
|
28
28
|
};
|
|
29
|
-
export function formatDecimal(value,
|
|
30
|
-
const { abbreviate , decimal_places } = options;
|
|
29
|
+
export function formatDecimal(value, { abbreviate , decimal_places }) {
|
|
31
30
|
const formatterOptions = {
|
|
32
31
|
style: 'decimal',
|
|
33
32
|
useGrouping: true
|
|
@@ -43,7 +42,8 @@ export function formatDecimal(value, options) {
|
|
|
43
42
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
|
-
|
|
45
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
46
|
+
return formatter.format(value);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
//# sourceMappingURL=decimal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst decimalUnitKinds = ['Decimal'] as const;\ntype DecimalUnitKind = (typeof decimalUnitKinds)[number];\nexport type DecimalUnitOptions = {\n kind: DecimalUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimal_places: true,\n abbreviate: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>> = {\n Decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number,
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst decimalUnitKinds = ['Decimal'] as const;\ntype DecimalUnitKind = (typeof decimalUnitKinds)[number];\nexport type DecimalUnitOptions = {\n kind: DecimalUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimal_places: true,\n abbreviate: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>> = {\n Decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { abbreviate, decimal_places }: DecimalUnitOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","decimalUnitKinds","DECIMAL_GROUP_CONFIG","label","decimal_places","abbreviate","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCA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AAC,OAAO,EAAET,gBAAgB,CAAC,AAAC;IAC/D,OAAOO,SAAS,CAACG,MAAM,CAACX,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AACrE,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAgB7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AACrE,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAgB7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAoBjG"}
|
|
@@ -40,10 +40,6 @@ export const PERCENT_UNIT_CONFIG = {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
export function formatPercent(value, { kind , decimal_places }) {
|
|
43
|
-
// Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
|
|
44
|
-
if (kind === 'Percent') {
|
|
45
|
-
value = value / 100;
|
|
46
|
-
}
|
|
47
43
|
const formatterOptions = {
|
|
48
44
|
style: 'percent',
|
|
49
45
|
useGrouping: true
|
|
@@ -54,7 +50,12 @@ export function formatPercent(value, { kind , decimal_places }) {
|
|
|
54
50
|
} else {
|
|
55
51
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
56
52
|
}
|
|
57
|
-
|
|
53
|
+
// Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.
|
|
54
|
+
if (kind === 'Percent') {
|
|
55
|
+
value = value / 100;
|
|
56
|
+
}
|
|
57
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
58
|
+
return formatter.format(value);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
//# sourceMappingURL=percent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst percentUnitKinds = ['Percent', 'PercentDecimal', '%'] as const;\ntype PercentUnitKind = (typeof percentUnitKinds)[number];\nexport type PercentUnitOptions = {\n kind: PercentUnitKind;\n decimal_places?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>> = {\n Percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n PercentDecimal: {\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, { kind, decimal_places }: PercentUnitOptions): string {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst percentUnitKinds = ['Percent', 'PercentDecimal', '%'] as const;\ntype PercentUnitKind = (typeof percentUnitKinds)[number];\nexport type PercentUnitOptions = {\n kind: PercentUnitKind;\n decimal_places?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>> = {\n Percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n PercentDecimal: {\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, { kind, decimal_places }: PercentUnitOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.\n if (kind === 'Percent') {\n value = value / 100;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","percentUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","PERCENT_GROUP","PERCENT_UNIT_CONFIG","Percent","group","PercentDecimal","disableSelectorOption","formatPercent","value","kind","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,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,AAAC;IAC/D,OAAOM,SAAS,CAACG,MAAM,CAACX,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAiCvE,CAAC;AAIF,oBAAY,oBAAoB;IAC9B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAiCvE,CAAC;AAIF,oBAAY,oBAAoB;IAC9B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AAwDD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,eAAe,GAAG,MAAM,CAoB3F"}
|
package/dist/model/units/time.js
CHANGED
|
@@ -72,12 +72,64 @@ export var PersesTimeToIntlTime;
|
|
|
72
72
|
PersesTimeToIntlTime["Months"] = 'month';
|
|
73
73
|
PersesTimeToIntlTime["Years"] = 'year';
|
|
74
74
|
})(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
|
|
75
|
+
/**
|
|
76
|
+
* Note: This conversion will not be exactly accurate for months and years,
|
|
77
|
+
* due variations in the lengths of months (i.e. 28 - 31 days) and years (i.e. leap years).
|
|
78
|
+
* For precision with months and years, we would need more complex algorithms and/or external libraries.
|
|
79
|
+
* However, we expect that measurements in months and years will be rare.
|
|
80
|
+
*/ const TIME_UNITS_IN_SECONDS = {
|
|
81
|
+
Years: 31536000,
|
|
82
|
+
Months: 2592000,
|
|
83
|
+
Weeks: 604800,
|
|
84
|
+
Days: 86400,
|
|
85
|
+
Hours: 3600,
|
|
86
|
+
Minutes: 60,
|
|
87
|
+
Seconds: 1,
|
|
88
|
+
Milliseconds: 0.001
|
|
89
|
+
};
|
|
90
|
+
const LARGEST_TO_SMALLEST_TIME_UNITS = [
|
|
91
|
+
'Years',
|
|
92
|
+
'Months',
|
|
93
|
+
'Weeks',
|
|
94
|
+
'Days',
|
|
95
|
+
'Hours',
|
|
96
|
+
'Minutes',
|
|
97
|
+
'Seconds',
|
|
98
|
+
'Milliseconds'
|
|
99
|
+
];
|
|
100
|
+
/**
|
|
101
|
+
* Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.
|
|
102
|
+
*/ function getValueAndKindForNaturalNumbers(value, kind) {
|
|
103
|
+
const valueInSeconds = value * TIME_UNITS_IN_SECONDS[kind];
|
|
104
|
+
// Initialize for TS
|
|
105
|
+
const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'Years';
|
|
106
|
+
let timeUnit = largestTimeUnit;
|
|
107
|
+
let valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];
|
|
108
|
+
for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS){
|
|
109
|
+
valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];
|
|
110
|
+
if (valueInTimeUnit >= 1) {
|
|
111
|
+
return {
|
|
112
|
+
value: valueInTimeUnit,
|
|
113
|
+
kind: timeUnit
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).
|
|
118
|
+
return {
|
|
119
|
+
value: valueInTimeUnit,
|
|
120
|
+
kind: timeUnit
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function isMonthOrYear(kind) {
|
|
124
|
+
return kind === 'Months' || kind === 'Years';
|
|
125
|
+
}
|
|
75
126
|
export function formatTime(value, { kind , decimal_places }) {
|
|
76
|
-
|
|
127
|
+
if (value === 0) return '0s';
|
|
128
|
+
const results = getValueAndKindForNaturalNumbers(value, kind);
|
|
77
129
|
const formatterOptions = {
|
|
78
130
|
style: 'unit',
|
|
79
|
-
unit: PersesTimeToIntlTime[kind],
|
|
80
|
-
unitDisplay: isMonthOrYear ? 'long' : 'narrow'
|
|
131
|
+
unit: PersesTimeToIntlTime[results.kind],
|
|
132
|
+
unitDisplay: isMonthOrYear(results.kind) ? 'long' : 'narrow'
|
|
81
133
|
};
|
|
82
134
|
if (hasDecimalPlaces(decimal_places)) {
|
|
83
135
|
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
|
|
@@ -85,7 +137,8 @@ export function formatTime(value, { kind , decimal_places }) {
|
|
|
85
137
|
} else {
|
|
86
138
|
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
87
139
|
}
|
|
88
|
-
|
|
140
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
141
|
+
return formatter.format(results.value);
|
|
89
142
|
}
|
|
90
143
|
|
|
91
144
|
//# sourceMappingURL=time.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst timeUnitKinds = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years'] as const;\ntype TimeUnitKind = (typeof timeUnitKinds)[number];\nexport type TimeUnitOptions = {\n kind: TimeUnitKind;\n decimal_places?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimal_places: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>> = {\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 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\
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst timeUnitKinds = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years'] as const;\ntype TimeUnitKind = (typeof timeUnitKinds)[number];\nexport type TimeUnitOptions = {\n kind: TimeUnitKind;\n decimal_places?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimal_places: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>> = {\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 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<TimeUnitKind, number> = {\n Years: 31536000, // 365 days\n Months: 2592000, // 30 days\n Weeks: 604800,\n Days: 86400,\n Hours: 3600,\n Minutes: 60,\n Seconds: 1,\n Milliseconds: 0.001,\n};\n\nconst LARGEST_TO_SMALLEST_TIME_UNITS: TimeUnitKind[] = [\n 'Years',\n 'Months',\n 'Weeks',\n 'Days',\n 'Hours',\n 'Minutes',\n 'Seconds',\n 'Milliseconds',\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, kind: TimeUnitKind): { value: number; kind: TimeUnitKind } {\n const valueInSeconds = value * TIME_UNITS_IN_SECONDS[kind];\n\n // Initialize for TS\n const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'Years';\n let timeUnit: TimeUnitKind = 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, kind: 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, kind: timeUnit };\n}\n\nfunction isMonthOrYear(kind: TimeUnitKind): boolean {\n return kind === 'Months' || kind === 'Years';\n}\n\nexport function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string {\n if (value === 0) return '0s';\n\n const results = getValueAndKindForNaturalNumbers(value, kind);\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: PersesTimeToIntlTime[results.kind],\n unitDisplay: isMonthOrYear(results.kind) ? 'long' : 'narrow',\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(results.value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","timeUnitKinds","TIME_GROUP","TIME_GROUP_CONFIG","label","decimal_places","TIME_UNIT_CONFIG","Milliseconds","group","Seconds","Minutes","Hours","Days","Weeks","Months","Years","PersesTimeToIntlTime","TIME_UNITS_IN_SECONDS","LARGEST_TO_SMALLEST_TIME_UNITS","getValueAndKindForNaturalNumbers","value","kind","valueInSeconds","largestTimeUnit","timeUnit","valueInTimeUnit","isMonthOrYear","formatTime","results","formatterOptions","style","unit","unitDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E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K,eAAe;QAAEJ,IAAI,EAAEG,QAAQ;KAAE,CAAC;AACpD,CAAC;AAED,SAASE,aAAa,CAACL,IAAkB,EAAW;IAClD,OAAOA,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,OAAO,CAAC;AAC/C,CAAC;AAED,OAAO,SAASM,UAAU,CAACP,KAAa,EAAE,EAAEC,IAAI,CAAA,EAAEhB,cAAc,CAAA,EAAmB,EAAU;IAC3F,IAAIe,KAAK,KAAK,CAAC,EAAE,OAAO,IAAI,CAAC;IAE7B,MAAMQ,OAAO,GAAGT,gCAAgC,CAACC,KAAK,EAAEC,IAAI,CAAC,AAAC;IAE9D,MAAMQ,gBAAgB,GAA6B;QACjDC,KAAK,EAAE,MAAM;QACbC,IAAI,EAAEf,oBAAoB,CAACY,OAAO,CAACP,IAAI,CAAC;QACxCW,WAAW,EAAEN,aAAa,CAACE,OAAO,CAACP,IAAI,CAAC,GAAG,MAAM,GAAG,QAAQ;KAC7D,AAAC;IAEF,IAAItB,gBAAgB,CAACM,cAAc,CAAC,EAAE;QACpCwB,gBAAgB,CAACI,qBAAqB,GAAGjC,kBAAkB,CAACK,cAAc,CAAC,CAAC;QAC5EwB,gBAAgB,CAACK,qBAAqB,GAAGlC,kBAAkB,CAACK,cAAc,CAAC,CAAC;IAC9E,OAAO;QACLwB,gBAAgB,CAACM,wBAAwB,GAAGrC,sBAAsB,CAAC;IACrE,CAAC;IAED,MAAMsC,SAAS,GAAGC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAET,gBAAgB,CAAC,AAAC;IAC/D,OAAOO,SAAS,CAACG,MAAM,CAACX,OAAO,CAACR,KAAK,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -3,6 +3,13 @@ import { DecimalUnitOptions } from './decimal';
|
|
|
3
3
|
import { PercentUnitOptions } from './percent';
|
|
4
4
|
import { TimeUnitOptions } from './time';
|
|
5
5
|
import { UnitGroup, UnitGroupConfig, UnitConfig } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.
|
|
8
|
+
* Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.
|
|
9
|
+
*
|
|
10
|
+
* To format bytes, we also make use of the `numbro` package,
|
|
11
|
+
* because it can handle adding units like KB, MB, GB, etc. correctly.
|
|
12
|
+
*/
|
|
6
13
|
export declare const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>>;
|
|
7
14
|
export declare const UNIT_CONFIG: {
|
|
8
15
|
readonly Bytes: UnitConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.ts"],"names":[],"mappings":"AAaA,OAAO,EAAe,gBAAgB,EAAyC,MAAM,SAAS,CAAC;AAC/F,OAAO,EAAiB,kBAAkB,EAA6C,MAAM,WAAW,CAAC;AACzG,OAAO,EAAiB,kBAAkB,EAA6C,MAAM,WAAW,CAAC;AACzG,OAAO,EAAc,eAAe,EAAuC,MAAM,QAAQ,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;;;GAMG;AAEH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,CAK1E,CAAC;AACF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CAKd,CAAC;AAEX,oBAAY,WAAW,GAAG,eAAe,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAEvG,aAAK,gBAAgB,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAC/F,aAAK,aAAa,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,CAuB5E;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAEtE;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAEhE;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,eAAe,CAG5E;AAGD,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,eAAe,CAEnF;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,kBAAkB,CAEzF;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,kBAAkB,CAEzF;AAED,wBAAgB,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,gBAAgB,CAErF;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAI9G;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,aAAa,CAAC,WAAW,CAAC,CAIxG"}
|
|
@@ -10,11 +10,17 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
13
|
+
import { formatBytes, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG } from './bytes';
|
|
14
|
+
import { formatDecimal, DECIMAL_GROUP_CONFIG, DECIMAL_UNIT_CONFIG } from './decimal';
|
|
15
|
+
import { formatPercent, PERCENT_GROUP_CONFIG, PERCENT_UNIT_CONFIG } from './percent';
|
|
16
16
|
import { formatTime, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.
|
|
19
|
+
* Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.
|
|
20
|
+
*
|
|
21
|
+
* To format bytes, we also make use of the `numbro` package,
|
|
22
|
+
* because it can handle adding units like KB, MB, GB, etc. correctly.
|
|
23
|
+
*/ export const UNIT_GROUP_CONFIG = {
|
|
18
24
|
Time: TIME_GROUP_CONFIG,
|
|
19
25
|
Percent: PERCENT_GROUP_CONFIG,
|
|
20
26
|
Decimal: DECIMAL_GROUP_CONFIG,
|
|
@@ -30,17 +36,17 @@ export function formatValue(value, unitOptions) {
|
|
|
30
36
|
if (unitOptions === undefined) {
|
|
31
37
|
return value.toString();
|
|
32
38
|
}
|
|
39
|
+
if (isBytesUnit(unitOptions)) {
|
|
40
|
+
return formatBytes(value, unitOptions);
|
|
41
|
+
}
|
|
33
42
|
if (isDecimalUnit(unitOptions)) {
|
|
34
43
|
return formatDecimal(value, unitOptions);
|
|
35
44
|
}
|
|
36
|
-
if (isTimeUnit(unitOptions)) {
|
|
37
|
-
return formatTime(value, unitOptions);
|
|
38
|
-
}
|
|
39
45
|
if (isPercentUnit(unitOptions)) {
|
|
40
46
|
return formatPercent(value, unitOptions);
|
|
41
47
|
}
|
|
42
|
-
if (
|
|
43
|
-
return
|
|
48
|
+
if (isTimeUnit(unitOptions)) {
|
|
49
|
+
return formatTime(value, unitOptions);
|
|
44
50
|
}
|
|
45
51
|
const exhaustive = unitOptions;
|
|
46
52
|
throw new Error(`Unknown unit options ${exhaustive}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/units.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BytesUnitOptions, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/units.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { formatBytes, BytesUnitOptions, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG } from './bytes';\nimport { formatDecimal, DecimalUnitOptions, DECIMAL_GROUP_CONFIG, DECIMAL_UNIT_CONFIG } from './decimal';\nimport { formatPercent, PercentUnitOptions, PERCENT_GROUP_CONFIG, PERCENT_UNIT_CONFIG } from './percent';\nimport { formatTime, TimeUnitOptions, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\n\n/**\n * Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.\n * Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.\n *\n * To format bytes, we also make use of the `numbro` package,\n * because it can handle adding units like KB, MB, GB, etc. correctly.\n */\n\nexport const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>> = {\n Time: TIME_GROUP_CONFIG,\n Percent: PERCENT_GROUP_CONFIG,\n Decimal: DECIMAL_GROUP_CONFIG,\n Bytes: BYTES_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n} as const;\n\nexport type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;\n\ntype HasDecimalPlaces<UnitOpt> = UnitOpt extends { decimal_places?: number } ? UnitOpt : never;\ntype HasAbbreviate<UnitOpt> = UnitOpt extends { abbreviate?: boolean } ? UnitOpt : never;\n\nexport function formatValue(value: number, unitOptions?: UnitOptions): string {\n if (unitOptions === undefined) {\n return value.toString();\n }\n\n if (isBytesUnit(unitOptions)) {\n return formatBytes(value, unitOptions);\n }\n\n if (isDecimalUnit(unitOptions)) {\n return formatDecimal(value, unitOptions);\n }\n\n if (isPercentUnit(unitOptions)) {\n return formatPercent(value, unitOptions);\n }\n\n if (isTimeUnit(unitOptions)) {\n return formatTime(value, unitOptions);\n }\n\n const exhaustive: never = unitOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n}\n\nexport function getUnitKindConfig(unitOptions: UnitOptions): UnitConfig {\n return UNIT_CONFIG[unitOptions.kind];\n}\n\nexport function getUnitGroup(unitOptions: UnitOptions): UnitGroup {\n return getUnitKindConfig(unitOptions).group;\n}\n\nexport function getUnitGroupConfig(unitOptions: UnitOptions): UnitGroupConfig {\n const unitConfig = getUnitKindConfig(unitOptions);\n return UNIT_GROUP_CONFIG[unitConfig.group];\n}\n\n// Type guards\nexport function isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions {\n return getUnitGroup(unitOptions) === 'Time';\n}\n\nexport function isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions {\n return getUnitGroup(unitOptions) === 'Percent';\n}\n\nexport function isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions {\n return getUnitGroup(unitOptions) === 'Decimal';\n}\n\nexport function isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions {\n return getUnitGroup(unitOptions) === 'Bytes';\n}\n\nexport function isUnitWithDecimalPlaces(unitOptions: UnitOptions): unitOptions is HasDecimalPlaces<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.decimal_places;\n}\n\nexport function isUnitWithAbbreviate(unitOptions: UnitOptions): unitOptions is HasAbbreviate<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.abbreviate;\n}\n"],"names":["formatBytes","BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatDecimal","DECIMAL_GROUP_CONFIG","DECIMAL_UNIT_CONFIG","formatPercent","PERCENT_GROUP_CONFIG","PERCENT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","UNIT_CONFIG","formatValue","value","unitOptions","undefined","toString","isBytesUnit","isDecimalUnit","isPercentUnit","isTimeUnit","exhaustive","Error","getUnitKindConfig","kind","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","decimal_places","isUnitWithAbbreviate","abbreviate"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,EAAoBC,kBAAkB,EAAEC,iBAAiB,QAAQ,SAAS,CAAC;AAC/F,SAASC,aAAa,EAAsBC,oBAAoB,EAAEC,mBAAmB,QAAQ,WAAW,CAAC;AACzG,SAASC,aAAa,EAAsBC,oBAAoB,EAAEC,mBAAmB,QAAQ,WAAW,CAAC;AACzG,SAASC,UAAU,EAAmBC,iBAAiB,EAAEC,gBAAgB,QA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EAAa;IAChE,OAAOS,iBAAiB,CAACT,WAAW,CAAC,CAACY,KAAK,CAAC;AAC9C,CAAC;AAED,OAAO,SAASC,kBAAkB,CAACb,WAAwB,EAAmB;IAC5E,MAAMc,UAAU,GAAGL,iBAAiB,CAACT,WAAW,CAAC,AAAC;IAClD,OAAOR,iBAAiB,CAACsB,UAAU,CAACF,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,cAAc;AACd,OAAO,SAASN,UAAU,CAACN,WAAwB,EAAkC;IACnF,OAAOW,YAAY,CAACX,WAAW,CAAC,KAAK,MAAM,CAAC;AAC9C,CAAC;AAED,OAAO,SAASK,aAAa,CAACL,WAAwB,EAAqC;IACzF,OAAOW,YAAY,CAACX,WAAW,CAAC,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,OAAO,SAASI,aAAa,CAACJ,WAAwB,EAAqC;IACzF,OAAOW,YAAY,CAACX,WAAW,CAAC,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,OAAO,SAASG,WAAW,CAACH,WAAwB,EAAmC;IACrF,OAAOW,YAAY,CAACX,WAAW,CAAC,KAAK,OAAO,CAAC;AAC/C,CAAC;AAED,OAAO,SAASe,uBAAuB,CAACf,WAAwB,EAAgD;IAC9G,MAAMgB,WAAW,GAAGH,kBAAkB,CAACb,WAAW,CAAC,AAAC;IAEpD,OAAO,CAAC,CAACgB,WAAW,CAACC,cAAc,CAAC;AACtC,CAAC;AAED,OAAO,SAASC,oBAAoB,CAAClB,WAAwB,EAA6C;IACxG,MAAMgB,WAAW,GAAGH,kBAAkB,CAACb,WAAW,CAAC,AAAC;IAEpD,OAAO,CAAC,CAACgB,WAAW,CAACG,UAAU,CAAC;AAClC,CAAC"}
|
package/dist/utils/text.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DashboardResource, VariableResource } from '../model';
|
|
1
|
+
import { Datasource, DashboardResource, VariableResource } from '../model';
|
|
2
2
|
/**
|
|
3
3
|
* If the dashboard has a display name, return the dashboard display name
|
|
4
4
|
* Else, only return the dashboard name
|
|
@@ -11,6 +11,12 @@ export declare function getDashboardDisplayName(dashboard: DashboardResource): s
|
|
|
11
11
|
* @param variable Project or Global variable
|
|
12
12
|
*/
|
|
13
13
|
export declare function getVariableDisplayName(variable: VariableResource): string;
|
|
14
|
+
/**
|
|
15
|
+
* If the variable has a display name, return the datasource display name
|
|
16
|
+
* Else, only return the datasource name
|
|
17
|
+
* @param variable Project or Global datasource
|
|
18
|
+
*/
|
|
19
|
+
export declare function getDatasourceDisplayName(datasource: Datasource): string;
|
|
14
20
|
/**
|
|
15
21
|
* If the dashboard has a display name, return the dashboard display name and the dashboard name
|
|
16
22
|
* Else, only return the dashboard name
|
|
@@ -23,4 +29,10 @@ export declare function getDashboardExtendedDisplayName(dashboard: DashboardReso
|
|
|
23
29
|
* @param variable Project or Global variable
|
|
24
30
|
*/
|
|
25
31
|
export declare function getVariableExtendedDisplayName(variable: VariableResource): string;
|
|
32
|
+
/**
|
|
33
|
+
* If the datasource has a display name, return the datasource display name and the datasource name
|
|
34
|
+
* Else, only return the datasource name
|
|
35
|
+
* @param variable Project or Global datasource
|
|
36
|
+
*/
|
|
37
|
+
export declare function getDatasourceExtendedDisplayName(datasource: Datasource): string;
|
|
26
38
|
//# sourceMappingURL=text.d.ts.map
|
package/dist/utils/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/utils/text.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE3E;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,iBAAiB,UAEnE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,UAEhE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,UAAU,UAE9D;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,SAAS,EAAE,iBAAiB,UAK3E;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,gBAAgB,UAKxE;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAAC,UAAU,EAAE,UAAU,UAKtE"}
|
package/dist/utils/text.js
CHANGED
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
var ref1;
|
|
29
29
|
return (ref1 = (ref = variable.spec.spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : variable.metadata.name;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* If the variable has a display name, return the datasource display name
|
|
33
|
+
* Else, only return the datasource name
|
|
34
|
+
* @param variable Project or Global datasource
|
|
35
|
+
*/ export function getDatasourceDisplayName(datasource) {
|
|
36
|
+
var ref;
|
|
37
|
+
return ((ref = datasource.spec.display) === null || ref === void 0 ? void 0 : ref.name) || datasource.metadata.name;
|
|
38
|
+
}
|
|
31
39
|
/**
|
|
32
40
|
* If the dashboard has a display name, return the dashboard display name and the dashboard name
|
|
33
41
|
* Else, only return the dashboard name
|
|
@@ -50,5 +58,16 @@
|
|
|
50
58
|
}
|
|
51
59
|
return variable.metadata.name;
|
|
52
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* If the datasource has a display name, return the datasource display name and the datasource name
|
|
63
|
+
* Else, only return the datasource name
|
|
64
|
+
* @param variable Project or Global datasource
|
|
65
|
+
*/ export function getDatasourceExtendedDisplayName(datasource) {
|
|
66
|
+
var ref;
|
|
67
|
+
if ((ref = datasource.spec.display) === null || ref === void 0 ? void 0 : ref.name) {
|
|
68
|
+
return `${datasource.spec.display.name} (ID: ${datasource.metadata.name})`;
|
|
69
|
+
}
|
|
70
|
+
return datasource.metadata.name;
|
|
71
|
+
}
|
|
53
72
|
|
|
54
73
|
//# sourceMappingURL=text.js.map
|
package/dist/utils/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/text.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DashboardResource, VariableResource } from '../model';\n\n/**\n * If the dashboard has a display name, return the dashboard display name\n * Else, only return the dashboard name\n * @param dashboard\n */\nexport function getDashboardDisplayName(dashboard: DashboardResource) {\n return dashboard.spec.display?.name ?? dashboard.metadata.name;\n}\n\n/**\n * If the variable has a display name, return the variable display name\n * Else, only return the variable name\n * @param variable Project or Global variable\n */\nexport function getVariableDisplayName(variable: VariableResource) {\n return variable.spec.spec.display?.name ?? variable.metadata.name;\n}\n\n/**\n * If the dashboard has a display name, return the dashboard display name and the dashboard name\n * Else, only return the dashboard name\n * @param dashboard\n */\nexport function getDashboardExtendedDisplayName(dashboard: DashboardResource) {\n if (dashboard.spec.display?.name) {\n return `${dashboard.spec.display.name} (Name: ${dashboard.metadata.name})`;\n }\n return dashboard.metadata.name;\n}\n\n/**\n * If the variable has a display name, return the variable display name and the variable name\n * Else, only return the variable name\n * @param variable Project or Global variable\n */\nexport function getVariableExtendedDisplayName(variable: VariableResource) {\n if (variable.spec.spec.display?.name) {\n return `${variable.spec.spec.display.name} (Name: ${variable.metadata.name})`;\n }\n return variable.metadata.name;\n}\n"],"names":["getDashboardDisplayName","dashboard","spec","display","name","metadata","getVariableDisplayName","variable","getDashboardExtendedDisplayName","getVariableExtendedDisplayName"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC;;;;CAIC,GACD,OAAO,SAASA,uBAAuB,CAACC,SAA4B,EAAE;QAC7DA,GAAsB;QAAtBA,IAA4B;IAAnC,OAAOA,CAAAA,IAA4B,GAA5BA,CAAAA,GAAsB,GAAtBA,SAAS,CAACC,IAAI,CAACC,OAAO,cAAtBF,GAAsB,WAAM,GAA5BA,KAAAA,CAA4B,GAA5BA,GAAsB,CAAEG,IAAI,cAA5BH,IAA4B,cAA5BA,IAA4B,GAAIA,SAAS,CAACI,QAAQ,CAACD,IAAI,CAAC;AACjE,CAAC;AAED;;;;CAIC,GACD,OAAO,SAASE,sBAAsB,CAACC,QAA0B,EAAE;QAC1DA,GAA0B;QAA1BA,IAAgC;IAAvC,OAAOA,CAAAA,IAAgC,GAAhCA,CAAAA,GAA0B,GAA1BA,QAAQ,CAACL,IAAI,CAACA,IAAI,CAACC,OAAO,cAA1BI,GAA0B,WAAM,GAAhCA,KAAAA,CAAgC,GAAhCA,GAA0B,CAAEH,IAAI,cAAhCG,IAAgC,cAAhCA,IAAgC,GAAIA,QAAQ,CAACF,QAAQ,CAACD,IAAI,CAAC;AACpE,CAAC;AAED;;;;CAIC,GACD,OAAO,SAASI,+BAA+B,
|
|
1
|
+
{"version":3,"sources":["../../src/utils/text.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Datasource, DashboardResource, VariableResource } from '../model';\n\n/**\n * If the dashboard has a display name, return the dashboard display name\n * Else, only return the dashboard name\n * @param dashboard\n */\nexport function getDashboardDisplayName(dashboard: DashboardResource) {\n return dashboard.spec.display?.name ?? dashboard.metadata.name;\n}\n\n/**\n * If the variable has a display name, return the variable display name\n * Else, only return the variable name\n * @param variable Project or Global variable\n */\nexport function getVariableDisplayName(variable: VariableResource) {\n return variable.spec.spec.display?.name ?? variable.metadata.name;\n}\n\n/**\n * If the variable has a display name, return the datasource display name\n * Else, only return the datasource name\n * @param variable Project or Global datasource\n */\nexport function getDatasourceDisplayName(datasource: Datasource) {\n return datasource.spec.display?.name || datasource.metadata.name;\n}\n\n/**\n * If the dashboard has a display name, return the dashboard display name and the dashboard name\n * Else, only return the dashboard name\n * @param dashboard\n */\nexport function getDashboardExtendedDisplayName(dashboard: DashboardResource) {\n if (dashboard.spec.display?.name) {\n return `${dashboard.spec.display.name} (Name: ${dashboard.metadata.name})`;\n }\n return dashboard.metadata.name;\n}\n\n/**\n * If the variable has a display name, return the variable display name and the variable name\n * Else, only return the variable name\n * @param variable Project or Global variable\n */\nexport function getVariableExtendedDisplayName(variable: VariableResource) {\n if (variable.spec.spec.display?.name) {\n return `${variable.spec.spec.display.name} (Name: ${variable.metadata.name})`;\n }\n return variable.metadata.name;\n}\n\n/**\n * If the datasource has a display name, return the datasource display name and the datasource name\n * Else, only return the datasource name\n * @param variable Project or Global datasource\n */\nexport function getDatasourceExtendedDisplayName(datasource: Datasource) {\n if (datasource.spec.display?.name) {\n return `${datasource.spec.display.name} (ID: ${datasource.metadata.name})`;\n }\n return datasource.metadata.name;\n}\n"],"names":["getDashboardDisplayName","dashboard","spec","display","name","metadata","getVariableDisplayName","variable","getDatasourceDisplayName","datasource","getDashboardExtendedDisplayName","getVariableExtendedDisplayName","getDatasourceExtendedDisplayName"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AA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AAC"}
|
|
@@ -6,13 +6,13 @@ export declare const MIN_STEP_INTERVAL_MS = 10;
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function getXValues(timeScale: TimeScale): number[];
|
|
8
8
|
/**
|
|
9
|
-
* [DEPRECATED] Used for legacy LineChart 'category' axis approach.
|
|
10
9
|
* Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
|
|
11
10
|
* processes the time series values, filling in any timestamps that are missing
|
|
12
11
|
* from the time series data with `null` values.
|
|
13
12
|
*/
|
|
14
13
|
export declare function getTimeSeriesValues(series: TimeSeries, timeScale: TimeScale): TimeSeriesValueTuple[];
|
|
15
14
|
/**
|
|
15
|
+
* [DEPRECATED] Used for legacy LineChart 'category' axis approach.
|
|
16
16
|
* Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
|
|
17
17
|
* gets the values for the y axis of a graph, filling in any timestamps that are
|
|
18
18
|
* missing from the time series data with `null` values.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/utils/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG1G,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,EAAE,CAQzD;AAED
|
|
1
|
+
{"version":3,"file":"time-series-data.d.ts","sourceRoot":"","sources":["../../src/utils/time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAG1G,eAAO,MAAM,oBAAoB,KAAK,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,EAAE,CAQzD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,0BAyB3E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,CAuBzF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,GACzE,SAAS,GAAG,SAAS,CAgFvB"}
|
|
@@ -25,7 +25,6 @@ export const MIN_STEP_INTERVAL_MS = 10;
|
|
|
25
25
|
return xValues;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* [DEPRECATED] Used for legacy LineChart 'category' axis approach.
|
|
29
28
|
* Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
|
|
30
29
|
* processes the time series values, filling in any timestamps that are missing
|
|
31
30
|
* from the time series data with `null` values.
|
|
@@ -60,6 +59,7 @@ export const MIN_STEP_INTERVAL_MS = 10;
|
|
|
60
59
|
return processedValues;
|
|
61
60
|
}
|
|
62
61
|
/**
|
|
62
|
+
* [DEPRECATED] Used for legacy LineChart 'category' axis approach.
|
|
63
63
|
* Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),
|
|
64
64
|
* gets the values for the y axis of a graph, filling in any timestamps that are
|
|
65
65
|
* missing from the time series data with `null` values.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange, TimeScale, TimeSeries, TimeSeriesData, TimeSeriesValueTuple } from '../model';\nimport { gcd } from './mathjs';\n\nexport const MIN_STEP_INTERVAL_MS = 10;\n\n/**\n * Given a common time scale (see `getCommonTimeScale`), generates an array of\n * timestamp values in ms for the x axis of a graph.\n */\nexport function getXValues(timeScale: TimeScale): number[] {\n const xValues: number[] = [];\n let timestamp = timeScale.startMs;\n while (timestamp <= timeScale.endMs) {\n xValues.push(timestamp);\n timestamp += timeScale.stepMs;\n }\n return xValues;\n}\n\n/**\n * [DEPRECATED] Used for legacy LineChart 'category' axis approach.\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * processes the time series values, filling in any timestamps that are missing\n * from the time series data with `null` values.\n */\nexport function getTimeSeriesValues(series: TimeSeries, timeScale: TimeScale) {\n let timestamp = timeScale.startMs;\n\n const values = series.values;\n const processedValues: TimeSeriesValueTuple[] = [];\n\n for (const valueTuple of values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n processedValues.push([timestamp, null]);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n processedValues.push([timestamp, valueTuple[1]]);\n timestamp += timeScale.stepMs;\n }\n\n // Add null values at the end of the series if necessary\n while (timestamp <= timeScale.endMs) {\n processedValues.push([timestamp, null]);\n timestamp += timeScale.stepMs;\n }\n\n return processedValues;\n}\n\n/**\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * gets the values for the y axis of a graph, filling in any timestamps that are\n * missing from the time series data with `null` values.\n */\nexport function getYValues(series: TimeSeries, timeScale: TimeScale): Array<number | null> {\n let timestamp = timeScale.startMs;\n\n const yValues: Array<number | null> = [];\n for (const valueTuple of series.values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n yValues.push(valueTuple[1]);\n timestamp += timeScale.stepMs;\n }\n\n // Add null values at the end of the series if necessary\n while (timestamp <= timeScale.endMs) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n return yValues;\n}\n\n/**\n * Given a list of running queries, calculates a common time scale for use on\n * the x axis (i.e. start/end dates and a step that is divisible into all of\n * the queries' steps).\n */\nexport function getCommonTimeScale(\n seriesData: Array<TimeSeriesData | Pick<TimeSeries, 'values'> | undefined>\n): TimeScale | undefined {\n let timeRange: AbsoluteTimeRange | undefined = undefined;\n const steps: number[] = [];\n\n for (const data of seriesData) {\n if (data && 'timeRange' in data) {\n if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;\n\n // Keep track of query steps so we can calculate a common one for the graph\n steps.push(data.stepMs);\n\n // If we don't have an overall time range yet, just start with this one\n if (timeRange === undefined) {\n timeRange = data.timeRange;\n continue;\n }\n\n // Otherwise, see if this query has a start or end outside of the current\n // time range\n if (data.timeRange.start < timeRange.start) {\n timeRange.start = data.timeRange.start;\n }\n if (data.timeRange.end > timeRange.end) {\n timeRange.end = data.timeRange.end;\n }\n } else if (data && 'values' in data) {\n for (let i = 0; i < data.values.length; i++) {\n const values = data.values[i];\n if (values === undefined) {\n continue;\n }\n\n const [timestamp] = values;\n const start = new Date(timestamp);\n const end = new Date(timestamp);\n\n if (timeRange === undefined) {\n timeRange = {\n start,\n end,\n };\n continue;\n }\n\n if (start < timeRange.start) {\n timeRange.start = start;\n }\n\n if (end > timeRange.end) {\n timeRange.end = end;\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, rangeMs, stepMs: MIN_STEP_INTERVAL_MS };\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n // Use the greatest common divisor of all step values as the overall step\n // for the x axis (or if only one query, just use that query's step value)\n let stepMs: number;\n if (steps.length === 1) {\n stepMs = steps[0] as number;\n } else {\n const calculatedStepMs = gcd(...steps);\n stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;\n }\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, stepMs, rangeMs };\n}\n"],"names":["gcd","MIN_STEP_INTERVAL_MS","getXValues","timeScale","xValues","timestamp","startMs","endMs","push","stepMs","getTimeSeriesValues","series","values","processedValues","valueTuple","getYValues","yValues","getCommonTimeScale","seriesData","timeRange","undefined","steps","data","start","end","i","length","Date","valueOf","rangeMs","calculatedStepMs"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,GAAG,QAAQ,UAAU,CAAC;AAE/B,OAAO,MAAMC,oBAAoB,GAAG,EAAE,CAAC;AAEvC;;;CAGC,GACD,OAAO,SAASC,UAAU,CAACC,SAAoB,EAAY;IACzD,MAAMC,OAAO,GAAa,EAAE,AAAC;IAC7B,IAAIC,SAAS,GAAGF,SAAS,CAACG,OAAO,AAAC;IAClC,MAAOD,SAAS,IAAIF,SAAS,CAACI,KAAK,CAAE;QACnCH,OAAO,CAACI,IAAI,CAACH,SAAS,CAAC,CAAC;QACxBA,SAAS,IAAIF,SAAS,CAACM,MAAM,CAAC;IAChC,CAAC;IACD,OAAOL,OAAO,CAAC;AACjB,CAAC;AAED;;;;;CAKC,GACD,OAAO,SAASM,mBAAmB,CAACC,MAAkB,EAAER,SAAoB,EAAE;IAC5E,IAAIE,SAAS,GAAGF,SAAS,CAACG,OAAO,AAAC;IAElC,MAAMM,MAAM,GAAGD,MAAM,CAACC,MAAM,AAAC;IAC7B,MAAMC,eAAe,GAA2B,EAAE,AAAC;IAEnD,KAAK,MA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CAAC,AAAU,CAAC;IAC9B,OAAO;QACL,MAAMS,gBAAgB,GAAG9B,GAAG,IAAIqB,KAAK,CAAC,AAAC;QACvCZ,MAAM,GAAGqB,gBAAgB,GAAG7B,oBAAoB,GAAGA,oBAAoB,GAAG6B,gBAAgB,CAAC;IAC7F,CAAC;IAED,MAAMxB,QAAO,GAAGa,SAAS,CAACI,KAAK,CAACK,OAAO,EAAE,AAAC;IAC1C,MAAMrB,MAAK,GAAGY,SAAS,CAACK,GAAG,CAACI,OAAO,EAAE,AAAC;IACtC,MAAMC,QAAO,GAAGtB,MAAK,GAAGD,QAAO,AAAC;IAEhC,OAAO;QAAEA,OAAO,EAAPA,QAAO;QAAEC,KAAK,EAALA,MAAK;QAAEE,MAAM;QAAEoB,OAAO,EAAPA,QAAO;KAAE,CAAC;AAC7C,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/utils/time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AbsoluteTimeRange, TimeScale, TimeSeries, TimeSeriesData, TimeSeriesValueTuple } from '../model';\nimport { gcd } from './mathjs';\n\nexport const MIN_STEP_INTERVAL_MS = 10;\n\n/**\n * Given a common time scale (see `getCommonTimeScale`), generates an array of\n * timestamp values in ms for the x axis of a graph.\n */\nexport function getXValues(timeScale: TimeScale): number[] {\n const xValues: number[] = [];\n let timestamp = timeScale.startMs;\n while (timestamp <= timeScale.endMs) {\n xValues.push(timestamp);\n timestamp += timeScale.stepMs;\n }\n return xValues;\n}\n\n/**\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * processes the time series values, filling in any timestamps that are missing\n * from the time series data with `null` values.\n */\nexport function getTimeSeriesValues(series: TimeSeries, timeScale: TimeScale) {\n let timestamp = timeScale.startMs;\n\n const values = series.values;\n const processedValues: TimeSeriesValueTuple[] = [];\n\n for (const valueTuple of values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n processedValues.push([timestamp, null]);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n processedValues.push([timestamp, valueTuple[1]]);\n timestamp += timeScale.stepMs;\n }\n\n // Add null values at the end of the series if necessary\n while (timestamp <= timeScale.endMs) {\n processedValues.push([timestamp, null]);\n timestamp += timeScale.stepMs;\n }\n\n return processedValues;\n}\n\n/**\n * [DEPRECATED] Used for legacy LineChart 'category' axis approach.\n * Given a TimeSeries from a query and a common time scale (see `getCommonTimeScale`),\n * gets the values for the y axis of a graph, filling in any timestamps that are\n * missing from the time series data with `null` values.\n */\nexport function getYValues(series: TimeSeries, timeScale: TimeScale): Array<number | null> {\n let timestamp = timeScale.startMs;\n\n const yValues: Array<number | null> = [];\n for (const valueTuple of series.values) {\n // Fill in values up to the current series value timestamp with nulls\n while (timestamp < valueTuple[0]) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n // Now add the current value since timestamp should match\n yValues.push(valueTuple[1]);\n timestamp += timeScale.stepMs;\n }\n\n // Add null values at the end of the series if necessary\n while (timestamp <= timeScale.endMs) {\n yValues.push(null);\n timestamp += timeScale.stepMs;\n }\n\n return yValues;\n}\n\n/**\n * Given a list of running queries, calculates a common time scale for use on\n * the x axis (i.e. start/end dates and a step that is divisible into all of\n * the queries' steps).\n */\nexport function getCommonTimeScale(\n seriesData: Array<TimeSeriesData | Pick<TimeSeries, 'values'> | undefined>\n): TimeScale | undefined {\n let timeRange: AbsoluteTimeRange | undefined = undefined;\n const steps: number[] = [];\n\n for (const data of seriesData) {\n if (data && 'timeRange' in data) {\n if (data === undefined || data.timeRange === undefined || data.stepMs === undefined) continue;\n\n // Keep track of query steps so we can calculate a common one for the graph\n steps.push(data.stepMs);\n\n // If we don't have an overall time range yet, just start with this one\n if (timeRange === undefined) {\n timeRange = data.timeRange;\n continue;\n }\n\n // Otherwise, see if this query has a start or end outside of the current\n // time range\n if (data.timeRange.start < timeRange.start) {\n timeRange.start = data.timeRange.start;\n }\n if (data.timeRange.end > timeRange.end) {\n timeRange.end = data.timeRange.end;\n }\n } else if (data && 'values' in data) {\n for (let i = 0; i < data.values.length; i++) {\n const values = data.values[i];\n if (values === undefined) {\n continue;\n }\n\n const [timestamp] = values;\n const start = new Date(timestamp);\n const end = new Date(timestamp);\n\n if (timeRange === undefined) {\n timeRange = {\n start,\n end,\n };\n continue;\n }\n\n if (start < timeRange.start) {\n timeRange.start = start;\n }\n\n if (end > timeRange.end) {\n timeRange.end = end;\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, rangeMs, stepMs: MIN_STEP_INTERVAL_MS };\n }\n }\n\n if (timeRange === undefined) return undefined;\n\n // Use the greatest common divisor of all step values as the overall step\n // for the x axis (or if only one query, just use that query's step value)\n let stepMs: number;\n if (steps.length === 1) {\n stepMs = steps[0] as number;\n } else {\n const calculatedStepMs = gcd(...steps);\n stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;\n }\n\n const startMs = timeRange.start.valueOf();\n const endMs = timeRange.end.valueOf();\n const rangeMs = endMs - startMs;\n\n return { startMs, endMs, stepMs, rangeMs };\n}\n"],"names":["gcd","MIN_STEP_INTERVAL_MS","getXValues","timeScale","xValues","timestamp","startMs","endMs","push","stepMs","getTimeSeriesValues","series","values","processedValues","valueTuple","getYValues","yValues","getCommonTimeScale","seriesData","timeRange","undefined","steps","data","start","end","i","length","Date","valueOf","rangeMs","calculatedStepMs"],"mappings":"AAAA,oCAAoC;A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