@perses-dev/components 0.15.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 (126) hide show
  1. package/dist/LineChart/LineChart.js +2 -1
  2. package/dist/LineChart/LineChart.js.map +1 -1
  3. package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts +13 -0
  4. package/dist/OptionsEditorLayout/OptionsEditorColumn.d.ts.map +1 -0
  5. package/dist/OptionsEditorLayout/OptionsEditorColumn.js +28 -0
  6. package/dist/OptionsEditorLayout/OptionsEditorColumn.js.map +1 -0
  7. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts +5 -0
  8. package/dist/OptionsEditorLayout/OptionsEditorControl.d.ts.map +1 -0
  9. package/dist/OptionsEditorLayout/OptionsEditorControl.js +50 -0
  10. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -0
  11. package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts +13 -0
  12. package/dist/OptionsEditorLayout/OptionsEditorGrid.d.ts.map +1 -0
  13. package/dist/OptionsEditorLayout/OptionsEditorGrid.js +26 -0
  14. package/dist/OptionsEditorLayout/OptionsEditorGrid.js.map +1 -0
  15. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts +13 -0
  16. package/dist/OptionsEditorLayout/OptionsEditorGroup.d.ts.map +1 -0
  17. package/dist/OptionsEditorLayout/OptionsEditorGroup.js +36 -0
  18. package/dist/OptionsEditorLayout/OptionsEditorGroup.js.map +1 -0
  19. package/dist/OptionsEditorLayout/index.d.ts +5 -0
  20. package/dist/OptionsEditorLayout/index.d.ts.map +1 -0
  21. package/dist/OptionsEditorLayout/index.js +18 -0
  22. package/dist/OptionsEditorLayout/index.js.map +1 -0
  23. package/dist/Tooltip/SeriesInfo.d.ts +1 -0
  24. package/dist/Tooltip/SeriesInfo.d.ts.map +1 -1
  25. package/dist/Tooltip/SeriesInfo.js +3 -3
  26. package/dist/Tooltip/SeriesInfo.js.map +1 -1
  27. package/dist/Tooltip/Tooltip.d.ts +2 -1
  28. package/dist/Tooltip/Tooltip.d.ts.map +1 -1
  29. package/dist/Tooltip/Tooltip.js +2 -2
  30. package/dist/Tooltip/Tooltip.js.map +1 -1
  31. package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
  32. package/dist/Tooltip/TooltipContent.js +2 -1
  33. package/dist/Tooltip/TooltipContent.js.map +1 -1
  34. package/dist/Tooltip/focused-series.d.ts +4 -3
  35. package/dist/Tooltip/focused-series.d.ts.map +1 -1
  36. package/dist/Tooltip/focused-series.js +6 -3
  37. package/dist/Tooltip/focused-series.js.map +1 -1
  38. package/dist/Tooltip/focused-series.test.js +20 -2
  39. package/dist/Tooltip/focused-series.test.js.map +1 -1
  40. package/dist/UnitSelector/UnitSelector.d.ts +8 -0
  41. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -0
  42. package/dist/UnitSelector/UnitSelector.js +112 -0
  43. package/dist/UnitSelector/UnitSelector.js.map +1 -0
  44. package/dist/UnitSelector/UnitSelector.test.d.ts +2 -0
  45. package/dist/UnitSelector/UnitSelector.test.d.ts.map +1 -0
  46. package/dist/UnitSelector/UnitSelector.test.js +211 -0
  47. package/dist/UnitSelector/UnitSelector.test.js.map +1 -0
  48. package/dist/UnitSelector/index.d.ts +2 -0
  49. package/dist/UnitSelector/index.d.ts.map +1 -0
  50. package/dist/UnitSelector/index.js +15 -0
  51. package/dist/UnitSelector/index.js.map +1 -0
  52. package/dist/cjs/LineChart/LineChart.js +2 -1
  53. package/dist/cjs/OptionsEditorLayout/OptionsEditorColumn.js +32 -0
  54. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +61 -0
  55. package/dist/cjs/OptionsEditorLayout/OptionsEditorGrid.js +29 -0
  56. package/dist/cjs/OptionsEditorLayout/OptionsEditorGroup.js +40 -0
  57. package/dist/cjs/OptionsEditorLayout/index.js +31 -0
  58. package/dist/cjs/Tooltip/SeriesInfo.js +3 -3
  59. package/dist/cjs/Tooltip/Tooltip.js +2 -2
  60. package/dist/cjs/Tooltip/TooltipContent.js +2 -1
  61. package/dist/cjs/Tooltip/focused-series.js +6 -3
  62. package/dist/cjs/Tooltip/focused-series.test.js +20 -2
  63. package/dist/cjs/UnitSelector/UnitSelector.js +118 -0
  64. package/dist/cjs/UnitSelector/UnitSelector.test.js +218 -0
  65. package/dist/cjs/UnitSelector/index.js +28 -0
  66. package/dist/cjs/index.js +4 -2
  67. package/dist/cjs/model/units/bytes.js +60 -0
  68. package/dist/cjs/model/units/constants.js +23 -0
  69. package/dist/cjs/model/units/decimal.js +67 -0
  70. package/dist/cjs/model/units/index.js +30 -0
  71. package/dist/cjs/model/units/percent.js +64 -0
  72. package/dist/cjs/model/units/time.js +138 -0
  73. package/dist/cjs/model/units/types.js +28 -0
  74. package/dist/cjs/model/units/units.js +104 -0
  75. package/dist/cjs/utils/component-ids.js +31 -0
  76. package/dist/cjs/utils/index.js +1 -0
  77. package/dist/index.d.ts +4 -2
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +4 -2
  80. package/dist/index.js.map +1 -1
  81. package/dist/model/units/bytes.d.ts +12 -0
  82. package/dist/model/units/bytes.d.ts.map +1 -0
  83. package/dist/model/units/bytes.js +48 -0
  84. package/dist/model/units/bytes.js.map +1 -0
  85. package/dist/model/units/constants.d.ts +2 -0
  86. package/dist/model/units/constants.d.ts.map +1 -0
  87. package/dist/model/units/constants.js +17 -0
  88. package/dist/model/units/constants.js.map +1 -0
  89. package/dist/model/units/decimal.d.ts +24 -0
  90. package/dist/model/units/decimal.d.ts.map +1 -0
  91. package/dist/model/units/decimal.js +59 -0
  92. package/dist/model/units/decimal.js.map +1 -0
  93. package/dist/model/units/index.d.ts +4 -0
  94. package/dist/model/units/index.d.ts.map +1 -0
  95. package/dist/model/units/index.js +17 -0
  96. package/dist/model/units/index.js.map +1 -0
  97. package/dist/model/units/percent.d.ts +12 -0
  98. package/dist/model/units/percent.d.ts.map +1 -0
  99. package/dist/model/units/percent.js +51 -0
  100. package/dist/model/units/percent.js.map +1 -0
  101. package/dist/model/units/time.d.ts +11 -0
  102. package/dist/model/units/time.d.ts.map +1 -0
  103. package/dist/model/units/time.js +125 -0
  104. package/dist/model/units/time.js.map +1 -0
  105. package/dist/model/units/types.d.ts +38 -0
  106. package/dist/model/units/types.d.ts.map +1 -0
  107. package/dist/model/units/types.js +22 -0
  108. package/dist/model/units/types.js.map +1 -0
  109. package/dist/model/units/units.d.ts +40 -0
  110. package/dist/model/units/units.d.ts.map +1 -0
  111. package/dist/model/units/units.js +83 -0
  112. package/dist/model/units/units.js.map +1 -0
  113. package/dist/utils/component-ids.d.ts +8 -0
  114. package/dist/utils/component-ids.d.ts.map +1 -0
  115. package/dist/utils/component-ids.js +27 -0
  116. package/dist/utils/component-ids.js.map +1 -0
  117. package/dist/utils/index.d.ts +1 -0
  118. package/dist/utils/index.d.ts.map +1 -1
  119. package/dist/utils/index.js +1 -0
  120. package/dist/utils/index.js.map +1 -1
  121. package/package.json +2 -2
  122. package/dist/cjs/model/units.js +0 -203
  123. package/dist/model/units.d.ts +0 -36
  124. package/dist/model/units.d.ts.map +0 -1
  125. package/dist/model/units.js +0 -196
  126. package/dist/model/units.js.map +0 -1
@@ -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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./UnitSelector"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
package/dist/cjs/index.js CHANGED
@@ -14,17 +14,19 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
+ _exportStar(require("./DateTimeRangePicker"), exports);
17
18
  _exportStar(require("./Drawer"), exports);
18
19
  _exportStar(require("./EChart"), exports);
19
20
  _exportStar(require("./ErrorAlert"), exports);
20
21
  _exportStar(require("./ErrorBoundary"), exports);
22
+ _exportStar(require("./GaugeChart"), exports);
21
23
  _exportStar(require("./InfoTooltip"), exports);
22
24
  _exportStar(require("./JSONEditor"), exports);
23
25
  _exportStar(require("./Legend"), exports);
24
26
  _exportStar(require("./LineChart"), exports);
25
- _exportStar(require("./GaugeChart"), exports);
27
+ _exportStar(require("./OptionsEditorLayout"), exports);
26
28
  _exportStar(require("./StatChart"), exports);
27
- _exportStar(require("./DateTimeRangePicker"), exports);
29
+ _exportStar(require("./UnitSelector"), exports);
28
30
  _exportStar(require("./context/ChartsThemeProvider"), exports);
29
31
  _exportStar(require("./utils"), exports);
30
32
  _exportStar(require("./model"), exports);
@@ -0,0 +1,60 @@
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
+ BYTES_GROUP_CONFIG: ()=>BYTES_GROUP_CONFIG,
25
+ BYTES_UNIT_CONFIG: ()=>BYTES_UNIT_CONFIG,
26
+ formatBytes: ()=>formatBytes
27
+ });
28
+ const bytesUnitKinds = [
29
+ 'Bytes'
30
+ ];
31
+ const BYTES_GROUP_CONFIG = {
32
+ label: 'Bytes',
33
+ decimal_places: true
34
+ };
35
+ const BYTES_UNIT_CONFIG = {
36
+ Bytes: {
37
+ group: 'Bytes',
38
+ label: 'Bytes'
39
+ }
40
+ };
41
+ function formatBytes(bytes, decimals = 2) {
42
+ if (bytes === 0) return '0 Bytes';
43
+ const k = 1024;
44
+ const dm = decimals < 0 ? 0 : decimals;
45
+ const sizes = [
46
+ 'Bytes',
47
+ 'KB',
48
+ 'MB',
49
+ 'GB',
50
+ 'TB',
51
+ 'PB',
52
+ 'EB',
53
+ 'ZB',
54
+ 'YB'
55
+ ];
56
+ // Math.max(0, ...) ensures that we don't return -1 as a value for the index.
57
+ // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
58
+ const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
59
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
60
+ }
@@ -0,0 +1,23 @@
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
+ "use strict";
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
19
+ Object.defineProperty(exports, "DEFAULT_DECIMAL_PLACES", {
20
+ enumerable: true,
21
+ get: ()=>DEFAULT_DECIMAL_PLACES
22
+ });
23
+ const DEFAULT_DECIMAL_PLACES = 2;
@@ -0,0 +1,67 @@
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
+ PERCENT_GROUP_CONFIG: ()=>PERCENT_GROUP_CONFIG,
25
+ DECIMAL_UNIT_CONFIG: ()=>DECIMAL_UNIT_CONFIG,
26
+ formatDecimal: ()=>formatDecimal,
27
+ abbreviateLargeNumber: ()=>abbreviateLargeNumber,
28
+ formatNumber: ()=>formatNumber
29
+ });
30
+ const _mathjs = require("../../utils/mathjs");
31
+ const _constants = require("./constants");
32
+ const decimalUnitKinds = [
33
+ 'Decimal'
34
+ ];
35
+ const PERCENT_GROUP_CONFIG = {
36
+ label: 'Percent',
37
+ decimal_places: true
38
+ };
39
+ const DECIMAL_UNIT_CONFIG = {
40
+ Decimal: {
41
+ group: 'Decimal',
42
+ label: 'Decimal'
43
+ }
44
+ };
45
+ function formatDecimal(value, unitOptions) {
46
+ var _decimal_places;
47
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
48
+ if (unitOptions.abbreviate === true) {
49
+ return abbreviateLargeNumber(value, decimals);
50
+ }
51
+ const formatParams = {
52
+ style: 'decimal',
53
+ minimumFractionDigits: decimals,
54
+ maximumFractionDigits: decimals,
55
+ useGrouping: true
56
+ };
57
+ const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);
58
+ return decimalFormatter.format(value);
59
+ }
60
+ function abbreviateLargeNumber(num, decimals = 2) {
61
+ const modifier = (n)=>(0, _mathjs.round)(n, decimals);
62
+ return formatNumber(num, modifier);
63
+ }
64
+ function formatNumber(num, modifier) {
65
+ const fn = modifier !== null && modifier !== void 0 ? modifier : Math.round;
66
+ 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();
67
+ }
@@ -0,0 +1,30 @@
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
+ _exportStar(require("./units"), exports);
18
+ _exportStar(require("./constants"), exports);
19
+ _exportStar(require("./types"), exports);
20
+ function _exportStar(from, to) {
21
+ Object.keys(from).forEach(function(k) {
22
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
23
+ enumerable: true,
24
+ get: function() {
25
+ return from[k];
26
+ }
27
+ });
28
+ });
29
+ return from;
30
+ }
@@ -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 './DateTimeRangePicker';
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,uBAAuB,CAAC;AACtC,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 './DateTimeRangePicker';
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 './DateTimeRangePicker';\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,uBAAuB,CAAC;AACtC,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"}