Skip to content

Commit 155afcb

Browse files
Yanyan-WangBlakko
andauthored
fix: Annotation readData with inexistent item; (#3985)
* chore: refine * feat: performance tweaks (#3969) * Don't set beforeDragNodes if stack ops are off * Prevent clone if stack ops are off * Reduce lookups * Simplify condition * chore: refine * chore: refine * doc: update CHANGELOG Co-authored-by: Fabio Tacchelli <[email protected]>
1 parent 7680af8 commit 155afcb

File tree

14 files changed

+71
-50
lines changed

14 files changed

+71
-50
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# ChangeLog
22

3+
### 4.7.6
4+
5+
- fix: Annotation readData with inexistent item;
6+
- perf: improve the performance for updating;
7+
38
### 4.7.5
49

510
- perf: Annotation support updating positions for outside cards by calling updateOutsideCards;

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-core",
3-
"version": "0.7.5",
3+
"version": "0.7.6",
44
"description": "A Graph Visualization Framework in JavaScript",
55
"keywords": [
66
"antv",

packages/core/src/global.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const colorSet = {
6464
};
6565

6666
export default {
67-
version: '0.7.5',
67+
version: '0.7.6',
6868
rootContainerClassName: 'root-container',
6969
nodeContainerClassName: 'node-container',
7070
edgeContainerClassName: 'edge-container',

packages/core/src/graph/controller/item.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ export default class ItemController {
271271
} else if (type === NODE) {
272272
item.update(cfg, updateType);
273273
const edges: IEdge[] = (item as INode).getEdges();
274-
const refreshEdge = updateType?.includes('bbox') || updateType === 'move';
275274
if (updateType === 'move') {
276275
each(edges, (edge: IEdge) => {
277276
this.edgeToBeUpdateMap[edge.getID()] = {
@@ -280,7 +279,7 @@ export default class ItemController {
280279
};
281280
this.throttleRefresh();
282281
});
283-
} else if (refreshEdge) {
282+
} else if (updateType?.includes('bbox')) {
284283
each(edges, (edge: IEdge) => {
285284
edge.refresh(updateType);
286285
});
@@ -329,14 +328,16 @@ export default class ItemController {
329328
const { graph } = this;
330329
if (!graph || graph.get('destroyed')) return;
331330
const edgeToBeUpdateMap = this.edgeToBeUpdateMap;
332-
if (!edgeToBeUpdateMap || !Object.keys(edgeToBeUpdateMap)?.length) return;
333-
Object.keys(edgeToBeUpdateMap).forEach(eid => {
334-
const edge = edgeToBeUpdateMap[eid].edge;
331+
if (!edgeToBeUpdateMap) return;
332+
const edgeValues = Object.values(edgeToBeUpdateMap);
333+
if (!edgeValues.length) return;
334+
edgeValues.forEach(obj => {
335+
const edge = obj.edge;
335336
if (!edge || edge.destroyed) return;
336337
const source = edge.getSource();
337338
const target = edge.getTarget();
338339
if (!source || source.destroyed || !target || target.destroyed) return;
339-
edge.refresh(edgeToBeUpdateMap[eid].updateType);
340+
edge.refresh(obj.updateType);
340341
});
341342
this.edgeToBeUpdateMap = {};
342343
},

packages/core/src/graph/graph.ts

+12-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
floydWarshall,
1010
} from '@antv/algorithm';
1111
import { IAbstractGraph } from '../interface/graph';
12-
import { IEdge, INode, ICombo } from '../interface/item';
12+
import { IEdge, INode, ICombo, IItemBaseConfig } from '../interface/item';
1313
import {
1414
GraphAnimateConfig,
1515
GraphOptions,
@@ -1337,14 +1337,18 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
13371337
stack: boolean = true,
13381338
): void {
13391339
const itemController: ItemController = this.get('itemController');
1340-
let currentItem;
1340+
let currentItem: Item;
13411341
if (isString(item)) {
13421342
currentItem = this.findById(item as string);
13431343
} else {
13441344
currentItem = item;
13451345
}
13461346

1347-
const UnupdateModel = clone(currentItem.getModel());
1347+
const stackEnabled = stack && this.get('enabledStack');
1348+
let unupdatedModel;
1349+
if (stackEnabled) {
1350+
unupdatedModel = clone(currentItem.getModel());
1351+
}
13481352

13491353
let type = '';
13501354
if (currentItem.getType) type = currentItem.getType();
@@ -1358,32 +1362,29 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
13581362
each(states, state => this.setItemState(currentItem, state, true));
13591363
}
13601364

1361-
if (stack && this.get('enabledStack')) {
1365+
if (stackEnabled) {
13621366
const before = { nodes: [], edges: [], combos: [] };
13631367
const after = { nodes: [], edges: [], combos: [] };
13641368
const afterModel = {
1365-
id: UnupdateModel.id,
1369+
id: unupdatedModel.id,
13661370
...cfg,
13671371
};
13681372
switch (type) {
13691373
case 'node':
1370-
before.nodes.push(UnupdateModel);
1374+
before.nodes.push(unupdatedModel);
13711375
after.nodes.push(afterModel);
13721376
break;
13731377
case 'edge':
1374-
before.edges.push(UnupdateModel);
1378+
before.edges.push(unupdatedModel);
13751379
after.edges.push(afterModel);
13761380
break;
13771381
case 'combo':
1378-
before.combos.push(UnupdateModel);
1382+
before.combos.push(unupdatedModel);
13791383
after.combos.push(afterModel);
13801384
break;
13811385
default:
13821386
break;
13831387
}
1384-
if (type === 'node') {
1385-
before.nodes.push(UnupdateModel);
1386-
}
13871388
this.pushStack('update', { before, after });
13881389
}
13891390
}

packages/element/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-element",
3-
"version": "0.7.5",
3+
"version": "0.7.6",
44
"description": "A Graph Visualization Framework in JavaScript",
55
"keywords": [
66
"antv",
@@ -61,7 +61,7 @@
6161
},
6262
"dependencies": {
6363
"@antv/g-base": "^0.5.1",
64-
"@antv/g6-core": "0.7.5",
64+
"@antv/g6-core": "0.7.6",
6565
"@antv/util": "~2.0.5"
6666
},
6767
"devDependencies": {

packages/g6/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6",
3-
"version": "4.7.5",
3+
"version": "4.7.6",
44
"description": "A Graph Visualization Framework in JavaScript",
55
"keywords": [
66
"antv",
@@ -66,7 +66,7 @@
6666
]
6767
},
6868
"dependencies": {
69-
"@antv/g6-pc": "0.7.5"
69+
"@antv/g6-pc": "0.7.6"
7070
},
7171
"devDependencies": {
7272
"@babel/core": "^7.7.7",

packages/g6/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import G6 from '@antv/g6-pc';
22

3-
G6.version = '4.7.5';
3+
G6.version = '4.7.6';
44

55
export * from '@antv/g6-pc';
66
export default G6;
7-
export const version = '4.7.5';
7+
export const version = '4.7.6';

packages/pc/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-pc",
3-
"version": "0.7.5",
3+
"version": "0.7.6",
44
"description": "A Graph Visualization Framework in JavaScript",
55
"keywords": [
66
"antv",
@@ -75,9 +75,9 @@
7575
"@antv/g-canvas": "^0.5.2",
7676
"@antv/g-math": "^0.1.1",
7777
"@antv/g-svg": "^0.5.1",
78-
"@antv/g6-core": "0.7.5",
79-
"@antv/g6-element": "0.7.5",
80-
"@antv/g6-plugin": "0.7.5",
78+
"@antv/g6-core": "0.7.6",
79+
"@antv/g6-element": "0.7.6",
80+
"@antv/g6-plugin": "0.7.6",
8181
"@antv/hierarchy": "^0.6.7",
8282
"@antv/layout": "^0.3.0",
8383
"@antv/matrix-util": "^3.1.0-beta.3",

packages/pc/src/behavior/drag-node.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default {
108108
// 拖动时,设置拖动元素的 capture 为false,则不拾取拖动的元素
109109
const group = item.getContainer();
110110
group.set('capture', false);
111-
if (!this.cachedCaptureItems) this.cachedCaptureItems = []
111+
if (!this.cachedCaptureItems) this.cachedCaptureItems = [];
112112
this.cachedCaptureItems.push(item);
113113

114114
// 如果拖动的target 是linkPoints / anchorPoints 则不允许拖动
@@ -152,12 +152,15 @@ export default {
152152
} else {
153153
this.targets.push(item);
154154
}
155-
const beforeDragNodes = [];
156-
this.targets.forEach(t => {
157-
const { x, y, id } = t.getModel();
158-
beforeDragNodes.push({ x, y, id });
159-
});
160-
this.set('beforeDragNodes', beforeDragNodes);
155+
156+
if (this.graph.get('enabledStack') && this.enableStack) {
157+
const beforeDragNodes = [];
158+
this.targets.forEach((t) => {
159+
const { x, y, id } = t.getModel();
160+
beforeDragNodes.push({ x, y, id });
161+
});
162+
this.set('beforeDragNodes', beforeDragNodes);
163+
}
161164

162165
this.hidenEdge = {};
163166
if (this.get('updateEdge') && this.enableOptimize && !this.enableDelegate) {

packages/pc/src/global.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const textColor = 'rgb(0, 0, 0)';
77
const colorSet = getColorsWithSubjectColor(subjectColor, backColor);
88

99
export default {
10-
version: '0.7.5',
10+
version: '0.7.6',
1111
rootContainerClassName: 'root-container',
1212
nodeContainerClassName: 'node-container',
1313
edgeContainerClassName: 'edge-container',

packages/plugin/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@antv/g6-plugin",
3-
"version": "0.7.5",
3+
"version": "0.7.6",
44
"description": "G6 Plugin",
55
"main": "lib/index.js",
66
"module": "es/index.js",
@@ -22,8 +22,8 @@
2222
"@antv/g-base": "^0.5.1",
2323
"@antv/g-canvas": "^0.5.2",
2424
"@antv/g-svg": "^0.5.2",
25-
"@antv/g6-core": "0.7.5",
26-
"@antv/g6-element": "0.7.5",
25+
"@antv/g6-core": "0.7.6",
26+
"@antv/g6-element": "0.7.6",
2727
"@antv/matrix-util": "^3.1.0-beta.3",
2828
"@antv/scale": "^0.3.4",
2929
"@antv/util": "^2.0.9",
@@ -61,4 +61,4 @@
6161
"ts-jest": "^26.4.4",
6262
"@antv/g6": "4.5.1"
6363
}
64-
}
64+
}

packages/plugin/src/annotation/index.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ interface CardInfoMap {
119119
}
120120
}
121121

122+
const CANVAS_ANNOTATION_ID = 'canvas-annotation';
123+
122124
export default class Annotation extends Base {
123125
constructor(config?: AnnotationConfig) {
124126
super(config);
@@ -413,7 +415,7 @@ export default class Annotation extends Base {
413415

414416
const isCanvas = item.isCanvas?.();
415417

416-
const itemId = isCanvas ? 'canvas-annotation' : item.getID();
418+
const itemId = isCanvas ? CANVAS_ANNOTATION_ID : item.getID();
417419
let { card, link, x, y, title, content } = cardInfoMap[itemId] || {};
418420

419421
const getTitle = this.get('getTitle');
@@ -588,7 +590,7 @@ export default class Annotation extends Base {
588590
public hideCard(id) {
589591
if (this.destroyed) return;
590592
const cardInfoMap = this.get('cardInfoMap');
591-
if (!cardInfoMap) return;
593+
if (!cardInfoMap || !cardInfoMap[id]) return;
592594
const { card, link } = cardInfoMap[id];
593595
modifyCSS(card, { display: 'none' });
594596
link?.hide();
@@ -876,7 +878,7 @@ export default class Annotation extends Base {
876878
const graph = this.get('graph');
877879
Object.values(cardInfoMap).forEach(info => {
878880
const { id, card, isCanvas } = info;
879-
if (isCanvas || card.style.display === 'none') return;
881+
if (!card || isCanvas || card.style.display === 'none') return;
880882
const item = graph.findById(id);
881883
if (item && item.isVisible()) {
882884
this.toggleAnnotation(item);
@@ -904,7 +906,7 @@ export default class Annotation extends Base {
904906
const data = [];
905907
Object.values(cardInfoMap).forEach(info => {
906908
const { title, content, x, y, id, collapsed, card } = info;
907-
if (card.style.display === 'none' && !saveClosed) return;
909+
if (card && card.style.display === 'none' && !saveClosed) return;
908910
const item = graph.findById(id) || graph.get('canvas');
909911
data.push({
910912
id,
@@ -913,7 +915,7 @@ export default class Annotation extends Base {
913915
collapsed,
914916
title: title || getTitle?.(item),
915917
content: content || getContent?.(item),
916-
visible: card.style.display !== 'none'
918+
visible: card && card.style.display !== 'none'
917919
})
918920
});
919921
return data;
@@ -923,10 +925,19 @@ export default class Annotation extends Base {
923925
const graph = this.get('graph');
924926
data.forEach(info => {
925927
const { id, x, y, title, content, collapsed, visible } = info;
926-
const item = graph.findById(id) || graph.get('canvas');
928+
let item = graph.findById(id);
929+
if (!item && id === CANVAS_ANNOTATION_ID) {
930+
item = graph.get('canvas');
931+
}
932+
if (!item) {
933+
const cardInfoMap = this.get('cardInfoMap') || {};
934+
cardInfoMap[id] = info;
935+
this.set('cardInfoMap', cardInfoMap);
936+
return;
937+
}
927938
this.toggleAnnotation(item, { x, y, title, content, collapsed });
928939
if (!visible) this.hideCard(id);
929-
})
940+
});
930941
}
931942

932943
/**

packages/site/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@antv/g6-site",
4-
"version": "4.7.5",
4+
"version": "4.7.6",
55
"description": "G6 sites deployed on gh-pages",
66
"keywords": [
77
"antv",
@@ -36,7 +36,7 @@
3636
"dependencies": {
3737
"@ant-design/icons": "^4.0.6",
3838
"@antv/chart-node-g6": "^0.0.3",
39-
"@antv/g6": "4.7.5",
39+
"@antv/g6": "4.7.6",
4040
"@antv/gatsby-theme-antv": "1.1.15",
4141
"@antv/util": "^2.0.9",
4242
"@antv/vis-predict-engine": "^0.1.1",

0 commit comments

Comments
 (0)