@antv/g2 5.4.1 → 5.4.3

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 (110) hide show
  1. package/dist/g2.lite.min.js +10 -10
  2. package/dist/g2.min.js +10 -10
  3. package/esm/component/constant.d.ts +1 -0
  4. package/esm/component/constant.js +8 -0
  5. package/esm/component/constant.js.map +1 -1
  6. package/esm/component/legendCategory.js +7 -1
  7. package/esm/component/legendCategory.js.map +1 -1
  8. package/esm/component/legendContinuous.js +4 -0
  9. package/esm/component/legendContinuous.js.map +1 -1
  10. package/esm/component/slider.js +3 -1
  11. package/esm/component/slider.js.map +1 -1
  12. package/esm/composition/view.js +4 -4
  13. package/esm/composition/view.js.map +1 -1
  14. package/esm/index.d.ts +2 -0
  15. package/esm/interaction/adaptiveFilter.d.ts +147 -0
  16. package/esm/interaction/adaptiveFilter.js +305 -0
  17. package/esm/interaction/adaptiveFilter.js.map +1 -0
  18. package/esm/interaction/legendFilter.d.ts +2 -0
  19. package/esm/interaction/legendFilter.js +203 -6
  20. package/esm/interaction/legendFilter.js.map +1 -1
  21. package/esm/interaction/sliderFilter.d.ts +2 -1
  22. package/esm/interaction/sliderFilter.js +400 -42
  23. package/esm/interaction/sliderFilter.js.map +1 -1
  24. package/esm/interaction/sliderWheel.d.ts +0 -3
  25. package/esm/interaction/sliderWheel.js +91 -10
  26. package/esm/interaction/sliderWheel.js.map +1 -1
  27. package/esm/interaction/tooltip.d.ts +2 -2
  28. package/esm/interaction/tooltip.js +40 -10
  29. package/esm/interaction/tooltip.js.map +1 -1
  30. package/esm/interaction/utils.d.ts +69 -0
  31. package/esm/interaction/utils.js +201 -0
  32. package/esm/interaction/utils.js.map +1 -1
  33. package/esm/lib/core.d.ts +1 -0
  34. package/esm/lib/core.js +2 -1
  35. package/esm/lib/core.js.map +1 -1
  36. package/esm/lib/std.d.ts +1 -0
  37. package/esm/mark/beeswarm.d.ts +7 -0
  38. package/esm/mark/beeswarm.js +98 -0
  39. package/esm/mark/beeswarm.js.map +1 -0
  40. package/esm/mark/index.d.ts +2 -0
  41. package/esm/mark/index.js +1 -0
  42. package/esm/mark/index.js.map +1 -1
  43. package/esm/runtime/layout.js +35 -4
  44. package/esm/runtime/layout.js.map +1 -1
  45. package/esm/runtime/render.js +1 -0
  46. package/esm/runtime/render.js.map +1 -1
  47. package/esm/spec/interaction.d.ts +8 -0
  48. package/lib/component/constant.d.ts +1 -0
  49. package/lib/component/constant.js +9 -1
  50. package/lib/component/constant.js.map +1 -1
  51. package/lib/component/legendCategory.js +7 -1
  52. package/lib/component/legendCategory.js.map +1 -1
  53. package/lib/component/legendContinuous.js +4 -0
  54. package/lib/component/legendContinuous.js.map +1 -1
  55. package/lib/component/slider.js +3 -1
  56. package/lib/component/slider.js.map +1 -1
  57. package/lib/composition/view.js +4 -4
  58. package/lib/composition/view.js.map +1 -1
  59. package/lib/index.d.ts +2 -0
  60. package/lib/interaction/adaptiveFilter.d.ts +147 -0
  61. package/lib/interaction/adaptiveFilter.js +315 -0
  62. package/lib/interaction/adaptiveFilter.js.map +1 -0
  63. package/lib/interaction/legendFilter.d.ts +2 -0
  64. package/lib/interaction/legendFilter.js +205 -7
  65. package/lib/interaction/legendFilter.js.map +1 -1
  66. package/lib/interaction/sliderFilter.d.ts +2 -1
  67. package/lib/interaction/sliderFilter.js +399 -41
  68. package/lib/interaction/sliderFilter.js.map +1 -1
  69. package/lib/interaction/sliderWheel.d.ts +0 -3
  70. package/lib/interaction/sliderWheel.js +91 -10
  71. package/lib/interaction/sliderWheel.js.map +1 -1
  72. package/lib/interaction/tooltip.d.ts +2 -2
  73. package/lib/interaction/tooltip.js +40 -10
  74. package/lib/interaction/tooltip.js.map +1 -1
  75. package/lib/interaction/utils.d.ts +69 -0
  76. package/lib/interaction/utils.js +207 -1
  77. package/lib/interaction/utils.js.map +1 -1
  78. package/lib/lib/core.d.ts +1 -0
  79. package/lib/lib/core.js +1 -0
  80. package/lib/lib/core.js.map +1 -1
  81. package/lib/lib/std.d.ts +1 -0
  82. package/lib/mark/beeswarm.d.ts +7 -0
  83. package/lib/mark/beeswarm.js +102 -0
  84. package/lib/mark/beeswarm.js.map +1 -0
  85. package/lib/mark/index.d.ts +2 -0
  86. package/lib/mark/index.js +3 -1
  87. package/lib/mark/index.js.map +1 -1
  88. package/lib/runtime/layout.js +41 -10
  89. package/lib/runtime/layout.js.map +1 -1
  90. package/lib/runtime/render.js +1 -0
  91. package/lib/runtime/render.js.map +1 -1
  92. package/lib/spec/interaction.d.ts +8 -0
  93. package/package.json +3 -3
  94. package/src/component/constant.ts +9 -0
  95. package/src/component/legendCategory.ts +9 -0
  96. package/src/component/legendContinuous.ts +4 -0
  97. package/src/component/slider.ts +6 -1
  98. package/src/composition/view.ts +4 -1
  99. package/src/interaction/adaptiveFilter.ts +517 -0
  100. package/src/interaction/legendFilter.ts +222 -7
  101. package/src/interaction/sliderFilter.ts +762 -72
  102. package/src/interaction/sliderWheel.ts +109 -10
  103. package/src/interaction/tooltip.ts +43 -10
  104. package/src/interaction/utils.ts +261 -0
  105. package/src/lib/core.ts +2 -0
  106. package/src/mark/beeswarm.ts +150 -0
  107. package/src/mark/index.ts +2 -0
  108. package/src/runtime/layout.ts +46 -3
  109. package/src/runtime/render.ts +1 -0
  110. package/src/spec/interaction.ts +8 -0
@@ -1,4 +1,4 @@
1
- import { CustomEvent } from '@antv/g';
1
+ import { CustomEvent, DisplayObject } from '@antv/g';
2
2
  import { isTranspose } from '../utils/coordinate';
3
3
  import { SLIDER_CLASS_NAME } from './sliderFilter';
4
4
  import { calculateSensitivityMultiplier } from './utils';
@@ -7,6 +7,23 @@ import { calculateSensitivityMultiplier } from './utils';
7
7
  * SliderWheel interaction for mouse wheel/touchpad gestures on charts.
8
8
  */
9
9
 
10
+ /**
11
+ * Get the real DOM canvas element from G2 container.
12
+ * This helper function provides better type safety than using 'as any' directly.
13
+ */
14
+ function getCanvasDOM(container: any): HTMLElement | null {
15
+ try {
16
+ const canvas = container.ownerDocument?.defaultView;
17
+ if (!canvas || typeof canvas.getContextService !== 'function') {
18
+ return null;
19
+ }
20
+ const dom = canvas.getContextService().getDomElement();
21
+ return dom instanceof HTMLElement ? dom : null;
22
+ } catch {
23
+ return null;
24
+ }
25
+ }
26
+
10
27
  type SliderDirection = true | false | 'shift' | 'ctrl' | 'alt';
11
28
 
12
29
  interface SliderWheelOptions {
@@ -30,6 +47,9 @@ export function SliderWheel({
30
47
  const { container, view } = context;
31
48
  const { coordinate } = view;
32
49
  const transposed = isTranspose(coordinate);
50
+
51
+ // Get the real DOM canvas element to attach wheel listener
52
+ const canvasDOM = getCanvasDOM(container);
33
53
  const safeMinRange = Math.max(0.000001, Math.min(1, minRange));
34
54
 
35
55
  const sliders = container.getElementsByClassName(className);
@@ -63,9 +83,46 @@ export function SliderWheel({
63
83
  );
64
84
  };
65
85
 
86
+ /**
87
+ * Calculate zoom center based on mouse position relative to slider track.
88
+ * @param mousePos - Mouse position (X or Y) relative to canvas
89
+ * @param sliderPos - Slider position (X or Y)
90
+ * @param trackLength - Length of slider track
91
+ * @param v0 - Current selection start value [0-1]
92
+ * @param v1 - Current selection end value [0-1]
93
+ * @returns Normalized center position [0-1] clamped to current selection
94
+ */
95
+ const calculateZoomCenter = (
96
+ mousePos: number,
97
+ sliderPos: number,
98
+ trackLength: number,
99
+ v0: number,
100
+ v1: number,
101
+ ): number => {
102
+ const relativePos = mousePos - sliderPos;
103
+ const normalizedPosition = relativePos / trackLength;
104
+ // Clamp to [0, 1] range first, then to current selection range
105
+ const clamped = Math.max(0, Math.min(1, normalizedPosition));
106
+ return Math.max(v0, Math.min(v1, clamped));
107
+ };
108
+
66
109
  const handleWheel = (event: WheelEvent) => {
67
- event.preventDefault();
68
- event.stopPropagation();
110
+ // Early return if canvas DOM is not available
111
+ if (!canvasDOM) return;
112
+
113
+ // Check if the event target is within our canvas container
114
+ const target = event.target as HTMLElement;
115
+ if (!canvasDOM.contains(target)) {
116
+ return;
117
+ }
118
+
119
+ // Get mouse position relative to canvas
120
+ const canvasRect = canvasDOM.getBoundingClientRect();
121
+ const mouseX = event.clientX - canvasRect.left;
122
+ const mouseY = event.clientY - canvasRect.top;
123
+
124
+ // Find all sliders that should respond to this event
125
+ const activeSliders: DisplayObject[] = [];
69
126
 
70
127
  for (const slider of sliders) {
71
128
  const { values, orientation } = (slider as any).attributes;
@@ -81,11 +138,38 @@ export function SliderWheel({
81
138
  : 'y';
82
139
  const axisConfig = actualAxis === 'x' ? x : y;
83
140
 
84
- if (!isModifierKeyActive(axisConfig, event)) continue;
141
+ if (isModifierKeyActive(axisConfig, event)) {
142
+ activeSliders.push(slider);
143
+ }
144
+ }
145
+
146
+ // If no slider should handle this event, let it propagate
147
+ if (activeSliders.length === 0) {
148
+ return;
149
+ }
150
+
151
+ // Prevent page scroll since we have active sliders
152
+ event.preventDefault();
153
+ event.stopPropagation();
85
154
 
155
+ // Process all active sliders
156
+ for (const slider of activeSliders) {
157
+ const {
158
+ values,
159
+ orientation,
160
+ x: sliderX,
161
+ y: sliderY,
162
+ trackLength,
163
+ } = (slider as any).attributes;
86
164
  const [v0, v1] = values;
87
165
  const range = v1 - v0;
88
- const center = (v0 + v1) / 2;
166
+ const isHorizontal = orientation === 'horizontal';
167
+
168
+ // Calculate zoom center based on mouse position relative to slider
169
+ const center = isHorizontal
170
+ ? calculateZoomCenter(mouseX, sliderX, trackLength, v0, v1)
171
+ : calculateZoomCenter(mouseY, sliderY, trackLength, v0, v1);
172
+
89
173
  const adaptiveSensitivity =
90
174
  wheelSensitivity * calculateSensitivityMultiplier(range);
91
175
 
@@ -96,10 +180,15 @@ export function SliderWheel({
96
180
  Math.min(1, range * zoomFactor),
97
181
  );
98
182
 
99
- const halfRange = newRange / 2;
100
- let newV0 = center - halfRange;
101
- let newV1 = center + halfRange;
183
+ // Calculate new range boundaries based on mouse position
184
+ // The zoom should maintain the ratio of distances from center to edges
185
+ const leftRatio = (center - v0) / range;
186
+ const rightRatio = (v1 - center) / range;
187
+
188
+ let newV0 = center - newRange * leftRatio;
189
+ let newV1 = center + newRange * rightRatio;
102
190
 
191
+ // Handle boundary conditions while trying to maintain mouse position as center
103
192
  if (newV0 < 0) {
104
193
  newV0 = 0;
105
194
  newV1 = Math.min(1, newRange);
@@ -112,10 +201,20 @@ export function SliderWheel({
112
201
  }
113
202
  };
114
203
 
115
- container.addEventListener('wheel', handleWheel, { passive: false });
204
+ // Listen on the real DOM canvas element with passive: false AND capture: true
205
+ // Capture phase ensures we intercept BEFORE @antv/g-canvas's passive listener
206
+ // This is the only way to preventDefault() before the passive listener receives it
207
+ if (canvasDOM) {
208
+ canvasDOM.addEventListener('wheel', handleWheel, {
209
+ passive: false,
210
+ capture: true,
211
+ });
212
+ }
116
213
 
117
214
  return () => {
118
- container.removeEventListener('wheel', handleWheel);
215
+ if (canvasDOM) {
216
+ canvasDOM.removeEventListener('wheel', handleWheel, { capture: true });
217
+ }
119
218
  };
120
219
  };
121
220
  }
@@ -26,6 +26,8 @@ import {
26
26
  maybeRoot,
27
27
  } from './utils';
28
28
 
29
+ const LOCKED_SYMBOL = 'tooltipLocked';
30
+
29
31
  function getContainer(
30
32
  group: IElement,
31
33
  mount?: string | HTMLElement,
@@ -144,7 +146,10 @@ function showTooltip({
144
146
  tooltipElement.update({
145
147
  x,
146
148
  y,
147
- data: items,
149
+ data: items.map((item) => ({
150
+ ...item,
151
+ value: !item.value && item.value !== 0 ? '' : item.value,
152
+ })),
148
153
  title,
149
154
  position,
150
155
  enterable,
@@ -942,6 +947,8 @@ export function seriesTooltip(
942
947
  preserve = false,
943
948
  style: _style = {},
944
949
  css = {},
950
+ clickLock = false,
951
+ disableAutoHide = false,
945
952
  ...rest
946
953
  }: Record<string, any>,
947
954
  ) {
@@ -959,6 +966,7 @@ export function seriesTooltip(
959
966
  } = coordinate.getOptions();
960
967
  const update = throttle(
961
968
  (event) => {
969
+ if (clickLock && root.getAttribute(LOCKED_SYMBOL)) return;
962
970
  const mouse = mousePosition(root, event);
963
971
  if (!mouse) return;
964
972
  const bbox = bboxOf(root);
@@ -1088,6 +1096,8 @@ export function seriesTooltip(
1088
1096
  ) as (...args: any[]) => void;
1089
1097
 
1090
1098
  const hide = (event: MouseEvent) => {
1099
+ if ((clickLock && root.getAttribute(LOCKED_SYMBOL)) || disableAutoHide)
1100
+ return;
1091
1101
  hideTooltip({ root, single, emitter, event });
1092
1102
  };
1093
1103
 
@@ -1130,9 +1140,16 @@ export function seriesTooltip(
1130
1140
  addEventListeners();
1131
1141
  };
1132
1142
 
1143
+ const pointerdown = (e) => {
1144
+ if (clickLock) {
1145
+ root.setAttribute(LOCKED_SYMBOL, !root.getAttribute(LOCKED_SYMBOL));
1146
+ }
1147
+ update(e);
1148
+ };
1149
+
1133
1150
  const addEventListeners = () => {
1134
1151
  if (!disableNative) {
1135
- root.addEventListener('pointerdown', update);
1152
+ root.addEventListener('pointerdown', pointerdown);
1136
1153
  root.addEventListener('pointerenter', update);
1137
1154
  root.addEventListener('pointermove', update);
1138
1155
  // Only emit pointerleave event when the pointer is not in the root area.
@@ -1143,7 +1160,7 @@ export function seriesTooltip(
1143
1160
 
1144
1161
  const removeEventListeners = () => {
1145
1162
  if (!disableNative) {
1146
- root.removeEventListener('pointerdown', update);
1163
+ root.removeEventListener('pointerdown', pointerdown);
1147
1164
  root.removeEventListener('pointerenter', update);
1148
1165
  root.removeEventListener('pointermove', update);
1149
1166
  root.removeEventListener('pointerleave', pointerleave);
@@ -1204,12 +1221,15 @@ export function tooltip(
1204
1221
  disableNative = false,
1205
1222
  preserve = false,
1206
1223
  css = {},
1224
+ clickLock = false,
1225
+ disableAutoHide = false,
1207
1226
  }: Record<string, any>,
1208
1227
  ) {
1209
1228
  const elements = elementsof(root);
1210
1229
  const keyGroup = group(elements, groupKey);
1211
1230
  const pointermove = throttle(
1212
1231
  (event) => {
1232
+ if (clickLock && root.getAttribute(LOCKED_SYMBOL)) return;
1213
1233
  const element = findSingleElement({
1214
1234
  root,
1215
1235
  event,
@@ -1219,7 +1239,9 @@ export function tooltip(
1219
1239
  shared,
1220
1240
  });
1221
1241
  if (!element) {
1222
- hideTooltip({ root, single, emitter, event });
1242
+ if (!disableAutoHide) {
1243
+ hideTooltip({ root, single, emitter, event });
1244
+ }
1223
1245
  return;
1224
1246
  }
1225
1247
  const k = groupKey(element);
@@ -1241,7 +1263,9 @@ export function tooltip(
1241
1263
  }
1242
1264
 
1243
1265
  if (isEmptyTooltipData(data)) {
1244
- hideTooltip({ root, single, emitter, event });
1266
+ if (!disableAutoHide) {
1267
+ hideTooltip({ root, single, emitter, event });
1268
+ }
1245
1269
  return;
1246
1270
  }
1247
1271
 
@@ -1278,12 +1302,20 @@ export function tooltip(
1278
1302
  ) as (...args: any[]) => void;
1279
1303
 
1280
1304
  const pointerleave = (event) => {
1305
+ if (disableAutoHide) return;
1281
1306
  hideTooltip({ root, single, emitter, event });
1282
1307
  };
1283
1308
 
1309
+ const pointerdown = (e) => {
1310
+ if (clickLock) {
1311
+ root.setAttribute(LOCKED_SYMBOL, !root.getAttribute(LOCKED_SYMBOL));
1312
+ }
1313
+ pointermove(e);
1314
+ };
1315
+
1284
1316
  const addEventListeners = () => {
1285
1317
  if (!disableNative) {
1286
- root.addEventListener('pointerdown', pointermove);
1318
+ root.addEventListener('pointerdown', pointerdown);
1287
1319
  root.addEventListener('pointermove', pointermove);
1288
1320
  // Only emit pointerleave event when the pointer is not in the root area.
1289
1321
  // !!!DO NOT USE pointerout event, it will emit when the pointer is in the child area.
@@ -1294,7 +1326,7 @@ export function tooltip(
1294
1326
 
1295
1327
  const removeEventListeners = () => {
1296
1328
  if (!disableNative) {
1297
- root.removeEventListener('pointerdown', pointermove);
1329
+ root.removeEventListener('pointerdown', pointerdown);
1298
1330
  root.removeEventListener('pointermove', pointermove);
1299
1331
  root.removeEventListener('pointerleave', pointerleave);
1300
1332
  root.removeEventListener('pointerup', pointerleave);
@@ -1373,7 +1405,7 @@ export function Tooltip(options) {
1373
1405
  const plotArea = selectPlotArea(container);
1374
1406
  const isSeries = maybeValue(series, defaultSeries);
1375
1407
  const crosshairsSetting = maybeValue(crosshairs, defaultShowCrosshairs);
1376
-
1408
+ if (rest.clickLock && !facet) plotArea.setAttribute(LOCKED_SYMBOL, false);
1377
1409
  // For non-facet and series tooltip.
1378
1410
  if (isSeries && hasSeries(markState) && !facet) {
1379
1411
  return seriesTooltip(plotArea, {
@@ -1406,11 +1438,12 @@ export function Tooltip(options) {
1406
1438
  const startX = bbox.min[0];
1407
1439
  const startY = bbox.min[1];
1408
1440
  Object.assign(scale, { facet: true });
1409
-
1441
+ const root = plotArea.parentNode.parentNode as DisplayObject;
1442
+ if (rest.clickLock) root.setAttribute(LOCKED_SYMBOL, false);
1410
1443
  // @todo Nested structure rather than flat structure for facet?
1411
1444
  // Add listener to the root area.
1412
1445
  // @ts-ignore
1413
- return seriesTooltip(plotArea.parentNode.parentNode, {
1446
+ return seriesTooltip(root, {
1414
1447
  ...rest,
1415
1448
  theme,
1416
1449
  elements: () => elements,
@@ -722,3 +722,264 @@ export function calculateSensitivityMultiplier(range: number): number {
722
722
  // Clamp to reasonable range: 0.1x to 100x
723
723
  return Math.max(MIN_MULTIPLIER, Math.min(MAX_MULTIPLIER, multiplier));
724
724
  }
725
+
726
+ /**
727
+ * Check if a value is considered "falsy" for configuration purposes.
728
+ * Returns true for false, null, or undefined values.
729
+ * Uses type predicate for better type safety.
730
+ *
731
+ * @param value The value to check
732
+ * @returns true if the value is falsy (false, null, undefined)
733
+ */
734
+ export function isFalsyValue(
735
+ value: unknown,
736
+ ): value is false | null | undefined {
737
+ return value === false || value === null || value === undefined;
738
+ }
739
+
740
+ /**
741
+ * Extract channel data with preserved X-Y relationships from all marks in a view.
742
+ * Supports multi-mark scenarios, bin transforms, and array-encoded Y values.
743
+ *
744
+ * @param view The view object containing markState
745
+ * @returns Object containing flattened values for backward compatibility and structured mark data
746
+ */
747
+ export function extractChannelValues(view: G2ViewDescriptor): {
748
+ xChannelValues: unknown[];
749
+ yChannelValues: unknown[];
750
+ markDataPairs: Array<{
751
+ markKey: string;
752
+ channelData: { [key: string]: unknown[] };
753
+ }>;
754
+ } {
755
+ const allXChannelValues: unknown[][] = [];
756
+ const allYChannelValues: unknown[][] = [];
757
+ const markDataPairs: Array<{
758
+ markKey: string;
759
+ channelData: { [key: string]: unknown[] };
760
+ }> = [];
761
+ const marks = view.markState;
762
+
763
+ if (marks) {
764
+ for (const [mark, state] of marks.entries()) {
765
+ if (state?.channels) {
766
+ const channelData: { [key: string]: any[] } = {};
767
+
768
+ // Process each channel for the current mark
769
+ for (const channel of state.channels) {
770
+ if (channel?.name === 'x' && channel.values?.length > 0) {
771
+ // Collect X values (supports bin transforms with multiple values)
772
+ let xValues: unknown[] = [];
773
+ for (const valueItem of channel.values) {
774
+ if (valueItem?.value) {
775
+ xValues = xValues.concat(valueItem.value);
776
+ allXChannelValues.push(valueItem.value);
777
+ }
778
+ }
779
+ channelData['x'] = xValues;
780
+ } else if (
781
+ channel &&
782
+ (channel.name === 'y' || channel.name.startsWith('y')) && // Support y, y1, y2, y3, etc.
783
+ channel.values?.length > 0
784
+ ) {
785
+ const channelName = channel.name;
786
+ const channelValues: unknown[] = [];
787
+
788
+ // Handle Y and Y1+ channels for multi-Y marks (e.g., area charts, candlestick charts)
789
+ for (const valueItem of channel.values) {
790
+ if (valueItem?.value) {
791
+ const values = valueItem.value;
792
+ // Preserve G2's internal structure for array-encoded data
793
+ // Area charts: [[low1,low2,low3], [high1,high2,high3]]
794
+ // Line charts: [[value1,value2,value3]]
795
+ channelValues.push(values);
796
+ if (channelName === 'y' || channelName === 'y1') {
797
+ // For global domain calculation, flatten only for allYChannelValues
798
+ if (Array.isArray(values)) {
799
+ allYChannelValues.push(values.flat());
800
+ } else {
801
+ allYChannelValues.push([values]);
802
+ }
803
+ }
804
+ }
805
+ }
806
+
807
+ // Store all Y-related channels
808
+ channelData[channelName] = channelValues;
809
+ }
810
+ }
811
+
812
+ // Store mark data with preserved X-Y relationships
813
+ const xValues = channelData['x'] || [];
814
+ const yValues = channelData['y'] || [];
815
+
816
+ if (xValues.length > 0 && yValues.length > 0) {
817
+ markDataPairs.push({
818
+ markKey: mark.key || `mark_${markDataPairs.length}`,
819
+ channelData,
820
+ });
821
+ }
822
+ }
823
+ }
824
+ }
825
+
826
+ return {
827
+ xChannelValues: allXChannelValues.flat(),
828
+ yChannelValues: allYChannelValues.flat(),
829
+ markDataPairs,
830
+ };
831
+ }
832
+
833
+ export function hasIndependentXYScale(
834
+ channel1: string,
835
+ marks: readonly unknown[],
836
+ ): boolean {
837
+ return marks.some((mark) => {
838
+ const { scale: markScale } = mark as Record<string, unknown>;
839
+ const channelScale = (markScale as Record<string, unknown>)?.[channel1] as
840
+ | Record<string, unknown>
841
+ | undefined;
842
+ return !!channelScale?.independent;
843
+ });
844
+ }
845
+
846
+ /**
847
+ * Calculate multi-axis channel domains for slider filtering.
848
+ * When independent scales are detected, generates separate domains for each axis (x1, y1, x2, y2, etc.)
849
+ *
850
+ * @param view The view object containing markState
851
+ * @param initDomain Initial domain configuration
852
+ * @param scaleX X scale instance
853
+ * @param scaleY Y scale instance
854
+ * @param independentInfo Pre-computed independent scale information
855
+ * @returns Extended channelDomain object with multi-axis support
856
+ */
857
+ export function calculateMultiAxisChannelDomains(
858
+ view: G2ViewDescriptor,
859
+ initDomain: Record<string, unknown>,
860
+ scaleX: { getOptions(): { domain: unknown } },
861
+ scaleY: { getOptions(): { domain: unknown } },
862
+ independentInfo?: IndependentScaleInfo,
863
+ ): Record<string, unknown[]> {
864
+ const channelDomain: Record<string, unknown[]> = {
865
+ x:
866
+ (initDomain.x as unknown[]) ||
867
+ (scaleX.getOptions().domain as unknown[]) ||
868
+ [],
869
+ y:
870
+ (initDomain.y as unknown[]) ||
871
+ (scaleY.getOptions().domain as unknown[]) ||
872
+ [],
873
+ };
874
+
875
+ // Use pre-computed info if available, otherwise calculate
876
+ const info = independentInfo || calculateAllIndependentScaleInfo(view);
877
+ const { hasIndependentX, hasIndependentY } = info;
878
+
879
+ if (hasIndependentX || hasIndependentY) {
880
+ let xIndex = 1;
881
+ let yIndex = 1;
882
+
883
+ // Iterate through marks to collect independent scale domains
884
+ for (const [mark, state] of view.markState.entries()) {
885
+ if (state?.channels) {
886
+ // Process independent X scales
887
+ if (hasIndependentX) {
888
+ const xChannel = state.channels.find((ch) => ch.name === 'x');
889
+ if (mark?.scale?.x?.independent) {
890
+ const xKey = `x${xIndex}`;
891
+ channelDomain[xKey] = xChannel.scale.domain;
892
+ xIndex++;
893
+ }
894
+ }
895
+
896
+ // Process independent Y scales
897
+ if (hasIndependentY) {
898
+ const yChannel = state.channels.find((ch) => ch.name === 'y');
899
+ if (mark?.scale?.y?.independent) {
900
+ const yKey = `y${yIndex}`;
901
+ channelDomain[yKey] = yChannel.scale.domain;
902
+ yIndex++;
903
+ }
904
+ }
905
+ }
906
+ }
907
+ }
908
+
909
+ return channelDomain;
910
+ }
911
+
912
+ /**
913
+ * Independent scale information cache interface
914
+ */
915
+ export interface IndependentScaleInfo {
916
+ hasIndependentX: boolean;
917
+ hasIndependentY: boolean;
918
+ marksWithSharedX: string[];
919
+ marksWithIndependentX: string[];
920
+ marksWithSharedY: string[];
921
+ marksWithIndependentY: string[];
922
+ markToXScaleMap: Map<string, string>;
923
+ markToYScaleMap: Map<string, string>;
924
+ }
925
+
926
+ /**
927
+ * Calculate all independent scale information in one pass
928
+ * This function performs a single traversal to compute all independent scale related information,
929
+ * avoiding repeated calculations throughout the codebase.
930
+ *
931
+ * @param view The view object containing markState
932
+ * @returns Complete independent scale information
933
+ */
934
+ export function calculateAllIndependentScaleInfo(
935
+ view: G2ViewDescriptor,
936
+ ): IndependentScaleInfo {
937
+ const marks = Array.from(view.markState.keys());
938
+ const hasIndependentX = hasIndependentXYScale('x', marks);
939
+ const hasIndependentY = hasIndependentXYScale('y', marks);
940
+
941
+ const marksWithSharedX: string[] = [];
942
+ const marksWithIndependentX: string[] = [];
943
+ const marksWithSharedY: string[] = [];
944
+ const marksWithIndependentY: string[] = [];
945
+
946
+ const markToXScaleMap = new Map<string, string>();
947
+ const markToYScaleMap = new Map<string, string>();
948
+
949
+ // Single traversal to compute all classifications and mappings
950
+ let xIndex = 1;
951
+ let yIndex = 1;
952
+
953
+ for (const [mark] of view.markState.entries()) {
954
+ const markKey = mark.key;
955
+
956
+ // X axis processing
957
+ if (mark?.scale?.x?.independent) {
958
+ marksWithIndependentX.push(markKey);
959
+ markToXScaleMap.set(markKey, `x${xIndex++}`);
960
+ } else {
961
+ marksWithSharedX.push(markKey);
962
+ markToXScaleMap.set(markKey, 'x');
963
+ }
964
+
965
+ // Y axis processing
966
+ if (mark?.scale?.y?.independent) {
967
+ marksWithIndependentY.push(markKey);
968
+ markToYScaleMap.set(markKey, `y${yIndex++}`);
969
+ } else {
970
+ marksWithSharedY.push(markKey);
971
+ markToYScaleMap.set(markKey, 'y');
972
+ }
973
+ }
974
+
975
+ return {
976
+ hasIndependentX,
977
+ hasIndependentY,
978
+ marksWithSharedX,
979
+ marksWithIndependentX,
980
+ marksWithSharedY,
981
+ marksWithIndependentY,
982
+ markToXScaleMap,
983
+ markToYScaleMap,
984
+ };
985
+ }
package/src/lib/core.ts CHANGED
@@ -34,6 +34,7 @@ import {
34
34
  Density,
35
35
  Heatmap,
36
36
  WordCloud as WordCloudGeometry,
37
+ Beeswarm,
37
38
  } from '../mark';
38
39
  import { Category10, Category20 } from '../palette';
39
40
  import {
@@ -247,6 +248,7 @@ export function corelib() {
247
248
  'mark.density': Density,
248
249
  'mark.heatmap': Heatmap,
249
250
  'mark.wordCloud': WordCloudGeometry,
251
+ 'mark.beeswarm': Beeswarm,
250
252
  'palette.category10': Category10,
251
253
  'palette.category20': Category20,
252
254
  'scale.linear': ScaleLinear,