diff --git a/CHANGELOG.md b/CHANGELOG.md index bc311adfd30..7dd3f9b78d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # ChangeLog +#### 3.5.9 +- fix: multiple animate update shape for combo; +- fix: removeItem from a combo. + #### 3.5.8 - fix: combo edge problem, issues #1722; - feat: adjacency matrix algorithm; diff --git a/package.json b/package.json index 66ae0e6ba4f..0edc936c3c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antv/g6", - "version": "3.5.8", + "version": "3.5.9", "description": "A Graph Visualization Framework in JavaScript", "keywords": [ "antv", diff --git a/src/global.ts b/src/global.ts index 168bff80acd..07651d883ac 100644 --- a/src/global.ts +++ b/src/global.ts @@ -1,5 +1,5 @@ export default { - version: '3.5.8', + version: '3.5.9', rootContainerClassName: 'root-container', nodeContainerClassName: 'node-container', edgeContainerClassName: 'edge-container', diff --git a/src/graph/controller/item.ts b/src/graph/controller/item.ts index cc3d0e21cbc..c1d65a8a7dc 100644 --- a/src/graph/controller/item.ts +++ b/src/graph/controller/item.ts @@ -353,6 +353,7 @@ export default class ItemController { const comboTrees = graph.get('comboTrees'); const id = item.get('id'); if (type === NODE) { + const comboId = item.getModel().comboId as string; if (comboTrees) { let brothers = comboTrees; let found = false; // the flag to terminate the forEach circulation @@ -376,8 +377,9 @@ export default class ItemController { for (let i = edges.length; i >= 0; i--) { graph.removeItem(edges[i], false); } - } - else if (type === COMBO) { + if (comboId) graph.updateCombo(comboId); + } else if (type === COMBO) { + const parentId = item.getModel().parentId as string; let comboInTree; // find the subtree rooted at the item to be removed let found = false; // the flag to terminate the forEach circulation @@ -403,6 +405,7 @@ export default class ItemController { for (let i = edges.length; i >= 0; i--) { graph.removeItem(edges[i], false); } + if (parentId) graph.updateCombo(parentId); } item.destroy(); diff --git a/src/graph/graph.ts b/src/graph/graph.ts index 1788af9c575..19f27ff533f 100644 --- a/src/graph/graph.ts +++ b/src/graph/graph.ts @@ -1408,33 +1408,30 @@ export default class Graph extends EventEmitter implements IGraph { // step 1: 创建新的 Combo let comboId = '' let currentCombo: ICombo; + let comboConfig: ComboConfig; + if (!combo) return; if (isString(combo)) { comboId = combo - currentCombo = this.addItem('combo', { + comboConfig = { id: combo - }, false) + }; } else { comboId = combo.id if (!comboId) { console.warn('Create combo failed. Please assign a unique string id for the adding combo.'); return; } - currentCombo = this.addItem('combo', combo, false) + comboConfig = combo; } - const comboModel = currentCombo.getModel(); - const trees = children.map(elementId => { + const trees: ComboTree[] = children.map(elementId => { const item = this.findById(elementId) - // step 2: 将元素添加到 Combo 中 - currentCombo.addChild(item as INode | ICombo) - let type = ''; if (item.getType) type = item.getType(); - const cItem = { + const cItem: ComboTree = { id: item.getID(), - depth: (comboModel.depth as number) + 2, - itemType: type + itemType: type as "node" | "combo" } if (type === 'combo') { @@ -1446,6 +1443,18 @@ export default class Graph extends EventEmitter implements IGraph { return cItem }) + comboConfig.children = trees; + + currentCombo = this.addItem('combo', comboConfig, false) + const comboModel = currentCombo.getModel(); + + trees.forEach(child => { + const item = this.findById(child.id) + // step 2: 将元素添加到 Combo 中 + currentCombo.addChild(item as INode | ICombo) + child.depth = (comboModel.depth as number) + 2; + }); + // step3: 更新 comboTrees 结构 const comboTrees = this.get('comboTrees') comboTrees && comboTrees.forEach(ctree => { @@ -1458,8 +1467,7 @@ export default class Graph extends EventEmitter implements IGraph { return true; }); }) - - this.updateCombos() + this.sortCombos(); } /** diff --git a/src/plugins/toolBar/index.ts b/src/plugins/toolBar/index.ts index 7801c50e204..f01344fa4cf 100644 --- a/src/plugins/toolBar/index.ts +++ b/src/plugins/toolBar/index.ts @@ -54,7 +54,6 @@ export default class ToolBar extends Base { handleClick: undefined, // 指定菜单内容,function(e) {...} getContent: (e) => { - console.log(e) return `