@splunk/visualizations 26.1.2 → 26.2.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 (159) hide show
  1. package/Area.config.js +2 -1
  2. package/Area.config.js.map +1 -1
  3. package/Area.js +1562 -433
  4. package/Area.js.map +1 -1
  5. package/Bar.config.js +1 -0
  6. package/Bar.config.js.map +1 -1
  7. package/Bar.js +1555 -430
  8. package/Bar.js.map +1 -1
  9. package/Bubble.config.js +1 -0
  10. package/Bubble.config.js.map +1 -1
  11. package/Bubble.js +1580 -455
  12. package/Bubble.js.map +1 -1
  13. package/ChoroplethSvg.config.js +1 -0
  14. package/ChoroplethSvg.config.js.map +1 -1
  15. package/ChoroplethSvg.js +1418 -351
  16. package/ChoroplethSvg.js.map +1 -1
  17. package/Column.config.js +2 -1
  18. package/Column.config.js.map +1 -1
  19. package/Column.js +1564 -435
  20. package/Column.js.map +1 -1
  21. package/Ellipse.config.js +1 -0
  22. package/Ellipse.config.js.map +1 -1
  23. package/Ellipse.js +1342 -297
  24. package/Ellipse.js.map +1 -1
  25. package/Events.config.js +4 -0
  26. package/Events.config.js.map +1 -1
  27. package/Events.js +1503 -489
  28. package/Events.js.map +1 -1
  29. package/FEATUREFLAGS.md +3 -0
  30. package/FillerGauge.config.js +1 -0
  31. package/FillerGauge.config.js.map +1 -1
  32. package/FillerGauge.js +1406 -345
  33. package/FillerGauge.js.map +1 -1
  34. package/Image.config.js +1 -0
  35. package/Image.config.js.map +1 -1
  36. package/Image.js +2355 -1183
  37. package/Image.js.map +1 -1
  38. package/Line.config.js +2 -1
  39. package/Line.config.js.map +1 -1
  40. package/Line.js +1562 -433
  41. package/Line.js.map +1 -1
  42. package/LinkGraph.config.js +1 -0
  43. package/LinkGraph.config.js.map +1 -1
  44. package/LinkGraph.js +2013 -968
  45. package/LinkGraph.js.map +1 -1
  46. package/Map.config.js +1 -0
  47. package/Map.config.js.map +1 -1
  48. package/Map.js +2556 -1527
  49. package/Map.js.map +1 -1
  50. package/Markdown.config.js +1 -0
  51. package/Markdown.config.js.map +1 -1
  52. package/Markdown.js +1952 -883
  53. package/Markdown.js.map +1 -1
  54. package/MarkerGauge.config.js +1 -0
  55. package/MarkerGauge.config.js.map +1 -1
  56. package/MarkerGauge.js +4049 -2965
  57. package/MarkerGauge.js.map +1 -1
  58. package/ParallelCoordinates.config.js +1 -0
  59. package/ParallelCoordinates.config.js.map +1 -1
  60. package/ParallelCoordinates.js +3286 -2215
  61. package/ParallelCoordinates.js.map +1 -1
  62. package/Pie.config.js +1 -0
  63. package/Pie.config.js.map +1 -1
  64. package/Pie.js +2187 -1036
  65. package/Pie.js.map +1 -1
  66. package/Punchcard.config.js +1 -0
  67. package/Punchcard.config.js.map +1 -1
  68. package/Punchcard.js +3397 -2299
  69. package/Punchcard.js.map +1 -1
  70. package/Rectangle.config.js +1 -0
  71. package/Rectangle.config.js.map +1 -1
  72. package/Rectangle.js +2181 -1112
  73. package/Rectangle.js.map +1 -1
  74. package/Sankey.config.js +1 -0
  75. package/Sankey.config.js.map +1 -1
  76. package/Sankey.js +3275 -2199
  77. package/Sankey.js.map +1 -1
  78. package/Scatter.config.js +1 -0
  79. package/Scatter.config.js.map +1 -1
  80. package/Scatter.js +3551 -2400
  81. package/Scatter.js.map +1 -1
  82. package/SingleValue.config.js +27 -0
  83. package/SingleValue.config.js.map +1 -1
  84. package/SingleValue.js +5551 -4397
  85. package/SingleValue.js.map +1 -1
  86. package/SingleValueBasic.js +1227 -1209
  87. package/SingleValueBasic.js.map +1 -1
  88. package/SingleValueIcon.config.js +27 -0
  89. package/SingleValueIcon.config.js.map +1 -1
  90. package/SingleValueIcon.js +2850 -1696
  91. package/SingleValueIcon.js.map +1 -1
  92. package/SingleValueRadial.config.js +1 -0
  93. package/SingleValueRadial.config.js.map +1 -1
  94. package/SingleValueRadial.js +6334 -5215
  95. package/SingleValueRadial.js.map +1 -1
  96. package/SparkLine.js +96 -96
  97. package/SparkLine.js.map +1 -1
  98. package/Table.config.js +172 -7
  99. package/Table.config.js.map +1 -1
  100. package/Table.js +3500 -2195
  101. package/Table.js.map +1 -1
  102. package/common/Charting.js +1009 -82
  103. package/common/Charting.js.map +1 -1
  104. package/common/ChartingApi.js +4 -4
  105. package/common/ChartingApi.js.map +1 -1
  106. package/common/DocExampleWithVizSandbox.js +54 -57
  107. package/common/DocExampleWithVizSandbox.js.map +1 -1
  108. package/common/EventsDoc.js +40 -40
  109. package/common/EventsDoc.js.map +1 -1
  110. package/common/GaugeMajorTicks.js +15 -13
  111. package/common/GaugeMajorTicks.js.map +1 -1
  112. package/common/GaugeValueMarker.js +12 -12
  113. package/common/GaugeValueMarker.js.map +1 -1
  114. package/common/OptionsDoc.js +34 -34
  115. package/common/OptionsDoc.js.map +1 -1
  116. package/common/OverviewDoc.js +124 -103
  117. package/common/OverviewDoc.js.map +1 -1
  118. package/common/SplunkVisualization.js +49 -49
  119. package/common/SplunkVisualization.js.map +1 -1
  120. package/common/SplunkVisualizationApi.js +4 -4
  121. package/common/SplunkVisualizationApi.js.map +1 -1
  122. package/common/ThemesDoc.js +31 -31
  123. package/common/ThemesDoc.js.map +1 -1
  124. package/common/chartingUtils.js +24 -8
  125. package/common/chartingUtils.js.map +1 -1
  126. package/common/docUtils.js +4 -4
  127. package/common/docUtils.js.map +1 -1
  128. package/common/gaugeUtils.js +16 -16
  129. package/common/gaugeUtils.js.map +1 -1
  130. package/common/shapeUtils.js +36 -36
  131. package/common/shapeUtils.js.map +1 -1
  132. package/common/utils/configUtils.js +48 -47
  133. package/common/utils/configUtils.js.map +1 -1
  134. package/common/utils/dataUtils.js +832 -6
  135. package/common/utils/dataUtils.js.map +1 -1
  136. package/common/utils/featureFlagUtils.js +139 -0
  137. package/common/utils/featureFlagUtils.js.map +1 -0
  138. package/common/utils/hocUtils.js +2 -2
  139. package/common/utils/hocUtils.js.map +1 -1
  140. package/common/utils/layoutUtils.js +2 -2
  141. package/common/utils/layoutUtils.js.map +1 -1
  142. package/common/utils/mapUtils.js +77 -54
  143. package/common/utils/mapUtils.js.map +1 -1
  144. package/common/utils/singleValueUtils.js +28 -19
  145. package/common/utils/singleValueUtils.js.map +1 -1
  146. package/common/utils/testHelper.js +10 -10
  147. package/common/utils/testHelper.js.map +1 -1
  148. package/common/utils/trellisUtils.js +6 -6
  149. package/common/utils/trellisUtils.js.map +1 -1
  150. package/common/utils/urlUtils.js +2 -2
  151. package/common/utils/urlUtils.js.map +1 -1
  152. package/common/withDashboardViz.js +1313 -235
  153. package/common/withDashboardViz.js.map +1 -1
  154. package/package.json +13 -12
  155. package/__mocks__/fileMock.js +0 -2
  156. package/__mocks__/styleMock.js +0 -2
  157. package/babel.config.js +0 -11
  158. package/jest.config.js +0 -8
  159. package/loki.config.js +0 -14
@@ -90,9 +90,67 @@ module.exports =
90
90
  /******/ return __webpack_require__(__webpack_require__.s = 16);
91
91
  /******/ })
92
92
  /************************************************************************/
93
- /******/ ({
93
+ /******/ ([
94
+ /* 0 */,
95
+ /* 1 */,
96
+ /* 2 */
97
+ /***/ (function(module, exports) {
94
98
 
95
- /***/ 16:
99
+ module.exports = require("@splunk/visualizations-shared/numberUtils");
100
+
101
+ /***/ }),
102
+ /* 3 */,
103
+ /* 4 */,
104
+ /* 5 */,
105
+ /* 6 */,
106
+ /* 7 */
107
+ /***/ (function(module, exports, __webpack_require__) {
108
+
109
+ "use strict";
110
+
111
+
112
+ Object.defineProperty(exports, "__esModule", {
113
+ value: true
114
+ });
115
+ exports.VizBehavior = void 0;
116
+ var VizBehavior;
117
+
118
+ (function (VizBehavior) {
119
+ /**
120
+ * Dynamic Options Behavior.
121
+ * This allows visualization options to be powered by data
122
+ *
123
+ * **Example**
124
+ *
125
+ * sparklineValues: ">primary|seriesByIndex(0)"
126
+ * would configure sparklineValues with an array of data points
127
+ * coming from the first series in the primary datasource
128
+ *
129
+ */
130
+ VizBehavior["DYNAMIC_OPTIONS"] = "dynamic-options";
131
+ VizBehavior["EVENTS"] = "events";
132
+ VizBehavior["DOWNSAMPLING"] = "downsampling";
133
+ /**
134
+ * Placeholder behavior: visualization will display a placeholder rather than fail if any of the `requiredProps` is
135
+ * missing.
136
+ * @type {string}
137
+ */
138
+
139
+ VizBehavior["PLACEHOLDER"] = "placeholder";
140
+ VizBehavior["PAGE_AND_SORT"] = "page-and-sort";
141
+ VizBehavior["TRELLIS"] = "trellis";
142
+ })(VizBehavior = exports.VizBehavior || (exports.VizBehavior = {}));
143
+
144
+ /***/ }),
145
+ /* 8 */,
146
+ /* 9 */,
147
+ /* 10 */,
148
+ /* 11 */,
149
+ /* 12 */,
150
+ /* 13 */,
151
+ /* 14 */,
152
+ /* 15 */,
153
+ /* 16 */
96
154
  /***/ (function(module, exports, __webpack_require__) {
97
155
 
98
156
  "use strict";
@@ -101,7 +159,12 @@ module.exports =
101
159
  Object.defineProperty(exports, "__esModule", {
102
160
  value: true
103
161
  });
104
- exports.convertToArrOfObjects = void 0; // TODO: utilize this fn in ParallelCoordinates
162
+ exports.downsampleDataSources = exports.calculateDownsamplingThreshold = exports.calculateThresholdOnRangeSelect = exports.isDownsamplingEnabledForViz = exports.convertToArrOfObjects = void 0;
163
+
164
+ var numberUtils_1 = __webpack_require__(2);
165
+
166
+ var interfaces_1 = __webpack_require__(17); // TODO: utilize this fn in ParallelCoordinates
167
+
105
168
 
106
169
  var convertToArrOfObjects = function convertToArrOfObjects(columns, fields) {
107
170
  if (!columns || !columns[0] || !columns[0].length) return [];
@@ -128,9 +191,772 @@ var convertToArrOfObjects = function convertToArrOfObjects(columns, fields) {
128
191
  return data;
129
192
  };
130
193
 
131
- exports.convertToArrOfObjects = convertToArrOfObjects;
194
+ exports.convertToArrOfObjects = convertToArrOfObjects; // LTTB algorithm which can be used to downsample time series data while striving to maintain
195
+ // the spikes and overall shape of the chart
196
+ // Copied from https://github.com/sveinn-steinarsson/flot-downsample/blob/0815010016fc94b1bbc6a010afb8aad13ada6d0d/jquery.flot.downsample.js
197
+ // Modifications include:
198
+ // 1) Convert to modern JavaScript(use const, let, and use array.push to push to last element of array)
199
+ // 2) Convert to camel case
200
+ // 3) Convert to TS and also return the indices of the points that are in the downsampled result.
201
+ // 4) Add a new parameter preferredDownsampleIndices that correspond to the indices of points
202
+ // that should be used in case of a tie of the max area in a bucket
132
203
 
133
- /***/ })
204
+ var largestTriangleThreeBuckets = function largestTriangleThreeBuckets(data, threshold, preferredDownsampleIndices) {
205
+ var dataLength = data.length;
206
+ var downsampledIndices = [];
207
+
208
+ if (threshold >= dataLength || threshold === 0) {
209
+ var allIndices = data.map(function (values, index) {
210
+ return index;
211
+ });
212
+ return {
213
+ downsampledData: data,
214
+ downsampledIndices: allIndices
215
+ }; // Nothing to do
216
+ }
217
+
218
+ var sampled = [];
219
+ var sampledIndex = 0; // Bucket size. Leave room for start and end data points
220
+
221
+ var every = (dataLength - 2) / (threshold - 2);
222
+ var a = 0; // Initially a is the first point in the triangle
223
+
224
+ var maxAreaPoint;
225
+ var maxArea;
226
+ var area;
227
+ var nextA;
228
+ sampled.push(data[a]); // Always add the first point
229
+
230
+ downsampledIndices.push(0); // eslint-disable-next-line no-plusplus
231
+
232
+ for (var i = 0; i < threshold - 2; i++) {
233
+ // Calculate point average for next bucket (containing c)
234
+ var avgX = 0;
235
+ var avgY = 0;
236
+ var avgRangeStart = Math.floor((i + 1) * every) + 1;
237
+ var avgRangeEnd = Math.floor((i + 2) * every) + 1;
238
+ avgRangeEnd = avgRangeEnd < dataLength ? avgRangeEnd : dataLength;
239
+ var avgRangeLength = avgRangeEnd - avgRangeStart; // eslint-disable-next-line no-plusplus
240
+
241
+ for (; avgRangeStart < avgRangeEnd; avgRangeStart++) {
242
+ avgX += Number(data[avgRangeStart][0]); // * 1 enforces Number (value may be Date)
243
+
244
+ avgY += data[avgRangeStart][1] * 1;
245
+ }
246
+
247
+ avgX /= avgRangeLength;
248
+ avgY /= avgRangeLength; // Get the range for this bucket
249
+
250
+ var rangeOffs = Math.floor((i + 0) * every) + 1;
251
+ var rangeTo = Math.floor((i + 1) * every) + 1; // Point a
252
+
253
+ var pointAX = Number(data[a][0]); // Enforce Number (value may be Date)
254
+
255
+ var pointAY = data[a][1] * 1; // eslint-disable-next-line no-multi-assign
256
+
257
+ maxArea = area = -1;
258
+ var maxAreaIndex = rangeOffs; // eslint-disable-next-line no-plusplus
259
+
260
+ for (; rangeOffs < rangeTo; rangeOffs++) {
261
+ // Calculate triangle area over three buckets
262
+ area = Math.abs((pointAX - avgX) * (data[rangeOffs][1] - pointAY) - (pointAX - Number(data[rangeOffs][0])) * (avgY - pointAY)) * 0.5; // Modification: try to downsample the least amount of points possible when there are multiple series
263
+ // If all points in a bucket have the same area, prioritize the one with an x index
264
+ // that also existed from another series so we don't add another point unnecessarily.
265
+ // By default LTTB picks the leftmost point in the bucket
266
+
267
+ if (area > maxArea || area === maxArea && preferredDownsampleIndices.has(rangeOffs)) {
268
+ maxArea = area;
269
+ maxAreaPoint = data[rangeOffs];
270
+ nextA = rangeOffs; // Next a is this b
271
+ // Modification: save the index of the point with the most area
272
+
273
+ maxAreaIndex = rangeOffs;
274
+ }
275
+ } // eslint-disable-next-line no-plusplus
276
+
277
+
278
+ sampled[sampledIndex++] = maxAreaPoint; // Pick this point from the bucket
279
+
280
+ downsampledIndices.push(maxAreaIndex);
281
+ a = nextA; // This a is the next a (chosen b)
282
+ } // eslint-disable-next-line no-plusplus
283
+
284
+
285
+ sampled[sampledIndex++] = data[dataLength - 1]; // Always add last
286
+
287
+ downsampledIndices.push(dataLength - 1);
288
+ return {
289
+ downsampledData: sampled,
290
+ downsampledIndices: downsampledIndices
291
+ };
292
+ };
293
+ /**
294
+ * Strictly coerces the entire column to numbers if it only consists of numeric strings or numbers. Also determines
295
+ * if at least one of the values in the column can be loosely coerced to a number.
296
+ * If the column cannot be strictly downsampled (if it contains nulls or non-numeric strings), returns an empty array and
297
+ * returns that it cannot downsample the column.
298
+ */
299
+
300
+
301
+ var strictlyCoerceYColumn = function strictlyCoerceYColumn(column) {
302
+ // Splunk charting allows for numbers in formats such as negative hex that
303
+ // Number() does not support and also allows loose coercion of hex numbers (but not other formats)
304
+ // We want to identify columns which contain at least one value that can be loosely coerced
305
+ var canLooselyCoerceSomeValues = column.findIndex(function (value) {
306
+ return (0, numberUtils_1.startsWithNumber)("".concat(value));
307
+ }) >= 0; // If not all values in column can be strictly coerced to a number, we do not downsample
308
+
309
+ var coercedColumn = [];
310
+ var canDownsampleColumn = !column.some(function (value) {
311
+ var coercedValue = Number(value); // if it can't be parsed or isn't safe, fail
312
+
313
+ if (Number.isNaN(coercedValue) || coercedValue <= Number.MIN_SAFE_INTEGER || coercedValue >= Number.MAX_SAFE_INTEGER || typeof value !== 'string' && typeof value !== 'number') {
314
+ return true;
315
+ } // save value and continue to next
316
+
317
+
318
+ coercedColumn.push(coercedValue);
319
+ return false;
320
+ });
321
+ return {
322
+ canDownsampleColumn: canDownsampleColumn,
323
+ canLooselyCoerceSomeValues: canLooselyCoerceSomeValues,
324
+ coercedColumn: canDownsampleColumn ? coercedColumn : []
325
+ };
326
+ };
327
+ /**
328
+ * Tries to coerce the x-column to numbers or dates, if it is eligible for downsampling.
329
+ * Only strictly increasing x-columns are eligible for downsampling.
330
+ * If the column is not eligible for downsampling, returns an empty array.
331
+ */
332
+
333
+
334
+ var strictlyCoerceXColumn = function strictlyCoerceXColumn(column, fieldType) {
335
+ if (fieldType === 'number') {
336
+ var coercedXColumn = column.map(function (xValue) {
337
+ return Number(xValue);
338
+ });
339
+
340
+ if (isColumnStrictlyIncreasing(coercedXColumn, fieldType)) {
341
+ return coercedXColumn;
342
+ }
343
+ } else if (fieldType === 'time') {
344
+ var _coercedXColumn = column.map(function (xValue) {
345
+ return new Date(xValue);
346
+ });
347
+
348
+ if (isColumnStrictlyIncreasing(_coercedXColumn, fieldType)) {
349
+ return _coercedXColumn;
350
+ }
351
+ }
352
+
353
+ return [];
354
+ };
355
+
356
+ var isDownsamplingEnabledForViz = function isDownsamplingEnabledForViz(_ref) {
357
+ var vizConfig = _ref.vizConfig;
358
+
359
+ var _a;
360
+
361
+ return (_a = vizConfig.supports) === null || _a === void 0 ? void 0 : _a.includes(interfaces_1.VizBehavior.DOWNSAMPLING);
362
+ };
363
+
364
+ exports.isDownsamplingEnabledForViz = isDownsamplingEnabledForViz;
365
+
366
+ var calculateThresholdOnRangeSelect = function calculateThresholdOnRangeSelect(_ref2) {
367
+ var firstIndex = _ref2.firstIndex,
368
+ lastIndex = _ref2.lastIndex,
369
+ dataSources = _ref2.dataSources,
370
+ width = _ref2.width;
371
+
372
+ var _a, _b, _c;
373
+
374
+ var window = lastIndex - firstIndex + 1;
375
+ var ratio = Math.round(Number(((_c = (_b = (_a = dataSources === null || dataSources === void 0 ? void 0 : dataSources.primary) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.columns[0]) === null || _c === void 0 ? void 0 : _c.length) / window) * 10) / 10;
376
+ return Math.round(ratio * Number(width));
377
+ };
378
+
379
+ exports.calculateThresholdOnRangeSelect = calculateThresholdOnRangeSelect;
380
+ /**
381
+ * Calculates the downsampling threshold based on the range selection. If search zoom is enabled or there is no selection,
382
+ * then returns the width of the visualization.
383
+ *
384
+ * Otherwise calculates the threshold based on the ratio of the window selected compared to the size of the non-downsampled
385
+ * data sources. Returns null if the chart event's dataset does not match the passed in primary data source or if the chart is zoomed
386
+ * in for a categorical chart.
387
+ */
388
+
389
+ var calculateDownsamplingThreshold = function calculateDownsamplingThreshold(_ref3) {
390
+ var enableSearchZoom = _ref3.enableSearchZoom,
391
+ dataSources = _ref3.dataSources,
392
+ selectChartEvent = _ref3.selectChartEvent,
393
+ width = _ref3.width,
394
+ xField = _ref3.xField,
395
+ y2Fields = _ref3.y2Fields;
396
+
397
+ var _a, _b, _c;
398
+
399
+ if (enableSearchZoom || !selectChartEvent) {
400
+ return Number(width);
401
+ }
402
+
403
+ var primaryDataSource = dataSources === null || dataSources === void 0 ? void 0 : dataSources.primary;
404
+
405
+ if (!primaryDataSource) {
406
+ return null;
407
+ }
408
+
409
+ var startXIndex = selectChartEvent.startXIndex,
410
+ endXIndex = selectChartEvent.endXIndex,
411
+ currentTarget = selectChartEvent.currentTarget;
412
+
413
+ try {
414
+ var xFieldIndex = (_a = primaryDataSource === null || primaryDataSource === void 0 ? void 0 : primaryDataSource.data) === null || _a === void 0 ? void 0 : _a.fields.findIndex(function (field) {
415
+ return field.name === xField;
416
+ });
417
+ var downsampledXFieldIndex = (_b = currentTarget.dataSet) === null || _b === void 0 ? void 0 : _b.fields.findIndex(function (field) {
418
+ return field === xField;
419
+ });
420
+
421
+ if (xFieldIndex === -1 || downsampledXFieldIndex === -1) {
422
+ return null;
423
+ }
424
+
425
+ var fullSeries = (_c = primaryDataSource === null || primaryDataSource === void 0 ? void 0 : primaryDataSource.data) === null || _c === void 0 ? void 0 : _c.columns[xFieldIndex];
426
+ var downsampledSeries = currentTarget.dataSet.seriesList[downsampledXFieldIndex];
427
+ var firstIndex = fullSeries.findIndex(function (x) {
428
+ return downsampledSeries[startXIndex] === x;
429
+ });
430
+ var lastIndex = fullSeries.findIndex(function (x) {
431
+ return downsampledSeries[endXIndex] === x;
432
+ }); // For charts with categorical x-axis (charts with an xField that isn't _time), do not support
433
+ // re-calculating downsampling threshold if the chart is zoomed in until SPL-259458 is fixed
434
+ // Also do not support re-calculating downsampling threshold for zoomed-in charts with y2
435
+ // until SPL-259611 is fixed
436
+
437
+ if (xField !== '_time' || (y2Fields === null || y2Fields === void 0 ? void 0 : y2Fields.length)) {
438
+ return firstIndex === 0 && lastIndex === fullSeries.length - 1 ? width : null;
439
+ }
440
+
441
+ if (firstIndex >= 0 && lastIndex >= 0 && firstIndex <= lastIndex) {
442
+ return (0, exports.calculateThresholdOnRangeSelect)({
443
+ firstIndex: firstIndex,
444
+ lastIndex: lastIndex,
445
+ dataSources: dataSources,
446
+ width: width
447
+ });
448
+ }
449
+ } catch (e) {
450
+ console.error('Error occurred while setting downsample threshold on range select event', e);
451
+ }
452
+
453
+ return null;
454
+ };
455
+
456
+ exports.calculateDownsamplingThreshold = calculateDownsamplingThreshold;
457
+
458
+ var isColumnStrictlyIncreasing = function isColumnStrictlyIncreasing(column, fieldType) {
459
+ return column.every(function (value, index) {
460
+ if (fieldType === 'number') {
461
+ if (Number.isNaN(value)) {
462
+ return false;
463
+ }
464
+ }
465
+
466
+ if (fieldType === 'time') {
467
+ if (Number.isNaN(value.getTime())) {
468
+ return false;
469
+ }
470
+ }
471
+
472
+ if (index === 0) {
473
+ return true;
474
+ }
475
+
476
+ return value > column[index - 1];
477
+ });
478
+ };
479
+ /**
480
+ * Verifies that all of the columns that are displayed in a chart can be downsampled. Valid columns that can be
481
+ * displayed are those that contain at least one number. We can only downsample columns that only consist of numbers.
482
+ *
483
+ * If all columns can be downsampled, returns the x column coerced to time/number and y columns coerced to numbers.
484
+ * If not all columns can be downsampled, then returns empty arrays for both x and y
485
+ */
486
+
487
+
488
+ var tryToCoerceAllDisplayedFields = function tryToCoerceAllDisplayedFields(ds, xField, yFields, fieldTypes) {
489
+ var xColumn = [];
490
+ var yColumns = [];
491
+ var canDownsample = !ds.data.fields.some(function (field, index) {
492
+ var _a, _b;
493
+
494
+ var fieldName = (_a = field.name) !== null && _a !== void 0 ? _a : field;
495
+ var fieldType = (_b = fieldTypes[index]) !== null && _b !== void 0 ? _b : 'unknown';
496
+ var column = ds.data.columns[index];
497
+ var hasDisplayedColumnThatCantBeDownsampled = false;
498
+
499
+ if (fieldName === xField) {
500
+ xColumn = strictlyCoerceXColumn(column, fieldType);
501
+ } else if (yFields.has(fieldName)) {
502
+ var _strictlyCoerceYColum = strictlyCoerceYColumn(ds.data.columns[index]),
503
+ coercedColumn = _strictlyCoerceYColum.coercedColumn,
504
+ canLooselyCoerceSomeValues = _strictlyCoerceYColum.canLooselyCoerceSomeValues,
505
+ canDownsampleColumn = _strictlyCoerceYColum.canDownsampleColumn; // do not perform downsampling if a column can possibly be displayed but cannot
506
+ // be downsampled using LTTB
507
+
508
+
509
+ hasDisplayedColumnThatCantBeDownsampled = canLooselyCoerceSomeValues && !canDownsampleColumn;
510
+
511
+ if (hasDisplayedColumnThatCantBeDownsampled) {
512
+ return true;
513
+ }
514
+
515
+ if (canDownsampleColumn) {
516
+ yColumns.push(coercedColumn);
517
+ }
518
+ }
519
+
520
+ return false;
521
+ });
522
+
523
+ if (canDownsample) {
524
+ return {
525
+ xColumn: xColumn,
526
+ yColumns: yColumns
527
+ };
528
+ }
529
+
530
+ return {
531
+ xColumn: [],
532
+ yColumns: []
533
+ };
534
+ };
535
+
536
+ var pickIndicesFromDataSource = function pickIndicesFromDataSource(ds, indices) {
537
+ var sortedIndices = Array.from(indices).sort(function (a, b) {
538
+ return a - b;
539
+ });
540
+ var slicedColumns = [];
541
+ ds.data.columns.forEach(function (column) {
542
+ var slicedColumn = [];
543
+ sortedIndices.forEach(function (index) {
544
+ slicedColumn.push(column[index]);
545
+ });
546
+ slicedColumns.push(slicedColumn);
547
+ }); // update data columns with downsampled columns
548
+
549
+ return Object.assign(Object.assign({}, ds), {
550
+ data: Object.assign(Object.assign({}, ds.data), {
551
+ columns: slicedColumns
552
+ })
553
+ });
554
+ };
555
+
556
+ var downsampleDataSources = function downsampleDataSources(_ref4) {
557
+ var dataSources = _ref4.dataSources,
558
+ threshold = _ref4.threshold,
559
+ options = _ref4.options;
560
+
561
+ var _a, _b, _c;
562
+
563
+ var primaryDS = dataSources === null || dataSources === void 0 ? void 0 : dataSources.primary; // only downsample time series when number of data points are over threshold
564
+
565
+ var numPoints = (_c = (_b = (_a = primaryDS === null || primaryDS === void 0 ? void 0 : primaryDS.data) === null || _a === void 0 ? void 0 : _a.columns[0]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
566
+
567
+ if (Number.isNaN(threshold) || numPoints <= threshold || threshold < 2) {
568
+ return dataSources;
569
+ }
570
+
571
+ var xField = options.xField,
572
+ yFields = options.yFields,
573
+ fieldTypes = options.fieldTypes;
574
+
575
+ if (!xField || !(yFields === null || yFields === void 0 ? void 0 : yFields.length) || !(fieldTypes === null || fieldTypes === void 0 ? void 0 : fieldTypes.length)) {
576
+ return dataSources;
577
+ }
578
+
579
+ var nonInternalYFields = new Set(yFields.filter(function (yField) {
580
+ return !yField.startsWith('_');
581
+ }));
582
+ var maxPointsInDownsample = Math.min(nonInternalYFields.size * threshold, numPoints); // Do not try to downsample if there are too many downsampled pts
583
+ // At the worst case, each series has non-overlapping downsampled pts
584
+ // which will mean that all points will be included in the downsampled result
585
+ // This will just lead to additional overhead due to coercing each
586
+ // x and y field to number
587
+
588
+ if (maxPointsInDownsample >= numPoints) {
589
+ return dataSources;
590
+ }
591
+
592
+ var _tryToCoerceAllDispla = tryToCoerceAllDisplayedFields(primaryDS, xField, nonInternalYFields, fieldTypes),
593
+ xColumn = _tryToCoerceAllDispla.xColumn,
594
+ yColumns = _tryToCoerceAllDispla.yColumns;
595
+
596
+ if (!yColumns.length || !xColumn.length) {
597
+ return dataSources;
598
+ }
599
+
600
+ var downsampledDataSources = Object.assign({}, dataSources);
601
+ var downsampledIndices = new Set();
602
+ yColumns.forEach(function (yColumn, columnIndex) {
603
+ // perform LTTB downsampling for current series, LTTB takes an [x, y] pair
604
+ var xyPair = yColumn.map(function (yValue, index) {
605
+ return [xColumn[index], yValue];
606
+ });
607
+
608
+ try {
609
+ var _largestTriangleThree = largestTriangleThreeBuckets(xyPair, threshold, downsampledIndices),
610
+ downsampledIndicesForSeries = _largestTriangleThree.downsampledIndices;
611
+
612
+ downsampledIndicesForSeries.forEach(function (downsampleIndex) {
613
+ return downsampledIndices.add(downsampleIndex);
614
+ });
615
+ } catch (e) {
616
+ console.error("Error occurred while downsampling column ".concat(columnIndex), e);
617
+ }
618
+ }); // update data columns with downsampled columns
619
+
620
+ downsampledDataSources.primary = pickIndicesFromDataSource(primaryDS, downsampledIndices);
621
+ return downsampledDataSources;
622
+ };
623
+
624
+ exports.downsampleDataSources = downsampleDataSources;
625
+
626
+ /***/ }),
627
+ /* 17 */
628
+ /***/ (function(module, exports, __webpack_require__) {
629
+
630
+ "use strict";
631
+
632
+
633
+ var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
634
+ if (k2 === undefined) k2 = k;
635
+ var desc = Object.getOwnPropertyDescriptor(m, k);
636
+
637
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
638
+ desc = {
639
+ enumerable: true,
640
+ get: function get() {
641
+ return m[k];
642
+ }
643
+ };
644
+ }
645
+
646
+ Object.defineProperty(o, k2, desc);
647
+ } : function (o, m, k, k2) {
648
+ if (k2 === undefined) k2 = k;
649
+ o[k2] = m[k];
650
+ });
651
+
652
+ var __exportStar = this && this.__exportStar || function (m, exports) {
653
+ for (var p in m) {
654
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
655
+ }
656
+ };
657
+
658
+ Object.defineProperty(exports, "__esModule", {
659
+ value: true
660
+ });
661
+
662
+ __exportStar(__webpack_require__(18), exports);
663
+
664
+ __exportStar(__webpack_require__(19), exports);
665
+
666
+ __exportStar(__webpack_require__(20), exports);
667
+
668
+ __exportStar(__webpack_require__(21), exports);
669
+
670
+ __exportStar(__webpack_require__(22), exports);
671
+
672
+ __exportStar(__webpack_require__(23), exports);
673
+
674
+ __exportStar(__webpack_require__(24), exports);
675
+
676
+ __exportStar(__webpack_require__(25), exports);
677
+
678
+ __exportStar(__webpack_require__(26), exports);
679
+
680
+ __exportStar(__webpack_require__(27), exports);
681
+
682
+ __exportStar(__webpack_require__(28), exports);
683
+
684
+ __exportStar(__webpack_require__(7), exports);
685
+
686
+ __exportStar(__webpack_require__(31), exports);
687
+
688
+ __exportStar(__webpack_require__(32), exports);
689
+
690
+ __exportStar(__webpack_require__(33), exports);
691
+
692
+ __exportStar(__webpack_require__(34), exports);
693
+
694
+ __exportStar(__webpack_require__(35), exports);
134
695
 
135
- /******/ });
696
+ __exportStar(__webpack_require__(36), exports);
697
+
698
+ __exportStar(__webpack_require__(37), exports);
699
+
700
+ /***/ }),
701
+ /* 18 */
702
+ /***/ (function(module, exports, __webpack_require__) {
703
+
704
+ "use strict";
705
+
706
+
707
+ Object.defineProperty(exports, "__esModule", {
708
+ value: true
709
+ });
710
+
711
+ /***/ }),
712
+ /* 19 */
713
+ /***/ (function(module, exports, __webpack_require__) {
714
+
715
+ "use strict";
716
+
717
+ /**
718
+ * A data structure used at runtime to wire up a visualization.
719
+ */
720
+
721
+ Object.defineProperty(exports, "__esModule", {
722
+ value: true
723
+ });
724
+
725
+ /***/ }),
726
+ /* 20 */
727
+ /***/ (function(module, exports, __webpack_require__) {
728
+
729
+ "use strict";
730
+
731
+
732
+ Object.defineProperty(exports, "__esModule", {
733
+ value: true
734
+ });
735
+ exports.validOutputModes = exports.validSegmentationModes = exports.validSortDirs = void 0;
736
+ exports.validSortDirs = ['asc', 'desc', 'none'];
737
+ exports.validSegmentationModes = ['none', 'inner'];
738
+ exports.validOutputModes = ['json_cols', 'json'];
739
+
740
+ /***/ }),
741
+ /* 21 */
742
+ /***/ (function(module, exports, __webpack_require__) {
743
+
744
+ "use strict";
745
+
746
+
747
+ Object.defineProperty(exports, "__esModule", {
748
+ value: true
749
+ });
750
+
751
+ /***/ }),
752
+ /* 22 */
753
+ /***/ (function(module, exports, __webpack_require__) {
754
+
755
+ "use strict";
756
+
757
+
758
+ Object.defineProperty(exports, "__esModule", {
759
+ value: true
760
+ });
761
+
762
+ /***/ }),
763
+ /* 23 */
764
+ /***/ (function(module, exports, __webpack_require__) {
765
+
766
+ "use strict";
767
+
768
+
769
+ Object.defineProperty(exports, "__esModule", {
770
+ value: true
771
+ });
772
+
773
+ /***/ }),
774
+ /* 24 */
775
+ /***/ (function(module, exports, __webpack_require__) {
776
+
777
+ "use strict";
778
+
779
+
780
+ Object.defineProperty(exports, "__esModule", {
781
+ value: true
782
+ });
783
+
784
+ /***/ }),
785
+ /* 25 */
786
+ /***/ (function(module, exports, __webpack_require__) {
787
+
788
+ "use strict";
789
+
790
+
791
+ Object.defineProperty(exports, "__esModule", {
792
+ value: true
793
+ });
794
+
795
+ /***/ }),
796
+ /* 26 */
797
+ /***/ (function(module, exports, __webpack_require__) {
798
+
799
+ "use strict";
800
+
801
+
802
+ Object.defineProperty(exports, "__esModule", {
803
+ value: true
804
+ });
805
+
806
+ /***/ }),
807
+ /* 27 */
808
+ /***/ (function(module, exports, __webpack_require__) {
809
+
810
+ "use strict";
811
+
812
+
813
+ Object.defineProperty(exports, "__esModule", {
814
+ value: true
815
+ });
816
+
817
+ /***/ }),
818
+ /* 28 */
819
+ /***/ (function(module, exports, __webpack_require__) {
820
+
821
+ "use strict";
822
+
823
+
824
+ var _classCallCheck = __webpack_require__(29);
825
+
826
+ var _createClass = __webpack_require__(30);
827
+
828
+ Object.defineProperty(exports, "__esModule", {
829
+ value: true
830
+ });
831
+ exports.DefaultVizActionHandler = void 0;
832
+
833
+ var DefaultVizActionHandler = /*#__PURE__*/function () {
834
+ function DefaultVizActionHandler() {
835
+ _classCallCheck(this, DefaultVizActionHandler);
836
+ }
837
+
838
+ _createClass(DefaultVizActionHandler, [{
839
+ key: "focus",
840
+ value: function focus() {// noop
841
+ }
842
+ }, {
843
+ key: "snapshot",
844
+ value: function snapshot() {
845
+ return null; // noop
846
+ }
847
+ }]);
848
+
849
+ return DefaultVizActionHandler;
850
+ }();
851
+
852
+ exports.DefaultVizActionHandler = DefaultVizActionHandler;
853
+
854
+ /***/ }),
855
+ /* 29 */
856
+ /***/ (function(module, exports) {
857
+
858
+ module.exports = require("@babel/runtime/helpers/classCallCheck");
859
+
860
+ /***/ }),
861
+ /* 30 */
862
+ /***/ (function(module, exports) {
863
+
864
+ module.exports = require("@babel/runtime/helpers/createClass");
865
+
866
+ /***/ }),
867
+ /* 31 */
868
+ /***/ (function(module, exports, __webpack_require__) {
869
+
870
+ "use strict";
871
+
872
+
873
+ Object.defineProperty(exports, "__esModule", {
874
+ value: true
875
+ });
876
+ exports.VizCategory = void 0;
877
+ var VizCategory;
878
+
879
+ (function (VizCategory) {
880
+ VizCategory["SINGLE_VALUE"] = "Single Value";
881
+ VizCategory["TRENDS"] = "Trends";
882
+ VizCategory["COMPARISONS"] = "Comparisons";
883
+ VizCategory["TABLE"] = "Table";
884
+ VizCategory["GAUGE"] = "Gauge";
885
+ VizCategory["DISTRIBUTIONS"] = "Distributions";
886
+ VizCategory["CHOROPLETH"] = "Choropleth Maps";
887
+ VizCategory["SHAPES"] = "Shapes";
888
+ VizCategory["MISC"] = "misc";
889
+ VizCategory["FLOW"] = "Flow";
890
+ VizCategory["CORRELATION"] = "Correlation";
891
+ VizCategory["SPATIAL"] = "Spatial";
892
+ })(VizCategory = exports.VizCategory || (exports.VizCategory = {}));
893
+
894
+ /***/ }),
895
+ /* 32 */
896
+ /***/ (function(module, exports, __webpack_require__) {
897
+
898
+ "use strict";
899
+
900
+
901
+ Object.defineProperty(exports, "__esModule", {
902
+ value: true
903
+ });
904
+
905
+ /***/ }),
906
+ /* 33 */
907
+ /***/ (function(module, exports, __webpack_require__) {
908
+
909
+ "use strict";
910
+
911
+
912
+ Object.defineProperty(exports, "__esModule", {
913
+ value: true
914
+ });
915
+
916
+ /***/ }),
917
+ /* 34 */
918
+ /***/ (function(module, exports, __webpack_require__) {
919
+
920
+ "use strict";
921
+
922
+
923
+ Object.defineProperty(exports, "__esModule", {
924
+ value: true
925
+ });
926
+
927
+ /***/ }),
928
+ /* 35 */
929
+ /***/ (function(module, exports, __webpack_require__) {
930
+
931
+ "use strict";
932
+
933
+
934
+ Object.defineProperty(exports, "__esModule", {
935
+ value: true
936
+ });
937
+
938
+ /***/ }),
939
+ /* 36 */
940
+ /***/ (function(module, exports, __webpack_require__) {
941
+
942
+ "use strict";
943
+
944
+
945
+ Object.defineProperty(exports, "__esModule", {
946
+ value: true
947
+ });
948
+
949
+ /***/ }),
950
+ /* 37 */
951
+ /***/ (function(module, exports, __webpack_require__) {
952
+
953
+ "use strict";
954
+
955
+
956
+ Object.defineProperty(exports, "__esModule", {
957
+ value: true
958
+ });
959
+
960
+ /***/ })
961
+ /******/ ]);
136
962
  //# sourceMappingURL=dataUtils.js.map