@kepler.gl/utils 3.3.0-alpha.2 → 3.3.0-alpha.21

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 (264) hide show
  1. package/dist/application-config.d.ts +180 -1
  2. package/dist/arrow-data-container.d.ts +55 -2
  3. package/dist/camera-tour.d.ts +11 -0
  4. package/dist/camera-utils.d.ts +7 -0
  5. package/dist/cjs/aggregation.js +84 -0
  6. package/dist/cjs/aggregation.js.map +1 -0
  7. package/dist/cjs/application-config-types.js +6 -0
  8. package/dist/cjs/application-config-types.js.map +1 -0
  9. package/dist/cjs/application-config.js +178 -0
  10. package/dist/cjs/application-config.js.map +1 -0
  11. package/dist/cjs/arrow-data-container.js +1152 -0
  12. package/dist/cjs/arrow-data-container.js.map +1 -0
  13. package/dist/cjs/browser-utils.js +17 -0
  14. package/dist/cjs/browser-utils.js.map +1 -0
  15. package/dist/cjs/camera-tour.js +99 -0
  16. package/dist/cjs/camera-tour.js.map +1 -0
  17. package/dist/cjs/camera-utils.js +81 -0
  18. package/dist/cjs/camera-utils.js.map +1 -0
  19. package/dist/cjs/color-utils.js +462 -0
  20. package/dist/cjs/color-utils.js.map +1 -0
  21. package/dist/cjs/column-statistics.js +115 -0
  22. package/dist/cjs/column-statistics.js.map +1 -0
  23. package/dist/cjs/data-container-interface.js +6 -0
  24. package/dist/cjs/data-container-interface.js.map +1 -0
  25. package/dist/cjs/data-container-utils.js +76 -0
  26. package/dist/cjs/data-container-utils.js.map +1 -0
  27. package/dist/cjs/data-row.js +110 -0
  28. package/dist/cjs/data-row.js.map +1 -0
  29. package/dist/cjs/data-scale-utils.js +634 -0
  30. package/dist/cjs/data-scale-utils.js.map +1 -0
  31. package/dist/cjs/data-utils.js +538 -0
  32. package/dist/cjs/data-utils.js.map +1 -0
  33. package/dist/cjs/dataset-utils.js +361 -0
  34. package/dist/cjs/dataset-utils.js.map +1 -0
  35. package/dist/cjs/dom-to-image.js +433 -0
  36. package/dist/cjs/dom-to-image.js.map +1 -0
  37. package/dist/cjs/dom-utils.js +349 -0
  38. package/dist/cjs/dom-utils.js.map +1 -0
  39. package/dist/cjs/editor-feature-utils.js +177 -0
  40. package/dist/cjs/editor-feature-utils.js.map +1 -0
  41. package/dist/cjs/effect-utils.js +340 -0
  42. package/dist/cjs/effect-utils.js.map +1 -0
  43. package/dist/cjs/export-map-html.js +112 -0
  44. package/dist/cjs/export-map-html.js.map +1 -0
  45. package/dist/cjs/export-utils.js +318 -0
  46. package/dist/cjs/export-utils.js.map +1 -0
  47. package/dist/cjs/extract-dataset-utils.js +218 -0
  48. package/dist/cjs/extract-dataset-utils.js.map +1 -0
  49. package/dist/cjs/filter-utils.js +1762 -0
  50. package/dist/cjs/filter-utils.js.map +1 -0
  51. package/dist/cjs/format.js +38 -0
  52. package/dist/cjs/format.js.map +1 -0
  53. package/dist/cjs/gl-utils.js +118 -0
  54. package/dist/cjs/gl-utils.js.map +1 -0
  55. package/dist/{index.js → cjs/index.js} +391 -10
  56. package/dist/cjs/index.js.map +1 -0
  57. package/dist/cjs/indexed-data-container.js +214 -0
  58. package/dist/cjs/indexed-data-container.js.map +1 -0
  59. package/dist/cjs/jenks.js +156 -0
  60. package/dist/cjs/jenks.js.map +1 -0
  61. package/dist/cjs/locale-utils.js +39 -0
  62. package/dist/cjs/locale-utils.js.map +1 -0
  63. package/dist/cjs/map-info-utils.js +41 -0
  64. package/dist/cjs/map-info-utils.js.map +1 -0
  65. package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js +198 -0
  66. package/dist/cjs/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
  67. package/dist/cjs/map-style-utils/mapbox-utils.js +155 -0
  68. package/dist/cjs/map-style-utils/mapbox-utils.js.map +1 -0
  69. package/dist/cjs/map-utils.js +76 -0
  70. package/dist/cjs/map-utils.js.map +1 -0
  71. package/dist/cjs/mapbox-utils.js +19 -0
  72. package/dist/cjs/mapbox-utils.js.map +1 -0
  73. package/dist/cjs/notifications-utils.js +69 -0
  74. package/dist/cjs/notifications-utils.js.map +1 -0
  75. package/dist/cjs/observe-dimensions.js +136 -0
  76. package/dist/cjs/observe-dimensions.js.map +1 -0
  77. package/dist/cjs/plot.js +1502 -0
  78. package/dist/cjs/plot.js.map +1 -0
  79. package/dist/cjs/position-utils.js +29 -0
  80. package/dist/cjs/position-utils.js.map +1 -0
  81. package/dist/cjs/projection-utils.js +141 -0
  82. package/dist/cjs/projection-utils.js.map +1 -0
  83. package/dist/cjs/quick-insertion-sort.js +132 -0
  84. package/dist/cjs/quick-insertion-sort.js.map +1 -0
  85. package/dist/cjs/row-data-container.js +291 -0
  86. package/dist/cjs/row-data-container.js.map +1 -0
  87. package/dist/cjs/slider-scale-utils.js +138 -0
  88. package/dist/cjs/slider-scale-utils.js.map +1 -0
  89. package/dist/cjs/split-map-utils.js +117 -0
  90. package/dist/cjs/split-map-utils.js.map +1 -0
  91. package/dist/cjs/strings.js +16 -0
  92. package/dist/cjs/strings.js.map +1 -0
  93. package/dist/cjs/theme-utils.js +46 -0
  94. package/dist/cjs/theme-utils.js.map +1 -0
  95. package/dist/cjs/time.js +321 -0
  96. package/dist/cjs/time.js.map +1 -0
  97. package/dist/cjs/types.js +6 -0
  98. package/dist/cjs/types.js.map +1 -0
  99. package/dist/cjs/utils.js +224 -0
  100. package/dist/cjs/utils.js.map +1 -0
  101. package/dist/column-statistics.d.ts +54 -0
  102. package/dist/data-container-interface.d.ts +16 -1
  103. package/dist/data-container-utils.d.ts +2 -1
  104. package/dist/data-scale-utils.d.ts +5 -0
  105. package/dist/data-utils.d.ts +3 -3
  106. package/dist/dataset-utils.d.ts +11 -28
  107. package/dist/editor-feature-utils.d.ts +30 -0
  108. package/dist/esm/aggregation.js +75 -0
  109. package/dist/esm/aggregation.js.map +1 -0
  110. package/dist/esm/application-config-types.js +3 -0
  111. package/dist/esm/application-config-types.js.map +1 -0
  112. package/dist/esm/application-config.js +167 -0
  113. package/dist/esm/application-config.js.map +1 -0
  114. package/dist/esm/arrow-data-container.js +1136 -0
  115. package/dist/esm/arrow-data-container.js.map +1 -0
  116. package/dist/esm/browser-utils.js +11 -0
  117. package/dist/esm/browser-utils.js.map +1 -0
  118. package/dist/esm/camera-tour.js +92 -0
  119. package/dist/esm/camera-tour.js.map +1 -0
  120. package/dist/esm/camera-utils.js +74 -0
  121. package/dist/esm/camera-utils.js.map +1 -0
  122. package/dist/esm/color-utils.js +435 -0
  123. package/dist/esm/color-utils.js.map +1 -0
  124. package/dist/esm/column-statistics.js +105 -0
  125. package/dist/esm/column-statistics.js.map +1 -0
  126. package/dist/esm/data-container-interface.js +3 -0
  127. package/dist/esm/data-container-interface.js.map +1 -0
  128. package/dist/esm/data-container-utils.js +68 -0
  129. package/dist/esm/data-container-utils.js.map +1 -0
  130. package/dist/esm/data-row.js +106 -0
  131. package/dist/esm/data-row.js.map +1 -0
  132. package/dist/esm/data-scale-utils.js +602 -0
  133. package/dist/esm/data-scale-utils.js.map +1 -0
  134. package/dist/esm/data-utils.js +504 -0
  135. package/dist/esm/data-utils.js.map +1 -0
  136. package/dist/esm/dataset-utils.js +352 -0
  137. package/dist/esm/dataset-utils.js.map +1 -0
  138. package/dist/esm/dom-to-image.js +426 -0
  139. package/dist/esm/dom-to-image.js.map +1 -0
  140. package/dist/esm/dom-utils.js +323 -0
  141. package/dist/esm/dom-utils.js.map +1 -0
  142. package/dist/esm/editor-feature-utils.js +164 -0
  143. package/dist/esm/editor-feature-utils.js.map +1 -0
  144. package/dist/esm/effect-utils.js +333 -0
  145. package/dist/esm/effect-utils.js.map +1 -0
  146. package/dist/esm/export-map-html.js +107 -0
  147. package/dist/esm/export-map-html.js.map +1 -0
  148. package/dist/esm/export-utils.js +297 -0
  149. package/dist/esm/export-utils.js.map +1 -0
  150. package/dist/esm/extract-dataset-utils.js +206 -0
  151. package/dist/esm/extract-dataset-utils.js.map +1 -0
  152. package/dist/esm/filter-utils.js +1701 -0
  153. package/dist/esm/filter-utils.js.map +1 -0
  154. package/dist/esm/format.js +31 -0
  155. package/dist/esm/format.js.map +1 -0
  156. package/dist/esm/gl-utils.js +113 -0
  157. package/dist/esm/gl-utils.js.map +1 -0
  158. package/dist/esm/index.js +55 -0
  159. package/dist/esm/index.js.map +1 -0
  160. package/dist/esm/indexed-data-container.js +210 -0
  161. package/dist/esm/indexed-data-container.js.map +1 -0
  162. package/dist/esm/jenks.js +149 -0
  163. package/dist/esm/jenks.js.map +1 -0
  164. package/dist/esm/locale-utils.js +36 -0
  165. package/dist/esm/locale-utils.js.map +1 -0
  166. package/dist/esm/map-info-utils.js +35 -0
  167. package/dist/esm/map-info-utils.js.map +1 -0
  168. package/dist/esm/map-style-utils/mapbox-gl-style-editor.js +188 -0
  169. package/dist/esm/map-style-utils/mapbox-gl-style-editor.js.map +1 -0
  170. package/dist/esm/map-style-utils/mapbox-utils.js +144 -0
  171. package/dist/esm/map-style-utils/mapbox-utils.js.map +1 -0
  172. package/dist/esm/map-utils.js +72 -0
  173. package/dist/esm/map-utils.js.map +1 -0
  174. package/dist/esm/mapbox-utils.js +13 -0
  175. package/dist/esm/mapbox-utils.js.map +1 -0
  176. package/dist/esm/notifications-utils.js +63 -0
  177. package/dist/esm/notifications-utils.js.map +1 -0
  178. package/dist/esm/observe-dimensions.js +128 -0
  179. package/dist/esm/observe-dimensions.js.map +1 -0
  180. package/dist/esm/plot.js +1460 -0
  181. package/dist/esm/plot.js.map +1 -0
  182. package/dist/esm/position-utils.js +22 -0
  183. package/dist/esm/position-utils.js.map +1 -0
  184. package/dist/esm/projection-utils.js +131 -0
  185. package/dist/esm/projection-utils.js.map +1 -0
  186. package/dist/esm/quick-insertion-sort.js +125 -0
  187. package/dist/esm/quick-insertion-sort.js.map +1 -0
  188. package/dist/esm/row-data-container.js +286 -0
  189. package/dist/esm/row-data-container.js.map +1 -0
  190. package/dist/esm/slider-scale-utils.js +129 -0
  191. package/dist/esm/slider-scale-utils.js.map +1 -0
  192. package/dist/esm/split-map-utils.js +109 -0
  193. package/dist/esm/split-map-utils.js.map +1 -0
  194. package/dist/esm/strings.js +10 -0
  195. package/dist/esm/strings.js.map +1 -0
  196. package/dist/esm/theme-utils.js +38 -0
  197. package/dist/esm/theme-utils.js.map +1 -0
  198. package/dist/esm/time.js +308 -0
  199. package/dist/esm/time.js.map +1 -0
  200. package/dist/esm/types.js +3 -0
  201. package/dist/esm/types.js.map +1 -0
  202. package/dist/esm/utils.js +203 -0
  203. package/dist/esm/utils.js.map +1 -0
  204. package/dist/export-map-html.d.ts +5 -0
  205. package/dist/export-utils.d.ts +31 -3
  206. package/dist/extract-dataset-utils.d.ts +79 -0
  207. package/dist/filter-utils.d.ts +56 -7
  208. package/dist/index.d.ts +20 -9
  209. package/dist/jenks.d.ts +5 -0
  210. package/dist/map-info-utils.d.ts +11 -1
  211. package/dist/map-style-utils/mapbox-gl-style-editor.d.ts +11 -10
  212. package/dist/map-style-utils/mapbox-utils.d.ts +29 -1
  213. package/dist/plot.d.ts +187 -21
  214. package/dist/projection-utils.d.ts +6 -4
  215. package/dist/row-data-container.d.ts +19 -0
  216. package/dist/split-map-utils.d.ts +7 -0
  217. package/dist/theme-utils.d.ts +8 -0
  218. package/dist/time.d.ts +3 -3
  219. package/dist/types.d.ts +2 -0
  220. package/package.json +33 -26
  221. package/dist/aggregation.js +0 -84
  222. package/dist/application-config-types.js +0 -6
  223. package/dist/application-config.js +0 -113
  224. package/dist/arrow-data-container.js +0 -398
  225. package/dist/browser-utils.js +0 -17
  226. package/dist/color-utils.js +0 -462
  227. package/dist/data-container-interface.js +0 -6
  228. package/dist/data-container-utils.js +0 -75
  229. package/dist/data-row.js +0 -110
  230. package/dist/data-scale-utils.js +0 -620
  231. package/dist/data-utils.js +0 -532
  232. package/dist/dataset-utils.js +0 -330
  233. package/dist/dom-to-image.js +0 -433
  234. package/dist/dom-utils.js +0 -349
  235. package/dist/effect-utils.js +0 -318
  236. package/dist/export-map-html.js +0 -38
  237. package/dist/export-utils.js +0 -203
  238. package/dist/filter-utils.js +0 -1274
  239. package/dist/format.js +0 -38
  240. package/dist/gl-utils.js +0 -118
  241. package/dist/indexed-data-container.js +0 -214
  242. package/dist/locale-utils.js +0 -39
  243. package/dist/map-info-utils.js +0 -14
  244. package/dist/map-style-utils/mapbox-gl-style-editor.js +0 -194
  245. package/dist/map-style-utils/mapbox-utils.js +0 -107
  246. package/dist/map-utils.js +0 -72
  247. package/dist/mapbox-utils.js +0 -19
  248. package/dist/noop.d.ts +0 -1
  249. package/dist/noop.js +0 -13
  250. package/dist/notifications-utils.js +0 -69
  251. package/dist/observe-dimensions.js +0 -136
  252. package/dist/plot.js +0 -637
  253. package/dist/position-utils.js +0 -26
  254. package/dist/projection-utils.js +0 -91
  255. package/dist/quick-insertion-sort.js +0 -132
  256. package/dist/row-data-container.js +0 -206
  257. package/dist/searcher-utils.d.ts +0 -1
  258. package/dist/searcher-utils.js +0 -25
  259. package/dist/slider-scale-utils.js +0 -138
  260. package/dist/split-map-utils.js +0 -99
  261. package/dist/strings.js +0 -16
  262. package/dist/time.js +0 -325
  263. package/dist/types.js +0 -6
  264. package/dist/utils.js +0 -224
@@ -0,0 +1,1502 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.PLOT_NUM_GROUPS_OPTIONS = exports.PLOT_NUM_GROUPS_ALL = exports.PLOT_GROUP_OTHERS_NAME = exports.MAX_PLOT_NUM_GROUPS = exports.DEFAULT_PLOT_NUM_GROUPS = void 0;
8
+ exports.adjustValueToAnimationWindow = adjustValueToAnimationWindow;
9
+ exports.binByTime = binByTime;
10
+ exports.defaultPlotGroupColorRange = defaultPlotGroupColorRange;
11
+ exports.getAggregationOptiosnBasedOnField = void 0;
12
+ exports.getBinThresholds = getBinThresholds;
13
+ exports.getChartTitle = getChartTitle;
14
+ exports.getDefaultPlotType = getDefaultPlotType;
15
+ exports.getFilterBinThresholds = getFilterBinThresholds;
16
+ exports.getFilterDataFunc = getFilterDataFunc;
17
+ exports.getLineChart = getLineChart;
18
+ exports.getNumericBinThresholds = getNumericBinThresholds;
19
+ exports.getNumericPlotInterval = getNumericPlotInterval;
20
+ exports.getNumericRangeMinimum = getNumericRangeMinimum;
21
+ exports.getPctChange = getPctChange;
22
+ exports.getRangeFilterBins = getRangeFilterBins;
23
+ exports.getTimeBins = getTimeBins;
24
+ exports.getValueAggrFunc = void 0;
25
+ exports.histogramFromDomain = histogramFromDomain;
26
+ exports.histogramFromOrdinal = histogramFromOrdinal;
27
+ exports.histogramFromThreshold = histogramFromThreshold;
28
+ exports.histogramFromTimeIntervals = histogramFromTimeIntervals;
29
+ exports.histogramFromValues = histogramFromValues;
30
+ exports.intervalBinFromMarks = intervalBinFromMarks;
31
+ exports.isPercentField = isPercentField;
32
+ exports.lineChartSeriesLegend = lineChartSeriesLegend;
33
+ exports.mergePlotGroupBy = mergePlotGroupBy;
34
+ exports.mergePolygonLayerIndexes = mergePolygonLayerIndexes;
35
+ exports.nextDown = nextDown;
36
+ exports.nextUp = nextUp;
37
+ exports.normalizeValue = normalizeValue;
38
+ exports.plotGroupColorSteps = plotGroupColorSteps;
39
+ exports.runGpuFilterForPlot = runGpuFilterForPlot;
40
+ exports.snapToMarks = snapToMarks;
41
+ exports.splitSeries = splitSeries;
42
+ exports.updateAggregationByField = updateAggregationByField;
43
+ exports.updateRangeFilterPlotType = updateRangeFilterPlotType;
44
+ exports.updateTimeFilterPlotType = updateTimeFilterPlotType;
45
+ exports.validBin = validBin;
46
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
47
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
48
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
49
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
50
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
51
+ var _d3Array = require("d3-array");
52
+ var _isEqual = _interopRequireDefault(require("es-toolkit/compat/isEqual"));
53
+ var _time = require("./time");
54
+ var _commonUtils = require("@kepler.gl/common-utils");
55
+ var _constants = require("@kepler.gl/constants");
56
+ var _dataUtils = require("./data-utils");
57
+ var _aggregation = require("./aggregation");
58
+ var _strings = require("./strings");
59
+ var _format = require("./format");
60
+ var _colorUtils = require("./color-utils");
61
+ var _excluded = ["numericInterval"];
62
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
63
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
64
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
65
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
66
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } // SPDX-License-Identifier: MIT
67
+ // Copyright contributors to the kepler.gl project
68
+ // TODO kepler-table module isn't accessible from utils. Add compatible interface to types
69
+
70
+ /**
71
+ * Merge per-layer polygon-filtered indices into a dataset-level index.
72
+ * When any layers are polygon-filtered, take the union of their indices (a row is kept if it
73
+ * is visible on at least one targeted layer), then intersect with the base index.
74
+ * Used for filtered export and filter plots/histograms.
75
+ */
76
+ function mergePolygonLayerIndexes(baseIndex) {
77
+ var filteredIndexByLayer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
78
+ var layerIndexes = Object.values(filteredIndexByLayer);
79
+ if (!layerIndexes.length) {
80
+ return baseIndex;
81
+ }
82
+ var union = new Set();
83
+ for (var _i = 0, _layerIndexes = layerIndexes; _i < _layerIndexes.length; _i++) {
84
+ var indexes = _layerIndexes[_i];
85
+ var _iterator = _createForOfIteratorHelper(indexes),
86
+ _step;
87
+ try {
88
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
89
+ var idx = _step.value;
90
+ union.add(idx);
91
+ }
92
+ } catch (err) {
93
+ _iterator.e(err);
94
+ } finally {
95
+ _iterator.f();
96
+ }
97
+ }
98
+ return baseIndex.filter(function (i) {
99
+ return union.has(i);
100
+ });
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @param thresholds
106
+ * @param values
107
+ * @param indexes
108
+ */
109
+ function histogramFromThreshold(thresholds, values, valueAccessor) {
110
+ var filterEmptyBins = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
111
+ var getBins = (0, _d3Array.histogram)().domain([thresholds[0], thresholds[thresholds.length - 1]]).thresholds(thresholds);
112
+ if (valueAccessor) {
113
+ getBins.value(valueAccessor);
114
+ }
115
+
116
+ // @ts-ignore
117
+ var bins = getBins(values).map(function (bin) {
118
+ return {
119
+ count: bin.length,
120
+ indexes: bin,
121
+ x0: bin.x0,
122
+ x1: bin.x1
123
+ };
124
+ });
125
+
126
+ // d3-histogram ignores threshold values outside the domain
127
+ // The first bin.x0 is always equal to the minimum domain value, and the last bin.x1 is always equal to the maximum domain value.
128
+
129
+ // bins[0].x0 = thresholds[0];
130
+ // bins[bins.length - 1].x1 = thresholds[thresholds.length - 1];
131
+
132
+ // @ts-ignore
133
+ return filterEmptyBins ? bins.filter(function (b) {
134
+ return b.count > 0;
135
+ }) : bins;
136
+ }
137
+
138
+ /**
139
+ *
140
+ * @param values
141
+ * @param numBins
142
+ * @param valueAccessor
143
+ */
144
+ function histogramFromValues(values, numBins, valueAccessor) {
145
+ var getBins = (0, _d3Array.histogram)().thresholds(numBins);
146
+ if (valueAccessor) {
147
+ getBins.value(valueAccessor);
148
+ }
149
+
150
+ // @ts-ignore d3-array types doesn't match
151
+ return getBins(values).map(function (bin) {
152
+ return {
153
+ count: bin.length,
154
+ indexes: bin,
155
+ x0: bin.x0,
156
+ x1: bin.x1
157
+ };
158
+ }).filter(function (b) {
159
+ var x0 = b.x0,
160
+ x1 = b.x1;
161
+ return (0, _dataUtils.isNumber)(x0) && (0, _dataUtils.isNumber)(x1);
162
+ });
163
+ }
164
+ function histogramFromOrdinal(domain, values, valueAccessor) {
165
+ // @ts-expect-error to typed to expect strings
166
+ var getBins = (0, _d3Array.histogram)().thresholds(domain);
167
+ if (valueAccessor) {
168
+ // @ts-expect-error to typed to expect strings
169
+ getBins.value(valueAccessor);
170
+ }
171
+
172
+ // @ts-expect-error null values aren't expected
173
+ var bins = getBins(values);
174
+
175
+ // @ts-ignore d3-array types doesn't match
176
+ return bins.map(function (bin) {
177
+ return {
178
+ count: bin.length,
179
+ indexes: bin,
180
+ x0: bin.x0,
181
+ x1: bin.x0
182
+ };
183
+ });
184
+ }
185
+
186
+ /**
187
+ * Bin rows by time interval overlap: a feature [start, end] is counted in every
188
+ * bin whose range intersects that span. Null/undefined end is treated as still
189
+ * active through the last threshold (open-ended).
190
+ */
191
+ function histogramFromTimeIntervals(thresholds, indexes, startAccessor, endAccessor) {
192
+ if (!thresholds || thresholds.length < 2) {
193
+ return [];
194
+ }
195
+ var nBins = thresholds.length - 1;
196
+ var bins = [];
197
+ for (var i = 0; i < nBins; i++) {
198
+ bins.push({
199
+ count: 0,
200
+ indexes: [],
201
+ x0: thresholds[i],
202
+ x1: thresholds[i + 1]
203
+ });
204
+ }
205
+ var lastThreshold = thresholds[nBins];
206
+ var _iterator2 = _createForOfIteratorHelper(indexes),
207
+ _step2;
208
+ try {
209
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
210
+ var idx = _step2.value;
211
+ var start = startAccessor(idx);
212
+ if (!(0, _commonUtils.notNullorUndefined)(start) || Number.isNaN(start)) {
213
+ continue;
214
+ }
215
+ var rawEnd = endAccessor(idx);
216
+ if ((0, _commonUtils.notNullorUndefined)(rawEnd) && !Number.isNaN(rawEnd) && rawEnd < start) {
217
+ continue;
218
+ }
219
+ var end = (0, _commonUtils.notNullorUndefined)(rawEnd) && !Number.isNaN(rawEnd) ? rawEnd : lastThreshold;
220
+ var startBin = (0, _d3Array.bisectRight)(thresholds, start) - 1;
221
+ var endBin = (0, _d3Array.bisectRight)(thresholds, end) - 1;
222
+ if (startBin < 0) startBin = 0;
223
+ if (startBin >= nBins && start === lastThreshold) startBin = nBins - 1;
224
+ if (endBin >= nBins) endBin = nBins - 1;
225
+ if (endBin < 0 || startBin >= nBins || endBin < startBin) {
226
+ continue;
227
+ }
228
+ for (var _i2 = startBin; _i2 <= endBin; _i2++) {
229
+ bins[_i2].indexes.push(idx);
230
+ bins[_i2].count += 1;
231
+ }
232
+ }
233
+ } catch (err) {
234
+ _iterator2.e(err);
235
+ } finally {
236
+ _iterator2.f();
237
+ }
238
+ return bins.filter(function (b) {
239
+ return b.count > 0;
240
+ });
241
+ }
242
+ function getEndMappedValue(dataset, filter) {
243
+ var _filter$endMappedValu, _field$filterProps;
244
+ var datasetIdx = (0, _commonUtils.toArray)(filter.dataId).indexOf(dataset.id);
245
+ var fromFilter = (_filter$endMappedValu = filter.endMappedValue) === null || _filter$endMappedValu === void 0 ? void 0 : _filter$endMappedValu[datasetIdx];
246
+ if (Array.isArray(fromFilter)) {
247
+ return fromFilter;
248
+ }
249
+ var endName = (0, _commonUtils.toArray)(filter.endName)[datasetIdx];
250
+ if (!endName || typeof dataset.getColumnField !== 'function') {
251
+ return null;
252
+ }
253
+ var field = dataset.getColumnField(endName);
254
+ return (field === null || field === void 0 || (_field$filterProps = field.filterProps) === null || _field$filterProps === void 0 ? void 0 : _field$filterProps.mappedValue) || null;
255
+ }
256
+
257
+ /**
258
+ * @param domain
259
+ * @param values
260
+ * @param numBins
261
+ * @param valueAccessor
262
+ */
263
+ function histogramFromDomain(domain, values, numBins, valueAccessor) {
264
+ var getBins = (0, _d3Array.histogram)().thresholds((0, _d3Array.ticks)(domain[0], domain[1], numBins)).domain(domain);
265
+ if (valueAccessor) {
266
+ getBins.value(valueAccessor);
267
+ }
268
+
269
+ // @ts-ignore d3-array types doesn't match
270
+ return getBins(values).map(function (bin) {
271
+ return {
272
+ count: bin.length,
273
+ indexes: bin,
274
+ x0: bin.x0,
275
+ x1: bin.x1
276
+ };
277
+ });
278
+ }
279
+ var timeBinDomains = new WeakMap();
280
+
281
+ /**
282
+ * @param filter
283
+ * @param datasets
284
+ * @param interval
285
+ */
286
+ function getTimeBins(filter, datasets, interval, plotBaseIndexByDataId) {
287
+ interval = getTimeBinConfig(interval, filter.domain).interval;
288
+ var cachedDomain = filter.timeBins && timeBinDomains.get(filter.timeBins);
289
+ // Preserve caller-supplied caches; invalidate a domain change once it is known.
290
+ var bins = cachedDomain && !(0, _isEqual["default"])(cachedDomain, filter.domain) ? {} : filter.timeBins || {};
291
+ filter.dataId.forEach(function (dataId) {
292
+ // reuse bins if filterData did not change
293
+ if (bins[dataId] && bins[dataId][interval]) {
294
+ return;
295
+ }
296
+ var dataset = datasets[dataId];
297
+
298
+ // do not apply current filter
299
+ var indexes = runGpuFilterForPlot(dataset, filter, undefined, plotBaseIndexByDataId === null || plotBaseIndexByDataId === void 0 ? void 0 : plotBaseIndexByDataId[dataId]);
300
+ bins = _objectSpread(_objectSpread({}, bins), {}, (0, _defineProperty2["default"])({}, dataId, _objectSpread(_objectSpread({}, bins[dataId]), {}, (0, _defineProperty2["default"])({}, interval, binByTime(indexes, dataset, interval, filter)))));
301
+ });
302
+ timeBinDomains.set(bins, Array.isArray(filter.domain) ? filter.domain.slice(0, 2) : []);
303
+ return bins;
304
+ }
305
+ function binByTime(indexes, dataset, interval, filter) {
306
+ // gpuFilters need to be apply to filteredIndex
307
+ var mappedValue = (0, _time.getFilterMappedValue)(dataset, filter);
308
+ if (!mappedValue) {
309
+ return null;
310
+ }
311
+ var intervalBins = getBinThresholds(interval, filter.domain);
312
+ var endMapped = getEndMappedValue(dataset, filter);
313
+ if (Array.isArray(endMapped)) {
314
+ return histogramFromTimeIntervals(intervalBins, indexes, function (idx) {
315
+ return mappedValue[idx];
316
+ }, function (idx) {
317
+ return endMapped[idx];
318
+ });
319
+ }
320
+ var valueAccessor = function valueAccessor(idx) {
321
+ return mappedValue[idx];
322
+ };
323
+ var bins = histogramFromThreshold(intervalBins, indexes, valueAccessor);
324
+ return bins;
325
+ }
326
+ function getBinThresholds(interval, domain) {
327
+ return getTimeBinConfig(interval, domain).thresholds.slice();
328
+ }
329
+ var MAX_TIME_BINS = 2048;
330
+ // Weak keys keep validation local to live domains without retaining old filters.
331
+ var timeBinConfigs = new WeakMap();
332
+
333
+ /** Resolve the interval and its complete domain together, never truncating a plot. */
334
+ function getTimeBinConfig(interval, domain) {
335
+ if (!Array.isArray(domain) || domain.length !== 2 || !domain.every(function (value) {
336
+ return Number.isFinite(value) && Number.isFinite(new Date(value).getTime());
337
+ }) || domain[1] < domain[0]) {
338
+ return {
339
+ interval: interval,
340
+ thresholds: []
341
+ };
342
+ }
343
+ var cached = timeBinConfigs.get(domain);
344
+ if (cached && (0, _isEqual["default"])(cached.domain, domain) && (cached.requestedInterval === interval || cached.result.interval === interval)) {
345
+ return cached.result;
346
+ }
347
+ var build = function build(id) {
348
+ var match = /^(\d+)-(millisecond|second|minute|hour|day|week|month|year)$/.exec(id);
349
+ var step = Number(match === null || match === void 0 ? void 0 : match[1]);
350
+ if (!match || !Number.isSafeInteger(step) || step <= 0) return null;
351
+ var timeInterval = (0, _time.intervalToFunction)(id);
352
+ if (!timeInterval) return null;
353
+ // Filtered D3 intervals can loop internally after Date overflow. Near the
354
+ // Date limits, walk at most one field cycle using the unfiltered interval.
355
+ var period = {
356
+ second: 60,
357
+ minute: 60,
358
+ hour: 24,
359
+ day: 31,
360
+ month: 12
361
+ }[match[2]];
362
+ if (step > 1 && period) {
363
+ var base = (0, _time.intervalToFunction)("1-".concat(match[2]));
364
+ if (!Number.isFinite(Number(base.offset(domain[0], -period))) || !Number.isFinite(Number(base.offset(domain[1], period)))) {
365
+ var field = {
366
+ second: function second(date) {
367
+ return date.getUTCSeconds();
368
+ },
369
+ minute: function minute(date) {
370
+ return date.getUTCMinutes();
371
+ },
372
+ hour: function hour(date) {
373
+ return date.getUTCHours();
374
+ },
375
+ day: function day(date) {
376
+ return date.getUTCDate() - 1;
377
+ },
378
+ month: function month(date) {
379
+ return date.getUTCMonth();
380
+ }
381
+ }[match[2]];
382
+ if (!field) return null;
383
+ var walk = function walk(value, direction) {
384
+ var includeCurrent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
385
+ var date = base.floor(value);
386
+ for (var index = 0; index < period; index++) {
387
+ if (!includeCurrent || index) date = base.offset(date, direction);
388
+ if (!Number.isFinite(Number(date))) return date;
389
+ if (field(date) % step === 0) return date;
390
+ }
391
+ return new Date(NaN);
392
+ };
393
+ timeInterval = {
394
+ floor: function floor(value) {
395
+ return walk(value, -1, true);
396
+ },
397
+ offset: function offset(value) {
398
+ return walk(value, 1);
399
+ }
400
+ };
401
+ }
402
+ }
403
+ if (match[2] === 'week' && step > 1) {
404
+ // D3's filtered week.offset walks every intervening week. Use the same
405
+ // epoch alignment without an unbounded scan for large configured steps.
406
+ var week = (0, _time.intervalToFunction)('1-week');
407
+ timeInterval = {
408
+ floor: function floor(value) {
409
+ var floor = week.floor(value);
410
+ var remainder = (week.count(0, floor) % step + step) % step;
411
+ return week.offset(floor, -remainder);
412
+ },
413
+ offset: function offset(value) {
414
+ return week.offset(value, step);
415
+ }
416
+ };
417
+ }
418
+ var boundary = Number(timeInterval.floor(domain[0]));
419
+ var thresholds = [];
420
+ // Include the first boundary strictly after max, even when max is aligned.
421
+ // This preserves the existing inclusive maximum bin and calendar padding.
422
+ for (var index = 0; index <= MAX_TIME_BINS; index++) {
423
+ if (!Number.isFinite(boundary)) return null;
424
+ thresholds.push(boundary);
425
+ if (boundary > domain[1]) return thresholds;
426
+ var next = Number(timeInterval.floor(timeInterval.offset(boundary)));
427
+ if (!(next > boundary)) return null;
428
+ boundary = next;
429
+ }
430
+ return null;
431
+ };
432
+ var requestedInterval = interval;
433
+ var thresholds = build(interval);
434
+ // Domain-only fallback avoids copying/sorting every timestamp on refresh.
435
+ // Retry fewer ticks when the nearest interval still exceeds the cap.
436
+ for (var target = _constants.BINS_LARGE; !thresholds && target >= 1; target /= 10) {
437
+ interval = (0, _time.getIntervalByTicks)(target, domain[0], domain[1]);
438
+ thresholds = build(interval);
439
+ }
440
+ var result = {
441
+ interval: interval,
442
+ thresholds: thresholds || []
443
+ };
444
+ timeBinConfigs.set(domain, {
445
+ requestedInterval: requestedInterval,
446
+ domain: domain.slice(),
447
+ result: result
448
+ });
449
+ return result;
450
+ }
451
+ function normalizeTimePlotType(plotType, domain) {
452
+ var _getTimeBinConfig = getTimeBinConfig(plotType.interval, domain),
453
+ interval = _getTimeBinConfig.interval;
454
+ return interval === plotType.interval ? plotType : _objectSpread(_objectSpread({}, plotType), {}, {
455
+ interval: interval,
456
+ defaultTimeFormat: (0, _format.getDefaultTimeFormat)(interval)
457
+ });
458
+ }
459
+ var MAX_NUMERIC_BINS = 2048;
460
+ function getNumericBinCount(domain, interval) {
461
+ var _domain = (0, _slicedToArray2["default"])(domain, 2),
462
+ start = _domain[0],
463
+ end = _domain[1];
464
+ var rawCount = (end - start) / interval;
465
+ var roundedCount = Math.round(rawCount);
466
+ return Math.abs(rawCount - roundedCount) <= Number.EPSILON * Math.max(1, Math.abs(rawCount)) * 16 ? roundedCount : Math.ceil(rawCount);
467
+ }
468
+ function normalizeNumericInterval(domain, interval) {
469
+ if (!Number.isFinite(interval) || !(Number(interval) > 0)) {
470
+ return undefined;
471
+ }
472
+ if (Array.isArray(domain) && domain.length >= 2 && domain.every(Number.isFinite) && domain[1] > domain[0] && getNumericBinCount(domain, Number(interval)) > MAX_NUMERIC_BINS) {
473
+ return undefined;
474
+ }
475
+ return Number(interval);
476
+ }
477
+
478
+ /**
479
+ * Build histogram thresholds in the numeric field's own units.
480
+ * Unlike time intervals, numeric intervals are anchored to the filter domain
481
+ * and never pass through calendar conversion.
482
+ */
483
+ function getNumericBinThresholds(domain, interval) {
484
+ var numBins = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _constants.BINS;
485
+ if (!Array.isArray(domain) || domain.length < 2 || !domain.every(Number.isFinite)) {
486
+ return [];
487
+ }
488
+ var _domain2 = (0, _slicedToArray2["default"])(domain, 2),
489
+ start = _domain2[0],
490
+ end = _domain2[1];
491
+ if (!(end > start)) {
492
+ return [start, end];
493
+ }
494
+ if (!Number.isFinite(interval) || !(Number(interval) > 0)) {
495
+ var numericTicks = (0, _d3Array.ticks)(start, end, numBins).filter(function (value) {
496
+ return value > start && value < end;
497
+ });
498
+ return [start].concat((0, _toConsumableArray2["default"])(numericTicks), [end]);
499
+ }
500
+ var width = Number(interval);
501
+ var count = getNumericBinCount(domain, width);
502
+ if (count > MAX_NUMERIC_BINS) {
503
+ return getNumericBinThresholds(domain, undefined, numBins);
504
+ }
505
+ var thresholds = [start];
506
+ for (var index = 1; index < count; index++) {
507
+ var boundary = start + index * width;
508
+ if (boundary > thresholds[thresholds.length - 1] && boundary < end) {
509
+ thresholds.push(boundary);
510
+ }
511
+ }
512
+ if (end > thresholds[thresholds.length - 1]) {
513
+ thresholds.push(end);
514
+ }
515
+ return thresholds;
516
+ }
517
+ var float64View = new DataView(new ArrayBuffer(8));
518
+ function adjacentFloat(value, direction) {
519
+ if (Number.isNaN(value) || value === direction * Infinity) {
520
+ return value;
521
+ }
522
+ if (value === 0) {
523
+ return direction > 0 ? Number.MIN_VALUE : -Number.MIN_VALUE;
524
+ }
525
+ float64View.setFloat64(0, value, false);
526
+ var high = float64View.getUint32(0, false);
527
+ var low = float64View.getUint32(4, false);
528
+ var incrementBits = value > 0 === direction > 0;
529
+ if (incrementBits) {
530
+ low = low + 1 >>> 0;
531
+ if (low === 0) {
532
+ high = high + 1 >>> 0;
533
+ }
534
+ } else if (low === 0) {
535
+ low = 0xffffffff;
536
+ high = high - 1 >>> 0;
537
+ } else {
538
+ low = low - 1 >>> 0;
539
+ }
540
+ float64View.setUint32(0, high, false);
541
+ float64View.setUint32(4, low, false);
542
+ return float64View.getFloat64(0, false);
543
+ }
544
+
545
+ /** Return the next representable IEEE-754 number above value. */
546
+ function nextUp(value) {
547
+ return adjacentFloat(value, 1);
548
+ }
549
+
550
+ /** Return the next representable IEEE-754 number below value. */
551
+ function nextDown(value) {
552
+ return adjacentFloat(value, -1);
553
+ }
554
+
555
+ /**
556
+ * Smallest useful range width across a numeric domain. It is large enough to
557
+ * move either endpoint by one representable value and never exceeds the span.
558
+ */
559
+ function getNumericRangeMinimum(domain) {
560
+ if (!Array.isArray(domain) || domain.length < 2 || !domain.every(Number.isFinite)) {
561
+ return 0;
562
+ }
563
+ var _domain3 = (0, _slicedToArray2["default"])(domain, 2),
564
+ start = _domain3[0],
565
+ end = _domain3[1];
566
+ var span = end - start;
567
+ if (!(span > 0)) {
568
+ return 0;
569
+ }
570
+ var startResolution = nextUp(start) - start;
571
+ var endResolution = end - nextDown(end);
572
+ return Math.min(span, Math.max(startResolution, endResolution));
573
+ }
574
+
575
+ /** Infer the regular numeric bin width, ignoring tiny padded edge bins. */
576
+ function getNumericPlotInterval(filter) {
577
+ var _filter$plotType, _filter$domain, _filter$domain2;
578
+ if (Number.isFinite((_filter$plotType = filter.plotType) === null || _filter$plotType === void 0 ? void 0 : _filter$plotType.numericInterval) && filter.plotType.numericInterval > 0) {
579
+ return filter.plotType.numericInterval;
580
+ }
581
+ var bins = Object.values(filter.bins || {}).find(function (value) {
582
+ return value === null || value === void 0 ? void 0 : value.length;
583
+ });
584
+ var binWidths = (bins || []).map(function (bin) {
585
+ return bin.x1 - bin.x0;
586
+ }).filter(function (width) {
587
+ return Number.isFinite(width) && width > 0;
588
+ }).sort(function (a, b) {
589
+ return a - b;
590
+ });
591
+ var binWidth = binWidths.length ? binWidths[Math.floor(binWidths.length / 2)] : 0;
592
+ if (binWidth > 0) {
593
+ return Number(binWidth.toPrecision(10));
594
+ }
595
+ var span = ((_filter$domain = filter.domain) === null || _filter$domain === void 0 ? void 0 : _filter$domain[1]) - ((_filter$domain2 = filter.domain) === null || _filter$domain2 === void 0 ? void 0 : _filter$domain2[0]);
596
+ return span > 0 ? Number((span / _constants.BINS).toPrecision(10)) : filter.step;
597
+ }
598
+
599
+ /** Return the plotted bin boundaries for either a time or numeric range filter. */
600
+ function getFilterBinThresholds(filter) {
601
+ var _filter$plotType3;
602
+ if (filter.type === _constants.FILTER_TYPES.timeRange) {
603
+ var _filter$plotType2;
604
+ return getBinThresholds((_filter$plotType2 = filter.plotType) === null || _filter$plotType2 === void 0 ? void 0 : _filter$plotType2.interval, filter.domain);
605
+ }
606
+ var firstBins = Object.values(filter.bins || {}).find(Boolean) || [];
607
+ if (firstBins.length) {
608
+ return [].concat((0, _toConsumableArray2["default"])(firstBins.map(function (bin) {
609
+ return bin.x0;
610
+ })), [firstBins[firstBins.length - 1].x1]);
611
+ }
612
+ return getNumericBinThresholds(filter.domain, (_filter$plotType3 = filter.plotType) === null || _filter$plotType3 === void 0 ? void 0 : _filter$plotType3.numericInterval);
613
+ }
614
+
615
+ /**
616
+ * Run GPU filter on current filter result to generate indexes for ploting chart
617
+ * Skip ruuning for the same field
618
+ * @param dataset
619
+ * @param filter Histogram filter whose dataId-paired column should be skipped
620
+ * @param skipFieldNames Extra GPU field names to skip (charts cross-filter). Histogram callers omit this.
621
+ * @param baseIndex CPU base that excludes the plotted filter and already includes polygon filters.
622
+ */
623
+ function runGpuFilterForPlot(dataset, filter, skipFieldNames, baseIndex) {
624
+ var skipIndexes = getSkipIndexes(dataset, filter, skipFieldNames);
625
+ var _dataset$gpuFilter = dataset.gpuFilter,
626
+ filterValueUpdateTriggers = _dataset$gpuFilter.filterValueUpdateTriggers,
627
+ filterRange = _dataset$gpuFilter.filterRange,
628
+ filterValueAccessor = _dataset$gpuFilter.filterValueAccessor,
629
+ filteredIndex = dataset.filteredIndex,
630
+ filteredIndexByLayer = dataset.filteredIndexByLayer;
631
+ // Cached polygon indexes were built after the current CPU filter. When that
632
+ // filter is omitted, use the polygon-filtered base reconstructed by the caller.
633
+ var plotFilteredIndex = baseIndex !== null && baseIndex !== void 0 ? baseIndex : mergePolygonLayerIndexes(filteredIndex, filteredIndexByLayer);
634
+ var getFilterValue = filterValueAccessor(dataset.dataContainer)();
635
+ var allChannels = Object.keys(filterValueUpdateTriggers).map(function (_, i) {
636
+ return i;
637
+ }).filter(function (i) {
638
+ return Object.values(filterValueUpdateTriggers)[i];
639
+ });
640
+ var skipAll = !allChannels.filter(function (i) {
641
+ return !skipIndexes.includes(i);
642
+ }).length;
643
+ if (skipAll) {
644
+ return plotFilteredIndex;
645
+ }
646
+ var filterData = getFilterDataFunc(filterRange, getFilterValue, dataset.dataContainer, skipIndexes);
647
+ return plotFilteredIndex.filter(filterData);
648
+ }
649
+ function getSkipIndexes(dataset, filter, skipFieldNames) {
650
+ var _filter$endName;
651
+ // array of gpu filter names
652
+ var gpuFilters = Object.values(dataset.gpuFilter.filterValueUpdateTriggers);
653
+
654
+ // Charts pass extra field names so a cross-filter does not hide its own bins.
655
+ // Histogram plots never pass this list and keep the original dataId pairing.
656
+ if (skipFieldNames !== null && skipFieldNames !== void 0 && skipFieldNames.length) {
657
+ var skipNames = new Set(skipFieldNames.filter(function (name) {
658
+ return Boolean(name);
659
+ }));
660
+ return gpuFilters.reduce(function (accu, item, idx) {
661
+ if (item && skipNames.has(item.name)) {
662
+ accu.push(idx);
663
+ }
664
+ return accu;
665
+ }, []);
666
+ }
667
+ if (!filter) {
668
+ return [];
669
+ }
670
+ var valueIndex = filter.dataId.findIndex(function (id) {
671
+ return id === dataset.id;
672
+ });
673
+ // Channels identify the plotted GPU filter precisely when another filter uses the same field.
674
+ if (filter.gpu && valueIndex >= 0) {
675
+ var _filter$gpuChannel, _filter$gpuEndChannel;
676
+ var assignedChannels = [(_filter$gpuChannel = filter.gpuChannel) === null || _filter$gpuChannel === void 0 ? void 0 : _filter$gpuChannel[valueIndex], (_filter$gpuEndChannel = filter.gpuEndChannel) === null || _filter$gpuEndChannel === void 0 ? void 0 : _filter$gpuEndChannel[valueIndex]].filter(Number.isFinite);
677
+ if (assignedChannels.length) {
678
+ return assignedChannels;
679
+ }
680
+ }
681
+ // CPU filters are already omitted from baseIndex, so every GPU channel remains applicable.
682
+ if (filter.gpu === false && valueIndex >= 0) {
683
+ return [];
684
+ }
685
+ var filterColumn = filter.name[valueIndex];
686
+ var filterEndColumn = (_filter$endName = filter.endName) === null || _filter$endName === void 0 ? void 0 : _filter$endName[valueIndex];
687
+ return gpuFilters.reduce(function (accu, item, idx) {
688
+ if (item && (filterColumn === item.name || filterEndColumn === item.name)) {
689
+ accu.push(idx);
690
+ }
691
+ return accu;
692
+ }, []);
693
+ }
694
+ function getFilterDataFunc(filterRange, getFilterValue, dataContainer, skips) {
695
+ return function (index) {
696
+ return getFilterValue({
697
+ index: index
698
+ }).every(function (val, i) {
699
+ return skips.includes(i) || val >= filterRange[i][0] && val <= filterRange[i][1];
700
+ });
701
+ };
702
+ }
703
+ function validBin(b) {
704
+ return b.x0 !== undefined && b.x1 !== undefined;
705
+ }
706
+
707
+ /**
708
+ * Turn a histogram brush or slider position into one bin.
709
+ * Interval playback steps by bin, and the filter comparison is inclusive.
710
+ * Time bins preserve their millisecond offset. Numeric bins use the immediate
711
+ * representable predecessor of the next mark so their membership matches D3's
712
+ * half-open bins; only the final numeric bin includes its upper boundary.
713
+ */
714
+ function intervalBinFromMarks(marks, value) {
715
+ var endOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
716
+ if (!marks.length || !Number.isFinite(value)) {
717
+ return [value, value];
718
+ }
719
+ if (marks.length === 1) {
720
+ return [marks[0], marks[0]];
721
+ }
722
+ var idx = (0, _d3Array.bisectCenter)(marks, value);
723
+ if (idx < 0) {
724
+ idx = 0;
725
+ }
726
+ // The last mark closes the final bin. Keep a drag there on that bin.
727
+ var lastBin = marks.length - 2;
728
+ if (idx > lastBin) {
729
+ idx = lastBin;
730
+ }
731
+ var start = marks[idx];
732
+ var end = marks[idx + 1];
733
+ if (endOffset === 0) {
734
+ return [start, idx === lastBin ? end : Math.max(start, nextDown(end))];
735
+ }
736
+ var offset = Number.isFinite(endOffset) && endOffset > 0 ? Math.min(endOffset, end - start) : 0;
737
+ return [start, Math.max(start, end - offset)];
738
+ }
739
+ function snapToMarks(value, marks) {
740
+ // always use bin x0
741
+ if (!marks.length) {
742
+ // @ts-expect-error looking at the usage null return value isn't expected and requires extra handling in a lot of places
743
+ return null;
744
+ }
745
+ var i = (0, _d3Array.bisectLeft)(marks, value);
746
+ if (i === 0) {
747
+ return marks[i];
748
+ } else if (i === marks.length) {
749
+ return marks[i - 1];
750
+ }
751
+ var idx = marks[i] - value < value - marks[i - 1] ? i : i - 1;
752
+ return marks[idx];
753
+ }
754
+ function normalizeValue(val, minValue, step, marks) {
755
+ if (marks && marks.length) {
756
+ return snapToMarks(val, marks);
757
+ }
758
+ return (0, _dataUtils.roundValToStep)(minValue, step, val);
759
+ }
760
+ function isPercentField(field) {
761
+ return field.metadata && field.metadata.numerator && field.metadata.denominator;
762
+ }
763
+ function updateAggregationByField(field, aggregation) {
764
+ // shouldn't apply sum to percent fiele type
765
+ // default aggregation is average
766
+ return field && isPercentField(field) ? _constants.AGGREGATION_TYPES.average : aggregation || _constants.AGGREGATION_TYPES.average;
767
+ }
768
+ var getAgregationType = function getAgregationType(field, aggregation) {
769
+ if (isPercentField(field)) {
770
+ return 'mean_of_percent';
771
+ }
772
+ return aggregation;
773
+ };
774
+ var getAggregationAccessor = function getAggregationAccessor(field, fields) {
775
+ if (isPercentField(field)) {
776
+ var numeratorIdx = fields.findIndex(function (f) {
777
+ return f.name === field.metadata.numerator;
778
+ });
779
+ var denominatorIdx = fields.findIndex(function (f) {
780
+ return f.name === field.metadata.denominator;
781
+ });
782
+ return {
783
+ getNumerator: function getNumerator(i) {
784
+ return fields[numeratorIdx].valueAccessor({
785
+ index: i
786
+ });
787
+ },
788
+ getDenominator: function getDenominator(i) {
789
+ return fields[denominatorIdx].valueAccessor({
790
+ index: i
791
+ });
792
+ }
793
+ };
794
+ }
795
+ return function (i) {
796
+ return field.valueAccessor({
797
+ index: i
798
+ });
799
+ };
800
+ };
801
+ var getValueAggrFunc = exports.getValueAggrFunc = function getValueAggrFunc(field, aggregation, dataset) {
802
+ var fields = dataset.fields;
803
+
804
+ // The passed-in field might not have all the fields set (e.g. valueAccessor)
805
+ var datasetField = fields.find(function (f) {
806
+ return field && (f.name === field || f.name === field.name);
807
+ });
808
+ return datasetField && aggregation ? function (bin) {
809
+ return (0, _aggregation.aggregate)(bin.indexes, getAgregationType(datasetField, aggregation),
810
+ // @ts-expect-error can return {getNumerator, getDenominator}
811
+ getAggregationAccessor(datasetField, fields));
812
+ } : function (bin) {
813
+ return bin.count;
814
+ };
815
+ };
816
+ var getAggregationOptiosnBasedOnField = exports.getAggregationOptiosnBasedOnField = function getAggregationOptiosnBasedOnField(field) {
817
+ if (isPercentField(field)) {
818
+ // don't show sum
819
+ return _constants.TIME_AGGREGATION.filter(function (_ref) {
820
+ var id = _ref.id;
821
+ return id !== _constants.AGGREGATION_TYPES.sum;
822
+ });
823
+ }
824
+ return _constants.TIME_AGGREGATION;
825
+ };
826
+ function getDelta(bins, y, _interval) {
827
+ // if (WOW[interval]) return getWow(bins, y, interval);
828
+ var lastBin = bins[bins.length - 1];
829
+ return {
830
+ delta: 'last',
831
+ pct: lastBin ? getPctChange(y, lastBin.y) : null
832
+ };
833
+ }
834
+ function getPctChange(y, y0) {
835
+ if (Number.isFinite(y) && Number.isFinite(y0) && y0 !== 0) {
836
+ return (y - y0) / y0;
837
+ }
838
+ return null;
839
+ }
840
+ var PLOT_GROUP_OTHERS_NAME = exports.PLOT_GROUP_OTHERS_NAME = 'Others';
841
+ var PLOT_NUM_GROUPS_ALL = exports.PLOT_NUM_GROUPS_ALL = 'ALL';
842
+ var DEFAULT_PLOT_NUM_GROUPS = exports.DEFAULT_PLOT_NUM_GROUPS = 10;
843
+ /** Qualitative palettes stop at 20. All uses this cap instead of one series per value. */
844
+ var MAX_PLOT_NUM_GROUPS = exports.MAX_PLOT_NUM_GROUPS = 20;
845
+ var PLOT_NUM_GROUPS_OPTIONS = exports.PLOT_NUM_GROUPS_OPTIONS = [1, 3, 5, 7, 10, MAX_PLOT_NUM_GROUPS];
846
+ var DEFAULT_PLOT_GROUP_PALETTE = 'Uber Viz Qualitative';
847
+ var FALLBACK_SERIES_COLORS = ['#12939A', '#DDB27C', '#88572C', '#FF991F', '#F15C17', '#223F9A'];
848
+ function plotGroupColorSteps(numGroups) {
849
+ if (numGroups === PLOT_NUM_GROUPS_ALL || typeof numGroups !== 'number' || numGroups < 1) {
850
+ return MAX_PLOT_NUM_GROUPS;
851
+ }
852
+ return Math.max(2, Math.min(numGroups, MAX_PLOT_NUM_GROUPS));
853
+ }
854
+ function defaultPlotGroupColorRange(numGroups) {
855
+ var steps = plotGroupColorSteps(numGroups);
856
+ var palette = _constants.KEPLER_COLOR_PALETTES.find(function (item) {
857
+ return item.name === DEFAULT_PLOT_GROUP_PALETTE;
858
+ });
859
+ if (!palette) {
860
+ return {
861
+ name: DEFAULT_PLOT_GROUP_PALETTE,
862
+ type: 'qualitative',
863
+ category: 'Uber',
864
+ colors: FALLBACK_SERIES_COLORS
865
+ };
866
+ }
867
+ return (0, _constants.colorPaletteToColorRange)(palette, {
868
+ reversed: false,
869
+ steps: steps
870
+ });
871
+ }
872
+ function defaultPlotGroupColorUI(numGroups, colorRange) {
873
+ return _objectSpread(_objectSpread({}, _constants.DEFAULT_COLOR_UI), {}, {
874
+ colorRangeConfig: _objectSpread(_objectSpread({}, _constants.DEFAULT_COLOR_UI.colorRangeConfig), {}, {
875
+ type: 'qualitative',
876
+ steps: plotGroupColorSteps(numGroups)
877
+ }),
878
+ customPalette: _objectSpread(_objectSpread({}, _constants.DEFAULT_CUSTOM_PALETTE), {}, {
879
+ colors: colorRange.colors || []
880
+ })
881
+ });
882
+ }
883
+ function mergeGroupColorUI(prev, next, numGroups, colorRange) {
884
+ var base = prev !== null && prev !== void 0 ? prev : defaultPlotGroupColorUI(numGroups, colorRange);
885
+ if (!next) {
886
+ return base;
887
+ }
888
+ return _objectSpread(_objectSpread(_objectSpread({}, base), next), {}, {
889
+ colorRangeConfig: _objectSpread(_objectSpread({}, base.colorRangeConfig), next.colorRangeConfig || {}),
890
+ customPalette: next.customPalette ? _objectSpread(_objectSpread({}, base.customPalette), next.customPalette) : base.customPalette
891
+ });
892
+ }
893
+
894
+ /**
895
+ * Merge a partial timeline group-by onto the previous one.
896
+ * `null` clears grouping. Missing fields keep the previous value, then defaults.
897
+ */
898
+ function mergePlotGroupBy(prev, next) {
899
+ var _ref2, _source$numGroups, _ref3, _source$colorRange;
900
+ if (next === null) {
901
+ return null;
902
+ }
903
+ if (!next && !prev) {
904
+ return null;
905
+ }
906
+ var source = next || {};
907
+ var numGroups = (_ref2 = (_source$numGroups = source.numGroups) !== null && _source$numGroups !== void 0 ? _source$numGroups : prev === null || prev === void 0 ? void 0 : prev.numGroups) !== null && _ref2 !== void 0 ? _ref2 : DEFAULT_PLOT_NUM_GROUPS;
908
+ var colorRange = (_ref3 = (_source$colorRange = source.colorRange) !== null && _source$colorRange !== void 0 ? _source$colorRange : prev === null || prev === void 0 ? void 0 : prev.colorRange) !== null && _ref3 !== void 0 ? _ref3 : defaultPlotGroupColorRange(numGroups);
909
+ return {
910
+ fieldName: source.fieldName !== undefined ? source.fieldName : prev === null || prev === void 0 ? void 0 : prev.fieldName,
911
+ numGroups: numGroups,
912
+ groupOthers: Boolean(source.groupOthers !== undefined ? source.groupOthers : prev === null || prev === void 0 ? void 0 : prev.groupOthers),
913
+ colorRange: colorRange,
914
+ colorUI: mergeGroupColorUI(prev === null || prev === void 0 ? void 0 : prev.colorUI, source.colorUI, numGroups, colorRange)
915
+ };
916
+ }
917
+ function groupByCacheValue(plotType) {
918
+ var _groupBy$numGroups, _groupBy$colorRange$c, _groupBy$colorRange, _groupBy$colorRange$c2, _groupBy$colorRange2;
919
+ var groupBy = plotType === null || plotType === void 0 ? void 0 : plotType.groupBy;
920
+ if (!(groupBy !== null && groupBy !== void 0 && groupBy.fieldName)) {
921
+ return null;
922
+ }
923
+ return {
924
+ fieldName: groupBy.fieldName,
925
+ numGroups: (_groupBy$numGroups = groupBy.numGroups) !== null && _groupBy$numGroups !== void 0 ? _groupBy$numGroups : DEFAULT_PLOT_NUM_GROUPS,
926
+ groupOthers: Boolean(groupBy.groupOthers),
927
+ colors: (_groupBy$colorRange$c = (_groupBy$colorRange = groupBy.colorRange) === null || _groupBy$colorRange === void 0 ? void 0 : _groupBy$colorRange.colors) !== null && _groupBy$colorRange$c !== void 0 ? _groupBy$colorRange$c : null,
928
+ colorMap: (_groupBy$colorRange$c2 = (_groupBy$colorRange2 = groupBy.colorRange) === null || _groupBy$colorRange2 === void 0 ? void 0 : _groupBy$colorRange2.colorMap) !== null && _groupBy$colorRange$c2 !== void 0 ? _groupBy$colorRange$c2 : null
929
+ };
930
+ }
931
+ function toGroupKey(value) {
932
+ if (value === null || value === undefined || value === '') {
933
+ return null;
934
+ }
935
+ return String(value);
936
+ }
937
+ function mappedSeriesColor(colorRange, key) {
938
+ var colorMap = colorRange === null || colorRange === void 0 ? void 0 : colorRange.colorMap;
939
+ if (!Array.isArray(colorMap)) {
940
+ return null;
941
+ }
942
+ var _iterator3 = _createForOfIteratorHelper(colorMap),
943
+ _step3;
944
+ try {
945
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
946
+ var entry = _step3.value;
947
+ var domain = entry === null || entry === void 0 ? void 0 : entry[0];
948
+ var color = entry === null || entry === void 0 ? void 0 : entry[1];
949
+ if (!color) {
950
+ continue;
951
+ }
952
+ if (Array.isArray(domain)) {
953
+ if (domain.map(function (item) {
954
+ return String(item);
955
+ }).includes(key)) {
956
+ return color;
957
+ }
958
+ } else if (domain !== null && domain !== undefined && String(domain) === key) {
959
+ return color;
960
+ }
961
+ }
962
+ } catch (err) {
963
+ _iterator3.e(err);
964
+ } finally {
965
+ _iterator3.f();
966
+ }
967
+ return null;
968
+ }
969
+ function seriesColor(colorRange, key, index) {
970
+ var mapped = mappedSeriesColor(colorRange, key);
971
+ if (mapped) {
972
+ return mapped;
973
+ }
974
+ var colors = colorRange === null || colorRange === void 0 ? void 0 : colorRange.colors;
975
+ if (colors !== null && colors !== void 0 && colors.length) {
976
+ return colors[index % colors.length];
977
+ }
978
+ return FALLBACK_SERIES_COLORS[index % FALLBACK_SERIES_COLORS.length];
979
+ }
980
+ var OTHERS_SERIES_COLOR = '#A0A7B4';
981
+ function defaultQualitativeColors() {
982
+ var palette = _constants.KEPLER_COLOR_PALETTES.find(function (item) {
983
+ return item.name === DEFAULT_PLOT_GROUP_PALETTE;
984
+ });
985
+ if ((palette === null || palette === void 0 ? void 0 : palette.type) === 'qualitative') {
986
+ return palette.colors(palette.maxStep);
987
+ }
988
+ return FALLBACK_SERIES_COLORS;
989
+ }
990
+
991
+ /** Others must not wrap onto a color already used by a kept group. */
992
+ function othersSeriesColor(colorRange, used) {
993
+ var _colorRange$colors, _candidates$find;
994
+ var mapped = mappedSeriesColor(colorRange, PLOT_GROUP_OTHERS_NAME);
995
+ if (mapped) {
996
+ return mapped;
997
+ }
998
+ var usedSet = new Set(used.map(function (color) {
999
+ return color.toLowerCase();
1000
+ }));
1001
+ var candidates = [].concat((0, _toConsumableArray2["default"])((_colorRange$colors = colorRange === null || colorRange === void 0 ? void 0 : colorRange.colors) !== null && _colorRange$colors !== void 0 ? _colorRange$colors : []), (0, _toConsumableArray2["default"])(defaultQualitativeColors()), FALLBACK_SERIES_COLORS, [OTHERS_SERIES_COLOR]);
1002
+ return (_candidates$find = candidates.find(function (color) {
1003
+ return !usedSet.has(color.toLowerCase());
1004
+ })) !== null && _candidates$find !== void 0 ? _candidates$find : OTHERS_SERIES_COLOR;
1005
+ }
1006
+ function groupValueAccessor(dataset, fieldName) {
1007
+ var _dataset$fields;
1008
+ var field = dataset === null || dataset === void 0 || (_dataset$fields = dataset.fields) === null || _dataset$fields === void 0 ? void 0 : _dataset$fields.find(function (item) {
1009
+ return item.name === fieldName;
1010
+ });
1011
+ if (!(field !== null && field !== void 0 && field.valueAccessor)) {
1012
+ return null;
1013
+ }
1014
+ return function (index) {
1015
+ return field.valueAccessor({
1016
+ index: index
1017
+ });
1018
+ };
1019
+ }
1020
+ function groupLimit(numGroups) {
1021
+ if (numGroups === PLOT_NUM_GROUPS_ALL) {
1022
+ return MAX_PLOT_NUM_GROUPS;
1023
+ }
1024
+ if (typeof numGroups !== 'number' || !(numGroups > 0)) {
1025
+ return DEFAULT_PLOT_NUM_GROUPS;
1026
+ }
1027
+ return Math.min(numGroups, MAX_PLOT_NUM_GROUPS);
1028
+ }
1029
+
1030
+ /**
1031
+ * Split time bins into one line per group-by value.
1032
+ * Groups keep first-seen order, then the list is capped at numGroups.
1033
+ * Remaining values fold into an Others series when groupOthers is set.
1034
+ */
1035
+ function buildGroupedLineSeries(_ref4) {
1036
+ var _plotType$groupBy;
1037
+ var bins = _ref4.bins,
1038
+ dataset = _ref4.dataset,
1039
+ plotType = _ref4.plotType,
1040
+ getYValue = _ref4.getYValue,
1041
+ interval = _ref4.interval;
1042
+ var cache = groupByCacheValue(plotType);
1043
+ if (!cache) {
1044
+ return null;
1045
+ }
1046
+ var getGroup = groupValueAccessor(dataset, cache.fieldName);
1047
+ if (!getGroup) {
1048
+ return null;
1049
+ }
1050
+ var order = [];
1051
+ var seen = new Set();
1052
+ var _iterator4 = _createForOfIteratorHelper(bins),
1053
+ _step4;
1054
+ try {
1055
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
1056
+ var bin = _step4.value;
1057
+ var _iterator6 = _createForOfIteratorHelper(bin.indexes || []),
1058
+ _step6;
1059
+ try {
1060
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1061
+ var idx = _step6.value;
1062
+ var key = toGroupKey(getGroup(idx));
1063
+ if (key === null || seen.has(key)) {
1064
+ continue;
1065
+ }
1066
+ seen.add(key);
1067
+ order.push(key);
1068
+ }
1069
+ } catch (err) {
1070
+ _iterator6.e(err);
1071
+ } finally {
1072
+ _iterator6.f();
1073
+ }
1074
+ }
1075
+ } catch (err) {
1076
+ _iterator4.e(err);
1077
+ } finally {
1078
+ _iterator4.f();
1079
+ }
1080
+ if (!order.length) {
1081
+ return null;
1082
+ }
1083
+ var limit = groupLimit(cache.numGroups);
1084
+ var keep = order.slice(0, limit);
1085
+ var rest = order.slice(keep.length);
1086
+ var includeOthers = Boolean(cache.groupOthers) && rest.length > 0;
1087
+ var colorRange = plotType === null || plotType === void 0 || (_plotType$groupBy = plotType.groupBy) === null || _plotType$groupBy === void 0 ? void 0 : _plotType$groupBy.colorRange;
1088
+ var groups = keep.map(function (key, index) {
1089
+ return {
1090
+ name: key,
1091
+ keys: new Set([key]),
1092
+ color: seriesColor(colorRange, key, index)
1093
+ };
1094
+ });
1095
+ if (includeOthers) {
1096
+ groups.push({
1097
+ name: PLOT_GROUP_OTHERS_NAME,
1098
+ keys: new Set(rest),
1099
+ color: othersSeriesColor(colorRange, groups.map(function (group) {
1100
+ return group.color;
1101
+ }))
1102
+ });
1103
+ }
1104
+ var keyToGroup = new Map();
1105
+ groups.forEach(function (group, index) {
1106
+ group.keys.forEach(function (key) {
1107
+ return keyToGroup.set(key, index);
1108
+ });
1109
+ });
1110
+ var lines = [];
1111
+ var colors = [];
1112
+ var names = [];
1113
+ var points = [];
1114
+ groups.forEach(function (group, groupIndex) {
1115
+ var seriesPoints = [];
1116
+ bins.forEach(function (bin) {
1117
+ var indexes = [];
1118
+ var _iterator5 = _createForOfIteratorHelper(bin.indexes || []),
1119
+ _step5;
1120
+ try {
1121
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
1122
+ var idx = _step5.value;
1123
+ var key = toGroupKey(getGroup(idx));
1124
+ if (key !== null && keyToGroup.get(key) === groupIndex) {
1125
+ indexes.push(idx);
1126
+ }
1127
+ }
1128
+ } catch (err) {
1129
+ _iterator5.e(err);
1130
+ } finally {
1131
+ _iterator5.f();
1132
+ }
1133
+ var y = indexes.length ? getYValue(_objectSpread(_objectSpread({}, bin), {}, {
1134
+ indexes: indexes,
1135
+ count: indexes.length
1136
+ })) : undefined;
1137
+ var delta = getDelta(seriesPoints, y, interval);
1138
+ var point = _objectSpread({
1139
+ x: bin.x0,
1140
+ y: y
1141
+ }, delta);
1142
+ seriesPoints.push(point);
1143
+ points.push(point);
1144
+ });
1145
+ var split = splitSeries(seriesPoints);
1146
+ split.lines.forEach(function (line) {
1147
+ lines.push(line);
1148
+ colors.push(group.color);
1149
+ names.push(group.name);
1150
+ });
1151
+ });
1152
+ return {
1153
+ series: {
1154
+ lines: lines,
1155
+ markers: [],
1156
+ colors: colors,
1157
+ names: names
1158
+ },
1159
+ points: points
1160
+ };
1161
+ }
1162
+ function lineChartSeriesLegend(lineChart) {
1163
+ var series = lineChart === null || lineChart === void 0 ? void 0 : lineChart.series;
1164
+ if (!series || Array.isArray(series) || !series.names || !series.colors) {
1165
+ return [];
1166
+ }
1167
+ var seen = new Map();
1168
+ series.names.forEach(function (name, index) {
1169
+ if (name && !seen.has(name)) {
1170
+ var _series$colors;
1171
+ seen.set(name, ((_series$colors = series.colors) === null || _series$colors === void 0 ? void 0 : _series$colors[index]) || FALLBACK_SERIES_COLORS[0]);
1172
+ }
1173
+ });
1174
+ return Array.from(seen, function (_ref5) {
1175
+ var _ref6 = (0, _slicedToArray2["default"])(_ref5, 2),
1176
+ name = _ref6[0],
1177
+ color = _ref6[1];
1178
+ return {
1179
+ name: name,
1180
+ color: color
1181
+ };
1182
+ });
1183
+ }
1184
+
1185
+ /**
1186
+ *
1187
+ * @param datasets
1188
+ * @param filter
1189
+ */
1190
+ function getLineChart(datasets, filter) {
1191
+ var _plotType$numericInte, _bins, _timeBins, _lineChart$groupBy;
1192
+ var dataId = filter.dataId,
1193
+ yAxis = filter.yAxis,
1194
+ plotType = filter.plotType,
1195
+ lineChart = filter.lineChart;
1196
+ var interval = plotType.interval;
1197
+ var aggregation = plotType.aggregation || _constants.AGGREGATION_TYPES.average;
1198
+ var seriesDataId = dataId[0];
1199
+ var isNumericFilter = filter.type === _constants.FILTER_TYPES.range;
1200
+ var binning = isNumericFilter ? (_plotType$numericInte = plotType.numericInterval) !== null && _plotType$numericInte !== void 0 ? _plotType$numericInte : null : interval;
1201
+ var bins = isNumericFilter ? (_bins = filter.bins) === null || _bins === void 0 ? void 0 : _bins[seriesDataId] : (_timeBins = filter.timeBins) === null || _timeBins === void 0 || (_timeBins = _timeBins[seriesDataId]) === null || _timeBins === void 0 ? void 0 : _timeBins[interval];
1202
+ var groupBy = groupByCacheValue(plotType);
1203
+ if (lineChart && lineChart.aggregation === aggregation && lineChart.interval === binning && lineChart.yAxis === (yAxis === null || yAxis === void 0 ? void 0 : yAxis.name) && (0, _isEqual["default"])((_lineChart$groupBy = lineChart.groupBy) !== null && _lineChart$groupBy !== void 0 ? _lineChart$groupBy : null, groupBy) &&
1204
+ // we need to make sure we validate bins because of cross filter data changes
1205
+ (0, _isEqual["default"])(bins, lineChart === null || lineChart === void 0 ? void 0 : lineChart.bins)) {
1206
+ // don't update lineChart if plotType hasn't change
1207
+ return lineChart;
1208
+ }
1209
+ var dataset = datasets[seriesDataId];
1210
+ var getYValue = getValueAggrFunc(yAxis, aggregation, dataset);
1211
+ var grouped = groupBy && bins !== null && bins !== void 0 && bins.length ? buildGroupedLineSeries({
1212
+ bins: bins,
1213
+ dataset: dataset,
1214
+ plotType: plotType,
1215
+ getYValue: getYValue,
1216
+ interval: binning
1217
+ }) : null;
1218
+ var init = [];
1219
+ var series = grouped ? grouped.points : (bins || []).reduce(function (accu, bin) {
1220
+ var y = getYValue(bin);
1221
+ var delta = getDelta(accu, y, binning);
1222
+ accu.push(_objectSpread({
1223
+ x: bin.x0,
1224
+ y: y
1225
+ }, delta));
1226
+ return accu;
1227
+ }, init);
1228
+ var yDomain = (0, _d3Array.extent)(series, function (d) {
1229
+ return d.y;
1230
+ });
1231
+ var xDomain = bins !== null && bins !== void 0 && bins.length ? [bins[0].x0, bins[bins.length - 1].x1] : [];
1232
+
1233
+ // treat missing data as another series
1234
+ var split = grouped ? grouped.series : splitSeries(series);
1235
+ var aggrName = _aggregation.AGGREGATION_NAME[aggregation];
1236
+ return _objectSpread({
1237
+ // @ts-ignore
1238
+ yDomain: yDomain,
1239
+ // @ts-ignore
1240
+ xDomain: xDomain,
1241
+ interval: binning,
1242
+ aggregation: aggregation,
1243
+ // @ts-ignore
1244
+ series: split,
1245
+ title: "".concat(aggrName, ' of ').concat(yAxis ? yAxis.name : 'Count'),
1246
+ fieldType: yAxis ? yAxis.type : 'integer',
1247
+ yAxis: yAxis ? yAxis.name : null,
1248
+ allTime: {
1249
+ title: isNumericFilter ? "All Range Average" : "All Time Average",
1250
+ value: (0, _aggregation.aggregate)(series, _constants.AGGREGATION_TYPES.average, function (d) {
1251
+ return d.y;
1252
+ })
1253
+ },
1254
+ bins: bins
1255
+ }, groupBy ? {
1256
+ groupBy: groupBy
1257
+ } : {});
1258
+ }
1259
+
1260
+ // split into multiple series when see missing data
1261
+ function splitSeries(series) {
1262
+ var lines = [];
1263
+ var temp = [];
1264
+ for (var i = 0; i < series.length; i++) {
1265
+ var d = series[i];
1266
+ if (!(0, _commonUtils.notNullorUndefined)(d.y) && temp.length) {
1267
+ // ends temp
1268
+ lines.push(temp);
1269
+ temp = [];
1270
+ } else if ((0, _commonUtils.notNullorUndefined)(d.y)) {
1271
+ temp.push(d);
1272
+ }
1273
+ if (i === series.length - 1 && temp.length) {
1274
+ lines.push(temp);
1275
+ }
1276
+ }
1277
+ var markers = lines.length > 1 ? series.filter(function (d) {
1278
+ return (0, _commonUtils.notNullorUndefined)(d.y);
1279
+ }) : [];
1280
+ return {
1281
+ lines: lines,
1282
+ markers: markers
1283
+ };
1284
+ }
1285
+ function adjustValueToAnimationWindow(state, filter, plotBaseIndexByDataId) {
1286
+ var plotType = filter.plotType,
1287
+ _filter$value = (0, _slicedToArray2["default"])(filter.value, 2),
1288
+ value0 = _filter$value[0],
1289
+ value1 = _filter$value[1],
1290
+ animationWindow = filter.animationWindow;
1291
+ var isTimeFilter = filter.type === _constants.FILTER_TYPES.timeRange;
1292
+ var timePlotType = isTimeFilter ? normalizeTimePlotType(_objectSpread(_objectSpread({}, plotType), {}, {
1293
+ interval: plotType.interval || (0, _time.getInitialInterval)(filter, state.datasets)
1294
+ }), filter.domain) : plotType;
1295
+ var interval = isTimeFilter ? timePlotType.interval : undefined;
1296
+ var bins = isTimeFilter ? getTimeBins(filter, state.datasets, interval, plotBaseIndexByDataId) : getRangeFilterBins(filter, state.datasets, _constants.BINS, plotBaseIndexByDataId);
1297
+ var firstBins = bins && Object.keys(bins).length ? Object.values(bins)[0] : null;
1298
+ var datasetBins = isTimeFilter ? firstBins === null || firstBins === void 0 ? void 0 : firstBins[interval] : firstBins;
1299
+ var thresholds = (datasetBins || []).map(function (b) {
1300
+ return b.x0;
1301
+ });
1302
+ var numericIntervalMarks = datasetBins !== null && datasetBins !== void 0 && datasetBins.length ? [].concat((0, _toConsumableArray2["default"])(thresholds), [datasetBins[datasetBins.length - 1].x1]) : thresholds;
1303
+ var val0 = value0;
1304
+ var val1 = value1;
1305
+ var idx;
1306
+ if (animationWindow === _constants.ANIMATION_WINDOW.interval) {
1307
+ val0 = snapToMarks(value1, thresholds);
1308
+ idx = thresholds.indexOf(val0);
1309
+ if (isTimeFilter) {
1310
+ var _datasetBins$idx;
1311
+ // Time histograms discard empty bins. Use the selected cached bin's
1312
+ // actual end instead of the next non-empty bin's start so sparse
1313
+ // calendar intervals do not absorb the empty gap between them.
1314
+ var binEnd = idx > -1 ? datasetBins === null || datasetBins === void 0 || (_datasetBins$idx = datasetBins[idx]) === null || _datasetBins$idx === void 0 ? void 0 : _datasetBins$idx.x1 : NaN;
1315
+ val1 = Number.isFinite(binEnd) && binEnd > val0 ? Math.max(val0, binEnd - Math.min(1, binEnd - val0)) : binEnd;
1316
+ } else {
1317
+ var _intervalBinFromMarks = intervalBinFromMarks(numericIntervalMarks, val0, 0);
1318
+ var _intervalBinFromMarks2 = (0, _slicedToArray2["default"])(_intervalBinFromMarks, 2);
1319
+ val1 = _intervalBinFromMarks2[1];
1320
+ }
1321
+ } else {
1322
+ // fit current value to window
1323
+ val0 = snapToMarks(value0, thresholds);
1324
+ val1 = snapToMarks(value1, thresholds);
1325
+ if (val0 === val1) {
1326
+ idx = thresholds.indexOf(val0);
1327
+ if (idx === thresholds.length - 1) {
1328
+ val0 = thresholds[idx - 1];
1329
+ } else {
1330
+ val1 = thresholds[idx + 1];
1331
+ }
1332
+ }
1333
+ }
1334
+ return _objectSpread(_objectSpread(_objectSpread({}, filter), isTimeFilter ? {
1335
+ plotType: timePlotType,
1336
+ timeBins: bins
1337
+ } : {
1338
+ bins: bins
1339
+ }), {}, {
1340
+ value: [val0, val1]
1341
+ });
1342
+ }
1343
+
1344
+ /**
1345
+ * Create or update colors for a filter plot
1346
+ * @param filter
1347
+ * @param datasets
1348
+ * @param oldColorsByDataId
1349
+ */
1350
+ function getFilterPlotColorsByDataId(filter, datasets, oldColorsByDataId) {
1351
+ var colorsByDataId = oldColorsByDataId || {};
1352
+ var _iterator7 = _createForOfIteratorHelper(filter.dataId),
1353
+ _step7;
1354
+ try {
1355
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1356
+ var dataId = _step7.value;
1357
+ if (!colorsByDataId[dataId] && datasets[dataId]) {
1358
+ colorsByDataId = _objectSpread(_objectSpread({}, colorsByDataId), {}, (0, _defineProperty2["default"])({}, dataId, (0, _colorUtils.rgbToHex)(datasets[dataId].color)));
1359
+ }
1360
+ }
1361
+ } catch (err) {
1362
+ _iterator7.e(err);
1363
+ } finally {
1364
+ _iterator7.f();
1365
+ }
1366
+ return colorsByDataId;
1367
+ }
1368
+
1369
+ /**
1370
+ *
1371
+ * @param filter
1372
+ * @param plotType
1373
+ * @param datasets
1374
+ * @param dataId
1375
+ */
1376
+ function updateTimeFilterPlotType(filter, plotType, datasets, _dataId, plotBaseIndexByDataId) {
1377
+ var nextFilter = filter;
1378
+ var nextPlotType = plotType;
1379
+ if ((0, _typeof2["default"])(nextPlotType) !== 'object' || !nextPlotType.aggregation || !nextPlotType.interval) {
1380
+ nextPlotType = getDefaultPlotType(filter, datasets);
1381
+ }
1382
+ var normalizedPlotType = normalizeTimePlotType(nextPlotType, filter.domain);
1383
+ if (normalizedPlotType.interval !== nextPlotType.interval) {
1384
+ nextFilter = _objectSpread(_objectSpread({}, filter), {}, {
1385
+ timeBins: undefined,
1386
+ lineChart: undefined
1387
+ });
1388
+ }
1389
+ nextPlotType = normalizedPlotType;
1390
+ if (filter.dataId.length > 1) {
1391
+ nextPlotType = _objectSpread(_objectSpread({}, nextPlotType), {}, {
1392
+ colorsByDataId: getFilterPlotColorsByDataId(filter, datasets, nextPlotType.colorsByDataId)
1393
+ });
1394
+ }
1395
+ nextFilter = _objectSpread(_objectSpread({}, nextFilter), {}, {
1396
+ plotType: nextPlotType
1397
+ });
1398
+ var bins = getTimeBins(nextFilter, datasets, nextPlotType.interval, plotBaseIndexByDataId);
1399
+ nextFilter = _objectSpread(_objectSpread({}, nextFilter), {}, {
1400
+ timeBins: bins
1401
+ });
1402
+ if (plotType.type === _constants.PLOT_TYPES.histogram) {
1403
+ // Histogram is calculated and memoized in the chart itself
1404
+ } else if (plotType.type === _constants.PLOT_TYPES.lineChart) {
1405
+ // we should be able to move this into its own component so react will do the shallow comparison for us.
1406
+ nextFilter = _objectSpread(_objectSpread({}, nextFilter), {}, {
1407
+ lineChart: getLineChart(datasets, nextFilter)
1408
+ });
1409
+ }
1410
+ return nextFilter;
1411
+ }
1412
+ function getRangeFilterBins(filter, datasets, numBins, plotBaseIndexByDataId) {
1413
+ var domain = filter.domain;
1414
+ if (!filter.dataId) return null;
1415
+ return filter.dataId.reduce(function (acc, dataId, datasetIdx) {
1416
+ var _filter$bins;
1417
+ if ((_filter$bins = filter.bins) !== null && _filter$bins !== void 0 && _filter$bins[dataId]) {
1418
+ // don't recalculate bins
1419
+ acc[dataId] = filter.bins[dataId];
1420
+ return acc;
1421
+ }
1422
+ var fieldName = filter.name[datasetIdx];
1423
+ if (dataId && fieldName) {
1424
+ var dataset = datasets[dataId];
1425
+ var field = dataset === null || dataset === void 0 ? void 0 : dataset.getColumnField(fieldName);
1426
+ if (dataset && field) {
1427
+ var _filter$plotType4;
1428
+ var indexes = runGpuFilterForPlot(dataset, filter, undefined, plotBaseIndexByDataId === null || plotBaseIndexByDataId === void 0 ? void 0 : plotBaseIndexByDataId[dataId]);
1429
+ var valueAccessor = function valueAccessor(index) {
1430
+ return field.valueAccessor({
1431
+ index: index
1432
+ });
1433
+ };
1434
+ var numericInterval = (_filter$plotType4 = filter.plotType) === null || _filter$plotType4 === void 0 ? void 0 : _filter$plotType4.numericInterval;
1435
+ acc[dataId] = Number.isFinite(numericInterval) && numericInterval > 0 ? histogramFromThreshold(getNumericBinThresholds(domain, numericInterval, numBins), indexes, valueAccessor, false) : histogramFromDomain(domain, indexes, numBins, valueAccessor);
1436
+ }
1437
+ }
1438
+ return acc;
1439
+ }, {});
1440
+ }
1441
+ function updateRangeFilterPlotType(filter, plotType, datasets, _dataId, plotBaseIndexByDataId) {
1442
+ // if (dataId) {
1443
+ // // clear bins
1444
+ // nextFilter = {
1445
+ // ...nextFilter,
1446
+ // bins: {
1447
+ // ...nextFilter.bins,
1448
+ // [dataId]: null
1449
+ // }
1450
+ // };
1451
+ // }
1452
+
1453
+ var configuredNumericInterval = plotType === null || plotType === void 0 ? void 0 : plotType.numericInterval;
1454
+ var numericInterval = normalizeNumericInterval(filter.domain, configuredNumericInterval);
1455
+ var shouldUseAutomaticBins = configuredNumericInterval !== undefined && numericInterval === undefined;
1456
+ var nextPlotType = plotType;
1457
+ if (shouldUseAutomaticBins) {
1458
+ var _ref7 = nextPlotType || {},
1459
+ _numericInterval = _ref7.numericInterval,
1460
+ automaticPlotType = (0, _objectWithoutProperties2["default"])(_ref7, _excluded);
1461
+ nextPlotType = automaticPlotType;
1462
+ }
1463
+ if (filter.dataId.length > 1) {
1464
+ nextPlotType = _objectSpread(_objectSpread({}, nextPlotType), {}, {
1465
+ colorsByDataId: getFilterPlotColorsByDataId(filter, datasets, nextPlotType.colorsByDataId)
1466
+ });
1467
+ }
1468
+ var nextFilter = _objectSpread(_objectSpread(_objectSpread({}, filter), shouldUseAutomaticBins ? {
1469
+ bins: undefined,
1470
+ lineChart: undefined
1471
+ } : {}), {}, {
1472
+ plotType: nextPlotType
1473
+ });
1474
+ var updatedFilter = _objectSpread(_objectSpread({}, nextFilter), {}, {
1475
+ bins: getRangeFilterBins(nextFilter, datasets, _constants.BINS, plotBaseIndexByDataId)
1476
+ });
1477
+ if (nextPlotType.type === _constants.PLOT_TYPES.lineChart) {
1478
+ updatedFilter = _objectSpread(_objectSpread({}, updatedFilter), {}, {
1479
+ lineChart: getLineChart(datasets, updatedFilter)
1480
+ });
1481
+ }
1482
+ return updatedFilter;
1483
+ }
1484
+ function getChartTitle(yAxis, plotType) {
1485
+ var yAxisName = yAxis === null || yAxis === void 0 ? void 0 : yAxis.displayName;
1486
+ var aggregation = plotType.aggregation;
1487
+ if (yAxisName) {
1488
+ return (0, _strings.capitalizeFirstLetter)("".concat(aggregation, " ").concat(yAxisName, " over Time"));
1489
+ }
1490
+ return "Count of Rows over Time";
1491
+ }
1492
+ function getDefaultPlotType(filter, datasets) {
1493
+ var interval = (0, _time.getInitialInterval)(filter, datasets);
1494
+ var defaultTimeFormat = (0, _format.getDefaultTimeFormat)(interval);
1495
+ return {
1496
+ interval: interval,
1497
+ defaultTimeFormat: defaultTimeFormat,
1498
+ type: _constants.PLOT_TYPES.histogram,
1499
+ aggregation: _constants.AGGREGATION_TYPES.average
1500
+ };
1501
+ }
1502
+ //# sourceMappingURL=plot.js.map