@perses-dev/core 0.35.0 → 0.36.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 (70) hide show
  1. package/dist/cjs/model/calculations.js +1 -1
  2. package/dist/cjs/model/index.js +1 -0
  3. package/dist/cjs/model/legend.js +19 -2
  4. package/dist/cjs/model/units/bytes.js +84 -0
  5. package/dist/cjs/model/units/constants.js +23 -0
  6. package/dist/cjs/model/units/decimal.js +62 -0
  7. package/dist/cjs/model/units/index.js +31 -0
  8. package/dist/cjs/model/units/percent.js +73 -0
  9. package/dist/cjs/model/units/time.js +105 -0
  10. package/dist/cjs/model/units/types.js +28 -0
  11. package/dist/cjs/model/units/units.js +101 -0
  12. package/dist/cjs/model/units/utils.js +42 -0
  13. package/dist/cjs/model/variables.js +5 -0
  14. package/dist/model/calculations.js +1 -1
  15. package/dist/model/calculations.js.map +1 -1
  16. package/dist/model/dashboard.d.ts +1 -0
  17. package/dist/model/dashboard.d.ts.map +1 -1
  18. package/dist/model/dashboard.js.map +1 -1
  19. package/dist/model/index.d.ts +1 -0
  20. package/dist/model/index.d.ts.map +1 -1
  21. package/dist/model/index.js +1 -0
  22. package/dist/model/index.js.map +1 -1
  23. package/dist/model/legend.d.ts +5 -0
  24. package/dist/model/legend.d.ts.map +1 -1
  25. package/dist/model/legend.js +15 -1
  26. package/dist/model/legend.js.map +1 -1
  27. package/dist/model/thresholds.d.ts +4 -0
  28. package/dist/model/thresholds.d.ts.map +1 -1
  29. package/dist/model/thresholds.js.map +1 -1
  30. package/dist/model/units/bytes.d.ts +13 -0
  31. package/dist/model/units/bytes.d.ts.map +1 -0
  32. package/dist/model/units/bytes.js +66 -0
  33. package/dist/model/units/bytes.js.map +1 -0
  34. package/dist/model/units/constants.d.ts +2 -0
  35. package/dist/model/units/constants.d.ts.map +1 -0
  36. package/dist/model/units/constants.js +17 -0
  37. package/dist/model/units/constants.js.map +1 -0
  38. package/dist/model/units/decimal.d.ts +13 -0
  39. package/dist/model/units/decimal.d.ts.map +1 -0
  40. package/dist/model/units/decimal.js +49 -0
  41. package/dist/model/units/decimal.js.map +1 -0
  42. package/dist/model/units/index.d.ts +5 -0
  43. package/dist/model/units/index.d.ts.map +1 -0
  44. package/dist/model/units/index.js +18 -0
  45. package/dist/model/units/index.js.map +1 -0
  46. package/dist/model/units/percent.d.ts +12 -0
  47. package/dist/model/units/percent.d.ts.map +1 -0
  48. package/dist/model/units/percent.js +60 -0
  49. package/dist/model/units/percent.js.map +1 -0
  50. package/dist/model/units/time.d.ts +22 -0
  51. package/dist/model/units/time.d.ts.map +1 -0
  52. package/dist/model/units/time.js +91 -0
  53. package/dist/model/units/time.js.map +1 -0
  54. package/dist/model/units/types.d.ts +47 -0
  55. package/dist/model/units/types.d.ts.map +1 -0
  56. package/dist/model/units/types.js +22 -0
  57. package/dist/model/units/types.js.map +1 -0
  58. package/dist/model/units/units.d.ts +40 -0
  59. package/dist/model/units/units.d.ts.map +1 -0
  60. package/dist/model/units/units.js +80 -0
  61. package/dist/model/units/units.js.map +1 -0
  62. package/dist/model/units/utils.d.ts +4 -0
  63. package/dist/model/units/utils.d.ts.map +1 -0
  64. package/dist/model/units/utils.js +32 -0
  65. package/dist/model/units/utils.js.map +1 -0
  66. package/dist/model/variables.d.ts +1 -0
  67. package/dist/model/variables.d.ts.map +1 -1
  68. package/dist/model/variables.js +1 -1
  69. package/dist/model/variables.js.map +1 -1
  70. package/package.json +3 -2
@@ -55,7 +55,7 @@ const CALCULATIONS_CONFIG = {
55
55
  description: 'Last numeric value'
56
56
  },
57
57
  Mean: {
58
- label: 'Average',
58
+ label: 'Avg',
59
59
  description: 'Average value excluding nulls'
60
60
  },
61
61
  Sum: {
@@ -30,6 +30,7 @@ _exportStar(require("./thresholds"), exports);
30
30
  _exportStar(require("./time"), exports);
31
31
  _exportStar(require("./time-series-data"), exports);
32
32
  _exportStar(require("./time-series-queries"), exports);
33
+ _exportStar(require("./units"), exports);
33
34
  _exportStar(require("./variables"), exports);
34
35
  function _exportStar(from, to) {
35
36
  Object.keys(from).forEach(function(k) {
@@ -27,11 +27,14 @@ function _export(target, all) {
27
27
  _export(exports, {
28
28
  legendPositions: ()=>legendPositions,
29
29
  legendModes: ()=>legendModes,
30
+ legendSizes: ()=>legendSizes,
30
31
  isValidLegendPosition: ()=>isValidLegendPosition,
31
32
  isValidLegendMode: ()=>isValidLegendMode,
33
+ isValidLegendSize: ()=>isValidLegendSize,
32
34
  DEFAULT_LEGEND: ()=>DEFAULT_LEGEND,
33
35
  getLegendPosition: ()=>getLegendPosition,
34
- getLegendMode: ()=>getLegendMode
36
+ getLegendMode: ()=>getLegendMode,
37
+ getLegendSize: ()=>getLegendSize
35
38
  });
36
39
  const legendPositions = [
37
40
  'Bottom',
@@ -41,15 +44,23 @@ const legendModes = [
41
44
  'List',
42
45
  'Table'
43
46
  ];
47
+ const legendSizes = [
48
+ 'Small',
49
+ 'Medium'
50
+ ];
44
51
  function isValidLegendPosition(position) {
45
52
  return legendPositions.includes(position);
46
53
  }
47
54
  function isValidLegendMode(mode) {
48
55
  return legendModes.includes(mode);
49
56
  }
57
+ function isValidLegendSize(size) {
58
+ return legendSizes.includes(size);
59
+ }
50
60
  const DEFAULT_LEGEND = {
51
61
  position: 'Bottom',
52
- mode: 'List'
62
+ mode: 'List',
63
+ size: 'Medium'
53
64
  };
54
65
  function getLegendPosition(position) {
55
66
  if (position === undefined) {
@@ -66,3 +77,9 @@ function getLegendMode(mode) {
66
77
  }
67
78
  return mode;
68
79
  }
80
+ function getLegendSize(size) {
81
+ if (!size || !isValidLegendSize(size)) {
82
+ return DEFAULT_LEGEND.size;
83
+ }
84
+ return size;
85
+ }
@@ -0,0 +1,84 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ BYTES_GROUP_CONFIG: ()=>BYTES_GROUP_CONFIG,
25
+ BYTES_UNIT_CONFIG: ()=>BYTES_UNIT_CONFIG,
26
+ formatBytes: ()=>formatBytes
27
+ });
28
+ const _numbro = /*#__PURE__*/ _interopRequireDefault(require("numbro"));
29
+ const _constants = require("./constants");
30
+ const _utils = require("./utils");
31
+ function _interopRequireDefault(obj) {
32
+ return obj && obj.__esModule ? obj : {
33
+ default: obj
34
+ };
35
+ }
36
+ const DEFAULT_NUMBRO_MANTISSA = 2;
37
+ const bytesUnitKinds = [
38
+ 'Bytes'
39
+ ];
40
+ const BYTES_GROUP_CONFIG = {
41
+ label: 'Bytes',
42
+ decimal_places: true,
43
+ abbreviate: true
44
+ };
45
+ const BYTES_UNIT_CONFIG = {
46
+ // These units are powers of 1000.
47
+ // In other words, 1 KB = 1000 bytes.
48
+ Bytes: {
49
+ group: 'Bytes',
50
+ label: 'Bytes'
51
+ }
52
+ };
53
+ function formatBytes(bytes, options) {
54
+ const { abbreviate , decimal_places } = options;
55
+ if (!(0, _utils.shouldAbbreviate)(abbreviate) || Math.abs(bytes) < 1000) {
56
+ const formatterOptions = {
57
+ style: 'unit',
58
+ unit: 'byte',
59
+ unitDisplay: 'long',
60
+ useGrouping: true
61
+ };
62
+ if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
63
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
64
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
65
+ } else {
66
+ // This can happen if bytes is between -1000 and 1000
67
+ if ((0, _utils.shouldAbbreviate)(abbreviate)) {
68
+ formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
69
+ }
70
+ }
71
+ return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
72
+ }
73
+ // numbro is able to add units like KB, MB, GB, etc. correctly
74
+ return (0, _numbro.default)(bytes).format({
75
+ output: 'byte',
76
+ base: 'decimal',
77
+ spaceSeparated: true,
78
+ mantissa: (0, _utils.hasDecimalPlaces)(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
79
+ // trimMantissa trims trailing 0s
80
+ trimMantissa: !(0, _utils.hasDecimalPlaces)(decimal_places),
81
+ // optionalMantissa excludes all the decimal places if they're all zeros
82
+ optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimal_places)
83
+ });
84
+ }
@@ -0,0 +1,23 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ // 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, "MAX_SIGNIFICANT_DIGITS", {
20
+ enumerable: true,
21
+ get: ()=>MAX_SIGNIFICANT_DIGITS
22
+ });
23
+ const MAX_SIGNIFICANT_DIGITS = 3;
@@ -0,0 +1,62 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ DECIMAL_GROUP_CONFIG: ()=>DECIMAL_GROUP_CONFIG,
25
+ DECIMAL_UNIT_CONFIG: ()=>DECIMAL_UNIT_CONFIG,
26
+ formatDecimal: ()=>formatDecimal
27
+ });
28
+ const _constants = require("./constants");
29
+ const _utils = require("./utils");
30
+ const decimalUnitKinds = [
31
+ 'Decimal'
32
+ ];
33
+ const DECIMAL_GROUP_CONFIG = {
34
+ label: 'Decimal',
35
+ decimal_places: true,
36
+ abbreviate: true
37
+ };
38
+ const DECIMAL_UNIT_CONFIG = {
39
+ Decimal: {
40
+ group: 'Decimal',
41
+ label: 'Decimal'
42
+ }
43
+ };
44
+ function formatDecimal(value, options) {
45
+ const { abbreviate , decimal_places } = options;
46
+ const formatterOptions = {
47
+ style: 'decimal',
48
+ useGrouping: true
49
+ };
50
+ if ((0, _utils.shouldAbbreviate)(abbreviate)) {
51
+ formatterOptions.notation = 'compact';
52
+ }
53
+ if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
54
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
55
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
56
+ } else {
57
+ if ((0, _utils.shouldAbbreviate)(abbreviate)) {
58
+ formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
59
+ }
60
+ }
61
+ return Intl.NumberFormat('en-US', formatterOptions).format(value);
62
+ }
@@ -0,0 +1,31 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./utils"), exports);
18
+ _exportStar(require("./units"), exports);
19
+ _exportStar(require("./constants"), exports);
20
+ _exportStar(require("./types"), exports);
21
+ function _exportStar(from, to) {
22
+ Object.keys(from).forEach(function(k) {
23
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
24
+ enumerable: true,
25
+ get: function() {
26
+ return from[k];
27
+ }
28
+ });
29
+ });
30
+ return from;
31
+ }
@@ -0,0 +1,73 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ PERCENT_GROUP_CONFIG: ()=>PERCENT_GROUP_CONFIG,
25
+ PERCENT_UNIT_CONFIG: ()=>PERCENT_UNIT_CONFIG,
26
+ formatPercent: ()=>formatPercent
27
+ });
28
+ const _constants = require("./constants");
29
+ const _utils = require("./utils");
30
+ const percentUnitKinds = [
31
+ 'Percent',
32
+ 'PercentDecimal',
33
+ '%'
34
+ ];
35
+ const PERCENT_GROUP_CONFIG = {
36
+ label: 'Percent',
37
+ decimal_places: 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, { kind , decimal_places }) {
58
+ // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
59
+ if (kind === 'Percent') {
60
+ value = value / 100;
61
+ }
62
+ const formatterOptions = {
63
+ style: 'percent',
64
+ useGrouping: true
65
+ };
66
+ if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
67
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
68
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
69
+ } else {
70
+ formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
71
+ }
72
+ return Intl.NumberFormat('en-US', formatterOptions).format(value);
73
+ }
@@ -0,0 +1,105 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ PersesTimeToIntlTime: ()=>PersesTimeToIntlTime,
25
+ TIME_GROUP_CONFIG: ()=>TIME_GROUP_CONFIG,
26
+ TIME_UNIT_CONFIG: ()=>TIME_UNIT_CONFIG,
27
+ formatTime: ()=>formatTime
28
+ });
29
+ const _constants = require("./constants");
30
+ const _utils = require("./utils");
31
+ const timeUnitKinds = [
32
+ 'Milliseconds',
33
+ 'Seconds',
34
+ 'Minutes',
35
+ 'Hours',
36
+ 'Days',
37
+ 'Weeks',
38
+ 'Months',
39
+ 'Years'
40
+ ];
41
+ const TIME_GROUP = 'Time';
42
+ const TIME_GROUP_CONFIG = {
43
+ label: 'Time',
44
+ decimal_places: true
45
+ };
46
+ const TIME_UNIT_CONFIG = {
47
+ Milliseconds: {
48
+ group: TIME_GROUP,
49
+ label: 'Milliseconds'
50
+ },
51
+ Seconds: {
52
+ group: TIME_GROUP,
53
+ label: 'Seconds'
54
+ },
55
+ Minutes: {
56
+ group: TIME_GROUP,
57
+ label: 'Minutes'
58
+ },
59
+ Hours: {
60
+ group: TIME_GROUP,
61
+ label: 'Hours'
62
+ },
63
+ Days: {
64
+ group: TIME_GROUP,
65
+ label: 'Days'
66
+ },
67
+ Weeks: {
68
+ group: TIME_GROUP,
69
+ label: 'Weeks'
70
+ },
71
+ Months: {
72
+ group: TIME_GROUP,
73
+ label: 'Months'
74
+ },
75
+ Years: {
76
+ group: TIME_GROUP,
77
+ label: 'Years'
78
+ }
79
+ };
80
+ var PersesTimeToIntlTime;
81
+ (function(PersesTimeToIntlTime) {
82
+ PersesTimeToIntlTime["Milliseconds"] = 'millisecond';
83
+ PersesTimeToIntlTime["Seconds"] = 'second';
84
+ PersesTimeToIntlTime["Minutes"] = 'minute';
85
+ PersesTimeToIntlTime["Hours"] = 'hour';
86
+ PersesTimeToIntlTime["Days"] = 'day';
87
+ PersesTimeToIntlTime["Weeks"] = 'week';
88
+ PersesTimeToIntlTime["Months"] = 'month';
89
+ PersesTimeToIntlTime["Years"] = 'year';
90
+ })(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
91
+ function formatTime(value, { kind , decimal_places }) {
92
+ const isMonthOrYear = kind === 'Months' || kind === 'Years';
93
+ const formatterOptions = {
94
+ style: 'unit',
95
+ unit: PersesTimeToIntlTime[kind],
96
+ unitDisplay: isMonthOrYear ? 'long' : 'narrow'
97
+ };
98
+ if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
99
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
100
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
101
+ } else {
102
+ formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
103
+ }
104
+ return Intl.NumberFormat('en-US', formatterOptions).format(value);
105
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ // 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,101 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ UNIT_GROUP_CONFIG: ()=>UNIT_GROUP_CONFIG,
25
+ UNIT_CONFIG: ()=>UNIT_CONFIG,
26
+ formatValue: ()=>formatValue,
27
+ getUnitKindConfig: ()=>getUnitKindConfig,
28
+ getUnitGroup: ()=>getUnitGroup,
29
+ getUnitGroupConfig: ()=>getUnitGroupConfig,
30
+ isTimeUnit: ()=>isTimeUnit,
31
+ isPercentUnit: ()=>isPercentUnit,
32
+ isDecimalUnit: ()=>isDecimalUnit,
33
+ isBytesUnit: ()=>isBytesUnit,
34
+ isUnitWithDecimalPlaces: ()=>isUnitWithDecimalPlaces,
35
+ isUnitWithAbbreviate: ()=>isUnitWithAbbreviate
36
+ });
37
+ const _bytes = require("./bytes");
38
+ const _decimal = require("./decimal");
39
+ const _percent = require("./percent");
40
+ const _time = require("./time");
41
+ const UNIT_GROUP_CONFIG = {
42
+ Time: _time.TIME_GROUP_CONFIG,
43
+ Percent: _percent.PERCENT_GROUP_CONFIG,
44
+ Decimal: _decimal.DECIMAL_GROUP_CONFIG,
45
+ Bytes: _bytes.BYTES_GROUP_CONFIG
46
+ };
47
+ const UNIT_CONFIG = {
48
+ ..._time.TIME_UNIT_CONFIG,
49
+ ..._percent.PERCENT_UNIT_CONFIG,
50
+ ..._decimal.DECIMAL_UNIT_CONFIG,
51
+ ..._bytes.BYTES_UNIT_CONFIG
52
+ };
53
+ function formatValue(value, unitOptions) {
54
+ if (unitOptions === undefined) {
55
+ return value.toString();
56
+ }
57
+ if (isDecimalUnit(unitOptions)) {
58
+ return (0, _decimal.formatDecimal)(value, unitOptions);
59
+ }
60
+ if (isTimeUnit(unitOptions)) {
61
+ return (0, _time.formatTime)(value, unitOptions);
62
+ }
63
+ if (isPercentUnit(unitOptions)) {
64
+ return (0, _percent.formatPercent)(value, unitOptions);
65
+ }
66
+ if (isBytesUnit(unitOptions)) {
67
+ return (0, _bytes.formatBytes)(value, unitOptions);
68
+ }
69
+ const exhaustive = unitOptions;
70
+ throw new Error(`Unknown unit options ${exhaustive}`);
71
+ }
72
+ function getUnitKindConfig(unitOptions) {
73
+ return UNIT_CONFIG[unitOptions.kind];
74
+ }
75
+ function getUnitGroup(unitOptions) {
76
+ return getUnitKindConfig(unitOptions).group;
77
+ }
78
+ function getUnitGroupConfig(unitOptions) {
79
+ const unitConfig = getUnitKindConfig(unitOptions);
80
+ return UNIT_GROUP_CONFIG[unitConfig.group];
81
+ }
82
+ function isTimeUnit(unitOptions) {
83
+ return getUnitGroup(unitOptions) === 'Time';
84
+ }
85
+ function isPercentUnit(unitOptions) {
86
+ return getUnitGroup(unitOptions) === 'Percent';
87
+ }
88
+ function isDecimalUnit(unitOptions) {
89
+ return getUnitGroup(unitOptions) === 'Decimal';
90
+ }
91
+ function isBytesUnit(unitOptions) {
92
+ return getUnitGroup(unitOptions) === 'Bytes';
93
+ }
94
+ function isUnitWithDecimalPlaces(unitOptions) {
95
+ const groupConfig = getUnitGroupConfig(unitOptions);
96
+ return !!groupConfig.decimal_places;
97
+ }
98
+ function isUnitWithAbbreviate(unitOptions) {
99
+ const groupConfig = getUnitGroupConfig(unitOptions);
100
+ return !!groupConfig.abbreviate;
101
+ }
@@ -0,0 +1,42 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ shouldAbbreviate: ()=>shouldAbbreviate,
25
+ hasDecimalPlaces: ()=>hasDecimalPlaces,
26
+ limitDecimalPlaces: ()=>limitDecimalPlaces
27
+ });
28
+ function shouldAbbreviate(abbreviate) {
29
+ return abbreviate !== false;
30
+ }
31
+ function hasDecimalPlaces(decimal_places) {
32
+ return typeof decimal_places === 'number';
33
+ }
34
+ function limitDecimalPlaces(num) {
35
+ if (!num) return num;
36
+ if (num < 0) {
37
+ num = 0;
38
+ } else if (num > 20) {
39
+ num = 20;
40
+ }
41
+ return num;
42
+ }
@@ -14,3 +14,8 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
+ Object.defineProperty(exports, "DEFAULT_ALL_VALUE", {
18
+ enumerable: true,
19
+ get: ()=>DEFAULT_ALL_VALUE
20
+ });
21
+ const DEFAULT_ALL_VALUE = '$__all';
@@ -38,7 +38,7 @@ export const CALCULATIONS_CONFIG = {
38
38
  description: 'Last numeric value'
39
39
  },
40
40
  Mean: {
41
- label: 'Average',
41
+ label: 'Avg',
42
42
  description: 'Average value excluding nulls'
43
43
  },
44
44
  Sum: {