@perses-dev/components 0.20.0 → 0.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +38 -32
- 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 +9 -2
- 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 -4
- 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 +37 -31
- package/dist/cjs/LineChart/utils.js +4 -3
- package/dist/cjs/StatChart/StatChart.test.js +9 -2
- package/dist/cjs/Tooltip/TooltipContent.js +8 -9
- package/dist/cjs/UnitSelector/UnitSelector.test.js +3 -4
- 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 +1 -1
- package/dist/cjs/model/units/units.js +1 -4
- package/dist/cjs/model/units/units.test.js +153 -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.js +1 -1
- 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/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
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
dateFormatOptionsWithTimeZone: ()=>dateFormatOptionsWithTimeZone,
|
|
25
|
+
formatWithTimeZone: ()=>formatWithTimeZone
|
|
26
|
+
});
|
|
27
|
+
const _dateFnsTz = require("date-fns-tz");
|
|
28
|
+
const _dateFns = require("date-fns");
|
|
29
|
+
function dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone) {
|
|
30
|
+
/*
|
|
31
|
+
* if timeZone is provided, and is not local|browser,
|
|
32
|
+
* then set timeZone option (recognize UTC regardless of uppercase/lowercase)
|
|
33
|
+
* otherwise, default to browser timeZone setting
|
|
34
|
+
*/ if (timeZone) {
|
|
35
|
+
const lowerTimeZone = timeZone.toLowerCase();
|
|
36
|
+
if (lowerTimeZone !== 'local' && lowerTimeZone !== 'browser') {
|
|
37
|
+
return {
|
|
38
|
+
...dateFormatOptions,
|
|
39
|
+
timeZone: lowerTimeZone === 'utc' ? 'UTC' : timeZone
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return dateFormatOptions;
|
|
44
|
+
}
|
|
45
|
+
function formatWithTimeZone(date, formatString, timeZone) {
|
|
46
|
+
/*
|
|
47
|
+
* if timeZone is provided, and is not local|browser,
|
|
48
|
+
* then format using timeZone option (recognize UTC regardless of uppercase/lowercase)
|
|
49
|
+
* otherwise, format without timeZone option, defaulting to browser timeZone setting
|
|
50
|
+
*/ const lowerTimeZone = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toLowerCase();
|
|
51
|
+
if (!timeZone || lowerTimeZone === 'local' || lowerTimeZone === 'browser') {
|
|
52
|
+
return (0, _dateFns.format)(date, formatString);
|
|
53
|
+
} else {
|
|
54
|
+
return (0, _dateFnsTz.formatInTimeZone)(date, lowerTimeZone === 'utc' ? 'UTC' : timeZone, formatString);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
const _format = require("./format");
|
|
18
|
+
const DATE = new Date(168523200000);
|
|
19
|
+
const DATE_FORMAT_OPTIONS = {
|
|
20
|
+
hour: 'numeric',
|
|
21
|
+
minute: 'numeric',
|
|
22
|
+
hourCycle: 'h23'
|
|
23
|
+
};
|
|
24
|
+
describe('formatWithTimeZone', ()=>{
|
|
25
|
+
it('should format in Los Angeles timezone', ()=>{
|
|
26
|
+
expect((0, _format.formatWithTimeZone)(DATE, 'yyyy-MM-dd HH:mm:ss', 'America/Los_Angeles')).toBe('1975-05-05 05:00:00');
|
|
27
|
+
});
|
|
28
|
+
it('should format in UTC timezone', ()=>{
|
|
29
|
+
expect((0, _format.formatWithTimeZone)(DATE, 'yyyy-MM-dd HH:mm:ss', 'UTC')).toBe('1975-05-05 12:00:00');
|
|
30
|
+
expect((0, _format.formatWithTimeZone)(DATE, 'yyyy-MM-dd HH:mm:ss', 'utc')).toBe('1975-05-05 12:00:00');
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('dateFormatOptionsWithTimeZone', ()=>{
|
|
34
|
+
it('should format in Los Angeles timezone', ()=>{
|
|
35
|
+
const dateFormatOptions = (0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS, 'America/Los_Angeles');
|
|
36
|
+
expect(new Intl.DateTimeFormat(undefined, dateFormatOptions).format(DATE)).toBe('05:00');
|
|
37
|
+
});
|
|
38
|
+
it('should format in UTC timezone', ()=>{
|
|
39
|
+
const dateFormatOptions = (0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS, 'utc');
|
|
40
|
+
expect(new Intl.DateTimeFormat(undefined, dateFormatOptions).format(DATE)).toBe('12:00');
|
|
41
|
+
});
|
|
42
|
+
it('should use browser local timezone', ()=>{
|
|
43
|
+
expect((0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS, 'browser').timeZone).toBeUndefined();
|
|
44
|
+
expect((0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS, 'local').timeZone).toBeUndefined();
|
|
45
|
+
expect((0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS).timeZone).toBeUndefined();
|
|
46
|
+
});
|
|
47
|
+
});
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
17
17
|
_exportStar(require("./combine-sx"), exports);
|
|
18
18
|
_exportStar(require("./theme-gen"), exports);
|
|
19
19
|
_exportStar(require("./component-ids"), exports);
|
|
20
|
+
_exportStar(require("./format"), exports);
|
|
20
21
|
function _exportStar(from, to) {
|
|
21
22
|
Object.keys(from).forEach(function(k) {
|
|
22
23
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare const TimeZoneContext: React.Context<string | undefined>;
|
|
3
|
+
export interface TimeZoneProviderProps {
|
|
4
|
+
timeZone?: string;
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function TimeZoneProvider(props: TimeZoneProviderProps): JSX.Element;
|
|
8
|
+
export declare function useTimeZone(): {
|
|
9
|
+
timeZone: string;
|
|
10
|
+
formatWithUserTimeZone(date: Date, formatString: string): string;
|
|
11
|
+
dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions): Intl.DateTimeFormatOptions;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=TimeZoneProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeZoneProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeZoneProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAGzD,eAAO,MAAM,eAAe,mCAA+C,CAAC;AAE5E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,eAG5D;AAED,wBAAgB,WAAW;;iCAKM,IAAI,gBAAgB,MAAM;yDAGF,KAAK,qBAAqB;EAIlF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import React, { createContext, useContext } from 'react';
|
|
15
|
+
import { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';
|
|
16
|
+
export const TimeZoneContext = /*#__PURE__*/ createContext(undefined);
|
|
17
|
+
export function TimeZoneProvider(props) {
|
|
18
|
+
const { children , timeZone } = props;
|
|
19
|
+
return /*#__PURE__*/ _jsx(TimeZoneContext.Provider, {
|
|
20
|
+
value: timeZone,
|
|
21
|
+
children: children
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function useTimeZone() {
|
|
25
|
+
const timeZone = useContext(TimeZoneContext);
|
|
26
|
+
return {
|
|
27
|
+
// fallback to "local" timezone if TimeZoneProvider is not present in the React tree
|
|
28
|
+
timeZone: timeZone !== null && timeZone !== void 0 ? timeZone : 'local',
|
|
29
|
+
formatWithUserTimeZone (date, formatString) {
|
|
30
|
+
return formatWithTimeZone(date, formatString, timeZone);
|
|
31
|
+
},
|
|
32
|
+
dateFormatOptionsWithUserTimeZone (dateFormatOptions) {
|
|
33
|
+
return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=TimeZoneProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/TimeZoneProvider.tsx"],"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 React, { createContext, useContext } from 'react';\nimport { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';\n\nexport const TimeZoneContext = createContext<string | undefined>(undefined);\n\nexport interface TimeZoneProviderProps {\n timeZone?: string;\n children?: React.ReactNode;\n}\n\nexport function TimeZoneProvider(props: TimeZoneProviderProps) {\n const { children, timeZone } = props;\n return <TimeZoneContext.Provider value={timeZone}>{children}</TimeZoneContext.Provider>;\n}\n\nexport function useTimeZone() {\n const timeZone = useContext(TimeZoneContext);\n return {\n // fallback to \"local\" timezone if TimeZoneProvider is not present in the React tree\n timeZone: timeZone ?? 'local',\n formatWithUserTimeZone(date: Date, formatString: string) {\n return formatWithTimeZone(date, formatString, timeZone);\n },\n dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions) {\n return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);\n },\n };\n}\n"],"names":["React","createContext","useContext","formatWithTimeZone","dateFormatOptionsWithTimeZone","TimeZoneContext","undefined","TimeZoneProvider","props","children","timeZone","Provider","value","useTimeZone","formatWithUserTimeZone","date","formatString","dateFormatOptionsWithUserTimeZone","dateFormatOptions"],"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;AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,QAAQ,OAAO,CAAC;AACzD,SAASC,kBAAkB,EAAEC,6BAA6B,QAAQ,UAAU,CAAC;AAE7E,OAAO,MAAMC,eAAe,iBAAGJ,aAAa,CAAqBK,SAAS,CAAC,CAAC;AAO5E,OAAO,SAASC,gBAAgB,CAACC,KAA4B,EAAE;IAC7D,MAAM,EAAEC,QAAQ,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAGF,KAAK,AAAC;IACrC,qBAAO,KAACH,eAAe,CAACM,QAAQ;QAACC,KAAK,EAAEF,QAAQ;kBAAGD,QAAQ;MAA4B,CAAC;AAC1F,CAAC;AAED,OAAO,SAASI,WAAW,GAAG;IAC5B,MAAMH,QAAQ,GAAGR,UAAU,CAACG,eAAe,CAAC,AAAC;IAC7C,OAAO;QACL,oFAAoF;QACpFK,QAAQ,EAAEA,QAAQ,aAARA,QAAQ,cAARA,QAAQ,GAAI,OAAO;QAC7BI,sBAAsB,EAACC,IAAU,EAAEC,YAAoB,EAAE;YACvD,OAAOb,kBAAkB,CAACY,IAAI,EAAEC,YAAY,EAAEN,QAAQ,CAAC,CAAC;QAC1D,CAAC;QACDO,iCAAiC,EAACC,iBAA6C,EAAE;YAC/E,OAAOd,6BAA6B,CAACc,iBAAiB,EAAER,QAAQ,CAAC,CAAC;QACpE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -7,12 +7,14 @@ export * from './GaugeChart';
|
|
|
7
7
|
export * from './InfoTooltip';
|
|
8
8
|
export * from './JSONEditor';
|
|
9
9
|
export * from './Legend';
|
|
10
|
+
export * from './LegendOptionsEditor';
|
|
10
11
|
export * from './LineChart';
|
|
11
12
|
export * from './OptionsEditorLayout';
|
|
12
13
|
export * from './StatChart';
|
|
13
14
|
export * from './UnitSelector';
|
|
14
15
|
export * from './YAxisLabel';
|
|
15
16
|
export * from './context/ChartsThemeProvider';
|
|
17
|
+
export * from './context/TimeZoneProvider';
|
|
16
18
|
export * from './utils';
|
|
17
19
|
export * from './model';
|
|
18
20
|
export * from './test-utils';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -19,12 +19,14 @@ export * from './GaugeChart';
|
|
|
19
19
|
export * from './InfoTooltip';
|
|
20
20
|
export * from './JSONEditor';
|
|
21
21
|
export * from './Legend';
|
|
22
|
+
export * from './LegendOptionsEditor';
|
|
22
23
|
export * from './LineChart';
|
|
23
24
|
export * from './OptionsEditorLayout';
|
|
24
25
|
export * from './StatChart';
|
|
25
26
|
export * from './UnitSelector';
|
|
26
27
|
export * from './YAxisLabel';
|
|
27
28
|
export * from './context/ChartsThemeProvider';
|
|
29
|
+
export * from './context/TimeZoneProvider';
|
|
28
30
|
export * from './utils';
|
|
29
31
|
export * from './model';
|
|
30
32
|
export * from './test-utils';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.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\nexport * from './DateTimeRangePicker';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './UnitSelector';\nexport * from './YAxisLabel';\nexport * from './context/ChartsThemeProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\nexport * from './theme';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/index.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\nexport * from './DateTimeRangePicker';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LegendOptionsEditor';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './UnitSelector';\nexport * from './YAxisLabel';\nexport * from './context/ChartsThemeProvider';\nexport * from './context/TimeZoneProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\nexport * from './theme';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/dist/model/graph.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface GraphSeries {
|
|
|
9
9
|
}
|
|
10
10
|
export declare type EChartsValues = number | null | '-';
|
|
11
11
|
export interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {
|
|
12
|
-
data:
|
|
12
|
+
data: EChartsValues[];
|
|
13
13
|
}
|
|
14
14
|
export declare type EChartsDataFormat = {
|
|
15
15
|
timeSeries: EChartsTimeSeries[];
|
|
@@ -22,7 +22,7 @@ export declare type EChartsDataFormat = {
|
|
|
22
22
|
* Supported legend options
|
|
23
23
|
*/
|
|
24
24
|
export interface LegendOptions {
|
|
25
|
-
position
|
|
25
|
+
position: 'bottom' | 'right';
|
|
26
26
|
}
|
|
27
27
|
export interface LegendItem {
|
|
28
28
|
id: string;
|
|
@@ -31,4 +31,6 @@ export interface LegendItem {
|
|
|
31
31
|
color: string;
|
|
32
32
|
onClick: MouseEventHandler<HTMLLIElement>;
|
|
33
33
|
}
|
|
34
|
+
export declare const DEFAULT_LEGEND_POSITION = "bottom";
|
|
35
|
+
export declare const DEFAULT_LEGEND: LegendOptions;
|
|
34
36
|
//# sourceMappingURL=graph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/model/graph.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,oBAAY,qBAAqB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;CACzC;AAED,oBAAY,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAEvE,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/model/graph.ts"],"names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
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
// adjust display when there are many time series to help with performance
|
|
14
14
|
export const OPTIMIZED_MODE_SERIES_LIMIT = 1000;
|
|
15
|
+
export const DEFAULT_LEGEND_POSITION = 'bottom';
|
|
16
|
+
export const DEFAULT_LEGEND = {
|
|
17
|
+
position: DEFAULT_LEGEND_POSITION
|
|
18
|
+
};
|
|
15
19
|
|
|
16
20
|
//# sourceMappingURL=graph.js.map
|
package/dist/model/graph.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/graph.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 { MouseEventHandler } from 'react';\nimport { LineSeriesOption } from 'echarts/charts';\n\n// adjust display when there are many time series to help with performance\nexport const OPTIMIZED_MODE_SERIES_LIMIT = 1000;\n\nexport type UnixTimeMs = number;\n\nexport type GraphSeriesValueTuple = [timestamp: UnixTimeMs, value: number];\n\nexport interface GraphSeries {\n name: string;\n values: Iterable<GraphSeriesValueTuple>;\n}\n\nexport type EChartsValues = number | null | '-';\n\nexport interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {\n // TODO: support dataset and both category / time xAxis types\n data:
|
|
1
|
+
{"version":3,"sources":["../../src/model/graph.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 { MouseEventHandler } from 'react';\nimport { LineSeriesOption } from 'echarts/charts';\n\n// adjust display when there are many time series to help with performance\nexport const OPTIMIZED_MODE_SERIES_LIMIT = 1000;\n\nexport type UnixTimeMs = number;\n\nexport type GraphSeriesValueTuple = [timestamp: UnixTimeMs, value: number];\n\nexport interface GraphSeries {\n name: string;\n values: Iterable<GraphSeriesValueTuple>;\n}\n\nexport type EChartsValues = number | null | '-';\n\nexport interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {\n // TODO: support dataset and both category / time xAxis types\n data: EChartsValues[];\n}\n\nexport type EChartsDataFormat = {\n timeSeries: EChartsTimeSeries[];\n xAxis: number[];\n legendItems?: LegendItem[];\n xAxisMax?: number | string;\n rangeMs?: number;\n};\n\n/**\n * Supported legend options\n */\nexport interface LegendOptions {\n position: 'bottom' | 'right';\n}\n\nexport interface LegendItem {\n id: string;\n label: string;\n isSelected: boolean;\n color: string;\n onClick: MouseEventHandler<HTMLLIElement>;\n}\n\nexport const DEFAULT_LEGEND_POSITION = 'bottom';\n\nexport const DEFAULT_LEGEND: LegendOptions = {\n position: DEFAULT_LEGEND_POSITION,\n};\n"],"names":["OPTIMIZED_MODE_SERIES_LIMIT","DEFAULT_LEGEND_POSITION","DEFAULT_LEGEND","position"],"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;AAKjC,0EAA0E;AAC1E,OAAO,MAAMA,2BAA2B,GAAG,IAAI,CAAC;AAyChD,OAAO,MAAMC,uBAAuB,GAAG,QAAQ,CAAC;AAEhD,OAAO,MAAMC,cAAc,GAAkB;IAC3CC,QAAQ,EAAEF,uBAAuB;CAClC,CAAC"}
|
|
@@ -4,9 +4,14 @@ declare type BytesUnitKind = typeof bytesUnitKinds[number];
|
|
|
4
4
|
export declare type BytesUnitOptions = {
|
|
5
5
|
kind: BytesUnitKind;
|
|
6
6
|
decimal_places?: number;
|
|
7
|
+
abbreviate?: boolean;
|
|
7
8
|
};
|
|
8
9
|
export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
|
|
9
10
|
export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Format value as bytes, use abbreviate option for more readable sizes (KB, MB, GB, etc.)
|
|
13
|
+
* https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatBytes(bytes: number, unitOptions: BytesUnitOptions): string;
|
|
11
16
|
export {};
|
|
12
17
|
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,UAmCvE"}
|
|
@@ -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,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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"}
|
package/dist/model/units/time.js
CHANGED
|
@@ -75,7 +75,7 @@ export function formatTime(value, unitOptions) {
|
|
|
75
75
|
var _decimal_places;
|
|
76
76
|
const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
|
|
77
77
|
const timeUnit = TimeIntlDuration[unitOptions.kind];
|
|
78
|
-
const formatter = new Intl.NumberFormat('en', {
|
|
78
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
79
79
|
style: 'unit',
|
|
80
80
|
unit: timeUnit,
|
|
81
81
|
unitDisplay: 'long',
|
|
@@ -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 { 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', {\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;QACjBE,KAAK,EAAE,OAAO;KACf;IACDU,MAAM,EAAE;QACNN,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,QAAQ;KAChB;IACDW,KAAK,EAAE;QACLP,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,OAAO;KACf;CACF,CAAC;WAIK,gBASN;UATWY,gBAAgB;IAAhBA,gBAAgB,CAC1BT,cAAY,IAAG,aAAa;IADlBS,gBAAgB,CAE1BP,SAAO,IAAG,QAAQ;IAFRO,gBAAgB,CAG1BN,SAAO,IAAG,QAAQ;IAHRM,gBAAgB,CAI1BL,OAAK,IAAG,MAAM;IAJJK,gBAAgB,CAK1BJ,MAAI,IAAG,KAAK;IALFI,gBAAgB,CAM1BH,OAAK,IAAG,MAAM;IANJG,gBAAgB,CAO1BF,QAAM,IAAG,OAAO;IAPNE,gBAAgB,CAQ1BD,OAAK,IAAG,MAAM;GARJC,gBAAgB,KAAhBA,gBAAgB;AAW5B,OAAO,SAASC,UAAU,CAACC,KAAa,EAAEC,WAA4B,EAAU;QAC7DA,eAA0B;IAA3C,MAAMC,QAAQ,GAAGD,CAAAA,eAA0B,GAA1BA,WAAW,CAACd,cAAc,cAA1Bc,eAA0B,cAA1BA,eAA0B,GAAInB,sBAAsB,AAAC;IACtE,MAAMqB,QAAQ,GAAWL,gBAAgB,CAACG,WAAW,CAACG,IAAI,CAAC,AAAC;IAC5D,MAAMC,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,
|
|
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,I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KAAK,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAsD,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAsD,MAAM,SAAS,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAA4D,MAAM,WAAW,CAAC;AACzG,OAAO,EAAuC,kBAAkB,EAAuB,MAAM,WAAW,CAAC;AACzG,OAAO,EAAc,eAAe,EAAuC,MAAM,QAAQ,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEjE,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,CAK1E,CAAC;AACF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CAKd,CAAC;AAEX,oBAAY,WAAW,GAAG,eAAe,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAEvG,aAAK,gBAAgB,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAC/F,aAAK,aAAa,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,CAuB5E;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAEtE;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAEhE;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,eAAe,CAG5E;AAGD,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,eAAe,CAEnF;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,kBAAkB,CAEzF;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,kBAAkB,CAEzF;AAED,wBAAgB,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,gBAAgB,CAErF;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAI9G;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,aAAa,CAAC,WAAW,CAAC,CAIxG"}
|
|
@@ -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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,CAAC,CAAC;AACvC,CAAC;AAED,OAAO,SAASC,YAAY,CAACX,WAAwB,EAAa;IAChE,OAAOS,iBAAiB,CAACT,WAAW,CAAC,CAACY,KAAK,CAAC;AAC9C,CAAC;AAED,OAAO,SAASC,kBAAkB,CAACb,WAAwB,EAAmB;IAC5E,MAAMc,UAAU,GAAGL,iBAAiB,CAACT,WAAW,CAAC,AAAC;IAClD,OAAOR,iBAAiB,CAACsB,UAAU,CAACF,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED,cAAc;AACd,OAAO,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":""}
|