@antv/g6 5.0.6 → 5.0.7

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 (50) hide show
  1. package/dist/g6.min.js +2 -2
  2. package/dist/lib/behaviors/drag-canvas.d.ts +4 -0
  3. package/dist/lib/runtime/canvas.d.ts +6 -5
  4. package/dist/lib/runtime/viewport.d.ts +1 -0
  5. package/dist/lib/types/point.d.ts +5 -0
  6. package/dist/lib/utils/point.d.ts +4 -4
  7. package/dist/lib/version.d.ts +1 -1
  8. package/esm/behaviors/drag-canvas.d.ts +4 -0
  9. package/esm/behaviors/drag-canvas.js +29 -9
  10. package/esm/behaviors/drag-canvas.js.map +1 -1
  11. package/esm/behaviors/zoom-canvas.js.map +1 -1
  12. package/esm/plugins/contextmenu/index.js +4 -2
  13. package/esm/plugins/contextmenu/index.js.map +1 -1
  14. package/esm/runtime/canvas.d.ts +6 -5
  15. package/esm/runtime/canvas.js.map +1 -1
  16. package/esm/runtime/viewport.d.ts +1 -0
  17. package/esm/runtime/viewport.js +13 -3
  18. package/esm/runtime/viewport.js.map +1 -1
  19. package/esm/types/point.d.ts +5 -0
  20. package/esm/utils/point.d.ts +4 -4
  21. package/esm/utils/point.js +2 -2
  22. package/esm/utils/point.js.map +1 -1
  23. package/esm/version.d.ts +1 -1
  24. package/esm/version.js +1 -1
  25. package/lib/behaviors/drag-canvas.d.ts +4 -0
  26. package/lib/behaviors/drag-canvas.js +28 -8
  27. package/lib/behaviors/drag-canvas.js.map +1 -1
  28. package/lib/behaviors/zoom-canvas.js.map +1 -1
  29. package/lib/plugins/contextmenu/index.js +4 -2
  30. package/lib/plugins/contextmenu/index.js.map +1 -1
  31. package/lib/runtime/canvas.d.ts +6 -5
  32. package/lib/runtime/canvas.js.map +1 -1
  33. package/lib/runtime/viewport.d.ts +1 -0
  34. package/lib/runtime/viewport.js +13 -3
  35. package/lib/runtime/viewport.js.map +1 -1
  36. package/lib/types/point.d.ts +5 -0
  37. package/lib/utils/point.d.ts +4 -4
  38. package/lib/utils/point.js +2 -2
  39. package/lib/utils/point.js.map +1 -1
  40. package/lib/version.d.ts +1 -1
  41. package/lib/version.js +1 -1
  42. package/package.json +1 -1
  43. package/src/behaviors/drag-canvas.ts +32 -9
  44. package/src/behaviors/zoom-canvas.ts +2 -3
  45. package/src/plugins/contextmenu/index.ts +4 -2
  46. package/src/runtime/canvas.ts +6 -5
  47. package/src/runtime/viewport.ts +17 -4
  48. package/src/types/point.ts +6 -0
  49. package/src/utils/point.ts +6 -6
  50. package/src/version.ts +1 -1
@@ -1,7 +1,7 @@
1
1
  import { AABB } from '@antv/g';
2
2
  import { clamp, isNumber, pick } from '@antv/util';
3
3
  import { AnimationType, GraphEvent } from '../constants';
4
- import type { FitViewOptions, ID, Point, TransformOptions, ViewportAnimationEffectTiming } from '../types';
4
+ import type { FitViewOptions, ID, Point, TransformOptions, Vector2, ViewportAnimationEffectTiming } from '../types';
5
5
  import { getAnimationOptions } from '../utils/animation';
6
6
  import { getBBoxSize, getCombinedBBox } from '../utils/bbox';
7
7
  import { AnimateEvent, ViewportEvent, emit } from '../utils/event';
@@ -133,14 +133,24 @@ export class ViewportController {
133
133
  return clamp(mode === 'relative' ? currentZoom * scale : scale, ...zoomRange!);
134
134
  }
135
135
 
136
+ private transformResolver?: () => void;
137
+
136
138
  public async transform(options: TransformOptions, animation?: ViewportAnimationEffectTiming) {
137
139
  const { graph } = this.context;
138
- const { translate, rotate, scale } = options;
140
+ const { translate, rotate, scale, origin } = options;
139
141
  this.cancelAnimation();
140
142
 
141
- emit(graph, new ViewportEvent(GraphEvent.BEFORE_TRANSFORM, options));
142
143
  const _animation = this.getAnimation(animation);
143
144
 
145
+ // 针对缩放操作,且不涉及平移、旋转、中心点、动画时,直接调用 setZoomByViewportPoint
146
+ // For zoom operations, and no translation, rotation, center point, and animation involved, call setZoomByViewportPoint directly
147
+ if (!rotate && scale && !translate && origin && !_animation) {
148
+ this.camera.setZoomByViewportPoint(scale, origin as Vector2);
149
+ return;
150
+ }
151
+
152
+ emit(graph, new ViewportEvent(GraphEvent.BEFORE_TRANSFORM, options));
153
+
144
154
  const landmarkOptions: Parameters<typeof this.camera.createLandmark>[1] = {};
145
155
  if (translate) Object.assign(landmarkOptions, this.getTranslateOptions(options));
146
156
  if (isNumber(rotate)) Object.assign(landmarkOptions, this.getRotateOptions(options));
@@ -150,11 +160,13 @@ export class ViewportController {
150
160
  emit(graph, new AnimateEvent(GraphEvent.BEFORE_ANIMATE, AnimationType.TRANSFORM, null, options));
151
161
 
152
162
  return new Promise<void>((resolve) => {
163
+ this.transformResolver = resolve;
153
164
  this.camera.gotoLandmark(this.createLandmark(landmarkOptions), {
154
165
  ..._animation,
155
166
  onfinish: () => {
156
167
  emit(graph, new AnimateEvent(GraphEvent.AFTER_ANIMATE, AnimationType.TRANSFORM, null, options));
157
168
  emit(graph, new ViewportEvent(GraphEvent.AFTER_TRANSFORM, options));
169
+ this.transformResolver = undefined;
158
170
  resolve();
159
171
  },
160
172
  });
@@ -218,7 +230,7 @@ export class ViewportController {
218
230
  }
219
231
 
220
232
  private async focus(bbox: AABB, animation?: ViewportAnimationEffectTiming) {
221
- const { center } = this.getBBoxInViewport(bbox);
233
+ const center = this.context.graph.getViewportByCanvas(bbox.center);
222
234
  const canvasCenter = this.getCanvasCenter();
223
235
  const delta = subtract(canvasCenter, center);
224
236
  await this.transform({ mode: 'relative', translate: add(delta, this.paddingOffset) }, animation);
@@ -247,5 +259,6 @@ export class ViewportController {
247
259
  if (this.camera.landmarks?.length) {
248
260
  this.camera.cancelLandmarkAnimation();
249
261
  }
262
+ this.transformResolver?.();
250
263
  }
251
264
  }
@@ -1 +1,7 @@
1
1
  export type Point = [number, number] | [number, number, number] | Float32Array;
2
+
3
+ export type PointObject = {
4
+ x: number;
5
+ y: number;
6
+ z?: number;
7
+ };
@@ -1,5 +1,5 @@
1
- import type { AABB, PointLike } from '@antv/g';
2
- import type { Point } from '../types';
1
+ import type { AABB } from '@antv/g';
2
+ import type { Point, PointObject } from '../types';
3
3
  import { getBBoxHeight, getBBoxWidth } from './bbox';
4
4
  import type { LineSegment } from './line';
5
5
  import { getLinesIntersection, isLinesParallel } from './line';
@@ -12,8 +12,8 @@ import { add, distance, divide, normalize, subtract, toVector2 } from './vector'
12
12
  * @param point - <zh/> 对象坐标 | <en/> object coordinates
13
13
  * @returns <zh/> 数组坐标 | <en/> array coordinates
14
14
  */
15
- export function parsePoint(point: PointLike): Point {
16
- return [point.x, point.y];
15
+ export function parsePoint(point: PointObject): Point {
16
+ return [point.x, point.y, point.z ?? 0];
17
17
  }
18
18
 
19
19
  /**
@@ -23,8 +23,8 @@ export function parsePoint(point: PointLike): Point {
23
23
  * @param point - <zh/> 数组坐标 | <en/> array coordinates
24
24
  * @returns <zh/> 对象坐标 | <en/> object coordinates
25
25
  */
26
- export function toPointObject(point: Point): PointLike {
27
- return { x: point[0], y: point[1] };
26
+ export function toPointObject(point: Point): PointObject {
27
+ return { x: point[0], y: point[1], z: point[2] ?? 0 };
28
28
  }
29
29
 
30
30
  /**
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '5.0.6';
1
+ export const version = '5.0.7';