@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
@@ -87,7 +87,7 @@ module.exports =
87
87
  /******/
88
88
  /******/
89
89
  /******/ // Load entry module and return exports
90
- /******/ return __webpack_require__(__webpack_require__.s = 53);
90
+ /******/ return __webpack_require__(__webpack_require__.s = 74);
91
91
  /******/ })
92
92
  /************************************************************************/
93
93
  /******/ ([
@@ -118,13 +118,13 @@ module.exports = require("lodash");
118
118
  /* 4 */
119
119
  /***/ (function(module, exports) {
120
120
 
121
- module.exports = require("@splunk/ui-utils/i18n");
121
+ module.exports = require("@babel/runtime/helpers/classCallCheck");
122
122
 
123
123
  /***/ }),
124
124
  /* 5 */
125
125
  /***/ (function(module, exports) {
126
126
 
127
- module.exports = require("@babel/runtime/helpers/classCallCheck");
127
+ module.exports = require("@splunk/ui-utils/i18n");
128
128
 
129
129
  /***/ }),
130
130
  /* 6 */,
@@ -135,43 +135,642 @@ module.exports = require("@babel/runtime/helpers/createClass");
135
135
 
136
136
  /***/ }),
137
137
  /* 8 */,
138
- /* 9 */,
138
+ /* 9 */
139
+ /***/ (function(module, exports) {
140
+
141
+ module.exports = require("@splunk/visualizations-shared/numberUtils");
142
+
143
+ /***/ }),
139
144
  /* 10 */,
140
145
  /* 11 */,
141
146
  /* 12 */,
142
147
  /* 13 */,
143
- /* 14 */,
148
+ /* 14 */
149
+ /***/ (function(module, exports, __webpack_require__) {
150
+
151
+ "use strict";
152
+
153
+
154
+ var _classCallCheck = __webpack_require__(4);
155
+
156
+ var _createClass = __webpack_require__(7);
157
+
158
+ Object.defineProperty(exports, "__esModule", {
159
+ value: true
160
+ });
161
+ exports.DefaultVizActionHandler = void 0;
162
+
163
+ var DefaultVizActionHandler = /*#__PURE__*/function () {
164
+ function DefaultVizActionHandler() {
165
+ _classCallCheck(this, DefaultVizActionHandler);
166
+ }
167
+
168
+ _createClass(DefaultVizActionHandler, [{
169
+ key: "focus",
170
+ value: function focus() {// noop
171
+ }
172
+ }, {
173
+ key: "snapshot",
174
+ value: function snapshot() {
175
+ return null; // noop
176
+ }
177
+ }]);
178
+
179
+ return DefaultVizActionHandler;
180
+ }();
181
+
182
+ exports.DefaultVizActionHandler = DefaultVizActionHandler;
183
+
184
+ /***/ }),
144
185
  /* 15 */,
145
186
  /* 16 */,
146
187
  /* 17 */,
147
- /* 18 */,
148
- /* 19 */,
149
- /* 20 */
188
+ /* 18 */
189
+ /***/ (function(module, exports, __webpack_require__) {
190
+
191
+ "use strict";
192
+
193
+
194
+ Object.defineProperty(exports, "__esModule", {
195
+ value: true
196
+ });
197
+ exports.VizBehavior = void 0;
198
+ var VizBehavior;
199
+
200
+ (function (VizBehavior) {
201
+ /**
202
+ * Dynamic Options Behavior.
203
+ * This allows visualization options to be powered by data
204
+ *
205
+ * **Example**
206
+ *
207
+ * sparklineValues: ">primary|seriesByIndex(0)"
208
+ * would configure sparklineValues with an array of data points
209
+ * coming from the first series in the primary datasource
210
+ *
211
+ */
212
+ VizBehavior["DYNAMIC_OPTIONS"] = "dynamic-options";
213
+ VizBehavior["EVENTS"] = "events";
214
+ VizBehavior["DOWNSAMPLING"] = "downsampling";
215
+ /**
216
+ * Placeholder behavior: visualization will display a placeholder rather than fail if any of the `requiredProps` is
217
+ * missing.
218
+ * @type {string}
219
+ */
220
+
221
+ VizBehavior["PLACEHOLDER"] = "placeholder";
222
+ VizBehavior["PAGE_AND_SORT"] = "page-and-sort";
223
+ VizBehavior["TRELLIS"] = "trellis";
224
+ })(VizBehavior = exports.VizBehavior || (exports.VizBehavior = {}));
225
+
226
+ /***/ }),
227
+ /* 19 */
228
+ /***/ (function(module, exports, __webpack_require__) {
229
+
230
+ "use strict";
231
+
232
+
233
+ Object.defineProperty(exports, "__esModule", {
234
+ value: true
235
+ });
236
+ exports.VizCategory = void 0;
237
+ var VizCategory;
238
+
239
+ (function (VizCategory) {
240
+ VizCategory["SINGLE_VALUE"] = "Single Value";
241
+ VizCategory["TRENDS"] = "Trends";
242
+ VizCategory["COMPARISONS"] = "Comparisons";
243
+ VizCategory["TABLE"] = "Table";
244
+ VizCategory["GAUGE"] = "Gauge";
245
+ VizCategory["DISTRIBUTIONS"] = "Distributions";
246
+ VizCategory["CHOROPLETH"] = "Choropleth Maps";
247
+ VizCategory["SHAPES"] = "Shapes";
248
+ VizCategory["MISC"] = "misc";
249
+ VizCategory["FLOW"] = "Flow";
250
+ VizCategory["CORRELATION"] = "Correlation";
251
+ VizCategory["SPATIAL"] = "Spatial";
252
+ })(VizCategory = exports.VizCategory || (exports.VizCategory = {}));
253
+
254
+ /***/ }),
255
+ /* 20 */,
256
+ /* 21 */,
257
+ /* 22 */,
258
+ /* 23 */,
259
+ /* 24 */
150
260
  /***/ (function(module, exports) {
151
261
 
152
262
  module.exports = require("@splunk/visualizations-shared/Message");
153
263
 
154
264
  /***/ }),
155
- /* 21 */,
156
- /* 22 */
265
+ /* 25 */
266
+ /***/ (function(module, exports, __webpack_require__) {
267
+
268
+ "use strict";
269
+
270
+
271
+ Object.defineProperty(exports, "__esModule", {
272
+ value: true
273
+ });
274
+ exports.downsampleDataSources = exports.calculateDownsamplingThreshold = exports.calculateThresholdOnRangeSelect = exports.isDownsamplingEnabledForViz = exports.convertToArrOfObjects = void 0;
275
+
276
+ var numberUtils_1 = __webpack_require__(9);
277
+
278
+ var interfaces_1 = __webpack_require__(32); // TODO: utilize this fn in ParallelCoordinates
279
+
280
+
281
+ var convertToArrOfObjects = function convertToArrOfObjects(columns, fields) {
282
+ if (!columns || !columns[0] || !columns[0].length) return [];
283
+ var data = [];
284
+
285
+ var _loop = function _loop(i) {
286
+ var newObj = {};
287
+ fields.forEach(function (field, index) {
288
+ var fieldName = typeof field === 'string' ? field : field.name;
289
+
290
+ if (columns[index][i] === '') {
291
+ newObj[fieldName] = null;
292
+ } else {
293
+ newObj[fieldName] = columns[index][i];
294
+ }
295
+ });
296
+ data.push(newObj);
297
+ };
298
+
299
+ for (var i = 0; i < columns[0].length; i += 1) {
300
+ _loop(i);
301
+ }
302
+
303
+ return data;
304
+ };
305
+
306
+ exports.convertToArrOfObjects = convertToArrOfObjects; // LTTB algorithm which can be used to downsample time series data while striving to maintain
307
+ // the spikes and overall shape of the chart
308
+ // Copied from https://github.com/sveinn-steinarsson/flot-downsample/blob/0815010016fc94b1bbc6a010afb8aad13ada6d0d/jquery.flot.downsample.js
309
+ // Modifications include:
310
+ // 1) Convert to modern JavaScript(use const, let, and use array.push to push to last element of array)
311
+ // 2) Convert to camel case
312
+ // 3) Convert to TS and also return the indices of the points that are in the downsampled result.
313
+ // 4) Add a new parameter preferredDownsampleIndices that correspond to the indices of points
314
+ // that should be used in case of a tie of the max area in a bucket
315
+
316
+ var largestTriangleThreeBuckets = function largestTriangleThreeBuckets(data, threshold, preferredDownsampleIndices) {
317
+ var dataLength = data.length;
318
+ var downsampledIndices = [];
319
+
320
+ if (threshold >= dataLength || threshold === 0) {
321
+ var allIndices = data.map(function (values, index) {
322
+ return index;
323
+ });
324
+ return {
325
+ downsampledData: data,
326
+ downsampledIndices: allIndices
327
+ }; // Nothing to do
328
+ }
329
+
330
+ var sampled = [];
331
+ var sampledIndex = 0; // Bucket size. Leave room for start and end data points
332
+
333
+ var every = (dataLength - 2) / (threshold - 2);
334
+ var a = 0; // Initially a is the first point in the triangle
335
+
336
+ var maxAreaPoint;
337
+ var maxArea;
338
+ var area;
339
+ var nextA;
340
+ sampled.push(data[a]); // Always add the first point
341
+
342
+ downsampledIndices.push(0); // eslint-disable-next-line no-plusplus
343
+
344
+ for (var i = 0; i < threshold - 2; i++) {
345
+ // Calculate point average for next bucket (containing c)
346
+ var avgX = 0;
347
+ var avgY = 0;
348
+ var avgRangeStart = Math.floor((i + 1) * every) + 1;
349
+ var avgRangeEnd = Math.floor((i + 2) * every) + 1;
350
+ avgRangeEnd = avgRangeEnd < dataLength ? avgRangeEnd : dataLength;
351
+ var avgRangeLength = avgRangeEnd - avgRangeStart; // eslint-disable-next-line no-plusplus
352
+
353
+ for (; avgRangeStart < avgRangeEnd; avgRangeStart++) {
354
+ avgX += Number(data[avgRangeStart][0]); // * 1 enforces Number (value may be Date)
355
+
356
+ avgY += data[avgRangeStart][1] * 1;
357
+ }
358
+
359
+ avgX /= avgRangeLength;
360
+ avgY /= avgRangeLength; // Get the range for this bucket
361
+
362
+ var rangeOffs = Math.floor((i + 0) * every) + 1;
363
+ var rangeTo = Math.floor((i + 1) * every) + 1; // Point a
364
+
365
+ var pointAX = Number(data[a][0]); // Enforce Number (value may be Date)
366
+
367
+ var pointAY = data[a][1] * 1; // eslint-disable-next-line no-multi-assign
368
+
369
+ maxArea = area = -1;
370
+ var maxAreaIndex = rangeOffs; // eslint-disable-next-line no-plusplus
371
+
372
+ for (; rangeOffs < rangeTo; rangeOffs++) {
373
+ // Calculate triangle area over three buckets
374
+ 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
375
+ // If all points in a bucket have the same area, prioritize the one with an x index
376
+ // that also existed from another series so we don't add another point unnecessarily.
377
+ // By default LTTB picks the leftmost point in the bucket
378
+
379
+ if (area > maxArea || area === maxArea && preferredDownsampleIndices.has(rangeOffs)) {
380
+ maxArea = area;
381
+ maxAreaPoint = data[rangeOffs];
382
+ nextA = rangeOffs; // Next a is this b
383
+ // Modification: save the index of the point with the most area
384
+
385
+ maxAreaIndex = rangeOffs;
386
+ }
387
+ } // eslint-disable-next-line no-plusplus
388
+
389
+
390
+ sampled[sampledIndex++] = maxAreaPoint; // Pick this point from the bucket
391
+
392
+ downsampledIndices.push(maxAreaIndex);
393
+ a = nextA; // This a is the next a (chosen b)
394
+ } // eslint-disable-next-line no-plusplus
395
+
396
+
397
+ sampled[sampledIndex++] = data[dataLength - 1]; // Always add last
398
+
399
+ downsampledIndices.push(dataLength - 1);
400
+ return {
401
+ downsampledData: sampled,
402
+ downsampledIndices: downsampledIndices
403
+ };
404
+ };
405
+ /**
406
+ * Strictly coerces the entire column to numbers if it only consists of numeric strings or numbers. Also determines
407
+ * if at least one of the values in the column can be loosely coerced to a number.
408
+ * If the column cannot be strictly downsampled (if it contains nulls or non-numeric strings), returns an empty array and
409
+ * returns that it cannot downsample the column.
410
+ */
411
+
412
+
413
+ var strictlyCoerceYColumn = function strictlyCoerceYColumn(column) {
414
+ // Splunk charting allows for numbers in formats such as negative hex that
415
+ // Number() does not support and also allows loose coercion of hex numbers (but not other formats)
416
+ // We want to identify columns which contain at least one value that can be loosely coerced
417
+ var canLooselyCoerceSomeValues = column.findIndex(function (value) {
418
+ return (0, numberUtils_1.startsWithNumber)("".concat(value));
419
+ }) >= 0; // If not all values in column can be strictly coerced to a number, we do not downsample
420
+
421
+ var coercedColumn = [];
422
+ var canDownsampleColumn = !column.some(function (value) {
423
+ var coercedValue = Number(value); // if it can't be parsed or isn't safe, fail
424
+
425
+ if (Number.isNaN(coercedValue) || coercedValue <= Number.MIN_SAFE_INTEGER || coercedValue >= Number.MAX_SAFE_INTEGER || typeof value !== 'string' && typeof value !== 'number') {
426
+ return true;
427
+ } // save value and continue to next
428
+
429
+
430
+ coercedColumn.push(coercedValue);
431
+ return false;
432
+ });
433
+ return {
434
+ canDownsampleColumn: canDownsampleColumn,
435
+ canLooselyCoerceSomeValues: canLooselyCoerceSomeValues,
436
+ coercedColumn: canDownsampleColumn ? coercedColumn : []
437
+ };
438
+ };
439
+ /**
440
+ * Tries to coerce the x-column to numbers or dates, if it is eligible for downsampling.
441
+ * Only strictly increasing x-columns are eligible for downsampling.
442
+ * If the column is not eligible for downsampling, returns an empty array.
443
+ */
444
+
445
+
446
+ var strictlyCoerceXColumn = function strictlyCoerceXColumn(column, fieldType) {
447
+ if (fieldType === 'number') {
448
+ var coercedXColumn = column.map(function (xValue) {
449
+ return Number(xValue);
450
+ });
451
+
452
+ if (isColumnStrictlyIncreasing(coercedXColumn, fieldType)) {
453
+ return coercedXColumn;
454
+ }
455
+ } else if (fieldType === 'time') {
456
+ var _coercedXColumn = column.map(function (xValue) {
457
+ return new Date(xValue);
458
+ });
459
+
460
+ if (isColumnStrictlyIncreasing(_coercedXColumn, fieldType)) {
461
+ return _coercedXColumn;
462
+ }
463
+ }
464
+
465
+ return [];
466
+ };
467
+
468
+ var isDownsamplingEnabledForViz = function isDownsamplingEnabledForViz(_ref) {
469
+ var vizConfig = _ref.vizConfig;
470
+
471
+ var _a;
472
+
473
+ return (_a = vizConfig.supports) === null || _a === void 0 ? void 0 : _a.includes(interfaces_1.VizBehavior.DOWNSAMPLING);
474
+ };
475
+
476
+ exports.isDownsamplingEnabledForViz = isDownsamplingEnabledForViz;
477
+
478
+ var calculateThresholdOnRangeSelect = function calculateThresholdOnRangeSelect(_ref2) {
479
+ var firstIndex = _ref2.firstIndex,
480
+ lastIndex = _ref2.lastIndex,
481
+ dataSources = _ref2.dataSources,
482
+ width = _ref2.width;
483
+
484
+ var _a, _b, _c;
485
+
486
+ var window = lastIndex - firstIndex + 1;
487
+ 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;
488
+ return Math.round(ratio * Number(width));
489
+ };
490
+
491
+ exports.calculateThresholdOnRangeSelect = calculateThresholdOnRangeSelect;
492
+ /**
493
+ * Calculates the downsampling threshold based on the range selection. If search zoom is enabled or there is no selection,
494
+ * then returns the width of the visualization.
495
+ *
496
+ * Otherwise calculates the threshold based on the ratio of the window selected compared to the size of the non-downsampled
497
+ * 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
498
+ * in for a categorical chart.
499
+ */
500
+
501
+ var calculateDownsamplingThreshold = function calculateDownsamplingThreshold(_ref3) {
502
+ var enableSearchZoom = _ref3.enableSearchZoom,
503
+ dataSources = _ref3.dataSources,
504
+ selectChartEvent = _ref3.selectChartEvent,
505
+ width = _ref3.width,
506
+ xField = _ref3.xField,
507
+ y2Fields = _ref3.y2Fields;
508
+
509
+ var _a, _b, _c;
510
+
511
+ if (enableSearchZoom || !selectChartEvent) {
512
+ return Number(width);
513
+ }
514
+
515
+ var primaryDataSource = dataSources === null || dataSources === void 0 ? void 0 : dataSources.primary;
516
+
517
+ if (!primaryDataSource) {
518
+ return null;
519
+ }
520
+
521
+ var startXIndex = selectChartEvent.startXIndex,
522
+ endXIndex = selectChartEvent.endXIndex,
523
+ currentTarget = selectChartEvent.currentTarget;
524
+
525
+ try {
526
+ var xFieldIndex = (_a = primaryDataSource === null || primaryDataSource === void 0 ? void 0 : primaryDataSource.data) === null || _a === void 0 ? void 0 : _a.fields.findIndex(function (field) {
527
+ return field.name === xField;
528
+ });
529
+ var downsampledXFieldIndex = (_b = currentTarget.dataSet) === null || _b === void 0 ? void 0 : _b.fields.findIndex(function (field) {
530
+ return field === xField;
531
+ });
532
+
533
+ if (xFieldIndex === -1 || downsampledXFieldIndex === -1) {
534
+ return null;
535
+ }
536
+
537
+ var fullSeries = (_c = primaryDataSource === null || primaryDataSource === void 0 ? void 0 : primaryDataSource.data) === null || _c === void 0 ? void 0 : _c.columns[xFieldIndex];
538
+ var downsampledSeries = currentTarget.dataSet.seriesList[downsampledXFieldIndex];
539
+ var firstIndex = fullSeries.findIndex(function (x) {
540
+ return downsampledSeries[startXIndex] === x;
541
+ });
542
+ var lastIndex = fullSeries.findIndex(function (x) {
543
+ return downsampledSeries[endXIndex] === x;
544
+ }); // For charts with categorical x-axis (charts with an xField that isn't _time), do not support
545
+ // re-calculating downsampling threshold if the chart is zoomed in until SPL-259458 is fixed
546
+ // Also do not support re-calculating downsampling threshold for zoomed-in charts with y2
547
+ // until SPL-259611 is fixed
548
+
549
+ if (xField !== '_time' || (y2Fields === null || y2Fields === void 0 ? void 0 : y2Fields.length)) {
550
+ return firstIndex === 0 && lastIndex === fullSeries.length - 1 ? width : null;
551
+ }
552
+
553
+ if (firstIndex >= 0 && lastIndex >= 0 && firstIndex <= lastIndex) {
554
+ return (0, exports.calculateThresholdOnRangeSelect)({
555
+ firstIndex: firstIndex,
556
+ lastIndex: lastIndex,
557
+ dataSources: dataSources,
558
+ width: width
559
+ });
560
+ }
561
+ } catch (e) {
562
+ console.error('Error occurred while setting downsample threshold on range select event', e);
563
+ }
564
+
565
+ return null;
566
+ };
567
+
568
+ exports.calculateDownsamplingThreshold = calculateDownsamplingThreshold;
569
+
570
+ var isColumnStrictlyIncreasing = function isColumnStrictlyIncreasing(column, fieldType) {
571
+ return column.every(function (value, index) {
572
+ if (fieldType === 'number') {
573
+ if (Number.isNaN(value)) {
574
+ return false;
575
+ }
576
+ }
577
+
578
+ if (fieldType === 'time') {
579
+ if (Number.isNaN(value.getTime())) {
580
+ return false;
581
+ }
582
+ }
583
+
584
+ if (index === 0) {
585
+ return true;
586
+ }
587
+
588
+ return value > column[index - 1];
589
+ });
590
+ };
591
+ /**
592
+ * Verifies that all of the columns that are displayed in a chart can be downsampled. Valid columns that can be
593
+ * displayed are those that contain at least one number. We can only downsample columns that only consist of numbers.
594
+ *
595
+ * If all columns can be downsampled, returns the x column coerced to time/number and y columns coerced to numbers.
596
+ * If not all columns can be downsampled, then returns empty arrays for both x and y
597
+ */
598
+
599
+
600
+ var tryToCoerceAllDisplayedFields = function tryToCoerceAllDisplayedFields(ds, xField, yFields, fieldTypes) {
601
+ var xColumn = [];
602
+ var yColumns = [];
603
+ var canDownsample = !ds.data.fields.some(function (field, index) {
604
+ var _a, _b;
605
+
606
+ var fieldName = (_a = field.name) !== null && _a !== void 0 ? _a : field;
607
+ var fieldType = (_b = fieldTypes[index]) !== null && _b !== void 0 ? _b : 'unknown';
608
+ var column = ds.data.columns[index];
609
+ var hasDisplayedColumnThatCantBeDownsampled = false;
610
+
611
+ if (fieldName === xField) {
612
+ xColumn = strictlyCoerceXColumn(column, fieldType);
613
+ } else if (yFields.has(fieldName)) {
614
+ var _strictlyCoerceYColum = strictlyCoerceYColumn(ds.data.columns[index]),
615
+ coercedColumn = _strictlyCoerceYColum.coercedColumn,
616
+ canLooselyCoerceSomeValues = _strictlyCoerceYColum.canLooselyCoerceSomeValues,
617
+ canDownsampleColumn = _strictlyCoerceYColum.canDownsampleColumn; // do not perform downsampling if a column can possibly be displayed but cannot
618
+ // be downsampled using LTTB
619
+
620
+
621
+ hasDisplayedColumnThatCantBeDownsampled = canLooselyCoerceSomeValues && !canDownsampleColumn;
622
+
623
+ if (hasDisplayedColumnThatCantBeDownsampled) {
624
+ return true;
625
+ }
626
+
627
+ if (canDownsampleColumn) {
628
+ yColumns.push(coercedColumn);
629
+ }
630
+ }
631
+
632
+ return false;
633
+ });
634
+
635
+ if (canDownsample) {
636
+ return {
637
+ xColumn: xColumn,
638
+ yColumns: yColumns
639
+ };
640
+ }
641
+
642
+ return {
643
+ xColumn: [],
644
+ yColumns: []
645
+ };
646
+ };
647
+
648
+ var pickIndicesFromDataSource = function pickIndicesFromDataSource(ds, indices) {
649
+ var sortedIndices = Array.from(indices).sort(function (a, b) {
650
+ return a - b;
651
+ });
652
+ var slicedColumns = [];
653
+ ds.data.columns.forEach(function (column) {
654
+ var slicedColumn = [];
655
+ sortedIndices.forEach(function (index) {
656
+ slicedColumn.push(column[index]);
657
+ });
658
+ slicedColumns.push(slicedColumn);
659
+ }); // update data columns with downsampled columns
660
+
661
+ return Object.assign(Object.assign({}, ds), {
662
+ data: Object.assign(Object.assign({}, ds.data), {
663
+ columns: slicedColumns
664
+ })
665
+ });
666
+ };
667
+
668
+ var downsampleDataSources = function downsampleDataSources(_ref4) {
669
+ var dataSources = _ref4.dataSources,
670
+ threshold = _ref4.threshold,
671
+ options = _ref4.options;
672
+
673
+ var _a, _b, _c;
674
+
675
+ var primaryDS = dataSources === null || dataSources === void 0 ? void 0 : dataSources.primary; // only downsample time series when number of data points are over threshold
676
+
677
+ 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;
678
+
679
+ if (Number.isNaN(threshold) || numPoints <= threshold || threshold < 2) {
680
+ return dataSources;
681
+ }
682
+
683
+ var xField = options.xField,
684
+ yFields = options.yFields,
685
+ fieldTypes = options.fieldTypes;
686
+
687
+ if (!xField || !(yFields === null || yFields === void 0 ? void 0 : yFields.length) || !(fieldTypes === null || fieldTypes === void 0 ? void 0 : fieldTypes.length)) {
688
+ return dataSources;
689
+ }
690
+
691
+ var nonInternalYFields = new Set(yFields.filter(function (yField) {
692
+ return !yField.startsWith('_');
693
+ }));
694
+ var maxPointsInDownsample = Math.min(nonInternalYFields.size * threshold, numPoints); // Do not try to downsample if there are too many downsampled pts
695
+ // At the worst case, each series has non-overlapping downsampled pts
696
+ // which will mean that all points will be included in the downsampled result
697
+ // This will just lead to additional overhead due to coercing each
698
+ // x and y field to number
699
+
700
+ if (maxPointsInDownsample >= numPoints) {
701
+ return dataSources;
702
+ }
703
+
704
+ var _tryToCoerceAllDispla = tryToCoerceAllDisplayedFields(primaryDS, xField, nonInternalYFields, fieldTypes),
705
+ xColumn = _tryToCoerceAllDispla.xColumn,
706
+ yColumns = _tryToCoerceAllDispla.yColumns;
707
+
708
+ if (!yColumns.length || !xColumn.length) {
709
+ return dataSources;
710
+ }
711
+
712
+ var downsampledDataSources = Object.assign({}, dataSources);
713
+ var downsampledIndices = new Set();
714
+ yColumns.forEach(function (yColumn, columnIndex) {
715
+ // perform LTTB downsampling for current series, LTTB takes an [x, y] pair
716
+ var xyPair = yColumn.map(function (yValue, index) {
717
+ return [xColumn[index], yValue];
718
+ });
719
+
720
+ try {
721
+ var _largestTriangleThree = largestTriangleThreeBuckets(xyPair, threshold, downsampledIndices),
722
+ downsampledIndicesForSeries = _largestTriangleThree.downsampledIndices;
723
+
724
+ downsampledIndicesForSeries.forEach(function (downsampleIndex) {
725
+ return downsampledIndices.add(downsampleIndex);
726
+ });
727
+ } catch (e) {
728
+ console.error("Error occurred while downsampling column ".concat(columnIndex), e);
729
+ }
730
+ }); // update data columns with downsampled columns
731
+
732
+ downsampledDataSources.primary = pickIndicesFromDataSource(primaryDS, downsampledIndices);
733
+ return downsampledDataSources;
734
+ };
735
+
736
+ exports.downsampleDataSources = downsampleDataSources;
737
+
738
+ /***/ }),
739
+ /* 26 */
740
+ /***/ (function(module, exports, __webpack_require__) {
741
+
742
+ "use strict";
743
+
744
+
745
+ Object.defineProperty(exports, "__esModule", {
746
+ value: true
747
+ });
748
+ exports.validOutputModes = exports.validSegmentationModes = exports.validSortDirs = void 0;
749
+ exports.validSortDirs = ['asc', 'desc', 'none'];
750
+ exports.validSegmentationModes = ['none', 'inner'];
751
+ exports.validOutputModes = ['json_cols', 'json'];
752
+
753
+ /***/ }),
754
+ /* 27 */,
755
+ /* 28 */
157
756
  /***/ (function(module, exports) {
158
757
 
159
758
  module.exports = require("@splunk/visualization-context/TimezoneContext");
160
759
 
161
760
  /***/ }),
162
- /* 23 */
761
+ /* 29 */
163
762
  /***/ (function(module, exports) {
164
763
 
165
764
  module.exports = require("@splunk/visualizations-shared/style");
166
765
 
167
766
  /***/ }),
168
- /* 24 */
767
+ /* 30 */
169
768
  /***/ (function(module, exports, __webpack_require__) {
170
769
 
171
770
  "use strict";
172
771
 
173
772
 
174
- var _classCallCheck = __webpack_require__(5);
773
+ var _classCallCheck = __webpack_require__(4);
175
774
 
176
775
  var _createClass = __webpack_require__(7);
177
776
 
@@ -233,35 +832,298 @@ var ChartingApiFunctional = /*#__PURE__*/function () {
233
832
  exports.ChartingApiFunctional = ChartingApiFunctional;
234
833
 
235
834
  /***/ }),
236
- /* 25 */,
237
- /* 26 */,
238
- /* 27 */,
239
- /* 28 */,
240
- /* 29 */,
241
- /* 30 */,
242
- /* 31 */,
243
- /* 32 */,
244
- /* 33 */,
245
- /* 34 */,
246
- /* 35 */,
247
- /* 36 */,
248
- /* 37 */,
249
- /* 38 */,
250
- /* 39 */,
251
- /* 40 */,
252
- /* 41 */,
253
- /* 42 */,
254
- /* 43 */,
255
- /* 44 */,
256
- /* 45 */,
257
- /* 46 */,
258
- /* 47 */,
835
+ /* 31 */
836
+ /***/ (function(module, exports, __webpack_require__) {
837
+
838
+ "use strict";
839
+
840
+
841
+ Object.defineProperty(exports, "__esModule", {
842
+ value: true
843
+ });
844
+
845
+ var react_1 = __webpack_require__(0);
846
+
847
+ function usePrevious(value) {
848
+ var ref = (0, react_1.useRef)();
849
+ (0, react_1.useEffect)(function () {
850
+ ref.current = value;
851
+ });
852
+ return ref.current;
853
+ }
854
+
855
+ exports.default = usePrevious;
856
+
857
+ /***/ }),
858
+ /* 32 */
859
+ /***/ (function(module, exports, __webpack_require__) {
860
+
861
+ "use strict";
862
+
863
+
864
+ var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
865
+ if (k2 === undefined) k2 = k;
866
+ var desc = Object.getOwnPropertyDescriptor(m, k);
867
+
868
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
869
+ desc = {
870
+ enumerable: true,
871
+ get: function get() {
872
+ return m[k];
873
+ }
874
+ };
875
+ }
876
+
877
+ Object.defineProperty(o, k2, desc);
878
+ } : function (o, m, k, k2) {
879
+ if (k2 === undefined) k2 = k;
880
+ o[k2] = m[k];
881
+ });
882
+
883
+ var __exportStar = this && this.__exportStar || function (m, exports) {
884
+ for (var p in m) {
885
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
886
+ }
887
+ };
888
+
889
+ Object.defineProperty(exports, "__esModule", {
890
+ value: true
891
+ });
892
+
893
+ __exportStar(__webpack_require__(33), exports);
894
+
895
+ __exportStar(__webpack_require__(34), exports);
896
+
897
+ __exportStar(__webpack_require__(26), exports);
898
+
899
+ __exportStar(__webpack_require__(35), exports);
900
+
901
+ __exportStar(__webpack_require__(36), exports);
902
+
903
+ __exportStar(__webpack_require__(37), exports);
904
+
905
+ __exportStar(__webpack_require__(38), exports);
906
+
907
+ __exportStar(__webpack_require__(39), exports);
908
+
909
+ __exportStar(__webpack_require__(40), exports);
910
+
911
+ __exportStar(__webpack_require__(41), exports);
912
+
913
+ __exportStar(__webpack_require__(14), exports);
914
+
915
+ __exportStar(__webpack_require__(18), exports);
916
+
917
+ __exportStar(__webpack_require__(19), exports);
918
+
919
+ __exportStar(__webpack_require__(42), exports);
920
+
921
+ __exportStar(__webpack_require__(43), exports);
922
+
923
+ __exportStar(__webpack_require__(44), exports);
924
+
925
+ __exportStar(__webpack_require__(45), exports);
926
+
927
+ __exportStar(__webpack_require__(46), exports);
928
+
929
+ __exportStar(__webpack_require__(47), exports);
930
+
931
+ /***/ }),
932
+ /* 33 */
933
+ /***/ (function(module, exports, __webpack_require__) {
934
+
935
+ "use strict";
936
+
937
+
938
+ Object.defineProperty(exports, "__esModule", {
939
+ value: true
940
+ });
941
+
942
+ /***/ }),
943
+ /* 34 */
944
+ /***/ (function(module, exports, __webpack_require__) {
945
+
946
+ "use strict";
947
+
948
+ /**
949
+ * A data structure used at runtime to wire up a visualization.
950
+ */
951
+
952
+ Object.defineProperty(exports, "__esModule", {
953
+ value: true
954
+ });
955
+
956
+ /***/ }),
957
+ /* 35 */
958
+ /***/ (function(module, exports, __webpack_require__) {
959
+
960
+ "use strict";
961
+
962
+
963
+ Object.defineProperty(exports, "__esModule", {
964
+ value: true
965
+ });
966
+
967
+ /***/ }),
968
+ /* 36 */
969
+ /***/ (function(module, exports, __webpack_require__) {
970
+
971
+ "use strict";
972
+
973
+
974
+ Object.defineProperty(exports, "__esModule", {
975
+ value: true
976
+ });
977
+
978
+ /***/ }),
979
+ /* 37 */
980
+ /***/ (function(module, exports, __webpack_require__) {
981
+
982
+ "use strict";
983
+
984
+
985
+ Object.defineProperty(exports, "__esModule", {
986
+ value: true
987
+ });
988
+
989
+ /***/ }),
990
+ /* 38 */
991
+ /***/ (function(module, exports, __webpack_require__) {
992
+
993
+ "use strict";
994
+
995
+
996
+ Object.defineProperty(exports, "__esModule", {
997
+ value: true
998
+ });
999
+
1000
+ /***/ }),
1001
+ /* 39 */
1002
+ /***/ (function(module, exports, __webpack_require__) {
1003
+
1004
+ "use strict";
1005
+
1006
+
1007
+ Object.defineProperty(exports, "__esModule", {
1008
+ value: true
1009
+ });
1010
+
1011
+ /***/ }),
1012
+ /* 40 */
1013
+ /***/ (function(module, exports, __webpack_require__) {
1014
+
1015
+ "use strict";
1016
+
1017
+
1018
+ Object.defineProperty(exports, "__esModule", {
1019
+ value: true
1020
+ });
1021
+
1022
+ /***/ }),
1023
+ /* 41 */
1024
+ /***/ (function(module, exports, __webpack_require__) {
1025
+
1026
+ "use strict";
1027
+
1028
+
1029
+ Object.defineProperty(exports, "__esModule", {
1030
+ value: true
1031
+ });
1032
+
1033
+ /***/ }),
1034
+ /* 42 */
1035
+ /***/ (function(module, exports, __webpack_require__) {
1036
+
1037
+ "use strict";
1038
+
1039
+
1040
+ Object.defineProperty(exports, "__esModule", {
1041
+ value: true
1042
+ });
1043
+
1044
+ /***/ }),
1045
+ /* 43 */
1046
+ /***/ (function(module, exports, __webpack_require__) {
1047
+
1048
+ "use strict";
1049
+
1050
+
1051
+ Object.defineProperty(exports, "__esModule", {
1052
+ value: true
1053
+ });
1054
+
1055
+ /***/ }),
1056
+ /* 44 */
1057
+ /***/ (function(module, exports, __webpack_require__) {
1058
+
1059
+ "use strict";
1060
+
1061
+
1062
+ Object.defineProperty(exports, "__esModule", {
1063
+ value: true
1064
+ });
1065
+
1066
+ /***/ }),
1067
+ /* 45 */
1068
+ /***/ (function(module, exports, __webpack_require__) {
1069
+
1070
+ "use strict";
1071
+
1072
+
1073
+ Object.defineProperty(exports, "__esModule", {
1074
+ value: true
1075
+ });
1076
+
1077
+ /***/ }),
1078
+ /* 46 */
1079
+ /***/ (function(module, exports, __webpack_require__) {
1080
+
1081
+ "use strict";
1082
+
1083
+
1084
+ Object.defineProperty(exports, "__esModule", {
1085
+ value: true
1086
+ });
1087
+
1088
+ /***/ }),
1089
+ /* 47 */
1090
+ /***/ (function(module, exports, __webpack_require__) {
1091
+
1092
+ "use strict";
1093
+
1094
+
1095
+ Object.defineProperty(exports, "__esModule", {
1096
+ value: true
1097
+ });
1098
+
1099
+ /***/ }),
259
1100
  /* 48 */,
260
1101
  /* 49 */,
261
1102
  /* 50 */,
262
1103
  /* 51 */,
263
1104
  /* 52 */,
264
- /* 53 */
1105
+ /* 53 */,
1106
+ /* 54 */,
1107
+ /* 55 */,
1108
+ /* 56 */,
1109
+ /* 57 */,
1110
+ /* 58 */,
1111
+ /* 59 */,
1112
+ /* 60 */,
1113
+ /* 61 */,
1114
+ /* 62 */,
1115
+ /* 63 */,
1116
+ /* 64 */,
1117
+ /* 65 */,
1118
+ /* 66 */,
1119
+ /* 67 */,
1120
+ /* 68 */,
1121
+ /* 69 */,
1122
+ /* 70 */,
1123
+ /* 71 */,
1124
+ /* 72 */,
1125
+ /* 73 */,
1126
+ /* 74 */
265
1127
  /***/ (function(module, exports, __webpack_require__) {
266
1128
 
267
1129
  "use strict";
@@ -275,9 +1137,9 @@ exports.updateRowPayload = exports.canUpdateInPlace = exports.changedOptions = e
275
1137
 
276
1138
  var lodash_1 = __webpack_require__(3);
277
1139
 
278
- var i18n_1 = __webpack_require__(4);
1140
+ var i18n_1 = __webpack_require__(5);
279
1141
 
280
- var visualization_color_palettes_1 = __webpack_require__(54);
1142
+ var visualization_color_palettes_1 = __webpack_require__(75);
281
1143
 
282
1144
  var react_1 = __webpack_require__(0);
283
1145
 
@@ -285,26 +1147,32 @@ var React = __webpack_require__(0);
285
1147
 
286
1148
  var T = __webpack_require__(1);
287
1149
 
288
- var react_event_listener_1 = __webpack_require__(55);
1150
+ var react_event_listener_1 = __webpack_require__(76);
289
1151
 
290
- __webpack_require__(56); // fixme, @splunk/charting should be refactor to use locale & timezone instead of i18n functions
1152
+ __webpack_require__(77); // fixme, @splunk/charting should be refactor to use locale & timezone instead of i18n functions
291
1153
 
292
1154
 
293
- var charting_bundle_1 = __webpack_require__(57);
1155
+ var charting_bundle_1 = __webpack_require__(78);
294
1156
 
295
- var TimezoneContext_1 = __webpack_require__(22);
1157
+ var TimezoneContext_1 = __webpack_require__(28);
296
1158
 
297
- var style_1 = __webpack_require__(23);
1159
+ var style_1 = __webpack_require__(29);
298
1160
 
299
1161
  var styled_components_1 = __webpack_require__(2);
300
1162
 
301
- var Message_1 = __webpack_require__(20);
1163
+ var Message_1 = __webpack_require__(24);
1164
+
1165
+ var useSplunkTheme_1 = __webpack_require__(79);
302
1166
 
303
- var useSplunkTheme_1 = __webpack_require__(58);
1167
+ var themeUtils_1 = __webpack_require__(80);
304
1168
 
305
- var themeUtils_1 = __webpack_require__(59);
1169
+ var ChartingApi_1 = __webpack_require__(30);
306
1170
 
307
- var ChartingApi_1 = __webpack_require__(24);
1171
+ var usePrevious_1 = __webpack_require__(31);
1172
+
1173
+ var useEventCallback_1 = __webpack_require__(81);
1174
+
1175
+ var dataUtils_1 = __webpack_require__(25);
308
1176
 
309
1177
  exports.NO_INPLACE_PROPS = ['chart', 'chart.orientation', 'layout.splitSeries', 'chart.style', 'legend.placement'];
310
1178
 
@@ -318,14 +1186,6 @@ var changedOptions = function changedOptions(curOptions, nextOptions) {
318
1186
 
319
1187
  exports.changedOptions = changedOptions;
320
1188
 
321
- function usePrevious(value) {
322
- var ref = (0, react_1.useRef)();
323
- (0, react_1.useEffect)(function () {
324
- ref.current = value;
325
- });
326
- return ref.current;
327
- }
328
-
329
1189
  var canUpdateInPlace = function canUpdateInPlace(curOptions, nextOptions) {
330
1190
  // if either of the options are undefined
331
1191
  // it cannot update in place.
@@ -390,16 +1250,23 @@ var propTypes = {
390
1250
  style: T.object,
391
1251
  colorPalette: T.array,
392
1252
  visualizationApiRef: T.func,
393
- themeKey: T.string
1253
+ themeKey: T.string,
1254
+ originalDataSources: T.object,
1255
+ onDownsamplingThresholdChange: T.func,
1256
+ xField: T.string,
1257
+ y2Fields: T.array
394
1258
  };
395
1259
 
396
1260
  var Charting = function Charting(props) {
1261
+ var _a, _b;
1262
+
397
1263
  var container = (0, react_1.useRef)(null);
398
1264
  var needsInit = (0, react_1.useRef)(true);
399
1265
  var chart = (0, react_1.useRef)();
400
1266
  var needsRedraw = (0, react_1.useRef)(true);
401
1267
  var api = (0, react_1.useRef)(new ChartingApi_1.ChartingApiFunctional(chart));
402
1268
  var timezone = (0, react_1.useContext)(TimezoneContext_1.default);
1269
+ var selectChartEvent = (0, react_1.useRef)(null);
403
1270
 
404
1271
  var computeChartingSize = function computeChartingSize() {
405
1272
  if (container.current) {
@@ -427,9 +1294,13 @@ var Charting = function Charting(props) {
427
1294
  onSelect = props.onSelect,
428
1295
  onPointMouseOut = props.onPointMouseOut,
429
1296
  onPointMouseOver = props.onPointMouseOver,
430
- onEventTrigger = props.onEventTrigger;
431
- var prevOptions = usePrevious(options);
432
- var prevTimezone = usePrevious(timezone);
1297
+ onEventTrigger = props.onEventTrigger,
1298
+ originalDataSources = props.originalDataSources,
1299
+ onDownsamplingThresholdChange = props.onDownsamplingThresholdChange,
1300
+ xField = props.xField,
1301
+ y2Fields = props.y2Fields;
1302
+ var prevOptions = (0, usePrevious_1.default)(options);
1303
+ var prevTimezone = (0, usePrevious_1.default)(timezone);
433
1304
 
434
1305
  var handleClick = function handleClick(chartEvent, type) {
435
1306
  var payload = (0, lodash_1.pick)(chartEvent, 'name2', 'value2', '_span', 'modifierKey');
@@ -459,8 +1330,37 @@ var Charting = function Charting(props) {
459
1330
  needsInit.current = true;
460
1331
  };
461
1332
 
462
- var handleSelect = function handleSelect(chartEvent) {
463
- // todo: need change this after breaking all visualizations
1333
+ var enableSearchZoom = (_b = (_a = chartData === null || chartData === void 0 ? void 0 : chartData.chartDataOptions) === null || _a === void 0 ? void 0 : _a.enableSearchZoom) !== null && _b !== void 0 ? _b : false;
1334
+ var recalculateDownsamplingThreshold = React.useCallback(function () {
1335
+ if (!onDownsamplingThresholdChange || !xField) {
1336
+ return;
1337
+ }
1338
+
1339
+ var newThreshold = (0, dataUtils_1.calculateDownsamplingThreshold)({
1340
+ enableSearchZoom: enableSearchZoom,
1341
+ dataSources: originalDataSources,
1342
+ width: Number(width),
1343
+ selectChartEvent: selectChartEvent.current,
1344
+ xField: xField,
1345
+ y2Fields: y2Fields
1346
+ });
1347
+
1348
+ if (Number.isFinite(newThreshold)) {
1349
+ onDownsamplingThresholdChange(newThreshold);
1350
+ }
1351
+ }, [enableSearchZoom, originalDataSources, onDownsamplingThresholdChange, width, xField, y2Fields]);
1352
+ React.useEffect(function () {
1353
+ recalculateDownsamplingThreshold();
1354
+ }, [recalculateDownsamplingThreshold]); // useEventCallback is used for these handlers to make sure that they are a stable reference and
1355
+ // we always use the latest version of the callback
1356
+ // Since chart drawing is debounced, there is a race condition where a stale callback may be called
1357
+ // if a prop changes and the event handler is called before the chart redraws. This means that
1358
+ // it will use the old callback rather than the newer one, which can lead to inaccurate results
1359
+
1360
+ var handleSelect = (0, useEventCallback_1.default)(function (chartEvent) {
1361
+ selectChartEvent.current = chartEvent;
1362
+ recalculateDownsamplingThreshold(); // todo: need change this after breaking all visualizations
1363
+
464
1364
  if (onSelect && typeof onSelect === 'function') {
465
1365
  onSelect({
466
1366
  type: 'range.select',
@@ -476,9 +1376,8 @@ var Charting = function Charting(props) {
476
1376
  originalEvent: chartEvent,
477
1377
  payload: (0, lodash_1.pick)(chartEvent, 'startXIndex', 'endXIndex', 'startXValue', 'endXValue')
478
1378
  });
479
- };
480
-
481
- var handlePointMouseOut = function handlePointMouseOut(chartEvent, type) {
1379
+ });
1380
+ var handlePointMouseOut = (0, useEventCallback_1.default)(function (chartEvent, type) {
482
1381
  var payload = (0, lodash_1.pick)(chartEvent, 'name2', 'value2', '_span', 'modifierKey', 'tooltipContext');
483
1382
  payload.name = payload.name2;
484
1383
  delete payload.name2;
@@ -490,9 +1389,8 @@ var Charting = function Charting(props) {
490
1389
  originalEvent: chartEvent,
491
1390
  payload: payload
492
1391
  });
493
- };
494
-
495
- var handlePointMouseOver = function handlePointMouseOver(chartEvent, type) {
1392
+ });
1393
+ var handlePointMouseOver = (0, useEventCallback_1.default)(function (chartEvent, type) {
496
1394
  var payload = (0, lodash_1.pick)(chartEvent, 'name2', 'value2', '_span', 'modifierKey', 'tooltipContext');
497
1395
  payload.name = payload.name2;
498
1396
  delete payload.name2;
@@ -504,7 +1402,7 @@ var Charting = function Charting(props) {
504
1402
  originalEvent: chartEvent,
505
1403
  payload: payload
506
1404
  });
507
- };
1405
+ });
508
1406
 
509
1407
  var drawChart = function drawChart() {
510
1408
  var updatedOptions = Object.assign(Object.assign({}, options), {
@@ -530,7 +1428,7 @@ var Charting = function Charting(props) {
530
1428
 
531
1429
  if (prevOptions) {
532
1430
  Object.keys(prevOptions).forEach(function (key) {
533
- if (updatedOptions[key] === undefined) {
1431
+ if (prevOptions[key] && updatedOptions[key] === undefined) {
534
1432
  updatedOptions[key] = '';
535
1433
  }
536
1434
  });
@@ -600,8 +1498,8 @@ var Charting = function Charting(props) {
600
1498
  debouncedDrawChart();
601
1499
  };
602
1500
 
603
- var prevTheme = usePrevious(themeKey);
604
- var prevOnClick = usePrevious(onClick);
1501
+ var prevTheme = (0, usePrevious_1.default)(themeKey);
1502
+ var prevOnClick = (0, usePrevious_1.default)(onClick);
605
1503
  (0, react_1.useEffect)(function () {
606
1504
  debouncedDrawChart();
607
1505
  props.visualizationApiRef(api.current);
@@ -616,11 +1514,11 @@ var Charting = function Charting(props) {
616
1514
  if (!chart.current || !(0, exports.canUpdateInPlace)(prevOptions, options) || // timezone is a simple object so this comparison should be fast
617
1515
  JSON.stringify(prevTimezone) !== JSON.stringify(timezone) || !props.themeKey && prevTheme !== themeKey || prevOnClick !== onClick) {
618
1516
  needsInit.current = true;
619
- }
620
-
621
- needsRedraw.current = true; // need to immediately call drawChart upon an option or chartData change
1517
+ } // need to immediately call drawChart upon an option or chartData change
622
1518
  // otherwise a noop would occur if the onContainerMount drawChart is re-invoked when dimensions change
623
1519
 
1520
+
1521
+ needsRedraw.current = true;
624
1522
  drawChart();
625
1523
  }, [JSON.stringify(options), JSON.stringify(chartData.toJSON()), JSON.stringify(chartData.annotations), timezone === null || timezone === void 0 ? void 0 : timezone.ianaTimezone, timezone === null || timezone === void 0 ? void 0 : timezone.utcOffset, timezone === null || timezone === void 0 ? void 0 : timezone.serializedTimezone, themeKey, onClick]);
626
1524
  return React.createElement(ChartingContainer, {
@@ -648,7 +1546,11 @@ var defaultProps = {
648
1546
  colorPalette: visualization_color_palettes_1.VIZ_CATEGORICAL,
649
1547
  visualizationApiRef: lodash_1.noop,
650
1548
  chartData: null,
651
- themeKey: null
1549
+ themeKey: null,
1550
+ onDownsamplingThresholdChange: null,
1551
+ originalDataSources: null,
1552
+ xField: null,
1553
+ y2Fields: []
652
1554
  };
653
1555
  Charting.propTypes = propTypes;
654
1556
  Charting.defaultProps = defaultProps; // allow for early return in case of empty chartData while still following hook rules
@@ -684,41 +1586,66 @@ var withEmptyChartMessage = function withEmptyChartMessage(Chart) {
684
1586
  exports.default = withEmptyChartMessage(Charting);
685
1587
 
686
1588
  /***/ }),
687
- /* 54 */
1589
+ /* 75 */
688
1590
  /***/ (function(module, exports) {
689
1591
 
690
1592
  module.exports = require("@splunk/visualization-color-palettes");
691
1593
 
692
1594
  /***/ }),
693
- /* 55 */
1595
+ /* 76 */
694
1596
  /***/ (function(module, exports) {
695
1597
 
696
1598
  module.exports = require("react-event-listener");
697
1599
 
698
1600
  /***/ }),
699
- /* 56 */
1601
+ /* 77 */
700
1602
  /***/ (function(module, exports) {
701
1603
 
702
1604
  module.exports = require("@splunk/visualizations-shared/i18n");
703
1605
 
704
1606
  /***/ }),
705
- /* 57 */
1607
+ /* 78 */
706
1608
  /***/ (function(module, exports) {
707
1609
 
708
1610
  module.exports = require("@splunk/charting-bundle");
709
1611
 
710
1612
  /***/ }),
711
- /* 58 */
1613
+ /* 79 */
712
1614
  /***/ (function(module, exports) {
713
1615
 
714
1616
  module.exports = require("@splunk/themes/useSplunkTheme");
715
1617
 
716
1618
  /***/ }),
717
- /* 59 */
1619
+ /* 80 */
718
1620
  /***/ (function(module, exports) {
719
1621
 
720
1622
  module.exports = require("@splunk/visualizations-shared/themeUtils");
721
1623
 
1624
+ /***/ }),
1625
+ /* 81 */
1626
+ /***/ (function(module, exports, __webpack_require__) {
1627
+
1628
+ "use strict";
1629
+
1630
+
1631
+ Object.defineProperty(exports, "__esModule", {
1632
+ value: true
1633
+ });
1634
+
1635
+ var react_1 = __webpack_require__(0);
1636
+
1637
+ var useEventCallback = function useEventCallback(fn) {
1638
+ var ref = (0, react_1.useRef)(fn);
1639
+ (0, react_1.useLayoutEffect)(function () {
1640
+ ref.current = fn;
1641
+ });
1642
+ return (0, react_1.useCallback)(function () {
1643
+ return ref.current.apply(ref, arguments);
1644
+ }, []);
1645
+ };
1646
+
1647
+ exports.default = useEventCallback;
1648
+
722
1649
  /***/ })
723
1650
  /******/ ]);
724
1651
  //# sourceMappingURL=Charting.js.map