@perses-dev/core 0.0.0-snapshot-panel-extra-content-3-17f9c42 → 0.0.0-snapshot-scatterplot-fix-imports-95e1b59
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants/dashboard-defaults.js +6 -2
- package/dist/cjs/constants/dialog.js +3 -1
- package/dist/cjs/constants/index.js +11 -9
- package/dist/cjs/index.js +12 -10
- package/dist/cjs/model/calculations.js +61 -51
- package/dist/cjs/model/ephemeraldashboard.js +16 -0
- package/dist/cjs/model/http-proxy.js +16 -0
- package/dist/cjs/model/index.js +35 -26
- package/dist/cjs/model/kind.js +39 -0
- package/dist/cjs/model/legend.js +39 -19
- package/dist/cjs/model/resource.js +9 -0
- package/dist/cjs/model/rolebindings.js +16 -0
- package/dist/cjs/model/roles.js +60 -0
- package/dist/cjs/model/secrets.js +16 -0
- package/dist/cjs/model/time-series-queries.js +3 -1
- package/dist/cjs/model/time.js +151 -65
- package/dist/cjs/model/trace-data.js +16 -0
- package/dist/cjs/model/units/bytes.js +37 -25
- package/dist/cjs/model/units/constants.js +3 -1
- package/dist/cjs/model/units/decimal.js +22 -16
- package/dist/cjs/model/units/index.js +13 -11
- package/dist/cjs/model/units/percent.js +26 -19
- package/dist/cjs/model/units/throughput.js +113 -0
- package/dist/cjs/model/units/time.js +99 -38
- package/dist/cjs/model/units/types.js +5 -2
- package/dist/cjs/model/units/units.js +81 -45
- package/dist/cjs/model/units/utils.js +13 -7
- package/dist/cjs/model/variables.js +16 -3
- package/dist/cjs/utils/event.js +3 -1
- package/dist/cjs/utils/fetch.js +32 -7
- package/dist/cjs/utils/index.js +17 -14
- package/dist/cjs/utils/is-empty-object.js +3 -1
- package/dist/cjs/utils/mathjs.js +4 -2
- package/dist/cjs/utils/memo.js +10 -6
- package/dist/cjs/utils/panel-refs.js +9 -3
- package/dist/cjs/utils/text.js +33 -21
- package/dist/cjs/utils/time-series-data.js +21 -11
- package/dist/cjs/utils/types.js +16 -0
- package/dist/constants/dashboard-defaults.js.map +1 -1
- package/dist/constants/dialog.js.map +1 -1
- package/dist/constants/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/calculations.d.ts +12 -12
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +46 -46
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/dashboard.js.map +1 -1
- package/dist/model/datasource.d.ts +17 -3
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js +3 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/definitions.d.ts +1 -1
- package/dist/model/definitions.d.ts.map +1 -1
- package/dist/model/definitions.js +3 -0
- package/dist/model/definitions.js.map +1 -1
- package/dist/model/display.d.ts +1 -1
- package/dist/model/display.d.ts.map +1 -1
- package/dist/model/display.js.map +1 -1
- package/dist/model/ephemeraldashboard.d.ts +15 -0
- package/dist/model/ephemeraldashboard.d.ts.map +1 -0
- package/dist/model/ephemeraldashboard.js +15 -0
- package/dist/model/ephemeraldashboard.js.map +1 -0
- package/dist/model/http-proxy.d.ts +16 -0
- package/dist/model/http-proxy.d.ts.map +1 -0
- package/dist/model/http-proxy.js +15 -0
- package/dist/model/http-proxy.js.map +1 -0
- package/dist/model/http.d.ts +1 -1
- package/dist/model/http.d.ts.map +1 -1
- package/dist/model/index.d.ts +7 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +7 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/kind.d.ts +3 -0
- package/dist/model/kind.d.ts.map +1 -0
- package/dist/model/kind.js +31 -0
- package/dist/model/kind.js.map +1 -0
- package/dist/model/layout.d.ts +1 -1
- package/dist/model/layout.d.ts.map +1 -1
- package/dist/model/layout.js.map +1 -1
- package/dist/model/legend.d.ts +9 -9
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +9 -9
- package/dist/model/legend.js.map +1 -1
- package/dist/model/panels.d.ts +5 -2
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js +3 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/project.js.map +1 -1
- package/dist/model/query.d.ts +15 -2
- package/dist/model/query.d.ts.map +1 -1
- package/dist/model/query.js +4 -1
- package/dist/model/query.js.map +1 -1
- package/dist/model/resource.d.ts +3 -2
- package/dist/model/resource.d.ts.map +1 -1
- package/dist/model/resource.js +3 -1
- package/dist/model/resource.js.map +1 -1
- package/dist/model/rolebindings.d.ts +27 -0
- package/dist/model/rolebindings.d.ts.map +1 -0
- package/dist/model/rolebindings.js +15 -0
- package/dist/model/rolebindings.js.map +1 -0
- package/dist/model/roles.d.ts +32 -0
- package/dist/model/roles.d.ts.map +1 -0
- package/dist/model/roles.js +41 -0
- package/dist/model/roles.js.map +1 -0
- package/dist/model/secrets.d.ts +44 -0
- package/dist/model/secrets.d.ts.map +1 -0
- package/dist/model/secrets.js +15 -0
- package/dist/model/secrets.js.map +1 -0
- package/dist/model/thresholds.d.ts +2 -2
- package/dist/model/thresholds.d.ts.map +1 -1
- package/dist/model/thresholds.js.map +1 -1
- package/dist/model/time-series-data.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +3 -3
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/time.d.ts +15 -11
- package/dist/model/time.d.ts.map +1 -1
- package/dist/model/time.js +117 -57
- package/dist/model/time.js.map +1 -1
- package/dist/model/trace-data.d.ts +20 -0
- package/dist/model/trace-data.d.ts.map +1 -0
- package/dist/model/trace-data.js +18 -0
- package/dist/model/trace-data.js.map +1 -0
- package/dist/model/units/bytes.d.ts +8 -8
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +27 -21
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/constants.js.map +1 -1
- package/dist/model/units/decimal.d.ts +8 -8
- package/dist/model/units/decimal.d.ts.map +1 -1
- package/dist/model/units/decimal.js +14 -14
- package/dist/model/units/decimal.js.map +1 -1
- package/dist/model/units/index.js.map +1 -1
- package/dist/model/units/percent.d.ts +7 -7
- package/dist/model/units/percent.d.ts.map +1 -1
- package/dist/model/units/percent.js +17 -16
- package/dist/model/units/percent.js.map +1 -1
- package/dist/model/units/throughput.d.ts +13 -0
- package/dist/model/units/throughput.d.ts.map +1 -0
- package/dist/model/units/throughput.js +94 -0
- package/dist/model/units/throughput.js.map +1 -0
- package/dist/model/units/time.d.ts +15 -15
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +87 -34
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/types.d.ts +18 -9
- package/dist/model/units/types.d.ts.map +1 -1
- package/dist/model/units/types.js +2 -1
- package/dist/model/units/types.js.map +1 -1
- package/dist/model/units/units.d.ts +50 -31
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +52 -37
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/utils.d.ts +2 -2
- package/dist/model/units/utils.d.ts.map +1 -1
- package/dist/model/units/utils.js +4 -4
- package/dist/model/units/utils.js.map +1 -1
- package/dist/model/variables.d.ts +28 -9
- package/dist/model/variables.d.ts.map +1 -1
- package/dist/model/variables.js +3 -0
- package/dist/model/variables.js.map +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/event.js.map +1 -1
- package/dist/utils/fetch.d.ts +3 -1
- package/dist/utils/fetch.d.ts.map +1 -1
- package/dist/utils/fetch.js +21 -4
- package/dist/utils/fetch.js.map +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/is-empty-object.js.map +1 -1
- package/dist/utils/mathjs.js +1 -1
- package/dist/utils/mathjs.js.map +1 -1
- package/dist/utils/memo.js +2 -2
- package/dist/utils/memo.js.map +1 -1
- package/dist/utils/panel-refs.js.map +1 -1
- package/dist/utils/text.d.ts +7 -7
- package/dist/utils/text.d.ts.map +1 -1
- package/dist/utils/text.js +17 -17
- package/dist/utils/text.js.map +1 -1
- package/dist/utils/time-series-data.d.ts +1 -1
- package/dist/utils/time-series-data.d.ts.map +1 -1
- package/dist/utils/time-series-data.js +7 -7
- package/dist/utils/time-series-data.js.map +1 -1
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/utils/types.js +15 -0
- package/dist/utils/types.js.map +1 -0
- package/package.json +5 -4
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
|
+
import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
|
|
15
|
+
const throughputUnits = [
|
|
16
|
+
'counts/sec',
|
|
17
|
+
'events/sec',
|
|
18
|
+
'messages/sec',
|
|
19
|
+
'ops/sec',
|
|
20
|
+
'packets/sec',
|
|
21
|
+
'reads/sec',
|
|
22
|
+
'records/sec',
|
|
23
|
+
'requests/sec',
|
|
24
|
+
'rows/sec',
|
|
25
|
+
'writes/sec'
|
|
26
|
+
];
|
|
27
|
+
export const THROUGHPUT_GROUP_CONFIG = {
|
|
28
|
+
label: 'Throughput',
|
|
29
|
+
decimalPlaces: true
|
|
30
|
+
};
|
|
31
|
+
const THROUGHPUT_GROUP = 'Throughput';
|
|
32
|
+
export const THROUGHPUT_UNIT_CONFIG = {
|
|
33
|
+
'counts/sec': {
|
|
34
|
+
group: THROUGHPUT_GROUP,
|
|
35
|
+
label: 'Counts/sec'
|
|
36
|
+
},
|
|
37
|
+
'events/sec': {
|
|
38
|
+
group: THROUGHPUT_GROUP,
|
|
39
|
+
label: 'Events/sec'
|
|
40
|
+
},
|
|
41
|
+
'messages/sec': {
|
|
42
|
+
group: THROUGHPUT_GROUP,
|
|
43
|
+
label: 'Messages/sec'
|
|
44
|
+
},
|
|
45
|
+
'ops/sec': {
|
|
46
|
+
group: THROUGHPUT_GROUP,
|
|
47
|
+
label: 'Ops/sec'
|
|
48
|
+
},
|
|
49
|
+
'packets/sec': {
|
|
50
|
+
group: THROUGHPUT_GROUP,
|
|
51
|
+
label: 'Packets/sec'
|
|
52
|
+
},
|
|
53
|
+
'reads/sec': {
|
|
54
|
+
group: THROUGHPUT_GROUP,
|
|
55
|
+
label: 'Reads/sec'
|
|
56
|
+
},
|
|
57
|
+
'requests/sec': {
|
|
58
|
+
group: THROUGHPUT_GROUP,
|
|
59
|
+
label: 'Requests/sec'
|
|
60
|
+
},
|
|
61
|
+
'records/sec': {
|
|
62
|
+
group: THROUGHPUT_GROUP,
|
|
63
|
+
label: 'Records/sec'
|
|
64
|
+
},
|
|
65
|
+
'rows/sec': {
|
|
66
|
+
group: THROUGHPUT_GROUP,
|
|
67
|
+
label: 'Rows/sec'
|
|
68
|
+
},
|
|
69
|
+
'writes/sec': {
|
|
70
|
+
group: THROUGHPUT_GROUP,
|
|
71
|
+
label: 'Writes/sec'
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
export function formatThroughput(value, { unit, shortValues, decimalPlaces }) {
|
|
75
|
+
const formatterOptions = {
|
|
76
|
+
style: 'decimal',
|
|
77
|
+
useGrouping: true
|
|
78
|
+
};
|
|
79
|
+
if (shouldShortenValues(shortValues)) {
|
|
80
|
+
formatterOptions.notation = 'compact';
|
|
81
|
+
}
|
|
82
|
+
if (hasDecimalPlaces(decimalPlaces)) {
|
|
83
|
+
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
84
|
+
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
85
|
+
} else {
|
|
86
|
+
if (shouldShortenValues(shortValues)) {
|
|
87
|
+
formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const formatter = Intl.NumberFormat('en-US', formatterOptions);
|
|
91
|
+
return formatter.format(value) + ' ' + unit;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//# sourceMappingURL=throughput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/throughput.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, shouldShortenValues } from './utils';\n\nconst throughputUnits = [\n 'counts/sec',\n 'events/sec',\n 'messages/sec',\n 'ops/sec',\n 'packets/sec',\n 'reads/sec',\n 'records/sec',\n 'requests/sec',\n 'rows/sec',\n 'writes/sec',\n] as const;\ntype ThroughputUnit = (typeof throughputUnits)[number];\nexport type ThroughputFormatOptions = {\n unit: ThroughputUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const THROUGHPUT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Throughput',\n decimalPlaces: true,\n};\nconst THROUGHPUT_GROUP = 'Throughput';\nexport const THROUGHPUT_UNIT_CONFIG: Readonly<Record<ThroughputUnit, UnitConfig>> = {\n 'counts/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Counts/sec',\n },\n 'events/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Events/sec',\n },\n 'messages/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Messages/sec',\n },\n 'ops/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Ops/sec',\n },\n 'packets/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Packets/sec',\n },\n 'reads/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Reads/sec',\n },\n 'requests/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Requests/sec',\n },\n 'records/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Records/sec',\n },\n 'rows/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Rows/sec',\n },\n 'writes/sec': {\n group: THROUGHPUT_GROUP,\n label: 'Writes/sec',\n },\n};\n\nexport function formatThroughput(value: number, { unit, shortValues, decimalPlaces }: ThroughputFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value) + ' ' + unit;\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","throughputUnits","THROUGHPUT_GROUP_CONFIG","label","decimalPlaces","THROUGHPUT_GROUP","THROUGHPUT_UNIT_CONFIG","group","formatThroughput","value","unit","shortValues","formatterOptions","style","useGrouping","notation","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,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAEpF,MAAMC,kBAAkB;IACtB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAOD,OAAO,MAAMC,0BAA2C;IACtDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,MAAMC,mBAAmB;AACzB,OAAO,MAAMC,yBAAuE;IAClF,cAAc;QACZC,OAAOF;QACPF,OAAO;IACT;IACA,cAAc;QACZI,OAAOF;QACPF,OAAO;IACT;IACA,gBAAgB;QACdI,OAAOF;QACPF,OAAO;IACT;IACA,WAAW;QACTI,OAAOF;QACPF,OAAO;IACT;IACA,eAAe;QACbI,OAAOF;QACPF,OAAO;IACT;IACA,aAAa;QACXI,OAAOF;QACPF,OAAO;IACT;IACA,gBAAgB;QACdI,OAAOF;QACPF,OAAO;IACT;IACA,eAAe;QACbI,OAAOF;QACPF,OAAO;IACT;IACA,YAAY;QACVI,OAAOF;QACPF,OAAO;IACT;IACA,cAAc;QACZI,OAAOF;QACPF,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASK,iBAAiBC,KAAa,EAAE,EAAEC,IAAI,EAAEC,WAAW,EAAEP,aAAa,EAA2B;IAC3G,MAAMQ,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAId,oBAAoBW,cAAc;QACpCC,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAIjB,iBAAiBM,gBAAgB;QACnCQ,iBAAiBI,qBAAqB,GAAGjB,mBAAmBK;QAC5DQ,iBAAiBK,qBAAqB,GAAGlB,mBAAmBK;IAC9D,OAAO;QACL,IAAIJ,oBAAoBW,cAAc;YACpCC,iBAAiBM,wBAAwB,GAAGrB;QAC9C;IACF;IAEA,MAAMsB,YAAYC,KAAKC,YAAY,CAAC,SAAST;IAC7C,OAAOO,UAAUG,MAAM,CAACb,SAAS,MAAMC;AACzC"}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { UnitGroupConfig, UnitConfig } from './types';
|
|
2
|
-
declare const
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
declare const timeUnits: readonly ["milliseconds", "seconds", "minutes", "hours", "days", "weeks", "months", "years"];
|
|
3
|
+
type TimeUnits = (typeof timeUnits)[number];
|
|
4
|
+
export type TimeFormatOptions = {
|
|
5
|
+
unit: TimeUnits;
|
|
6
|
+
decimalPlaces?: number;
|
|
7
7
|
};
|
|
8
8
|
export declare const TIME_GROUP_CONFIG: UnitGroupConfig;
|
|
9
|
-
export declare const TIME_UNIT_CONFIG: Readonly<Record<
|
|
9
|
+
export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnits, UnitConfig>>;
|
|
10
10
|
export declare enum PersesTimeToIntlTime {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
milliseconds = "millisecond",
|
|
12
|
+
seconds = "second",
|
|
13
|
+
minutes = "minute",
|
|
14
|
+
hours = "hour",
|
|
15
|
+
days = "day",
|
|
16
|
+
weeks = "week",
|
|
17
|
+
months = "month",
|
|
18
|
+
years = "year"
|
|
19
19
|
}
|
|
20
|
-
export declare function formatTime(value: number, {
|
|
20
|
+
export declare function formatTime(value: number, { unit, decimalPlaces }: TimeFormatOptions): string;
|
|
21
21
|
export {};
|
|
22
22
|
//# sourceMappingURL=time.d.ts.map
|
|
@@ -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,
|
|
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,SAAS,8FAA+F,CAAC;AAC/G,KAAK,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAC5C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAiCpE,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,aAAa,EAAE,EAAE,iBAAiB,GAAG,MAAM,CAoB5F"}
|
package/dist/model/units/time.js
CHANGED
|
@@ -12,80 +12,133 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { MAX_SIGNIFICANT_DIGITS } from './constants';
|
|
14
14
|
import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
|
|
15
|
-
const
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
15
|
+
const timeUnits = [
|
|
16
|
+
'milliseconds',
|
|
17
|
+
'seconds',
|
|
18
|
+
'minutes',
|
|
19
|
+
'hours',
|
|
20
|
+
'days',
|
|
21
|
+
'weeks',
|
|
22
|
+
'months',
|
|
23
|
+
'years'
|
|
24
24
|
];
|
|
25
25
|
const TIME_GROUP = 'Time';
|
|
26
26
|
export const TIME_GROUP_CONFIG = {
|
|
27
27
|
label: 'Time',
|
|
28
|
-
|
|
28
|
+
decimalPlaces: true
|
|
29
29
|
};
|
|
30
30
|
export const TIME_UNIT_CONFIG = {
|
|
31
|
-
|
|
31
|
+
milliseconds: {
|
|
32
32
|
group: TIME_GROUP,
|
|
33
33
|
label: 'Milliseconds'
|
|
34
34
|
},
|
|
35
|
-
|
|
35
|
+
seconds: {
|
|
36
36
|
group: TIME_GROUP,
|
|
37
37
|
label: 'Seconds'
|
|
38
38
|
},
|
|
39
|
-
|
|
39
|
+
minutes: {
|
|
40
40
|
group: TIME_GROUP,
|
|
41
41
|
label: 'Minutes'
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
hours: {
|
|
44
44
|
group: TIME_GROUP,
|
|
45
45
|
label: 'Hours'
|
|
46
46
|
},
|
|
47
|
-
|
|
47
|
+
days: {
|
|
48
48
|
group: TIME_GROUP,
|
|
49
49
|
label: 'Days'
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
weeks: {
|
|
52
52
|
group: TIME_GROUP,
|
|
53
53
|
label: 'Weeks'
|
|
54
54
|
},
|
|
55
|
-
|
|
55
|
+
months: {
|
|
56
56
|
group: TIME_GROUP,
|
|
57
57
|
label: 'Months'
|
|
58
58
|
},
|
|
59
|
-
|
|
59
|
+
years: {
|
|
60
60
|
group: TIME_GROUP,
|
|
61
61
|
label: 'Years'
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
export var PersesTimeToIntlTime;
|
|
65
65
|
(function(PersesTimeToIntlTime) {
|
|
66
|
-
PersesTimeToIntlTime["
|
|
67
|
-
PersesTimeToIntlTime["
|
|
68
|
-
PersesTimeToIntlTime["
|
|
69
|
-
PersesTimeToIntlTime["
|
|
70
|
-
PersesTimeToIntlTime["
|
|
71
|
-
PersesTimeToIntlTime["
|
|
72
|
-
PersesTimeToIntlTime["
|
|
73
|
-
PersesTimeToIntlTime["
|
|
66
|
+
PersesTimeToIntlTime["milliseconds"] = "millisecond";
|
|
67
|
+
PersesTimeToIntlTime["seconds"] = "second";
|
|
68
|
+
PersesTimeToIntlTime["minutes"] = "minute";
|
|
69
|
+
PersesTimeToIntlTime["hours"] = "hour";
|
|
70
|
+
PersesTimeToIntlTime["days"] = "day";
|
|
71
|
+
PersesTimeToIntlTime["weeks"] = "week";
|
|
72
|
+
PersesTimeToIntlTime["months"] = "month";
|
|
73
|
+
PersesTimeToIntlTime["years"] = "year";
|
|
74
74
|
})(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
|
|
75
|
-
|
|
76
|
-
|
|
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, unit) {
|
|
103
|
+
const valueInSeconds = value * TIME_UNITS_IN_SECONDS[unit];
|
|
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
|
+
unit: 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
|
+
unit: timeUnit
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function isMonthOrYear(unit) {
|
|
124
|
+
return unit === 'months' || unit === 'years';
|
|
125
|
+
}
|
|
126
|
+
export function formatTime(value, { unit, decimalPlaces }) {
|
|
127
|
+
if (value === 0) return '0s';
|
|
128
|
+
const results = getValueAndKindForNaturalNumbers(value, unit);
|
|
77
129
|
const formatterOptions = {
|
|
78
130
|
style: 'unit',
|
|
79
|
-
unit: PersesTimeToIntlTime[
|
|
80
|
-
unitDisplay: isMonthOrYear ? 'long' : 'narrow'
|
|
131
|
+
unit: PersesTimeToIntlTime[results.unit],
|
|
132
|
+
unitDisplay: isMonthOrYear(results.unit) ? 'long' : 'narrow'
|
|
81
133
|
};
|
|
82
|
-
if (hasDecimalPlaces(
|
|
83
|
-
formatterOptions.minimumFractionDigits = limitDecimalPlaces(
|
|
84
|
-
formatterOptions.maximumFractionDigits = limitDecimalPlaces(
|
|
134
|
+
if (hasDecimalPlaces(decimalPlaces)) {
|
|
135
|
+
formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
136
|
+
formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
|
|
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
|
|
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 timeUnits = ['milliseconds', 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'] as const;\ntype TimeUnits = (typeof timeUnits)[number];\nexport type TimeFormatOptions = {\n unit: TimeUnits;\n decimalPlaces?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimalPlaces: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnits, UnitConfig>> = {\n 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<TimeUnits, number> = {\n years: 31536000, // 365 days\n months: 2592000, // 30 days\n weeks: 604800, // 7 days\n days: 86400,\n hours: 3600,\n minutes: 60,\n seconds: 1,\n milliseconds: 0.001,\n};\n\nconst LARGEST_TO_SMALLEST_TIME_UNITS: TimeUnits[] = [\n 'years',\n 'months',\n 'weeks',\n 'days',\n 'hours',\n 'minutes',\n 'seconds',\n 'milliseconds',\n];\n\n/**\n * Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.\n */\nfunction getValueAndKindForNaturalNumbers(value: number, unit: TimeUnits): { value: number; unit: TimeUnits } {\n const valueInSeconds = value * TIME_UNITS_IN_SECONDS[unit];\n\n // Initialize for TS\n const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'years';\n let timeUnit: TimeUnits = largestTimeUnit;\n let valueInTimeUnit: number = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];\n\n for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS) {\n valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];\n if (valueInTimeUnit >= 1) {\n return { value: valueInTimeUnit, unit: timeUnit };\n }\n }\n\n // If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).\n return { value: valueInTimeUnit, unit: timeUnit };\n}\n\nfunction isMonthOrYear(unit: TimeUnits): boolean {\n return unit === 'months' || unit === 'years';\n}\n\nexport function formatTime(value: number, { unit, decimalPlaces }: TimeFormatOptions): string {\n if (value === 0) return '0s';\n\n const results = getValueAndKindForNaturalNumbers(value, unit);\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: PersesTimeToIntlTime[results.unit],\n unitDisplay: isMonthOrYear(results.unit) ? 'long' : 'narrow',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(results.value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","timeUnits","TIME_GROUP","TIME_GROUP_CONFIG","label","decimalPlaces","TIME_UNIT_CONFIG","milliseconds","group","seconds","minutes","hours","days","weeks","months","years","PersesTimeToIntlTime","TIME_UNITS_IN_SECONDS","LARGEST_TO_SMALLEST_TIME_UNITS","getValueAndKindForNaturalNumbers","value","unit","valueInSeconds","largestTimeUnit","timeUnit","valueInTimeUnit","isMonthOrYear","formatTime","results","formatterOptions","style","unitDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","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,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAE/D,MAAMC,YAAY;IAAC;IAAgB;IAAW;IAAW;IAAS;IAAQ;IAAS;IAAU;CAAQ;AAMrG,MAAMC,aAAa;AACnB,OAAO,MAAMC,oBAAqC;IAChDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,OAAO,MAAMC,mBAA4D;IACvEC,cAAc;QACZC,OAAON;QACPE,OAAO;IACT;IACAK,SAAS;QACPD,OAAON;QACPE,OAAO;IACT;IACAM,SAAS;QACPF,OAAON;QACPE,OAAO;IACT;IACAO,OAAO;QACLH,OAAON;QACPE,OAAO;IACT;IACAQ,MAAM;QACJJ,OAAON;QACPE,OAAO;IACT;IACAS,OAAO;QACLL,OAAON;QACPE,OAAO;IACT;IACAU,QAAQ;QACNN,OAAON;QACPE,OAAO;IACT;IACAW,OAAO;QACLP,OAAON;QACPE,OAAO;IACT;AACF,EAAE;;UAIUY;;;;;;;;;GAAAA,yBAAAA;AAWZ;;;;;CAKC,GACD,MAAMC,wBAAmD;IACvDF,OAAO;IACPD,QAAQ;IACRD,OAAO;IACPD,MAAM;IACND,OAAO;IACPD,SAAS;IACTD,SAAS;IACTF,cAAc;AAChB;AAEA,MAAMW,iCAA8C;IAClD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED;;CAEC,GACD,SAASC,iCAAiCC,KAAa,EAAEC,IAAe;IACtE,MAAMC,iBAAiBF,QAAQH,qBAAqB,CAACI,KAAK;IAE1D,oBAAoB;IACpB,MAAME,kBAAkBL,8BAA8B,CAAC,EAAE,IAAI;IAC7D,IAAIM,WAAsBD;IAC1B,IAAIE,kBAA0BH,iBAAiBL,qBAAqB,CAACM,gBAAgB;IAErF,KAAKC,YAAYN,+BAAgC;QAC/CO,kBAAkBH,iBAAiBL,qBAAqB,CAACO,SAAS;QAClE,IAAIC,mBAAmB,GAAG;YACxB,OAAO;gBAAEL,OAAOK;gBAAiBJ,MAAMG;YAAS;QAClD;IACF;IAEA,6GAA6G;IAC7G,OAAO;QAAEJ,OAAOK;QAAiBJ,MAAMG;IAAS;AAClD;AAEA,SAASE,cAAcL,IAAe;IACpC,OAAOA,SAAS,YAAYA,SAAS;AACvC;AAEA,OAAO,SAASM,WAAWP,KAAa,EAAE,EAAEC,IAAI,EAAEhB,aAAa,EAAqB;IAClF,IAAIe,UAAU,GAAG,OAAO;IAExB,MAAMQ,UAAUT,iCAAiCC,OAAOC;IAExD,MAAMQ,mBAA6C;QACjDC,OAAO;QACPT,MAAML,oBAAoB,CAACY,QAAQP,IAAI,CAAC;QACxCU,aAAaL,cAAcE,QAAQP,IAAI,IAAI,SAAS;IACtD;IAEA,IAAItB,iBAAiBM,gBAAgB;QACnCwB,iBAAiBG,qBAAqB,GAAGhC,mBAAmBK;QAC5DwB,iBAAiBI,qBAAqB,GAAGjC,mBAAmBK;IAC9D,OAAO;QACLwB,iBAAiBK,wBAAwB,GAAGpC;IAC9C;IAEA,MAAMqC,YAAYC,KAAKC,YAAY,CAAC,SAASR;IAC7C,OAAOM,UAAUG,MAAM,CAACV,QAAQR,KAAK;AACvC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare
|
|
1
|
+
import { AbsoluteTimeRange, DurationString } from '../time';
|
|
2
|
+
import { FormatOptions } from './units';
|
|
3
|
+
export declare const UNIT_GROUPS: readonly ["Time", "Percent", "Decimal", "Bytes", "Throughput"];
|
|
4
|
+
export type UnitGroup = (typeof UNIT_GROUPS)[number];
|
|
4
5
|
/**
|
|
5
6
|
* Configuration for rendering units that are part of a group.
|
|
6
7
|
*/
|
|
7
|
-
export
|
|
8
|
+
export type UnitGroupConfig = {
|
|
8
9
|
/**
|
|
9
10
|
* The label that is shown in the UI.
|
|
10
11
|
*/
|
|
@@ -12,16 +13,16 @@ export declare type UnitGroupConfig = {
|
|
|
12
13
|
/**
|
|
13
14
|
* When true, the unit group supports setting decimal places.
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
|
+
decimalPlaces?: boolean;
|
|
16
17
|
/**
|
|
17
|
-
* When true, the unit group supports enabling
|
|
18
|
+
* When true, the unit group supports enabling shortValues.
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
+
shortValues?: boolean;
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Configuration for rendering a specific unit.
|
|
23
24
|
*/
|
|
24
|
-
export
|
|
25
|
+
export type UnitConfig = {
|
|
25
26
|
/**
|
|
26
27
|
* The group the unit is part of. This will inform common rendering behavior.
|
|
27
28
|
*/
|
|
@@ -41,7 +42,15 @@ export declare type UnitConfig = {
|
|
|
41
42
|
*/
|
|
42
43
|
export interface UnitTestCase {
|
|
43
44
|
value: number;
|
|
44
|
-
|
|
45
|
+
format: FormatOptions;
|
|
45
46
|
expected: string;
|
|
46
47
|
}
|
|
48
|
+
export interface IntervalTestCase {
|
|
49
|
+
timeRange: AbsoluteTimeRange;
|
|
50
|
+
expected: Duration;
|
|
51
|
+
}
|
|
52
|
+
export interface FormatTestCase {
|
|
53
|
+
duration: Duration;
|
|
54
|
+
expected: DurationString;
|
|
55
|
+
}
|
|
47
56
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,eAAO,MAAM,WAAW,gEAAiE,CAAC;AAC1F,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;CAC1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/types.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\n// Common types needed across individual unit groups and the overall combined\n// units.\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/types.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\n// Common types needed across individual unit groups and the overall combined\n// units.\n\nimport { AbsoluteTimeRange, DurationString } from '../time';\nimport { FormatOptions } from './units';\n\nexport const UNIT_GROUPS = ['Time', 'Percent', 'Decimal', 'Bytes', 'Throughput'] as const;\nexport type UnitGroup = (typeof UNIT_GROUPS)[number];\n\n/**\n * Configuration for rendering units that are part of a group.\n */\nexport type UnitGroupConfig = {\n /**\n * The label that is shown in the UI.\n */\n label: string;\n /**\n * When true, the unit group supports setting decimal places.\n */\n decimalPlaces?: boolean;\n /**\n * When true, the unit group supports enabling shortValues.\n */\n shortValues?: boolean;\n};\n\n/**\n * Configuration for rendering a specific unit.\n */\nexport type UnitConfig = {\n /**\n * The group the unit is part of. This will inform common rendering behavior.\n */\n group: UnitGroup;\n\n /**\n * When true, this unit will not be displayed in the unit selector. This is\n * useful for units that are shorthand variants of other units.\n */\n disableSelectorOption?: boolean;\n\n /**\n * The label that is shown in the UI.\n */\n label: string;\n};\n\n/**\n * Used in the tests for each type of unit.\n */\nexport interface UnitTestCase {\n value: number;\n format: FormatOptions;\n expected: string;\n}\n\nexport interface IntervalTestCase {\n timeRange: AbsoluteTimeRange;\n expected: Duration;\n}\n\nexport interface FormatTestCase {\n duration: Duration;\n expected: DurationString;\n}\n"],"names":["UNIT_GROUPS"],"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,6EAA6E;AAC7E,SAAS;AAKT,OAAO,MAAMA,cAAc;IAAC;IAAQ;IAAW;IAAW;IAAS;CAAa,CAAU"}
|
|
@@ -1,40 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { BytesFormatOptions as BytesFormatOptions } from './bytes';
|
|
2
|
+
import { DecimalFormatOptions as DecimalFormatOptions } from './decimal';
|
|
3
|
+
import { PercentFormatOptions as PercentFormatOptions } from './percent';
|
|
4
|
+
import { TimeFormatOptions as TimeFormatOptions } from './time';
|
|
5
5
|
import { UnitGroup, UnitGroupConfig, UnitConfig } from './types';
|
|
6
|
+
import { ThroughputFormatOptions } from './throughput';
|
|
7
|
+
/**
|
|
8
|
+
* Most of the number formatting is based on Intl.NumberFormat, which is built into JavaScript.
|
|
9
|
+
* Prefer Intl.NumbeFormat because it covers most use cases and will continue to be supported with time.
|
|
10
|
+
*
|
|
11
|
+
* To format bytes, we also make use of the `numbro` package,
|
|
12
|
+
* because it can handle adding units like KB, MB, GB, etc. correctly.
|
|
13
|
+
*/
|
|
6
14
|
export declare const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>>;
|
|
7
15
|
export declare const UNIT_CONFIG: {
|
|
8
|
-
readonly
|
|
9
|
-
readonly
|
|
10
|
-
readonly
|
|
11
|
-
readonly
|
|
16
|
+
readonly "counts/sec": UnitConfig;
|
|
17
|
+
readonly "events/sec": UnitConfig;
|
|
18
|
+
readonly "messages/sec": UnitConfig;
|
|
19
|
+
readonly "ops/sec": UnitConfig;
|
|
20
|
+
readonly "packets/sec": UnitConfig;
|
|
21
|
+
readonly "reads/sec": UnitConfig;
|
|
22
|
+
readonly "records/sec": UnitConfig;
|
|
23
|
+
readonly "requests/sec": UnitConfig;
|
|
24
|
+
readonly "rows/sec": UnitConfig;
|
|
25
|
+
readonly "writes/sec": UnitConfig;
|
|
26
|
+
readonly bytes: UnitConfig;
|
|
27
|
+
readonly decimal: UnitConfig;
|
|
28
|
+
readonly percent: UnitConfig;
|
|
29
|
+
readonly "percent-decimal": UnitConfig;
|
|
12
30
|
readonly "%": UnitConfig;
|
|
13
|
-
readonly
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
16
|
-
readonly
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
19
|
-
readonly
|
|
20
|
-
readonly
|
|
31
|
+
readonly milliseconds: UnitConfig;
|
|
32
|
+
readonly seconds: UnitConfig;
|
|
33
|
+
readonly minutes: UnitConfig;
|
|
34
|
+
readonly hours: UnitConfig;
|
|
35
|
+
readonly days: UnitConfig;
|
|
36
|
+
readonly weeks: UnitConfig;
|
|
37
|
+
readonly months: UnitConfig;
|
|
38
|
+
readonly years: UnitConfig;
|
|
21
39
|
};
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
40
|
+
export type FormatOptions = TimeFormatOptions | PercentFormatOptions | DecimalFormatOptions | BytesFormatOptions | ThroughputFormatOptions;
|
|
41
|
+
type HasDecimalPlaces<UnitOpt> = UnitOpt extends {
|
|
42
|
+
decimalPlaces?: number;
|
|
25
43
|
} ? UnitOpt : never;
|
|
26
|
-
|
|
27
|
-
|
|
44
|
+
type HasShortValues<UnitOpt> = UnitOpt extends {
|
|
45
|
+
shortValues?: boolean;
|
|
28
46
|
} ? UnitOpt : never;
|
|
29
|
-
export declare function formatValue(value: number,
|
|
30
|
-
export declare function
|
|
31
|
-
export declare function getUnitGroup(
|
|
32
|
-
export declare function getUnitGroupConfig(
|
|
33
|
-
export declare function isTimeUnit(
|
|
34
|
-
export declare function isPercentUnit(
|
|
35
|
-
export declare function isDecimalUnit(
|
|
36
|
-
export declare function isBytesUnit(
|
|
37
|
-
export declare function isUnitWithDecimalPlaces(
|
|
38
|
-
export declare function
|
|
47
|
+
export declare function formatValue(value: number, formatOptions?: FormatOptions): string;
|
|
48
|
+
export declare function getUnitConfig(formatOptions: FormatOptions): UnitConfig;
|
|
49
|
+
export declare function getUnitGroup(formatOptions: FormatOptions): UnitGroup;
|
|
50
|
+
export declare function getUnitGroupConfig(formatOptions: FormatOptions): UnitGroupConfig;
|
|
51
|
+
export declare function isTimeUnit(formatOptions: FormatOptions): formatOptions is TimeFormatOptions;
|
|
52
|
+
export declare function isPercentUnit(formatOptions: FormatOptions): formatOptions is PercentFormatOptions;
|
|
53
|
+
export declare function isDecimalUnit(formatOptions: FormatOptions): formatOptions is DecimalFormatOptions;
|
|
54
|
+
export declare function isBytesUnit(formatOptions: FormatOptions): formatOptions is BytesFormatOptions;
|
|
55
|
+
export declare function isUnitWithDecimalPlaces(formatOptions: FormatOptions): formatOptions is HasDecimalPlaces<FormatOptions>;
|
|
56
|
+
export declare function isUnitWithShortValues(formatOptions: FormatOptions): formatOptions is HasShortValues<FormatOptions>;
|
|
57
|
+
export declare function isThroughputUnit(formatOptions: FormatOptions): formatOptions is ThroughputFormatOptions;
|
|
39
58
|
export {};
|
|
40
59
|
//# sourceMappingURL=units.d.ts.map
|
|
@@ -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,kBAAkB,IAAI,kBAAkB,EAAyC,MAAM,SAAS,CAAC;AACvH,OAAO,EAEL,oBAAoB,IAAI,oBAAoB,EAG7C,MAAM,WAAW,CAAC;AACnB,OAAO,EAEL,oBAAoB,IAAI,oBAAoB,EAG7C,MAAM,WAAW,CAAC;AACnB,OAAO,EAAc,iBAAiB,IAAI,iBAAiB,EAAuC,MAAM,QAAQ,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACjE,OAAO,EAIL,uBAAuB,EACxB,MAAM,cAAc,CAAC;AAEtB;;;;;;GAMG;AAEH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,CAM1E,CAAC;AACF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;CAMd,CAAC;AAEX,MAAM,MAAM,aAAa,GACrB,iBAAiB,GACjB,oBAAoB,GACpB,oBAAoB,GACpB,kBAAkB,GAClB,uBAAuB,CAAC;AAE5B,KAAK,gBAAgB,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAC9F,KAAK,cAAc,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAE3F,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,aAAa,GAAG,MAAM,CA2BhF;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,UAAU,CAEtE;AAED,wBAAgB,YAAY,CAAC,aAAa,EAAE,aAAa,GAAG,SAAS,CAEpE;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,aAAa,GAAG,eAAe,CAGhF;AAGD,wBAAgB,UAAU,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,iBAAiB,CAE3F;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,oBAAoB,CAEjG;AAED,wBAAgB,aAAa,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,oBAAoB,CAEjG;AAED,wBAAgB,WAAW,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,kBAAkB,CAE7F;AAED,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,aAAa,GAC3B,aAAa,IAAI,gBAAgB,CAAC,aAAa,CAAC,CAIlD;AAED,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,cAAc,CAAC,aAAa,CAAC,CAIlH;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,aAAa,IAAI,uBAAuB,CAEvG"}
|