@antv/g6 5.0.6 → 5.0.8
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 +8 -16
- package/dist/lib/behaviors/drag-canvas.d.ts +4 -0
- package/dist/lib/elements/base-element.d.ts +5 -4
- package/dist/lib/plugins/fullscreen/index.d.ts +2 -0
- package/dist/lib/registry/index.d.ts +5 -1
- package/dist/lib/runtime/animation.d.ts +7 -0
- package/dist/lib/runtime/canvas.d.ts +27 -38
- package/dist/lib/runtime/element.d.ts +1 -1
- package/dist/lib/runtime/graph.d.ts +1 -17
- package/dist/lib/runtime/viewport.d.ts +1 -0
- package/dist/lib/types/point.d.ts +5 -0
- package/dist/lib/utils/point.d.ts +4 -4
- package/dist/lib/utils/print.d.ts +15 -0
- package/dist/lib/utils/shortcut.d.ts +1 -0
- package/dist/lib/utils/state.d.ts +9 -0
- package/dist/lib/version.d.ts +1 -1
- package/esm/behaviors/brush-select.js +1 -2
- package/esm/behaviors/brush-select.js.map +1 -1
- package/esm/behaviors/click-select.d.ts +8 -16
- package/esm/behaviors/click-select.js +108 -90
- package/esm/behaviors/click-select.js.map +1 -1
- package/esm/behaviors/drag-canvas.d.ts +4 -0
- package/esm/behaviors/drag-canvas.js +29 -9
- package/esm/behaviors/drag-canvas.js.map +1 -1
- package/esm/behaviors/drag-element-force.js +2 -1
- package/esm/behaviors/drag-element-force.js.map +1 -1
- package/esm/behaviors/drag-element.js +1 -2
- package/esm/behaviors/drag-element.js.map +1 -1
- package/esm/behaviors/zoom-canvas.js.map +1 -1
- package/esm/elements/base-element.d.ts +5 -4
- package/esm/elements/base-element.js +3 -0
- package/esm/elements/base-element.js.map +1 -1
- package/esm/elements/combos/base-combo.js +2 -2
- package/esm/elements/combos/base-combo.js.map +1 -1
- package/esm/elements/nodes/html.js +3 -5
- package/esm/elements/nodes/html.js.map +1 -1
- package/esm/elements/shapes/base-shape.js +27 -3
- package/esm/elements/shapes/base-shape.js.map +1 -1
- package/esm/plugins/contextmenu/index.js +5 -2
- package/esm/plugins/contextmenu/index.js.map +1 -1
- package/esm/plugins/fullscreen/index.d.ts +2 -0
- package/esm/plugins/fullscreen/index.js +15 -2
- package/esm/plugins/fullscreen/index.js.map +1 -1
- package/esm/registry/extension/index.js +2 -1
- package/esm/registry/extension/index.js.map +1 -1
- package/esm/registry/index.d.ts +5 -1
- package/esm/registry/index.js +8 -3
- package/esm/registry/index.js.map +1 -1
- package/esm/runtime/animation.d.ts +7 -0
- package/esm/runtime/animation.js +17 -0
- package/esm/runtime/animation.js.map +1 -1
- package/esm/runtime/canvas.d.ts +27 -38
- package/esm/runtime/canvas.js +128 -175
- package/esm/runtime/canvas.js.map +1 -1
- package/esm/runtime/data.js +4 -3
- package/esm/runtime/data.js.map +1 -1
- package/esm/runtime/element.d.ts +1 -1
- package/esm/runtime/element.js +2 -1
- package/esm/runtime/element.js.map +1 -1
- package/esm/runtime/graph.d.ts +1 -17
- package/esm/runtime/graph.js +8 -34
- package/esm/runtime/graph.js.map +1 -1
- package/esm/runtime/layout.js +5 -2
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/viewport.d.ts +1 -0
- package/esm/runtime/viewport.js +13 -3
- package/esm/runtime/viewport.js.map +1 -1
- package/esm/types/point.d.ts +5 -0
- package/esm/utils/animation.js +9 -3
- package/esm/utils/animation.js.map +1 -1
- package/esm/utils/id.js +2 -1
- package/esm/utils/id.js.map +1 -1
- package/esm/utils/layout.js +9 -1
- package/esm/utils/layout.js.map +1 -1
- package/esm/utils/palette.js +2 -1
- package/esm/utils/palette.js.map +1 -1
- package/esm/utils/point.d.ts +4 -4
- package/esm/utils/point.js +2 -2
- package/esm/utils/point.js.map +1 -1
- package/esm/utils/print.d.ts +15 -0
- package/esm/utils/print.js +28 -0
- package/esm/utils/print.js.map +1 -0
- package/esm/utils/shortcut.d.ts +1 -0
- package/esm/utils/shortcut.js +7 -0
- package/esm/utils/shortcut.js.map +1 -1
- package/esm/utils/state.d.ts +9 -0
- package/esm/utils/state.js +11 -0
- package/esm/utils/state.js.map +1 -0
- package/esm/utils/theme.js +5 -1
- package/esm/utils/theme.js.map +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/lib/behaviors/brush-select.js +1 -2
- package/lib/behaviors/brush-select.js.map +1 -1
- package/lib/behaviors/click-select.d.ts +8 -16
- package/lib/behaviors/click-select.js +106 -88
- package/lib/behaviors/click-select.js.map +1 -1
- package/lib/behaviors/drag-canvas.d.ts +4 -0
- package/lib/behaviors/drag-canvas.js +28 -8
- package/lib/behaviors/drag-canvas.js.map +1 -1
- package/lib/behaviors/drag-element-force.js +2 -1
- package/lib/behaviors/drag-element-force.js.map +1 -1
- package/lib/behaviors/drag-element.js +1 -2
- package/lib/behaviors/drag-element.js.map +1 -1
- package/lib/behaviors/zoom-canvas.js.map +1 -1
- package/lib/elements/base-element.d.ts +5 -4
- package/lib/elements/base-element.js +3 -0
- package/lib/elements/base-element.js.map +1 -1
- package/lib/elements/combos/base-combo.js +2 -2
- package/lib/elements/combos/base-combo.js.map +1 -1
- package/lib/elements/nodes/html.js +3 -5
- package/lib/elements/nodes/html.js.map +1 -1
- package/lib/elements/shapes/base-shape.js +27 -3
- package/lib/elements/shapes/base-shape.js.map +1 -1
- package/lib/plugins/contextmenu/index.js +5 -2
- package/lib/plugins/contextmenu/index.js.map +1 -1
- package/lib/plugins/fullscreen/index.d.ts +2 -0
- package/lib/plugins/fullscreen/index.js +15 -2
- package/lib/plugins/fullscreen/index.js.map +1 -1
- package/lib/registry/extension/index.js +2 -1
- package/lib/registry/extension/index.js.map +1 -1
- package/lib/registry/index.d.ts +5 -1
- package/lib/registry/index.js +8 -3
- package/lib/registry/index.js.map +1 -1
- package/lib/runtime/animation.d.ts +7 -0
- package/lib/runtime/animation.js +17 -0
- package/lib/runtime/animation.js.map +1 -1
- package/lib/runtime/canvas.d.ts +27 -38
- package/lib/runtime/canvas.js +127 -174
- package/lib/runtime/canvas.js.map +1 -1
- package/lib/runtime/data.js +4 -3
- package/lib/runtime/data.js.map +1 -1
- package/lib/runtime/element.d.ts +1 -1
- package/lib/runtime/element.js +2 -1
- package/lib/runtime/element.js.map +1 -1
- package/lib/runtime/graph.d.ts +1 -17
- package/lib/runtime/graph.js +8 -34
- package/lib/runtime/graph.js.map +1 -1
- package/lib/runtime/layout.js +5 -2
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/viewport.d.ts +1 -0
- package/lib/runtime/viewport.js +13 -3
- package/lib/runtime/viewport.js.map +1 -1
- package/lib/types/point.d.ts +5 -0
- package/lib/utils/animation.js +8 -2
- package/lib/utils/animation.js.map +1 -1
- package/lib/utils/id.js +2 -1
- package/lib/utils/id.js.map +1 -1
- package/lib/utils/layout.js +9 -1
- package/lib/utils/layout.js.map +1 -1
- package/lib/utils/palette.js +2 -1
- package/lib/utils/palette.js.map +1 -1
- package/lib/utils/point.d.ts +4 -4
- package/lib/utils/point.js +2 -2
- package/lib/utils/point.js.map +1 -1
- package/lib/utils/print.d.ts +15 -0
- package/lib/utils/print.js +32 -0
- package/lib/utils/print.js.map +1 -0
- package/lib/utils/shortcut.d.ts +1 -0
- package/lib/utils/shortcut.js +7 -0
- package/lib/utils/shortcut.js.map +1 -1
- package/lib/utils/state.d.ts +9 -0
- package/lib/utils/state.js +14 -0
- package/lib/utils/state.js.map +1 -0
- package/lib/utils/theme.js +5 -1
- package/lib/utils/theme.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +8 -8
- package/src/behaviors/brush-select.ts +1 -2
- package/src/behaviors/click-select.ts +117 -88
- package/src/behaviors/drag-canvas.ts +32 -9
- package/src/behaviors/drag-element-force.ts +2 -1
- package/src/behaviors/drag-element.ts +1 -2
- package/src/behaviors/zoom-canvas.ts +2 -3
- package/src/elements/base-element.ts +8 -4
- package/src/elements/combos/base-combo.ts +2 -2
- package/src/elements/nodes/html.ts +3 -7
- package/src/elements/shapes/base-shape.ts +30 -3
- package/src/global.d.ts +12 -0
- package/src/plugins/contextmenu/index.ts +5 -2
- package/src/plugins/fullscreen/index.ts +18 -2
- package/src/registry/extension/index.ts +2 -1
- package/src/registry/index.ts +8 -2
- package/src/runtime/animation.ts +21 -0
- package/src/runtime/canvas.ts +140 -208
- package/src/runtime/data.ts +4 -3
- package/src/runtime/element.ts +3 -2
- package/src/runtime/graph.ts +8 -38
- package/src/runtime/layout.ts +5 -2
- package/src/runtime/viewport.ts +18 -5
- package/src/types/point.ts +6 -0
- package/src/utils/animation.ts +9 -2
- package/src/utils/id.ts +2 -1
- package/src/utils/layout.ts +7 -1
- package/src/utils/palette.ts +2 -1
- package/src/utils/point.ts +6 -6
- package/src/utils/print.ts +30 -0
- package/src/utils/shortcut.ts +9 -0
- package/src/utils/state.ts +12 -0
- package/src/utils/theme.ts +6 -1
- package/src/version.ts +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { isFunction } from '@antv/util';
|
|
2
|
-
import { CanvasEvent, CommonEvent
|
|
2
|
+
import { CanvasEvent, CommonEvent } from '../constants';
|
|
3
3
|
import { ELEMENT_TYPES } from '../constants/element';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
|
-
import type { ElementType, ID, IPointerEvent, State } from '../types';
|
|
6
|
-
import
|
|
7
|
-
import { idOf, idsOf } from '../utils/id';
|
|
5
|
+
import type { Element, ElementType, ID, IPointerEvent, State } from '../types';
|
|
6
|
+
import { idOf } from '../utils/id';
|
|
8
7
|
import { getElementNthDegreeIds } from '../utils/relation';
|
|
9
8
|
import type { ShortcutKey } from '../utils/shortcut';
|
|
10
9
|
import { Shortcut } from '../utils/shortcut';
|
|
10
|
+
import { statesOf } from '../utils/state';
|
|
11
11
|
import type { BaseBehaviorOptions } from './base-behavior';
|
|
12
12
|
import { BaseBehavior } from './base-behavior';
|
|
13
13
|
|
|
@@ -108,10 +108,6 @@ export interface ClickSelectOptions extends BaseBehaviorOptions {
|
|
|
108
108
|
* <en/> When the mouse clicks on an element, you can activate the state of the element, such as selecting nodes or edges. When the degree is 1, clicking on a node will highlight the current node and its directly adjacent nodes and edges.
|
|
109
109
|
*/
|
|
110
110
|
export class ClickSelect extends BaseBehavior<ClickSelectOptions> {
|
|
111
|
-
private select: Set<ID> = new Set<ID>();
|
|
112
|
-
|
|
113
|
-
private neighbor: Set<ID> = new Set<ID>();
|
|
114
|
-
|
|
115
111
|
private shortcut: Shortcut;
|
|
116
112
|
|
|
117
113
|
static defaultOptions: Partial<ClickSelectOptions> = {
|
|
@@ -138,20 +134,17 @@ export class ClickSelect extends BaseBehavior<ClickSelectOptions> {
|
|
|
138
134
|
graph.on(`${type}:${CommonEvent.CLICK}`, this.onClickSelect);
|
|
139
135
|
});
|
|
140
136
|
graph.on(CanvasEvent.CLICK, this.onClickCanvas);
|
|
141
|
-
graph.on(GraphEvent.AFTER_ELEMENT_UPDATE, this.syncState);
|
|
142
137
|
}
|
|
143
138
|
|
|
144
|
-
private onClickSelect = (event: IPointerEvent) => {
|
|
139
|
+
private onClickSelect = async (event: IPointerEvent<Element>) => {
|
|
145
140
|
if (!this.validate(event)) return;
|
|
146
|
-
this.updateState(event);
|
|
141
|
+
await this.updateState(event);
|
|
147
142
|
this.options.onClick?.(event);
|
|
148
143
|
};
|
|
149
144
|
|
|
150
|
-
private onClickCanvas = (event: IPointerEvent) => {
|
|
145
|
+
private onClickCanvas = async (event: IPointerEvent) => {
|
|
151
146
|
if (!this.validate(event)) return;
|
|
152
|
-
this.
|
|
153
|
-
this.select.clear();
|
|
154
|
-
this.neighbor.clear();
|
|
147
|
+
await this.clearState();
|
|
155
148
|
this.options.onClick?.(event);
|
|
156
149
|
};
|
|
157
150
|
|
|
@@ -160,96 +153,135 @@ export class ClickSelect extends BaseBehavior<ClickSelectOptions> {
|
|
|
160
153
|
return multiple && this.shortcut.match(trigger);
|
|
161
154
|
}
|
|
162
155
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
156
|
+
private getNeighborIds(event: IPointerEvent<Element>) {
|
|
157
|
+
const { target, targetType } = event;
|
|
158
|
+
const { graph } = this.context;
|
|
159
|
+
const { degree } = this.options;
|
|
160
|
+
return getElementNthDegreeIds(
|
|
161
|
+
graph,
|
|
162
|
+
targetType as ElementType,
|
|
163
|
+
target.id,
|
|
164
|
+
typeof degree === 'function' ? degree(event) : degree,
|
|
165
|
+
).filter((id) => id !== target.id);
|
|
166
|
+
}
|
|
169
167
|
|
|
170
|
-
private async updateState(event: IPointerEvent) {
|
|
171
|
-
const { state:
|
|
172
|
-
if (!
|
|
168
|
+
private async updateState(event: IPointerEvent<Element>) {
|
|
169
|
+
const { state: selectState, unselectedState, neighborState, animation } = this.options;
|
|
170
|
+
if (!selectState && !neighborState && !unselectedState) return;
|
|
173
171
|
|
|
174
|
-
const target = event
|
|
172
|
+
const { target } = event;
|
|
175
173
|
const { graph } = this.context;
|
|
176
174
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (datum?.states?.includes(select)) {
|
|
181
|
-
this.select.delete(id);
|
|
182
|
-
} else {
|
|
183
|
-
if (!this.isMultipleSelect) this.select.clear();
|
|
184
|
-
this.select.add(id);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
// 点击了空白处 / click canvas
|
|
188
|
-
else this.select.clear();
|
|
175
|
+
const datum = graph.getElementData(target.id);
|
|
176
|
+
|
|
177
|
+
const type = statesOf(datum).includes(selectState) ? 'unselect' : 'select';
|
|
189
178
|
|
|
190
179
|
const states: Record<ID, State[]> = {};
|
|
191
180
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
181
|
+
const isMultipleSelect = this.isMultipleSelect;
|
|
182
|
+
|
|
183
|
+
const click = [target.id];
|
|
184
|
+
const neighbor = this.getNeighborIds(event);
|
|
185
|
+
|
|
186
|
+
if (!isMultipleSelect) {
|
|
187
|
+
if (type === 'select') {
|
|
188
|
+
Object.assign(states, this.getClearStates(!!unselectedState));
|
|
189
|
+
const addState = (list: ID[], state: State) => {
|
|
190
|
+
list.forEach((id) => {
|
|
191
|
+
if (!states[id]) states[id] = [];
|
|
192
|
+
states[id].push(state);
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
addState(click, selectState);
|
|
196
|
+
addState(neighbor, neighborState);
|
|
197
|
+
if (unselectedState) {
|
|
198
|
+
Object.keys(states).forEach((id) => {
|
|
199
|
+
if (!click.includes(id) && !neighbor.includes(id)) states[id].push(unselectedState);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
} else Object.assign(states, this.getClearStates());
|
|
203
|
+
} else {
|
|
204
|
+
Object.assign(states, this.getDataStates());
|
|
205
|
+
|
|
206
|
+
if (type === 'select') {
|
|
207
|
+
const addState = (list: ID[], state: State) => {
|
|
208
|
+
list.forEach((id) => {
|
|
209
|
+
const datum = graph.getElementData(id);
|
|
210
|
+
const dataStatesSet = new Set(statesOf(datum));
|
|
211
|
+
dataStatesSet.add(state);
|
|
212
|
+
dataStatesSet.delete(unselectedState);
|
|
213
|
+
states[id] = Array.from(dataStatesSet);
|
|
214
|
+
});
|
|
215
|
+
};
|
|
199
216
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
217
|
+
addState(click, selectState);
|
|
218
|
+
addState(neighbor, neighborState);
|
|
219
|
+
if (unselectedState) {
|
|
220
|
+
Object.keys(states).forEach((id) => {
|
|
221
|
+
const _states = states[id];
|
|
222
|
+
if (
|
|
223
|
+
!_states.includes(selectState) &&
|
|
224
|
+
!_states.includes(neighborState) &&
|
|
225
|
+
!_states.includes(unselectedState)
|
|
226
|
+
) {
|
|
227
|
+
states[id].push(unselectedState);
|
|
228
|
+
}
|
|
208
229
|
});
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
const targetState = states[target.id];
|
|
233
|
+
states[target.id] = targetState.filter((s) => s !== selectState && s !== neighborState);
|
|
234
|
+
if (!targetState.includes(unselectedState)) states[target.id].push(unselectedState);
|
|
235
|
+
neighbor.forEach((id) => {
|
|
236
|
+
states[id] = states[id].filter((s) => s !== neighborState);
|
|
237
|
+
if (!states[id].includes(selectState)) states[id].push(unselectedState);
|
|
209
238
|
});
|
|
210
239
|
}
|
|
211
|
-
const exclude = [select, unselect];
|
|
212
|
-
neighborIds.forEach((id) => {
|
|
213
|
-
const state = graph.getElementState(id);
|
|
214
|
-
states[id] = uniq([...state.filter((s) => !exclude.includes(s)), neighbor]);
|
|
215
|
-
});
|
|
216
240
|
}
|
|
217
241
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
242
|
+
await graph.setElementState(states, animation);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
private getDataStates() {
|
|
246
|
+
const { graph } = this.context;
|
|
247
|
+
const { nodes, edges, combos } = graph.getData();
|
|
248
|
+
|
|
249
|
+
const states: Record<ID, State[]> = {};
|
|
250
|
+
[...nodes, ...edges, ...combos].forEach((data) => {
|
|
251
|
+
states[idOf(data)] = statesOf(data);
|
|
228
252
|
});
|
|
229
253
|
|
|
230
|
-
|
|
231
|
-
await graph.setElementState(states, animation);
|
|
232
|
-
this.updating = false;
|
|
254
|
+
return states;
|
|
233
255
|
}
|
|
234
256
|
|
|
235
257
|
/**
|
|
236
|
-
* <zh/>
|
|
258
|
+
* <zh/> 获取需要清除的状态
|
|
237
259
|
*
|
|
238
|
-
* <en/>
|
|
239
|
-
* @
|
|
240
|
-
* <zh/>
|
|
241
|
-
*
|
|
242
|
-
* <en/> Avoid inconsistency between this.select and the actual state after other operations update the state
|
|
243
|
-
* @param event - <zh/> 元素生命周期事件 | <en/> Element life cycle event
|
|
260
|
+
* <en/> Get the states that need to be cleared
|
|
261
|
+
* @param complete - <zh/> 是否返回所有状态 | <en/> Whether to return all states
|
|
262
|
+
* @returns - <zh/> 需要清除的状态 | <en/> States that need to be cleared
|
|
244
263
|
*/
|
|
245
|
-
private
|
|
246
|
-
|
|
247
|
-
const {
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
264
|
+
private getClearStates(complete = false) {
|
|
265
|
+
const { graph } = this.context;
|
|
266
|
+
const { state, unselectedState, neighborState } = this.options;
|
|
267
|
+
const statesToClear = new Set([state, unselectedState, neighborState]);
|
|
268
|
+
const { nodes, edges, combos } = graph.getData();
|
|
269
|
+
|
|
270
|
+
const states: Record<ID, State[]> = {};
|
|
271
|
+
[...nodes, ...edges, ...combos].forEach((data) => {
|
|
272
|
+
const datumStates = statesOf(data);
|
|
273
|
+
const newStates = datumStates.filter((s) => !statesToClear.has(s));
|
|
274
|
+
if (complete) states[idOf(data)] = newStates;
|
|
275
|
+
else if (newStates.length !== datumStates.length) states[idOf(data)] = newStates;
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
return states;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private async clearState() {
|
|
282
|
+
const { graph } = this.context;
|
|
283
|
+
await graph.setElementState(this.getClearStates(), this.options.animation);
|
|
284
|
+
}
|
|
253
285
|
|
|
254
286
|
private validate(event: IPointerEvent) {
|
|
255
287
|
if (this.destroyed) return false;
|
|
@@ -265,7 +297,6 @@ export class ClickSelect extends BaseBehavior<ClickSelectOptions> {
|
|
|
265
297
|
graph.off(`${type}:${CommonEvent.CLICK}`, this.onClickSelect);
|
|
266
298
|
});
|
|
267
299
|
graph.off(CanvasEvent.CLICK, this.onClickCanvas);
|
|
268
|
-
graph.off(GraphEvent.AFTER_ELEMENT_UPDATE, this.syncState);
|
|
269
300
|
}
|
|
270
301
|
|
|
271
302
|
public destroy() {
|
|
@@ -273,5 +304,3 @@ export class ClickSelect extends BaseBehavior<ClickSelectOptions> {
|
|
|
273
304
|
super.destroy();
|
|
274
305
|
}
|
|
275
306
|
}
|
|
276
|
-
|
|
277
|
-
const uniq = <T>(array: T[]): T[] => Array.from(new Set(array));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Cursor } from '@antv/g';
|
|
2
|
-
import { isFunction, isObject } from '@antv/util';
|
|
2
|
+
import { debounce, isFunction, isObject } from '@antv/util';
|
|
3
3
|
import { CanvasEvent } from '../constants';
|
|
4
4
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
5
|
import type { IKeyboardEvent, IPointerEvent, Vector2, ViewportAnimationEffectTiming } from '../types';
|
|
@@ -76,7 +76,6 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
76
76
|
|
|
77
77
|
this.bindEvents();
|
|
78
78
|
this.defaultCursor = this.context.canvas.getConfig().cursor || 'default';
|
|
79
|
-
context.canvas.setCursor('grab');
|
|
80
79
|
}
|
|
81
80
|
|
|
82
81
|
/**
|
|
@@ -97,7 +96,6 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
97
96
|
const { graph } = this.context;
|
|
98
97
|
|
|
99
98
|
if (isObject(trigger)) {
|
|
100
|
-
graph.off(CanvasEvent.DRAG, this.onDrag);
|
|
101
99
|
const { up = [], down = [], left = [], right = [] } = trigger;
|
|
102
100
|
|
|
103
101
|
this.shortcut.bind(up, (event) => this.onTranslate([0, 1], event));
|
|
@@ -105,24 +103,46 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
105
103
|
this.shortcut.bind(left, (event) => this.onTranslate([1, 0], event));
|
|
106
104
|
this.shortcut.bind(right, (event) => this.onTranslate([-1, 0], event));
|
|
107
105
|
} else {
|
|
106
|
+
graph.on(CanvasEvent.DRAG_START, this.onDragStart);
|
|
108
107
|
graph.on(CanvasEvent.DRAG, this.onDrag);
|
|
108
|
+
graph.on(CanvasEvent.DRAG_END, this.onDragEnd);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
private
|
|
112
|
+
private isDragging = false;
|
|
113
|
+
|
|
114
|
+
private onDragStart = (event: IPointerEvent) => {
|
|
113
115
|
if (!this.validate(event)) return;
|
|
114
|
-
if (event.targetType
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
if (event.targetType !== 'canvas') return;
|
|
117
|
+
this.isDragging = true;
|
|
118
|
+
this.context.canvas.setCursor('grabbing');
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
private onDrag = (event: IPointerEvent) => {
|
|
122
|
+
if (!this.isDragging) return;
|
|
123
|
+
const { x, y } = event.movement;
|
|
124
|
+
if ((x | y) !== 0) {
|
|
125
|
+
this.translate([x, y], false);
|
|
117
126
|
}
|
|
118
127
|
};
|
|
119
128
|
|
|
129
|
+
private onDragEnd = () => {
|
|
130
|
+
this.isDragging = false;
|
|
131
|
+
this.context.canvas.setCursor(this.defaultCursor);
|
|
132
|
+
this.options.onFinish?.();
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
private invokeOnFinish = debounce(() => {
|
|
136
|
+
this.options.onFinish?.();
|
|
137
|
+
}, 300);
|
|
138
|
+
|
|
120
139
|
private async onTranslate(value: Vector2, event: IPointerEvent | IKeyboardEvent) {
|
|
121
140
|
if (!this.validate(event)) return;
|
|
122
141
|
const { sensitivity } = this.options;
|
|
123
142
|
const delta = sensitivity * -1;
|
|
124
143
|
await this.translate(multiply(value, delta) as Vector2, this.options.animation);
|
|
125
|
-
|
|
144
|
+
|
|
145
|
+
this.invokeOnFinish();
|
|
126
146
|
}
|
|
127
147
|
|
|
128
148
|
/**
|
|
@@ -146,7 +166,10 @@ export class DragCanvas extends BaseBehavior<DragCanvasOptions> {
|
|
|
146
166
|
|
|
147
167
|
private unbindEvents() {
|
|
148
168
|
this.shortcut.unbindAll();
|
|
149
|
-
|
|
169
|
+
const { graph } = this.context;
|
|
170
|
+
graph.off(CanvasEvent.DRAG_START, this.onDragStart);
|
|
171
|
+
graph.off(CanvasEvent.DRAG, this.onDrag);
|
|
172
|
+
graph.off(CanvasEvent.DRAG_END, this.onDragEnd);
|
|
150
173
|
}
|
|
151
174
|
|
|
152
175
|
public destroy(): void {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ID, IElementDragEvent, Point } from '../types';
|
|
2
2
|
import { idOf } from '../utils/id';
|
|
3
3
|
import { getLayoutProperty, invokeLayoutMethod } from '../utils/layout';
|
|
4
|
+
import { print } from '../utils/print';
|
|
4
5
|
import { add } from '../utils/vector';
|
|
5
6
|
import type { DragElementOptions } from './drag-element';
|
|
6
7
|
import { DragElement } from './drag-element';
|
|
@@ -37,7 +38,7 @@ export class DragElementForce extends DragElement {
|
|
|
37
38
|
|
|
38
39
|
// 未使用力导布局 / The force layout is not used
|
|
39
40
|
if (!this.forceLayoutInstance) {
|
|
40
|
-
|
|
41
|
+
print.warn('DragElementForce only works with d3-force or d3-force-3d layout');
|
|
41
42
|
return false;
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -376,11 +376,10 @@ export class DragElement extends BaseBehavior<DragElementOptions> {
|
|
|
376
376
|
} else {
|
|
377
377
|
this.shadow = new Rect({
|
|
378
378
|
style: {
|
|
379
|
+
$layer: 'transient',
|
|
379
380
|
...shadowStyle,
|
|
380
381
|
...positionStyle,
|
|
381
382
|
pointerEvents: 'none',
|
|
382
|
-
// @ts-expect-error $layer is not in the type definition
|
|
383
|
-
$layer: 'transient',
|
|
384
383
|
},
|
|
385
384
|
});
|
|
386
385
|
this.context.canvas.appendChild(this.shadow);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { PointLike } from '@antv/g';
|
|
2
1
|
import { clamp, isArray, isFunction, isObject } from '@antv/util';
|
|
3
2
|
import { CommonEvent } from '../constants';
|
|
4
3
|
import type { RuntimeContext } from '../runtime/types';
|
|
5
|
-
import type { IKeyboardEvent, IWheelEvent, Point, ViewportAnimationEffectTiming } from '../types';
|
|
4
|
+
import type { IKeyboardEvent, IWheelEvent, Point, PointObject, ViewportAnimationEffectTiming } from '../types';
|
|
6
5
|
import { parsePoint } from '../utils/point';
|
|
7
6
|
import type { ShortcutKey } from '../utils/shortcut';
|
|
8
7
|
import { Shortcut } from '../utils/shortcut';
|
|
@@ -141,7 +140,7 @@ export class ZoomCanvas extends BaseBehavior<ZoomCanvasOptions> {
|
|
|
141
140
|
|
|
142
141
|
let origin: Point | undefined;
|
|
143
142
|
if ('viewport' in event) {
|
|
144
|
-
origin = parsePoint(event.viewport as
|
|
143
|
+
origin = parsePoint(event.viewport as PointObject);
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
const { sensitivity, onFinish } = this.options;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { IAnimation } from '@antv/g';
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import type { IAnimation } from '@antv/g';
|
|
2
|
+
import type { RuntimeContext } from '../runtime/types';
|
|
3
|
+
import type { BaseElementStyleProps, Keyframe } from '../types';
|
|
4
4
|
import { BaseShape } from './shapes';
|
|
5
5
|
|
|
6
|
-
export abstract class BaseElement<T extends
|
|
6
|
+
export abstract class BaseElement<T extends BaseElementStyleProps> extends BaseShape<T> {
|
|
7
|
+
protected get context(): RuntimeContext {
|
|
8
|
+
return this.attributes.context!;
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
protected get parsedAttributes() {
|
|
8
12
|
return this.attributes as Required<T>;
|
|
9
13
|
}
|
|
@@ -194,7 +194,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
protected getComboZIndex(attributes: Required<S>): number {
|
|
197
|
-
const ancestors =
|
|
197
|
+
const ancestors = this.context.model.getAncestorsData(this.id, COMBO_KEY) || [];
|
|
198
198
|
return ancestors.length;
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -231,7 +231,7 @@ export abstract class BaseCombo<S extends BaseComboStyleProps = BaseComboStylePr
|
|
|
231
231
|
Object.assign(this.style, comboStyle);
|
|
232
232
|
// Sync combo position to model
|
|
233
233
|
const { x, y } = comboStyle;
|
|
234
|
-
|
|
234
|
+
this.context.model.syncComboDatum({ id: this.id, style: { x, y } });
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
public render(attributes: Required<S>, container: Group = this) {
|
|
@@ -50,7 +50,7 @@ export class HTML extends BaseNode<HTMLStyleProps> {
|
|
|
50
50
|
private rootPointerEvent = new FederatedPointerEvent(null);
|
|
51
51
|
|
|
52
52
|
private get eventService() {
|
|
53
|
-
return this.
|
|
53
|
+
return this.context.canvas.context.eventService;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
private get events() {
|
|
@@ -105,7 +105,7 @@ export class HTML extends BaseNode<HTMLStyleProps> {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
private forwardEvents = (nativeEvent: PointerEvent) => {
|
|
108
|
-
const canvas = this.
|
|
108
|
+
const canvas = this.context.canvas;
|
|
109
109
|
const iCanvas = canvas.context.renderingContext.root!.ownerDocument!.defaultView!;
|
|
110
110
|
|
|
111
111
|
const normalizedEvents = this.normalizeToPointerEvent(nativeEvent, iCanvas);
|
|
@@ -232,11 +232,7 @@ export class HTML extends BaseNode<HTMLStyleProps> {
|
|
|
232
232
|
let x: number;
|
|
233
233
|
let y: number;
|
|
234
234
|
const { offsetX, offsetY, clientX, clientY } = nativeEvent;
|
|
235
|
-
if (
|
|
236
|
-
this.attributes.context?.canvas.main.context.config.supportsCSSTransform &&
|
|
237
|
-
!isNil(offsetX) &&
|
|
238
|
-
!isNil(offsetY)
|
|
239
|
-
) {
|
|
235
|
+
if (this.context.canvas.context.config.supportsCSSTransform && !isNil(offsetX) && !isNil(offsetY)) {
|
|
240
236
|
x = offsetX;
|
|
241
237
|
y = offsetY;
|
|
242
238
|
} else {
|
|
@@ -152,7 +152,10 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
const result = super.animate(keyframes, options);
|
|
155
|
-
if (result)
|
|
155
|
+
if (result) {
|
|
156
|
+
releaseAnimation(this, result);
|
|
157
|
+
animationMap.push(result);
|
|
158
|
+
}
|
|
156
159
|
|
|
157
160
|
if (Array.isArray(keyframes) && keyframes.length > 0) {
|
|
158
161
|
// 如果 keyframes 中仅存在 skippedAttrs 中的属性,则仅更新父元素属性(跳过子图形)
|
|
@@ -170,7 +173,10 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
170
173
|
method.call(this, { ...this.attributes, ...style }),
|
|
171
174
|
);
|
|
172
175
|
const result = shape.animate(preprocessKeyframes(subKeyframes), options);
|
|
173
|
-
if (result)
|
|
176
|
+
if (result) {
|
|
177
|
+
releaseAnimation(shape, result);
|
|
178
|
+
animationMap.push(result);
|
|
179
|
+
}
|
|
174
180
|
}
|
|
175
181
|
});
|
|
176
182
|
|
|
@@ -185,7 +191,10 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
185
191
|
const shape = shapeSet[key];
|
|
186
192
|
if (shape) {
|
|
187
193
|
const result = shape.animate(preprocessKeyframes(subKeyframes), options);
|
|
188
|
-
if (result)
|
|
194
|
+
if (result) {
|
|
195
|
+
releaseAnimation(shape, result);
|
|
196
|
+
animationMap.push(result);
|
|
197
|
+
}
|
|
189
198
|
}
|
|
190
199
|
});
|
|
191
200
|
}
|
|
@@ -217,3 +226,21 @@ export abstract class BaseShape<StyleProps extends BaseShapeStyleProps> extends
|
|
|
217
226
|
super.destroy();
|
|
218
227
|
}
|
|
219
228
|
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* <zh/> 释放动画
|
|
232
|
+
*
|
|
233
|
+
* <en/> Release animation
|
|
234
|
+
* @param target - <zh/> 目标对象 | <en/> target object
|
|
235
|
+
* @param animation - <zh/> 动画实例 | <en/> animation instance
|
|
236
|
+
* @description see: https://github.com/antvis/G/issues/1731
|
|
237
|
+
*/
|
|
238
|
+
function releaseAnimation(target: DisplayObject, animation: IAnimation) {
|
|
239
|
+
animation.oncancel = () => console.log('cancel');
|
|
240
|
+
animation?.finished.then(() => {
|
|
241
|
+
// @ts-expect-error private property
|
|
242
|
+
const index = target.activeAnimations.findIndex((_) => _ === animation);
|
|
243
|
+
// @ts-expect-error private property
|
|
244
|
+
if (index > -1) target.activeAnimations.splice(index, 1);
|
|
245
|
+
});
|
|
246
|
+
}
|
package/src/global.d.ts
ADDED
|
@@ -126,6 +126,7 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
126
126
|
const content = await this.getDOMContent(event);
|
|
127
127
|
|
|
128
128
|
if (content instanceof HTMLElement) {
|
|
129
|
+
this.$element.innerHTML = '';
|
|
129
130
|
this.$element.appendChild(content);
|
|
130
131
|
} else {
|
|
131
132
|
this.$element.innerHTML = content;
|
|
@@ -213,13 +214,15 @@ export class Contextmenu extends BasePlugin<ContextmenuOptions> {
|
|
|
213
214
|
};
|
|
214
215
|
|
|
215
216
|
private onMenuItemClick = (event: MouseEvent) => {
|
|
216
|
-
const { onClick } = this.options;
|
|
217
|
+
const { onClick, trigger } = this.options;
|
|
217
218
|
if (event.target instanceof HTMLElement) {
|
|
218
219
|
if (event.target.className.includes('g6-contextmenu-li')) {
|
|
219
220
|
const value = event.target.getAttribute('value') as string;
|
|
220
221
|
onClick?.(value, event.target);
|
|
222
|
+
this.hide();
|
|
221
223
|
}
|
|
222
224
|
}
|
|
223
|
-
|
|
225
|
+
|
|
226
|
+
if (trigger !== 'click') this.hide();
|
|
224
227
|
};
|
|
225
228
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RuntimeContext } from '../../runtime/types';
|
|
2
|
+
import { print } from '../../utils/print';
|
|
2
3
|
import type { ShortcutKey } from '../../utils/shortcut';
|
|
3
4
|
import { Shortcut } from '../../utils/shortcut';
|
|
4
5
|
import type { BasePluginOptions } from '../base-plugin';
|
|
@@ -57,7 +58,10 @@ export class Fullscreen extends BasePlugin<FullscreenOptions> {
|
|
|
57
58
|
|
|
58
59
|
private shortcut: Shortcut;
|
|
59
60
|
|
|
61
|
+
private style: HTMLStyleElement;
|
|
62
|
+
|
|
60
63
|
private $el = this.context.canvas.getContainer()!;
|
|
64
|
+
|
|
61
65
|
private graphSize: [number, number] = [0, 0];
|
|
62
66
|
|
|
63
67
|
constructor(context: RuntimeContext, options: FullscreenOptions) {
|
|
@@ -67,7 +71,13 @@ export class Fullscreen extends BasePlugin<FullscreenOptions> {
|
|
|
67
71
|
|
|
68
72
|
this.bindEvents();
|
|
69
73
|
|
|
70
|
-
this
|
|
74
|
+
this.style = document.createElement('style');
|
|
75
|
+
document.head.appendChild(this.style);
|
|
76
|
+
this.style.innerHTML = `
|
|
77
|
+
:not(:root):fullscreen::backdrop {
|
|
78
|
+
background: transparent;
|
|
79
|
+
}
|
|
80
|
+
`;
|
|
71
81
|
}
|
|
72
82
|
|
|
73
83
|
private bindEvents() {
|
|
@@ -123,7 +133,7 @@ export class Fullscreen extends BasePlugin<FullscreenOptions> {
|
|
|
123
133
|
public request() {
|
|
124
134
|
if (document.fullscreenElement || !isFullscreenEnabled()) return;
|
|
125
135
|
this.$el.requestFullscreen().catch((err: Error) => {
|
|
126
|
-
|
|
136
|
+
print.warn(`Error attempting to enable full-screen: ${err.message} (${err.name})`);
|
|
127
137
|
});
|
|
128
138
|
}
|
|
129
139
|
|
|
@@ -149,6 +159,12 @@ export class Fullscreen extends BasePlugin<FullscreenOptions> {
|
|
|
149
159
|
super.update(options);
|
|
150
160
|
this.bindEvents();
|
|
151
161
|
}
|
|
162
|
+
|
|
163
|
+
public destroy(): void {
|
|
164
|
+
this.exit();
|
|
165
|
+
this.style.remove();
|
|
166
|
+
super.destroy();
|
|
167
|
+
}
|
|
152
168
|
}
|
|
153
169
|
|
|
154
170
|
/**
|
|
@@ -5,6 +5,7 @@ import type { RuntimeContext } from '../../runtime/types';
|
|
|
5
5
|
import type { IEvent } from '../../types';
|
|
6
6
|
import { arrayDiff } from '../../utils/diff';
|
|
7
7
|
import { parseExtensions } from '../../utils/extension';
|
|
8
|
+
import { print } from '../../utils/print';
|
|
8
9
|
import type { STDExtensionOption } from './types';
|
|
9
10
|
|
|
10
11
|
export abstract class ExtensionController<E extends BaseExtension<any>> {
|
|
@@ -42,7 +43,7 @@ export abstract class ExtensionController<E extends BaseExtension<any>> {
|
|
|
42
43
|
|
|
43
44
|
const { key, type } = extension;
|
|
44
45
|
const Ctor = getExtension(category, type);
|
|
45
|
-
if (!Ctor) return;
|
|
46
|
+
if (!Ctor) return print.warn(`The extension ${type} of ${category} is not registered.`);
|
|
46
47
|
|
|
47
48
|
const instance = new Ctor(this.context, extension);
|
|
48
49
|
this.extensionMap[key] = instance as E;
|