billboard.js 3.17.4 → 3.18.0-next.2

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 (137) hide show
  1. package/CONTRIBUTING.md +12 -12
  2. package/README.md +12 -12
  3. package/dist/billboard.css +15 -1
  4. package/dist/billboard.js +1146 -463
  5. package/dist/billboard.min.css +2 -2
  6. package/dist/billboard.min.js +10 -10
  7. package/dist/billboard.pkgd.js +1147 -464
  8. package/dist/billboard.pkgd.min.js +21 -21
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-sparkline.js +117 -26
  12. package/dist/plugin/billboardjs-plugin-sparkline.min.js +4 -4
  13. package/dist/plugin/billboardjs-plugin-stanford.js +119 -28
  14. package/dist/plugin/billboardjs-plugin-stanford.min.js +10 -10
  15. package/dist/plugin/billboardjs-plugin-tableview.js +117 -27
  16. package/dist/plugin/billboardjs-plugin-tableview.min.js +5 -5
  17. package/dist/plugin/billboardjs-plugin-textoverlap.js +116 -26
  18. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +3 -3
  19. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.js +2 -2
  20. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.pkgd.min.js +2 -2
  21. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.js +117 -26
  22. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.pkgd.min.js +10 -10
  23. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.js +120 -29
  24. package/dist/plugin/pkgd/billboardjs-plugin-stanford.pkgd.min.js +14 -14
  25. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.js +117 -27
  26. package/dist/plugin/pkgd/billboardjs-plugin-tableview.pkgd.min.js +12 -12
  27. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.js +116 -26
  28. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.pkgd.min.js +10 -10
  29. package/dist/theme/dark.css +15 -1
  30. package/dist/theme/dark.min.css +2 -2
  31. package/dist/theme/datalab.css +15 -1
  32. package/dist/theme/datalab.min.css +2 -2
  33. package/dist/theme/graph.css +15 -1
  34. package/dist/theme/graph.min.css +2 -2
  35. package/dist/theme/insight.css +15 -1
  36. package/dist/theme/insight.min.css +2 -2
  37. package/dist/theme/modern.css +15 -1
  38. package/dist/theme/modern.min.css +2 -2
  39. package/dist-esm/billboard.js +1467 -536
  40. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  41. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +3 -2
  42. package/dist-esm/plugin/billboardjs-plugin-stanford.js +5 -4
  43. package/dist-esm/plugin/billboardjs-plugin-tableview.js +94 -16
  44. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +2 -2
  45. package/package.json +38 -37
  46. package/src/Chart/Chart.ts +1 -1
  47. package/src/Chart/api/chart.ts +5 -5
  48. package/src/Chart/api/data.ts +2 -1
  49. package/src/Chart/api/export.ts +1 -1
  50. package/src/Chart/api/flow.ts +1 -1
  51. package/src/Chart/api/load.ts +3 -3
  52. package/src/Chart/api/subchart.ts +3 -3
  53. package/src/Chart/api/tooltip.ts +1 -1
  54. package/src/Chart/api/zoom.ts +1 -1
  55. package/src/ChartInternal/Axis/Axis.ts +1 -1
  56. package/src/ChartInternal/Axis/AxisRendererHelper.ts +1 -1
  57. package/src/ChartInternal/ChartInternal.ts +3 -2
  58. package/src/ChartInternal/data/IData.ts +3 -0
  59. package/src/ChartInternal/data/convert.helper.ts +1 -1
  60. package/src/ChartInternal/data/convert.ts +9 -8
  61. package/src/ChartInternal/data/data.ts +135 -17
  62. package/src/ChartInternal/data/load.ts +8 -8
  63. package/src/ChartInternal/interactions/drag.ts +53 -42
  64. package/src/ChartInternal/interactions/eventrect.ts +15 -5
  65. package/src/ChartInternal/interactions/flow.ts +1 -1
  66. package/src/ChartInternal/interactions/interaction.ts +1 -1
  67. package/src/ChartInternal/interactions/zoom.ts +24 -20
  68. package/src/ChartInternal/internals/color.ts +27 -10
  69. package/src/ChartInternal/internals/domain.ts +22 -5
  70. package/src/ChartInternal/internals/format.ts +4 -4
  71. package/src/ChartInternal/internals/grid.ts +11 -11
  72. package/src/ChartInternal/internals/legend.ts +80 -19
  73. package/src/ChartInternal/internals/scale.ts +6 -6
  74. package/src/ChartInternal/internals/selection.ts +1 -1
  75. package/src/ChartInternal/internals/style.ts +3 -3
  76. package/src/ChartInternal/internals/text.arc.ts +304 -0
  77. package/src/ChartInternal/internals/text.ts +44 -14
  78. package/src/ChartInternal/internals/text.util.ts +19 -0
  79. package/src/ChartInternal/internals/title.ts +3 -3
  80. package/src/ChartInternal/internals/tooltip.ts +23 -15
  81. package/src/ChartInternal/shape/arc.ts +174 -71
  82. package/src/ChartInternal/shape/area.ts +2 -2
  83. package/src/ChartInternal/shape/bar.ts +7 -6
  84. package/src/ChartInternal/shape/candlestick.ts +3 -3
  85. package/src/ChartInternal/shape/funnel.ts +18 -18
  86. package/src/ChartInternal/shape/line.ts +9 -10
  87. package/src/ChartInternal/shape/point.common.ts +24 -6
  88. package/src/ChartInternal/shape/radar.ts +4 -4
  89. package/src/ChartInternal/shape/shape.ts +24 -6
  90. package/src/ChartInternal/shape/treemap.ts +19 -5
  91. package/src/Plugin/stanford/Options.ts +2 -2
  92. package/src/Plugin/tableview/Options.ts +1 -1
  93. package/src/config/Options/axis/axis.ts +7 -7
  94. package/src/config/Options/axis/x.ts +6 -6
  95. package/src/config/Options/axis/y.ts +4 -4
  96. package/src/config/Options/axis/y2.ts +16 -3
  97. package/src/config/Options/common/color.ts +2 -2
  98. package/src/config/Options/common/legend.ts +6 -5
  99. package/src/config/Options/common/main.ts +23 -23
  100. package/src/config/Options/common/point.ts +4 -3
  101. package/src/config/Options/common/tooltip.ts +14 -13
  102. package/src/config/Options/data/axis.ts +31 -6
  103. package/src/config/Options/data/data.ts +44 -44
  104. package/src/config/Options/data/selection.ts +4 -4
  105. package/src/config/Options/interaction/interaction.ts +2 -1
  106. package/src/config/Options/interaction/subchart.ts +2 -2
  107. package/src/config/Options/interaction/zoom.ts +4 -4
  108. package/src/config/Options/shape/arc.ts +4 -4
  109. package/src/config/Options/shape/area.ts +1 -1
  110. package/src/config/Options/shape/bar.ts +4 -4
  111. package/src/config/Options/shape/bubble.ts +2 -2
  112. package/src/config/Options/shape/candlestick.ts +1 -1
  113. package/src/config/Options/shape/donut.ts +34 -3
  114. package/src/config/Options/shape/gauge.ts +36 -4
  115. package/src/config/Options/shape/line.ts +1 -1
  116. package/src/config/Options/shape/pie.ts +34 -3
  117. package/src/config/Options/shape/polar.ts +35 -4
  118. package/src/config/Options/shape/radar.ts +1 -1
  119. package/src/config/Options/shape/scatter.ts +1 -1
  120. package/src/config/Options/shape/treemap.ts +31 -5
  121. package/src/config/Store/State.ts +11 -1
  122. package/src/config/classes.ts +1 -0
  123. package/src/core.ts +1 -1
  124. package/src/module/Cache.ts +29 -4
  125. package/src/module/generator.ts +1 -1
  126. package/src/module/util.ts +308 -117
  127. package/src/module/worker.ts +3 -3
  128. package/src/scss/billboard.scss +15 -0
  129. package/src/scss/theme/dark.scss +15 -0
  130. package/src/scss/theme/datalab.scss +15 -0
  131. package/src/scss/theme/graph.scss +15 -0
  132. package/src/scss/theme/insight.scss +15 -0
  133. package/src/scss/theme/modern.scss +15 -0
  134. package/types/axis.d.ts +3 -3
  135. package/types/chart.d.ts +4 -4
  136. package/types/options.d.ts +22 -9
  137. package/types/options.shape.d.ts +59 -2
@@ -9,7 +9,8 @@ import {
9
9
  isObject,
10
10
  isUndefined,
11
11
  isValue,
12
- notEmpty
12
+ notEmpty,
13
+ toSet
13
14
  } from "../../module/util";
14
15
  import {runWorker} from "../../module/worker";
15
16
  import type {IData} from "../data/IData";
@@ -22,7 +23,7 @@ import {columns, json, rows, url} from "./convert.helper";
22
23
  * @returns {string} Data key
23
24
  * @private
24
25
  */
25
- function getDataKeyForJson(keysParam, config) {
26
+ function _getDataKeyForJson(keysParam, config) {
26
27
  const keys = keysParam || config?.data_keys;
27
28
 
28
29
  if (keys?.x) {
@@ -44,7 +45,7 @@ function getDataKeyForJson(keysParam, config) {
44
45
  * @param {boolean} params.customX Whether the x is custom
45
46
  * @private
46
47
  */
47
- function setXS(
48
+ function _setXS(
48
49
  ids: string[],
49
50
  data: {[key: string]: number | null}[],
50
51
  params: {appendXs, xs, categorized: boolean, timeSeries: boolean, customX: boolean}
@@ -95,7 +96,7 @@ export default {
95
96
  /**
96
97
  * Convert data according its type
97
98
  * @param {object} args data object
98
- * @param {Function} [callback] callback for url(XHR) type loading
99
+ * @param {function} [callback] callback for url(XHR) type loading
99
100
  * @private
100
101
  */
101
102
  convertData(args, callback: Function): void {
@@ -117,12 +118,12 @@ export default {
117
118
  }
118
119
 
119
120
  if (data.url && callback) {
120
- url(data.url, data.mimeType, data.headers, getDataKeyForJson(data.keys, config),
121
+ url(data.url, data.mimeType, data.headers, _getDataKeyForJson(data.keys, config),
121
122
  callback);
122
123
  } else if (data.json) {
123
124
  runWorker(useWorker(data.json), json, callback, [columns, rows])(
124
125
  data.json,
125
- getDataKeyForJson(data.keys, config)
126
+ _getDataKeyForJson(data.keys, config)
126
127
  );
127
128
  } else if (data.rows) {
128
129
  runWorker(useWorker(data.rows), rows, callback)(data.rows);
@@ -169,7 +170,7 @@ export default {
169
170
  };
170
171
 
171
172
  // save x for update data by load when custom x and bb.x API
172
- setXS.bind($$)(ids, data, params);
173
+ _setXS.bind($$)(ids, data, params);
173
174
 
174
175
  // convert to target
175
176
  const targets = ids.map((id, index) => {
@@ -177,7 +178,7 @@ export default {
177
178
  const xKey = $$.getXKey(id);
178
179
  const isCategory = params.customX && params.categorized;
179
180
  const hasCategory = isCategory && (() => {
180
- const categorySet = new Set(config.axis_x_categories);
181
+ const categorySet = toSet(config.axis_x_categories);
181
182
  return data.every(v => categorySet.has(v.x));
182
183
  })();
183
184
 
@@ -46,7 +46,26 @@ export default {
46
46
  isStackNormalized(): boolean {
47
47
  const {config} = this;
48
48
 
49
- return !!(config.data_stack_normalize && config.data_groups.length);
49
+ return !!(
50
+ (config.data_stack_normalize === true ||
51
+ isObjectType(config.data_stack_normalize)) &&
52
+ config.data_groups.length
53
+ );
54
+ },
55
+
56
+ /**
57
+ * Check if stack normalization should be applied per group
58
+ * @returns {boolean}
59
+ * @private
60
+ */
61
+ isStackNormalizedPerGroup(): boolean {
62
+ const {config} = this;
63
+
64
+ return !!(
65
+ isObjectType(config.data_stack_normalize) &&
66
+ config.data_stack_normalize?.perGroup &&
67
+ config.data_groups.length
68
+ );
50
69
  },
51
70
 
52
71
  /**
@@ -61,6 +80,26 @@ export default {
61
80
  return id ? groups.some(v => v.indexOf(id) >= 0 && v.length > 1) : groups.length > 0;
62
81
  },
63
82
 
83
+ /**
84
+ * Check if the given axis has any grouped data
85
+ * @param {string} axisId Axis ID (e.g., "y", "y2")
86
+ * @returns {boolean} true if axis has grouped data
87
+ * @private
88
+ */
89
+ hasAxisGroupedData(axisId: "y" | "y2"): boolean {
90
+ const $$ = this;
91
+ const {axis} = $$;
92
+ const targets = $$.data.targets;
93
+
94
+ // Get all data IDs that belong to this axis
95
+ const axisDataIds = targets
96
+ .filter(t => axis.getId(t.id) === axisId)
97
+ .map(t => t.id);
98
+
99
+ // Check if any of the axis data IDs are in groups
100
+ return axisDataIds.some(id => $$.isGrouped(id));
101
+ },
102
+
64
103
  getXKey(id) {
65
104
  const $$ = this;
66
105
  const {config} = $$;
@@ -325,18 +364,37 @@ export default {
325
364
 
326
365
  /**
327
366
  * Get sum of data per index
367
+ * @param {string} targetId Target ID to get total for (only for normalized stack per group)
328
368
  * @private
329
369
  * @returns {Array}
330
370
  */
331
- getTotalPerIndex() {
371
+ getTotalPerIndex(targetId?: string) {
332
372
  const $$ = this;
333
- const cacheKey = KEY.dataTotalPerIndex;
373
+ const {config} = $$;
374
+ const cacheKey = targetId ? `${KEY.dataTotalPerIndex}-${targetId}` : KEY.dataTotalPerIndex;
334
375
  let sum = $$.cache.get(cacheKey);
335
376
 
336
377
  if (($$.config.data_groups.length || $$.isStackNormalized()) && !sum) {
337
378
  sum = [];
338
379
 
339
- $$.data.targets.forEach(row => {
380
+ // When normalize per group is enabled and targetId is provided,
381
+ // only sum data within the same group
382
+ let {targets} = $$.data;
383
+
384
+ if ($$.isStackNormalizedPerGroup() && targetId) {
385
+ // Find which group the target belongs to
386
+ const group = config.data_groups.find(g => g.indexOf(targetId) >= 0);
387
+
388
+ if (group) {
389
+ // Only sum targets in the same group
390
+ targets = targets.filter(t => group.indexOf(t.id) >= 0);
391
+ } else {
392
+ // If target is not in any group, return null to indicate no normalization
393
+ return null;
394
+ }
395
+ }
396
+
397
+ targets.forEach(row => {
340
398
  row.values.forEach((v, i) => {
341
399
  if (!sum[i]) {
342
400
  sum[i] = 0;
@@ -345,6 +403,8 @@ export default {
345
403
  sum[i] += ~~v.value;
346
404
  });
347
405
  });
406
+
407
+ $$.cache.add(cacheKey, sum);
348
408
  }
349
409
 
350
410
  return sum;
@@ -363,7 +423,7 @@ export default {
363
423
 
364
424
  if (!isNumber(total)) {
365
425
  total = $$.data.targets.reduce((acc, t) => {
366
- return acc + t.values.reduce((sum, v) => sum + ~~v.value, 0);
426
+ return acc + t.values.reduce((sum, v) => sum + (v.value ?? 0), 0);
367
427
  }, 0);
368
428
 
369
429
  $$.cache.add(cacheKey, total);
@@ -469,7 +529,33 @@ export default {
469
529
  filterTargetsToShow(targets?) {
470
530
  const $$ = this;
471
531
 
472
- return (targets || $$.data.targets).filter(t => $$.isTargetToShow(t.id));
532
+ // When called without arguments, use caching
533
+ if (!targets) {
534
+ const {cache, data, state} = $$;
535
+ const cacheKey = KEY.filteredTargets;
536
+ const visibilityChecksum = state.hiddenTargetIds.join(",");
537
+ const storedChecksum = cache.get(KEY.visibilityChecksum);
538
+
539
+ // Invalidate cache if visibility changed
540
+ if (visibilityChecksum !== storedChecksum) {
541
+ cache.remove(cacheKey);
542
+ cache.add(KEY.visibilityChecksum, visibilityChecksum);
543
+ }
544
+
545
+ // Return cached result if available
546
+ if (cache.has(cacheKey)) {
547
+ return cache.get(cacheKey);
548
+ }
549
+
550
+ // Compute and cache result (store the filtered array)
551
+ const filtered = data.targets.filter(t => $$.isTargetToShow(t.id));
552
+ cache.add(cacheKey, filtered);
553
+
554
+ return filtered;
555
+ }
556
+
557
+ // When called with custom targets, don't cache
558
+ return targets.filter(t => $$.isTargetToShow(t.id));
473
559
  },
474
560
 
475
561
  mapTargetsToUniqueXs(targets) {
@@ -489,7 +575,7 @@ export default {
489
575
  },
490
576
 
491
577
  /**
492
- * Add to the state target Ids
578
+ * Add to thetarget Ids
493
579
  * @param {string} type State's prop name
494
580
  * @param {Array|string} targetIds Target ids array
495
581
  * @private
@@ -547,6 +633,9 @@ export default {
547
633
  .map(v => (isString(v) ? v : +v)) :
548
634
  null;
549
635
 
636
+ // Create xIndexMap for O(1) lookup instead of O(n) indexOf in getIndexByX
637
+ const xIndexMap = xs ? new Map(xs.map((x, i) => [x, i])) : null;
638
+
550
639
  targets.forEach(t => {
551
640
  const data: any[] = [];
552
641
 
@@ -569,8 +658,14 @@ export default {
569
658
  } else if ($$.isBubbleZType(v)) {
570
659
  data.push(hasAxis && $$.getBubbleZData(value, "y"));
571
660
  } else {
572
- if (isMultipleX) {
573
- data[$$.getIndexByX(v.x, xs)] = value;
661
+ if (isMultipleX && xIndexMap) {
662
+ // Use Map for O(1) lookup instead of getIndexByX which uses indexOf
663
+ const xKey = isString(v.x) ? v.x : +v.x;
664
+ const index = xIndexMap.get(xKey);
665
+
666
+ if (index !== undefined) {
667
+ data[index as number] = value;
668
+ }
574
669
  } else {
575
670
  data.push(value);
576
671
  }
@@ -620,7 +715,7 @@ export default {
620
715
  /**
621
716
  * Get data.order compare function
622
717
  * @param {boolean} isReversed for Arc & Treemap type sort order needs to be reversed
623
- * @returns {Function} compare function
718
+ * @returns {function} compare function
624
719
  * @private
625
720
  */
626
721
  getSortCompareFn(isReversed = false): Function | null {
@@ -1014,16 +1109,39 @@ export default {
1014
1109
  }
1015
1110
  } else if (type === "index") {
1016
1111
  const dataValues = api.data.values.bind(api);
1017
- let total = this.getTotalPerIndex();
1112
+ const {hiddenTargetIds} = state;
1113
+
1114
+ // For normalized stack per group, get total per group
1115
+ let total = this.getTotalPerIndex(
1116
+ $$.isStackNormalizedPerGroup() ? d.id : undefined
1117
+ );
1018
1118
 
1019
- if (state.hiddenTargetIds.length) {
1020
- let hiddenSum = dataValues(state.hiddenTargetIds, false);
1119
+ // If total is null, the data is not in any group - don't normalize
1120
+ if (total === null) {
1121
+ return ratio;
1122
+ }
1021
1123
 
1022
- if (hiddenSum.length) {
1023
- hiddenSum = hiddenSum
1024
- .reduce((acc, curr) => acc.map((v, i) => ~~v + curr[i]));
1124
+ if (hiddenTargetIds.length) {
1125
+ // When normalized per group, only subtract hidden data from the same group
1126
+ let hiddenIds = hiddenTargetIds;
1025
1127
 
1026
- total = total.map((v, i) => v - hiddenSum[i]);
1128
+ if ($$.isStackNormalizedPerGroup() && d.id) {
1129
+ const group = config.data_groups.find(g => g.indexOf(d.id) >= 0);
1130
+ if (group) {
1131
+ // Only consider hidden IDs in the same group
1132
+ hiddenIds = hiddenIds.filter(id => group.indexOf(id) >= 0);
1133
+ }
1134
+ }
1135
+
1136
+ if (hiddenIds.length) {
1137
+ let hiddenSum = dataValues(hiddenIds, false);
1138
+
1139
+ if (hiddenSum.length) {
1140
+ hiddenSum = hiddenSum
1141
+ .reduce((acc, curr) => acc.map((v, i) => ~~v + curr[i]));
1142
+
1143
+ total = total.map((v, i) => v - hiddenSum[i]);
1144
+ }
1027
1145
  }
1028
1146
  }
1029
1147
 
@@ -7,7 +7,7 @@ import {endall} from "../../module/util";
7
7
 
8
8
  /**
9
9
  * Call done callback with resize after transition
10
- * @param {Function} fn Callback function
10
+ * @param {function} fn Callback function
11
11
  * @param {boolean} resizeAfter Weather to resize chart after the load
12
12
  * @private
13
13
  */
@@ -156,13 +156,6 @@ export default {
156
156
  return;
157
157
  }
158
158
 
159
- const targets = $el.svg.selectAll(targetIds.map(id => $$.selectorTarget(id)));
160
-
161
- $T(targets)
162
- .style("opacity", "0")
163
- .remove()
164
- .call(endall, done);
165
-
166
159
  targetIds.forEach(id => {
167
160
  const suffixId = $$.getTargetSelectorSuffix(id);
168
161
 
@@ -189,5 +182,12 @@ export default {
189
182
 
190
183
  // Update current state chart type and elements list after redraw
191
184
  $$.updateTypesElements();
185
+
186
+ const targets = $el.svg.selectAll(targetIds.map(id => $$.selectorTarget(id)));
187
+
188
+ $T(targets)
189
+ .style("opacity", "0")
190
+ .remove()
191
+ .call(endall, done);
192
192
  }
193
193
  };
@@ -5,7 +5,7 @@
5
5
  import {select as d3Select} from "d3-selection";
6
6
  import type {d3Selection} from "../../../types/types";
7
7
  import {$BAR, $CIRCLE, $COMMON, $DRAG, $SELECT, $SHAPE} from "../../config/classes";
8
- import {getPathBox} from "../../module/util";
8
+ import {getPathBox, scheduleRAFUpdate} from "../../module/util";
9
9
 
10
10
  /**
11
11
  * Module used for data.selection.draggable option
@@ -40,47 +40,58 @@ export default {
40
40
  const minY = isSelectionGrouped ? state.margin.top : Math.min(sy, my);
41
41
  const maxY = isSelectionGrouped ? state.height : Math.max(sy, my);
42
42
 
43
- main.select(`.${$DRAG.dragarea}`)
44
- .attr("x", minX)
45
- .attr("y", minY)
46
- .attr("width", maxX - minX)
47
- .attr("height", maxY - minY);
48
-
49
- // TODO: binary search when multiple xs
50
- main.selectAll(`.${$SHAPE.shapes}`)
51
- .selectAll(`.${$SHAPE.shape}`)
52
- .filter(d => isSelectable?.bind($$.api)(d))
53
- .each(function(d, i) {
54
- const shape: d3Selection = d3Select(this);
55
- const isSelected = shape.classed($SELECT.SELECTED);
56
- const isIncluded = shape.classed($DRAG.INCLUDED);
57
- let isWithin: any = false;
58
- let toggle;
59
-
60
- if (shape.classed($CIRCLE.circle)) {
61
- const x: number = +shape.attr("cx") * 1;
62
- const y: number = +shape.attr("cy") * 1;
63
-
64
- toggle = $$.togglePoint;
65
- isWithin = minX < x && x < maxX && minY < y && y < maxY;
66
- } else if (shape.classed($BAR.bar)) {
67
- const {x, y, width, height} = getPathBox(this);
68
-
69
- toggle = $$.togglePath;
70
- isWithin = !(maxX < x || x + width < minX) && !(maxY < y || y + height < minY);
71
- } else {
72
- // line/area selection not supported yet
73
- return;
74
- }
75
-
76
- // @ts-ignore
77
- if (isWithin ^ isIncluded) {
78
- shape.classed($DRAG.INCLUDED, !isIncluded);
79
- // TODO: included/unincluded callback here
80
- shape.classed($SELECT.SELECTED, !isSelected);
81
- toggle.call($$, !isSelected, shape, d, i);
82
- }
83
- });
43
+ // Use RAF batching to smooth out rapid drag events
44
+ const executeDrag = () => {
45
+ // Check if chart still exists before executing
46
+ if (!$$ || !$$.$el || !$$.$el.main) {
47
+ return;
48
+ }
49
+
50
+ main.select(`.${$DRAG.dragarea}`)
51
+ .attr("x", minX)
52
+ .attr("y", minY)
53
+ .attr("width", maxX - minX)
54
+ .attr("height", maxY - minY);
55
+
56
+ // TODO: binary search when multiple xs
57
+ main.selectAll(`.${$SHAPE.shapes}`)
58
+ .selectAll(`.${$SHAPE.shape}`)
59
+ .filter(d => isSelectable?.bind($$.api)(d))
60
+ .each(function(d, i) {
61
+ const shape: d3Selection = d3Select(this);
62
+ const isSelected = shape.classed($SELECT.SELECTED);
63
+ const isIncluded = shape.classed($DRAG.INCLUDED);
64
+ let isWithin: any = false;
65
+ let toggle;
66
+
67
+ if (shape.classed($CIRCLE.circle)) {
68
+ const x: number = +shape.attr("cx") * 1;
69
+ const y: number = +shape.attr("cy") * 1;
70
+
71
+ toggle = $$.togglePoint;
72
+ isWithin = minX < x && x < maxX && minY < y && y < maxY;
73
+ } else if (shape.classed($BAR.bar)) {
74
+ const {x, y, width, height} = getPathBox(this);
75
+
76
+ toggle = $$.togglePath;
77
+ isWithin = !(maxX < x || x + width < minX) &&
78
+ !(maxY < y || y + height < minY);
79
+ } else {
80
+ // line/area selection not supported yet
81
+ return;
82
+ }
83
+
84
+ // @ts-ignore
85
+ if (isWithin ^ isIncluded) {
86
+ shape.classed($DRAG.INCLUDED, !isIncluded);
87
+ // TODO: included/unincluded callback here
88
+ shape.classed($SELECT.SELECTED, !isSelected);
89
+ toggle.call($$, !isSelected, shape, d, i);
90
+ }
91
+ });
92
+ };
93
+
94
+ scheduleRAFUpdate($$.state, executeDrag);
84
95
  },
85
96
 
86
97
  /**
@@ -125,6 +125,10 @@ export default {
125
125
  const preventThreshold = (!isNaN(preventDefault) && preventDefault) || null;
126
126
  let startPx;
127
127
 
128
+ // Determine passive option based on preventDefault setting
129
+ // If preventDefault is needed, passive must be false
130
+ const passiveOption = !isPrevented && preventThreshold === null;
131
+
128
132
  const preventEvent = event => {
129
133
  const eventType = event.type;
130
134
  const touch = event.changedTouches[0];
@@ -156,7 +160,7 @@ export default {
156
160
  .on("touchstart", event => {
157
161
  state.event = event;
158
162
  $$.updateEventRect();
159
- })
163
+ }, {passive: passiveOption})
160
164
  .on("touchstart.eventRect touchmove.eventRect", event => {
161
165
  state.event = event;
162
166
 
@@ -174,7 +178,7 @@ export default {
174
178
  } else {
175
179
  unselectRect();
176
180
  }
177
- }, true)
181
+ }, {passive: passiveOption})
178
182
  .on("touchend.eventRect", event => {
179
183
  state.event = event;
180
184
 
@@ -183,7 +187,7 @@ export default {
183
187
  state.cancelClick && (state.cancelClick = false);
184
188
  }
185
189
  }
186
- }, true);
190
+ }, {passive: passiveOption});
187
191
 
188
192
  svg.on("touchstart", event => {
189
193
  state.event = event;
@@ -192,7 +196,7 @@ export default {
192
196
  if (target && target !== eventRect.node()) {
193
197
  unselectRect();
194
198
  }
195
- });
199
+ }, {passive: passiveOption});
196
200
  },
197
201
 
198
202
  /**
@@ -473,7 +477,13 @@ export default {
473
477
  if ($$.isBarType(closest.id) || dist < $$.getPointSensitivity(closest)) {
474
478
  $$.$el.svg.select(`.${$EVENT.eventRect}`).style("cursor", "pointer");
475
479
 
476
- if (triggerEvent && !state.mouseover) {
480
+ if (
481
+ triggerEvent && (
482
+ !state.mouseover ||
483
+ state.mouseover.x !== closest.x ||
484
+ state.mouseover.id !== closest.id
485
+ )
486
+ ) {
477
487
  config.data_onover.call($$.api, closest);
478
488
  state.mouseover = closest;
479
489
  }
@@ -11,7 +11,7 @@ export default {
11
11
  /**
12
12
  * Generate flow
13
13
  * @param {object} args option object
14
- * @returns {Function}
14
+ * @returns {function}
15
15
  * @private
16
16
  */
17
17
  generateFlow(args): Function {
@@ -149,7 +149,7 @@ export default {
149
149
 
150
150
  /**
151
151
  * Return draggable selection function
152
- * @returns {Function}
152
+ * @returns {function}
153
153
  * @private
154
154
  */
155
155
  getDraggableSelection(): Function {
@@ -10,7 +10,7 @@ import {
10
10
  } from "d3-zoom";
11
11
  import {$COMMON, $ZOOM} from "../../config/classes";
12
12
  import {window} from "../../module/browser";
13
- import {callFn, diffDomain, getPointer, isFunction} from "../../module/util";
13
+ import {callFn, diffDomain, getPointer, isFunction, scheduleRAFUpdate} from "../../module/util";
14
14
 
15
15
  export default {
16
16
  /**
@@ -120,10 +120,6 @@ export default {
120
120
  d3ZoomIdentity.translate(tX, tY).scale(transform.k));
121
121
  }
122
122
 
123
- if (!$$.state.xTickOffset) {
124
- $$.state.xTickOffset = $$.axis.x.tickOffset();
125
- }
126
-
127
123
  scale.zoom = $$.getCustomizedXScale(newScale);
128
124
  $$.axis.x.scale(scale.zoom);
129
125
 
@@ -216,22 +212,30 @@ export default {
216
212
  state.dragging || isUnZoom || !event.sourceEvent
217
213
  );
218
214
 
219
- $$.redraw({
220
- withTransition: doTransition,
221
- withY: config.zoom_rescale,
222
- withSubchart: false,
223
- withEventRect: false,
224
- withDimension: false
225
- });
215
+ // Use RAF batching for continuous drag zoom events only
216
+ // Wheel zoom and API calls need synchronous execution for correct behavior and tests
217
+ const useRAF = sourceEvent && isMousemove && config.zoom_type !== "wheel";
218
+
219
+ const executeRedraw = () => {
220
+ $$.redraw({
221
+ withTransition: doTransition,
222
+ withY: config.zoom_rescale,
223
+ withSubchart: false,
224
+ withEventRect: false,
225
+ withDimension: false
226
+ });
226
227
 
227
- $$.state.cancelClick = isMousemove;
228
+ $$.state.cancelClick = isMousemove;
228
229
 
229
- // do not call event cb when is .unzoom() is called
230
- !isUnZoom && callFn(
231
- config.zoom_onzoom,
232
- $$.api,
233
- $$.state.domain ?? $$.zoom.getDomain()
234
- );
230
+ // do not call event cb when is .unzoom() is called
231
+ !isUnZoom && callFn(
232
+ config.zoom_onzoom,
233
+ $$.api,
234
+ $$.state.domain ?? $$.zoom.getDomain()
235
+ );
236
+ };
237
+
238
+ useRAF ? scheduleRAFUpdate($$.state, executeRedraw) : executeRedraw();
235
239
  },
236
240
 
237
241
  /**
@@ -309,7 +313,7 @@ export default {
309
313
 
310
314
  /**
311
315
  * Set zoom transform to event rect
312
- * @param {Function} x x Axis scale function
316
+ * @param {function} x x Axis scale function
313
317
  * @param {Array} domain Domain value to be set
314
318
  * @private
315
319
  */