graph = {
const svg = d3
.select(DOM.svg(width, width))
.attr("viewBox", `${-width / 2} ${-width / 2} ${width} ${width}`)
.style("font-family", "'Helvetica Neue', Helvetica, Arial sans-serif");
let link = svg
.append("g")
.selectAll("link")
.data(connectivity)
.enter()
.append("path")
.each(function (d) {
(d.source = d[0]), (d.target = d[d.length - 1]);
})
.attr("d", line)
.attr("fill", "none")
.attr("stroke", (d) => color(d.source.x));
let node = svg
.append("g")
.selectAll("text")
.data(root.leaves())
.enter()
.append("text")
.text((d) => d.data.Alias)
.attr("transform", (d) => tilt(d))
.attr("dy", "0.3em")
.attr("x", (d) => (d.x < Math.PI ? 5 : -5))
.attr("text-anchor", (d) => (d.x < Math.PI ? "start" : "end"))
.on("mouseover", mouseover)
.on("mouseout", reset);
let highlight = svg
.append("g")
.attr("text-anchor", "middle")
.attr("fill", "#333")
.attr("fill-opacity", 0.8)
.style("font-size", "10vw")
.style("font-weight", 700);
let alias = highlight.append("text").attr("dy", "-0.3em");
let points = highlight
.append("text")
.attr("dy", "0.3em")
.attr("fill-opacity", 0.6)
.style("font-size", "2.5vw")
.style("font-weight", 500);
let connections = highlight
.append("text")
.attr("dy", "0.8em")
.style("font-size", "3vw")
.style("font-weight", 600);
function mouseover(d) {
d3.select(this)
.attr("fill", (d) => color(d.x))
.style("font-weight", 700)
.style("font-size", "2vw");
node.each((n) => (n.linked = false));
link
.filter((l) => (l.target === d) | (l.source === d))
.each((l) =>
l.target === d ? (l.source.linked = true) : (l.target.linked = true)
)
.attr("stroke-width", 2)
.attr("stroke-opacity", 0.7);
node
.filter((n) => n.linked)
.style("font-weight", 500)
.style("font-size", "1.4vw");
alias.text(d.data.Alias).attr("fill", color(d.x));
points.text(d3.format(",")(d.data.Points) + " points");
connections.text(d.data.Count + " connections");
}
function reset() {
node
.attr("fill", "#999")
.style("font-weight", 300)
.style("font-size", "1.3vw");
link.attr("stroke-opacity", 0.3).attr("stroke-width", 0.5);
alias.text("");
points.text("");
connections.text("");
}
reset();
return svg.node();
}