@perses-dev/core 0.38.0 → 0.40.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 (127) hide show
  1. package/dist/cjs/constants/dashboard-defaults.js +6 -2
  2. package/dist/cjs/constants/dialog.js +3 -1
  3. package/dist/cjs/constants/index.js +11 -9
  4. package/dist/cjs/index.js +12 -10
  5. package/dist/cjs/model/calculations.js +61 -51
  6. package/dist/cjs/model/index.js +28 -26
  7. package/dist/cjs/model/legend.js +39 -19
  8. package/dist/cjs/model/resource.js +9 -0
  9. package/dist/cjs/model/time-series-queries.js +3 -1
  10. package/dist/cjs/model/time.js +147 -64
  11. package/dist/cjs/model/units/bytes.js +37 -25
  12. package/dist/cjs/model/units/constants.js +3 -1
  13. package/dist/cjs/model/units/decimal.js +22 -16
  14. package/dist/cjs/model/units/index.js +13 -11
  15. package/dist/cjs/model/units/percent.js +26 -19
  16. package/dist/cjs/model/units/time.js +99 -38
  17. package/dist/cjs/model/units/types.js +3 -1
  18. package/dist/cjs/model/units/units.js +67 -43
  19. package/dist/cjs/model/units/utils.js +13 -7
  20. package/dist/cjs/model/variables.js +16 -3
  21. package/dist/cjs/utils/event.js +3 -1
  22. package/dist/cjs/utils/fetch.js +12 -4
  23. package/dist/cjs/utils/index.js +17 -14
  24. package/dist/cjs/utils/is-empty-object.js +3 -1
  25. package/dist/cjs/utils/mathjs.js +3 -1
  26. package/dist/cjs/utils/memo.js +10 -6
  27. package/dist/cjs/utils/panel-refs.js +9 -3
  28. package/dist/cjs/utils/text.js +39 -14
  29. package/dist/cjs/utils/time-series-data.js +21 -11
  30. package/dist/cjs/utils/types.js +16 -0
  31. package/dist/constants/dashboard-defaults.js.map +1 -1
  32. package/dist/constants/dialog.js.map +1 -1
  33. package/dist/constants/index.js.map +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/model/calculations.d.ts +9 -9
  36. package/dist/model/calculations.d.ts.map +1 -1
  37. package/dist/model/calculations.js +46 -46
  38. package/dist/model/calculations.js.map +1 -1
  39. package/dist/model/datasource.d.ts +20 -4
  40. package/dist/model/datasource.d.ts.map +1 -1
  41. package/dist/model/datasource.js.map +1 -1
  42. package/dist/model/display.d.ts +1 -1
  43. package/dist/model/display.d.ts.map +1 -1
  44. package/dist/model/display.js.map +1 -1
  45. package/dist/model/index.js.map +1 -1
  46. package/dist/model/legend.d.ts +6 -6
  47. package/dist/model/legend.js +9 -9
  48. package/dist/model/legend.js.map +1 -1
  49. package/dist/model/panels.d.ts +5 -2
  50. package/dist/model/panels.d.ts.map +1 -1
  51. package/dist/model/panels.js.map +1 -1
  52. package/dist/model/query.d.ts +13 -2
  53. package/dist/model/query.d.ts.map +1 -1
  54. package/dist/model/query.js.map +1 -1
  55. package/dist/model/resource.d.ts +3 -2
  56. package/dist/model/resource.d.ts.map +1 -1
  57. package/dist/model/resource.js +3 -1
  58. package/dist/model/resource.js.map +1 -1
  59. package/dist/model/thresholds.d.ts +2 -2
  60. package/dist/model/thresholds.d.ts.map +1 -1
  61. package/dist/model/thresholds.js.map +1 -1
  62. package/dist/model/time-series-data.d.ts +6 -0
  63. package/dist/model/time-series-data.d.ts.map +1 -1
  64. package/dist/model/time-series-data.js.map +1 -1
  65. package/dist/model/time-series-queries.js.map +1 -1
  66. package/dist/model/time.d.ts +3 -0
  67. package/dist/model/time.d.ts.map +1 -1
  68. package/dist/model/time.js +115 -55
  69. package/dist/model/time.js.map +1 -1
  70. package/dist/model/units/bytes.d.ts +8 -8
  71. package/dist/model/units/bytes.d.ts.map +1 -1
  72. package/dist/model/units/bytes.js +27 -21
  73. package/dist/model/units/bytes.js.map +1 -1
  74. package/dist/model/units/constants.js.map +1 -1
  75. package/dist/model/units/decimal.d.ts +8 -8
  76. package/dist/model/units/decimal.d.ts.map +1 -1
  77. package/dist/model/units/decimal.js +14 -14
  78. package/dist/model/units/decimal.js.map +1 -1
  79. package/dist/model/units/index.js.map +1 -1
  80. package/dist/model/units/percent.d.ts +7 -7
  81. package/dist/model/units/percent.d.ts.map +1 -1
  82. package/dist/model/units/percent.js +17 -16
  83. package/dist/model/units/percent.js.map +1 -1
  84. package/dist/model/units/time.d.ts +15 -15
  85. package/dist/model/units/time.d.ts.map +1 -1
  86. package/dist/model/units/time.js +87 -34
  87. package/dist/model/units/time.js.map +1 -1
  88. package/dist/model/units/types.d.ts +14 -5
  89. package/dist/model/units/types.d.ts.map +1 -1
  90. package/dist/model/units/types.js.map +1 -1
  91. package/dist/model/units/units.d.ts +37 -30
  92. package/dist/model/units/units.d.ts.map +1 -1
  93. package/dist/model/units/units.js +41 -35
  94. package/dist/model/units/units.js.map +1 -1
  95. package/dist/model/units/utils.d.ts +2 -2
  96. package/dist/model/units/utils.d.ts.map +1 -1
  97. package/dist/model/units/utils.js +4 -4
  98. package/dist/model/units/utils.js.map +1 -1
  99. package/dist/model/variables.d.ts +25 -7
  100. package/dist/model/variables.d.ts.map +1 -1
  101. package/dist/model/variables.js +3 -0
  102. package/dist/model/variables.js.map +1 -1
  103. package/dist/test/setup-tests.js.map +1 -1
  104. package/dist/utils/event.js.map +1 -1
  105. package/dist/utils/fetch.js.map +1 -1
  106. package/dist/utils/index.d.ts +2 -1
  107. package/dist/utils/index.d.ts.map +1 -1
  108. package/dist/utils/index.js +2 -1
  109. package/dist/utils/index.js.map +1 -1
  110. package/dist/utils/is-empty-object.js.map +1 -1
  111. package/dist/utils/mathjs.js.map +1 -1
  112. package/dist/utils/memo.js +2 -2
  113. package/dist/utils/memo.js.map +1 -1
  114. package/dist/utils/panel-refs.js.map +1 -1
  115. package/dist/utils/text.d.ts +15 -3
  116. package/dist/utils/text.d.ts.map +1 -1
  117. package/dist/utils/text.js +29 -10
  118. package/dist/utils/text.js.map +1 -1
  119. package/dist/utils/time-series-data.d.ts +1 -1
  120. package/dist/utils/time-series-data.d.ts.map +1 -1
  121. package/dist/utils/time-series-data.js +7 -7
  122. package/dist/utils/time-series-data.js.map +1 -1
  123. package/dist/utils/types.d.ts +2 -0
  124. package/dist/utils/types.d.ts.map +1 -0
  125. package/dist/utils/types.js +15 -0
  126. package/dist/utils/types.js.map +1 -0
  127. package/package.json +5 -4
@@ -21,85 +21,146 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- PersesTimeToIntlTime: ()=>PersesTimeToIntlTime,
25
- TIME_GROUP_CONFIG: ()=>TIME_GROUP_CONFIG,
26
- TIME_UNIT_CONFIG: ()=>TIME_UNIT_CONFIG,
27
- formatTime: ()=>formatTime
24
+ PersesTimeToIntlTime: function() {
25
+ return PersesTimeToIntlTime;
26
+ },
27
+ TIME_GROUP_CONFIG: function() {
28
+ return TIME_GROUP_CONFIG;
29
+ },
30
+ TIME_UNIT_CONFIG: function() {
31
+ return TIME_UNIT_CONFIG;
32
+ },
33
+ formatTime: function() {
34
+ return formatTime;
35
+ }
28
36
  });
29
37
  const _constants = require("./constants");
30
38
  const _utils = require("./utils");
31
- const timeUnitKinds = [
32
- 'Milliseconds',
33
- 'Seconds',
34
- 'Minutes',
35
- 'Hours',
36
- 'Days',
37
- 'Weeks',
38
- 'Months',
39
- 'Years'
39
+ const timeUnits = [
40
+ 'milliseconds',
41
+ 'seconds',
42
+ 'minutes',
43
+ 'hours',
44
+ 'days',
45
+ 'weeks',
46
+ 'months',
47
+ 'years'
40
48
  ];
41
49
  const TIME_GROUP = 'Time';
42
50
  const TIME_GROUP_CONFIG = {
43
51
  label: 'Time',
44
- decimal_places: true
52
+ decimalPlaces: true
45
53
  };
46
54
  const TIME_UNIT_CONFIG = {
47
- Milliseconds: {
55
+ milliseconds: {
48
56
  group: TIME_GROUP,
49
57
  label: 'Milliseconds'
50
58
  },
51
- Seconds: {
59
+ seconds: {
52
60
  group: TIME_GROUP,
53
61
  label: 'Seconds'
54
62
  },
55
- Minutes: {
63
+ minutes: {
56
64
  group: TIME_GROUP,
57
65
  label: 'Minutes'
58
66
  },
59
- Hours: {
67
+ hours: {
60
68
  group: TIME_GROUP,
61
69
  label: 'Hours'
62
70
  },
63
- Days: {
71
+ days: {
64
72
  group: TIME_GROUP,
65
73
  label: 'Days'
66
74
  },
67
- Weeks: {
75
+ weeks: {
68
76
  group: TIME_GROUP,
69
77
  label: 'Weeks'
70
78
  },
71
- Months: {
79
+ months: {
72
80
  group: TIME_GROUP,
73
81
  label: 'Months'
74
82
  },
75
- Years: {
83
+ years: {
76
84
  group: TIME_GROUP,
77
85
  label: 'Years'
78
86
  }
79
87
  };
80
88
  var PersesTimeToIntlTime;
81
89
  (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["milliseconds"] = 'millisecond';
91
+ PersesTimeToIntlTime["seconds"] = 'second';
92
+ PersesTimeToIntlTime["minutes"] = 'minute';
93
+ PersesTimeToIntlTime["hours"] = 'hour';
94
+ PersesTimeToIntlTime["days"] = 'day';
95
+ PersesTimeToIntlTime["weeks"] = 'week';
96
+ PersesTimeToIntlTime["months"] = 'month';
97
+ PersesTimeToIntlTime["years"] = 'year';
90
98
  })(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
91
- function formatTime(value, { kind , decimal_places }) {
92
- const isMonthOrYear = kind === 'Months' || kind === 'Years';
99
+ /**
100
+ * Note: This conversion will not be exactly accurate for months and years,
101
+ * due variations in the lengths of months (i.e. 28 - 31 days) and years (i.e. leap years).
102
+ * For precision with months and years, we would need more complex algorithms and/or external libraries.
103
+ * However, we expect that measurements in months and years will be rare.
104
+ */ const TIME_UNITS_IN_SECONDS = {
105
+ years: 31536000,
106
+ months: 2592000,
107
+ weeks: 604800,
108
+ days: 86400,
109
+ hours: 3600,
110
+ minutes: 60,
111
+ seconds: 1,
112
+ milliseconds: 0.001
113
+ };
114
+ const LARGEST_TO_SMALLEST_TIME_UNITS = [
115
+ 'years',
116
+ 'months',
117
+ 'weeks',
118
+ 'days',
119
+ 'hours',
120
+ 'minutes',
121
+ 'seconds',
122
+ 'milliseconds'
123
+ ];
124
+ /**
125
+ * Choose the first time unit that produces a number greater than 1, starting from the biggest time unit.
126
+ */ function getValueAndKindForNaturalNumbers(value, unit) {
127
+ const valueInSeconds = value * TIME_UNITS_IN_SECONDS[unit];
128
+ // Initialize for TS
129
+ const largestTimeUnit = LARGEST_TO_SMALLEST_TIME_UNITS[0] || 'years';
130
+ let timeUnit = largestTimeUnit;
131
+ let valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[largestTimeUnit];
132
+ for (timeUnit of LARGEST_TO_SMALLEST_TIME_UNITS){
133
+ valueInTimeUnit = valueInSeconds / TIME_UNITS_IN_SECONDS[timeUnit];
134
+ if (valueInTimeUnit >= 1) {
135
+ return {
136
+ value: valueInTimeUnit,
137
+ unit: timeUnit
138
+ };
139
+ }
140
+ }
141
+ // If we didn't find a time unit, we have to settle for the smallest time unit (which is the last time unit).
142
+ return {
143
+ value: valueInTimeUnit,
144
+ unit: timeUnit
145
+ };
146
+ }
147
+ function isMonthOrYear(unit) {
148
+ return unit === 'months' || unit === 'years';
149
+ }
150
+ function formatTime(value, { unit , decimalPlaces }) {
151
+ if (value === 0) return '0s';
152
+ const results = getValueAndKindForNaturalNumbers(value, unit);
93
153
  const formatterOptions = {
94
154
  style: 'unit',
95
- unit: PersesTimeToIntlTime[kind],
96
- unitDisplay: isMonthOrYear ? 'long' : 'narrow'
155
+ unit: PersesTimeToIntlTime[results.unit],
156
+ unitDisplay: isMonthOrYear(results.unit) ? 'long' : 'narrow'
97
157
  };
98
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
99
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
100
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
158
+ if ((0, _utils.hasDecimalPlaces)(decimalPlaces)) {
159
+ formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
160
+ formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimalPlaces);
101
161
  } else {
102
162
  formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
103
163
  }
104
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
164
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
165
+ return formatter.format(results.value);
105
166
  }
@@ -18,7 +18,9 @@ Object.defineProperty(exports, "__esModule", {
18
18
  });
19
19
  Object.defineProperty(exports, "UNIT_GROUPS", {
20
20
  enumerable: true,
21
- get: ()=>UNIT_GROUPS
21
+ get: function() {
22
+ return UNIT_GROUPS;
23
+ }
22
24
  });
23
25
  const UNIT_GROUPS = [
24
26
  'Time',
@@ -21,18 +21,42 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
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
24
+ UNIT_GROUP_CONFIG: function() {
25
+ return UNIT_GROUP_CONFIG;
26
+ },
27
+ UNIT_CONFIG: function() {
28
+ return UNIT_CONFIG;
29
+ },
30
+ formatValue: function() {
31
+ return formatValue;
32
+ },
33
+ getUnitConfig: function() {
34
+ return getUnitConfig;
35
+ },
36
+ getUnitGroup: function() {
37
+ return getUnitGroup;
38
+ },
39
+ getUnitGroupConfig: function() {
40
+ return getUnitGroupConfig;
41
+ },
42
+ isTimeUnit: function() {
43
+ return isTimeUnit;
44
+ },
45
+ isPercentUnit: function() {
46
+ return isPercentUnit;
47
+ },
48
+ isDecimalUnit: function() {
49
+ return isDecimalUnit;
50
+ },
51
+ isBytesUnit: function() {
52
+ return isBytesUnit;
53
+ },
54
+ isUnitWithDecimalPlaces: function() {
55
+ return isUnitWithDecimalPlaces;
56
+ },
57
+ isUnitWithShortValues: function() {
58
+ return isUnitWithShortValues;
59
+ }
36
60
  });
37
61
  const _bytes = require("./bytes");
38
62
  const _decimal = require("./decimal");
@@ -50,52 +74,52 @@ const UNIT_CONFIG = {
50
74
  ..._decimal.DECIMAL_UNIT_CONFIG,
51
75
  ..._bytes.BYTES_UNIT_CONFIG
52
76
  };
53
- function formatValue(value, unitOptions) {
54
- if (unitOptions === undefined) {
77
+ function formatValue(value, formatOptions) {
78
+ if (formatOptions === undefined) {
55
79
  return value.toString();
56
80
  }
57
- if (isDecimalUnit(unitOptions)) {
58
- return (0, _decimal.formatDecimal)(value, unitOptions);
81
+ if (isBytesUnit(formatOptions)) {
82
+ return (0, _bytes.formatBytes)(value, formatOptions);
59
83
  }
60
- if (isTimeUnit(unitOptions)) {
61
- return (0, _time.formatTime)(value, unitOptions);
84
+ if (isDecimalUnit(formatOptions)) {
85
+ return (0, _decimal.formatDecimal)(value, formatOptions);
62
86
  }
63
- if (isPercentUnit(unitOptions)) {
64
- return (0, _percent.formatPercent)(value, unitOptions);
87
+ if (isPercentUnit(formatOptions)) {
88
+ return (0, _percent.formatPercent)(value, formatOptions);
65
89
  }
66
- if (isBytesUnit(unitOptions)) {
67
- return (0, _bytes.formatBytes)(value, unitOptions);
90
+ if (isTimeUnit(formatOptions)) {
91
+ return (0, _time.formatTime)(value, formatOptions);
68
92
  }
69
- const exhaustive = unitOptions;
93
+ const exhaustive = formatOptions;
70
94
  throw new Error(`Unknown unit options ${exhaustive}`);
71
95
  }
72
- function getUnitKindConfig(unitOptions) {
73
- return UNIT_CONFIG[unitOptions.kind];
96
+ function getUnitConfig(formatOptions) {
97
+ return UNIT_CONFIG[formatOptions.unit];
74
98
  }
75
- function getUnitGroup(unitOptions) {
76
- return getUnitKindConfig(unitOptions).group;
99
+ function getUnitGroup(formatOptions) {
100
+ return getUnitConfig(formatOptions).group;
77
101
  }
78
- function getUnitGroupConfig(unitOptions) {
79
- const unitConfig = getUnitKindConfig(unitOptions);
102
+ function getUnitGroupConfig(formatOptions) {
103
+ const unitConfig = getUnitConfig(formatOptions);
80
104
  return UNIT_GROUP_CONFIG[unitConfig.group];
81
105
  }
82
- function isTimeUnit(unitOptions) {
83
- return getUnitGroup(unitOptions) === 'Time';
106
+ function isTimeUnit(formatOptions) {
107
+ return getUnitGroup(formatOptions) === 'Time';
84
108
  }
85
- function isPercentUnit(unitOptions) {
86
- return getUnitGroup(unitOptions) === 'Percent';
109
+ function isPercentUnit(formatOptions) {
110
+ return getUnitGroup(formatOptions) === 'Percent';
87
111
  }
88
- function isDecimalUnit(unitOptions) {
89
- return getUnitGroup(unitOptions) === 'Decimal';
112
+ function isDecimalUnit(formatOptions) {
113
+ return getUnitGroup(formatOptions) === 'Decimal';
90
114
  }
91
- function isBytesUnit(unitOptions) {
92
- return getUnitGroup(unitOptions) === 'Bytes';
115
+ function isBytesUnit(formatOptions) {
116
+ return getUnitGroup(formatOptions) === 'Bytes';
93
117
  }
94
- function isUnitWithDecimalPlaces(unitOptions) {
95
- const groupConfig = getUnitGroupConfig(unitOptions);
96
- return !!groupConfig.decimal_places;
118
+ function isUnitWithDecimalPlaces(formatOptions) {
119
+ const groupConfig = getUnitGroupConfig(formatOptions);
120
+ return !!groupConfig.decimalPlaces;
97
121
  }
98
- function isUnitWithAbbreviate(unitOptions) {
99
- const groupConfig = getUnitGroupConfig(unitOptions);
100
- return !!groupConfig.abbreviate;
122
+ function isUnitWithShortValues(formatOptions) {
123
+ const groupConfig = getUnitGroupConfig(formatOptions);
124
+ return !!groupConfig.shortValues;
101
125
  }
@@ -21,15 +21,21 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- shouldAbbreviate: ()=>shouldAbbreviate,
25
- hasDecimalPlaces: ()=>hasDecimalPlaces,
26
- limitDecimalPlaces: ()=>limitDecimalPlaces
24
+ shouldShortenValues: function() {
25
+ return shouldShortenValues;
26
+ },
27
+ hasDecimalPlaces: function() {
28
+ return hasDecimalPlaces;
29
+ },
30
+ limitDecimalPlaces: function() {
31
+ return limitDecimalPlaces;
32
+ }
27
33
  });
28
- function shouldAbbreviate(abbreviate) {
29
- return abbreviate !== false;
34
+ function shouldShortenValues(shortValues) {
35
+ return shortValues !== false;
30
36
  }
31
- function hasDecimalPlaces(decimal_places) {
32
- return typeof decimal_places === 'number';
37
+ function hasDecimalPlaces(decimalPlaces) {
38
+ return typeof decimalPlaces === 'number';
33
39
  }
34
40
  function limitDecimalPlaces(num) {
35
41
  if (!num) return num;
@@ -14,8 +14,21 @@
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
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
+ getVariableProject: function() {
25
+ return getVariableProject;
26
+ },
27
+ DEFAULT_ALL_VALUE: function() {
28
+ return DEFAULT_ALL_VALUE;
29
+ }
20
30
  });
31
+ function getVariableProject(variable) {
32
+ return 'project' in variable.metadata ? variable.metadata.project : undefined;
33
+ }
21
34
  const DEFAULT_ALL_VALUE = '$__all';
@@ -16,7 +16,9 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  Object.defineProperty(exports, "useEvent", {
18
18
  enumerable: true,
19
- get: ()=>useEvent
19
+ get: function() {
20
+ return useEvent;
21
+ }
20
22
  });
21
23
  const _react = require("react");
22
24
  function useEvent(handler) {
@@ -23,10 +23,18 @@ function _export(target, all) {
23
23
  });
24
24
  }
25
25
  _export(exports, {
26
- fetch: ()=>fetch,
27
- fetchJson: ()=>fetchJson,
28
- FetchError: ()=>FetchError,
29
- UserFriendlyError: ()=>UserFriendlyError
26
+ fetch: function() {
27
+ return fetch;
28
+ },
29
+ fetchJson: function() {
30
+ return fetchJson;
31
+ },
32
+ FetchError: function() {
33
+ return FetchError;
34
+ },
35
+ UserFriendlyError: function() {
36
+ return UserFriendlyError;
37
+ }
30
38
  });
31
39
  async function fetch(...args) {
32
40
  const response = await global.fetch(...args);
@@ -14,21 +14,24 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _exportStar(require("./event"), exports);
18
- _exportStar(require("./fetch"), exports);
19
- _exportStar(require("./is-empty-object"), exports);
20
- _exportStar(require("./memo"), exports);
21
- _exportStar(require("./panel-refs"), exports);
22
- _exportStar(require("./time-series-data"), exports);
23
- _exportStar(require("./text"), exports);
24
- function _exportStar(from, to) {
17
+ _export_star(require("./event"), exports);
18
+ _export_star(require("./fetch"), exports);
19
+ _export_star(require("./is-empty-object"), exports);
20
+ _export_star(require("./memo"), exports);
21
+ _export_star(require("./panel-refs"), exports);
22
+ _export_star(require("./text"), exports);
23
+ _export_star(require("./time-series-data"), exports);
24
+ _export_star(require("./types"), exports);
25
+ function _export_star(from, to) {
25
26
  Object.keys(from).forEach(function(k) {
26
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
27
- enumerable: true,
28
- get: function() {
29
- return from[k];
30
- }
31
- });
27
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
28
+ Object.defineProperty(to, k, {
29
+ enumerable: true,
30
+ get: function() {
31
+ return from[k];
32
+ }
33
+ });
34
+ }
32
35
  });
33
36
  return from;
34
37
  }
@@ -18,7 +18,9 @@ Object.defineProperty(exports, "__esModule", {
18
18
  });
19
19
  Object.defineProperty(exports, "isEmptyObject", {
20
20
  enumerable: true,
21
- get: ()=>isEmptyObject
21
+ get: function() {
22
+ return isEmptyObject;
23
+ }
22
24
  });
23
25
  function isEmptyObject(obj) {
24
26
  return Object.getOwnPropertyNames(obj).length === 0;
@@ -16,7 +16,9 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  Object.defineProperty(exports, "gcd", {
18
18
  enumerable: true,
19
- get: ()=>gcd
19
+ get: function() {
20
+ return gcd;
21
+ }
20
22
  });
21
23
  const _mathjs = require("mathjs");
22
24
  // This ensures we get a minimal mathjs bundle for just what we need (see https://mathjs.org/docs/custom_bundling.html)
@@ -21,12 +21,16 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- useMemoized: ()=>useMemoized,
25
- useDeepMemo: ()=>useDeepMemo
24
+ useMemoized: function() {
25
+ return useMemoized;
26
+ },
27
+ useDeepMemo: function() {
28
+ return useDeepMemo;
29
+ }
26
30
  });
27
31
  const _react = require("react");
28
- const _isEqual = /*#__PURE__*/ _interopRequireDefault(require("lodash/isEqual"));
29
- function _interopRequireDefault(obj) {
32
+ const _isEqual = /*#__PURE__*/ _interop_require_default(require("lodash/isEqual"));
33
+ function _interop_require_default(obj) {
30
34
  return obj && obj.__esModule ? obj : {
31
35
  default: obj
32
36
  };
@@ -35,8 +39,8 @@ function useMemoized(factory, deps) {
35
39
  const ref = (0, _react.useRef)();
36
40
  let areEqual = true;
37
41
  for(let i = 0; i < deps.length; i++){
38
- var ref1;
39
- if (((ref1 = ref.current) === null || ref1 === void 0 ? void 0 : ref1.deps[i]) !== deps[i]) {
42
+ var _ref_current;
43
+ if (((_ref_current = ref.current) === null || _ref_current === void 0 ? void 0 : _ref_current.deps[i]) !== deps[i]) {
40
44
  areEqual = false;
41
45
  break;
42
46
  }
@@ -21,9 +21,15 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- resolvePanelRef: ()=>resolvePanelRef,
25
- getPanelKeyFromRef: ()=>getPanelKeyFromRef,
26
- createPanelRef: ()=>createPanelRef
24
+ resolvePanelRef: function() {
25
+ return resolvePanelRef;
26
+ },
27
+ getPanelKeyFromRef: function() {
28
+ return getPanelKeyFromRef;
29
+ },
30
+ createPanelRef: function() {
31
+ return createPanelRef;
32
+ }
27
33
  });
28
34
  function resolvePanelRef(spec, panelRef) {
29
35
  const panelsKey = getPanelKeyFromRef(panelRef);
@@ -21,32 +21,57 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- getDashboardDisplayName: ()=>getDashboardDisplayName,
25
- getVariableDisplayName: ()=>getVariableDisplayName,
26
- getDashboardExtendedDisplayName: ()=>getDashboardExtendedDisplayName,
27
- getVariableExtendedDisplayName: ()=>getVariableExtendedDisplayName
24
+ getDashboardDisplayName: function() {
25
+ return getDashboardDisplayName;
26
+ },
27
+ getVariableDisplayName: function() {
28
+ return getVariableDisplayName;
29
+ },
30
+ getDatasourceDisplayName: function() {
31
+ return getDatasourceDisplayName;
32
+ },
33
+ getDashboardExtendedDisplayName: function() {
34
+ return getDashboardExtendedDisplayName;
35
+ },
36
+ getVariableExtendedDisplayName: function() {
37
+ return getVariableExtendedDisplayName;
38
+ },
39
+ getDatasourceExtendedDisplayName: function() {
40
+ return getDatasourceExtendedDisplayName;
41
+ }
28
42
  });
29
43
  function getDashboardDisplayName(dashboard) {
30
- var ref;
31
- var ref1;
32
- return (ref1 = (ref = dashboard.spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : dashboard.metadata.name;
44
+ var _dashboard_spec_display;
45
+ var _dashboard_spec_display_name;
46
+ return (_dashboard_spec_display_name = (_dashboard_spec_display = dashboard.spec.display) === null || _dashboard_spec_display === void 0 ? void 0 : _dashboard_spec_display.name) !== null && _dashboard_spec_display_name !== void 0 ? _dashboard_spec_display_name : dashboard.metadata.name;
33
47
  }
34
48
  function getVariableDisplayName(variable) {
35
- var ref;
36
- var ref1;
37
- return (ref1 = (ref = variable.spec.spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : variable.metadata.name;
49
+ var _variable_spec_spec_display;
50
+ var _variable_spec_spec_display_name;
51
+ return (_variable_spec_spec_display_name = (_variable_spec_spec_display = variable.spec.spec.display) === null || _variable_spec_spec_display === void 0 ? void 0 : _variable_spec_spec_display.name) !== null && _variable_spec_spec_display_name !== void 0 ? _variable_spec_spec_display_name : variable.metadata.name;
52
+ }
53
+ function getDatasourceDisplayName(datasource) {
54
+ var _datasource_spec_display;
55
+ return ((_datasource_spec_display = datasource.spec.display) === null || _datasource_spec_display === void 0 ? void 0 : _datasource_spec_display.name) || datasource.metadata.name;
38
56
  }
39
57
  function getDashboardExtendedDisplayName(dashboard) {
40
- var ref;
41
- if ((ref = dashboard.spec.display) === null || ref === void 0 ? void 0 : ref.name) {
58
+ var _dashboard_spec_display;
59
+ if ((_dashboard_spec_display = dashboard.spec.display) === null || _dashboard_spec_display === void 0 ? void 0 : _dashboard_spec_display.name) {
42
60
  return `${dashboard.spec.display.name} (Name: ${dashboard.metadata.name})`;
43
61
  }
44
62
  return dashboard.metadata.name;
45
63
  }
46
64
  function getVariableExtendedDisplayName(variable) {
47
- var ref;
48
- if ((ref = variable.spec.spec.display) === null || ref === void 0 ? void 0 : ref.name) {
65
+ var _variable_spec_spec_display;
66
+ if ((_variable_spec_spec_display = variable.spec.spec.display) === null || _variable_spec_spec_display === void 0 ? void 0 : _variable_spec_spec_display.name) {
49
67
  return `${variable.spec.spec.display.name} (Name: ${variable.metadata.name})`;
50
68
  }
51
69
  return variable.metadata.name;
52
70
  }
71
+ function getDatasourceExtendedDisplayName(datasource) {
72
+ var _datasource_spec_display;
73
+ if ((_datasource_spec_display = datasource.spec.display) === null || _datasource_spec_display === void 0 ? void 0 : _datasource_spec_display.name) {
74
+ return `${datasource.spec.display.name} (Name: ${datasource.metadata.name})`;
75
+ }
76
+ return datasource.metadata.name;
77
+ }
@@ -21,11 +21,21 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- MIN_STEP_INTERVAL_MS: ()=>MIN_STEP_INTERVAL_MS,
25
- getXValues: ()=>getXValues,
26
- getTimeSeriesValues: ()=>getTimeSeriesValues,
27
- getYValues: ()=>getYValues,
28
- getCommonTimeScale: ()=>getCommonTimeScale
24
+ MIN_STEP_INTERVAL_MS: function() {
25
+ return MIN_STEP_INTERVAL_MS;
26
+ },
27
+ getXValues: function() {
28
+ return getXValues;
29
+ },
30
+ getTimeSeriesValues: function() {
31
+ return getTimeSeriesValues;
32
+ },
33
+ getYValues: function() {
34
+ return getYValues;
35
+ },
36
+ getCommonTimeScale: function() {
37
+ return getCommonTimeScale;
38
+ }
29
39
  });
30
40
  const _mathjs = require("./mathjs");
31
41
  const MIN_STEP_INTERVAL_MS = 10;
@@ -154,13 +164,13 @@ function getCommonTimeScale(seriesData) {
154
164
  const calculatedStepMs = (0, _mathjs.gcd)(...steps);
155
165
  stepMs = calculatedStepMs < MIN_STEP_INTERVAL_MS ? MIN_STEP_INTERVAL_MS : calculatedStepMs;
156
166
  }
157
- const startMs1 = timeRange.start.valueOf();
158
- const endMs1 = timeRange.end.valueOf();
159
- const rangeMs1 = endMs1 - startMs1;
167
+ const startMs = timeRange.start.valueOf();
168
+ const endMs = timeRange.end.valueOf();
169
+ const rangeMs = endMs - startMs;
160
170
  return {
161
- startMs: startMs1,
162
- endMs: endMs1,
171
+ startMs,
172
+ endMs,
163
173
  stepMs,
164
- rangeMs: rangeMs1
174
+ rangeMs
165
175
  };
166
176
  }