@perses-dev/components 0.29.1 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  2. package/dist/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  3. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  4. package/dist/EChart/EChart.d.ts.map +1 -1
  5. package/dist/EChart/EChart.js +1 -7
  6. package/dist/EChart/EChart.js.map +1 -1
  7. package/dist/Legend/CompactLegend.d.ts +6 -4
  8. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  9. package/dist/Legend/CompactLegend.js +4 -1
  10. package/dist/Legend/CompactLegend.js.map +1 -1
  11. package/dist/Legend/Legend.d.ts +11 -9
  12. package/dist/Legend/Legend.d.ts.map +1 -1
  13. package/dist/Legend/Legend.js +45 -11
  14. package/dist/Legend/Legend.js.map +1 -1
  15. package/dist/Legend/ListLegend.d.ts +5 -8
  16. package/dist/Legend/ListLegend.d.ts.map +1 -1
  17. package/dist/Legend/ListLegend.js +34 -99
  18. package/dist/Legend/ListLegend.js.map +1 -1
  19. package/dist/Legend/ListLegendItem.d.ts +8 -8
  20. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  21. package/dist/Legend/ListLegendItem.js +9 -12
  22. package/dist/Legend/ListLegendItem.js.map +1 -1
  23. package/dist/LineChart/LineChart.d.ts +2 -1
  24. package/dist/LineChart/LineChart.d.ts.map +1 -1
  25. package/dist/LineChart/LineChart.js +35 -22
  26. package/dist/LineChart/LineChart.js.map +1 -1
  27. package/dist/StatChart/StatChart.d.ts.map +1 -1
  28. package/dist/StatChart/StatChart.js +5 -1
  29. package/dist/StatChart/StatChart.js.map +1 -1
  30. package/dist/Table/InnerTable.d.ts +9 -0
  31. package/dist/Table/InnerTable.d.ts.map +1 -0
  32. package/dist/Table/InnerTable.js +38 -0
  33. package/dist/Table/InnerTable.js.map +1 -0
  34. package/dist/Table/Table.d.ts +10 -0
  35. package/dist/Table/Table.d.ts.map +1 -0
  36. package/dist/Table/Table.js +101 -0
  37. package/dist/Table/Table.js.map +1 -0
  38. package/dist/Table/TableBody.d.ts +6 -0
  39. package/dist/Table/TableBody.d.ts.map +1 -0
  40. package/dist/Table/TableBody.js +23 -0
  41. package/dist/Table/TableBody.js.map +1 -0
  42. package/dist/Table/TableCell.d.ts +18 -0
  43. package/dist/Table/TableCell.d.ts.map +1 -0
  44. package/dist/Table/TableCell.js +91 -0
  45. package/dist/Table/TableCell.js.map +1 -0
  46. package/dist/Table/TableCheckbox.d.ts +9 -0
  47. package/dist/Table/TableCheckbox.d.ts.map +1 -0
  48. package/dist/Table/TableCheckbox.js +49 -0
  49. package/dist/Table/TableCheckbox.js.map +1 -0
  50. package/dist/Table/TableHead.d.ts +6 -0
  51. package/dist/Table/TableHead.d.ts.map +1 -0
  52. package/dist/Table/TableHead.js +23 -0
  53. package/dist/Table/TableHead.js.map +1 -0
  54. package/dist/Table/TableRow.d.ts +9 -0
  55. package/dist/Table/TableRow.d.ts.map +1 -0
  56. package/dist/Table/TableRow.js +29 -0
  57. package/dist/Table/TableRow.js.map +1 -0
  58. package/dist/Table/VirtualizedTable.d.ts +11 -0
  59. package/dist/Table/VirtualizedTable.d.ts.map +1 -0
  60. package/dist/Table/VirtualizedTable.js +152 -0
  61. package/dist/Table/VirtualizedTable.js.map +1 -0
  62. package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
  63. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
  64. package/dist/Table/VirtualizedTableContainer.js +24 -0
  65. package/dist/Table/VirtualizedTableContainer.js.map +1 -0
  66. package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
  67. package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
  68. package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
  69. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
  70. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
  71. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
  72. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
  73. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
  74. package/dist/Table/index.d.ts +4 -0
  75. package/dist/Table/index.d.ts.map +1 -0
  76. package/dist/Table/index.js +16 -0
  77. package/dist/Table/index.js.map +1 -0
  78. package/dist/Table/model/table-model.d.ts +83 -0
  79. package/dist/Table/model/table-model.d.ts.map +1 -0
  80. package/dist/Table/model/table-model.js +73 -0
  81. package/dist/Table/model/table-model.js.map +1 -0
  82. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
  83. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  84. package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
  85. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  86. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +3 -2
  87. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  88. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +63 -17
  89. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  90. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +5 -3
  91. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  92. package/dist/TimeSeriesTooltip/TooltipContent.js +81 -44
  93. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  94. package/dist/TimeSeriesTooltip/index.d.ts +1 -1
  95. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  96. package/dist/TimeSeriesTooltip/index.js +1 -1
  97. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  98. package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
  99. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
  100. package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
  101. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
  102. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +12 -4
  103. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  104. package/dist/TimeSeriesTooltip/tooltip-model.js +10 -2
  105. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  106. package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
  107. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  108. package/dist/TimeSeriesTooltip/utils.js +7 -15
  109. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  110. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  111. package/dist/UnitSelector/UnitSelector.js +40 -17
  112. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  113. package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  114. package/dist/cjs/EChart/EChart.js +1 -7
  115. package/dist/cjs/Legend/CompactLegend.js +4 -1
  116. package/dist/cjs/Legend/Legend.js +45 -11
  117. package/dist/cjs/Legend/ListLegend.js +33 -98
  118. package/dist/cjs/Legend/ListLegendItem.js +8 -11
  119. package/dist/cjs/LineChart/LineChart.js +35 -22
  120. package/dist/cjs/StatChart/StatChart.js +5 -1
  121. package/dist/cjs/Table/InnerTable.js +44 -0
  122. package/dist/cjs/Table/Table.js +102 -0
  123. package/dist/cjs/Table/TableBody.js +29 -0
  124. package/dist/cjs/Table/TableCell.js +97 -0
  125. package/dist/cjs/Table/TableCheckbox.js +55 -0
  126. package/dist/cjs/Table/TableHead.js +29 -0
  127. package/dist/cjs/Table/TableRow.js +35 -0
  128. package/dist/cjs/Table/VirtualizedTable.js +155 -0
  129. package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
  130. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
  131. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
  132. package/dist/cjs/Table/index.js +33 -0
  133. package/dist/cjs/Table/model/table-model.js +80 -0
  134. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
  135. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +67 -16
  136. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +85 -43
  137. package/dist/cjs/TimeSeriesTooltip/index.js +1 -1
  138. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
  139. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +15 -3
  140. package/dist/cjs/TimeSeriesTooltip/utils.js +6 -14
  141. package/dist/cjs/UnitSelector/UnitSelector.js +39 -16
  142. package/dist/cjs/context/SnackbarProvider.js +66 -0
  143. package/dist/cjs/index.js +2 -0
  144. package/dist/cjs/model/legend.js +7 -1
  145. package/dist/cjs/model/units/bytes.js +25 -21
  146. package/dist/cjs/model/units/constants.js +3 -3
  147. package/dist/cjs/model/units/decimal.js +22 -19
  148. package/dist/cjs/model/units/percent.js +15 -22
  149. package/dist/cjs/model/units/time.js +24 -20
  150. package/dist/cjs/model/units/units.js +2 -2
  151. package/dist/cjs/model/units/utils.js +42 -0
  152. package/dist/cjs/theme/palette/grey.js +6 -2
  153. package/dist/context/SnackbarProvider.d.ts +23 -0
  154. package/dist/context/SnackbarProvider.d.ts.map +1 -0
  155. package/dist/context/SnackbarProvider.js +59 -0
  156. package/dist/context/SnackbarProvider.js.map +1 -0
  157. package/dist/index.d.ts +2 -0
  158. package/dist/index.d.ts.map +1 -1
  159. package/dist/index.js +2 -0
  160. package/dist/index.js.map +1 -1
  161. package/dist/model/legend.d.ts +10 -2
  162. package/dist/model/legend.d.ts.map +1 -1
  163. package/dist/model/legend.js +5 -0
  164. package/dist/model/legend.js.map +1 -1
  165. package/dist/model/units/bytes.d.ts +1 -1
  166. package/dist/model/units/bytes.d.ts.map +1 -1
  167. package/dist/model/units/bytes.js +26 -22
  168. package/dist/model/units/bytes.js.map +1 -1
  169. package/dist/model/units/constants.d.ts +1 -1
  170. package/dist/model/units/constants.js +1 -1
  171. package/dist/model/units/constants.js.map +1 -1
  172. package/dist/model/units/decimal.d.ts +2 -2
  173. package/dist/model/units/decimal.d.ts.map +1 -1
  174. package/dist/model/units/decimal.js +22 -19
  175. package/dist/model/units/decimal.js.map +1 -1
  176. package/dist/model/units/percent.d.ts +1 -1
  177. package/dist/model/units/percent.d.ts.map +1 -1
  178. package/dist/model/units/percent.js +14 -21
  179. package/dist/model/units/percent.js.map +1 -1
  180. package/dist/model/units/time.d.ts +1 -1
  181. package/dist/model/units/time.d.ts.map +1 -1
  182. package/dist/model/units/time.js +24 -20
  183. package/dist/model/units/time.js.map +1 -1
  184. package/dist/model/units/units.js +2 -2
  185. package/dist/model/units/units.js.map +1 -1
  186. package/dist/model/units/utils.d.ts +4 -0
  187. package/dist/model/units/utils.d.ts.map +1 -0
  188. package/dist/model/units/utils.js +32 -0
  189. package/dist/model/units/utils.js.map +1 -0
  190. package/dist/theme/palette/grey.d.ts.map +1 -1
  191. package/dist/theme/palette/grey.js +6 -2
  192. package/dist/theme/palette/grey.js.map +1 -1
  193. package/package.json +6 -6
  194. package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
  195. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
  196. package/dist/TimeSeriesTooltip/focused-series.js +0 -111
  197. package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
  198. package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -117
@@ -11,7 +11,9 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import numbro from 'numbro';
14
- import { DEFAULT_DECIMAL_PLACES } from './constants';
14
+ import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
+ import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
16
+ const DEFAULT_NUMBRO_MANTISSA = 2;
15
17
  const bytesUnitKinds = [
16
18
  'Bytes'
17
19
  ];
@@ -21,41 +23,43 @@ export const BYTES_GROUP_CONFIG = {
21
23
  abbreviate: true
22
24
  };
23
25
  export const BYTES_UNIT_CONFIG = {
24
- // This uses units that are powers of 1000.
25
- // In other words, 1KB = 1000 bytes.
26
+ // These units are powers of 1000.
27
+ // In other words, 1 KB = 1000 bytes.
26
28
  Bytes: {
27
29
  group: 'Bytes',
28
30
  label: 'Bytes'
29
31
  }
30
32
  };
31
- export function formatBytes(bytes, { abbreviate , decimal_places }) {
32
- if (bytes === 0) return '0 bytes';
33
- decimal_places = decimal_places !== null && decimal_places !== void 0 ? decimal_places : DEFAULT_DECIMAL_PLACES;
34
- // Avoids maximumFractionDigits value is out of range error. Possible values are 0 to 20.
35
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits
36
- if (decimal_places < 0) {
37
- decimal_places = 0;
38
- } else if (decimal_places > 20) {
39
- decimal_places = 20;
40
- }
41
- const showFullNumber = abbreviate == false || bytes < 1000;
42
- if (showFullNumber) {
43
- const formatter = new Intl.NumberFormat('en-US', {
33
+ export function formatBytes(bytes, options) {
34
+ const { abbreviate , decimal_places } = options;
35
+ if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
36
+ const formatterOptions = {
44
37
  style: 'unit',
45
38
  unit: 'byte',
46
39
  unitDisplay: 'long',
47
- maximumFractionDigits: decimal_places,
48
40
  useGrouping: true
49
- });
50
- return formatter.format(bytes);
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);
51
52
  }
53
+ // numbro is able to add units like KB, MB, GB, etc. correctly
52
54
  return numbro(bytes).format({
53
55
  output: 'byte',
54
56
  base: 'decimal',
55
57
  spaceSeparated: true,
56
- mantissa: decimal_places,
57
- trimMantissa: true,
58
- optionalMantissa: 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)
59
63
  });
60
64
  }
61
65
 
@@ -1 +1 @@
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 { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = (typeof bytesUnitKinds)[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n // This uses units that are powers of 1000.\n // In other words, 1KB = 1000 bytes.\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\nexport function formatBytes(bytes: number, { abbreviate, decimal_places }: BytesUnitOptions) {\n if (bytes === 0) return '0 bytes';\n\n decimal_places = decimal_places ?? DEFAULT_DECIMAL_PLACES;\n // Avoids maximumFractionDigits value is out of range error. Possible values are 0 to 20.\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits\n if (decimal_places < 0) {\n decimal_places = 0;\n } else if (decimal_places > 20) {\n decimal_places = 20;\n }\n\n const showFullNumber = abbreviate == false || bytes < 1000;\n\n if (showFullNumber) {\n const formatter = new Intl.NumberFormat('en-US', {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n maximumFractionDigits: decimal_places,\n useGrouping: true,\n });\n return formatter.format(bytes);\n }\n\n return numbro(bytes).format({\n output: 'byte',\n base: 'decimal',\n spaceSeparated: true,\n mantissa: decimal_places,\n trimMantissa: true,\n optionalMantissa: true,\n });\n}\n"],"names":["numbro","DEFAULT_DECIMAL_PLACES","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","showFullNumber","formatter","Intl","NumberFormat","style","unit","unitDisplay","maximumFractionDigits","useGrouping","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;AAGrD,MAAMC,cAAc,GAAG;IAAC,OAAO;CAAC,AAAS,AAAC;AAO1C,OAAO,MAAMC,kBAAkB,GAAoB;IACjDC,KAAK,EAAE,OAAO;IACdC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,iBAAiB,GAAgD;IAC5E,2CAA2C;IAC3C,oCAAoC;IACpCC,KAAK,EAAE;QACLC,KAAK,EAAE,OAAO;QACdL,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF,OAAO,SAASM,WAAW,CAACC,KAAa,EAAE,EAAEL,UAAU,CAAA,EAAED,cAAc,CAAA,EAAoB,EAAE;IAC3F,IAAIM,KAAK,KAAK,CAAC,EAAE,OAAO,SAAS,CAAC;IAElCN,cAAc,GAAGA,cAAc,aAAdA,cAAc,cAAdA,cAAc,GAAIJ,sBAAsB,CAAC;IAC1D,yFAAyF;IACzF,wIAAwI;IACxI,IAAII,cAAc,GAAG,CAAC,EAAE;QACtBA,cAAc,GAAG,CAAC,CAAC;IACrB,OAAO,IAAIA,cAAc,GAAG,EAAE,EAAE;QAC9BA,cAAc,GAAG,EAAE,CAAC;IACtB,CAAC;IAED,MAAMO,cAAc,GAAGN,UAAU,IAAI,KAAK,IAAIK,KAAK,GAAG,IAAI,AAAC;IAE3D,IAAIC,cAAc,EAAE;QAClB,MAAMC,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAE;YAC/CC,KAAK,EAAE,MAAM;YACbC,IAAI,EAAE,MAAM;YACZC,WAAW,EAAE,MAAM;YACnBC,qBAAqB,EAAEd,cAAc;YACrCe,WAAW,EAAE,IAAI;SAClB,CAAC,AAAC;QACH,OAAOP,SAAS,CAACQ,MAAM,CAACV,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,OAAOX,MAAM,CAACW,KAAK,CAAC,CAACU,MAAM,CAAC;QAC1BC,MAAM,EAAE,MAAM;QACdC,IAAI,EAAE,SAAS;QACfC,cAAc,EAAE,IAAI;QACpBC,QAAQ,EAAEpB,cAAc;QACxBqB,YAAY,EAAE,IAAI;QAClBC,gBAAgB,EAAE,IAAI;KACvB,CAAC,CAAC;AACL,CAAC"}
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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AAC;AACL,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const DEFAULT_DECIMAL_PLACES = 2;
1
+ export declare const MAX_SIGNIFICANT_DIGITS = 3;
2
2
  //# sourceMappingURL=constants.d.ts.map
@@ -12,6 +12,6 @@
12
12
  // limitations under the License.
13
13
  // Common constants needed across individual unit groups and the overall
14
14
  // combined units.
15
- export const DEFAULT_DECIMAL_PLACES = 2;
15
+ export const MAX_SIGNIFICANT_DIGITS = 3;
16
16
 
17
17
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
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 DEFAULT_DECIMAL_PLACES = 2;\n"],"names":["DEFAULT_DECIMAL_PLACES"],"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
+ {"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"}
@@ -6,8 +6,8 @@ export declare type DecimalUnitOptions = {
6
6
  decimal_places?: number;
7
7
  abbreviate?: boolean;
8
8
  };
9
- export declare const PERCENT_GROUP_CONFIG: UnitGroupConfig;
9
+ export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
10
10
  export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>>;
11
- export declare function formatDecimal(value: number, { abbreviate, decimal_places }: DecimalUnitOptions): string;
11
+ export declare function formatDecimal(value: number, options: DecimalUnitOptions): string;
12
12
  export {};
13
13
  //# sourceMappingURL=decimal.d.ts.map
@@ -1 +1 @@
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;AAEtD,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,eAGlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAoBvG"}
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"}
@@ -10,13 +10,15 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { DEFAULT_DECIMAL_PLACES } from './constants';
13
+ import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
+ import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
14
15
  const decimalUnitKinds = [
15
16
  'Decimal'
16
17
  ];
17
- export const PERCENT_GROUP_CONFIG = {
18
- label: 'Percent',
19
- decimal_places: true
18
+ export const DECIMAL_GROUP_CONFIG = {
19
+ label: 'Decimal',
20
+ decimal_places: true,
21
+ abbreviate: true
20
22
  };
21
23
  export const DECIMAL_UNIT_CONFIG = {
22
24
  Decimal: {
@@ -24,23 +26,24 @@ export const DECIMAL_UNIT_CONFIG = {
24
26
  label: 'Decimal'
25
27
  }
26
28
  };
27
- export function formatDecimal(value, { abbreviate , decimal_places }) {
28
- decimal_places = decimal_places !== null && decimal_places !== void 0 ? decimal_places : DEFAULT_DECIMAL_PLACES;
29
- // Avoids maximumFractionDigits value is out of range error. Possible values are 0 to 20.
30
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits
31
- if (decimal_places < 0) {
32
- decimal_places = 0;
33
- } else if (decimal_places > 20) {
34
- decimal_places = 20;
35
- }
36
- const showFullNumber = abbreviate == false || value < 1000;
37
- const formatter = new Intl.NumberFormat('en-US', {
29
+ export function formatDecimal(value, options) {
30
+ const { abbreviate , decimal_places } = options;
31
+ const formatterOptions = {
38
32
  style: 'decimal',
39
- notation: showFullNumber ? 'standard' : 'compact',
40
- maximumFractionDigits: decimal_places,
41
33
  useGrouping: true
42
- });
43
- return formatter.format(value);
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);
44
47
  }
45
48
 
46
49
  //# sourceMappingURL=decimal.js.map
@@ -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 { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\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 PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: 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 decimal_places = decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n // Avoids maximumFractionDigits value is out of range error. Possible values are 0 to 20.\n // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#minimumfractiondigits\n if (decimal_places < 0) {\n decimal_places = 0;\n } else if (decimal_places > 20) {\n decimal_places = 20;\n }\n\n const showFullNumber = abbreviate == false || value < 1000;\n\n const formatter = new Intl.NumberFormat('en-US', {\n style: 'decimal',\n notation: showFullNumber ? 'standard' : 'compact',\n maximumFractionDigits: decimal_places,\n useGrouping: true,\n });\n return formatter.format(value);\n}\n"],"names":["DEFAULT_DECIMAL_PLACES","decimalUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","abbreviate","showFullNumber","formatter","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,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, 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"}
@@ -5,7 +5,7 @@ export declare type PercentUnitOptions = {
5
5
  kind: PercentUnitKind;
6
6
  decimal_places?: number;
7
7
  };
8
- export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
8
+ export declare const PERCENT_GROUP_CONFIG: UnitGroupConfig;
9
9
  export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>>;
10
10
  export declare function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string;
11
11
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,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,eAIlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAgB7E,CAAC;AAIF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CA0BjG"}
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"}
@@ -10,15 +10,16 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
+ import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
+ import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
13
15
  const percentUnitKinds = [
14
16
  'Percent',
15
17
  'PercentDecimal',
16
18
  '%'
17
19
  ];
18
- export const DECIMAL_GROUP_CONFIG = {
19
- label: 'Decimal',
20
- decimal_places: true,
21
- abbreviate: true
20
+ export const PERCENT_GROUP_CONFIG = {
21
+ label: 'Percent',
22
+ decimal_places: true
22
23
  };
23
24
  const PERCENT_GROUP = 'Percent';
24
25
  export const PERCENT_UNIT_CONFIG = {
@@ -38,30 +39,22 @@ export const PERCENT_UNIT_CONFIG = {
38
39
  label: '%'
39
40
  }
40
41
  };
41
- const MAX_SIGNIFICANT_DIGITS = 3;
42
42
  export function formatPercent(value, { kind , decimal_places }) {
43
43
  // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
44
44
  if (kind === 'Percent') {
45
45
  value = value / 100;
46
46
  }
47
- const hasDecimalPlaces = decimal_places !== undefined;
48
- let formatter;
49
- if (hasDecimalPlaces) {
50
- // If there is a specified # of decimal places, use maximumFractionDigits
51
- formatter = new Intl.NumberFormat('en-US', {
52
- style: 'percent',
53
- maximumFractionDigits: decimal_places,
54
- useGrouping: true
55
- });
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);
56
54
  } else {
57
- // By default, use maximumSignificantDigits
58
- formatter = new Intl.NumberFormat('en-US', {
59
- style: 'percent',
60
- maximumSignificantDigits: MAX_SIGNIFICANT_DIGITS,
61
- useGrouping: true
62
- });
55
+ formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
63
56
  }
64
- return formatter.format(value);
57
+ return Intl.NumberFormat('en-US', formatterOptions).format(value);
65
58
  }
66
59
 
67
60
  //# sourceMappingURL=percent.js.map
@@ -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 { UnitGroupConfig, UnitConfig } from './types';\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 DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimal_places: true,\n abbreviate: 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\nconst MAX_SIGNIFICANT_DIGITS = 3;\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 hasDecimalPlaces = decimal_places !== undefined;\n\n let formatter;\n if (hasDecimalPlaces) {\n // If there is a specified # of decimal places, use maximumFractionDigits\n formatter = new Intl.NumberFormat('en-US', {\n style: 'percent',\n maximumFractionDigits: decimal_places,\n useGrouping: true,\n });\n } else {\n // By default, use maximumSignificantDigits\n formatter = new Intl.NumberFormat('en-US', {\n style: 'percent',\n maximumSignificantDigits: MAX_SIGNIFICANT_DIGITS,\n useGrouping: true,\n });\n }\n\n return formatter.format(value);\n}\n"],"names":["percentUnitKinds","DECIMAL_GROUP_CONFIG","label","decimal_places","abbreviate","PERCENT_GROUP","PERCENT_UNIT_CONFIG","Percent","group","PercentDecimal","disableSelectorOption","MAX_SIGNIFICANT_DIGITS","formatPercent","value","kind","hasDecimalPlaces","undefined","formatter","Intl","NumberFormat","style","maximumFractionDigits","useGrouping","maximumSignificantDigits","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF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,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAE;YACzCC,KAAK,EAAE,SAAS;YAChBG,wBAAwB,EAAEZ,sBAAsB;YAChDW,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;IAED,OAAOL,SAAS,CAACO,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 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"}
@@ -7,7 +7,7 @@ export declare type TimeUnitOptions = {
7
7
  };
8
8
  export declare const TIME_GROUP_CONFIG: UnitGroupConfig;
9
9
  export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>>;
10
- export declare enum TimeIntlDuration {
10
+ export declare enum PersesTimeToIntlTime {
11
11
  Milliseconds = "millisecond",
12
12
  Seconds = "second",
13
13
  Minutes = "minute",
@@ -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,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;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"}
@@ -10,7 +10,8 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { DEFAULT_DECIMAL_PLACES } from './constants';
13
+ import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
+ import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
14
15
  const timeUnitKinds = [
15
16
  'Milliseconds',
16
17
  'Seconds',
@@ -60,28 +61,31 @@ export const TIME_UNIT_CONFIG = {
60
61
  label: 'Years'
61
62
  }
62
63
  };
63
- export var TimeIntlDuration;
64
- (function(TimeIntlDuration) {
65
- TimeIntlDuration["Milliseconds"] = 'millisecond';
66
- TimeIntlDuration["Seconds"] = 'second';
67
- TimeIntlDuration["Minutes"] = 'minute';
68
- TimeIntlDuration["Hours"] = 'hour';
69
- TimeIntlDuration["Days"] = 'day';
70
- TimeIntlDuration["Weeks"] = 'week';
71
- TimeIntlDuration["Months"] = 'month';
72
- TimeIntlDuration["Years"] = 'year';
73
- })(TimeIntlDuration || (TimeIntlDuration = {}));
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 = {}));
74
75
  export function formatTime(value, { kind , decimal_places }) {
75
- const decimalPlaces = decimal_places !== null && decimal_places !== void 0 ? decimal_places : DEFAULT_DECIMAL_PLACES;
76
- const timeUnit = TimeIntlDuration[kind];
77
76
  const isMonthOrYear = kind === 'Months' || kind === 'Years';
78
- const formatter = new Intl.NumberFormat('en-US', {
77
+ const formatterOptions = {
79
78
  style: 'unit',
80
- unit: timeUnit,
81
- unitDisplay: isMonthOrYear ? 'long' : 'narrow',
82
- maximumFractionDigits: decimalPlaces
83
- });
84
- return formatter.format(value);
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);
85
89
  }
86
90
 
87
91
  //# sourceMappingURL=time.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DEFAULT_DECIMAL_PLACES } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst timeUnitKinds = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Days', 'Weeks', 'Months', 'Years'] as const;\ntype TimeUnitKind = (typeof timeUnitKinds)[number];\nexport type TimeUnitOptions = {\n kind: TimeUnitKind;\n decimal_places?: number;\n};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\n decimal_places: true,\n};\nexport const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>> = {\n Milliseconds: {\n group: TIME_GROUP,\n label: 'Milliseconds',\n },\n Seconds: {\n group: TIME_GROUP,\n label: 'Seconds',\n },\n Minutes: {\n group: TIME_GROUP,\n label: 'Minutes',\n },\n Hours: {\n group: TIME_GROUP,\n label: 'Hours',\n },\n Days: {\n group: TIME_GROUP,\n label: 'Days',\n },\n Weeks: {\n group: TIME_GROUP,\n label: 'Weeks',\n },\n Months: {\n group: TIME_GROUP,\n label: 'Months',\n },\n Years: {\n group: TIME_GROUP,\n label: 'Years',\n },\n};\n\n// Mapping of time units to what Intl.NumberFormat formatter expects\n// https://v8.dev/features/intl-numberformat#units\nexport enum TimeIntlDuration {\n Milliseconds = 'millisecond',\n Seconds = 'second',\n Minutes = 'minute',\n Hours = 'hour',\n Days = 'day',\n Weeks = 'week',\n Months = 'month',\n Years = 'year',\n}\n\nexport function formatTime(value: number, { kind, decimal_places }: TimeUnitOptions): string {\n const decimalPlaces = decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n const timeUnit: string = TimeIntlDuration[kind];\n const isMonthOrYear = kind === 'Months' || kind === 'Years';\n\n const formatter = new Intl.NumberFormat('en-US', {\n style: 'unit',\n unit: timeUnit,\n unitDisplay: isMonthOrYear ? 'long' : 'narrow',\n maximumFractionDigits: decimalPlaces,\n });\n return formatter.format(value);\n}\n"],"names":["DEFAULT_DECIMAL_PLACES","timeUnitKinds","TIME_GROUP","TIME_GROUP_CONFIG","label","decimal_places","TIME_UNIT_CONFIG","Milliseconds","group","Seconds","Minutes","Hours","Days","Weeks","Months","Years","TimeIntlDuration","formatTime","value","kind","decimalPlaces","timeUnit","isMonthOrYear","formatter","Intl","NumberFormat","style","unit","unitD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BS,gBAAgB,CAE1BP,SAAO,IAAG,QAAQ;IAFRO,gBAAgB,CAG1BN,SAAO,IAAG,QAAQ;IAHRM,gBAAgB,CAI1BL,OAAK,IAAG,MAAM;IAJJK,gBAAgB,CAK1BJ,MAAI,IAAG,KAAK;IALFI,gBAAgB,CAM1BH,OAAK,IAAG,MAAM;IANJG,gBAAgB,CAO1BF,QAAM,IAAG,OAAO;IAPNE,gBAAgB,CAQ1BD,OAAK,IAAG,MAAM;GARJC,gBAAgB,KAAhBA,gBAAgB;AAW5B,OAAO,SAASC,UAAU,CAACC,KAAa,EAAE,EAAEC,IAAI,CAAA,EAAEd,cAAc,CAAA,EAAmB,EAAU;IAC3F,MAAMe,aAAa,GAAGf,cAAc,aAAdA,cAAc,cAAdA,cAAc,GAAIL,sBAAsB,AAAC;IAE/D,MAAMqB,QAAQ,GAAWL,gBAAgB,CAACG,IAAI,CAAC,AAAC;IAChD,MAAMG,aAAa,GAAGH,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,OAAO,AAAC;IAE5D,MAAMI,SAAS,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAE;QAC/CC,KAAK,EAAE,MAAM;QACbC,IAAI,EAAEN,QAAQ;QACdO,WAAW,EAAEN,aAAa,GAAG,MAAM,GAAG,QAAQ;QAC9CO,qBAAqB,EAAET,aAAa;KACrC,CAAC,AAAC;IACH,OAAOG,SAAS,CAACO,MAAM,CAACZ,KAAK,CAAC,CAAC;AACjC,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 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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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"}
@@ -11,8 +11,8 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG, formatBytes } from './bytes';
14
- import { DECIMAL_UNIT_CONFIG, formatDecimal, PERCENT_GROUP_CONFIG } from './decimal';
15
- import { DECIMAL_GROUP_CONFIG, formatPercent, PERCENT_UNIT_CONFIG } from './percent';
14
+ import { DECIMAL_UNIT_CONFIG, formatDecimal, DECIMAL_GROUP_CONFIG } from './decimal';
15
+ import { PERCENT_GROUP_CONFIG, formatPercent, PERCENT_UNIT_CONFIG } from './percent';
16
16
  import { formatTime, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';
17
17
  export const UNIT_GROUP_CONFIG = {
18
18
  Time: TIME_GROUP_CONFIG,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/units.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 { BytesUnitOptions, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG, formatBytes } from './bytes';\nimport { DecimalUnitOptions, DECIMAL_UNIT_CONFIG, formatDecimal, PERCENT_GROUP_CONFIG } from './decimal';\nimport { DECIMAL_GROUP_CONFIG, formatPercent, PercentUnitOptions, PERCENT_UNIT_CONFIG } from './percent';\nimport { formatTime, TimeUnitOptions, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\n\nexport const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>> = {\n Time: TIME_GROUP_CONFIG,\n Percent: PERCENT_GROUP_CONFIG,\n Decimal: DECIMAL_GROUP_CONFIG,\n Bytes: BYTES_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n} as const;\n\nexport type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;\n\ntype HasDecimalPlaces<UnitOpt> = UnitOpt extends { decimal_places?: number } ? UnitOpt : never;\ntype HasAbbreviate<UnitOpt> = UnitOpt extends { abbreviate?: boolean } ? UnitOpt : never;\n\nexport function formatValue(value: number, unitOptions?: UnitOptions): string {\n if (unitOptions === undefined) {\n return value.toString();\n }\n\n if (isDecimalUnit(unitOptions)) {\n return formatDecimal(value, unitOptions);\n }\n\n if (isTimeUnit(unitOptions)) {\n return formatTime(value, unitOptions);\n }\n\n if (isPercentUnit(unitOptions)) {\n return formatPercent(value, unitOptions);\n }\n\n if (isBytesUnit(unitOptions)) {\n return formatBytes(value, unitOptions);\n }\n\n const exhaustive: never = unitOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n}\n\nexport function getUnitKindConfig(unitOptions: UnitOptions): UnitConfig {\n return UNIT_CONFIG[unitOptions.kind];\n}\n\nexport function getUnitGroup(unitOptions: UnitOptions): UnitGroup {\n return getUnitKindConfig(unitOptions).group;\n}\n\nexport function getUnitGroupConfig(unitOptions: UnitOptions): UnitGroupConfig {\n const unitConfig = getUnitKindConfig(unitOptions);\n return UNIT_GROUP_CONFIG[unitConfig.group];\n}\n\n// Type guards\nexport function isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions {\n return getUnitGroup(unitOptions) === 'Time';\n}\n\nexport function isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions {\n return getUnitGroup(unitOptions) === 'Percent';\n}\n\nexport function isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions {\n return getUnitGroup(unitOptions) === 'Decimal';\n}\n\nexport function isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions {\n return getUnitGroup(unitOptions) === 'Bytes';\n}\n\nexport function isUnitWithDecimalPlaces(unitOptions: UnitOptions): unitOptions is HasDecimalPlaces<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.decimal_places;\n}\n\nexport function isUnitWithAbbreviate(unitOptions: UnitOptions): unitOptions is HasAbbreviate<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.abbreviate;\n}\n"],"names":["BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatBytes","DECIMAL_UNIT_CONFIG","formatDecimal","PERCENT_GROUP_CONFIG","DECIMAL_GROUP_CONFIG","formatPercent","PERCENT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","UNIT_CONFIG","formatValue","value","unitOptions","undefined","toString","isDecimalUnit","isTimeUnit","isPercentUnit","isBytesUnit","exhaustive","Error","getUnitKindConfig","kind","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","decimal_places","isUnitWithAbbreviate","abbreviate"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2E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GAAGH,kBAAkB,CAACb,WAAW,CAAC,AAAC;IAEpD,OAAO,CAAC,CAACgB,WAAW,CAACG,UAAU,CAAC;AAClC,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/units.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 { BytesUnitOptions, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG, formatBytes } from './bytes';\nimport { DecimalUnitOptions, DECIMAL_UNIT_CONFIG, formatDecimal, DECIMAL_GROUP_CONFIG } from './decimal';\nimport { PERCENT_GROUP_CONFIG, formatPercent, PercentUnitOptions, PERCENT_UNIT_CONFIG } from './percent';\nimport { formatTime, TimeUnitOptions, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';\nimport { UnitGroup, UnitGroupConfig, UnitConfig } from './types';\n\nexport const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>> = {\n Time: TIME_GROUP_CONFIG,\n Percent: PERCENT_GROUP_CONFIG,\n Decimal: DECIMAL_GROUP_CONFIG,\n Bytes: BYTES_GROUP_CONFIG,\n};\nexport const UNIT_CONFIG = {\n ...TIME_UNIT_CONFIG,\n ...PERCENT_UNIT_CONFIG,\n ...DECIMAL_UNIT_CONFIG,\n ...BYTES_UNIT_CONFIG,\n} as const;\n\nexport type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;\n\ntype HasDecimalPlaces<UnitOpt> = UnitOpt extends { decimal_places?: number } ? UnitOpt : never;\ntype HasAbbreviate<UnitOpt> = UnitOpt extends { abbreviate?: boolean } ? UnitOpt : never;\n\nexport function formatValue(value: number, unitOptions?: UnitOptions): string {\n if (unitOptions === undefined) {\n return value.toString();\n }\n\n if (isDecimalUnit(unitOptions)) {\n return formatDecimal(value, unitOptions);\n }\n\n if (isTimeUnit(unitOptions)) {\n return formatTime(value, unitOptions);\n }\n\n if (isPercentUnit(unitOptions)) {\n return formatPercent(value, unitOptions);\n }\n\n if (isBytesUnit(unitOptions)) {\n return formatBytes(value, unitOptions);\n }\n\n const exhaustive: never = unitOptions;\n throw new Error(`Unknown unit options ${exhaustive}`);\n}\n\nexport function getUnitKindConfig(unitOptions: UnitOptions): UnitConfig {\n return UNIT_CONFIG[unitOptions.kind];\n}\n\nexport function getUnitGroup(unitOptions: UnitOptions): UnitGroup {\n return getUnitKindConfig(unitOptions).group;\n}\n\nexport function getUnitGroupConfig(unitOptions: UnitOptions): UnitGroupConfig {\n const unitConfig = getUnitKindConfig(unitOptions);\n return UNIT_GROUP_CONFIG[unitConfig.group];\n}\n\n// Type guards\nexport function isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions {\n return getUnitGroup(unitOptions) === 'Time';\n}\n\nexport function isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions {\n return getUnitGroup(unitOptions) === 'Percent';\n}\n\nexport function isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions {\n return getUnitGroup(unitOptions) === 'Decimal';\n}\n\nexport function isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions {\n return getUnitGroup(unitOptions) === 'Bytes';\n}\n\nexport function isUnitWithDecimalPlaces(unitOptions: UnitOptions): unitOptions is HasDecimalPlaces<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.decimal_places;\n}\n\nexport function isUnitWithAbbreviate(unitOptions: UnitOptions): unitOptions is HasAbbreviate<UnitOptions> {\n const groupConfig = getUnitGroupConfig(unitOptions);\n\n return !!groupConfig.abbreviate;\n}\n"],"names":["BYTES_GROUP_CONFIG","BYTES_UNIT_CONFIG","formatBytes","DECIMAL_UNIT_CONFIG","formatDecimal","DECIMAL_GROUP_CONFIG","PERCENT_GROUP_CONFIG","formatPercent","PERCENT_UNIT_CONFIG","formatTime","TIME_GROUP_CONFIG","TIME_UNIT_CONFIG","UNIT_GROUP_CONFIG","Time","Percent","Decimal","Bytes","UNIT_CONFIG","formatValue","value","unitOptions","undefined","toString","isDecimalUnit","isTimeUnit","isPercentUnit","isBytesUnit","exhaustive","Error","getUnitKindConfig","kind","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","decimal_places","isUnitWithAbbreviate","abbreviate"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAA2BA,kBAAkB,EAAEC,iBAAiB,EAAEC,WAAW,QAAQ,SAAS,CAAC;AAC/F,SAA6BC,mBAAmB,EAAEC,aAAa,EAAEC,oBAAoB,QAAQ,WAAW,CAAC;AACzG,SAASC,oBAAoB,EAAEC,aAAa,EAAsBC,mBAAmB,QAAQ,WAAW,CAAC;AACzG,SAASC,UAAU,EAAmBC,iBAAiB,EAAEC,gBAAgB,QAAQ,QAAQ,CAAC;AAG1F,OAAO,MAAMC,iBAAiB,GAAiD;IAC7EC,IAAI,EAAEH,iBAAiB;IACvBI,OAAO,EAAER,oBAAoB;IAC7BS,OAAO,EAAEV,oBAAoB;IAC7BW,KAAK,EAAEhB,kBAAkB;CAC1B,CAAC;AACF,OAAO,MAAMiB,WAAW,GAAG;IACzB,GAAGN,gBAAgB;IACnB,GAAGH,mBAAmB;IACtB,GAAGL,mBAAmB;IACtB,GAAGF,iBAAiB;CACrB,AAAS,CAAC;AAOX,OAAO,SAASiB,WAAW,CAACC,KAAa,EAAEC,WAAyB,E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,aAAa,CAACL,WAAwB,EAAqC;IACzF,OAAOW,YAAY,CAACX,WAAW,CAAC,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,OAAO,SAASG,aAAa,CAACH,WAAwB,EAAqC;IACzF,OAAOW,YAAY,CAACX,WAAW,CAAC,KAAK,SAAS,CAAC;AACjD,CAAC;AAED,OAAO,SAASM,WAAW,CAACN,WAAwB,EAAmC;IACrF,OAAOW,YAAY,CAACX,WAAW,CAAC,KAAK,OAAO,CAAC;AAC/C,CAAC;AAED,OAAO,SAASe,uBAAuB,CAACf,WAAwB,EAAgD;IAC9G,MAAMgB,WAAW,GAAGH,kBAAkB,CAACb,WAAW,CAAC,AAAC;IAEpD,OAAO,CAAC,CAACgB,WAAW,CAACC,cAAc,CAAC;AACtC,CAAC;AAED,OAAO,SAASC,oBAAoB,CAAClB,WAAwB,EAA6C;IACxG,MAAMgB,WAAW,GAAGH,kBAAkB,CAACb,WAAW,CAAC,AAAC;IAEpD,OAAO,CAAC,CAACgB,WAAW,CAACG,UAAU,CAAC;AAClC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function shouldAbbreviate(abbreviate?: boolean): boolean;
2
+ export declare function hasDecimalPlaces(decimal_places?: number): boolean;
3
+ export declare function limitDecimalPlaces(num?: number): number | undefined;
4
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/model/units/utils.ts"],"names":[],"mappings":"AAaA,wBAAgB,gBAAgB,CAAC,UAAU,CAAC,EAAE,OAAO,WAEpD;AAED,wBAAgB,gBAAgB,CAAC,cAAc,CAAC,EAAE,MAAM,WAEvD;AAKD,wBAAgB,kBAAkB,CAAC,GAAG,CAAC,EAAE,MAAM,sBAU9C"}
@@ -0,0 +1,32 @@
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
+ export function shouldAbbreviate(abbreviate) {
14
+ return abbreviate !== false;
15
+ }
16
+ export function hasDecimalPlaces(decimal_places) {
17
+ return typeof decimal_places === 'number';
18
+ }
19
+ // Avoids maximumFractionDigits out-of-range error.
20
+ // Allowed values are 0 to 20.
21
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumfractiondigits
22
+ export function limitDecimalPlaces(num) {
23
+ if (!num) return num;
24
+ if (num < 0) {
25
+ num = 0;
26
+ } else if (num > 20) {
27
+ num = 20;
28
+ }
29
+ return num;
30
+ }
31
+
32
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/utils.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 function shouldAbbreviate(abbreviate?: boolean) {\n return abbreviate !== false;\n}\n\nexport function hasDecimalPlaces(decimal_places?: number) {\n return typeof decimal_places === 'number';\n}\n\n// Avoids maximumFractionDigits out-of-range error.\n// Allowed values are 0 to 20.\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#maximumfractiondigits\nexport function limitDecimalPlaces(num?: number) {\n if (!num) return num;\n\n if (num < 0) {\n num = 0;\n } else if (num > 20) {\n num = 20;\n }\n\n return num;\n}\n"],"names":["shouldAbbreviate","abbreviate","hasDecimalPlaces","decimal_places","limitDecimalPlaces","num"],"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,OAAO,SAASA,gBAAgB,CAACC,UAAoB,EAAE;IACrD,OAAOA,UAAU,KAAK,KAAK,CAAC;AAC9B,CAAC;AAED,OAAO,SAASC,gBAAgB,CAACC,cAAuB,EAAE;IACxD,OAAO,OAAOA,cAAc,KAAK,QAAQ,CAAC;AAC5C,CAAC;AAED,mDAAmD;AACnD,8BAA8B;AAC9B,wIAAwI;AACxI,OAAO,SAASC,kBAAkB,CAACC,GAAY,EAAE;IAC/C,IAAI,CAACA,GAAG,EAAE,OAAOA,GAAG,CAAC;IAErB,IAAIA,GAAG,GAAG,CAAC,EAAE;QACXA,GAAG,GAAG,CAAC,CAAC;IACV,OAAO,IAAIA,GAAG,GAAG,EAAE,EAAE;QACnBA,GAAG,GAAG,EAAE,CAAC;IACX,CAAC;IAED,OAAOA,GAAG,CAAC;AACb,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"grey.d.ts","sourceRoot":"","sources":["../../../src/theme/palette/grey.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5D,eAAO,MAAM,UAAU,SAAU,WAAW,KAAG,cAAc,CAAC,MAAM,CAyBnE,CAAC"}
1
+ {"version":3,"file":"grey.d.ts","sourceRoot":"","sources":["../../../src/theme/palette/grey.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5D,eAAO,MAAM,UAAU,SAAU,WAAW,KAAG,cAAc,CAAC,MAAM,CA6BnE,CAAC"}
@@ -13,6 +13,7 @@
13
13
  import { grey } from './colors/grey';
14
14
  export const greyOption = (mode)=>{
15
15
  return mode === 'light' ? {
16
+ 50: grey[50],
16
17
  100: grey[100],
17
18
  200: grey[200],
18
19
  300: grey[300],
@@ -21,8 +22,10 @@ export const greyOption = (mode)=>{
21
22
  600: grey[600],
22
23
  700: grey[700],
23
24
  800: grey[800],
24
- 900: grey[900]
25
+ 900: grey[900],
26
+ 950: grey[950]
25
27
  } : {
28
+ 50: grey[950],
26
29
  100: grey[900],
27
30
  200: grey[800],
28
31
  300: grey[700],
@@ -31,7 +34,8 @@ export const greyOption = (mode)=>{
31
34
  600: grey[400],
32
35
  700: grey[300],
33
36
  800: grey[200],
34
- 900: grey[100]
37
+ 900: grey[100],
38
+ 950: grey[50]
35
39
  };
36
40
  };
37
41