drawConnector = {
return function (data, width=800, height=100) {
const linkGenerator = d3.linkHorizontal().x(d => d[0]).y(d => d[1])
const svg = d3.create("svg")
.style("width", width)
.style("height", height)
.style("background", "white");
svg.selectAll("path")
.data(data.edges)
.enter()
.append("path")
.attr("d", (edge) => {
const [fromLabel, toLabel] = [edge.from, edge.to];
const [from, to] = [data.nodes[fromLabel], data.nodes[toLabel]];
console.log(from, to);
return linkGenerator({source: from, target:to});
})
.attr("class", "link")
svg.selectAll("circle")
.data(Object.keys(data.nodes))
.enter()
.append("circle")
.attr("cx", (label) => data.nodes[label][0])
.attr("cy", (label) => data.nodes[label][1])
.attr("r", 5)
.attr("class", "node")
svg.selectAll("text")
.data(Object.keys(data.nodes))
.enter()
.append("text")
.attr("x", d => data.nodes[d][0])
.attr("y", d => data.nodes[d][1])
.attr("dx", d => data.nodes[d][0] > 250 ? 10 : -10)
.attr("dy", 5)
.attr("text-anchor", d => data.nodes[d][0] > 250 ? "start" : "end")
.text(d => d)
return svg.node();
}
}