@perses-dev/components 0.53.1 → 0.54.0-beta.1

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 (232) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.js +1 -1
  2. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  3. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +1 -1
  4. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  5. package/dist/ContentWithLegend/model/content-with-legend-model.js +1 -1
  6. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  7. package/dist/FormEditor/FormActions.d.ts +1 -1
  8. package/dist/FormEditor/FormActions.d.ts.map +1 -1
  9. package/dist/FormEditor/FormActions.js.map +1 -1
  10. package/dist/FormatControls/FormatControls.d.ts +1 -1
  11. package/dist/FormatControls/FormatControls.d.ts.map +1 -1
  12. package/dist/FormatControls/FormatControls.js +1 -1
  13. package/dist/FormatControls/FormatControls.js.map +1 -1
  14. package/dist/FormatControls/UnitSelector.d.ts +1 -1
  15. package/dist/FormatControls/UnitSelector.d.ts.map +1 -1
  16. package/dist/FormatControls/UnitSelector.js +1 -1
  17. package/dist/FormatControls/UnitSelector.js.map +1 -1
  18. package/dist/Legend/Legend.js +1 -1
  19. package/dist/Legend/Legend.js.map +1 -1
  20. package/dist/Legend/legend-model.d.ts +1 -1
  21. package/dist/Legend/legend-model.d.ts.map +1 -1
  22. package/dist/Legend/legend-model.js.map +1 -1
  23. package/dist/LinksEditor/LinksEditor.d.ts +1 -1
  24. package/dist/LinksEditor/LinksEditor.js.map +1 -1
  25. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts +1 -1
  26. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -1
  27. package/dist/Table/Table.d.ts +1 -1
  28. package/dist/Table/Table.d.ts.map +1 -1
  29. package/dist/Table/Table.js +26 -6
  30. package/dist/Table/Table.js.map +1 -1
  31. package/dist/Table/TableToolbar.d.ts +34 -0
  32. package/dist/Table/TableToolbar.d.ts.map +1 -0
  33. package/dist/Table/TableToolbar.js +127 -0
  34. package/dist/Table/TableToolbar.js.map +1 -0
  35. package/dist/Table/VirtualizedTable.d.ts +3 -1
  36. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  37. package/dist/Table/VirtualizedTable.js +128 -117
  38. package/dist/Table/VirtualizedTable.js.map +1 -1
  39. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -1
  40. package/dist/Table/VirtualizedTableContainer.js +5 -1
  41. package/dist/Table/VirtualizedTableContainer.js.map +1 -1
  42. package/dist/Table/hooks/useFuzzySearch.d.ts +12 -0
  43. package/dist/Table/hooks/useFuzzySearch.d.ts.map +1 -0
  44. package/dist/Table/hooks/useFuzzySearch.js +43 -0
  45. package/dist/Table/hooks/useFuzzySearch.js.map +1 -0
  46. package/dist/Table/model/table-model.d.ts +38 -4
  47. package/dist/Table/model/table-model.d.ts.map +1 -1
  48. package/dist/Table/model/table-model.js.map +1 -1
  49. package/dist/ThresholdsEditor/ThresholdInput.d.ts +1 -1
  50. package/dist/ThresholdsEditor/ThresholdInput.d.ts.map +1 -1
  51. package/dist/ThresholdsEditor/ThresholdInput.js.map +1 -1
  52. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts +1 -1
  53. package/dist/ThresholdsEditor/ThresholdsEditor.d.ts.map +1 -1
  54. package/dist/ThresholdsEditor/ThresholdsEditor.js.map +1 -1
  55. package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts +2 -3
  56. package/dist/TimeRangeSelector/DateTimeRangePicker.d.ts.map +1 -1
  57. package/dist/TimeRangeSelector/DateTimeRangePicker.js +2 -0
  58. package/dist/TimeRangeSelector/DateTimeRangePicker.js.map +1 -1
  59. package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +1 -1
  60. package/dist/TimeRangeSelector/TimeRangeSelector.js +1 -1
  61. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
  62. package/dist/TimeRangeSelector/utils.d.ts +1 -1
  63. package/dist/TimeRangeSelector/utils.js +1 -1
  64. package/dist/TimeRangeSelector/utils.js.map +1 -1
  65. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts +2 -2
  66. package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
  67. package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
  68. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
  69. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  70. package/dist/TimeSeriesTooltip/nearby-series.js +1 -2
  71. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  72. package/dist/TransformsEditor/TransformEditor.d.ts +1 -1
  73. package/dist/TransformsEditor/TransformEditor.d.ts.map +1 -1
  74. package/dist/TransformsEditor/TransformEditor.js.map +1 -1
  75. package/dist/TransformsEditor/TransformEditorContainer.d.ts.map +1 -1
  76. package/dist/TransformsEditor/TransformEditorContainer.js +1 -1
  77. package/dist/TransformsEditor/TransformEditorContainer.js.map +1 -1
  78. package/dist/TransformsEditor/TransformsEditor.d.ts +1 -1
  79. package/dist/TransformsEditor/TransformsEditor.d.ts.map +1 -1
  80. package/dist/TransformsEditor/TransformsEditor.js.map +1 -1
  81. package/dist/ValueMappingEditor/ValueMappingEditor.js.map +1 -1
  82. package/dist/ValueMappingEditor/ValueMappingsEditor.d.ts.map +1 -1
  83. package/dist/ValueMappingEditor/ValueMappingsEditor.js.map +1 -1
  84. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +2 -2
  85. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +2 -2
  86. package/dist/cjs/FormatControls/FormatControls.js +4 -4
  87. package/dist/cjs/FormatControls/UnitSelector.js +3 -3
  88. package/dist/cjs/Legend/Legend.js +2 -2
  89. package/dist/cjs/Table/Table.js +24 -4
  90. package/dist/cjs/Table/TableToolbar.js +140 -0
  91. package/dist/cjs/Table/VirtualizedTable.js +126 -115
  92. package/dist/cjs/Table/VirtualizedTableContainer.js +5 -1
  93. package/dist/cjs/Table/hooks/useFuzzySearch.js +48 -0
  94. package/dist/cjs/TimeRangeSelector/DateTimeRangePicker.js +2 -0
  95. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +3 -3
  96. package/dist/cjs/TimeRangeSelector/utils.js +2 -2
  97. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -3
  98. package/dist/cjs/TransformsEditor/TransformEditorContainer.js +2 -2
  99. package/dist/cjs/model/action.js +43 -0
  100. package/dist/cjs/model/bits.js +113 -0
  101. package/dist/cjs/model/bytes.js +115 -0
  102. package/dist/cjs/model/constants.js +23 -0
  103. package/dist/cjs/model/currency.js +126 -0
  104. package/dist/cjs/model/date.js +297 -0
  105. package/dist/cjs/model/decimal.js +72 -0
  106. package/dist/cjs/model/formatterCache.js +120 -0
  107. package/dist/cjs/model/index.js +16 -0
  108. package/dist/cjs/model/legend.js +101 -0
  109. package/dist/cjs/model/percent.js +82 -0
  110. package/dist/cjs/model/temperature.js +72 -0
  111. package/dist/cjs/model/thresholds.js +16 -0
  112. package/dist/cjs/model/throughput.js +161 -0
  113. package/dist/cjs/model/time.js +178 -0
  114. package/dist/cjs/model/timeOption.js +2 -2
  115. package/dist/cjs/model/transforms.js +29 -0
  116. package/dist/cjs/model/types.js +16 -0
  117. package/dist/cjs/model/units.js +186 -0
  118. package/dist/cjs/model/utils.js +48 -0
  119. package/dist/cjs/theme/theme.js +44 -29
  120. package/dist/cjs/theme/typography.js +8 -7
  121. package/dist/cjs/utils/axis.js +5 -5
  122. package/dist/cjs/utils/index.js +1 -0
  123. package/dist/cjs/utils/request-interpolation.js +49 -0
  124. package/dist/model/action.d.ts +4 -0
  125. package/dist/model/action.d.ts.map +1 -0
  126. package/dist/model/action.js +27 -0
  127. package/dist/model/action.js.map +1 -0
  128. package/dist/model/bits.d.ts +12 -0
  129. package/dist/model/bits.d.ts.map +1 -0
  130. package/dist/model/bits.js +89 -0
  131. package/dist/model/bits.js.map +1 -0
  132. package/dist/model/bytes.d.ts +12 -0
  133. package/dist/model/bytes.d.ts.map +1 -0
  134. package/dist/model/bytes.js +91 -0
  135. package/dist/model/bytes.js.map +1 -0
  136. package/dist/model/constants.d.ts +2 -0
  137. package/dist/model/constants.d.ts.map +1 -0
  138. package/dist/model/constants.js +15 -0
  139. package/dist/model/constants.js.map +1 -0
  140. package/dist/model/currency.d.ts +11 -0
  141. package/dist/model/currency.d.ts.map +1 -0
  142. package/dist/model/currency.js +107 -0
  143. package/dist/model/currency.js.map +1 -0
  144. package/dist/model/date.d.ts +28 -0
  145. package/dist/model/date.d.ts.map +1 -0
  146. package/dist/model/date.js +278 -0
  147. package/dist/model/date.js.map +1 -0
  148. package/dist/model/decimal.d.ts +12 -0
  149. package/dist/model/decimal.d.ts.map +1 -0
  150. package/dist/model/decimal.js +53 -0
  151. package/dist/model/decimal.js.map +1 -0
  152. package/dist/model/formatterCache.d.ts +11 -0
  153. package/dist/model/formatterCache.d.ts.map +1 -0
  154. package/dist/model/formatterCache.js +104 -0
  155. package/dist/model/formatterCache.js.map +1 -0
  156. package/dist/model/graph.d.ts +1 -1
  157. package/dist/model/graph.js.map +1 -1
  158. package/dist/model/index.d.ts +16 -0
  159. package/dist/model/index.d.ts.map +1 -1
  160. package/dist/model/index.js +16 -0
  161. package/dist/model/index.js.map +1 -1
  162. package/dist/model/legend.d.ts +19 -0
  163. package/dist/model/legend.d.ts.map +1 -0
  164. package/dist/model/legend.js +61 -0
  165. package/dist/model/legend.js.map +1 -0
  166. package/dist/model/percent.d.ts +11 -0
  167. package/dist/model/percent.d.ts.map +1 -0
  168. package/dist/model/percent.js +63 -0
  169. package/dist/model/percent.js.map +1 -0
  170. package/dist/model/temperature.d.ts +11 -0
  171. package/dist/model/temperature.d.ts.map +1 -0
  172. package/dist/model/temperature.js +53 -0
  173. package/dist/model/temperature.js.map +1 -0
  174. package/dist/model/theme.d.ts +1 -1
  175. package/dist/model/theme.d.ts.map +1 -1
  176. package/dist/model/theme.js.map +1 -1
  177. package/dist/model/thresholds.d.ts +16 -0
  178. package/dist/model/thresholds.d.ts.map +1 -0
  179. package/dist/model/thresholds.js +15 -0
  180. package/dist/model/thresholds.js.map +1 -0
  181. package/dist/model/throughput.d.ts +12 -0
  182. package/dist/model/throughput.d.ts.map +1 -0
  183. package/dist/model/throughput.js +142 -0
  184. package/dist/model/throughput.js.map +1 -0
  185. package/dist/model/time.d.ts +23 -0
  186. package/dist/model/time.d.ts.map +1 -0
  187. package/dist/model/time.js +158 -0
  188. package/dist/model/time.js.map +1 -0
  189. package/dist/model/timeOption.d.ts +1 -1
  190. package/dist/model/timeOption.js +1 -1
  191. package/dist/model/timeOption.js.map +1 -1
  192. package/dist/model/transforms.d.ts +43 -0
  193. package/dist/model/transforms.d.ts.map +1 -0
  194. package/dist/model/transforms.js +22 -0
  195. package/dist/model/transforms.js.map +1 -0
  196. package/dist/model/types.d.ts +56 -0
  197. package/dist/model/types.d.ts.map +1 -0
  198. package/dist/model/types.js +15 -0
  199. package/dist/model/types.js.map +1 -0
  200. package/dist/model/units.d.ts +105 -0
  201. package/dist/model/units.d.ts.map +1 -0
  202. package/dist/model/units.js +132 -0
  203. package/dist/model/units.js.map +1 -0
  204. package/dist/model/utils.d.ts +4 -0
  205. package/dist/model/utils.d.ts.map +1 -0
  206. package/dist/model/utils.js +32 -0
  207. package/dist/model/utils.js.map +1 -0
  208. package/dist/theme/theme.d.ts +3 -1
  209. package/dist/theme/theme.d.ts.map +1 -1
  210. package/dist/theme/theme.js +46 -29
  211. package/dist/theme/theme.js.map +1 -1
  212. package/dist/theme/typography.d.ts +6 -4
  213. package/dist/theme/typography.d.ts.map +1 -1
  214. package/dist/theme/typography.js +8 -7
  215. package/dist/theme/typography.js.map +1 -1
  216. package/dist/utils/axis.d.ts +1 -1
  217. package/dist/utils/axis.d.ts.map +1 -1
  218. package/dist/utils/axis.js +1 -1
  219. package/dist/utils/axis.js.map +1 -1
  220. package/dist/utils/chart-actions.d.ts +1 -1
  221. package/dist/utils/chart-actions.js.map +1 -1
  222. package/dist/utils/index.d.ts +1 -0
  223. package/dist/utils/index.d.ts.map +1 -1
  224. package/dist/utils/index.js +1 -0
  225. package/dist/utils/index.js.map +1 -1
  226. package/dist/utils/request-interpolation.d.ts +6 -0
  227. package/dist/utils/request-interpolation.d.ts.map +1 -0
  228. package/dist/utils/request-interpolation.js +33 -0
  229. package/dist/utils/request-interpolation.js.map +1 -0
  230. package/dist/utils/variable-interpolation.d.ts +1 -1
  231. package/dist/utils/variable-interpolation.js.map +1 -1
  232. package/package.json +6 -2
@@ -0,0 +1,278 @@
1
+ // Copyright 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 DATE_GROUP = 'Date';
14
+ export const DATE_GROUP_CONFIG = {
15
+ label: 'Date & Time'
16
+ };
17
+ export const DATE_UNIT_CONFIG = {
18
+ 'datetime-iso': {
19
+ group: DATE_GROUP,
20
+ label: 'DateTime (GMT)'
21
+ },
22
+ 'datetime-us': {
23
+ group: DATE_GROUP,
24
+ label: 'DateTime (US-East)'
25
+ },
26
+ 'datetime-local': {
27
+ group: DATE_GROUP,
28
+ label: 'DateTime (Browser Local)'
29
+ },
30
+ 'date-iso': {
31
+ group: DATE_GROUP,
32
+ label: 'Date (GMT)'
33
+ },
34
+ 'date-us': {
35
+ group: DATE_GROUP,
36
+ label: 'Date (US-East)'
37
+ },
38
+ 'date-local': {
39
+ group: DATE_GROUP,
40
+ label: 'Date (Browser Local)'
41
+ },
42
+ 'time-local': {
43
+ group: DATE_GROUP,
44
+ label: 'Time (Browser Local)'
45
+ },
46
+ 'time-iso': {
47
+ group: DATE_GROUP,
48
+ label: 'Time (GMT)'
49
+ },
50
+ 'time-us': {
51
+ group: DATE_GROUP,
52
+ label: 'Time (US-East)'
53
+ },
54
+ 'relative-time': {
55
+ group: DATE_GROUP,
56
+ label: 'Relative Time'
57
+ },
58
+ 'unix-timestamp': {
59
+ group: DATE_GROUP,
60
+ label: 'Unix Timestamp (s)'
61
+ },
62
+ 'unix-timestamp-ms': {
63
+ group: DATE_GROUP,
64
+ label: 'Unix Timestamp (ms)'
65
+ }
66
+ };
67
+ /**
68
+ * Converts a numeric value to a Date object.
69
+ * Handles both Unix timestamps (seconds) and millisecond timestamps.
70
+ */ function valueToDate(value) {
71
+ // Timestamp detection logic with special case handling
72
+ // Main threshold stays at 10 billion to maintain existing behavior
73
+ // Handle special edge cases explicitly
74
+ // Special case: negative timestamps
75
+ if (value < 0) {
76
+ // For negative values, check magnitude to distinguish seconds vs milliseconds
77
+ // Large negative values (> 1 billion in magnitude) are likely milliseconds
78
+ // Small negative values are likely seconds (rare edge case)
79
+ if (Math.abs(value) > 10000000000) {
80
+ return new Date(value); // milliseconds
81
+ } else {
82
+ return new Date(value * 1000); // seconds
83
+ }
84
+ }
85
+ // Special case: year 9999 in seconds (~253402300799)
86
+ // This is a very specific edge case for far-future timestamps
87
+ if (value >= 250000000000 && value <= 260000000000) {
88
+ // Check if this looks like year 9999 in seconds
89
+ const asSeconds = new Date(value * 1000);
90
+ const year = asSeconds.getUTCFullYear();
91
+ if (year >= 9999) {
92
+ return asSeconds; // seconds
93
+ }
94
+ }
95
+ const SECONDS_THRESHOLD = 10000000000; // ~year 2286 - original threshold
96
+ if (value < SECONDS_THRESHOLD) {
97
+ // Assume it's in seconds
98
+ return new Date(value * 1000);
99
+ } else {
100
+ // Assume it's in milliseconds
101
+ return new Date(value);
102
+ }
103
+ }
104
+ /**
105
+ * Formats a relative time string using the Intl.RelativeTimeFormat API.
106
+ */ function formatRelativeTime(date, referenceTime, locale) {
107
+ const referenceDate = new Date(referenceTime);
108
+ const diffMs = date.getTime() - referenceDate.getTime();
109
+ const units = [
110
+ {
111
+ unit: 'year',
112
+ ms: 1000 * 60 * 60 * 24 * 365
113
+ },
114
+ {
115
+ unit: 'month',
116
+ ms: 1000 * 60 * 60 * 24 * 30
117
+ },
118
+ {
119
+ unit: 'week',
120
+ ms: 1000 * 60 * 60 * 24 * 7
121
+ },
122
+ {
123
+ unit: 'day',
124
+ ms: 1000 * 60 * 60 * 24
125
+ },
126
+ {
127
+ unit: 'hour',
128
+ ms: 1000 * 60 * 60
129
+ },
130
+ {
131
+ unit: 'minute',
132
+ ms: 1000 * 60
133
+ },
134
+ {
135
+ unit: 'second',
136
+ ms: 1000
137
+ }
138
+ ];
139
+ for (const { unit, ms } of units){
140
+ // Determine the value for the current unit, ensuring it's an integer for Intl.RelativeTimeFormat
141
+ const value = Math.round(diffMs / ms);
142
+ // If the absolute value is 1 or more, use this unit
143
+ if (Math.abs(value) >= 1) {
144
+ const rtf = new Intl.RelativeTimeFormat(locale, {
145
+ numeric: 'auto'
146
+ });
147
+ return rtf.format(value, unit);
148
+ }
149
+ }
150
+ // If less than a second, show "now" or "0 seconds"
151
+ const rtf = new Intl.RelativeTimeFormat(locale, {
152
+ numeric: 'auto'
153
+ });
154
+ return rtf.format(0, 'second');
155
+ }
156
+ /**
157
+ * Gets the browser's preferred locale with comprehensive fallbacks.
158
+ */ const getBrowserLocale = ()=>{
159
+ if (typeof navigator !== 'undefined') {
160
+ if (navigator.language) return navigator.language;
161
+ if (navigator.languages && navigator.languages.length > 0) {
162
+ const firstLanguage = navigator.languages[0];
163
+ if (firstLanguage) return firstLanguage;
164
+ }
165
+ // Legacy fallbacks for older browsers
166
+ const nav = navigator;
167
+ if (nav.userLanguage) return nav.userLanguage;
168
+ if (nav.browserLanguage) return nav.browserLanguage;
169
+ if (nav.systemLanguage) return nav.systemLanguage;
170
+ }
171
+ // Node.js or server-side fallback, or if navigator is not available/empty
172
+ return Intl.DateTimeFormat().resolvedOptions().locale || 'en-US';
173
+ };
174
+ export function formatDate(value, options = {}) {
175
+ const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
176
+ const { unit = 'datetime-local', locale = getBrowserLocale(), timeZone = systemTimeZone, referenceTime = Date.now() } = options;
177
+ // Handle raw timestamp display
178
+ if (unit === 'unix-timestamp') {
179
+ // Ensure it's in seconds. If it looks like milliseconds, convert.
180
+ const timestamp = value > 1000000000000 ? Math.floor(value / 1000) : value;
181
+ return timestamp.toString();
182
+ }
183
+ if (unit === 'unix-timestamp-ms') {
184
+ // Ensure it's in milliseconds. If it looks like seconds, convert.
185
+ // Use 100 billion as threshold - values < 100B are likely seconds, >= 100B are likely milliseconds
186
+ // This distinguishes between 999999999 (seconds) and 999999999000 (milliseconds)
187
+ const MILLISECONDS_THRESHOLD = 100000000000; // 100 billion
188
+ const timestamp = value < MILLISECONDS_THRESHOLD ? value * 1000 : value;
189
+ return Math.floor(timestamp).toString();
190
+ }
191
+ const date = valueToDate(value);
192
+ // Handle relative time
193
+ if (unit === 'relative-time') {
194
+ return formatRelativeTime(date, referenceTime, locale);
195
+ }
196
+ // Configure Intl.DateTimeFormat options based on unit
197
+ const formatOptions = {
198
+ timeZone
199
+ };
200
+ switch(unit){
201
+ case 'datetime-iso':
202
+ // datetime-iso should ALWAYS show GMT/UTC time
203
+ return date.toISOString();
204
+ case 'datetime-us':
205
+ {
206
+ // datetime-us should ALWAYS show date in US Eastern timezone
207
+ formatOptions.timeZone = 'America/New_York';
208
+ formatOptions.year = 'numeric';
209
+ formatOptions.month = '2-digit';
210
+ formatOptions.day = '2-digit';
211
+ formatOptions.hour = '2-digit';
212
+ formatOptions.minute = '2-digit';
213
+ formatOptions.second = '2-digit';
214
+ formatOptions.hour12 = true; // 12-hour format with AM/PM
215
+ const formatter = new Intl.DateTimeFormat('en-US', formatOptions);
216
+ return formatter.format(date);
217
+ }
218
+ case 'datetime-local':
219
+ // datetime-local should use the browser's local timezone (detected automatically)
220
+ // Don't override timeZone - let it use the detected system timezone
221
+ formatOptions.year = 'numeric';
222
+ formatOptions.month = '2-digit';
223
+ formatOptions.day = '2-digit';
224
+ formatOptions.hour = '2-digit';
225
+ formatOptions.minute = '2-digit';
226
+ formatOptions.second = '2-digit';
227
+ formatOptions.hour12 = false; // 24-hour format
228
+ break;
229
+ case 'date-iso':
230
+ // date-iso should ALWAYS show GMT/UTC date
231
+ return date.toISOString().split('T')[0];
232
+ case 'date-us':
233
+ {
234
+ // date-us should ALWAYS show date in US Eastern timezone
235
+ formatOptions.timeZone = 'America/New_York';
236
+ formatOptions.year = 'numeric';
237
+ formatOptions.month = '2-digit';
238
+ formatOptions.day = '2-digit';
239
+ const formatter = new Intl.DateTimeFormat('en-US', formatOptions);
240
+ return formatter.format(date);
241
+ }
242
+ case 'date-local':
243
+ formatOptions.year = 'numeric';
244
+ formatOptions.month = '2-digit';
245
+ formatOptions.day = '2-digit';
246
+ break;
247
+ case 'time-local':
248
+ formatOptions.hour = '2-digit';
249
+ formatOptions.minute = '2-digit';
250
+ formatOptions.second = '2-digit';
251
+ formatOptions.hour12 = false; // 24-hour format
252
+ break;
253
+ case 'time-iso':
254
+ // time-iso should ALWAYS show GMT/UTC time
255
+ return date.toISOString().split('T')[1].replace('Z', '');
256
+ case 'time-us':
257
+ {
258
+ // time-us should show time in US-East timezone (Eastern Time)
259
+ formatOptions.timeZone = 'America/New_York';
260
+ formatOptions.hour = '2-digit';
261
+ formatOptions.minute = '2-digit';
262
+ formatOptions.second = '2-digit';
263
+ formatOptions.hour12 = true;
264
+ return new Intl.DateTimeFormat('en-US', formatOptions).format(date);
265
+ }
266
+ default:
267
+ {
268
+ // This ensures that all DateUnits are handled at compile time.
269
+ const exhaustive = unit;
270
+ throw new Error(`Unknown date unit: ${exhaustive}`);
271
+ }
272
+ }
273
+ // For all other units, use Intl.DateTimeFormat with the specified locale and options
274
+ const formatter = new Intl.DateTimeFormat(locale, formatOptions);
275
+ return formatter.format(date);
276
+ }
277
+
278
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/date.ts"],"sourcesContent":["// Copyright 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\ntype DateUnits =\n | 'datetime-iso'\n | 'datetime-us'\n | 'datetime-local'\n | 'date-iso'\n | 'date-us'\n | 'date-local'\n | 'time-local'\n | 'time-iso'\n | 'time-us'\n | 'relative-time'\n | 'unix-timestamp'\n | 'unix-timestamp-ms';\n\nexport type DateFormatOptions = {\n unit?: DateUnits;\n /**\n * The locale to use for formatting. Defaults to the system's locale.\n */\n locale?: string;\n /**\n * The timezone to use for formatting. Defaults to the user's local timezone.\n */\n timeZone?: string;\n /**\n * For relative time formatting, the reference time to compare against.\n * Defaults to current time.\n */\n referenceTime?: number;\n /**\n * This property is not used for date formatting, but is included for\n * compatibility with the FormatControls UI component.\n */\n decimalPlaces?: number;\n};\n\nconst DATE_GROUP = 'Date';\n\nexport const DATE_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Date & Time',\n};\n\nexport const DATE_UNIT_CONFIG: Readonly<Record<DateUnits, UnitConfig>> = {\n 'datetime-iso': {\n group: DATE_GROUP,\n label: 'DateTime (GMT)',\n },\n 'datetime-us': {\n group: DATE_GROUP,\n label: 'DateTime (US-East)',\n },\n 'datetime-local': {\n group: DATE_GROUP,\n label: 'DateTime (Browser Local)',\n },\n 'date-iso': {\n group: DATE_GROUP,\n label: 'Date (GMT)',\n },\n 'date-us': {\n group: DATE_GROUP,\n label: 'Date (US-East)',\n },\n 'date-local': {\n group: DATE_GROUP,\n label: 'Date (Browser Local)',\n },\n 'time-local': {\n group: DATE_GROUP,\n label: 'Time (Browser Local)',\n },\n 'time-iso': {\n group: DATE_GROUP,\n label: 'Time (GMT)',\n },\n 'time-us': {\n group: DATE_GROUP,\n label: 'Time (US-East)',\n },\n 'relative-time': {\n group: DATE_GROUP,\n label: 'Relative Time',\n },\n 'unix-timestamp': {\n group: DATE_GROUP,\n label: 'Unix Timestamp (s)',\n },\n 'unix-timestamp-ms': {\n group: DATE_GROUP,\n label: 'Unix Timestamp (ms)',\n },\n};\n\n/**\n * Converts a numeric value to a Date object.\n * Handles both Unix timestamps (seconds) and millisecond timestamps.\n */\nfunction valueToDate(value: number): Date {\n // Timestamp detection logic with special case handling\n // Main threshold stays at 10 billion to maintain existing behavior\n // Handle special edge cases explicitly\n\n // Special case: negative timestamps\n if (value < 0) {\n // For negative values, check magnitude to distinguish seconds vs milliseconds\n // Large negative values (> 1 billion in magnitude) are likely milliseconds\n // Small negative values are likely seconds (rare edge case)\n if (Math.abs(value) > 10000000000) {\n return new Date(value); // milliseconds\n } else {\n return new Date(value * 1000); // seconds\n }\n }\n\n // Special case: year 9999 in seconds (~253402300799)\n // This is a very specific edge case for far-future timestamps\n if (value >= 250000000000 && value <= 260000000000) {\n // Check if this looks like year 9999 in seconds\n const asSeconds = new Date(value * 1000);\n const year = asSeconds.getUTCFullYear();\n if (year >= 9999) {\n return asSeconds; // seconds\n }\n }\n\n const SECONDS_THRESHOLD = 10000000000; // ~year 2286 - original threshold\n\n if (value < SECONDS_THRESHOLD) {\n // Assume it's in seconds\n return new Date(value * 1000);\n } else {\n // Assume it's in milliseconds\n return new Date(value);\n }\n}\n\n/**\n * Formats a relative time string using the Intl.RelativeTimeFormat API.\n */\nfunction formatRelativeTime(date: Date, referenceTime: number, locale: string): string {\n const referenceDate = new Date(referenceTime);\n const diffMs = date.getTime() - referenceDate.getTime();\n\n const units = [\n { unit: 'year', ms: 1000 * 60 * 60 * 24 * 365 },\n { unit: 'month', ms: 1000 * 60 * 60 * 24 * 30 },\n { unit: 'week', ms: 1000 * 60 * 60 * 24 * 7 },\n { unit: 'day', ms: 1000 * 60 * 60 * 24 },\n { unit: 'hour', ms: 1000 * 60 * 60 },\n { unit: 'minute', ms: 1000 * 60 },\n { unit: 'second', ms: 1000 },\n ] as const;\n\n for (const { unit, ms } of units) {\n // Determine the value for the current unit, ensuring it's an integer for Intl.RelativeTimeFormat\n const value = Math.round(diffMs / ms);\n // If the absolute value is 1 or more, use this unit\n if (Math.abs(value) >= 1) {\n const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });\n return rtf.format(value, unit);\n }\n }\n\n // If less than a second, show \"now\" or \"0 seconds\"\n const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });\n return rtf.format(0, 'second');\n}\n\n/**\n * Gets the browser's preferred locale with comprehensive fallbacks.\n */\nconst getBrowserLocale = (): string => {\n if (typeof navigator !== 'undefined') {\n if (navigator.language) return navigator.language;\n if (navigator.languages && navigator.languages.length > 0) {\n const firstLanguage = navigator.languages[0];\n if (firstLanguage) return firstLanguage;\n }\n // Legacy fallbacks for older browsers\n const nav = navigator as Navigator & {\n userLanguage?: string;\n browserLanguage?: string;\n systemLanguage?: string;\n };\n if (nav.userLanguage) return nav.userLanguage;\n if (nav.browserLanguage) return nav.browserLanguage;\n if (nav.systemLanguage) return nav.systemLanguage;\n }\n // Node.js or server-side fallback, or if navigator is not available/empty\n return Intl.DateTimeFormat().resolvedOptions().locale || 'en-US';\n};\n\nexport function formatDate(value: number, options: DateFormatOptions = {}): string {\n const systemTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;\n\n const {\n unit = 'datetime-local',\n locale = getBrowserLocale(),\n timeZone = systemTimeZone,\n referenceTime = Date.now(),\n } = options;\n\n // Handle raw timestamp display\n if (unit === 'unix-timestamp') {\n // Ensure it's in seconds. If it looks like milliseconds, convert.\n const timestamp = value > 1000000000000 ? Math.floor(value / 1000) : value;\n return timestamp.toString();\n }\n\n if (unit === 'unix-timestamp-ms') {\n // Ensure it's in milliseconds. If it looks like seconds, convert.\n // Use 100 billion as threshold - values < 100B are likely seconds, >= 100B are likely milliseconds\n // This distinguishes between 999999999 (seconds) and 999999999000 (milliseconds)\n const MILLISECONDS_THRESHOLD = 100000000000; // 100 billion\n const timestamp = value < MILLISECONDS_THRESHOLD ? value * 1000 : value;\n return Math.floor(timestamp).toString();\n }\n\n const date = valueToDate(value);\n\n // Handle relative time\n if (unit === 'relative-time') {\n return formatRelativeTime(date, referenceTime, locale);\n }\n\n // Configure Intl.DateTimeFormat options based on unit\n const formatOptions: Intl.DateTimeFormatOptions = {\n timeZone, // This will be overridden for specific units that need different timezones\n };\n\n switch (unit) {\n case 'datetime-iso':\n // datetime-iso should ALWAYS show GMT/UTC time\n return date.toISOString();\n\n case 'datetime-us': {\n // datetime-us should ALWAYS show date in US Eastern timezone\n formatOptions.timeZone = 'America/New_York';\n formatOptions.year = 'numeric';\n formatOptions.month = '2-digit';\n formatOptions.day = '2-digit';\n formatOptions.hour = '2-digit';\n formatOptions.minute = '2-digit';\n formatOptions.second = '2-digit';\n formatOptions.hour12 = true; // 12-hour format with AM/PM\n const formatter = new Intl.DateTimeFormat('en-US', formatOptions);\n return formatter.format(date);\n }\n\n case 'datetime-local':\n // datetime-local should use the browser's local timezone (detected automatically)\n // Don't override timeZone - let it use the detected system timezone\n formatOptions.year = 'numeric';\n formatOptions.month = '2-digit';\n formatOptions.day = '2-digit';\n formatOptions.hour = '2-digit';\n formatOptions.minute = '2-digit';\n formatOptions.second = '2-digit';\n formatOptions.hour12 = false; // 24-hour format\n break;\n\n case 'date-iso':\n // date-iso should ALWAYS show GMT/UTC date\n return date.toISOString().split('T')[0]!;\n\n case 'date-us': {\n // date-us should ALWAYS show date in US Eastern timezone\n formatOptions.timeZone = 'America/New_York';\n formatOptions.year = 'numeric';\n formatOptions.month = '2-digit';\n formatOptions.day = '2-digit';\n const formatter = new Intl.DateTimeFormat('en-US', formatOptions);\n return formatter.format(date);\n }\n\n case 'date-local':\n formatOptions.year = 'numeric';\n formatOptions.month = '2-digit';\n formatOptions.day = '2-digit';\n break;\n\n case 'time-local':\n formatOptions.hour = '2-digit';\n formatOptions.minute = '2-digit';\n formatOptions.second = '2-digit';\n formatOptions.hour12 = false; // 24-hour format\n break;\n\n case 'time-iso':\n // time-iso should ALWAYS show GMT/UTC time\n return date.toISOString().split('T')[1]!.replace('Z', '');\n\n case 'time-us': {\n // time-us should show time in US-East timezone (Eastern Time)\n formatOptions.timeZone = 'America/New_York';\n formatOptions.hour = '2-digit';\n formatOptions.minute = '2-digit';\n formatOptions.second = '2-digit';\n formatOptions.hour12 = true;\n return new Intl.DateTimeFormat('en-US', formatOptions).format(date);\n }\n\n default: {\n // This ensures that all DateUnits are handled at compile time.\n const exhaustive: never = unit;\n throw new Error(`Unknown date unit: ${exhaustive}`);\n }\n }\n\n // For all other units, use Intl.DateTimeFormat with the specified locale and options\n const formatter = new Intl.DateTimeFormat(locale, formatOptions);\n return formatter.format(date);\n}\n"],"names":["DATE_GROUP","DATE_GROUP_CONFIG","label","DATE_UNIT_CONFIG","group","valueToDate","value","Math","abs","Date","asSeconds","year","getUTCFullYear","SECONDS_THRESHOLD","formatRelativeTime","date","referenceTime","locale","referenceDate","diffMs","getTime","units","unit","ms","round","rtf","Intl","RelativeTimeFormat","numeric","format","getBrowserLocale","navigator","language","languages","length","firstLanguage","nav","userLanguage","browserLanguage","systemLanguage","DateTimeFormat","resolvedOptions","formatDate","options","systemTimeZone","timeZone","now","timestamp","floor","toString","MILLISECONDS_THRESHOLD","formatOptions","toISOString","month","day","hour","minute","second","hour12","formatter","split","replace","exhaustive","Error"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AA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AI,GAAG;YACrBJ,cAAcK,MAAM,GAAG;YACvBL,cAAcM,MAAM,GAAG;YACvBN,cAAcO,MAAM,GAAG,OAAO,iBAAiB;YAC/C;QAEF,KAAK;YACH,2CAA2C;YAC3C,OAAO3C,KAAKqC,WAAW,GAAGQ,KAAK,CAAC,IAAI,CAAC,EAAE,CAAEC,OAAO,CAAC,KAAK;QAExD,KAAK;YAAW;gBACd,8DAA8D;gBAC9DV,cAAcN,QAAQ,GAAG;gBACzBM,cAAcI,IAAI,GAAG;gBACrBJ,cAAcK,MAAM,GAAG;gBACvBL,cAAcM,MAAM,GAAG;gBACvBN,cAAcO,MAAM,GAAG;gBACvB,OAAO,IAAIhC,KAAKc,cAAc,CAAC,SAASW,eAAetB,MAAM,CAACd;YAChE;QAEA;YAAS;gBACP,+DAA+D;gBAC/D,MAAM+C,aAAoBxC;gBAC1B,MAAM,IAAIyC,MAAM,CAAC,mBAAmB,EAAED,YAAY;YACpD;IACF;IAEA,qFAAqF;IACrF,MAAMH,YAAY,IAAIjC,KAAKc,cAAc,CAACvB,QAAQkC;IAClD,OAAOQ,UAAU9B,MAAM,CAACd;AAC1B"}
@@ -0,0 +1,12 @@
1
+ import { UnitGroupConfig, UnitConfig } from './types';
2
+ type DecimalUnit = 'decimal';
3
+ export type DecimalFormatOptions = {
4
+ unit?: DecimalUnit;
5
+ decimalPlaces?: number;
6
+ shortValues?: boolean;
7
+ };
8
+ export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
9
+ export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>>;
10
+ export declare function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string;
11
+ export {};
12
+ //# sourceMappingURL=decimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../src/model/decimal.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,KAAK,WAAW,GAAG,SAAS,CAAC;AAC7B,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CA4BzG"}
@@ -0,0 +1,53 @@
1
+ // Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';
14
+ import { getFormatterFromCache } from './formatterCache';
15
+ import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
16
+ export const DECIMAL_GROUP_CONFIG = {
17
+ label: 'Decimal',
18
+ decimalPlaces: true,
19
+ shortValues: true
20
+ };
21
+ export const DECIMAL_UNIT_CONFIG = {
22
+ decimal: {
23
+ group: 'Decimal',
24
+ label: 'Decimal'
25
+ }
26
+ };
27
+ export function formatDecimal(value, { shortValues, decimalPlaces }) {
28
+ const formatterOptions = {
29
+ style: 'decimal',
30
+ useGrouping: true
31
+ };
32
+ if (shouldShortenValues(shortValues)) {
33
+ formatterOptions.notation = 'compact';
34
+ }
35
+ if (hasDecimalPlaces(decimalPlaces)) {
36
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
37
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
38
+ } else {
39
+ if (shouldShortenValues(shortValues)) {
40
+ formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
41
+ }
42
+ }
43
+ const key = [
44
+ formatterOptions.style,
45
+ formatterOptions.useGrouping,
46
+ formatterOptions.notation,
47
+ formatterOptions.maximumSignificantDigits,
48
+ decimalPlaces
49
+ ];
50
+ return getFormatterFromCache(key, 'decimal', formatterOptions, 'en-US')(value);
51
+ }
52
+
53
+ //# sourceMappingURL=decimal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/decimal.ts"],"sourcesContent":["// Copyright 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 { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { getFormatterFromCache } from './formatterCache';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\ntype DecimalUnit = 'decimal';\nexport type DecimalFormatOptions = {\n unit?: DecimalUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>> = {\n decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const key = [\n formatterOptions.style,\n formatterOptions.useGrouping,\n formatterOptions.notation,\n formatterOptions.maximumSignificantDigits,\n decimalPlaces,\n ];\n\n return getFormatterFromCache(key, 'decimal', formatterOptions, 'en-US')(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","getFormatterFromCache","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DECIMAL_GROUP_CONFIG","label","decimalPlaces","shortValues","DECIMAL_UNIT_CONFIG","decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","key"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,cAAc;AACrD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAQpF,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASM,cAAcC,KAAa,EAAE,EAAEL,WAAW,EAAED,aAAa,EAAwB;IAC/F,MAAMO,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIZ,oBAAoBI,cAAc;QACpCM,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAIf,iBAAiBK,gBAAgB;QACnCO,iBAAiBI,qBAAqB,GAAGf,mBAAmBI;QAC5DO,iBAAiBK,qBAAqB,GAAGhB,mBAAmBI;IAC9D,OAAO;QACL,IAAIH,oBAAoBI,cAAc;YACpCM,iBAAiBM,wBAAwB,GAAGpB;QAC9C;IACF;IAEA,MAAMqB,MAAM;QACVP,iBAAiBC,KAAK;QACtBD,iBAAiBE,WAAW;QAC5BF,iBAAiBG,QAAQ;QACzBH,iBAAiBM,wBAAwB;QACzCb;KACD;IAED,OAAON,sBAAsBoB,KAAK,WAAWP,kBAAkB,SAASD;AAC1E"}
@@ -0,0 +1,11 @@
1
+ type FormatFn = (value: number | bigint) => string;
2
+ type InputType = 'time' | 'temperature' | 'bytes' | 'bits' | 'decimal' | 'currency' | 'percent' | 'throughput';
3
+ type Locals = 'en-US' | 'en-GB';
4
+ export declare function getFormatterFromCache(key: Array<string | number | boolean | undefined>, inputType: InputType, formatterOptions: Intl.NumberFormatOptions, locals?: Locals): FormatFn;
5
+ export interface IFormatterStats {
6
+ countCacheItems: (inputType: InputType | 'all') => number;
7
+ getKeys: (inputType: InputType) => string[];
8
+ }
9
+ export declare const getFormatterStats: () => IFormatterStats;
10
+ export {};
11
+ //# sourceMappingURL=formatterCache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formatterCache.d.ts","sourceRoot":"","sources":["../../src/model/formatterCache.ts"],"names":[],"mappings":"AAaA,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;AACnD,KAAK,SAAS,GAAG,MAAM,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,YAAY,CAAC;AAC/G,KAAK,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAqChC,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC,EACjD,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,IAAI,CAAC,mBAAmB,EAC1C,MAAM,GAAE,MAAgB,GACvB,QAAQ,CAcV;AAGD,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,KAAK,KAAK,MAAM,CAAC;IAC1D,OAAO,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,MAAM,EAAE,CAAC;CAC7C;AAED,eAAO,MAAM,iBAAiB,QAAO,eAcpC,CAAC"}
@@ -0,0 +1,104 @@
1
+ // Copyright 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
+ /**
14
+ * REASONING FOR CLUSTERING (Map-of-Maps):
15
+ *
16
+ * 1. PERSISTENCE & REUSE: Intl.NumberFormat instantiation is CPU-heavy due to
17
+ * locale/data lookups. Clustering allows 100x faster reuse via caching.
18
+ *
19
+ *
20
+ * 2. LOOKUP PERFORMANCE: Smaller, specialized Maps reduce the risk of hash
21
+ * collisions, ensuring O(1) retrieval time remains consistent even as
22
+ * the total number of formatters across the app grows.
23
+ *
24
+ * 3. GARBAGE COLLECTION & STATS: Categorization allows for targeted memory
25
+ * monitoring and easier debugging of which specific data types are
26
+ * consuming the most resources.
27
+ */ const TIME_FORMATTER_CACHE = new Map();
28
+ const DECIMAL_FORMATTER_CACHE = new Map();
29
+ const BITS_FORMATTER_CACHE = new Map();
30
+ const BYTES_FORMATTER_CACHE = new Map();
31
+ const CURRENCY_FORMATTER_CACHE = new Map();
32
+ const PERCENT_FORMATTER_CACHE = new Map();
33
+ const TEMPERATURE_FORMATTER_CACHE = new Map();
34
+ const THROUGHPUT_FORMATTER_CACHE = new Map();
35
+ const ALL_FORMATTERS = new Map([
36
+ [
37
+ 'time',
38
+ TIME_FORMATTER_CACHE
39
+ ],
40
+ [
41
+ 'decimal',
42
+ DECIMAL_FORMATTER_CACHE
43
+ ],
44
+ [
45
+ 'bits',
46
+ BITS_FORMATTER_CACHE
47
+ ],
48
+ [
49
+ 'bytes',
50
+ BYTES_FORMATTER_CACHE
51
+ ],
52
+ [
53
+ 'currency',
54
+ CURRENCY_FORMATTER_CACHE
55
+ ],
56
+ [
57
+ 'percent',
58
+ PERCENT_FORMATTER_CACHE
59
+ ],
60
+ [
61
+ 'temperature',
62
+ TEMPERATURE_FORMATTER_CACHE
63
+ ],
64
+ [
65
+ 'throughput',
66
+ THROUGHPUT_FORMATTER_CACHE
67
+ ]
68
+ ]);
69
+ export function getFormatterFromCache(key, inputType, formatterOptions, locals = 'en-US') {
70
+ const compoundKey = `${key.filter((k)=>![
71
+ undefined,
72
+ null,
73
+ '',
74
+ NaN
75
+ ].includes(k)).join('|')}|${locals}`;
76
+ const inputTypeFormatters = ALL_FORMATTERS.get(inputType);
77
+ if (!inputTypeFormatters) throw new Error('No formatter found for the input type');
78
+ const formatter = inputTypeFormatters.get(compoundKey);
79
+ if (formatter) {
80
+ return formatter.format;
81
+ }
82
+ const newFormatter = Intl.NumberFormat(locals, formatterOptions);
83
+ inputTypeFormatters?.set(`${compoundKey}`, newFormatter);
84
+ return newFormatter.format;
85
+ }
86
+ export const getFormatterStats = ()=>{
87
+ const countCacheItems = (inputType)=>{
88
+ if (inputType !== 'all') {
89
+ return ALL_FORMATTERS.get(inputType)?.size ?? 0;
90
+ }
91
+ return Array.from(ALL_FORMATTERS.values()).reduce((acc, map)=>acc + (map?.size ?? 0), 0);
92
+ };
93
+ const getKeys = (inputType)=>{
94
+ return [
95
+ ...ALL_FORMATTERS.get(inputType)?.keys() || []
96
+ ];
97
+ };
98
+ return {
99
+ countCacheItems,
100
+ getKeys
101
+ };
102
+ };
103
+
104
+ //# sourceMappingURL=formatterCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/formatterCache.ts"],"sourcesContent":["// Copyright 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\ntype FormatFn = (value: number | bigint) => string;\ntype InputType = 'time' | 'temperature' | 'bytes' | 'bits' | 'decimal' | 'currency' | 'percent' | 'throughput';\ntype Locals = 'en-US' | 'en-GB';\n\n/**\n * REASONING FOR CLUSTERING (Map-of-Maps):\n *\n * 1. PERSISTENCE & REUSE: Intl.NumberFormat instantiation is CPU-heavy due to\n * locale/data lookups. Clustering allows 100x faster reuse via caching.\n *\n *\n * 2. LOOKUP PERFORMANCE: Smaller, specialized Maps reduce the risk of hash\n * collisions, ensuring O(1) retrieval time remains consistent even as\n * the total number of formatters across the app grows.\n *\n * 3. GARBAGE COLLECTION & STATS: Categorization allows for targeted memory\n * monitoring and easier debugging of which specific data types are\n * consuming the most resources.\n */\nconst TIME_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst DECIMAL_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst BITS_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst BYTES_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst CURRENCY_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst PERCENT_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst TEMPERATURE_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\nconst THROUGHPUT_FORMATTER_CACHE = new Map<string, Intl.NumberFormat>();\n\nconst ALL_FORMATTERS: Map<InputType, Map<string, Intl.NumberFormat>> = new Map([\n ['time', TIME_FORMATTER_CACHE],\n ['decimal', DECIMAL_FORMATTER_CACHE],\n ['bits', BITS_FORMATTER_CACHE],\n ['bytes', BYTES_FORMATTER_CACHE],\n ['currency', CURRENCY_FORMATTER_CACHE],\n ['percent', PERCENT_FORMATTER_CACHE],\n ['temperature', TEMPERATURE_FORMATTER_CACHE],\n ['throughput', THROUGHPUT_FORMATTER_CACHE],\n]);\n\nexport function getFormatterFromCache(\n key: Array<string | number | boolean | undefined>,\n inputType: InputType,\n formatterOptions: Intl.NumberFormatOptions,\n locals: Locals = 'en-US'\n): FormatFn {\n const compoundKey = `${key.filter((k) => !([undefined, null, '', NaN] as unknown[]).includes(k)).join('|')}|${locals}`;\n const inputTypeFormatters = ALL_FORMATTERS.get(inputType);\n if (!inputTypeFormatters) throw new Error('No formatter found for the input type');\n\n const formatter = inputTypeFormatters.get(compoundKey);\n if (formatter) {\n return formatter.format;\n }\n\n const newFormatter = Intl.NumberFormat(locals, formatterOptions);\n inputTypeFormatters?.set(`${compoundKey}`, newFormatter);\n\n return newFormatter.format;\n}\n\n/* This is a small utility for unit tests */\nexport interface IFormatterStats {\n countCacheItems: (inputType: InputType | 'all') => number;\n getKeys: (inputType: InputType) => string[];\n}\n\nexport const getFormatterStats = (): IFormatterStats => {\n const countCacheItems = (inputType: InputType | 'all'): number => {\n if (inputType !== 'all') {\n return ALL_FORMATTERS.get(inputType)?.size ?? 0;\n }\n\n return Array.from(ALL_FORMATTERS.values()).reduce((acc, map) => acc + (map?.size ?? 0), 0);\n };\n\n const getKeys = (inputType: InputType): string[] => {\n return [...(ALL_FORMATTERS.get(inputType)?.keys() || [])];\n };\n\n return { countCacheItems, getKeys };\n};\n"],"names":["TIME_FORMATTER_CACHE","Map","DECIMAL_FORMATTER_CACHE","BITS_FORMATTER_CACHE","BYTES_FORMATTER_CACHE","CURRENCY_FORMATTER_CACHE","PERCENT_FORMATTER_CACHE","TEMPERATURE_FORMATTER_CACHE","THROUGHPUT_FORMATTER_CACHE","ALL_FORMATTERS","getFormatterFromCache","key","inputType","formatterOptions","locals","compoundKey","filter","k","undefined","NaN","includes","join","inputTypeFormatters","get","Error","formatter","format","newFormatter","Intl","NumberFormat","set","getFormatterStats","countCacheItems","size","Array","from","values","reduce","acc","map","getKeys","keys"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAMjC;;;;;;;;;;;;;;CAcC,GACD,MAAMA,uBAAuB,IAAIC;AACjC,MAAMC,0BAA0B,IAAID;AACpC,MAAME,uBAAuB,IAAIF;AACjC,MAAMG,wBAAwB,IAAIH;AAClC,MAAMI,2BAA2B,IAAIJ;AACrC,MAAMK,0BAA0B,IAAIL;AACpC,MAAMM,8BAA8B,IAAIN;AACxC,MAAMO,6BAA6B,IAAIP;AAEvC,MAAMQ,iBAAiE,IAAIR,IAAI;IAC7E;QAAC;QAAQD;KAAqB;IAC9B;QAAC;QAAWE;KAAwB;IACpC;QAAC;QAAQC;KAAqB;IAC9B;QAAC;QAASC;KAAsB;IAChC;QAAC;QAAYC;KAAyB;IACtC;QAAC;QAAWC;KAAwB;IACpC;QAAC;QAAeC;KAA4B;IAC5C;QAAC;QAAcC;KAA2B;CAC3C;AAED,OAAO,SAASE,sBACdC,GAAiD,EACjDC,SAAoB,EACpBC,gBAA0C,EAC1CC,SAAiB,OAAO;IAExB,MAAMC,cAAc,GAAGJ,IAAIK,MAAM,CAAC,CAACC,IAAM,CAAC,AAAC;YAACC;YAAW;YAAM;YAAIC;SAAI,CAAeC,QAAQ,CAACH,IAAII,IAAI,CAAC,KAAK,CAAC,EAAEP,QAAQ;IACtH,MAAMQ,sBAAsBb,eAAec,GAAG,CAACX;IAC/C,IAAI,CAACU,qBAAqB,MAAM,IAAIE,MAAM;IAE1C,MAAMC,YAAYH,oBAAoBC,GAAG,CAACR;IAC1C,IAAIU,WAAW;QACb,OAAOA,UAAUC,MAAM;IACzB;IAEA,MAAMC,eAAeC,KAAKC,YAAY,CAACf,QAAQD;IAC/CS,qBAAqBQ,IAAI,GAAGf,aAAa,EAAEY;IAE3C,OAAOA,aAAaD,MAAM;AAC5B;AAQA,OAAO,MAAMK,oBAAoB;IAC/B,MAAMC,kBAAkB,CAACpB;QACvB,IAAIA,cAAc,OAAO;YACvB,OAAOH,eAAec,GAAG,CAACX,YAAYqB,QAAQ;QAChD;QAEA,OAAOC,MAAMC,IAAI,CAAC1B,eAAe2B,MAAM,IAAIC,MAAM,CAAC,CAACC,KAAKC,MAAQD,MAAOC,CAAAA,KAAKN,QAAQ,CAAA,GAAI;IAC1F;IAEA,MAAMO,UAAU,CAAC5B;QACf,OAAO;eAAKH,eAAec,GAAG,CAACX,YAAY6B,UAAU,EAAE;SAAE;IAC3D;IAEA,OAAO;QAAET;QAAiBQ;IAAQ;AACpC,EAAE"}
@@ -1,4 +1,4 @@
1
- import { TimeSeriesValueTuple } from '@perses-dev/core';
1
+ import { TimeSeriesValueTuple } from '@perses-dev/spec';
2
2
  import { LineSeriesOption, BarSeriesOption } from 'echarts/charts';
3
3
  import { LegendItem } from '../Legend';
4
4
  export declare const OPTIMIZED_MODE_SERIES_LIMIT = 1000;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/graph.ts"],"sourcesContent":["// Copyright 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 { TimeSeriesValueTuple } from '@perses-dev/core';\nimport { LineSeriesOption, BarSeriesOption } from 'echarts/charts';\nimport { LegendItem } from '../Legend';\n\n// adjust display when there are many time series to help with performance\nexport const OPTIMIZED_MODE_SERIES_LIMIT = 1000;\n\nexport type UnixTimeMs = number;\n\nexport interface GraphSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n id?: string;\n}\n\nexport type EChartsValues = number | null | '-';\n\nexport interface LegacyTimeSeries extends Omit<LineSeriesOption, 'data'> {\n data: EChartsValues[];\n}\n\n// Used for TimeChart dataset support, each time series returned is mapped to series options using datasetIndex\n// - https://apache.github.io/echarts-handbook/en/concepts/dataset/#how-to-reference-several-datasets\nexport type TimeChartSeriesMapping = TimeSeriesOption[];\nexport type TimeChartLegendItems = LegendItem[];\n\nexport type TimeSeriesOption = LineSeriesOption | BarSeriesOption;\n\nexport type EChartsDataFormat = {\n timeSeries: LegacyTimeSeries[];\n xAxis: number[];\n legendItems?: LegendItem[];\n xAxisMax?: number | string;\n rangeMs?: number;\n};\n\n// Intentionally making this an object to start because it is plausible we will\n// want to support focusing by other attributes (e.g. index, name) in the future,\n// and starting with an object will make adding them a non-breaking change.\nexport type ChartInstanceFocusOpts = {\n name?: string; // e.g the TimeSeriesChart plugin uses name\n};\n\nexport type ChartInstance = {\n /**\n * Highlight the series associated with the specified options.\n */\n highlightSeries: (opts: ChartInstanceFocusOpts) => void;\n\n /**\n * Clear all highlighted series.\n */\n clearHighlightedSeries: () => void;\n};\n\nexport const PINNED_CROSSHAIR_SERIES_NAME = 'Pinned Crosshair';\n\nexport const DEFAULT_PINNED_CROSSHAIR: LineSeriesOption = {\n name: PINNED_CROSSHAIR_SERIES_NAME,\n type: 'line',\n // https://echarts.apache.org/en/option.html#series-line.markLine\n markLine: {\n data: [],\n lineStyle: {\n type: 'dashed',\n width: 2,\n },\n emphasis: {\n lineStyle: {\n width: 2,\n opacity: 1,\n },\n },\n blur: {\n lineStyle: {\n width: 2,\n opacity: 1,\n },\n },\n },\n};\n\nexport interface DatapointInfo {\n dataIndex: number;\n seriesIndex: number;\n seriesName: string;\n yValue: number;\n}\n"],"names":["OPTIMIZED_MODE_SERIES_LIMIT","PINNED_CROSSHAIR_SERIES_NAME","DEFAULT_PINNED_CROSSHAIR","name","type","markLine","data","lineStyle","width","emphasis","opacity","blur"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAMjC,0EAA0E;AAC1E,OAAO,MAAMA,8BAA8B,KAAK;AAkDhD,OAAO,MAAMC,+BAA+B,mBAAmB;AAE/D,OAAO,MAAMC,2BAA6C;IACxDC,MAAMF;IACNG,MAAM;IACN,iEAAiE;IACjEC,UAAU;QACRC,MAAM,EAAE;QACRC,WAAW;YACTH,MAAM;YACNI,OAAO;QACT;QACAC,UAAU;YACRF,WAAW;gBACTC,OAAO;gBACPE,SAAS;YACX;QACF;QACAC,MAAM;YACJJ,WAAW;gBACTC,OAAO;gBACPE,SAAS;YACX;QACF;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../src/model/graph.ts"],"sourcesContent":["// Copyright 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 { TimeSeriesValueTuple } from '@perses-dev/spec';\nimport { LineSeriesOption, BarSeriesOption } from 'echarts/charts';\nimport { LegendItem } from '../Legend';\n\n// adjust display when there are many time series to help with performance\nexport const OPTIMIZED_MODE_SERIES_LIMIT = 1000;\n\nexport type UnixTimeMs = number;\n\nexport interface GraphSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n id?: string;\n}\n\nexport type EChartsValues = number | null | '-';\n\nexport interface LegacyTimeSeries extends Omit<LineSeriesOption, 'data'> {\n data: EChartsValues[];\n}\n\n// Used for TimeChart dataset support, each time series returned is mapped to series options using datasetIndex\n// - https://apache.github.io/echarts-handbook/en/concepts/dataset/#how-to-reference-several-datasets\nexport type TimeChartSeriesMapping = TimeSeriesOption[];\nexport type TimeChartLegendItems = LegendItem[];\n\nexport type TimeSeriesOption = LineSeriesOption | BarSeriesOption;\n\nexport type EChartsDataFormat = {\n timeSeries: LegacyTimeSeries[];\n xAxis: number[];\n legendItems?: LegendItem[];\n xAxisMax?: number | string;\n rangeMs?: number;\n};\n\n// Intentionally making this an object to start because it is plausible we will\n// want to support focusing by other attributes (e.g. index, name) in the future,\n// and starting with an object will make adding them a non-breaking change.\nexport type ChartInstanceFocusOpts = {\n name?: string; // e.g the TimeSeriesChart plugin uses name\n};\n\nexport type ChartInstance = {\n /**\n * Highlight the series associated with the specified options.\n */\n highlightSeries: (opts: ChartInstanceFocusOpts) => void;\n\n /**\n * Clear all highlighted series.\n */\n clearHighlightedSeries: () => void;\n};\n\nexport const PINNED_CROSSHAIR_SERIES_NAME = 'Pinned Crosshair';\n\nexport const DEFAULT_PINNED_CROSSHAIR: LineSeriesOption = {\n name: PINNED_CROSSHAIR_SERIES_NAME,\n type: 'line',\n // https://echarts.apache.org/en/option.html#series-line.markLine\n markLine: {\n data: [],\n lineStyle: {\n type: 'dashed',\n width: 2,\n },\n emphasis: {\n lineStyle: {\n width: 2,\n opacity: 1,\n },\n },\n blur: {\n lineStyle: {\n width: 2,\n opacity: 1,\n },\n },\n },\n};\n\nexport interface DatapointInfo {\n dataIndex: number;\n seriesIndex: number;\n seriesName: string;\n yValue: number;\n}\n"],"names":["OPTIMIZED_MODE_SERIES_LIMIT","PINNED_CROSSHAIR_SERIES_NAME","DEFAULT_PINNED_CROSSHAIR","name","type","markLine","data","lineStyle","width","emphasis","opacity","blur"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAMjC,0EAA0E;AAC1E,OAAO,MAAMA,8BAA8B,KAAK;AAkDhD,OAAO,MAAMC,+BAA+B,mBAAmB;AAE/D,OAAO,MAAMC,2BAA6C;IACxDC,MAAMF;IACNG,MAAM;IACN,iEAAiE;IACjEC,UAAU;QACRC,MAAM,EAAE;QACRC,WAAW;YACTH,MAAM;YACNI,OAAO;QACT;QACAC,UAAU;YACRF,WAAW;gBACTC,OAAO;gBACPE,SAAS;YACX;QACF;QACAC,MAAM;YACJJ,WAAW;gBACTC,OAAO;gBACPE,SAAS;YACX;QACF;IACF;AACF,EAAE"}
@@ -2,4 +2,20 @@ export * from './graph';
2
2
  export * from './theme';
3
3
  export * from './timeOption';
4
4
  export * from './timeZoneOption';
5
+ export * from './action';
6
+ export * from './legend';
7
+ export * from './time';
8
+ export * from './bits';
9
+ export * from './bytes';
10
+ export * from './currency';
11
+ export * from './percent';
12
+ export * from './temperature';
13
+ export * from './decimal';
14
+ export * from './throughput';
15
+ export * from './formatterCache';
16
+ export * from './units';
17
+ export * from './utils';
18
+ export * from './types';
19
+ export * from './thresholds';
20
+ export * from './transforms';
5
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
@@ -14,5 +14,21 @@ export * from './graph';
14
14
  export * from './theme';
15
15
  export * from './timeOption';
16
16
  export * from './timeZoneOption';
17
+ export * from './action';
18
+ export * from './legend';
19
+ export * from './time';
20
+ export * from './bits';
21
+ export * from './bytes';
22
+ export * from './currency';
23
+ export * from './percent';
24
+ export * from './temperature';
25
+ export * from './decimal';
26
+ export * from './throughput';
27
+ export * from './formatterCache';
28
+ export * from './units';
29
+ export * from './utils';
30
+ export * from './types';
31
+ export * from './thresholds';
32
+ export * from './transforms';
17
33
 
18
34
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 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 './graph';\nexport * from './theme';\nexport * from './timeOption';\nexport * from './timeZoneOption';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,eAAe;AAC7B,cAAc,mBAAmB"}
1
+ {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 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 './graph';\nexport * from './theme';\nexport * from './timeOption';\nexport * from './timeZoneOption';\nexport * from './action';\nexport * from './legend';\nexport * from './time';\nexport * from './bits';\nexport * from './bytes';\nexport * from './currency';\nexport * from './percent';\nexport * from './temperature';\nexport * from './decimal';\nexport * from './throughput';\nexport * from './formatterCache';\nexport * from './units';\nexport * from './utils';\nexport * from './types';\nexport * from './thresholds';\nexport * from './transforms';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,eAAe;AAC7B,cAAc,mBAAmB;AACjC,cAAc,WAAW;AACzB,cAAc,WAAW;AACzB,cAAc,SAAS;AACvB,cAAc,SAAS;AACvB,cAAc,UAAU;AACxB,cAAc,aAAa;AAC3B,cAAc,YAAY;AAC1B,cAAc,gBAAgB;AAC9B,cAAc,YAAY;AAC1B,cAAc,eAAe;AAC7B,cAAc,mBAAmB;AACjC,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,eAAe;AAC7B,cAAc,eAAe"}