sankeychart = {
const svg = d3.select(DOM.svg(width, height))
.style("width", "100%")
.style("height", "auto");
const {nodes, links} = sankey(data2);
nodes.forEach(function(node) {
if(node.xAnchor) { console.log("node:", node) }
node.y = (node.yAnchor) ? parseInt(node.yAnchor) : node.y;
node.x = (node.xAnchor) ? parseInt(node.xAnchor) : node.x;
});
svg.append("g")
.selectAll("rect")
.data(nodes)
.enter().append("rect")
.attr("x", d => d.x0 + 10)
.attr("y", d => d.y0)
.attr("height", d => d.y1 - d.y0)
.attr("width", d => d.x1 - d.x0 - 20)
.attr("fill", "gray")
.append("title")
.text(d => `${d.name}\n${format(d.value)}`);
const link = svg.append("g")
.attr("fill", "none")
.attr("stroke-opacity", 0.5)
.selectAll("g")
.data(links)
.enter().append("g")
.style("mix-blend-mode", "multiply");
if (edgeColor === "path") {
const gradient = link.append("linearGradient")
.attr("id", d => (d.uid = DOM.uid("link")).id)
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", d => d.source.x1)
.attr("x2", d => d.target.x0);
gradient.append("stop")
.attr("offset", "0%")
.attr("stop-color", d => color(d.source.name));
gradient.append("stop")
.attr("offset", "100%")
.attr("stop-color", d => color(d.target.name));
}
link.append("path")
.attr("d", d3.sankeyLinkHorizontal())
.attr("stroke", d => edgeColor === "path" ? d.uid
: edgeColor === "input" ? color(d.source.name)
: edgeColor === "grey" ? d3.color("lightgray")
: color(d.target.name))
.attr("stroke-width", d => Math.max(1, d.width));
link.append("title")
.text(d => `${d.source.name} → ${d.target.name}\n${format(d.value)}`);
svg.append("g")
.style("font", "14px sans-serif")
.selectAll("text")
.data(nodes)
.enter().append("text")
.attr("x", d => d.x0 + 16)
.attr("y", d => d.y0 + 10)
.attr("fill", "white")
.attr("dy", "0.35em")
.attr("text-anchor", "start")
.text(d => d.name);
return svg.node();
}