@perses-dev/components 0.35.0 → 0.36.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 (182) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.d.ts +1 -1
  2. package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -1
  3. package/dist/ContentWithLegend/ContentWithLegend.js +4 -2
  4. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  5. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +9 -3
  6. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  7. package/dist/ContentWithLegend/model/content-with-legend-model.js +17 -7
  8. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  9. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -1
  10. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
  11. package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
  12. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +2 -5
  13. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  14. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  15. package/dist/GaugeChart/GaugeChart.d.ts +1 -1
  16. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  17. package/dist/GaugeChart/GaugeChart.js +1 -2
  18. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  19. package/dist/Legend/CompactLegend.d.ts +3 -1
  20. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  21. package/dist/Legend/CompactLegend.js +5 -2
  22. package/dist/Legend/CompactLegend.js.map +1 -1
  23. package/dist/Legend/Legend.d.ts +11 -2
  24. package/dist/Legend/Legend.d.ts.map +1 -1
  25. package/dist/Legend/Legend.js +4 -2
  26. package/dist/Legend/Legend.js.map +1 -1
  27. package/dist/Legend/ListLegend.d.ts +3 -1
  28. package/dist/Legend/ListLegend.d.ts.map +1 -1
  29. package/dist/Legend/ListLegend.js +5 -4
  30. package/dist/Legend/ListLegend.js.map +1 -1
  31. package/dist/Legend/ListLegendItem.d.ts +15 -2
  32. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  33. package/dist/Legend/ListLegendItem.js +17 -5
  34. package/dist/Legend/ListLegendItem.js.map +1 -1
  35. package/dist/Legend/TableLegend.d.ts +4 -2
  36. package/dist/Legend/TableLegend.d.ts.map +1 -1
  37. package/dist/Legend/TableLegend.js +8 -2
  38. package/dist/Legend/TableLegend.js.map +1 -1
  39. package/dist/LineChart/LineChart.d.ts +17 -3
  40. package/dist/LineChart/LineChart.d.ts.map +1 -1
  41. package/dist/LineChart/LineChart.js +33 -7
  42. package/dist/LineChart/LineChart.js.map +1 -1
  43. package/dist/LineChart/index.d.ts +1 -1
  44. package/dist/LineChart/index.d.ts.map +1 -1
  45. package/dist/LineChart/index.js +1 -0
  46. package/dist/LineChart/index.js.map +1 -1
  47. package/dist/LineChart/utils.d.ts +2 -1
  48. package/dist/LineChart/utils.d.ts.map +1 -1
  49. package/dist/LineChart/utils.js +14 -1
  50. package/dist/LineChart/utils.js.map +1 -1
  51. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts +12 -0
  52. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts.map +1 -0
  53. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +45 -0
  54. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -0
  55. package/dist/RefreshIntervalPicker/index.d.ts +2 -0
  56. package/dist/RefreshIntervalPicker/index.d.ts.map +1 -0
  57. package/dist/{model/units → RefreshIntervalPicker}/index.js +1 -3
  58. package/dist/RefreshIntervalPicker/index.js.map +1 -0
  59. package/dist/StatChart/StatChart.d.ts +1 -1
  60. package/dist/StatChart/StatChart.d.ts.map +1 -1
  61. package/dist/StatChart/StatChart.js +1 -1
  62. package/dist/StatChart/StatChart.js.map +1 -1
  63. package/dist/Table/InnerTable.js +2 -2
  64. package/dist/Table/InnerTable.js.map +1 -1
  65. package/dist/Table/Table.d.ts +1 -1
  66. package/dist/Table/Table.d.ts.map +1 -1
  67. package/dist/Table/Table.js +57 -9
  68. package/dist/Table/Table.js.map +1 -1
  69. package/dist/Table/TableCell.d.ts +11 -1
  70. package/dist/Table/TableCell.d.ts.map +1 -1
  71. package/dist/Table/TableCell.js +8 -3
  72. package/dist/Table/TableCell.js.map +1 -1
  73. package/dist/Table/TableCheckbox.js +1 -1
  74. package/dist/Table/TableCheckbox.js.map +1 -1
  75. package/dist/Table/TableHeaderCell.d.ts +23 -0
  76. package/dist/Table/TableHeaderCell.d.ts.map +1 -0
  77. package/dist/Table/TableHeaderCell.js +53 -0
  78. package/dist/Table/TableHeaderCell.js.map +1 -0
  79. package/dist/Table/VirtualizedTable.d.ts +3 -3
  80. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  81. package/dist/Table/VirtualizedTable.js +43 -8
  82. package/dist/Table/VirtualizedTable.js.map +1 -1
  83. package/dist/Table/model/table-model.d.ts +71 -7
  84. package/dist/Table/model/table-model.d.ts.map +1 -1
  85. package/dist/Table/model/table-model.js +6 -2
  86. package/dist/Table/model/table-model.js.map +1 -1
  87. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +2 -1
  88. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  89. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
  90. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  91. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -1
  92. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  93. package/dist/TimeSeriesTooltip/nearby-series.js +2 -11
  94. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  95. package/dist/UnitSelector/UnitSelector.d.ts +1 -1
  96. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  97. package/dist/UnitSelector/UnitSelector.js +1 -2
  98. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  99. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +4 -2
  100. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +17 -7
  101. package/dist/cjs/GaugeChart/GaugeChart.js +2 -3
  102. package/dist/cjs/Legend/CompactLegend.js +5 -2
  103. package/dist/cjs/Legend/Legend.js +4 -2
  104. package/dist/cjs/Legend/ListLegend.js +5 -4
  105. package/dist/cjs/Legend/ListLegendItem.js +17 -5
  106. package/dist/cjs/Legend/TableLegend.js +8 -2
  107. package/dist/cjs/LineChart/LineChart.js +31 -5
  108. package/dist/cjs/LineChart/index.js +1 -0
  109. package/dist/cjs/LineChart/utils.js +14 -3
  110. package/dist/cjs/RefreshIntervalPicker/RefreshIntervalPicker.js +51 -0
  111. package/dist/cjs/{model/units → RefreshIntervalPicker}/index.js +1 -3
  112. package/dist/cjs/StatChart/StatChart.js +4 -4
  113. package/dist/cjs/Table/InnerTable.js +2 -2
  114. package/dist/cjs/Table/Table.js +56 -8
  115. package/dist/cjs/Table/TableCell.js +8 -3
  116. package/dist/cjs/Table/TableCheckbox.js +1 -1
  117. package/dist/cjs/Table/TableHeaderCell.js +59 -0
  118. package/dist/cjs/Table/VirtualizedTable.js +43 -8
  119. package/dist/cjs/Table/model/table-model.js +6 -2
  120. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
  121. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -11
  122. package/dist/cjs/UnitSelector/UnitSelector.js +6 -7
  123. package/dist/cjs/index.js +1 -0
  124. package/dist/cjs/model/index.js +1 -1
  125. package/dist/{model/units/types.js → cjs/model/timeOption.js} +4 -10
  126. package/dist/index.d.ts +1 -0
  127. package/dist/index.d.ts.map +1 -1
  128. package/dist/index.js +1 -0
  129. package/dist/index.js.map +1 -1
  130. package/dist/model/index.d.ts +1 -1
  131. package/dist/model/index.d.ts.map +1 -1
  132. package/dist/model/index.js +1 -1
  133. package/dist/model/index.js.map +1 -1
  134. package/dist/model/theme.d.ts +1 -4
  135. package/dist/model/theme.d.ts.map +1 -1
  136. package/dist/model/theme.js.map +1 -1
  137. package/dist/model/timeOption.d.ts +6 -0
  138. package/dist/model/timeOption.d.ts.map +1 -0
  139. package/dist/model/{units/constants.js → timeOption.js} +2 -4
  140. package/dist/model/timeOption.js.map +1 -0
  141. package/package.json +3 -4
  142. package/dist/cjs/model/units/bytes.js +0 -84
  143. package/dist/cjs/model/units/constants.js +0 -23
  144. package/dist/cjs/model/units/decimal.js +0 -62
  145. package/dist/cjs/model/units/percent.js +0 -73
  146. package/dist/cjs/model/units/time.js +0 -105
  147. package/dist/cjs/model/units/types.js +0 -28
  148. package/dist/cjs/model/units/units.js +0 -101
  149. package/dist/cjs/model/units/utils.js +0 -42
  150. package/dist/model/units/bytes.d.ts +0 -13
  151. package/dist/model/units/bytes.d.ts.map +0 -1
  152. package/dist/model/units/bytes.js +0 -66
  153. package/dist/model/units/bytes.js.map +0 -1
  154. package/dist/model/units/constants.d.ts +0 -2
  155. package/dist/model/units/constants.d.ts.map +0 -1
  156. package/dist/model/units/constants.js.map +0 -1
  157. package/dist/model/units/decimal.d.ts +0 -13
  158. package/dist/model/units/decimal.d.ts.map +0 -1
  159. package/dist/model/units/decimal.js +0 -49
  160. package/dist/model/units/decimal.js.map +0 -1
  161. package/dist/model/units/index.d.ts +0 -4
  162. package/dist/model/units/index.d.ts.map +0 -1
  163. package/dist/model/units/index.js.map +0 -1
  164. package/dist/model/units/percent.d.ts +0 -12
  165. package/dist/model/units/percent.d.ts.map +0 -1
  166. package/dist/model/units/percent.js +0 -60
  167. package/dist/model/units/percent.js.map +0 -1
  168. package/dist/model/units/time.d.ts +0 -22
  169. package/dist/model/units/time.d.ts.map +0 -1
  170. package/dist/model/units/time.js +0 -91
  171. package/dist/model/units/time.js.map +0 -1
  172. package/dist/model/units/types.d.ts +0 -47
  173. package/dist/model/units/types.d.ts.map +0 -1
  174. package/dist/model/units/types.js.map +0 -1
  175. package/dist/model/units/units.d.ts +0 -40
  176. package/dist/model/units/units.d.ts.map +0 -1
  177. package/dist/model/units/units.js +0 -80
  178. package/dist/model/units/units.js.map +0 -1
  179. package/dist/model/units/utils.d.ts +0 -4
  180. package/dist/model/units/utils.d.ts.map +0 -1
  181. package/dist/model/units/utils.js +0 -32
  182. package/dist/model/units/utils.js.map +0 -1
@@ -1,101 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- "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
- UNIT_GROUP_CONFIG: ()=>UNIT_GROUP_CONFIG,
25
- UNIT_CONFIG: ()=>UNIT_CONFIG,
26
- formatValue: ()=>formatValue,
27
- getUnitKindConfig: ()=>getUnitKindConfig,
28
- getUnitGroup: ()=>getUnitGroup,
29
- getUnitGroupConfig: ()=>getUnitGroupConfig,
30
- isTimeUnit: ()=>isTimeUnit,
31
- isPercentUnit: ()=>isPercentUnit,
32
- isDecimalUnit: ()=>isDecimalUnit,
33
- isBytesUnit: ()=>isBytesUnit,
34
- isUnitWithDecimalPlaces: ()=>isUnitWithDecimalPlaces,
35
- isUnitWithAbbreviate: ()=>isUnitWithAbbreviate
36
- });
37
- const _bytes = require("./bytes");
38
- const _decimal = require("./decimal");
39
- const _percent = require("./percent");
40
- const _time = require("./time");
41
- const UNIT_GROUP_CONFIG = {
42
- Time: _time.TIME_GROUP_CONFIG,
43
- Percent: _percent.PERCENT_GROUP_CONFIG,
44
- Decimal: _decimal.DECIMAL_GROUP_CONFIG,
45
- Bytes: _bytes.BYTES_GROUP_CONFIG
46
- };
47
- const UNIT_CONFIG = {
48
- ..._time.TIME_UNIT_CONFIG,
49
- ..._percent.PERCENT_UNIT_CONFIG,
50
- ..._decimal.DECIMAL_UNIT_CONFIG,
51
- ..._bytes.BYTES_UNIT_CONFIG
52
- };
53
- function formatValue(value, unitOptions) {
54
- if (unitOptions === undefined) {
55
- return value.toString();
56
- }
57
- if (isDecimalUnit(unitOptions)) {
58
- return (0, _decimal.formatDecimal)(value, unitOptions);
59
- }
60
- if (isTimeUnit(unitOptions)) {
61
- return (0, _time.formatTime)(value, unitOptions);
62
- }
63
- if (isPercentUnit(unitOptions)) {
64
- return (0, _percent.formatPercent)(value, unitOptions);
65
- }
66
- if (isBytesUnit(unitOptions)) {
67
- return (0, _bytes.formatBytes)(value, unitOptions);
68
- }
69
- const exhaustive = unitOptions;
70
- throw new Error(`Unknown unit options ${exhaustive}`);
71
- }
72
- function getUnitKindConfig(unitOptions) {
73
- return UNIT_CONFIG[unitOptions.kind];
74
- }
75
- function getUnitGroup(unitOptions) {
76
- return getUnitKindConfig(unitOptions).group;
77
- }
78
- function getUnitGroupConfig(unitOptions) {
79
- const unitConfig = getUnitKindConfig(unitOptions);
80
- return UNIT_GROUP_CONFIG[unitConfig.group];
81
- }
82
- function isTimeUnit(unitOptions) {
83
- return getUnitGroup(unitOptions) === 'Time';
84
- }
85
- function isPercentUnit(unitOptions) {
86
- return getUnitGroup(unitOptions) === 'Percent';
87
- }
88
- function isDecimalUnit(unitOptions) {
89
- return getUnitGroup(unitOptions) === 'Decimal';
90
- }
91
- function isBytesUnit(unitOptions) {
92
- return getUnitGroup(unitOptions) === 'Bytes';
93
- }
94
- function isUnitWithDecimalPlaces(unitOptions) {
95
- const groupConfig = getUnitGroupConfig(unitOptions);
96
- return !!groupConfig.decimal_places;
97
- }
98
- function isUnitWithAbbreviate(unitOptions) {
99
- const groupConfig = getUnitGroupConfig(unitOptions);
100
- return !!groupConfig.abbreviate;
101
- }
@@ -1,42 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- "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
- shouldAbbreviate: ()=>shouldAbbreviate,
25
- hasDecimalPlaces: ()=>hasDecimalPlaces,
26
- limitDecimalPlaces: ()=>limitDecimalPlaces
27
- });
28
- function shouldAbbreviate(abbreviate) {
29
- return abbreviate !== false;
30
- }
31
- function hasDecimalPlaces(decimal_places) {
32
- return typeof decimal_places === 'number';
33
- }
34
- function limitDecimalPlaces(num) {
35
- if (!num) return num;
36
- if (num < 0) {
37
- num = 0;
38
- } else if (num > 20) {
39
- num = 20;
40
- }
41
- return num;
42
- }
@@ -1,13 +0,0 @@
1
- import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const bytesUnitKinds: readonly ["Bytes"];
3
- declare type BytesUnitKind = (typeof bytesUnitKinds)[number];
4
- export declare type BytesUnitOptions = {
5
- kind: BytesUnitKind;
6
- decimal_places?: number;
7
- abbreviate?: boolean;
8
- };
9
- export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
10
- export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
11
- export declare function formatBytes(bytes: number, options: BytesUnitOptions): string;
12
- export {};
13
- //# sourceMappingURL=bytes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAKtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAOzE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,UAmCnE"}
@@ -1,66 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import numbro from 'numbro';
14
- import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
- import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
16
- const DEFAULT_NUMBRO_MANTISSA = 2;
17
- const bytesUnitKinds = [
18
- 'Bytes'
19
- ];
20
- export const BYTES_GROUP_CONFIG = {
21
- label: 'Bytes',
22
- decimal_places: true,
23
- abbreviate: true
24
- };
25
- export const BYTES_UNIT_CONFIG = {
26
- // These units are powers of 1000.
27
- // In other words, 1 KB = 1000 bytes.
28
- Bytes: {
29
- group: 'Bytes',
30
- label: 'Bytes'
31
- }
32
- };
33
- export function formatBytes(bytes, options) {
34
- const { abbreviate , decimal_places } = options;
35
- if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
36
- const formatterOptions = {
37
- style: 'unit',
38
- unit: 'byte',
39
- unitDisplay: 'long',
40
- useGrouping: true
41
- };
42
- if (hasDecimalPlaces(decimal_places)) {
43
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
44
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
45
- } else {
46
- // This can happen if bytes is between -1000 and 1000
47
- if (shouldAbbreviate(abbreviate)) {
48
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
49
- }
50
- }
51
- return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
52
- }
53
- // numbro is able to add units like KB, MB, GB, etc. correctly
54
- return numbro(bytes).format({
55
- output: 'byte',
56
- base: 'decimal',
57
- spaceSeparated: true,
58
- mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
59
- // trimMantissa trims trailing 0s
60
- trimMantissa: !hasDecimalPlaces(decimal_places),
61
- // optionalMantissa excludes all the decimal places if they're all zeros
62
- optionalMantissa: !hasDecimalPlaces(decimal_places)
63
- });
64
- }
65
-
66
- //# sourceMappingURL=bytes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = (typeof bytesUnitKinds)[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n // These units are powers of 1000.\n // In other words, 1 KB = 1000 bytes.\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\nexport function formatBytes(bytes: number, options: BytesUnitOptions) {\n const { abbreviate, decimal_places } = options;\n\n if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n // This can happen if bytes is between -1000 and 1000\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(bytes);\n }\n\n // numbro is able to add units like KB, MB, GB, etc. correctly\n return numbro(bytes).format({\n output: 'byte',\n base: 'decimal',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimal_places),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimal_places),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","DEFAULT_NUMBRO_MANTISSA","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","options","Math","abs","formatterOptions","style","unit","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,MAAM,MAAM,QAAQ,CAAC;AAE5B,SAASC,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAQ,SAAS,CAAC;AAEjF,MAAMC,uBAAuB,GAAG,CAAC,AAAC;AAElC,MAAMC,cAAc,GAAG;IAAC,OAAO;CAAC,AAAS,AAAC;AAO1C,OAAO,MAAMC,kBAAkB,GAAoB;IACjDC,KAAK,EAAE,OAAO;IACdC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,iBAAiB,GAAgD;IAC5E,kCAAkC;IAClC,qCAAqC;IACrCC,KAAK,EAAE;QACLC,KAAK,EAAE,OAAO;QACdL,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF,OAAO,SAASM,WAAW,CAACC,KAAa,EAAEC,OAAyB,EAAE;IACpE,MAAM,EAAEN,UAAU,CAAA,EAAED,cAAc,CAAA,EAAE,GAAGO,OAAO,AAAC;IAE/C,IAAI,CAACZ,gBAAgB,CAACM,UAAU,CAAC,IAAIO,IAAI,CAACC,GAAG,CAACH,KAAK,CAAC,GAAG,IAAI,EAAE;QAC3D,MAAMI,gBAAgB,GAA6B;YACjDC,KAAK,EAAE,MAAM;YACbC,IAAI,EAAE,MAAM;YACZC,WAAW,EAAE,MAAM;YACnBC,WAAW,EAAE,IAAI;SAClB,AAAC;QAEF,IAAIrB,gBAAgB,CAACO,cAAc,CAAC,EAAE;YACpCU,gBAAgB,CAACK,qBAAqB,GAAGrB,kBAAkB,CAACM,cAAc,CAAC,CAAC;YAC5EU,gBAAgB,CAACM,qBAAqB,GAAGtB,kBAAkB,CAACM,cAAc,CAAC,CAAC;QAC9E,OAAO;YACL,qDAAqD;YACrD,IAAIL,gBAAgB,CAACM,UAAU,CAAC,EAAE;gBAChCS,gBAAgB,CAACO,wBAAwB,GAAGzB,sBAAsB,CAAC;YACrE,CAAC;QACH,CAAC;QAED,OAAO0B,IAAI,CAACC,YAAY,CAAC,OAAO,EAAET,gBAAgB,CAAC,CAACU,MAAM,CAACd,KAAK,CAAC,CAAC;IACpE,CAAC;IAED,8DAA8D;IAC9D,OAAOf,MAAM,CAACe,KAAK,CAAC,CAACc,MAAM,CAAC;QAC1BC,MAAM,EAAE,MAAM;QACdC,IAAI,EAAE,SAAS;QACfC,cAAc,EAAE,IAAI;QACpBC,QAAQ,EAAE/B,gBAAgB,CAACO,cAAc,CAAC,GAAGA,cAAc,GAAGJ,uBAAuB;QACrF,iCAAiC;QACjC6B,YAAY,EAAE,CAAChC,gBAAgB,CAACO,cAAc,CAAC;QAC/C,wEAAwE;QACxE0B,gBAAgB,EAAE,CAACjC,gBAAgB,CAACO,cAAc,CAAC;KACpD,CAAC,CAAC;AACL,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare const MAX_SIGNIFICANT_DIGITS = 3;
2
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/model/units/constants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/model/units/constants.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 constants needed across individual unit groups and the overall\n// combined units.\nexport const MAX_SIGNIFICANT_DIGITS = 3;\n"],"names":["MAX_SIGNIFICANT_DIGITS"],"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,wEAAwE;AACxE,kBAAkB;AAClB,OAAO,MAAMA,sBAAsB,GAAG,CAAC,CAAC"}
@@ -1,13 +0,0 @@
1
- import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const decimalUnitKinds: readonly ["Decimal"];
3
- declare type DecimalUnitKind = (typeof decimalUnitKinds)[number];
4
- export declare type DecimalUnitOptions = {
5
- kind: DecimalUnitKind;
6
- decimal_places?: number;
7
- abbreviate?: boolean;
8
- };
9
- export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
10
- export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>>;
11
- export declare function formatDecimal(value: number, options: DecimalUnitOptions): string;
12
- export {};
13
- //# sourceMappingURL=decimal.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAsBhF"}
@@ -1,49 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
- import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
15
- const decimalUnitKinds = [
16
- 'Decimal'
17
- ];
18
- export const DECIMAL_GROUP_CONFIG = {
19
- label: 'Decimal',
20
- decimal_places: true,
21
- abbreviate: true
22
- };
23
- export const DECIMAL_UNIT_CONFIG = {
24
- Decimal: {
25
- group: 'Decimal',
26
- label: 'Decimal'
27
- }
28
- };
29
- export function formatDecimal(value, options) {
30
- const { abbreviate , decimal_places } = options;
31
- const formatterOptions = {
32
- style: 'decimal',
33
- useGrouping: true
34
- };
35
- if (shouldAbbreviate(abbreviate)) {
36
- formatterOptions.notation = 'compact';
37
- }
38
- if (hasDecimalPlaces(decimal_places)) {
39
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
40
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
41
- } else {
42
- if (shouldAbbreviate(abbreviate)) {
43
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
44
- }
45
- }
46
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
47
- }
48
-
49
- //# sourceMappingURL=decimal.js.map
@@ -1 +0,0 @@
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, options: DecimalUnitOptions): string {\n const { abbreviate, decimal_places } = options;\n\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 return Intl.NumberFormat('en-US', formatterOptions).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","options","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","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,EAAEC,gBAAgB,QAAQ,SAAS,CAAC;AAEjF,MAAMC,gBAAgB,GAAG;IAAC,SAAS;CAAC,AAAS,AAAC;AAO9C,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAE,SAAS;QAChBL,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,OAAO,SAASM,aAAa,CAACC,KAAa,EAAEC,OAA2B,EAAU;IAChF,MAAM,EAAEN,UAAU,CAAA,EAAED,cAAc,CAAA,EAAE,GAAGO,OAAO,AAAC;IAE/C,MAAMC,gBAAgB,GAA6B;QACjDC,KAAK,EAAE,SAAS;QAChBC,WAAW,EAAE,IAAI;KAClB,AAAC;IAEF,IAAId,gBAAgB,CAACK,UAAU,CAAC,EAAE;QAChCO,gBAAgB,CAACG,QAAQ,GAAG,SAAS,CAAC;IACxC,CAAC;IAED,IAAIjB,gBAAgB,CAACM,cAAc,CAAC,EAAE;QACpCQ,gBAAgB,CAACI,qBAAqB,GAAGjB,kBAAkB,CAACK,cAAc,CAAC,CAAC;QAC5EQ,gBAAgB,CAACK,qBAAqB,GAAGlB,kBAAkB,CAACK,cAAc,CAAC,CAAC;IAC9E,OAAO;QACL,IAAIJ,gBAAgB,CAACK,UAAU,CAAC,EAAE;YAChCO,gBAAgB,CAACM,wBAAwB,GAAGrB,sBAAsB,CAAC;QACrE,CAAC;IACH,CAAC;IAED,OAAOsB,IAAI,CAACC,YAAY,CAAC,OAAO,EAAER,gBAAgB,CAAC,CAACS,MAAM,CAACX,KAAK,CAAC,CAAC;AACpE,CAAC"}
@@ -1,4 +0,0 @@
1
- export * from './units';
2
- export * from './constants';
3
- export * from './types';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/units/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
@@ -1 +0,0 @@
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 './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,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
@@ -1,12 +0,0 @@
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;
7
- };
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;
11
- export {};
12
- //# sourceMappingURL=percent.d.ts.map
@@ -1 +0,0 @@
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,CAmBjG"}
@@ -1,60 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
- import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
15
- const percentUnitKinds = [
16
- 'Percent',
17
- 'PercentDecimal',
18
- '%'
19
- ];
20
- export const PERCENT_GROUP_CONFIG = {
21
- label: 'Percent',
22
- decimal_places: true
23
- };
24
- const PERCENT_GROUP = 'Percent';
25
- export const PERCENT_UNIT_CONFIG = {
26
- Percent: {
27
- group: PERCENT_GROUP,
28
- label: 'Percent (0-100)'
29
- },
30
- PercentDecimal: {
31
- group: PERCENT_GROUP,
32
- label: 'Percent (0.0-1.0)'
33
- },
34
- '%': {
35
- // This option is not shown in the selector because it is a shorthand
36
- // duplicate of `Percent`.
37
- disableSelectorOption: true,
38
- group: PERCENT_GROUP,
39
- label: '%'
40
- }
41
- };
42
- export function formatPercent(value, { kind , decimal_places }) {
43
- // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
44
- if (kind === 'Percent') {
45
- value = value / 100;
46
- }
47
- const formatterOptions = {
48
- style: 'percent',
49
- useGrouping: true
50
- };
51
- if (hasDecimalPlaces(decimal_places)) {
52
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
53
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
54
- } else {
55
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
56
- }
57
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
58
- }
59
-
60
- //# sourceMappingURL=percent.js.map
@@ -1 +0,0 @@
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 // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%\n if (kind === 'Percent') {\n value = value / 100;\n }\n\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 return Intl.NumberFormat('en-US', formatterOptions).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","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,gBAAgB,GAAG;IAAC,SAAS;IAAE,gBAAgB;IAAE,GAAG;CAAC,AAAS,AAAC;AAMrE,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;CACrB,CAAC;AACF,MAAMC,aAAa,GAAG,SAAS,AAAC;AAChC,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAEH,aAAa;QACpBF,KAAK,EAAE,iBAAiB;KACzB;IACDM,cAAc,EAAE;QACdD,KAAK,EAAEH,aAAa;QACpBF,KAAK,EAAE,mBAAmB;KAC3B;IACD,GAAG,EAAE;QACH,qEAAqE;QACrE,0BAA0B;QAC1BO,qBAAqB,EAAE,IAAI;QAC3BF,KAAK,EAAEH,aAAa;QACpBF,KAAK,EAAE,GAAG;KACX;CACF,CAAC;AAEF,OAAO,SAASQ,aAAa,CAACC,KAAa,EAAE,EAAEC,IAAI,CAAA,EAAET,cAAc,CAAA,EAAsB,EAAU;IACjG,8DAA8D;IAC9D,IAAIS,IAAI,KAAK,SAAS,EAAE;QACtBD,KAAK,GAAGA,KAAK,GAAG,GAAG,CAAC;IACtB,CAAC;IAED,MAAME,gBAAgB,GAA6B;QACjDC,KAAK,EAAE,SAAS;QAChBC,WAAW,EAAE,IAAI;KAClB,AAAC;IAEF,IAAIjB,gBAAgB,CAACK,cAAc,CAAC,EAAE;QACpCU,gBAAgB,CAACG,qBAAqB,GAAGjB,kBAAkB,CAACI,cAAc,CAAC,CAAC;QAC5EU,gBAAgB,CAACI,qBAAqB,GAAGlB,kBAAkB,CAACI,cAAc,CAAC,CAAC;IAC9E,OAAO;QACLU,gBAAgB,CAACK,wBAAwB,GAAGrB,sBAAsB,CAAC;IACrE,CAAC;IAED,OAAOsB,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,gBAAgB,CAAC,CAACQ,MAAM,CAACV,KAAK,CAAC,CAAC;AACpE,CAAC"}
@@ -1,22 +0,0 @@
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;
7
- };
8
- export declare const TIME_GROUP_CONFIG: UnitGroupConfig;
9
- export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>>;
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"
19
- }
20
- export declare function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string;
21
- export {};
22
- //# sourceMappingURL=time.d.ts.map
@@ -1 +0,0 @@
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;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,eAAe,GAAG,MAAM,CAiB3F"}
@@ -1,91 +0,0 @@
1
- // Copyright 2023 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
- import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
15
- const timeUnitKinds = [
16
- 'Milliseconds',
17
- 'Seconds',
18
- 'Minutes',
19
- 'Hours',
20
- 'Days',
21
- 'Weeks',
22
- 'Months',
23
- 'Years'
24
- ];
25
- const TIME_GROUP = 'Time';
26
- export const TIME_GROUP_CONFIG = {
27
- label: 'Time',
28
- decimal_places: true
29
- };
30
- export const TIME_UNIT_CONFIG = {
31
- Milliseconds: {
32
- group: TIME_GROUP,
33
- label: 'Milliseconds'
34
- },
35
- Seconds: {
36
- group: TIME_GROUP,
37
- label: 'Seconds'
38
- },
39
- Minutes: {
40
- group: TIME_GROUP,
41
- label: 'Minutes'
42
- },
43
- Hours: {
44
- group: TIME_GROUP,
45
- label: 'Hours'
46
- },
47
- Days: {
48
- group: TIME_GROUP,
49
- label: 'Days'
50
- },
51
- Weeks: {
52
- group: TIME_GROUP,
53
- label: 'Weeks'
54
- },
55
- Months: {
56
- group: TIME_GROUP,
57
- label: 'Months'
58
- },
59
- Years: {
60
- group: TIME_GROUP,
61
- label: 'Years'
62
- }
63
- };
64
- export var PersesTimeToIntlTime;
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';
74
- })(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
75
- export function formatTime(value, { kind , decimal_places }) {
76
- const isMonthOrYear = kind === 'Months' || kind === 'Years';
77
- const formatterOptions = {
78
- style: 'unit',
79
- unit: PersesTimeToIntlTime[kind],
80
- unitDisplay: isMonthOrYear ? 'long' : 'narrow'
81
- };
82
- if (hasDecimalPlaces(decimal_places)) {
83
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
84
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
85
- } else {
86
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
87
- }
88
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
89
- }
90
-
91
- //# sourceMappingURL=time.js.map
@@ -1 +0,0 @@
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\nexport function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string {\n const isMonthOrYear = kind === 'Months' || kind === 'Years';\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: PersesTimeToIntlTime[kind],\n unitDisplay: isMonthOrYear ? '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 return Intl.NumberFormat('en-US', formatterOptions).format(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","formatTime","value","kind","isMonthOrYear","formatterOptions","style","unit","unitDisplay","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","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,KAAK,EAAE;QACLP,KAAK,EAAEN,UAAU;QACjBE,KAAK,EAAE,OAAO;KACf;CACF,CAAC;WAIK,oBASN;UATWY,oBAAoB;IAApBA,oBAAoB,CAC9BT,cAAY,IAAG,aAAa;IADlBS,oBAAoB,CAE9BP,SAAO,IAAG,QAAQ;IAFRO,oBAAoB,CAG9BN,SAAO,IAAG,QAAQ;IAHRM,oBAAoB,CAI9BL,OAAK,IAAG,MAAM;IAJJK,oBAAoB,CAK9BJ,MAAI,IAAG,KAAK;IALFI,oBAAoB,CAM9BH,OAAK,IAAG,MAAM;IANJG,oBAAoB,CAO9BF,QAAM,IAAG,OAAO;IAPNE,oBAAoB,CAQ9BD,OAAK,IAAG,MAAM;GARJC,oBAAoB,KAApBA,oBAAoB;AAWhC,OAAO,SAASC,UAAU,CAACC,KAAa,EAAE,EAAEC,IAAI,CAAA,EAAEd,cAAc,CAAA,EAAmB,EAAU;IAC3F,MAAMe,aAAa,GAAGD,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,OAAO,AAAC;IAE5D,MAAME,gBAAgB,GAA6B;QACjDC,KAAK,EAAE,MAAM;QACbC,IAAI,EAAEP,oBAAoB,CAACG,IAAI,CAAC;QAChCK,WAAW,EAAEJ,aAAa,GAAG,MAAM,GAAG,QAAQ;KAC/C,AAAC;IAEF,IAAIrB,gBAAgB,CAACM,cAAc,CAAC,EAAE;QACpCgB,gBAAgB,CAACI,qBAAqB,GAAGzB,kBAAkB,CAACK,cAAc,CAAC,CAAC;QAC5EgB,gBAAgB,CAACK,qBAAqB,GAAG1B,kBAAkB,CAACK,cAAc,CAAC,CAAC;IAC9E,OAAO;QACLgB,gBAAgB,CAACM,wBAAwB,GAAG7B,sBAAsB,CAAC;IACrE,CAAC;IAED,OAAO8B,IAAI,CAACC,YAAY,CAAC,OAAO,EAAER,gBAAgB,CAAC,CAACS,MAAM,CAACZ,KAAK,CAAC,CAAC;AACpE,CAAC"}
@@ -1,47 +0,0 @@
1
- import { UnitOptions } from './units';
2
- export declare const UNIT_GROUPS: readonly ["Time", "Percent", "Decimal", "Bytes"];
3
- export declare type UnitGroup = (typeof UNIT_GROUPS)[number];
4
- /**
5
- * Configuration for rendering units that are part of a group.
6
- */
7
- export declare type UnitGroupConfig = {
8
- /**
9
- * The label that is shown in the UI.
10
- */
11
- label: string;
12
- /**
13
- * When true, the unit group supports setting decimal places.
14
- */
15
- decimal_places?: boolean;
16
- /**
17
- * When true, the unit group supports enabling abbreviate.
18
- */
19
- abbreviate?: boolean;
20
- };
21
- /**
22
- * Configuration for rendering a specific unit.
23
- */
24
- export declare type UnitConfig = {
25
- /**
26
- * The group the unit is part of. This will inform common rendering behavior.
27
- */
28
- group: UnitGroup;
29
- /**
30
- * When true, this unit will not be displayed in the unit selector. This is
31
- * useful for units that are shorthand variants of other units.
32
- */
33
- disableSelectorOption?: boolean;
34
- /**
35
- * The label that is shown in the UI.
36
- */
37
- label: string;
38
- };
39
- /**
40
- * Used in the tests for each type of unit.
41
- */
42
- export interface UnitTestCase {
43
- value: number;
44
- unit: UnitOptions;
45
- expected: string;
46
- }
47
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
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 +0,0 @@
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"}