chart = {
const root = tree(data);
let x0 = Infinity;
let x1 = -x0;
root.each(d => {
if (d.x > x1) x1 = d.x;
if (d.x < x0) x0 = d.x;
});
const svg = d3.select(DOM.svg(width, x1 - x0 + root.dx * 2))
.style("width", "100%")
.style("height", "auto");
const g = svg.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("transform", `translate(0,${root.dx - x0})`);
const link = g.append("g")
.attr("fill", "none")
.attr("stroke", "#555")
.attr("stroke-opacity", 0.4)
.attr("stroke-width", 1.5)
.selectAll("path")
.data(root.links().filter(d => d.source.depth))
.enter().append("path")
.attr("d", d => `
M${d.target.y},${d.target.x}
C${d.source.y + root.dy / 2},${d.target.x}
${d.source.y + root.dy / 2},${d.source.x}
${d.source.y},${d.source.x}
`);
const node = g.append("g")
.attr("stroke-linejoin", "round")
.selectAll("a")
.data(root.descendants().slice(1).reverse())
.enter().append("a")
.style("cursor", "pointer")
.attr("xlink:href", d => d.data.sift
? `https://lear.inrialpes.fr/people/gordo/ImageNetResults/sift1000_accuracy/results_sift_${d.data.sift}.htm`
: `https://www.google.com/search?tbm=isch&q=${d.data.name}`)
.attr("target", "_blank")
.attr("transform", d => `translate(${d.y},${d.x})`);
node.append("circle")
.attr("fill", d => d.children ? "#555" : "#999")
.attr("r", 2.5);
node.filter(d => d.data.name).append("text")
.attr("dy", "0.31em")
.attr("x", d => d.children ? -6 : 6)
.attr("text-anchor", d => d.children ? "end" : "start")
.text(d => {
const name = d.data.name, i = name.indexOf(",");
return i > 0 ? name.slice(0, i) : name;
})
.filter(d => d.children)
.clone(true).lower()
.attr("stroke", "white")
.attr("stroke-width", 3);
return svg.node();
}