@perses-dev/components 0.19.0 → 0.21.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/DateTimeRangePicker/AbsoluteTimePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
- package/dist/DateTimeRangePicker/AbsoluteTimePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -0
- package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
- package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +1 -0
- package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/TimeRangeSelector.js +9 -3
- package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
- package/dist/DateTimeRangePicker/utils.d.ts +1 -1
- package/dist/DateTimeRangePicker/utils.d.ts.map +1 -1
- package/dist/DateTimeRangePicker/utils.js +5 -4
- package/dist/DateTimeRangePicker/utils.js.map +1 -1
- package/dist/GaugeChart/GaugeChart.d.ts +11 -2
- package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
- package/dist/GaugeChart/GaugeChart.js +58 -10
- package/dist/GaugeChart/GaugeChart.js.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.d.ts +3 -1
- package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
- package/dist/InfoTooltip/InfoTooltip.js +4 -2
- package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +8 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js +82 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +2 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +41 -0
- package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +1 -0
- package/dist/LegendOptionsEditor/index.d.ts +2 -0
- package/dist/LegendOptionsEditor/index.d.ts.map +1 -0
- package/dist/LegendOptionsEditor/index.js +15 -0
- package/dist/LegendOptionsEditor/index.js.map +1 -0
- package/dist/LineChart/LineChart.d.ts +2 -3
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +39 -34
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/LineChart/utils.d.ts +1 -1
- package/dist/LineChart/utils.d.ts.map +1 -1
- package/dist/LineChart/utils.js +4 -3
- package/dist/LineChart/utils.js.map +1 -1
- package/dist/StatChart/StatChart.test.js +42 -21
- package/dist/StatChart/StatChart.test.js.map +1 -1
- package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
- package/dist/Tooltip/TooltipContent.js +8 -9
- package/dist/Tooltip/TooltipContent.js.map +1 -1
- package/dist/UnitSelector/UnitSelector.test.js +3 -10
- package/dist/UnitSelector/UnitSelector.test.js.map +1 -1
- package/dist/cjs/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
- package/dist/cjs/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
- package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +9 -3
- package/dist/cjs/DateTimeRangePicker/utils.js +4 -3
- package/dist/cjs/GaugeChart/GaugeChart.js +66 -15
- package/dist/cjs/InfoTooltip/InfoTooltip.js +4 -2
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +88 -0
- package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +48 -0
- package/dist/cjs/LegendOptionsEditor/index.js +28 -0
- package/dist/cjs/LineChart/LineChart.js +40 -35
- package/dist/cjs/LineChart/utils.js +4 -3
- package/dist/cjs/StatChart/StatChart.test.js +43 -27
- package/dist/cjs/Tooltip/TooltipContent.js +8 -9
- package/dist/cjs/UnitSelector/UnitSelector.test.js +3 -10
- package/dist/cjs/context/TimeZoneProvider.js +90 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/model/graph.js +14 -3
- package/dist/cjs/model/units/bytes.js +32 -6
- package/dist/cjs/model/units/time.js +26 -62
- package/dist/cjs/model/units/units.js +1 -4
- package/dist/cjs/model/units/units.test.js +153 -0
- package/dist/cjs/theme/theme.js +19 -0
- package/dist/cjs/utils/format.js +56 -0
- package/dist/cjs/utils/format.test.js +47 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/context/TimeZoneProvider.d.ts +13 -0
- package/dist/context/TimeZoneProvider.d.ts.map +1 -0
- package/dist/context/TimeZoneProvider.js +38 -0
- package/dist/context/TimeZoneProvider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +4 -2
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js +4 -0
- package/dist/model/graph.js.map +1 -1
- package/dist/model/units/bytes.d.ts +6 -1
- package/dist/model/units/bytes.d.ts.map +1 -1
- package/dist/model/units/bytes.js +35 -7
- package/dist/model/units/bytes.js.map +1 -1
- package/dist/model/units/time.d.ts +11 -0
- package/dist/model/units/time.d.ts.map +1 -1
- package/dist/model/units/time.js +25 -62
- package/dist/model/units/time.js.map +1 -1
- package/dist/model/units/units.d.ts.map +1 -1
- package/dist/model/units/units.js +1 -4
- package/dist/model/units/units.js.map +1 -1
- package/dist/model/units/units.test.d.ts +2 -0
- package/dist/model/units/units.test.d.ts.map +1 -0
- package/dist/model/units/units.test.js +151 -0
- package/dist/model/units/units.test.js.map +1 -0
- package/dist/theme/theme.d.ts +2 -2
- package/dist/theme/theme.d.ts.map +1 -1
- package/dist/theme/theme.js +19 -0
- package/dist/theme/theme.js.map +1 -1
- package/dist/utils/format.d.ts +3 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +44 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/format.test.d.ts +2 -0
- package/dist/utils/format.test.d.ts.map +1 -0
- package/dist/utils/format.test.js +45 -0
- package/dist/utils/format.test.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -10,12 +10,14 @@
|
|
|
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 { DEFAULT_DECIMAL_PLACES } from './constants';
|
|
13
14
|
const bytesUnitKinds = [
|
|
14
15
|
'Bytes'
|
|
15
16
|
];
|
|
16
17
|
export const BYTES_GROUP_CONFIG = {
|
|
17
18
|
label: 'Bytes',
|
|
18
|
-
decimal_places: true
|
|
19
|
+
decimal_places: true,
|
|
20
|
+
abbreviate: true
|
|
19
21
|
};
|
|
20
22
|
export const BYTES_UNIT_CONFIG = {
|
|
21
23
|
Bytes: {
|
|
@@ -23,13 +25,38 @@ export const BYTES_UNIT_CONFIG = {
|
|
|
23
25
|
label: 'Bytes'
|
|
24
26
|
}
|
|
25
27
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Format value as bytes, use abbreviate option for more readable sizes (KB, MB, GB, etc.)
|
|
30
|
+
* https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828
|
|
31
|
+
*/ export function formatBytes(bytes, unitOptions) {
|
|
32
|
+
if (bytes === 0) return '0 bytes';
|
|
33
|
+
// default to full 'Bytes' formatting
|
|
34
|
+
const options = unitOptions.abbreviate === undefined ? {
|
|
35
|
+
...unitOptions,
|
|
36
|
+
abbreviate: false
|
|
37
|
+
} : unitOptions;
|
|
38
|
+
var _decimal_places;
|
|
39
|
+
let decimals = (_decimal_places = options.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
40
|
+
// avoids minimumFractionDigits value is out of range error, possible values are 0 to 20
|
|
41
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits
|
|
42
|
+
if (decimals < 0) {
|
|
43
|
+
decimals = 0;
|
|
44
|
+
} else if (decimals > 20) {
|
|
45
|
+
decimals = 20;
|
|
46
|
+
}
|
|
47
|
+
const formatParams = {
|
|
48
|
+
style: 'decimal',
|
|
49
|
+
minimumFractionDigits: decimals,
|
|
50
|
+
maximumFractionDigits: decimals,
|
|
51
|
+
useGrouping: true
|
|
52
|
+
};
|
|
53
|
+
const formatter = new Intl.NumberFormat('en-US', formatParams);
|
|
54
|
+
if (options.abbreviate === false) {
|
|
55
|
+
return `${formatter.format(bytes)} bytes`;
|
|
56
|
+
}
|
|
29
57
|
const k = 1024;
|
|
30
|
-
const dm = decimals < 0 ? 0 : decimals;
|
|
31
58
|
const sizes = [
|
|
32
|
-
'
|
|
59
|
+
'bytes',
|
|
33
60
|
'KB',
|
|
34
61
|
'MB',
|
|
35
62
|
'GB',
|
|
@@ -42,7 +69,8 @@ export function formatBytes(bytes, decimals = 2) {
|
|
|
42
69
|
// Math.max(0, ...) ensures that we don't return -1 as a value for the index.
|
|
43
70
|
// Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
|
|
44
71
|
const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
|
|
45
|
-
|
|
72
|
+
const abbreviatedValue = bytes / Math.pow(k, i);
|
|
73
|
+
return `${formatter.format(abbreviatedValue)} ${sizes[i]}`;
|
|
46
74
|
}
|
|
47
75
|
|
|
48
76
|
//# sourceMappingURL=bytes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2022 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 { UnitGroupConfig, UnitConfig } from './types';\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = typeof bytesUnitKinds[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\n
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2022 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 { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\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\n/**\n * Format value as bytes, use abbreviate option for more readable sizes (KB, MB, GB, etc.)\n * https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828\n */\nexport function formatBytes(bytes: number, unitOptions: BytesUnitOptions) {\n if (bytes === 0) return '0 bytes';\n\n // default to full 'Bytes' formatting\n const options = unitOptions.abbreviate === undefined ? { ...unitOptions, abbreviate: false } : unitOptions;\n\n let decimals = options.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n // avoids minimumFractionDigits value is out of range error, possible values are 0 to 20\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits\n if (decimals < 0) {\n decimals = 0;\n } else if (decimals > 20) {\n decimals = 20;\n }\n\n const formatParams: Intl.NumberFormatOptions = {\n style: 'decimal',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n };\n const formatter = new Intl.NumberFormat('en-US', formatParams);\n\n if (options.abbreviate === false) {\n return `${formatter.format(bytes)} bytes`;\n }\n\n const k = 1024;\n const sizes = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n // Math.max(0, ...) ensures that we don't return -1 as a value for the index.\n // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.\n const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));\n const abbreviatedValue = bytes / Math.pow(k, i);\n return `${formatter.format(abbreviatedValue)} ${sizes[i]}`;\n}\n"],"names":["DEFAULT_DECIMAL_PLACES","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","unitOptions","options","undefined","decimals","formatParams","style","minimumFractionDigits","maximumFractionDigits","useGrouping","formatter","Intl","NumberFormat","format","k","sizes","i","Math","max","floor","log","abbreviatedValue","pow"],"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;AAGrD,MAAMC,cAAc,GAAG;IAAC,OAAO;CAAC,AAAS,AAAC;AAO1C,OAAO,MAAMC,kBAAkB,GAAoB;IACjDC,KAAK,EAAE,OAAO;IACdC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,iBAAiB,GAAgD;IAC5EC,KAAK,EAAE;QACLC,KAAK,EAAE,OAAO;QACdL,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF;;;CAGC,GACD,OAAO,SAASM,WAAW,CAACC,KAAa,EAAEC,WAA6B,EAAE;IACxE,IAAID,KAAK,KAAK,CAAC,EAAE,OAAO,SAAS,CAAC;IAElC,qCAAqC;IACrC,MAAME,OAAO,GAAGD,WAAW,CAACN,UAAU,KAAKQ,SAAS,GAAG;QAAE,GAAGF,WAAW;QAAEN,UAAU,EAAE,KAAK;KAAE,GAAGM,WAAW,AAAC;QAE5FC,eAAsB;IAArC,IAAIE,QAAQ,GAAGF,CAAAA,eAAsB,GAAtBA,OAAO,CAACR,cAAc,cAAtBQ,eAAsB,cAAtBA,eAAsB,GAAIZ,sBAAsB,AAAC;IAChE,wFAAwF;IACxF,wIAAwI;IACxI,IAAIc,QAAQ,GAAG,CAAC,EAAE;QAChBA,QAAQ,GAAG,CAAC,CAAC;IACf,OAAO,IAAIA,QAAQ,GAAG,EAAE,EAAE;QACxBA,QAAQ,GAAG,EAAE,CAAC;IAChB,CAAC;IAED,MAAMC,YAAY,GAA6B;QAC7CC,KAAK,EAAE,SAAS;QAChBC,qBAAqB,EAAEH,QAAQ;QAC/BI,qBAAqB,EAAEJ,QAAQ;QAC/BK,WAAW,EAAE,IAAI;KAClB,AAAC;IACF,MAAMC,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,YAAY,CAAC,AAAC;IAE/D,IAAIH,OAAO,CAACP,UAAU,KAAK,KAAK,EAAE;QAChC,OAAO,CAAC,EAAEe,SAAS,CAACG,MAAM,CAACb,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,MAAMc,CAAC,GAAG,IAAI,AAAC;IACf,MAAMC,KAAK,GAAG;QAAC,OAAO;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;KAAC,AAAC;IAExE,6EAA6E;IAC7E,6GAA6G;IAC7G,MAAMC,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAACF,IAAI,CAACG,GAAG,CAACpB,KAAK,CAAC,GAAGiB,IAAI,CAACG,GAAG,CAACN,CAAC,CAAC,CAAC,CAAC,AAAC;IACjE,MAAMO,gBAAgB,GAAGrB,KAAK,GAAGiB,IAAI,CAACK,GAAG,CAACR,CAAC,EAAEE,CAAC,CAAC,AAAC;IAChD,OAAO,CAAC,EAAEN,SAAS,CAACG,MAAM,CAACQ,gBAAgB,CAAC,CAAC,CAAC,EAAEN,KAAK,CAACC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -3,9 +3,20 @@ declare const timeUnitKinds: readonly ["Milliseconds", "Seconds", "Minutes", "Ho
|
|
|
3
3
|
declare type TimeUnitKind = typeof timeUnitKinds[number];
|
|
4
4
|
export declare type TimeUnitOptions = {
|
|
5
5
|
kind: TimeUnitKind;
|
|
6
|
+
decimal_places?: number;
|
|
6
7
|
};
|
|
7
8
|
export declare const TIME_GROUP_CONFIG: UnitGroupConfig;
|
|
8
9
|
export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>>;
|
|
10
|
+
export declare enum TimeIntlDuration {
|
|
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
|
+
}
|
|
9
20
|
export declare function formatTime(value: number, unitOptions: TimeUnitOptions): string;
|
|
10
21
|
export {};
|
|
11
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;AAEtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;AACjD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;
|
|
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;AAEtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;AACjD,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,gBAAgB;IAC1B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,GAAG,MAAM,CAW9E"}
|
package/dist/model/units/time.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
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 {
|
|
13
|
+
import { DEFAULT_DECIMAL_PLACES } from './constants';
|
|
14
14
|
const timeUnitKinds = [
|
|
15
15
|
'Milliseconds',
|
|
16
16
|
'Seconds',
|
|
@@ -23,7 +23,8 @@ const timeUnitKinds = [
|
|
|
23
23
|
];
|
|
24
24
|
const TIME_GROUP = 'Time';
|
|
25
25
|
export const TIME_GROUP_CONFIG = {
|
|
26
|
-
label: 'Time'
|
|
26
|
+
label: 'Time',
|
|
27
|
+
decimal_places: true
|
|
27
28
|
};
|
|
28
29
|
export const TIME_UNIT_CONFIG = {
|
|
29
30
|
Milliseconds: {
|
|
@@ -59,67 +60,29 @@ export const TIME_UNIT_CONFIG = {
|
|
|
59
60
|
label: 'Years'
|
|
60
61
|
}
|
|
61
62
|
};
|
|
63
|
+
export var TimeIntlDuration;
|
|
64
|
+
(function(TimeIntlDuration) {
|
|
65
|
+
TimeIntlDuration["Milliseconds"] = 'millisecond';
|
|
66
|
+
TimeIntlDuration["Seconds"] = 'second';
|
|
67
|
+
TimeIntlDuration["Minutes"] = 'minute';
|
|
68
|
+
TimeIntlDuration["Hours"] = 'hour';
|
|
69
|
+
TimeIntlDuration["Days"] = 'day';
|
|
70
|
+
TimeIntlDuration["Weeks"] = 'week';
|
|
71
|
+
TimeIntlDuration["Months"] = 'month';
|
|
72
|
+
TimeIntlDuration["Years"] = 'year';
|
|
73
|
+
})(TimeIntlDuration || (TimeIntlDuration = {}));
|
|
62
74
|
export function formatTime(value, unitOptions) {
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
break;
|
|
75
|
-
case 'Hours':
|
|
76
|
-
duration.hours = value;
|
|
77
|
-
break;
|
|
78
|
-
case 'Days':
|
|
79
|
-
duration.days = value;
|
|
80
|
-
break;
|
|
81
|
-
case 'Weeks':
|
|
82
|
-
duration.weeks = value;
|
|
83
|
-
break;
|
|
84
|
-
case 'Months':
|
|
85
|
-
duration.months = value;
|
|
86
|
-
break;
|
|
87
|
-
case 'Years':
|
|
88
|
-
duration.years = value;
|
|
89
|
-
break;
|
|
90
|
-
default:
|
|
91
|
-
{
|
|
92
|
-
const exhaustive = unitOptions.kind;
|
|
93
|
-
throw new Error(`Unknown time unit type ${exhaustive}`);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
// Find the largest whole time unit we can display the value in and use it
|
|
97
|
-
const ms = milliseconds(duration);
|
|
98
|
-
const seconds = ms / 1000;
|
|
99
|
-
if (seconds < 1) {
|
|
100
|
-
return `${ms.toFixed()} milliseconds`;
|
|
101
|
-
}
|
|
102
|
-
const minutes = seconds / 60;
|
|
103
|
-
if (minutes < 1) {
|
|
104
|
-
return `${seconds.toFixed()} seconds`;
|
|
105
|
-
}
|
|
106
|
-
const hours = minutes / 60;
|
|
107
|
-
if (hours < 1) {
|
|
108
|
-
return `${minutes.toFixed()} minutes`;
|
|
109
|
-
}
|
|
110
|
-
const days = hours / 24;
|
|
111
|
-
if (days < 1) {
|
|
112
|
-
return `${hours.toFixed()} hours`;
|
|
113
|
-
}
|
|
114
|
-
const weeks = days / 7;
|
|
115
|
-
if (weeks < 1) {
|
|
116
|
-
return `${days.toFixed()} days`;
|
|
117
|
-
}
|
|
118
|
-
const years = weeks / 52;
|
|
119
|
-
if (years < 1) {
|
|
120
|
-
return `${weeks.toFixed()} weeks`;
|
|
121
|
-
}
|
|
122
|
-
return `${years.toFixed()} years`;
|
|
75
|
+
var _decimal_places;
|
|
76
|
+
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
77
|
+
const timeUnit = TimeIntlDuration[unitOptions.kind];
|
|
78
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
79
|
+
style: 'unit',
|
|
80
|
+
unit: timeUnit,
|
|
81
|
+
unitDisplay: 'long',
|
|
82
|
+
minimumFractionDigits: decimals,
|
|
83
|
+
maximumFractionDigits: decimals
|
|
84
|
+
});
|
|
85
|
+
return formatter.format(value);
|
|
123
86
|
}
|
|
124
87
|
|
|
125
88
|
//# sourceMappingURL=time.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2022 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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2022 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 { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\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 TimeIntlDuration {\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\nexport function formatTime(value: number, unitOptions: TimeUnitOptions): string {\n const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n const timeUnit: string = TimeIntlDuration[unitOptions.kind];\n const formatter = new Intl.NumberFormat('en-US', {\n style: 'unit',\n unit: timeUnit,\n unitDisplay: 'long',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n });\n return formatter.format(value);\n}\n"],"names":["DEFAULT_DECIMAL_PLACES","timeUnitKinds","TIME_GROUP","TIME_GROUP_CONFIG","label","decimal_places","TIME_UNIT_CONFIG","Milliseconds","group","Seconds","Minutes","Hours","Days","Weeks","Months","Years","TimeIntlDuration","formatTime","value","unitOptions","decimals","timeUnit","kind","formatter","Intl","NumberFormat","style","unit","unitDisplay","minimumFractionDigits","maximumFractionDigits","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;AAGrD,MAAMC,aAAa,GAAG;IAAC,cAAc;IAAE,SAAS;IAAE,SAAS;IAAE,OAAO;IAAE,MAAM;IAAE,OAAO;IAAE,QAAQ;IAAE,OAAO;CAAC,AAAS,AAAC;AAMnH,MAAMC,UAAU,GAAG,MAAM,AAAC;AAC1B,OAAO,MAAMC,iBAAiB,GAAoB;IAChDC,KAAK,EAAE,MAAM;IACbC,cAAc,EAAE,IAAI;CACrB,CAAC;AACF,OAAO,MAAMC,gBAAgB,GAA+C;IAC1EC,YAAY,EAAE;QACZC,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,cAAc;KACtB;IACDK,OAAO,EAAE;QACPD,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,SAAS;KACjB;IACDM,OAAO,EAAE;QACPF,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,SAAS;KACjB;IACDO,KAAK,EAAE;QACLH,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,OAAO;KACf;IACDQ,IAAI,EAAE;QACJJ,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,MAAM;KACd;IACDS,KAAK,EAAE;QACLL,KAAK,EAAEN,UAAU;QAC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E,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"}
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG, formatBytes } from './bytes';
|
|
14
|
-
import { DEFAULT_DECIMAL_PLACES } from './constants';
|
|
15
14
|
import { DECIMAL_UNIT_CONFIG, formatDecimal, PERCENT_GROUP_CONFIG } from './decimal';
|
|
16
15
|
import { DECIMAL_GROUP_CONFIG, formatPercent, PERCENT_UNIT_CONFIG } from './percent';
|
|
17
16
|
import { formatTime, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';
|
|
@@ -41,9 +40,7 @@ export function formatValue(value, unitOptions) {
|
|
|
41
40
|
return formatPercent(value, unitOptions);
|
|
42
41
|
}
|
|
43
42
|
if (isBytesUnit(unitOptions)) {
|
|
44
|
-
|
|
45
|
-
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
46
|
-
return formatBytes(value, decimals);
|
|
43
|
+
return formatBytes(value, unitOptions);
|
|
47
44
|
}
|
|
48
45
|
const exhaustive = unitOptions;
|
|
49
46
|
throw new Error(`Unknown unit options ${exhaustive}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/units/units.ts"],"sourcesContent":["// Copyright 2022 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, formatBytes } from './bytes';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/units.ts"],"sourcesContent":["// Copyright 2022 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, formatBytes } from './bytes';\nimport { DecimalUnitOptions, DECIMAL_UNIT_CONFIG, formatDecimal, PERCENT_GROUP_CONFIG } from './decimal';\nimport { DECIMAL_GROUP_CONFIG, formatPercent, PercentUnitOptions, PERCENT_UNIT_CONFIG } from './percent';\nimport { formatTime, TimeUnitOptions, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\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 (isDecimalUnit(unitOptions)) {\n return formatDecimal(value, unitOptions);\n }\n\n if (isTimeUnit(unitOptions)) {\n return formatTime(value, unitOptions);\n }\n\n if (isPercentUnit(unitOptions)) {\n return formatPercent(value, unitOptions);\n }\n\n if (isBytesUnit(unitOptions)) {\n return formatBytes(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":["BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatBytes","DECIMAL_UNIT_CONFIG","formatDecimal","PERCENT_GROUP_CONFIG","DECIMAL_GROUP_CONFIG","formatPercent","PERCENT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","UNIT_CONFIG","formatValue","value","unitOptions","undefined","toString","isDecimalUnit","isTimeUnit","isPercentUnit","isBytesUnit","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,SAA2BA,kBAAkB,EAAEC,iBAAiB,EAAEC,WAAW,QAAQ,SAAS,CAAC;AAC/F,SAA6BC,mBAAmB,EAAEC,aAAa,EAAEC,oBAAoB,QAAQ,WAAW,CAAC;AACzG,SAASC,oBAAoB,EAAEC,aAAa,EAAsBC,mBAAmB,QAAQ,WAAW,CAAC;AACzG,SAASC,UAAU,EAAmBC,iBAAiB,EAAEC,gBAAgB,QAAQ,QAAQ,CAAC;AAG1F,OAAO,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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,SAASR,UAAU,CAACJ,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,SAASG,aAAa,CAACH,WAAwB,EAAqC;IACzF,OAAOW,YAAY,CAACX,WAAW,CAAC,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,OAAO,SAASM,WAAW,CAACN,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.test.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// Copyright 2022 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 { formatValue } from './units';
|
|
14
|
+
describe('formatValue()', ()=>{
|
|
15
|
+
const tests = [
|
|
16
|
+
{
|
|
17
|
+
value: 100000,
|
|
18
|
+
unit: {
|
|
19
|
+
kind: 'Decimal'
|
|
20
|
+
},
|
|
21
|
+
expected: '100,000.00'
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
value: 155900,
|
|
25
|
+
unit: {
|
|
26
|
+
kind: 'Decimal',
|
|
27
|
+
decimal_places: 4
|
|
28
|
+
},
|
|
29
|
+
expected: '155,900.0000'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
value: 10,
|
|
33
|
+
unit: {
|
|
34
|
+
kind: 'Percent'
|
|
35
|
+
},
|
|
36
|
+
expected: '10.00%'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
value: 50,
|
|
40
|
+
unit: {
|
|
41
|
+
kind: 'Percent',
|
|
42
|
+
decimal_places: 0
|
|
43
|
+
},
|
|
44
|
+
expected: '50%'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
value: 0.1,
|
|
48
|
+
unit: {
|
|
49
|
+
kind: 'PercentDecimal'
|
|
50
|
+
},
|
|
51
|
+
expected: '10.00%'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
value: 100,
|
|
55
|
+
unit: {
|
|
56
|
+
kind: 'Bytes',
|
|
57
|
+
decimal_places: 0,
|
|
58
|
+
abbreviate: false
|
|
59
|
+
},
|
|
60
|
+
expected: '100 bytes'
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
value: 100,
|
|
64
|
+
unit: {
|
|
65
|
+
kind: 'Bytes',
|
|
66
|
+
decimal_places: -1,
|
|
67
|
+
abbreviate: false
|
|
68
|
+
},
|
|
69
|
+
expected: '100 bytes'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
value: 225000,
|
|
73
|
+
unit: {
|
|
74
|
+
kind: 'Bytes',
|
|
75
|
+
decimal_places: 0,
|
|
76
|
+
abbreviate: true
|
|
77
|
+
},
|
|
78
|
+
expected: '220 KB'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: 505200,
|
|
82
|
+
unit: {
|
|
83
|
+
kind: 'Bytes'
|
|
84
|
+
},
|
|
85
|
+
expected: '505,200.00 bytes'
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
value: 8000,
|
|
89
|
+
unit: {
|
|
90
|
+
kind: 'Milliseconds'
|
|
91
|
+
},
|
|
92
|
+
expected: '8,000.00 milliseconds'
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
value: 200900,
|
|
96
|
+
unit: {
|
|
97
|
+
kind: 'Seconds'
|
|
98
|
+
},
|
|
99
|
+
expected: '200,900.00 seconds'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
value: 300,
|
|
103
|
+
unit: {
|
|
104
|
+
kind: 'Minutes'
|
|
105
|
+
},
|
|
106
|
+
expected: '300.00 minutes'
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
value: 300,
|
|
110
|
+
unit: {
|
|
111
|
+
kind: 'Hours'
|
|
112
|
+
},
|
|
113
|
+
expected: '300.00 hours'
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
value: 300,
|
|
117
|
+
unit: {
|
|
118
|
+
kind: 'Days'
|
|
119
|
+
},
|
|
120
|
+
expected: '300.00 days'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
value: 300,
|
|
124
|
+
unit: {
|
|
125
|
+
kind: 'Weeks'
|
|
126
|
+
},
|
|
127
|
+
expected: '300.00 weeks'
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
value: 300,
|
|
131
|
+
unit: {
|
|
132
|
+
kind: 'Months'
|
|
133
|
+
},
|
|
134
|
+
expected: '300.00 months'
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
value: 300,
|
|
138
|
+
unit: {
|
|
139
|
+
kind: 'Years'
|
|
140
|
+
},
|
|
141
|
+
expected: '300.00 years'
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
tests.forEach(({ value , unit , expected })=>{
|
|
145
|
+
it(`formats ${value} as ${JSON.stringify(unit)}`, ()=>{
|
|
146
|
+
expect(formatValue(value, unit)).toEqual(expected);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=units.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/model/units/units.test.ts"],"sourcesContent":["// Copyright 2022 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 { formatValue, UnitOptions } from './units';\n\ndescribe('formatValue()', () => {\n const tests = [\n {\n value: 100000,\n unit: { kind: 'Decimal' },\n expected: '100,000.00',\n },\n {\n value: 155900,\n unit: { kind: 'Decimal', decimal_places: 4 },\n expected: '155,900.0000',\n },\n {\n value: 10,\n unit: { kind: 'Percent' },\n expected: '10.00%',\n },\n {\n value: 50,\n unit: { kind: 'Percent', decimal_places: 0 },\n expected: '50%',\n },\n {\n value: 0.1,\n unit: { kind: 'PercentDecimal' },\n expected: '10.00%',\n },\n {\n value: 100,\n unit: { kind: 'Bytes', decimal_places: 0, abbreviate: false },\n expected: '100 bytes',\n },\n {\n value: 100,\n unit: { kind: 'Bytes', decimal_places: -1, abbreviate: false },\n expected: '100 bytes',\n },\n {\n value: 225000,\n unit: { kind: 'Bytes', decimal_places: 0, abbreviate: true },\n expected: '220 KB',\n },\n {\n value: 505200,\n unit: { kind: 'Bytes' },\n expected: '505,200.00 bytes',\n },\n {\n value: 8000,\n unit: { kind: 'Milliseconds' },\n expected: '8,000.00 milliseconds',\n },\n {\n value: 200900,\n unit: { kind: 'Seconds' },\n expected: '200,900.00 seconds',\n },\n {\n value: 300,\n unit: { kind: 'Minutes' },\n expected: '300.00 minutes',\n },\n {\n value: 300,\n unit: { kind: 'Hours' },\n expected: '300.00 hours',\n },\n {\n value: 300,\n unit: { kind: 'Days' },\n expected: '300.00 days',\n },\n {\n value: 300,\n unit: { kind: 'Weeks' },\n expected: '300.00 weeks',\n },\n {\n value: 300,\n unit: { kind: 'Months' },\n expected: '300.00 months',\n },\n {\n value: 300,\n unit: { kind: 'Years' },\n expected: '300.00 years',\n },\n ];\n\n tests.forEach(({ value, unit, expected }) => {\n it(`formats ${value} as ${JSON.stringify(unit)}`, () => {\n expect(formatValue(value, unit as UnitOptions)).toEqual(expected);\n });\n });\n});\n"],"names":["formatValue","describe","tests","value","unit","kind","expected","decimal_places","abbreviate","forEach","it","JSON","stringify","expect","toEqual"],"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,QAAqB,SAAS,CAAC;AAEnDC,QAAQ,CAAC,eAAe,EAAE,IAAM;IAC9B,MAAMC,KAAK,GAAG;QACZ;YACEC,KAAK,EAAE,MAAM;YAC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C;QACpE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/theme/theme.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaletteMode } from '@mui/material';
|
|
1
|
+
import { PaletteMode, Theme } from '@mui/material';
|
|
2
2
|
/**
|
|
3
3
|
* Gets theme used by all components for the provided mode. For more details, see:
|
|
4
4
|
* - Base colors, typography, sizing - go/chrono-ui-theme
|
|
@@ -9,5 +9,5 @@ import { PaletteMode } from '@mui/material';
|
|
|
9
9
|
* Need to reinstantiate the theme everytime to support switching between light and dark themes
|
|
10
10
|
* https://github.com/mui-org/material-ui/issues/18831
|
|
11
11
|
*/
|
|
12
|
-
export declare function getTheme(mode: PaletteMode):
|
|
12
|
+
export declare function getTheme(mode: PaletteMode): Theme;
|
|
13
13
|
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme/theme.ts"],"names":[],"mappings":"AAaA,OAAO,EAAe,WAAW,EAAgB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/theme/theme.ts"],"names":[],"mappings":"AAaA,OAAO,EAAe,WAAW,EAAgB,KAAK,EAAE,MAAM,eAAe,CAAC;AAiB9E;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,SAQzC"}
|
package/dist/theme/theme.js
CHANGED
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
import { createTheme } from '@mui/material';
|
|
14
14
|
import { getPaletteOptions } from './palette/palette-options';
|
|
15
15
|
import { typography } from './typography';
|
|
16
|
+
const getModalBackgroundStyle = ({ theme })=>{
|
|
17
|
+
const backgroundStyle = theme.palette.mode === 'light' ? {} : {
|
|
18
|
+
backgroundImage: 'unset',
|
|
19
|
+
backgroundColor: theme.palette.designSystem.grey[800]
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
...backgroundStyle
|
|
23
|
+
};
|
|
24
|
+
};
|
|
16
25
|
/**
|
|
17
26
|
* Gets theme used by all components for the provided mode. For more details, see:
|
|
18
27
|
* - Base colors, typography, sizing - go/chrono-ui-theme
|
|
@@ -42,6 +51,16 @@ const components = {
|
|
|
42
51
|
defaultProps: {
|
|
43
52
|
size: 'small'
|
|
44
53
|
}
|
|
54
|
+
},
|
|
55
|
+
MuiDrawer: {
|
|
56
|
+
styleOverrides: {
|
|
57
|
+
paper: getModalBackgroundStyle
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
MuiDialog: {
|
|
61
|
+
styleOverrides: {
|
|
62
|
+
paper: getModalBackgroundStyle
|
|
63
|
+
}
|
|
45
64
|
}
|
|
46
65
|
};
|
|
47
66
|
|
package/dist/theme/theme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/theme/theme.ts"],"sourcesContent":["// Copyright 2022 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 { createTheme, PaletteMode, ThemeOptions } from '@mui/material';\nimport { getPaletteOptions } from './palette/palette-options';\nimport { typography } from './typography';\n\n/**\n * Gets theme used by all components for the provided mode. For more details, see:\n * - Base colors, typography, sizing - go/chrono-ui-theme\n * - Material UI defaults: https://material-ui.com/customization/default-theme/\n * - Material UI variables: https://material-ui.com/customization/theming/#theme-configuration-variables\n * - Material UI global overrides and default props: https://material-ui.com/customization/globals/#css\n *\n * Need to reinstantiate the theme everytime to support switching between light and dark themes\n * https://github.com/mui-org/material-ui/issues/18831\n */\nexport function getTheme(mode: PaletteMode) {\n const theme = createTheme({\n palette: getPaletteOptions(mode),\n typography,\n mixins: {},\n components,\n });\n return theme;\n}\n\n// Overrides for component default prop values and styles go here\nconst components: ThemeOptions['components'] = {\n MuiFormControl: {\n defaultProps: {\n size: 'small',\n },\n },\n MuiTextField: {\n defaultProps: {\n size: 'small',\n },\n },\n};\n"],"names":["createTheme","getPaletteOptions","typography","
|
|
1
|
+
{"version":3,"sources":["../../src/theme/theme.ts"],"sourcesContent":["// Copyright 2022 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 { createTheme, PaletteMode, ThemeOptions, Theme } from '@mui/material';\nimport { getPaletteOptions } from './palette/palette-options';\nimport { typography } from './typography';\n\nconst getModalBackgroundStyle = ({ theme }: { theme: Omit<Theme, 'components'> }) => {\n const backgroundStyle =\n theme.palette.mode === 'light'\n ? {}\n : {\n backgroundImage: 'unset',\n backgroundColor: theme.palette.designSystem.grey[800],\n };\n return {\n ...backgroundStyle,\n };\n};\n\n/**\n * Gets theme used by all components for the provided mode. For more details, see:\n * - Base colors, typography, sizing - go/chrono-ui-theme\n * - Material UI defaults: https://material-ui.com/customization/default-theme/\n * - Material UI variables: https://material-ui.com/customization/theming/#theme-configuration-variables\n * - Material UI global overrides and default props: https://material-ui.com/customization/globals/#css\n *\n * Need to reinstantiate the theme everytime to support switching between light and dark themes\n * https://github.com/mui-org/material-ui/issues/18831\n */\nexport function getTheme(mode: PaletteMode) {\n const theme = createTheme({\n palette: getPaletteOptions(mode),\n typography,\n mixins: {},\n components,\n });\n return theme;\n}\n\n// Overrides for component default prop values and styles go here\nconst components: ThemeOptions['components'] = {\n MuiFormControl: {\n defaultProps: {\n size: 'small',\n },\n },\n MuiTextField: {\n defaultProps: {\n size: 'small',\n },\n },\n MuiDrawer: {\n styleOverrides: {\n paper: getModalBackgroundStyle,\n },\n },\n MuiDialog: {\n styleOverrides: {\n paper: getModalBackgroundStyle,\n },\n },\n};\n"],"names":["createTheme","getPaletteOptions","typography","getModalBackgroundStyle","theme","backgroundStyle","palette","mode","backgroundImage","backgroundColor","designSystem","grey","getTheme","mixins","components","MuiFormControl","defaultProps","size","MuiTextField","MuiDrawer","styleOverrides","paper","MuiDialog"],"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,QAA0C,eAAe,CAAC;AAC9E,SAASC,iBAAiB,QAAQ,2BAA2B,CAAC;AAC9D,SAASC,UAAU,QAAQ,cAAc,CAAC;AAE1C,MAAMC,uBAAuB,GAAG,CAAC,EAAEC,KAAK,CAAA,EAAwC,GAAK;IACnF,MAAMC,eAAe,GACnBD,KAAK,CAACE,OAAO,CAACC,IAAI,KAAK,OAAO,GAC1B,EAAE,GACF;QACEC,eAAe,EAAE,OAAO;QACxBC,eAAe,EAAEL,KAAK,CAACE,OAAO,CAACI,YAAY,CAACC,IAAI,CAAC,GAAG,CAAC;KACtD,AAAC;IACR,OAAO;QACL,GAAGN,eAAe;KACnB,CAAC;AACJ,CAAC,AAAC;AAEF;;;;;;;;;CASC,GACD,OAAO,SAASO,QAAQ,CAACL,IAAiB,EAAE;IAC1C,MAAMH,KAAK,GAAGJ,WAAW,CAAC;QACxBM,OAAO,EAAEL,iBAAiB,CAACM,IAAI,CAAC;QAChCL,UAAU;QACVW,MAAM,EAAE,EAAE;QACVC,UAAU;KACX,CAAC,AAAC;IACH,OAAOV,KAAK,CAAC;AACf,CAAC;AAED,iEAAiE;AACjE,MAAMU,UAAU,GAA+B;IAC7CC,cAAc,EAAE;QACdC,YAAY,EAAE;YACZC,IAAI,EAAE,OAAO;SACd;KACF;IACDC,YAAY,EAAE;QACZF,YAAY,EAAE;YACZC,IAAI,EAAE,OAAO;SACd;KACF;IACDE,SAAS,EAAE;QACTC,cAAc,EAAE;YACdC,KAAK,EAAElB,uBAAuB;SAC/B;KACF;IACDmB,SAAS,EAAE;QACTF,cAAc,EAAE;YACdC,KAAK,EAAElB,uBAAuB;SAC/B;KACF;CACF,AAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function dateFormatOptionsWithTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions, timeZone?: string): Intl.DateTimeFormatOptions;
|
|
2
|
+
export declare function formatWithTimeZone(date: Date, formatString: string, timeZone?: string): string;
|
|
3
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/utils/format.ts"],"names":[],"mappings":"AAgBA,wBAAgB,6BAA6B,CAAC,iBAAiB,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,EAAE,MAAM,8BAgB7G;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,UAYrF"}
|