@antv/g6 5.0.4 → 5.0.5
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.
- package/dist/g6.min.js +2 -2
- package/dist/lib/behaviors/click-select.d.ts +17 -0
- package/dist/lib/constants/events/graph.d.ts +12 -0
- package/dist/lib/exports.d.ts +2 -0
- package/dist/lib/runtime/viewport.d.ts +3 -5
- package/dist/lib/utils/event/events.d.ts +1 -1
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/click-select.d.ts +17 -0
- package/esm/behaviors/click-select.js +35 -4
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/constants/events/graph.d.ts +12 -0
- package/esm/constants/events/graph.js +12 -0
- package/esm/constants/events/graph.js.map +1 -1
- package/esm/exports.d.ts +2 -0
- package/esm/exports.js +1 -0
- package/esm/exports.js.map +1 -1
- package/esm/runtime/behavior.js +5 -0
- package/esm/runtime/behavior.js.map +1 -1
- package/esm/runtime/data.js +2 -0
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/layout.js +4 -1
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/viewport.d.ts +3 -5
- package/esm/runtime/viewport.js +18 -49
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/utils/animation.js +6 -1
- package/esm/utils/animation.js.map +1 -1
- package/esm/utils/event/events.d.ts +1 -1
- package/esm/utils/event/events.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/click-select.d.ts +17 -0
- package/lib/behaviors/click-select.js +33 -2
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/constants/events/graph.d.ts +12 -0
- package/lib/constants/events/graph.js +12 -0
- package/lib/constants/events/graph.js.map +1 -1
- package/lib/exports.d.ts +2 -0
- package/lib/exports.js +3 -1
- package/lib/exports.js.map +1 -1
- package/lib/runtime/behavior.js +5 -0
- package/lib/runtime/behavior.js.map +1 -1
- package/lib/runtime/data.js +2 -0
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/layout.js +4 -1
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/viewport.d.ts +3 -5
- package/lib/runtime/viewport.js +18 -49
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/utils/animation.js +6 -1
- package/lib/utils/animation.js.map +1 -1
- package/lib/utils/event/events.d.ts +1 -1
- package/lib/utils/event/events.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/behaviors/click-select.ts +35 -4
- package/src/constants/events/graph.ts +12 -0
- package/src/exports.ts +2 -0
- package/src/runtime/behavior.ts +5 -0
- package/src/runtime/data.ts +1 -0
- package/src/runtime/layout.ts +5 -2
- package/src/runtime/viewport.ts +17 -48
- package/src/utils/animation.ts +7 -1
- package/src/utils/event/events.ts +2 -0
- package/src/version.ts +1 -1
package/src/runtime/viewport.ts
CHANGED
|
@@ -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,
|
|
4
|
+
import type { FitViewOptions, ID, Point, TransformOptions, 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';
|
|
@@ -96,28 +96,14 @@ export class ViewportController {
|
|
|
96
96
|
return this.camera.getRoll();
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
private
|
|
100
|
-
const currentZoom = this.getZoom();
|
|
101
|
-
const { camera } = this;
|
|
102
|
-
const { mode, translate = [] } = options;
|
|
103
|
-
const [x = 0, y = 0] = translate;
|
|
104
|
-
const [cx = 0, cy = 0] = this.getCanvasCenter();
|
|
105
|
-
const [px, py] = camera.getPosition();
|
|
106
|
-
|
|
107
|
-
const delta = divide([-x, -y], currentZoom);
|
|
108
|
-
|
|
109
|
-
const value = mode === 'relative' ? delta : add([cx - px, cy - py], delta);
|
|
110
|
-
return value as [number, number];
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private getAnimationTranslateArgs(options: TransformOptions) {
|
|
99
|
+
private getTranslateOptions(options: TransformOptions) {
|
|
114
100
|
const { camera } = this;
|
|
115
101
|
const { mode, translate = [] } = options;
|
|
116
102
|
const currentZoom = this.getZoom();
|
|
117
103
|
|
|
118
104
|
const position = camera.getPosition();
|
|
119
105
|
const focalPoint = camera.getFocalPoint();
|
|
120
|
-
const
|
|
106
|
+
const [cx, cy] = this.getCanvasCenter();
|
|
121
107
|
|
|
122
108
|
const [x = 0, y = 0, z = 0] = translate;
|
|
123
109
|
|
|
@@ -129,23 +115,18 @@ export class ViewportController {
|
|
|
129
115
|
focalPoint: add(focalPoint, delta),
|
|
130
116
|
}
|
|
131
117
|
: {
|
|
132
|
-
position: add(
|
|
133
|
-
focalPoint: add(focalPoint, delta),
|
|
118
|
+
position: add([cx, cy, position[2]], delta),
|
|
119
|
+
focalPoint: add([cx, cy, focalPoint[2]], delta),
|
|
134
120
|
};
|
|
135
121
|
}
|
|
136
122
|
|
|
137
|
-
private
|
|
138
|
-
const { mode, rotate = 0 } = options;
|
|
139
|
-
return mode === 'relative' ? rotate : rotate - this.camera.getRoll();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
private getAnimationRotateArgs(options: TransformOptions) {
|
|
123
|
+
private getRotateOptions(options: TransformOptions) {
|
|
143
124
|
const { mode, rotate = 0 } = options;
|
|
144
125
|
const roll = mode === 'relative' ? this.camera.getRoll() + rotate : rotate;
|
|
145
126
|
return { roll };
|
|
146
127
|
}
|
|
147
128
|
|
|
148
|
-
private
|
|
129
|
+
private getZoomOptions(options: TransformOptions) {
|
|
149
130
|
const { zoomRange } = this.context.options;
|
|
150
131
|
const currentZoom = this.camera.getZoom();
|
|
151
132
|
const { mode, scale = 1 } = options;
|
|
@@ -153,20 +134,19 @@ export class ViewportController {
|
|
|
153
134
|
}
|
|
154
135
|
|
|
155
136
|
public async transform(options: TransformOptions, animation?: ViewportAnimationEffectTiming) {
|
|
156
|
-
const { camera } = this;
|
|
157
137
|
const { graph } = this.context;
|
|
158
|
-
const { translate, rotate, scale
|
|
138
|
+
const { translate, rotate, scale } = options;
|
|
159
139
|
this.cancelAnimation();
|
|
160
140
|
|
|
161
141
|
emit(graph, new ViewportEvent(GraphEvent.BEFORE_TRANSFORM, options));
|
|
162
142
|
const _animation = this.getAnimation(animation);
|
|
163
143
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (isNumber(scale)) Object.assign(landmarkOptions, { zoom: this.getZoomArgs(options) });
|
|
144
|
+
const landmarkOptions: Parameters<typeof this.camera.createLandmark>[1] = {};
|
|
145
|
+
if (translate) Object.assign(landmarkOptions, this.getTranslateOptions(options));
|
|
146
|
+
if (isNumber(rotate)) Object.assign(landmarkOptions, this.getRotateOptions(options));
|
|
147
|
+
if (isNumber(scale)) Object.assign(landmarkOptions, { zoom: this.getZoomOptions(options) });
|
|
169
148
|
|
|
149
|
+
if (_animation) {
|
|
170
150
|
emit(graph, new AnimateEvent(GraphEvent.BEFORE_ANIMATE, AnimationType.TRANSFORM, null, options));
|
|
171
151
|
|
|
172
152
|
return new Promise<void>((resolve) => {
|
|
@@ -180,18 +160,9 @@ export class ViewportController {
|
|
|
180
160
|
});
|
|
181
161
|
});
|
|
182
162
|
} else {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (origin) camera.pan(origin[0] - x, origin[1] - y);
|
|
187
|
-
const value = this.getRotateArgs(options);
|
|
188
|
-
camera.rotate(0, 0, value);
|
|
189
|
-
if (origin) camera.pan(x - origin[0], y - origin[1]);
|
|
190
|
-
}
|
|
191
|
-
if (isNumber(scale)) {
|
|
192
|
-
const targetZoom = this.getZoomArgs(options);
|
|
193
|
-
camera.setZoomByViewportPoint(targetZoom, origin as Vector2);
|
|
194
|
-
}
|
|
163
|
+
this.camera.gotoLandmark(this.createLandmark(landmarkOptions), {
|
|
164
|
+
duration: 0,
|
|
165
|
+
});
|
|
195
166
|
|
|
196
167
|
emit(graph, new ViewportEvent(GraphEvent.AFTER_TRANSFORM, options));
|
|
197
168
|
}
|
|
@@ -227,9 +198,7 @@ export class ViewportController {
|
|
|
227
198
|
scale,
|
|
228
199
|
translate: add(
|
|
229
200
|
subtract(this.getCanvasCenter(), this.getBBoxInViewport(canvasBounds).center),
|
|
230
|
-
|
|
231
|
-
// When animation is enabled, zoom and translate are performed simultaneously, so they need to be divided by the scaling ratio
|
|
232
|
-
_animation ? divide(this.paddingOffset, scale) : this.paddingOffset,
|
|
201
|
+
divide(this.paddingOffset, scale),
|
|
233
202
|
),
|
|
234
203
|
},
|
|
235
204
|
_animation,
|
package/src/utils/animation.ts
CHANGED
|
@@ -86,13 +86,19 @@ export function preprocessKeyframes(keyframes: Keyframe[]): Keyframe[] {
|
|
|
86
86
|
|
|
87
87
|
// 将 PropertyIndexedKeyframes 转化为 Keyframe 格式
|
|
88
88
|
// convert PropertyIndexedKeyframes to Keyframe format
|
|
89
|
-
|
|
89
|
+
const output = Object.entries(propertyIndexedKeyframes).reduce((acc, [key, values]) => {
|
|
90
90
|
values.forEach((value, index) => {
|
|
91
91
|
if (!acc[index]) acc[index] = { [key]: value };
|
|
92
92
|
else acc[index][key] = value;
|
|
93
93
|
});
|
|
94
94
|
return acc;
|
|
95
95
|
}, [] as Keyframe[]);
|
|
96
|
+
|
|
97
|
+
// 如果处理后所有的属性都被过滤掉,则添加一个没有实际作用的属性用于触发动画
|
|
98
|
+
// If all properties are filtered out after processing, add a property that has no actual effect to trigger the animation
|
|
99
|
+
if (keyframes.length !== 0 && output.length === 0) output.push(...[{ _: 0 }, { _: 0 }]);
|
|
100
|
+
|
|
101
|
+
return output;
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
/**
|
|
@@ -23,6 +23,8 @@ export class GraphLifeCycleEvent extends BaseEvent implements IGraphLifeCycleEve
|
|
|
23
23
|
| GraphEvent.AFTER_DRAW
|
|
24
24
|
| GraphEvent.BEFORE_LAYOUT
|
|
25
25
|
| GraphEvent.AFTER_LAYOUT
|
|
26
|
+
| GraphEvent.BEFORE_STAGE_LAYOUT
|
|
27
|
+
| GraphEvent.AFTER_STAGE_LAYOUT
|
|
26
28
|
| GraphEvent.BEFORE_SIZE_CHANGE
|
|
27
29
|
| GraphEvent.AFTER_SIZE_CHANGE
|
|
28
30
|
| GraphEvent.BATCH_START
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.0.
|
|
1
|
+
export const version = '5.0.5';
|