Skip to content

Commit

Permalink
Merge pull request antvis#42 from sirensolutions/tweak-perf-siren
Browse files Browse the repository at this point in the history
  • Loading branch information
Blakko committed Sep 28, 2022
2 parents e74637b + c1e25a2 commit 873d894
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 39 deletions.
13 changes: 7 additions & 6 deletions packages/core/src/graph/controller/item.ts
Expand Up @@ -271,7 +271,6 @@ export default class ItemController {
} else if (type === NODE) {
item.update(cfg, updateType);
const edges: IEdge[] = (item as INode).getEdges();
const refreshEdge = updateType?.includes('bbox') || updateType === 'move';
if (updateType === 'move') {
each(edges, (edge: IEdge) => {
this.edgeToBeUpdateMap[edge.getID()] = {
Expand All @@ -280,7 +279,7 @@ export default class ItemController {
};
this.throttleRefresh();
});
} else if (refreshEdge) {
} else if (updateType?.includes('bbox')) {
each(edges, (edge: IEdge) => {
edge.refresh(updateType);
});
Expand Down Expand Up @@ -329,14 +328,16 @@ export default class ItemController {
const { graph } = this;
if (!graph || graph.get('destroyed')) return;
const edgeToBeUpdateMap = this.edgeToBeUpdateMap;
if (!edgeToBeUpdateMap || !Object.keys(edgeToBeUpdateMap)?.length) return;
Object.keys(edgeToBeUpdateMap).forEach(eid => {
const edge = edgeToBeUpdateMap[eid].edge;
if (!edgeToBeUpdateMap) return;
const edgeValues = Object.values(edgeToBeUpdateMap);
if (!edgeValues.length) return;
edgeValues.forEach(obj => {
const edge = obj.edge;
if (!edge || edge.destroyed) return;
const source = edge.getSource();
const target = edge.getTarget();
if (!source || source.destroyed || !target || target.destroyed) return;
edge.refresh(edgeToBeUpdateMap[eid].updateType);
edge.refresh(obj.updateType);
});
this.edgeToBeUpdateMap = {};
},
Expand Down
37 changes: 11 additions & 26 deletions packages/core/src/graph/graph.ts
Expand Up @@ -9,7 +9,7 @@ import {
floydWarshall,
} from '@antv/algorithm';
import { IAbstractGraph } from '../interface/graph';
import { IEdge, INode, ICombo } from '../interface/item';
import { IEdge, INode, ICombo, IItemBaseConfig } from '../interface/item';
import {
GraphAnimateConfig,
GraphOptions,
Expand Down Expand Up @@ -1346,21 +1346,17 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
stack: boolean = true,
): void {
const itemController: ItemController = this.get('itemController');
let currentItem;
let currentItem: Item;
if (isString(item)) {
currentItem = this.findById(item as string);
} else {
currentItem = item;
}

const currentModel = currentItem.getModel();
const UnupdateModel = clone(currentModel);

if (cfg.states && currentModel.states) {
// if `.states` is passed to update item
// and also presented on the previous model
// give priority to `cfg.states`
currentModel.states = {};
const stackEnabled = stack && this.get('enabledStack');
let unupdatedModel;
if (stackEnabled) {
unupdatedModel = clone(currentItem.getModel());
}

let type = '';
Expand All @@ -1375,40 +1371,29 @@ export default abstract class AbstractGraph extends EventEmitter implements IAbs
each(states, state => this.setItemState(currentItem, state, true));
}

if (cfg.states) {
currentItem.clearStates();

Object.keys(cfg.states).forEach(key => {
currentItem.setState(key, cfg.states[key]);
});
}

if (stack && this.get('enabledStack')) {
if (stackEnabled) {
const before = { nodes: [], edges: [], combos: [] };
const after = { nodes: [], edges: [], combos: [] };
const afterModel = {
id: UnupdateModel.id,
id: unupdatedModel.id,
...cfg,
};
switch (type) {
case 'node':
before.nodes.push(UnupdateModel);
before.nodes.push(unupdatedModel);
after.nodes.push(afterModel);
break;
case 'edge':
before.edges.push(UnupdateModel);
before.edges.push(unupdatedModel);
after.edges.push(afterModel);
break;
case 'combo':
before.combos.push(UnupdateModel);
before.combos.push(unupdatedModel);
after.combos.push(afterModel);
break;
default:
break;
}
if (type === 'node') {
before.nodes.push(UnupdateModel);
}
this.pushStack('update', { before, after });
}
}
Expand Down
17 changes: 10 additions & 7 deletions packages/pc/src/behavior/drag-node.ts
Expand Up @@ -108,7 +108,7 @@ export default {
// 拖动时,设置拖动元素的 capture 为false,则不拾取拖动的元素
const group = item.getContainer();
group.set('capture', false);
if (!this.cachedCaptureItems) this.cachedCaptureItems = []
if (!this.cachedCaptureItems) this.cachedCaptureItems = [];
this.cachedCaptureItems.push(item);

// 如果拖动的target 是linkPoints / anchorPoints 则不允许拖动
Expand Down Expand Up @@ -152,12 +152,15 @@ export default {
} else {
this.targets.push(item);
}
const beforeDragNodes = [];
this.targets.forEach(t => {
const { x, y, id } = t.getModel();
beforeDragNodes.push({ x, y, id });
});
this.set('beforeDragNodes', beforeDragNodes);

if (this.graph.get('enabledStack') && this.enableStack) {
const beforeDragNodes = [];
this.targets.forEach((t) => {
const { x, y, id } = t.getModel();
beforeDragNodes.push({ x, y, id });
});
this.set('beforeDragNodes', beforeDragNodes);
}

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

0 comments on commit 873d894

Please sign in to comment.