{
const { width, height, dag } = laidout;
console.log("x", [...new Set([...dag].map((n) => n.x))][0]);
for (const { points } of dag.ilinks()) {
if (points.length > 2) console.log(points.slice(1, -1));
}
const svgNode = svg`<svg width=${width} height=${height}></svg>`;
const svgSelection = d3.select(svgNode);
const defs = svgSelection.append("defs");
const steps = dag.size();
const interp = d3.interpolateRainbow;
const colorMap = {};
for (const [i, node] of [...dag].entries()) {
let nodeType = findNodeType(node.data.id);
colorMap[nodeType] = interp(i / steps);
}
const curveStyle =
splines.get(spline) ??
{
Grid: [d3.curveBasis, d3.curveBasis],
Zherebko: [d3.curveMonotoneY, d3.curveMonotoneX],
Sugiyama: [d3.curveNatural, d3.curveNatural]
}[algorithm][+horizontal];
const line = d3
.line()
.curve(curveStyle)
.x((d) => d.x)
.y((d) => d.y);
svgSelection
.append("g")
.selectAll("path")
.data(dag.links())
.enter()
.append("path")
.attr("d", ({ points }) => line(points))
.attr("fill", "none")
.attr("stroke-width", 3)
.attr("stroke", ({ source, target }) => {
const gradId = encodeURIComponent(
`${source.data.id.replaceAll(" ", "")}--${target.data.id.replaceAll(
" ",
""
)}`
);
const grad = defs
.append("linearGradient")
.attr("id", gradId)
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", source.x)
.attr("x2", target.x)
.attr("y1", source.y)
.attr("y2", target.y);
grad
.append("stop")
.attr("offset", "0%")
.attr("stop-color", colorMap[findNodeType(source.data.id)]);
grad
.append("stop")
.attr("offset", "100%")
.attr("stop-color", colorMap[findNodeType(target.data.id)]);
return `url(#${gradId})`;
});
const nodes = svgSelection
.append("g")
.selectAll("g")
.data(dag.descendants())
.enter()
.append("g")
.attr("transform", ({ x, y }) => `translate(${x}, ${y})`);
nodes
.append("circle")
.attr("r", nodeRadius)
.attr("fill", (n) => colorMap[findNodeType(n.data.id)]);
nodes
.append("text")
.text((d) => d.data.id)
.attr("font-size", "9")
.attr("font-weight", "bold")
.attr("font-family", "sans-serif")
.attr("text-anchor", "middle")
.attr("alignment-baseline", "middle")
.attr("stroke", "white")
.attr("paint-order", "stroke")
.attr("fill", "black");
return svgNode;
}