From 3798b476c2ef4d113f9b05b308d543efc93a4a4a Mon Sep 17 00:00:00 2001 From: Yanyan-Wang Date: Wed, 1 Apr 2020 22:15:10 +0800 Subject: [PATCH] feat: render zindex for combos when first render and changeData --- src/graph/graph.ts | 30 +++++++++++++++++++++++ stories/Combo/component/default-combo.tsx | 1 - 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/graph/graph.ts b/src/graph/graph.ts index 8acad5be71..2d22c20eec 100644 --- a/src/graph/graph.ts +++ b/src/graph/graph.ts @@ -1912,6 +1912,36 @@ export default class Graph extends EventEmitter implements IGraph { } } + private sortCombos(data: GraphData) { + const depthMap = []; + const dataDepthMap = {}; + const comboTrees = this.get('comboTrees'); + comboTrees.forEach(cTree => { + traverseTree(cTree, child => { + if (depthMap[child.depth]) depthMap[child.depth].push(child.id); + else depthMap[child.depth] = [ child.id ]; + dataDepthMap[child.id] = child.depth; + return true; + }); + }); + data.edges.forEach(edge => { + const sourceDepth: number = dataDepthMap[edge.source] || 0; + const targetDepth: number = dataDepthMap[edge.target] || 0; + const depth = Math.max(sourceDepth, targetDepth); + console.log(depth, edge.id, edge.source, edge.target, sourceDepth, targetDepth); + if (depthMap[depth]) depthMap[depth].push(edge.id); + else depthMap[depth] = [ edge.id ]; + }); + console.log(depthMap); + depthMap.forEach(array => { + if (!array || !array.length) return; + for (let i = array.length - 1; i >= 0; i--) { + const item = this.findById(array[i]); + item.toFront(); + } + }); + } + /** * 根据 comboTree 结构整理 Combo 相关的图形绘制层级,包括 Combo 本身、节点、边 * @param {GraphData} data 数据 diff --git a/stories/Combo/component/default-combo.tsx b/stories/Combo/component/default-combo.tsx index 5124d9ba46..43de81503e 100644 --- a/stories/Combo/component/default-combo.tsx +++ b/stories/Combo/component/default-combo.tsx @@ -249,7 +249,6 @@ const DefaultCombo = () => { //graph.focusItem(graph.getCombos()[0]); // graph.remove('B'); // graph.remove('A'); - // graph.changeData(data2); // graph.changeData(graph.save());