chart = {
const svg = d3.create("svg")
.attr("font-size", "11pt")
.attr("viewBox", [0, 0, width, height]);
const arcs = svg.selectAll("path")
.data(links)
.join("path")
.attr("fill", "none")
.attr("stroke", "#ccc")
.attr("stroke-width", d => w(d.value))
.attr("d", arc)
.call(g => g.append("title").text(d => `${d.source.name} - ${d.target.name}\n${toCurrency(d.value)}`))
.on("mouseover", highlight)
.on("mouseout", restore);
const circles = svg.selectAll(".node")
.data(nodes)
.join("g")
.attr("class", "node")
.attr("transform", d => `translate(${x(d.name)},${height - margin})`)
.on("mouseover", highlight)
.on("mouseout", restore);
circles.append("circle")
.attr("r", d => r(d.total))
.attr("fill", d=> color(d.name))
circles.append("g")
.attr("text-anchor", "middle")
.attr("transform", `translate(0,${radius.max + 20})`)
.call(g => g.append("text").text(d => d.name))
.call(g => g.append("text").attr("dy", "1em").text(d => toCurrency(d.total)));
return svg.node();
function highlight(e, d, restore) {
if (d.name) {
arcs.filter(a => a.source === d || a.target === d)
.transition().duration(500)
.attr("stroke", d => restore ? "#ccc" : color(d.target.name));
circles.select("circle")
.transition().duration(500)
.attr("fill", c => restore || linkedNodes(d).some(n => n === c) ? color(c.name) : "#ccc");
}
else if (d.source) {
arcs.transition().duration(500).attr("stroke", a => restore || a !== d ? "#ccc" : color(a.target.name));
circles.select("circle")
.transition().duration(500)
.attr("fill", c => restore || c === d.source || c === d.target ? color(c.name) : "#ccc");
}
}
function restore(e, d) { highlight(e, d, true); }
}