@perses-dev/components 0.14.0 → 0.16.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 (178) hide show
  1. package/dist/{TimeRangeSelector → DateTimeRangePicker}/AbsoluteTimePicker.d.ts +0 -0
  2. package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts.map +1 -0
  3. package/dist/{TimeRangeSelector → DateTimeRangePicker}/AbsoluteTimePicker.js +38 -33
  4. package/dist/DateTimeRangePicker/AbsoluteTimePicker.js.map +1 -0
  5. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +11 -0
  6. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -0
  7. package/dist/DateTimeRangePicker/DateTimeRangePicker.js +77 -0
  8. package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -0
  9. package/dist/{TimeRangeSelector → DateTimeRangePicker}/TimeRangeSelector.d.ts +0 -0
  10. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -0
  11. package/dist/{TimeRangeSelector → DateTimeRangePicker}/TimeRangeSelector.js +0 -0
  12. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -0
  13. package/dist/{TimeRangeSelector → DateTimeRangePicker}/index.d.ts +1 -0
  14. package/dist/DateTimeRangePicker/index.d.ts.map +1 -0
  15. package/dist/{TimeRangeSelector → DateTimeRangePicker}/index.js +1 -0
  16. package/dist/DateTimeRangePicker/index.js.map +1 -0
  17. package/dist/{TimeRangeSelector → DateTimeRangePicker}/utils.d.ts +0 -0
  18. package/dist/DateTimeRangePicker/utils.d.ts.map +1 -0
  19. package/dist/{TimeRangeSelector → DateTimeRangePicker}/utils.js +0 -0
  20. package/dist/DateTimeRangePicker/utils.js.map +1 -0
  21. package/dist/Legend/CompactLegend.d.ts +6 -1
  22. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  23. package/dist/Legend/CompactLegend.js +16 -7
  24. package/dist/Legend/CompactLegend.js.map +1 -1
  25. package/dist/Legend/Legend.d.ts.map +1 -1
  26. package/dist/Legend/Legend.js +4 -9
  27. package/dist/Legend/Legend.js.map +1 -1
  28. package/dist/Legend/ListLegend.d.ts +3 -0
  29. package/dist/Legend/ListLegend.d.ts.map +1 -1
  30. package/dist/Legend/ListLegend.js +18 -2
  31. package/dist/Legend/ListLegend.js.map +1 -1
  32. package/dist/Legend/ListLegendItem.d.ts +2 -1
  33. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  34. package/dist/Legend/ListLegendItem.js +11 -9
  35. package/dist/Legend/ListLegendItem.js.map +1 -1
  36. package/dist/LineChart/LineChart.js +2 -1
  37. package/dist/LineChart/LineChart.js.map +1 -1
  38. package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts +13 -0
  39. package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts.map +1 -0
  40. package/dist/OptionsEditorLayout/OptionsEditorColumn.js +28 -0
  41. package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -0
  42. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +5 -0
  43. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -0
  44. package/dist/OptionsEditorLayout/OptionsEditorControl.js +50 -0
  45. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -0
  46. package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts +13 -0
  47. package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts.map +1 -0
  48. package/dist/OptionsEditorLayout/OptionsEditorGrid.js +26 -0
  49. package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -0
  50. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +13 -0
  51. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -0
  52. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +36 -0
  53. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -0
  54. package/dist/OptionsEditorLayout/index.d.ts +5 -0
  55. package/dist/OptionsEditorLayout/index.d.ts.map +1 -0
  56. package/dist/OptionsEditorLayout/index.js +18 -0
  57. package/dist/OptionsEditorLayout/index.js.map +1 -0
  58. package/dist/Tooltip/SeriesInfo.d.ts +1 -0
  59. package/dist/Tooltip/SeriesInfo.d.ts.map +1 -1
  60. package/dist/Tooltip/SeriesInfo.js +3 -3
  61. package/dist/Tooltip/SeriesInfo.js.map +1 -1
  62. package/dist/Tooltip/Tooltip.d.ts +2 -1
  63. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  64. package/dist/Tooltip/Tooltip.js +2 -2
  65. package/dist/Tooltip/Tooltip.js.map +1 -1
  66. package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
  67. package/dist/Tooltip/TooltipContent.js +2 -1
  68. package/dist/Tooltip/TooltipContent.js.map +1 -1
  69. package/dist/Tooltip/focused-series.d.ts +4 -3
  70. package/dist/Tooltip/focused-series.d.ts.map +1 -1
  71. package/dist/Tooltip/focused-series.js +6 -3
  72. package/dist/Tooltip/focused-series.js.map +1 -1
  73. package/dist/Tooltip/focused-series.test.js +20 -2
  74. package/dist/Tooltip/focused-series.test.js.map +1 -1
  75. package/dist/UnitSelector/UnitSelector.d.ts +8 -0
  76. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -0
  77. package/dist/UnitSelector/UnitSelector.js +112 -0
  78. package/dist/UnitSelector/UnitSelector.js.map +1 -0
  79. package/dist/UnitSelector/UnitSelector.test.d.ts +2 -0
  80. package/dist/UnitSelector/UnitSelector.test.d.ts.map +1 -0
  81. package/dist/UnitSelector/UnitSelector.test.js +211 -0
  82. package/dist/UnitSelector/UnitSelector.test.js.map +1 -0
  83. package/dist/UnitSelector/index.d.ts +2 -0
  84. package/dist/UnitSelector/index.d.ts.map +1 -0
  85. package/dist/UnitSelector/index.js +15 -0
  86. package/dist/UnitSelector/index.js.map +1 -0
  87. package/dist/cjs/{TimeRangeSelector → DateTimeRangePicker}/AbsoluteTimePicker.js +37 -32
  88. package/dist/cjs/DateTimeRangePicker/DateTimeRangePicker.js +83 -0
  89. package/dist/cjs/{TimeRangeSelector → DateTimeRangePicker}/TimeRangeSelector.js +0 -0
  90. package/dist/cjs/{TimeRangeSelector → DateTimeRangePicker}/index.js +1 -0
  91. package/dist/cjs/{TimeRangeSelector → DateTimeRangePicker}/utils.js +0 -0
  92. package/dist/cjs/Legend/CompactLegend.js +12 -6
  93. package/dist/cjs/Legend/Legend.js +4 -9
  94. package/dist/cjs/Legend/ListLegend.js +15 -1
  95. package/dist/cjs/Legend/ListLegendItem.js +48 -13
  96. package/dist/cjs/LineChart/LineChart.js +2 -1
  97. package/dist/cjs/OptionsEditorLayout/OptionsEditorColumn.js +32 -0
  98. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +61 -0
  99. package/dist/cjs/OptionsEditorLayout/OptionsEditorGrid.js +29 -0
  100. package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +40 -0
  101. package/dist/cjs/OptionsEditorLayout/index.js +31 -0
  102. package/dist/cjs/Tooltip/SeriesInfo.js +3 -3
  103. package/dist/cjs/Tooltip/Tooltip.js +2 -2
  104. package/dist/cjs/Tooltip/TooltipContent.js +2 -1
  105. package/dist/cjs/Tooltip/focused-series.js +6 -3
  106. package/dist/cjs/Tooltip/focused-series.test.js +20 -2
  107. package/dist/cjs/UnitSelector/UnitSelector.js +118 -0
  108. package/dist/cjs/UnitSelector/UnitSelector.test.js +218 -0
  109. package/dist/cjs/UnitSelector/index.js +28 -0
  110. package/dist/cjs/index.js +4 -2
  111. package/dist/cjs/model/units/bytes.js +60 -0
  112. package/dist/cjs/model/units/constants.js +23 -0
  113. package/dist/cjs/model/units/decimal.js +67 -0
  114. package/dist/cjs/model/units/index.js +30 -0
  115. package/dist/cjs/model/units/percent.js +64 -0
  116. package/dist/cjs/model/units/time.js +138 -0
  117. package/dist/cjs/model/units/types.js +28 -0
  118. package/dist/cjs/model/units/units.js +104 -0
  119. package/dist/cjs/utils/component-ids.js +31 -0
  120. package/dist/cjs/utils/index.js +1 -0
  121. package/dist/index.d.ts +4 -2
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +4 -2
  124. package/dist/index.js.map +1 -1
  125. package/dist/model/units/bytes.d.ts +12 -0
  126. package/dist/model/units/bytes.d.ts.map +1 -0
  127. package/dist/model/units/bytes.js +48 -0
  128. package/dist/model/units/bytes.js.map +1 -0
  129. package/dist/model/units/constants.d.ts +2 -0
  130. package/dist/model/units/constants.d.ts.map +1 -0
  131. package/dist/model/units/constants.js +17 -0
  132. package/dist/model/units/constants.js.map +1 -0
  133. package/dist/model/units/decimal.d.ts +24 -0
  134. package/dist/model/units/decimal.d.ts.map +1 -0
  135. package/dist/model/units/decimal.js +59 -0
  136. package/dist/model/units/decimal.js.map +1 -0
  137. package/dist/model/units/index.d.ts +4 -0
  138. package/dist/model/units/index.d.ts.map +1 -0
  139. package/dist/model/units/index.js +17 -0
  140. package/dist/model/units/index.js.map +1 -0
  141. package/dist/model/units/percent.d.ts +12 -0
  142. package/dist/model/units/percent.d.ts.map +1 -0
  143. package/dist/model/units/percent.js +51 -0
  144. package/dist/model/units/percent.js.map +1 -0
  145. package/dist/model/units/time.d.ts +11 -0
  146. package/dist/model/units/time.d.ts.map +1 -0
  147. package/dist/model/units/time.js +125 -0
  148. package/dist/model/units/time.js.map +1 -0
  149. package/dist/model/units/types.d.ts +38 -0
  150. package/dist/model/units/types.d.ts.map +1 -0
  151. package/dist/model/units/types.js +22 -0
  152. package/dist/model/units/types.js.map +1 -0
  153. package/dist/model/units/units.d.ts +40 -0
  154. package/dist/model/units/units.d.ts.map +1 -0
  155. package/dist/model/units/units.js +83 -0
  156. package/dist/model/units/units.js.map +1 -0
  157. package/dist/utils/component-ids.d.ts +8 -0
  158. package/dist/utils/component-ids.d.ts.map +1 -0
  159. package/dist/utils/component-ids.js +27 -0
  160. package/dist/utils/component-ids.js.map +1 -0
  161. package/dist/utils/index.d.ts +1 -0
  162. package/dist/utils/index.d.ts.map +1 -1
  163. package/dist/utils/index.js +1 -0
  164. package/dist/utils/index.js.map +1 -1
  165. package/package.json +2 -2
  166. package/dist/TimeRangeSelector/AbsoluteTimePicker.d.ts.map +0 -1
  167. package/dist/TimeRangeSelector/AbsoluteTimePicker.js.map +0 -1
  168. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts.map +0 -1
  169. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +0 -1
  170. package/dist/TimeRangeSelector/index.d.ts.map +0 -1
  171. package/dist/TimeRangeSelector/index.js.map +0 -1
  172. package/dist/TimeRangeSelector/utils.d.ts.map +0 -1
  173. package/dist/TimeRangeSelector/utils.js.map +0 -1
  174. package/dist/cjs/model/units.js +0 -203
  175. package/dist/model/units.d.ts +0 -36
  176. package/dist/model/units.d.ts.map +0 -1
  177. package/dist/model/units.js +0 -196
  178. package/dist/model/units.js.map +0 -1
@@ -0,0 +1,64 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ DECIMAL_GROUP_CONFIG: ()=>DECIMAL_GROUP_CONFIG,
25
+ PERCENT_UNIT_CONFIG: ()=>PERCENT_UNIT_CONFIG,
26
+ formatPercent: ()=>formatPercent
27
+ });
28
+ const _constants = require("./constants");
29
+ const percentUnitKinds = [
30
+ 'Percent',
31
+ 'PercentDecimal',
32
+ '%'
33
+ ];
34
+ const DECIMAL_GROUP_CONFIG = {
35
+ label: 'Decimal',
36
+ decimal_places: true,
37
+ abbreviate: true
38
+ };
39
+ const PERCENT_GROUP = 'Percent';
40
+ const PERCENT_UNIT_CONFIG = {
41
+ Percent: {
42
+ group: PERCENT_GROUP,
43
+ label: 'Percent (0-100)'
44
+ },
45
+ PercentDecimal: {
46
+ group: PERCENT_GROUP,
47
+ label: 'Percent (0.0-1.0)'
48
+ },
49
+ '%': {
50
+ // This option is not shown in the selector because it is a shorthand
51
+ // duplicate of `Percent`.
52
+ disableSelectorOption: true,
53
+ group: PERCENT_GROUP,
54
+ label: '%'
55
+ }
56
+ };
57
+ function formatPercent(value, unitOptions) {
58
+ var _decimal_places;
59
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
60
+ if (unitOptions.kind === 'PercentDecimal') {
61
+ value = value * 100;
62
+ }
63
+ return value.toFixed(decimals) + '%';
64
+ }
@@ -0,0 +1,138 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ TIME_GROUP_CONFIG: ()=>TIME_GROUP_CONFIG,
25
+ TIME_UNIT_CONFIG: ()=>TIME_UNIT_CONFIG,
26
+ formatTime: ()=>formatTime
27
+ });
28
+ const _dateFns = require("date-fns");
29
+ const timeUnitKinds = [
30
+ 'Milliseconds',
31
+ 'Seconds',
32
+ 'Minutes',
33
+ 'Hours',
34
+ 'Days',
35
+ 'Weeks',
36
+ 'Months',
37
+ 'Years'
38
+ ];
39
+ const TIME_GROUP = 'Time';
40
+ const TIME_GROUP_CONFIG = {
41
+ label: 'Time'
42
+ };
43
+ const TIME_UNIT_CONFIG = {
44
+ Milliseconds: {
45
+ group: TIME_GROUP,
46
+ label: 'Milliseconds'
47
+ },
48
+ Seconds: {
49
+ group: TIME_GROUP,
50
+ label: 'Seconds'
51
+ },
52
+ Minutes: {
53
+ group: TIME_GROUP,
54
+ label: 'Minutes'
55
+ },
56
+ Hours: {
57
+ group: TIME_GROUP,
58
+ label: 'Hours'
59
+ },
60
+ Days: {
61
+ group: TIME_GROUP,
62
+ label: 'Days'
63
+ },
64
+ Weeks: {
65
+ group: TIME_GROUP,
66
+ label: 'Weeks'
67
+ },
68
+ Months: {
69
+ group: TIME_GROUP,
70
+ label: 'Months'
71
+ },
72
+ Years: {
73
+ group: TIME_GROUP,
74
+ label: 'Years'
75
+ }
76
+ };
77
+ function formatTime(value, unitOptions) {
78
+ // Create a Duration from the value based on what time unit it is
79
+ const duration = {};
80
+ switch(unitOptions.kind){
81
+ case 'Milliseconds':
82
+ duration.seconds = value / 1000;
83
+ break;
84
+ case 'Seconds':
85
+ duration.seconds = value;
86
+ break;
87
+ case 'Minutes':
88
+ duration.minutes = value;
89
+ break;
90
+ case 'Hours':
91
+ duration.hours = value;
92
+ break;
93
+ case 'Days':
94
+ duration.days = value;
95
+ break;
96
+ case 'Weeks':
97
+ duration.weeks = value;
98
+ break;
99
+ case 'Months':
100
+ duration.months = value;
101
+ break;
102
+ case 'Years':
103
+ duration.years = value;
104
+ break;
105
+ default:
106
+ {
107
+ const exhaustive = unitOptions.kind;
108
+ throw new Error(`Unknown time unit type ${exhaustive}`);
109
+ }
110
+ }
111
+ // Find the largest whole time unit we can display the value in and use it
112
+ const ms = (0, _dateFns.milliseconds)(duration);
113
+ const seconds = ms / 1000;
114
+ if (seconds < 1) {
115
+ return `${ms.toFixed()} milliseconds`;
116
+ }
117
+ const minutes = seconds / 60;
118
+ if (minutes < 1) {
119
+ return `${seconds.toFixed()} seconds`;
120
+ }
121
+ const hours = minutes / 60;
122
+ if (hours < 1) {
123
+ return `${minutes.toFixed()} minutes`;
124
+ }
125
+ const days = hours / 24;
126
+ if (days < 1) {
127
+ return `${hours.toFixed()} hours`;
128
+ }
129
+ const weeks = days / 7;
130
+ if (weeks < 1) {
131
+ return `${days.toFixed()} days`;
132
+ }
133
+ const years = weeks / 52;
134
+ if (years < 1) {
135
+ return `${weeks.toFixed()} weeks`;
136
+ }
137
+ return `${years.toFixed()} years`;
138
+ }
@@ -0,0 +1,28 @@
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
+ "use strict";
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
19
+ Object.defineProperty(exports, "UNIT_GROUPS", {
20
+ enumerable: true,
21
+ get: ()=>UNIT_GROUPS
22
+ });
23
+ const UNIT_GROUPS = [
24
+ 'Time',
25
+ 'Percent',
26
+ 'Decimal',
27
+ 'Bytes'
28
+ ];
@@ -0,0 +1,104 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ UNIT_GROUP_CONFIG: ()=>UNIT_GROUP_CONFIG,
25
+ UNIT_CONFIG: ()=>UNIT_CONFIG,
26
+ formatValue: ()=>formatValue,
27
+ getUnitKindConfig: ()=>getUnitKindConfig,
28
+ getUnitGroup: ()=>getUnitGroup,
29
+ getUnitGroupConfig: ()=>getUnitGroupConfig,
30
+ isTimeUnit: ()=>isTimeUnit,
31
+ isPercentUnit: ()=>isPercentUnit,
32
+ isDecimalUnit: ()=>isDecimalUnit,
33
+ isBytesUnit: ()=>isBytesUnit,
34
+ isUnitWithDecimalPlaces: ()=>isUnitWithDecimalPlaces,
35
+ isUnitWithAbbreviate: ()=>isUnitWithAbbreviate
36
+ });
37
+ const _bytes = require("./bytes");
38
+ const _constants = require("./constants");
39
+ const _decimal = require("./decimal");
40
+ const _percent = require("./percent");
41
+ const _time = require("./time");
42
+ const UNIT_GROUP_CONFIG = {
43
+ Time: _time.TIME_GROUP_CONFIG,
44
+ Percent: _decimal.PERCENT_GROUP_CONFIG,
45
+ Decimal: _percent.DECIMAL_GROUP_CONFIG,
46
+ Bytes: _bytes.BYTES_GROUP_CONFIG
47
+ };
48
+ const UNIT_CONFIG = {
49
+ ..._time.TIME_UNIT_CONFIG,
50
+ ..._percent.PERCENT_UNIT_CONFIG,
51
+ ..._decimal.DECIMAL_UNIT_CONFIG,
52
+ ..._bytes.BYTES_UNIT_CONFIG
53
+ };
54
+ function formatValue(value, unitOptions) {
55
+ if (unitOptions === undefined) {
56
+ return value.toString();
57
+ }
58
+ if (isDecimalUnit(unitOptions)) {
59
+ return (0, _decimal.formatDecimal)(value, unitOptions);
60
+ }
61
+ if (isTimeUnit(unitOptions)) {
62
+ return (0, _time.formatTime)(value, unitOptions);
63
+ }
64
+ if (isPercentUnit(unitOptions)) {
65
+ return (0, _percent.formatPercent)(value, unitOptions);
66
+ }
67
+ if (isBytesUnit(unitOptions)) {
68
+ var _decimal_places;
69
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
70
+ return (0, _bytes.formatBytes)(value, decimals);
71
+ }
72
+ const exhaustive = unitOptions;
73
+ throw new Error(`Unknown unit options ${exhaustive}`);
74
+ }
75
+ function getUnitKindConfig(unitOptions) {
76
+ return UNIT_CONFIG[unitOptions.kind];
77
+ }
78
+ function getUnitGroup(unitOptions) {
79
+ return getUnitKindConfig(unitOptions).group;
80
+ }
81
+ function getUnitGroupConfig(unitOptions) {
82
+ const unitConfig = getUnitKindConfig(unitOptions);
83
+ return UNIT_GROUP_CONFIG[unitConfig.group];
84
+ }
85
+ function isTimeUnit(unitOptions) {
86
+ return getUnitGroup(unitOptions) === 'Time';
87
+ }
88
+ function isPercentUnit(unitOptions) {
89
+ return getUnitGroup(unitOptions) === 'Percent';
90
+ }
91
+ function isDecimalUnit(unitOptions) {
92
+ return getUnitGroup(unitOptions) === 'Decimal';
93
+ }
94
+ function isBytesUnit(unitOptions) {
95
+ return getUnitGroup(unitOptions) === 'Bytes';
96
+ }
97
+ function isUnitWithDecimalPlaces(unitOptions) {
98
+ const groupConfig = getUnitGroupConfig(unitOptions);
99
+ return !!groupConfig.decimal_places;
100
+ }
101
+ function isUnitWithAbbreviate(unitOptions) {
102
+ const groupConfig = getUnitGroupConfig(unitOptions);
103
+ return !!groupConfig.abbreviate;
104
+ }
@@ -0,0 +1,31 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "useId", {
18
+ enumerable: true,
19
+ get: ()=>useId
20
+ });
21
+ const _react = require("react");
22
+ function useId(prefix) {
23
+ if (globalThis.useIdValue === undefined) {
24
+ globalThis.useIdValue = 0;
25
+ }
26
+ const id = (0, _react.useRef)(undefined);
27
+ if (id.current === undefined) {
28
+ id.current = `${prefix}-${globalThis.useIdValue++}`;
29
+ }
30
+ return id.current;
31
+ }
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  _exportStar(require("./combine-sx"), exports);
18
18
  _exportStar(require("./theme-gen"), exports);
19
+ _exportStar(require("./component-ids"), exports);
19
20
  function _exportStar(from, to) {
20
21
  Object.keys(from).forEach(function(k) {
21
22
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
package/dist/index.d.ts CHANGED
@@ -1,14 +1,16 @@
1
+ export * from './DateTimeRangePicker';
1
2
  export * from './Drawer';
2
3
  export * from './EChart';
3
4
  export * from './ErrorAlert';
4
5
  export * from './ErrorBoundary';
6
+ export * from './GaugeChart';
5
7
  export * from './InfoTooltip';
6
8
  export * from './JSONEditor';
7
9
  export * from './Legend';
8
10
  export * from './LineChart';
9
- export * from './GaugeChart';
11
+ export * from './OptionsEditorLayout';
10
12
  export * from './StatChart';
11
- export * from './TimeRangeSelector';
13
+ export * from './UnitSelector';
12
14
  export * from './context/ChartsThemeProvider';
13
15
  export * from './utils';
14
16
  export * from './model';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -10,17 +10,19 @@
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
+ export * from './DateTimeRangePicker';
13
14
  export * from './Drawer';
14
15
  export * from './EChart';
15
16
  export * from './ErrorAlert';
16
17
  export * from './ErrorBoundary';
18
+ export * from './GaugeChart';
17
19
  export * from './InfoTooltip';
18
20
  export * from './JSONEditor';
19
21
  export * from './Legend';
20
22
  export * from './LineChart';
21
- export * from './GaugeChart';
23
+ export * from './OptionsEditorLayout';
22
24
  export * from './StatChart';
23
- export * from './TimeRangeSelector';
25
+ export * from './UnitSelector';
24
26
  export * from './context/ChartsThemeProvider';
25
27
  export * from './utils';
26
28
  export * from './model';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LineChart';\nexport * from './GaugeChart';\nexport * from './StatChart';\nexport * from './TimeRangeSelector';\nexport * from './context/ChartsThemeProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DateTimeRangePicker';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './UnitSelector';\nexport * from './context/ChartsThemeProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { UnitGroupConfig, UnitConfig } from './types';
2
+ declare const bytesUnitKinds: readonly ["Bytes"];
3
+ declare type BytesUnitKind = typeof bytesUnitKinds[number];
4
+ export declare type BytesUnitOptions = {
5
+ kind: BytesUnitKind;
6
+ decimal_places?: number;
7
+ };
8
+ export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
9
+ export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
10
+ export declare function formatBytes(bytes: number, decimals?: number): string;
11
+ export {};
12
+ //# sourceMappingURL=bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAGhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAKzE,CAAC;AAGF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAI,UAYtD"}
@@ -0,0 +1,48 @@
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
+ const bytesUnitKinds = [
14
+ 'Bytes'
15
+ ];
16
+ export const BYTES_GROUP_CONFIG = {
17
+ label: 'Bytes',
18
+ decimal_places: true
19
+ };
20
+ export const BYTES_UNIT_CONFIG = {
21
+ Bytes: {
22
+ group: 'Bytes',
23
+ label: 'Bytes'
24
+ }
25
+ };
26
+ // https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828
27
+ export function formatBytes(bytes, decimals = 2) {
28
+ if (bytes === 0) return '0 Bytes';
29
+ const k = 1024;
30
+ const dm = decimals < 0 ? 0 : decimals;
31
+ const sizes = [
32
+ 'Bytes',
33
+ 'KB',
34
+ 'MB',
35
+ 'GB',
36
+ 'TB',
37
+ 'PB',
38
+ 'EB',
39
+ 'ZB',
40
+ 'YB'
41
+ ];
42
+ // Math.max(0, ...) ensures that we don't return -1 as a value for the index.
43
+ // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
44
+ const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
45
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
46
+ }
47
+
48
+ //# sourceMappingURL=bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnitGroupConfig, UnitConfig } from './types';\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = typeof bytesUnitKinds[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\n// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828\nexport function formatBytes(bytes: number, decimals = 2) {\n if (bytes === 0) return '0 Bytes';\n\n const k = 1024;\n const dm = decimals < 0 ? 0 : decimals;\n const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];\n\n // Math.max(0, ...) ensures that we don't return -1 as a value for the index.\n // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.\n const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));\n\n return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];\n}\n"],"names":["bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","decimals","k","dm","sizes","i","Math","max","floor","log","parseFloat","pow","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;AAIjC,MAAMA,cAAc,GAAG;IAAC,OAAO;CAAC,AAAS,AAAC;AAM1C,OAAO,MAAMC,kBAAkB,GAAoB;IACjDC,KAAK,EAAE,OAAO;IACdC,cAAc,EAAE,IAAI;CACrB,CAAC;AACF,OAAO,MAAMC,iBAAiB,GAAgD;IAC5EC,KAAK,EAAE;QACLC,KAAK,EAAE,OAAO;QACdJ,KAAK,EAAE,OAAO;KACf;CACF,CAAC;AAEF,gIAAgI;AAChI,OAAO,SAASK,WAAW,CAACC,KAAa,EAAEC,QAAQ,GAAG,CAAC,EAAE;IACvD,IAAID,KAAK,KAAK,CAAC,EAAE,OAAO,SAAS,CAAC;IAElC,MAAME,CAAC,GAAG,IAAI,AAAC;IACf,MAAMC,EAAE,GAAGF,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAGA,QAAQ,AAAC;IACvC,MAAMG,KAAK,GAAG;QAAC,OAAO;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;QAAE,IAAI;KAAC,AAAC;IAExE,6EAA6E;IAC7E,6GAA6G;IAC7G,MAAMC,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAED,IAAI,CAACE,KAAK,CAACF,IAAI,CAACG,GAAG,CAACT,KAAK,CAAC,GAAGM,IAAI,CAACG,GAAG,CAACP,CAAC,CAAC,CAAC,CAAC,AAAC;IAEjE,OAAOQ,UAAU,CAAC,AAACV,CAAAA,KAAK,GAAGM,IAAI,CAACK,GAAG,CAACT,CAAC,EAAEG,CAAC,CAAC,CAAA,CAAEO,OAAO,CAACT,EAAE,CAAC,CAAC,GAAG,GAAG,GAAGC,KAAK,CAACC,CAAC,CAAC,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const DEFAULT_DECIMAL_PLACES = 2;
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/model/units/constants.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,sBAAsB,IAAI,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
+ // Common constants needed across individual unit groups and the overall
14
+ // combined units.
15
+ export const DEFAULT_DECIMAL_PLACES = 2;
16
+
17
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/model/units/constants.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 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"}
@@ -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,gBAAgB,GAAG;IAAC,SAAS;CAAC,AAAS,AAAC;AAO9C,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;CACrB,CAAC;AACF,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAE,SAAS;QAChBJ,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,OAAO,SAASK,aAAa,CAACC,KAAa,EAAEC,WAA+B,EAAU;QACnEA,eAA0B;IAA3C,MAAMC,QAAQ,GAAGD,CAAAA,eAA0B,GAA1BA,WAAW,CAACN,cAAc,cAA1BM,eAA0B,cAA1BA,eAA0B,GAAIV,sBAAsB,AAAC;IAEtE,IAAIU,WAAW,CAACE,UAAU,KAAK,IAAI,EAAE;QACnC,OAAOC,qBAAqB,CAACJ,KAAK,EAAEE,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED,MAAMG,YAAY,GAA6B;QAC7CC,KAAK,EAAE,SAAS;QAChBC,qBAAqB,EAAEL,QAAQ;QAC/BM,qBAAqB,EAAEN,QAAQ;QAC/BO,WAAW,EAAE,IAAI;KAClB,AAAC;IACF,MAAMC,gBAAgB,GAAG,IAAIC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAEP,YAAY,CAAC,AAAC;IACtE,OAAOK,gBAAgB,CAACG,MAAM,CAACb,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;;CAIC,GACD,OAAO,SAASI,qBAAqB,CAACU,GAAW,EAAEZ,QAAQ,GAAG,CAAC,EAAE;IAC/D,MAAMa,QAAQ,GAAG,CAACC,CAAS,GAAK1B,KAAK,CAAC0B,CAAC,EAAEd,QAAQ,CAAC,AAAC;IACnD,OAAOe,YAAY,CAACH,GAAG,EAAEC,QAAQ,CAAC,CAAC;AACrC,CAAC;AAED;;;CAGC,GACD,OAAO,SAASE,YAAY,CAACH,GAAW,EAAEC,QAAgC,EAAU;IAClF,MAAMG,EAAE,GAAGH,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"}