@perses-dev/core 0.39.0 → 0.40.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.
Files changed (119) hide show
  1. package/dist/cjs/constants/dashboard-defaults.js +6 -2
  2. package/dist/cjs/constants/dialog.js +3 -1
  3. package/dist/cjs/constants/index.js +11 -9
  4. package/dist/cjs/index.js +12 -10
  5. package/dist/cjs/model/calculations.js +61 -49
  6. package/dist/cjs/model/index.js +28 -26
  7. package/dist/cjs/model/legend.js +39 -19
  8. package/dist/cjs/model/resource.js +9 -0
  9. package/dist/cjs/model/time-series-queries.js +3 -1
  10. package/dist/cjs/model/time.js +147 -64
  11. package/dist/cjs/model/units/bytes.js +26 -20
  12. package/dist/cjs/model/units/constants.js +3 -1
  13. package/dist/cjs/model/units/decimal.js +20 -14
  14. package/dist/cjs/model/units/index.js +13 -11
  15. package/dist/cjs/model/units/percent.js +21 -15
  16. package/dist/cjs/model/units/time.js +68 -60
  17. package/dist/cjs/model/units/types.js +3 -1
  18. package/dist/cjs/model/units/units.js +67 -43
  19. package/dist/cjs/model/units/utils.js +13 -7
  20. package/dist/cjs/model/variables.js +16 -3
  21. package/dist/cjs/utils/event.js +3 -1
  22. package/dist/cjs/utils/fetch.js +12 -4
  23. package/dist/cjs/utils/index.js +17 -14
  24. package/dist/cjs/utils/is-empty-object.js +3 -1
  25. package/dist/cjs/utils/mathjs.js +3 -1
  26. package/dist/cjs/utils/memo.js +10 -6
  27. package/dist/cjs/utils/panel-refs.js +9 -3
  28. package/dist/cjs/utils/text.js +33 -21
  29. package/dist/cjs/utils/time-series-data.js +21 -11
  30. package/dist/cjs/utils/types.js +16 -0
  31. package/dist/constants/dashboard-defaults.js.map +1 -1
  32. package/dist/constants/dialog.js.map +1 -1
  33. package/dist/constants/index.js.map +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/model/calculations.d.ts +9 -8
  36. package/dist/model/calculations.d.ts.map +1 -1
  37. package/dist/model/calculations.js +46 -45
  38. package/dist/model/calculations.js.map +1 -1
  39. package/dist/model/datasource.d.ts +19 -3
  40. package/dist/model/datasource.d.ts.map +1 -1
  41. package/dist/model/datasource.js.map +1 -1
  42. package/dist/model/display.d.ts +1 -1
  43. package/dist/model/display.d.ts.map +1 -1
  44. package/dist/model/display.js.map +1 -1
  45. package/dist/model/index.js.map +1 -1
  46. package/dist/model/legend.d.ts +6 -6
  47. package/dist/model/legend.js +9 -9
  48. package/dist/model/legend.js.map +1 -1
  49. package/dist/model/panels.d.ts +5 -2
  50. package/dist/model/panels.d.ts.map +1 -1
  51. package/dist/model/panels.js.map +1 -1
  52. package/dist/model/resource.d.ts +3 -2
  53. package/dist/model/resource.d.ts.map +1 -1
  54. package/dist/model/resource.js +3 -1
  55. package/dist/model/resource.js.map +1 -1
  56. package/dist/model/thresholds.d.ts +2 -2
  57. package/dist/model/thresholds.d.ts.map +1 -1
  58. package/dist/model/thresholds.js.map +1 -1
  59. package/dist/model/time-series-queries.js.map +1 -1
  60. package/dist/model/time.d.ts +3 -0
  61. package/dist/model/time.d.ts.map +1 -1
  62. package/dist/model/time.js +115 -55
  63. package/dist/model/time.js.map +1 -1
  64. package/dist/model/units/bytes.d.ts +8 -8
  65. package/dist/model/units/bytes.d.ts.map +1 -1
  66. package/dist/model/units/bytes.js +16 -16
  67. package/dist/model/units/bytes.js.map +1 -1
  68. package/dist/model/units/constants.js.map +1 -1
  69. package/dist/model/units/decimal.d.ts +8 -8
  70. package/dist/model/units/decimal.d.ts.map +1 -1
  71. package/dist/model/units/decimal.js +12 -12
  72. package/dist/model/units/decimal.js.map +1 -1
  73. package/dist/model/units/index.js.map +1 -1
  74. package/dist/model/units/percent.d.ts +7 -7
  75. package/dist/model/units/percent.d.ts.map +1 -1
  76. package/dist/model/units/percent.js +12 -12
  77. package/dist/model/units/percent.js.map +1 -1
  78. package/dist/model/units/time.d.ts +15 -15
  79. package/dist/model/units/time.d.ts.map +1 -1
  80. package/dist/model/units/time.js +56 -56
  81. package/dist/model/units/time.js.map +1 -1
  82. package/dist/model/units/types.d.ts +14 -5
  83. package/dist/model/units/types.d.ts.map +1 -1
  84. package/dist/model/units/types.js.map +1 -1
  85. package/dist/model/units/units.d.ts +30 -30
  86. package/dist/model/units/units.d.ts.map +1 -1
  87. package/dist/model/units/units.js +31 -31
  88. package/dist/model/units/units.js.map +1 -1
  89. package/dist/model/units/utils.d.ts +2 -2
  90. package/dist/model/units/utils.d.ts.map +1 -1
  91. package/dist/model/units/utils.js +4 -4
  92. package/dist/model/units/utils.js.map +1 -1
  93. package/dist/model/variables.d.ts +25 -7
  94. package/dist/model/variables.d.ts.map +1 -1
  95. package/dist/model/variables.js +3 -0
  96. package/dist/model/variables.js.map +1 -1
  97. package/dist/test/setup-tests.js.map +1 -1
  98. package/dist/utils/event.js.map +1 -1
  99. package/dist/utils/fetch.js.map +1 -1
  100. package/dist/utils/index.d.ts +2 -1
  101. package/dist/utils/index.d.ts.map +1 -1
  102. package/dist/utils/index.js +2 -1
  103. package/dist/utils/index.js.map +1 -1
  104. package/dist/utils/is-empty-object.js.map +1 -1
  105. package/dist/utils/mathjs.js.map +1 -1
  106. package/dist/utils/memo.js +2 -2
  107. package/dist/utils/memo.js.map +1 -1
  108. package/dist/utils/panel-refs.js.map +1 -1
  109. package/dist/utils/text.d.ts +5 -5
  110. package/dist/utils/text.d.ts.map +1 -1
  111. package/dist/utils/text.js +17 -17
  112. package/dist/utils/text.js.map +1 -1
  113. package/dist/utils/time-series-data.js +6 -6
  114. package/dist/utils/time-series-data.js.map +1 -1
  115. package/dist/utils/types.d.ts +2 -0
  116. package/dist/utils/types.d.ts.map +1 -0
  117. package/dist/utils/types.js +15 -0
  118. package/dist/utils/types.js.map +1 -0
  119. package/package.json +5 -4
@@ -11,34 +11,34 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
- import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
15
- const decimalUnitKinds = [
16
- 'Decimal'
14
+ import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
15
+ const decimalUnits = [
16
+ 'decimal'
17
17
  ];
18
18
  export const DECIMAL_GROUP_CONFIG = {
19
19
  label: 'Decimal',
20
- decimal_places: true,
21
- abbreviate: true
20
+ decimalPlaces: true,
21
+ shortValues: true
22
22
  };
23
23
  export const DECIMAL_UNIT_CONFIG = {
24
- Decimal: {
24
+ decimal: {
25
25
  group: 'Decimal',
26
26
  label: 'Decimal'
27
27
  }
28
28
  };
29
- export function formatDecimal(value, { abbreviate , decimal_places }) {
29
+ export function formatDecimal(value, { shortValues , decimalPlaces }) {
30
30
  const formatterOptions = {
31
31
  style: 'decimal',
32
32
  useGrouping: true
33
33
  };
34
- if (shouldAbbreviate(abbreviate)) {
34
+ if (shouldShortenValues(shortValues)) {
35
35
  formatterOptions.notation = 'compact';
36
36
  }
37
- if (hasDecimalPlaces(decimal_places)) {
38
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
39
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
37
+ if (hasDecimalPlaces(decimalPlaces)) {
38
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
39
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
40
40
  } else {
41
- if (shouldAbbreviate(abbreviate)) {
41
+ if (shouldShortenValues(shortValues)) {
42
42
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
43
43
  }
44
44
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst decimalUnitKinds = ['Decimal'] as const;\ntype DecimalUnitKind = (typeof decimalUnitKinds)[number];\nexport type DecimalUnitOptions = {\n kind: DecimalUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimal_places: true,\n abbreviate: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>> = {\n Decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { abbreviate, decimal_places }: DecimalUnitOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","decimalUnitKinds","DECIMAL_GROUP_CONFIG","label","decimal_places","abbreviate","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AA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gB,CAAC,AAAC;IAC/D,OAAOO,SAAS,CAACG,MAAM,CAACX,KAAK,CAAC,CAAC;AACjC,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\nconst decimalUnits = ['decimal'] as const;\ntype DecimalUnit = (typeof decimalUnits)[number];\nexport type DecimalFormatOptions = {\n unit: DecimalUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>> = {\n decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","decimalUnits","DECIMAL_GROUP_CONFIG","label","decimalPlaces","shortValues","DECIMAL_UNIT_CONFIG","decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAEpF,MAAMC,eAAe;IAAC;CAAU;AAOhC,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASM,cAAcC,KAAa,EAAE,EAAEL,YAAW,EAAED,cAAa,EAAwB;IAC/F,MAAMO,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIb,oBAAoBK,cAAc;QACpCM,iBAAiBG,WAAW;IAC9B;IAEA,IAAIhB,iBAAiBM,gBAAgB;QACnCO,iBAAiBI,wBAAwBhB,mBAAmBK;QAC5DO,iBAAiBK,wBAAwBjB,mBAAmBK;IAC9D,OAAO;QACL,IAAIJ,oBAAoBK,cAAc;YACpCM,iBAAiBM,2BAA2BpB;QAC9C;IACF;IAEA,MAAMqB,YAAYC,KAAKC,aAAa,SAAST;IAC7C,OAAOO,UAAUG,OAAOX;AAC1B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './utils';\nexport * from './units';\nexport * from './constants';\nexport * from './types';\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,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './utils';\nexport * from './units';\nexport * from './constants';\nexport * from './types';\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,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,cAAc;AAC5B,cAAc,UAAU"}
@@ -1,12 +1,12 @@
1
1
  import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const percentUnitKinds: readonly ["Percent", "PercentDecimal", "%"];
3
- declare type PercentUnitKind = (typeof percentUnitKinds)[number];
4
- export declare type PercentUnitOptions = {
5
- kind: PercentUnitKind;
6
- decimal_places?: number;
2
+ declare const percentUnits: readonly ["percent", "percent-decimal", "%"];
3
+ declare type PercentUnit = (typeof percentUnits)[number];
4
+ export declare type PercentFormatOptions = {
5
+ unit: PercentUnit;
6
+ decimalPlaces?: number;
7
7
  };
8
8
  export declare const PERCENT_GROUP_CONFIG: UnitGroupConfig;
9
- export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>>;
10
- export declare function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string;
9
+ export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnit, UnitConfig>>;
10
+ export declare function formatPercent(value: number, { unit, decimalPlaces }: PercentFormatOptions): string;
11
11
  export {};
12
12
  //# sourceMappingURL=percent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AACrE,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAgB7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAoBjG"}
1
+ {"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,YAAY,8CAA+C,CAAC;AAClE,aAAK,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACjD,oBAAY,oBAAoB,GAAG;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAgBzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CAoBlG"}
@@ -12,22 +12,22 @@
12
12
  // limitations under the License.
13
13
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
14
  import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
15
- const percentUnitKinds = [
16
- 'Percent',
17
- 'PercentDecimal',
15
+ const percentUnits = [
16
+ 'percent',
17
+ 'percent-decimal',
18
18
  '%'
19
19
  ];
20
20
  export const PERCENT_GROUP_CONFIG = {
21
- label: 'Percent',
22
- decimal_places: true
21
+ label: 'percent',
22
+ decimalPlaces: true
23
23
  };
24
24
  const PERCENT_GROUP = 'Percent';
25
25
  export const PERCENT_UNIT_CONFIG = {
26
- Percent: {
26
+ percent: {
27
27
  group: PERCENT_GROUP,
28
28
  label: 'Percent (0-100)'
29
29
  },
30
- PercentDecimal: {
30
+ 'percent-decimal': {
31
31
  group: PERCENT_GROUP,
32
32
  label: 'Percent (0.0-1.0)'
33
33
  },
@@ -39,19 +39,19 @@ export const PERCENT_UNIT_CONFIG = {
39
39
  label: '%'
40
40
  }
41
41
  };
42
- export function formatPercent(value, { kind , decimal_places }) {
42
+ export function formatPercent(value, { unit , decimalPlaces }) {
43
43
  const formatterOptions = {
44
44
  style: 'percent',
45
45
  useGrouping: true
46
46
  };
47
- if (hasDecimalPlaces(decimal_places)) {
48
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
49
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
47
+ if (hasDecimalPlaces(decimalPlaces)) {
48
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
49
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
50
50
  } else {
51
51
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
52
52
  }
53
53
  // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.
54
- if (kind === 'Percent') {
54
+ if (unit === 'percent') {
55
55
  value = value / 100;
56
56
  }
57
57
  const formatter = Intl.NumberFormat('en-US', formatterOptions);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst percentUnitKinds = ['Percent', 'PercentDecimal', '%'] as const;\ntype PercentUnitKind = (typeof percentUnitKinds)[number];\nexport type PercentUnitOptions = {\n kind: PercentUnitKind;\n decimal_places?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>> = {\n Percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n PercentDecimal: {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nexport function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.\n if (kind === 'Percent') {\n value = value / 100;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","percentUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","PERCENT_GROUP","PERCENT_UNIT_CONFIG","Percent","group","PercentDecimal","disableSelectorOption","formatPercent","value","kind","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAA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MAAMQ,SAAS,GAAGC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAER,gBAAgB,CAAC,AAAC;IAC/D,OAAOM,SAAS,CAACG,MAAM,CAACX,KAAK,CAAC,CAAC;AACjC,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst percentUnits = ['percent', 'percent-decimal', '%'] as const;\ntype PercentUnit = (typeof percentUnits)[number];\nexport type PercentFormatOptions = {\n unit: PercentUnit;\n decimalPlaces?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'percent',\n decimalPlaces: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnit, UnitConfig>> = {\n percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n 'percent-decimal': {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nexport function formatPercent(value: number, { unit, decimalPlaces }: PercentFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.\n if (unit === 'percent') {\n value = value / 100;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","percentUnits","PERCENT_GROUP_CONFIG","label","decimalPlaces","PERCENT_GROUP","PERCENT_UNIT_CONFIG","percent","group","disableSelectorOption","formatPercent","value","unit","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAE/D,MAAMC,eAAe;IAAC;IAAW;IAAmB;CAAI;AAMxD,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,MAAMC,gBAAgB;AACtB,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAOH;QACPF,OAAO;IACT;IACA,mBAAmB;QACjBK,OAAOH;QACPF,OAAO;IACT;IACA,KAAK;QACH,qEAAqE;QACrE,0BAA0B;QAC1BM,uBAAuB;QACvBD,OAAOH;QACPF,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,cAAcC,KAAa,EAAE,EAAEC,KAAI,EAAER,cAAa,EAAwB;IACxF,MAAMS,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIhB,iBAAiBK,gBAAgB;QACnCS,iBAAiBG,wBAAwBhB,mBAAmBI;QAC5DS,iBAAiBI,wBAAwBjB,mBAAmBI;IAC9D,OAAO;QACLS,iBAAiBK,2BAA2BpB;IAC9C;IAEA,oEAAoE;IACpE,IAAIc,SAAS,WAAW;QACtBD,QAAQA,QAAQ;IAClB;IAEA,MAAMQ,YAAYC,KAAKC,aAAa,SAASR;IAC7C,OAAOM,UAAUG,OAAOX;AAC1B"}
@@ -1,22 +1,22 @@
1
1
  import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const timeUnitKinds: readonly ["Milliseconds", "Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", "Years"];
3
- declare type TimeUnitKind = (typeof timeUnitKinds)[number];
4
- export declare type TimeUnitOptions = {
5
- kind: TimeUnitKind;
6
- decimal_places?: number;
2
+ declare const timeUnits: readonly ["milliseconds", "seconds", "minutes", "hours", "days", "weeks", "months", "years"];
3
+ declare type TimeUnits = (typeof timeUnits)[number];
4
+ export declare type TimeFormatOptions = {
5
+ unit: TimeUnits;
6
+ decimalPlaces?: number;
7
7
  };
8
8
  export declare const TIME_GROUP_CONFIG: UnitGroupConfig;
9
- export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>>;
9
+ export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnits, UnitConfig>>;
10
10
  export declare enum PersesTimeToIntlTime {
11
- Milliseconds = "millisecond",
12
- Seconds = "second",
13
- Minutes = "minute",
14
- Hours = "hour",
15
- Days = "day",
16
- Weeks = "week",
17
- Months = "month",
18
- Years = "year"
11
+ milliseconds = "millisecond",
12
+ seconds = "second",
13
+ minutes = "minute",
14
+ hours = "hour",
15
+ days = "day",
16
+ weeks = "week",
17
+ months = "month",
18
+ years = "year"
19
19
  }
20
- export declare function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string;
20
+ export declare function formatTime(value: number, { unit, decimalPlaces }: TimeFormatOptions): string;
21
21
  export {};
22
22
  //# sourceMappingURL=time.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAiCvE,CAAC;AAIF,oBAAY,oBAAoB;IAC9B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AAwDD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,eAAe,GAAG,MAAM,CAoB3F"}
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,SAAS,8FAA+F,CAAC;AAC/G,aAAK,SAAS,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAC5C,oBAAY,iBAAiB,GAAG;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAG/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAiCpE,CAAC;AAIF,oBAAY,oBAAoB;IAC9B,YAAY,gBAAgB;IAC5B,OAAO,WAAW;IAClB,OAAO,WAAW;IAClB,KAAK,SAAS;IACd,IAAI,QAAQ;IACZ,KAAK,SAAS;IACd,MAAM,UAAU;IAChB,KAAK,SAAS;CACf;AAwDD,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,iBAAiB,GAAG,MAAM,CAoB5F"}
@@ -12,65 +12,65 @@
12
12
  // limitations under the License.
13
13
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
14
  import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
15
- const timeUnitKinds = [
16
- 'Milliseconds',
17
- 'Seconds',
18
- 'Minutes',
19
- 'Hours',
20
- 'Days',
21
- 'Weeks',
22
- 'Months',
23
- 'Years'
15
+ const timeUnits = [
16
+ 'milliseconds',
17
+ 'seconds',
18
+ 'minutes',
19
+ 'hours',
20
+ 'days',
21
+ 'weeks',
22
+ 'months',
23
+ 'years'
24
24
  ];
25
25
  const TIME_GROUP = 'Time';
26
26
  export const TIME_GROUP_CONFIG = {
27
27
  label: 'Time',
28
- decimal_places: true
28
+ decimalPlaces: true
29
29
  };
30
30
  export const TIME_UNIT_CONFIG = {
31
- Milliseconds: {
31
+ milliseconds: {
32
32
  group: TIME_GROUP,
33
33
  label: 'Milliseconds'
34
34
  },
35
- Seconds: {
35
+ seconds: {
36
36
  group: TIME_GROUP,
37
37
  label: 'Seconds'
38
38
  },
39
- Minutes: {
39
+ minutes: {
40
40
  group: TIME_GROUP,
41
41
  label: 'Minutes'
42
42
  },
43
- Hours: {
43
+ hours: {
44
44
  group: TIME_GROUP,
45
45
  label: 'Hours'
46
46
  },
47
- Days: {
47
+ days: {
48
48
  group: TIME_GROUP,
49
49
  label: 'Days'
50
50
  },
51
- Weeks: {
51
+ weeks: {
52
52
  group: TIME_GROUP,
53
53
  label: 'Weeks'
54
54
  },
55
- Months: {
55
+ months: {
56
56
  group: TIME_GROUP,
57
57
  label: 'Months'
58
58
  },
59
- Years: {
59
+ years: {
60
60
  group: TIME_GROUP,
61
61
  label: 'Years'
62
62
  }
63
63
  };
64
64
  export var PersesTimeToIntlTime;
65
65
  (function(PersesTimeToIntlTime) {
66
- PersesTimeToIntlTime["Milliseconds"] = 'millisecond';
67
- PersesTimeToIntlTime["Seconds"] = 'second';
68
- PersesTimeToIntlTime["Minutes"] = 'minute';
69
- PersesTimeToIntlTime["Hours"] = 'hour';
70
- PersesTimeToIntlTime["Days"] = 'day';
71
- PersesTimeToIntlTime["Weeks"] = 'week';
72
- PersesTimeToIntlTime["Months"] = 'month';
73
- PersesTimeToIntlTime["Years"] = 'year';
66
+ PersesTimeToIntlTime["milliseconds"] = 'millisecond';
67
+ PersesTimeToIntlTime["seconds"] = 'second';
68
+ PersesTimeToIntlTime["minutes"] = 'minute';
69
+ PersesTimeToIntlTime["hours"] = 'hour';
70
+ PersesTimeToIntlTime["days"] = 'day';
71
+ PersesTimeToIntlTime["weeks"] = 'week';
72
+ PersesTimeToIntlTime["months"] = 'month';
73
+ PersesTimeToIntlTime["years"] = 'year';
74
74
  })(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
75
75
  /**
76
76
  * Note: This conversion will not be exactly accurate for months and years,
@@ -78,31 +78,31 @@ export var PersesTimeToIntlTime;
78
78
  * For precision with months and years, we would need more complex algorithms and/or external libraries.
79
79
  * However, we expect that measurements in months and years will be rare.
80
80
  */ const TIME_UNITS_IN_SECONDS = {
81
- Years: 31536000,
82
- Months: 2592000,
83
- Weeks: 604800,
84
- Days: 86400,
85
- Hours: 3600,
86
- Minutes: 60,
87
- Seconds: 1,
88
- Milliseconds: 0.001
81
+ years: 31536000,
82
+ months: 2592000,
83
+ weeks: 604800,
84
+ days: 86400,
85
+ hours: 3600,
86
+ minutes: 60,
87
+ seconds: 1,
88
+ milliseconds: 0.001
89
89
  };
90
90
  const LARGEST_TO_SMALLEST_TIME_UNITS = [
91
- 'Years',
92
- 'Months',
93
- 'Weeks',
94
- 'Days',
95
- 'Hours',
96
- 'Minutes',
97
- 'Seconds',
98
- 'Milliseconds'
91
+ 'years',
92
+ 'months',
93
+ 'weeks',
94
+ 'days',
95
+ 'hours',
96
+ 'minutes',
97
+ 'seconds',
98
+ 'milliseconds'
99
99
  ];
100
100
  /**
101
101
  * Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.
102
- */ function getValueAndKindForNaturalNumbers(value, kind) {
103
- const valueInSeconds = value * TIME_UNITS_IN_SECONDS[kind];
102
+ */ function getValueAndKindForNaturalNumbers(value, unit) {
103
+ const valueInSeconds = value * TIME_UNITS_IN_SECONDS[unit];
104
104
  // Initialize for TS
105
- const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'Years';
105
+ const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'years';
106
106
  let timeUnit = largestTimeUnit;
107
107
  let valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];
108
108
  for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS){
@@ -110,30 +110,30 @@ const LARGEST_TO_SMALLEST_TIME_UNITS = [
110
110
  if (valueInTimeUnit >= 1) {
111
111
  return {
112
112
  value: valueInTimeUnit,
113
- kind: timeUnit
113
+ unit: timeUnit
114
114
  };
115
115
  }
116
116
  }
117
117
  // If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).
118
118
  return {
119
119
  value: valueInTimeUnit,
120
- kind: timeUnit
120
+ unit: timeUnit
121
121
  };
122
122
  }
123
- function isMonthOrYear(kind) {
124
- return kind === 'Months' || kind === 'Years';
123
+ function isMonthOrYear(unit) {
124
+ return unit === 'months' || unit === 'years';
125
125
  }
126
- export function formatTime(value, { kind , decimal_places }) {
126
+ export function formatTime(value, { unit , decimalPlaces }) {
127
127
  if (value === 0) return '0s';
128
- const results = getValueAndKindForNaturalNumbers(value, kind);
128
+ const results = getValueAndKindForNaturalNumbers(value, unit);
129
129
  const formatterOptions = {
130
130
  style: 'unit',
131
- unit: PersesTimeToIntlTime[results.kind],
132
- unitDisplay: isMonthOrYear(results.kind) ? 'long' : 'narrow'
131
+ unit: PersesTimeToIntlTime[results.unit],
132
+ unitDisplay: isMonthOrYear(results.unit) ? 'long' : 'narrow'
133
133
  };
134
- if (hasDecimalPlaces(decimal_places)) {
135
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
136
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
134
+ if (hasDecimalPlaces(decimalPlaces)) {
135
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
136
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
137
137
  } else {
138
138
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
139
139
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst timeUnitKinds = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years'] as const;\ntype TimeUnitKind = (typeof timeUnitKinds)[number];\nexport type TimeUnitOptions = {\n kind: TimeUnitKind;\n decimal_places?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimal_places: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>> = {\n Milliseconds: {\n group: TIME_GROUP,\n label: 'Milliseconds',\n },\n Seconds: {\n group: TIME_GROUP,\n label: 'Seconds',\n },\n Minutes: {\n group: TIME_GROUP,\n label: 'Minutes',\n },\n Hours: {\n group: TIME_GROUP,\n label: 'Hours',\n },\n Days: {\n group: TIME_GROUP,\n label: 'Days',\n },\n Weeks: {\n group: TIME_GROUP,\n label: 'Weeks',\n },\n Months: {\n group: TIME_GROUP,\n label: 'Months',\n },\n Years: {\n group: TIME_GROUP,\n label: 'Years',\n },\n};\n\n// Mapping of time units to what Intl.NumberFormat formatter expects\n// https://v8.dev/features/intl-numberformat#units\nexport enum PersesTimeToIntlTime {\n Milliseconds = 'millisecond',\n Seconds = 'second',\n Minutes = 'minute',\n Hours = 'hour',\n Days = 'day',\n Weeks = 'week',\n Months = 'month',\n Years = 'year',\n}\n\n/**\n * Note: This conversion will not be exactly accurate for months and years,\n * due variations in the lengths of months (i.e. 28 - 31 days) and years (i.e. leap years).\n * For precision with months and years, we would need more complex algorithms and/or external libraries.\n * However, we expect that measurements in months and years will be rare.\n */\nconst TIME_UNITS_IN_SECONDS: Record<TimeUnitKind, number> = {\n Years: 31536000, // 365 days\n Months: 2592000, // 30 days\n Weeks: 604800,\n Days: 86400,\n Hours: 3600,\n Minutes: 60,\n Seconds: 1,\n Milliseconds: 0.001,\n};\n\nconst LARGEST_TO_SMALLEST_TIME_UNITS: TimeUnitKind[] = [\n 'Years',\n 'Months',\n 'Weeks',\n 'Days',\n 'Hours',\n 'Minutes',\n 'Seconds',\n 'Milliseconds',\n];\n\n/**\n * Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.\n */\nfunction getValueAndKindForNaturalNumbers(value: number, kind: TimeUnitKind): { value: number; kind: TimeUnitKind } {\n const valueInSeconds = value * TIME_UNITS_IN_SECONDS[kind];\n\n // Initialize for TS\n const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'Years';\n let timeUnit: TimeUnitKind = largestTimeUnit;\n let valueInTimeUnit: number = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];\n\n for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS) {\n valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];\n if (valueInTimeUnit >= 1) {\n return { value: valueInTimeUnit, kind: timeUnit };\n }\n }\n\n // If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).\n return { value: valueInTimeUnit, kind: timeUnit };\n}\n\nfunction isMonthOrYear(kind: TimeUnitKind): boolean {\n return kind === 'Months' || kind === 'Years';\n}\n\nexport function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string {\n if (value === 0) return '0s';\n\n const results = getValueAndKindForNaturalNumbers(value, kind);\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: PersesTimeToIntlTime[results.kind],\n unitDisplay: isMonthOrYear(results.kind) ? 'long' : 'narrow',\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(results.value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","timeUnitKinds","TIME_GROUP","TIME_GROUP_CONFIG","label","decimal_places","TIME_UNIT_CONFIG","Milliseconds","group","Seconds","Minutes","Hours","Days","Weeks","Months","Years","PersesTimeToIntlTime","TIME_UNITS_IN_SECONDS","LARGEST_TO_SMALLEST_TIME_UNITS","getValueAndKindForNaturalNumbers","value","kind","valueInSeconds","largestTimeUnit","timeUnit","valueInTimeUnit","isMonthOrYear","formatTime","results","formatterOptions","style","unit","unitDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,SAAS,CAAC;AAE/D,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,KAA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O,SAAS,CAACG,MAAM,CAACX,OAAO,CAACR,KAAK,CAAC,CAAC;AACzC,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst timeUnits = ['milliseconds', 'seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years'] as const;\ntype TimeUnits = (typeof timeUnits)[number];\nexport type TimeFormatOptions = {\n unit: TimeUnits;\n decimalPlaces?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimalPlaces: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnits, UnitConfig>> = {\n milliseconds: {\n group: TIME_GROUP,\n label: 'Milliseconds',\n },\n seconds: {\n group: TIME_GROUP,\n label: 'Seconds',\n },\n minutes: {\n group: TIME_GROUP,\n label: 'Minutes',\n },\n hours: {\n group: TIME_GROUP,\n label: 'Hours',\n },\n days: {\n group: TIME_GROUP,\n label: 'Days',\n },\n weeks: {\n group: TIME_GROUP,\n label: 'Weeks',\n },\n months: {\n group: TIME_GROUP,\n label: 'Months',\n },\n years: {\n group: TIME_GROUP,\n label: 'Years',\n },\n};\n\n// Mapping of time units to what Intl.NumberFormat formatter expects\n// https://v8.dev/features/intl-numberformat#units\nexport enum PersesTimeToIntlTime {\n milliseconds = 'millisecond',\n seconds = 'second',\n minutes = 'minute',\n hours = 'hour',\n days = 'day',\n weeks = 'week',\n months = 'month',\n years = 'year',\n}\n\n/**\n * Note: This conversion will not be exactly accurate for months and years,\n * due variations in the lengths of months (i.e. 28 - 31 days) and years (i.e. leap years).\n * For precision with months and years, we would need more complex algorithms and/or external libraries.\n * However, we expect that measurements in months and years will be rare.\n */\nconst TIME_UNITS_IN_SECONDS: Record<TimeUnits, number> = {\n years: 31536000, // 365 days\n months: 2592000, // 30 days\n weeks: 604800, // 7 days\n days: 86400,\n hours: 3600,\n minutes: 60,\n seconds: 1,\n milliseconds: 0.001,\n};\n\nconst LARGEST_TO_SMALLEST_TIME_UNITS: TimeUnits[] = [\n 'years',\n 'months',\n 'weeks',\n 'days',\n 'hours',\n 'minutes',\n 'seconds',\n 'milliseconds',\n];\n\n/**\n * Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.\n */\nfunction getValueAndKindForNaturalNumbers(value: number, unit: TimeUnits): { value: number; unit: TimeUnits } {\n const valueInSeconds = value * TIME_UNITS_IN_SECONDS[unit];\n\n // Initialize for TS\n const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'years';\n let timeUnit: TimeUnits = largestTimeUnit;\n let valueInTimeUnit: number = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];\n\n for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS) {\n valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];\n if (valueInTimeUnit >= 1) {\n return { value: valueInTimeUnit, unit: timeUnit };\n }\n }\n\n // If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).\n return { value: valueInTimeUnit, unit: timeUnit };\n}\n\nfunction isMonthOrYear(unit: TimeUnits): boolean {\n return unit === 'months' || unit === 'years';\n}\n\nexport function formatTime(value: number, { unit, decimalPlaces }: TimeFormatOptions): string {\n if (value === 0) return '0s';\n\n const results = getValueAndKindForNaturalNumbers(value, unit);\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: PersesTimeToIntlTime[results.unit],\n unitDisplay: isMonthOrYear(results.unit) ? 'long' : 'narrow',\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(results.value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","timeUnits","TIME_GROUP","TIME_GROUP_CONFIG","label","decimalPlaces","TIME_UNIT_CONFIG","milliseconds","group","seconds","minutes","hours","days","weeks","months","years","PersesTimeToIntlTime","TIME_UNITS_IN_SECONDS","LARGEST_TO_SMALLEST_TIME_UNITS","getValueAndKindForNaturalNumbers","value","unit","valueInSeconds","largestTimeUnit","timeUnit","valueInTimeUnit","isMonthOrYear","formatTime","results","formatterOptions","style","unitDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAE/D,MAAMC,YAAY;IAAC;IAAgB;IAAW;IAAW;IAAS;IAAQ;IAAS;IAAU;CAAQ;AAMrG,MAAMC,aAAa;AACnB,OAAO,MAAMC,oBAAqC;IAChDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,OAAO,MAAMC,mBAA4D;IACvEC,cAAc;QACZC,OAAON;QACPE,OAAO;IACT;IACAK,SAAS;QACPD,OAA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A,SAAS;AACvC;AAEA,OAAO,SAASM,WAAWP,KAAa,EAAE,EAAEC,KAAI,EAAEhB,cAAa,EAAqB;IAClF,IAAIe,UAAU,GAAG,OAAO;IAExB,MAAMQ,UAAUT,iCAAiCC,OAAOC;IAExD,MAAMQ,mBAA6C;QACjDC,OAAO;QACPT,MAAML,oBAAoB,CAACY,QAAQP,KAAK;QACxCU,aAAaL,cAAcE,QAAQP,QAAQ,SAAS;IACtD;IAEA,IAAItB,iBAAiBM,gBAAgB;QACnCwB,iBAAiBG,wBAAwBhC,mBAAmBK;QAC5DwB,iBAAiBI,wBAAwBjC,mBAAmBK;IAC9D,OAAO;QACLwB,iBAAiBK,2BAA2BpC;IAC9C;IAEA,MAAMqC,YAAYC,KAAKC,aAAa,SAASR;IAC7C,OAAOM,UAAUG,OAAOV,QAAQR;AAClC"}
@@ -1,4 +1,5 @@
1
- import { UnitOptions } from './units';
1
+ import { AbsoluteTimeRange, DurationString } from '../time';
2
+ import { FormatOptions } from './units';
2
3
  export declare const UNIT_GROUPS: readonly ["Time", "Percent", "Decimal", "Bytes"];
3
4
  export declare type UnitGroup = (typeof UNIT_GROUPS)[number];
4
5
  /**
@@ -12,11 +13,11 @@ export declare type UnitGroupConfig = {
12
13
  /**
13
14
  * When true, the unit group supports setting decimal places.
14
15
  */
15
- decimal_places?: boolean;
16
+ decimalPlaces?: boolean;
16
17
  /**
17
- * When true, the unit group supports enabling abbreviate.
18
+ * When true, the unit group supports enabling shortValues.
18
19
  */
19
- abbreviate?: boolean;
20
+ shortValues?: boolean;
20
21
  };
21
22
  /**
22
23
  * Configuration for rendering a specific unit.
@@ -41,7 +42,15 @@ export declare type UnitConfig = {
41
42
  */
42
43
  export interface UnitTestCase {
43
44
  value: number;
44
- unit: UnitOptions;
45
+ format: FormatOptions;
45
46
  expected: string;
46
47
  }
48
+ export interface IntervalTestCase {
49
+ timeRange: AbsoluteTimeRange;
50
+ expected: Duration;
51
+ }
52
+ export interface FormatTestCase {
53
+ duration: Duration;
54
+ expected: DurationString;
55
+ }
47
56
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,eAAO,MAAM,WAAW,kDAAmD,CAAC;AAC5E,oBAAY,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;GAEG;AACH,oBAAY,eAAe,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,oBAAY,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,eAAO,MAAM,WAAW,kDAAmD,CAAC;AAC5E,oBAAY,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD;;GAEG;AACH,oBAAY,eAAe,GAAG;IAC5B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,oBAAY,UAAU,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IAEjB;;;OAGG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,aAAa,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;CAC1B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common types needed across individual unit groups and the overall combined\n// units.\n\nimport { UnitOptions } from './units';\n\nexport const UNIT_GROUPS = ['Time', 'Percent', 'Decimal', 'Bytes'] as const;\nexport type UnitGroup = (typeof UNIT_GROUPS)[number];\n\n/**\n * Configuration for rendering units that are part of a group.\n */\nexport type UnitGroupConfig = {\n /**\n * The label that is shown in the UI.\n */\n label: string;\n /**\n * When true, the unit group supports setting decimal places.\n */\n decimal_places?: boolean;\n /**\n * When true, the unit group supports enabling abbreviate.\n */\n abbreviate?: boolean;\n};\n\n/**\n * Configuration for rendering a specific unit.\n */\nexport type UnitConfig = {\n /**\n * The group the unit is part of. This will inform common rendering behavior.\n */\n group: UnitGroup;\n\n /**\n * When true, this unit will not be displayed in the unit selector. This is\n * useful for units that are shorthand variants of other units.\n */\n disableSelectorOption?: boolean;\n\n /**\n * The label that is shown in the UI.\n */\n label: string;\n};\n\n/**\n * Used in the tests for each type of unit.\n */\nexport interface UnitTestCase {\n value: number;\n unit: UnitOptions;\n expected: string;\n}\n"],"names":["UNIT_GROUPS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,6EAA6E;AAC7E,SAAS;AAIT,OAAO,MAAMA,WAAW,GAAG;IAAC,MAAM;IAAE,SAAS;IAAE,SAAS;IAAE,OAAO;CAAC,AAAS,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common types needed across individual unit groups and the overall combined\n// units.\n\nimport { AbsoluteTimeRange, DurationString } from '../time';\nimport { FormatOptions } from './units';\n\nexport const UNIT_GROUPS = ['Time', 'Percent', 'Decimal', 'Bytes'] as const;\nexport type UnitGroup = (typeof UNIT_GROUPS)[number];\n\n/**\n * Configuration for rendering units that are part of a group.\n */\nexport type UnitGroupConfig = {\n /**\n * The label that is shown in the UI.\n */\n label: string;\n /**\n * When true, the unit group supports setting decimal places.\n */\n decimalPlaces?: boolean;\n /**\n * When true, the unit group supports enabling shortValues.\n */\n shortValues?: boolean;\n};\n\n/**\n * Configuration for rendering a specific unit.\n */\nexport type UnitConfig = {\n /**\n * The group the unit is part of. This will inform common rendering behavior.\n */\n group: UnitGroup;\n\n /**\n * When true, this unit will not be displayed in the unit selector. This is\n * useful for units that are shorthand variants of other units.\n */\n disableSelectorOption?: boolean;\n\n /**\n * The label that is shown in the UI.\n */\n label: string;\n};\n\n/**\n * Used in the tests for each type of unit.\n */\nexport interface UnitTestCase {\n value: number;\n format: FormatOptions;\n expected: string;\n}\n\nexport interface IntervalTestCase {\n timeRange: AbsoluteTimeRange;\n expected: Duration;\n}\n\nexport interface FormatTestCase {\n duration: Duration;\n expected: DurationString;\n}\n"],"names":["UNIT_GROUPS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,6EAA6E;AAC7E,SAAS;AAKT,OAAO,MAAMA,cAAc;IAAC;IAAQ;IAAW;IAAW;CAAQ,CAAU"}