Compare commits

..

No commits in common. "3706d30b82956bdef4220f2210d8eeb3176b26f0" and "a722292c57f218a26b1d76847acaac5f7b74bca2" have entirely different histories.

1 changed files with 31 additions and 42 deletions

View File

@ -61,15 +61,9 @@ export default {
}); });
this.render = new dagreD3.render(); this.render = new dagreD3.render();
let svg = d3.select("#mySvg").attr("preserveAspectRatio", "xMidYMid meet"); let svg = d3.select("#mySvg");
this.inner = svg.append("g"); this.inner = svg.append("g");
//
let zoom = d3.zoom().on("zoom", (event) => {
this.inner.attr("transform", event.transform);
});
svg.call(zoom);
this.renderGraph(); this.renderGraph();
this.bindNodeClick(svg); this.bindNodeClick(svg);
}, },
@ -77,7 +71,7 @@ export default {
/** 渲染节点和边 */ /** 渲染节点和边 */
renderGraph() { renderGraph() {
let that = this; let that = this;
that.inner.selectAll("*").remove(); //
// //
that.g.nodes().forEach((v) => that.g.removeNode(v)); that.g.nodes().forEach((v) => that.g.removeNode(v));
that.g.edges().forEach((e) => that.g.removeEdge(e)); that.g.edges().forEach((e) => that.g.removeEdge(e));
@ -97,46 +91,41 @@ export default {
} }
}); });
const edgeGroups = {}; // key
that.edges.forEach((edge) => { that.edges.forEach((edge, index) => {
const key = `${edge.source}_${edge.target}`; let edgeColor = "green"; // 绿
if (!edgeGroups[key]) edgeGroups[key] = []; if (edge.label === "驳回") edgeColor = "red";
edgeGroups[key].push(edge); if (edge.label === "退回") edgeColor = "red";
});
// 线 that.g.setEdge(
const curves = [d3.curveBasis, d3.curveCardinal, d3.curveBundle.beta(0.8)]; edge.source,
edge.target,
// {
Object.values(edgeGroups).forEach((edges) => { label: edge.label,
edges.forEach((edge, index) => { id: edge.id,
let edgeColor = "green"; style: `fill:#ffffff;stroke:${edgeColor};stroke-width:1.5px`,
if (edge.label === "驳回" || edge.label === "退回") edgeColor = "red"; curve: d3.curveBasis,
minlen: 1 + index % 3,
that.g.setEdge( },
edge.source, `${edge.source}_${edge.target}_${edge.id}`
edge.target, );
{
label: edge.label,
id: edge.id,
//
curve: curves[index % curves.length],
labeloffset: 16 + index * 10, //
minlen: 2 + index, // dagre
style: `fill:none;stroke:${edgeColor};stroke-width:1.5px`,
},
`${edge.source}_${edge.target}_${edge.id}`
);
});
}); });
// //
this.render(this.inner, this.g); this.render(this.inner, this.g);
// viewBox // SVG
const { width, height } = this.g.graph(); let mySvgHeight =
d3.select("#mySvg") document.getElementsByClassName("nodes")[0]?.getBoundingClientRect().height +
.attr("viewBox", `0 0 ${width + 2} ${height + 2}`); 50;
let mySvgWdith =
document.getElementsByClassName("output")[0]?.getBoundingClientRect().width +
150;
if (mySvgHeight && mySvgWdith) {
document.getElementById("mySvg").setAttribute("height", mySvgHeight);
document.getElementById("mySvg").setAttribute("width", mySvgWdith);
}
}, },
/** 更新图形 */ /** 更新图形 */