@perses-dev/components 0.15.0 → 0.17.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 (138) hide show
  1. package/dist/LineChart/LineChart.d.ts +3 -2
  2. package/dist/LineChart/LineChart.d.ts.map +1 -1
  3. package/dist/LineChart/LineChart.js +6 -16
  4. package/dist/LineChart/LineChart.js.map +1 -1
  5. package/dist/LineChart/utils.d.ts +18 -0
  6. package/dist/LineChart/utils.d.ts.map +1 -1
  7. package/dist/LineChart/utils.js +35 -9
  8. package/dist/LineChart/utils.js.map +1 -1
  9. package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts +13 -0
  10. package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts.map +1 -0
  11. package/dist/OptionsEditorLayout/OptionsEditorColumn.js +28 -0
  12. package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -0
  13. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +5 -0
  14. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -0
  15. package/dist/OptionsEditorLayout/OptionsEditorControl.js +50 -0
  16. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -0
  17. package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts +13 -0
  18. package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts.map +1 -0
  19. package/dist/OptionsEditorLayout/OptionsEditorGrid.js +26 -0
  20. package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -0
  21. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +13 -0
  22. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -0
  23. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +36 -0
  24. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -0
  25. package/dist/OptionsEditorLayout/index.d.ts +5 -0
  26. package/dist/OptionsEditorLayout/index.d.ts.map +1 -0
  27. package/dist/OptionsEditorLayout/index.js +18 -0
  28. package/dist/OptionsEditorLayout/index.js.map +1 -0
  29. package/dist/Tooltip/SeriesInfo.d.ts +1 -0
  30. package/dist/Tooltip/SeriesInfo.d.ts.map +1 -1
  31. package/dist/Tooltip/SeriesInfo.js +3 -3
  32. package/dist/Tooltip/SeriesInfo.js.map +1 -1
  33. package/dist/Tooltip/Tooltip.d.ts +2 -1
  34. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  35. package/dist/Tooltip/Tooltip.js +2 -2
  36. package/dist/Tooltip/Tooltip.js.map +1 -1
  37. package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
  38. package/dist/Tooltip/TooltipContent.js +2 -1
  39. package/dist/Tooltip/TooltipContent.js.map +1 -1
  40. package/dist/Tooltip/focused-series.d.ts +4 -3
  41. package/dist/Tooltip/focused-series.d.ts.map +1 -1
  42. package/dist/Tooltip/focused-series.js +6 -3
  43. package/dist/Tooltip/focused-series.js.map +1 -1
  44. package/dist/Tooltip/focused-series.test.js +20 -2
  45. package/dist/Tooltip/focused-series.test.js.map +1 -1
  46. package/dist/UnitSelector/UnitSelector.d.ts +8 -0
  47. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -0
  48. package/dist/UnitSelector/UnitSelector.js +112 -0
  49. package/dist/UnitSelector/UnitSelector.js.map +1 -0
  50. package/dist/UnitSelector/UnitSelector.test.d.ts +2 -0
  51. package/dist/UnitSelector/UnitSelector.test.d.ts.map +1 -0
  52. package/dist/UnitSelector/UnitSelector.test.js +211 -0
  53. package/dist/UnitSelector/UnitSelector.test.js.map +1 -0
  54. package/dist/UnitSelector/index.d.ts +2 -0
  55. package/dist/UnitSelector/index.d.ts.map +1 -0
  56. package/dist/UnitSelector/index.js +15 -0
  57. package/dist/UnitSelector/index.js.map +1 -0
  58. package/dist/YAxisLabel.d.ts +8 -0
  59. package/dist/YAxisLabel.d.ts.map +1 -0
  60. package/dist/YAxisLabel.js +39 -0
  61. package/dist/YAxisLabel.js.map +1 -0
  62. package/dist/cjs/LineChart/LineChart.js +5 -15
  63. package/dist/cjs/LineChart/utils.js +23 -1
  64. package/dist/cjs/OptionsEditorLayout/OptionsEditorColumn.js +32 -0
  65. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +61 -0
  66. package/dist/cjs/OptionsEditorLayout/OptionsEditorGrid.js +29 -0
  67. package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +40 -0
  68. package/dist/cjs/OptionsEditorLayout/index.js +31 -0
  69. package/dist/cjs/Tooltip/SeriesInfo.js +3 -3
  70. package/dist/cjs/Tooltip/Tooltip.js +2 -2
  71. package/dist/cjs/Tooltip/TooltipContent.js +2 -1
  72. package/dist/cjs/Tooltip/focused-series.js +6 -3
  73. package/dist/cjs/Tooltip/focused-series.test.js +20 -2
  74. package/dist/cjs/UnitSelector/UnitSelector.js +118 -0
  75. package/dist/cjs/UnitSelector/UnitSelector.test.js +218 -0
  76. package/dist/cjs/UnitSelector/index.js +28 -0
  77. package/dist/cjs/YAxisLabel.js +45 -0
  78. package/dist/cjs/index.js +5 -2
  79. package/dist/cjs/model/units/bytes.js +60 -0
  80. package/dist/cjs/model/units/constants.js +23 -0
  81. package/dist/cjs/model/units/decimal.js +67 -0
  82. package/dist/cjs/model/units/index.js +30 -0
  83. package/dist/cjs/model/units/percent.js +64 -0
  84. package/dist/cjs/model/units/time.js +138 -0
  85. package/dist/cjs/model/units/types.js +28 -0
  86. package/dist/cjs/model/units/units.js +104 -0
  87. package/dist/cjs/utils/component-ids.js +31 -0
  88. package/dist/cjs/utils/index.js +1 -0
  89. package/dist/index.d.ts +5 -2
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +5 -2
  92. package/dist/index.js.map +1 -1
  93. package/dist/model/units/bytes.d.ts +12 -0
  94. package/dist/model/units/bytes.d.ts.map +1 -0
  95. package/dist/model/units/bytes.js +48 -0
  96. package/dist/model/units/bytes.js.map +1 -0
  97. package/dist/model/units/constants.d.ts +2 -0
  98. package/dist/model/units/constants.d.ts.map +1 -0
  99. package/dist/model/units/constants.js +17 -0
  100. package/dist/model/units/constants.js.map +1 -0
  101. package/dist/model/units/decimal.d.ts +24 -0
  102. package/dist/model/units/decimal.d.ts.map +1 -0
  103. package/dist/model/units/decimal.js +59 -0
  104. package/dist/model/units/decimal.js.map +1 -0
  105. package/dist/model/units/index.d.ts +4 -0
  106. package/dist/model/units/index.d.ts.map +1 -0
  107. package/dist/model/units/index.js +17 -0
  108. package/dist/model/units/index.js.map +1 -0
  109. package/dist/model/units/percent.d.ts +12 -0
  110. package/dist/model/units/percent.d.ts.map +1 -0
  111. package/dist/model/units/percent.js +51 -0
  112. package/dist/model/units/percent.js.map +1 -0
  113. package/dist/model/units/time.d.ts +11 -0
  114. package/dist/model/units/time.d.ts.map +1 -0
  115. package/dist/model/units/time.js +125 -0
  116. package/dist/model/units/time.js.map +1 -0
  117. package/dist/model/units/types.d.ts +38 -0
  118. package/dist/model/units/types.d.ts.map +1 -0
  119. package/dist/model/units/types.js +22 -0
  120. package/dist/model/units/types.js.map +1 -0
  121. package/dist/model/units/units.d.ts +40 -0
  122. package/dist/model/units/units.d.ts.map +1 -0
  123. package/dist/model/units/units.js +83 -0
  124. package/dist/model/units/units.js.map +1 -0
  125. package/dist/utils/component-ids.d.ts +8 -0
  126. package/dist/utils/component-ids.d.ts.map +1 -0
  127. package/dist/utils/component-ids.js +27 -0
  128. package/dist/utils/component-ids.js.map +1 -0
  129. package/dist/utils/index.d.ts +1 -0
  130. package/dist/utils/index.d.ts.map +1 -1
  131. package/dist/utils/index.js +1 -0
  132. package/dist/utils/index.js.map +1 -1
  133. package/package.json +2 -2
  134. package/dist/cjs/model/units.js +0 -203
  135. package/dist/model/units.d.ts +0 -36
  136. package/dist/model/units.d.ts.map +0 -1
  137. package/dist/model/units.js +0 -196
  138. package/dist/model/units.js.map +0 -1
@@ -0,0 +1,24 @@
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 PERCENT_GROUP_CONFIG: UnitGroupConfig;
10
+ export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>>;
11
+ export declare function formatDecimal(value: number, unitOptions: DecimalUnitOptions): string;
12
+ /**
13
+ * Takes large numbers and abbreviates them with the appropriate suffix
14
+ * 10123 -> 10.123k
15
+ * 1000000 -> 1M
16
+ */
17
+ export declare function abbreviateLargeNumber(num: number, decimals?: number): string;
18
+ /**
19
+ * Takes large numbers, rounds and abbreviates them with the appropriate suffix
20
+ * Add modifier to run on output value prior to unit being added (defaults to rounding)
21
+ */
22
+ export declare function formatNumber(num: number, modifier?: (n: number) => number): string;
23
+ export {};
24
+ //# sourceMappingURL=decimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACvD,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,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAepF;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAI,UAG9D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAYlF"}
@@ -0,0 +1,59 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { round } from '../../utils/mathjs';
14
+ import { DEFAULT_DECIMAL_PLACES } from './constants';
15
+ const decimalUnitKinds = [
16
+ 'Decimal'
17
+ ];
18
+ export const PERCENT_GROUP_CONFIG = {
19
+ label: 'Percent',
20
+ decimal_places: true
21
+ };
22
+ export const DECIMAL_UNIT_CONFIG = {
23
+ Decimal: {
24
+ group: 'Decimal',
25
+ label: 'Decimal'
26
+ }
27
+ };
28
+ export function formatDecimal(value, unitOptions) {
29
+ var _decimal_places;
30
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
31
+ if (unitOptions.abbreviate === true) {
32
+ return abbreviateLargeNumber(value, decimals);
33
+ }
34
+ const formatParams = {
35
+ style: 'decimal',
36
+ minimumFractionDigits: decimals,
37
+ maximumFractionDigits: decimals,
38
+ useGrouping: true
39
+ };
40
+ const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);
41
+ return decimalFormatter.format(value);
42
+ }
43
+ /**
44
+ * Takes large numbers and abbreviates them with the appropriate suffix
45
+ * 10123 -> 10.123k
46
+ * 1000000 -> 1M
47
+ */ export function abbreviateLargeNumber(num, decimals = 2) {
48
+ const modifier = (n)=>round(n, decimals);
49
+ return formatNumber(num, modifier);
50
+ }
51
+ /**
52
+ * Takes large numbers, rounds and abbreviates them with the appropriate suffix
53
+ * Add modifier to run on output value prior to unit being added (defaults to rounding)
54
+ */ export function formatNumber(num, modifier) {
55
+ const fn = modifier !== null && modifier !== void 0 ? modifier : Math.round;
56
+ return num >= 1e12 ? fn(num / 1e12) + 'T' : num >= 1e9 ? fn(num / 1e9) + 'B' : num >= 1e6 ? fn(num / 1e6) + 'M' : num >= 1e3 ? fn(num / 1e3) + 'K' : num.toString();
57
+ }
58
+
59
+ //# sourceMappingURL=decimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { round } from '../../utils/mathjs';\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, unitOptions: DecimalUnitOptions): string {\n const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n if (unitOptions.abbreviate === true) {\n return abbreviateLargeNumber(value, decimals);\n }\n\n const formatParams: Intl.NumberFormatOptions = {\n style: 'decimal',\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals,\n useGrouping: true,\n };\n const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);\n return decimalFormatter.format(value);\n}\n\n/**\n * Takes large numbers and abbreviates them with the appropriate suffix\n * 10123 -> 10.123k\n * 1000000 -> 1M\n */\nexport function abbreviateLargeNumber(num: number, decimals = 2) {\n const modifier = (n: number) => round(n, decimals);\n return formatNumber(num, modifier);\n}\n\n/**\n * Takes large numbers, rounds and abbreviates them with the appropriate suffix\n * Add modifier to run on output value prior to unit being added (defaults to rounding)\n */\nexport function formatNumber(num: number, modifier?: (n: number) => number): string {\n const fn = modifier ?? Math.round;\n\n return num >= 1e12\n ? fn(num / 1e12) + 'T'\n : num >= 1e9\n ? fn(num / 1e9) + 'B'\n : num >= 1e6\n ? fn(num / 1e6) + 'M'\n : num >= 1e3\n ? fn(num / 1e3) + 'K'\n : num.toString();\n}\n"],"names":["round","DEFAULT_DECIMAL_PLACES","decimalUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","unitOptions","decimals","abbreviate","abbreviateLargeNumber","formatParams","style","minimumFractionDigits","maximumFractionDigits","useGrouping","decimalFormatter","Intl","NumberFormat","format","num","modifier","n","formatNumber","fn","Math","toString"],"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,KAAK,QAAQ,oBAAoB,CAAC;AAC3C,SAASC,sBAAsB,QAAQ,aAAa,CAAC;AAGrD,MAAMC,gB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H,QAAQ,aAARA,QAAQ,cAARA,QAAQ,GAAII,IAAI,CAAC7B,KAAK,AAAC;IAElC,OAAOwB,GAAG,IAAI,IAAI,GACdI,EAAE,CAACJ,GAAG,GAAG,IAAI,CAAC,GAAG,GAAG,GACpBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,IAAI,GAAG,GACVI,EAAE,CAACJ,GAAG,GAAG,GAAG,CAAC,GAAG,GAAG,GACnBA,GAAG,CAACM,QAAQ,EAAE,CAAC;AACrB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './units';
2
+ export * from './constants';
3
+ export * from './types';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,17 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './units';
14
+ export * from './constants';
15
+ export * from './types';
16
+
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './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"}
@@ -0,0 +1,12 @@
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 DECIMAL_GROUP_CONFIG: UnitGroupConfig;
9
+ export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>>;
10
+ export declare function formatPercent(value: number, unitOptions: PercentUnitOptions): string;
11
+ export {};
12
+ //# sourceMappingURL=percent.d.ts.map
@@ -0,0 +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;AAGtD,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AACrE,aAAK,eAAe,GAAG,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACvD,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;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAQpF"}
@@ -0,0 +1,51 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { DEFAULT_DECIMAL_PLACES } from './constants';
14
+ const percentUnitKinds = [
15
+ 'Percent',
16
+ 'PercentDecimal',
17
+ '%'
18
+ ];
19
+ export const DECIMAL_GROUP_CONFIG = {
20
+ label: 'Decimal',
21
+ decimal_places: true,
22
+ abbreviate: 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, unitOptions) {
43
+ var _decimal_places;
44
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
45
+ if (unitOptions.kind === 'PercentDecimal') {
46
+ value = value * 100;
47
+ }
48
+ return value.toFixed(decimals) + '%';
49
+ }
50
+
51
+ //# sourceMappingURL=percent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { DEFAULT_DECIMAL_PLACES } from './constants';\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\nexport function formatPercent(value: number, unitOptions: PercentUnitOptions): string {\n const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n\n if (unitOptions.kind === 'PercentDecimal') {\n value = value * 100;\n }\n\n return value.toFixed(decimals) + '%';\n}\n"],"names":["DEFAULT_DECIMAL_PLACES","percentUnitKinds","DECIMAL_GROUP_CONFIG","label","decimal_places","abbreviate","PERCENT_GROUP","PERCENT_UNIT_CONFIG","Percent","group","PercentDecimal","disableSelectorOption","formatPercent","value","unitOptions","decimals","kind","toFixed"],"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;AAGjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAErD,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;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,MAAMC,aAAa,GAAG,SAAS,AAAC;AAChC,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAEH,aAAa;QACpBH,KAAK,EAAE,iBAAiB;KACzB;IACDO,cAAc,EAAE;QACdD,KAAK,EAAEH,aAAa;QACpBH,KAAK,EAAE,mBAAmB;KAC3B;IACD,GAAG,EAAE;QACH,qEAAqE;QACrE,0BAA0B;QAC1BQ,qBAAqB,EAAE,IAAI;QAC3BF,KAAK,EAAEH,aAAa;QACpBH,KAAK,EAAE,GAAG;KACX;CACF,CAAC;AAEF,OAAO,SAASS,aAAa,CAACC,KAAa,EAAEC,WAA+B,EAAU;QACnEA,eAA0B;IAA3C,MAAMC,QAAQ,GAAGD,CAAAA,eAA0B,GAA1BA,WAAW,CAACV,cAAc,cAA1BU,eAA0B,cAA1BA,eAA0B,GAAId,sBAAsB,AAAC;IAEtE,IAAIc,WAAW,CAACE,IAAI,KAAK,gBAAgB,EAAE;QACzCH,KAAK,GAAGA,KAAK,GAAG,GAAG,CAAC;IACtB,CAAC;IAED,OAAOA,KAAK,CAACI,OAAO,CAACF,QAAQ,CAAC,GAAG,GAAG,CAAC;AACvC,CAAC"}
@@ -0,0 +1,11 @@
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
+ };
7
+ export declare const TIME_GROUP_CONFIG: UnitGroupConfig;
8
+ export declare const TIME_UNIT_CONFIG: Readonly<Record<TimeUnitKind, UnitConfig>>;
9
+ export declare function formatTime(value: number, unitOptions: TimeUnitOptions): string;
10
+ export {};
11
+ //# sourceMappingURL=time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/units/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AACnH,aAAK,YAAY,GAAG,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;AACjD,oBAAY,eAAe,GAAG;IAC5B,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,eAE/B,CAAC;AACF,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAiCvE,CAAC;AAEF,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,GAAG,MAAM,CAmE9E"}
@@ -0,0 +1,125 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { milliseconds } from 'date-fns';
14
+ const timeUnitKinds = [
15
+ 'Milliseconds',
16
+ 'Seconds',
17
+ 'Minutes',
18
+ 'Hours',
19
+ 'Days',
20
+ 'Weeks',
21
+ 'Months',
22
+ 'Years'
23
+ ];
24
+ const TIME_GROUP = 'Time';
25
+ export const TIME_GROUP_CONFIG = {
26
+ label: 'Time'
27
+ };
28
+ export const TIME_UNIT_CONFIG = {
29
+ Milliseconds: {
30
+ group: TIME_GROUP,
31
+ label: 'Milliseconds'
32
+ },
33
+ Seconds: {
34
+ group: TIME_GROUP,
35
+ label: 'Seconds'
36
+ },
37
+ Minutes: {
38
+ group: TIME_GROUP,
39
+ label: 'Minutes'
40
+ },
41
+ Hours: {
42
+ group: TIME_GROUP,
43
+ label: 'Hours'
44
+ },
45
+ Days: {
46
+ group: TIME_GROUP,
47
+ label: 'Days'
48
+ },
49
+ Weeks: {
50
+ group: TIME_GROUP,
51
+ label: 'Weeks'
52
+ },
53
+ Months: {
54
+ group: TIME_GROUP,
55
+ label: 'Months'
56
+ },
57
+ Years: {
58
+ group: TIME_GROUP,
59
+ label: 'Years'
60
+ }
61
+ };
62
+ export function formatTime(value, unitOptions) {
63
+ // Create a Duration from the value based on what time unit it is
64
+ const duration = {};
65
+ switch(unitOptions.kind){
66
+ case 'Milliseconds':
67
+ duration.seconds = value / 1000;
68
+ break;
69
+ case 'Seconds':
70
+ duration.seconds = value;
71
+ break;
72
+ case 'Minutes':
73
+ duration.minutes = value;
74
+ break;
75
+ case 'Hours':
76
+ duration.hours = value;
77
+ break;
78
+ case 'Days':
79
+ duration.days = value;
80
+ break;
81
+ case 'Weeks':
82
+ duration.weeks = value;
83
+ break;
84
+ case 'Months':
85
+ duration.months = value;
86
+ break;
87
+ case 'Years':
88
+ duration.years = value;
89
+ break;
90
+ default:
91
+ {
92
+ const exhaustive = unitOptions.kind;
93
+ throw new Error(`Unknown time unit type ${exhaustive}`);
94
+ }
95
+ }
96
+ // Find the largest whole time unit we can display the value in and use it
97
+ const ms = milliseconds(duration);
98
+ const seconds = ms / 1000;
99
+ if (seconds < 1) {
100
+ return `${ms.toFixed()} milliseconds`;
101
+ }
102
+ const minutes = seconds / 60;
103
+ if (minutes < 1) {
104
+ return `${seconds.toFixed()} seconds`;
105
+ }
106
+ const hours = minutes / 60;
107
+ if (hours < 1) {
108
+ return `${minutes.toFixed()} minutes`;
109
+ }
110
+ const days = hours / 24;
111
+ if (days < 1) {
112
+ return `${hours.toFixed()} hours`;
113
+ }
114
+ const weeks = days / 7;
115
+ if (weeks < 1) {
116
+ return `${days.toFixed()} days`;
117
+ }
118
+ const years = weeks / 52;
119
+ if (years < 1) {
120
+ return `${weeks.toFixed()} weeks`;
121
+ }
122
+ return `${years.toFixed()} years`;
123
+ }
124
+
125
+ //# sourceMappingURL=time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/time.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Duration, milliseconds } from 'date-fns';\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};\nconst TIME_GROUP = 'Time';\nexport const TIME_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Time',\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\nexport function formatTime(value: number, unitOptions: TimeUnitOptions): string {\n // Create a Duration from the value based on what time unit it is\n const duration: Duration = {};\n switch (unitOptions.kind) {\n case 'Milliseconds':\n duration.seconds = value / 1000;\n break;\n case 'Seconds':\n duration.seconds = value;\n break;\n case 'Minutes':\n duration.minutes = value;\n break;\n case 'Hours':\n duration.hours = value;\n break;\n case 'Days':\n duration.days = value;\n break;\n case 'Weeks':\n duration.weeks = value;\n break;\n case 'Months':\n duration.months = value;\n break;\n case 'Years':\n duration.years = value;\n break;\n default: {\n const exhaustive: never = unitOptions.kind;\n throw new Error(`Unknown time unit type ${exhaustive}`);\n }\n }\n\n // Find the largest whole time unit we can display the value in and use it\n const ms = milliseconds(duration);\n const seconds = ms / 1000;\n if (seconds < 1) {\n return `${ms.toFixed()} milliseconds`;\n }\n\n const minutes = seconds / 60;\n if (minutes < 1) {\n return `${seconds.toFixed()} seconds`;\n }\n\n const hours = minutes / 60;\n if (hours < 1) {\n return `${minutes.toFixed()} minutes`;\n }\n\n const days = hours / 24;\n if (days < 1) {\n return `${hours.toFixed()} hours`;\n }\n\n const weeks = days / 7;\n if (weeks < 1) {\n return `${days.toFixed()} days`;\n }\n\n const years = weeks / 52;\n if (years < 1) {\n return `${weeks.toFixed()} weeks`;\n }\n\n return `${years.toFixed()} years`;\n}\n"],"names":["milliseconds","timeUnitKinds","TIME_GROUP","TIME_GROUP_CONFIG","label","TIME_UNIT_CONFIG","Milliseconds","group","Seconds","Minutes","Hours","Days","Weeks","Months","Years","formatTime","value","unitOptions","duration","kind","seconds","minutes","hours","days","weeks","months","years","exhaustive","Error","ms","toFixed"],"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,SAAmBA,YAAY,QAAQ,UAAU,CAAC;AAGlD,MAAMC,aAAa,GAAG;IAAC,cAAc;IAAE,SAAS;IAAE,SAAS;IAAE,OAAO;IAAE,MAAM;IAAE,OAAO;IAAE,QAAQ;IAAE,OAAO;CAAC,AAAS,AAAC;AAKnH,MAAMC,UAAU,GAAG,MAAM,AAAC;AAC1B,OAAO,MAAMC,iBAAiB,GAAoB;IAChDC,KAAK,EAAE,MAAM;CACd,CAAC;AACF,OAAO,MAAMC,gBAAgB,GAA+C;IAC1EC,YAAY,EAAE;QACZC,KAAK,EAAEL,UAAU;QACjBE,KAAK,EAAE,cAAc;KACtB;IACDI,OAAO,EAAE;QACPD,KAAK,EAAEL,UAAU;QACjBE,KAAK,EAAE,SAAS;KACjB;IACDK,OAAO,EAAE;QACPF,KAAK,EAAEL,UAAU;QACjBE,KAAK,EAAE,SAAS;KACjB;IACDM,KAAK,EAAE;QACLH,KAAK,EAAEL,UAAU;QACjBE,KAAK,EAAE,OAAO;KACf;IACDO,IAAI,EAAE;QACJJ,KAAK,EAAEL,UAAU;QACjBE,KAAK,EAAE,MAAM;KACd;IACDQ,KAAK,EAAE;QACLL,KAAK,EAAEL,UAAU;QACjBE,KAAK,EAAE,OAAO;KACf;IACDS,MAAM,EAAE;QACNN,KAAK,EAAEL,UAAU;QACjBE,KAAK,EAAE,QAAQ;KAChB;I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C,CAAC;IAED,MAAMT,OAAO,GAAGD,OAAO,GAAG,EAAE,AAAC;IAC7B,IAAIC,OAAO,GAAG,CAAC,EAAE;QACf,OAAO,CAAC,EAAED,OAAO,CAACU,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,MAAMR,KAAK,GAAGD,OAAO,GAAG,EAAE,AAAC;IAC3B,IAAIC,KAAK,GAAG,CAAC,EAAE;QACb,OAAO,CAAC,EAAED,OAAO,CAACS,OAAO,EAAE,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,MAAMP,IAAI,GAAGD,KAAK,GAAG,EAAE,AAAC;IACxB,IAAIC,IAAI,GAAG,CAAC,EAAE;QACZ,OAAO,CAAC,EAAED,KAAK,CAACQ,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,MAAMN,KAAK,GAAGD,IAAI,GAAG,CAAC,AAAC;IACvB,IAAIC,KAAK,GAAG,CAAC,EAAE;QACb,OAAO,CAAC,EAAED,IAAI,CAACO,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,MAAMJ,KAAK,GAAGF,KAAK,GAAG,EAAE,AAAC;IACzB,IAAIE,KAAK,GAAG,CAAC,EAAE;QACb,OAAO,CAAC,EAAEF,KAAK,CAACM,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,CAAC,EAAEJ,KAAK,CAACI,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,38 @@
1
+ export declare const UNIT_GROUPS: readonly ["Time", "Percent", "Decimal", "Bytes"];
2
+ export declare type UnitGroup = typeof UNIT_GROUPS[number];
3
+ /**
4
+ * Configuration for rendering units that are part of a group.
5
+ */
6
+ export declare type UnitGroupConfig = {
7
+ /**
8
+ * The label that is shown in the UI.
9
+ */
10
+ label: string;
11
+ /**
12
+ * When true, the unit group supports setting decimal places.
13
+ */
14
+ decimal_places?: boolean;
15
+ /**
16
+ * When true, the unit group supports enabling abbreviate.
17
+ */
18
+ abbreviate?: boolean;
19
+ };
20
+ /**
21
+ * Configuration for rendering a specific unit.
22
+ */
23
+ export declare type UnitConfig = {
24
+ /**
25
+ * The group the unit is part of. This will inform common rendering behavior.
26
+ */
27
+ group: UnitGroup;
28
+ /**
29
+ * When true, this unit will not be displayed in the unit selector. This is
30
+ * useful for units that are shorthand variants of other units.
31
+ */
32
+ disableSelectorOption?: boolean;
33
+ /**
34
+ * The label that is shown in the UI.
35
+ */
36
+ label: string;
37
+ };
38
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/model/units/types.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,WAAW,kDAAmD,CAAC;AAC5E,oBAAY,SAAS,GAAG,OAAO,WAAW,CAAC,MAAM,CAAC,CAAC;AAEnD;;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"}
@@ -0,0 +1,22 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ // Common types needed across individual unit groups and the overall combined
14
+ // units.
15
+ export const UNIT_GROUPS = [
16
+ 'Time',
17
+ 'Percent',
18
+ 'Decimal',
19
+ 'Bytes'
20
+ ];
21
+
22
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/types.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common types needed across individual unit groups and the overall combined\n// 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"],"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;AAET,OAAO,MAAMA,WAAW,GAAG;IAAC,MAAM;IAAE,SAAS;IAAE,SAAS;IAAE,OAAO;CAAC,AAAS,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { BytesUnitOptions } from './bytes';
2
+ import { DecimalUnitOptions } from './decimal';
3
+ import { PercentUnitOptions } from './percent';
4
+ import { TimeUnitOptions } from './time';
5
+ import { UnitGroup, UnitGroupConfig, UnitConfig } from './types';
6
+ export declare const UNIT_GROUP_CONFIG: Readonly<Record<UnitGroup, UnitGroupConfig>>;
7
+ export declare const UNIT_CONFIG: {
8
+ readonly Bytes: UnitConfig;
9
+ readonly Decimal: UnitConfig;
10
+ readonly Percent: UnitConfig;
11
+ readonly PercentDecimal: UnitConfig;
12
+ readonly "%": UnitConfig;
13
+ readonly Milliseconds: UnitConfig;
14
+ readonly Seconds: UnitConfig;
15
+ readonly Minutes: UnitConfig;
16
+ readonly Hours: UnitConfig;
17
+ readonly Days: UnitConfig;
18
+ readonly Weeks: UnitConfig;
19
+ readonly Months: UnitConfig;
20
+ readonly Years: UnitConfig;
21
+ };
22
+ export declare type UnitOptions = TimeUnitOptions | PercentUnitOptions | DecimalUnitOptions | BytesUnitOptions;
23
+ declare type HasDecimalPlaces<UnitOpt> = UnitOpt extends {
24
+ decimal_places?: number;
25
+ } ? UnitOpt : never;
26
+ declare type HasAbbreviate<UnitOpt> = UnitOpt extends {
27
+ abbreviate?: boolean;
28
+ } ? UnitOpt : never;
29
+ export declare function formatValue(value: number, unitOptions?: UnitOptions): string;
30
+ export declare function getUnitKindConfig(unitOptions: UnitOptions): UnitConfig;
31
+ export declare function getUnitGroup(unitOptions: UnitOptions): UnitGroup;
32
+ export declare function getUnitGroupConfig(unitOptions: UnitOptions): UnitGroupConfig;
33
+ export declare function isTimeUnit(unitOptions: UnitOptions): unitOptions is TimeUnitOptions;
34
+ export declare function isPercentUnit(unitOptions: UnitOptions): unitOptions is PercentUnitOptions;
35
+ export declare function isDecimalUnit(unitOptions: UnitOptions): unitOptions is DecimalUnitOptions;
36
+ export declare function isBytesUnit(unitOptions: UnitOptions): unitOptions is BytesUnitOptions;
37
+ export declare function isUnitWithDecimalPlaces(unitOptions: UnitOptions): unitOptions is HasDecimalPlaces<UnitOptions>;
38
+ export declare function isUnitWithAbbreviate(unitOptions: UnitOptions): unitOptions is HasAbbreviate<UnitOptions>;
39
+ export {};
40
+ //# sourceMappingURL=units.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../../src/model/units/units.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAsD,MAAM,SAAS,CAAC;AAE/F,OAAO,EAAE,kBAAkB,EAA4D,MAAM,WAAW,CAAC;AACzG,OAAO,EAAuC,kBAAkB,EAAuB,MAAM,WAAW,CAAC;AACzG,OAAO,EAAc,eAAe,EAAuC,MAAM,QAAQ,CAAC;AAC1F,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEjE,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,CAAC,CAK1E,CAAC;AACF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CAKd,CAAC;AAEX,oBAAY,WAAW,GAAG,eAAe,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAEvG,aAAK,gBAAgB,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAC/F,aAAK,aAAa,CAAC,OAAO,IAAI,OAAO,SAAS;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,CAwB5E;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAEtE;AAED,wBAAgB,YAAY,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,CAEhE;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,eAAe,CAG5E;AAGD,wBAAgB,UAAU,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,eAAe,CAEnF;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,kBAAkB,CAEzF;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,kBAAkB,CAEzF;AAED,wBAAgB,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,gBAAgB,CAErF;AAED,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAI9G;AAED,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,IAAI,aAAa,CAAC,WAAW,CAAC,CAIxG"}
@@ -0,0 +1,83 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG, formatBytes } from './bytes';
14
+ import { DEFAULT_DECIMAL_PLACES } from './constants';
15
+ import { DECIMAL_UNIT_CONFIG, formatDecimal, PERCENT_GROUP_CONFIG } from './decimal';
16
+ import { DECIMAL_GROUP_CONFIG, formatPercent, PERCENT_UNIT_CONFIG } from './percent';
17
+ import { formatTime, TIME_GROUP_CONFIG, TIME_UNIT_CONFIG } from './time';
18
+ export const UNIT_GROUP_CONFIG = {
19
+ Time: TIME_GROUP_CONFIG,
20
+ Percent: PERCENT_GROUP_CONFIG,
21
+ Decimal: DECIMAL_GROUP_CONFIG,
22
+ Bytes: BYTES_GROUP_CONFIG
23
+ };
24
+ export const UNIT_CONFIG = {
25
+ ...TIME_UNIT_CONFIG,
26
+ ...PERCENT_UNIT_CONFIG,
27
+ ...DECIMAL_UNIT_CONFIG,
28
+ ...BYTES_UNIT_CONFIG
29
+ };
30
+ export function formatValue(value, unitOptions) {
31
+ if (unitOptions === undefined) {
32
+ return value.toString();
33
+ }
34
+ if (isDecimalUnit(unitOptions)) {
35
+ return formatDecimal(value, unitOptions);
36
+ }
37
+ if (isTimeUnit(unitOptions)) {
38
+ return formatTime(value, unitOptions);
39
+ }
40
+ if (isPercentUnit(unitOptions)) {
41
+ return formatPercent(value, unitOptions);
42
+ }
43
+ if (isBytesUnit(unitOptions)) {
44
+ var _decimal_places;
45
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
46
+ return formatBytes(value, decimals);
47
+ }
48
+ const exhaustive = unitOptions;
49
+ throw new Error(`Unknown unit options ${exhaustive}`);
50
+ }
51
+ export function getUnitKindConfig(unitOptions) {
52
+ return UNIT_CONFIG[unitOptions.kind];
53
+ }
54
+ export function getUnitGroup(unitOptions) {
55
+ return getUnitKindConfig(unitOptions).group;
56
+ }
57
+ export function getUnitGroupConfig(unitOptions) {
58
+ const unitConfig = getUnitKindConfig(unitOptions);
59
+ return UNIT_GROUP_CONFIG[unitConfig.group];
60
+ }
61
+ // Type guards
62
+ export function isTimeUnit(unitOptions) {
63
+ return getUnitGroup(unitOptions) === 'Time';
64
+ }
65
+ export function isPercentUnit(unitOptions) {
66
+ return getUnitGroup(unitOptions) === 'Percent';
67
+ }
68
+ export function isDecimalUnit(unitOptions) {
69
+ return getUnitGroup(unitOptions) === 'Decimal';
70
+ }
71
+ export function isBytesUnit(unitOptions) {
72
+ return getUnitGroup(unitOptions) === 'Bytes';
73
+ }
74
+ export function isUnitWithDecimalPlaces(unitOptions) {
75
+ const groupConfig = getUnitGroupConfig(unitOptions);
76
+ return !!groupConfig.decimal_places;
77
+ }
78
+ export function isUnitWithAbbreviate(unitOptions) {
79
+ const groupConfig = getUnitGroupConfig(unitOptions);
80
+ return !!groupConfig.abbreviate;
81
+ }
82
+
83
+ //# sourceMappingURL=units.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/units.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BytesUnitOptions, BYTES_GROUP_CONFIG, BYTES_UNIT_CONFIG, formatBytes } from './bytes';\nimport { DEFAULT_DECIMAL_PLACES } from './constants';\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 const decimals = unitOptions.decimal_places ?? DEFAULT_DECIMAL_PLACES;\n return formatBytes(value, decimals);\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","DEFAULT_DECIMAL_PLACES","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","decimals","decimal_places","exhaustive","Error","getUnitKindConfig","kind","getUnitGroup","group","getUnitGroupConfig","unitConfig","isUnitWithDecimalPlaces","groupConfig","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,SAASC,sBAAsB,QAAQ,aAAa,CAAC;AACrD,SAA6BC,mBAAmB,EAAEC,aAAa,EAAEC,oBAAoB,QAAQ,WAAW,CAAC;AACzG,SAASC,oBAAoB,EAAEC,aAAa,EAAsBC,m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CAAC;AAClC,CAAC"}
@@ -0,0 +1,8 @@
1
+ declare global {
2
+ var useIdValue: number;
3
+ }
4
+ /**
5
+ * Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.
6
+ */
7
+ export declare function useId(prefix: string): string;
8
+ //# sourceMappingURL=component-ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-ids.d.ts","sourceRoot":"","sources":["../../src/utils/component-ids.ts"],"names":[],"mappings":"AAeA,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,UAAU,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,UAUnC"}
@@ -0,0 +1,27 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { useRef } from 'react';
14
+ /**
15
+ * Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.
16
+ */ export function useId(prefix) {
17
+ if (globalThis.useIdValue === undefined) {
18
+ globalThis.useIdValue = 0;
19
+ }
20
+ const id = useRef(undefined);
21
+ if (id.current === undefined) {
22
+ id.current = `${prefix}-${globalThis.useIdValue++}`;
23
+ }
24
+ return id.current;
25
+ }
26
+
27
+ //# sourceMappingURL=component-ids.js.map