chart = {
data.nodes.forEach(d => {
d.import_count = data.links.filter(l => l.__proto__.target == d.id).length;
});
const simulation = d3.forceSimulation(data.nodes)
.force("link", d3.forceLink(data.links).id(d => d.id).distance(50).strength(2))
.force("charge", d3.forceManyBody().strength(d => -10-d.import_count*10))
.force("center", d3.forceCenter(width / 2, height / 2));
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("xlink", "http://www.w3.org/1999/xlink");
const s = 10;
svg
.append('defs')
.append('marker')
.attr('id', 'arrow')
.attr('viewBox', [0, 0, 20, 20])
.attr('refX', 20)
.attr('refY', 10)
.attr('markerWidth', 10)
.attr('markerHeight', 10)
.attr('orient', 'auto-start-reverse')
.append('path')
.attr('d', d3.line()([[0, 0], [0, 20], [20, 10]]))
.attr('fill', 'currentColor')
.attr('stroke', 'none');
const big_g = svg.append("g");
const link = big_g.append("g")
.attr("stroke", "#999")
.attr("fill", "#999")
.attr("stroke-opacity", 0.6)
.attr('marker-end', 'url(#arrow)')
.selectAll("line")
.data(data.links)
.join("line");
const g = big_g.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 1.5)
const node = g
.selectAll("a")
.data(data.nodes)
.join("a")
.attr("xlink:href", d => `https://pygae.github.io/lean-ga-docs/${d.path.join('/')}.html`)
.attr("target", "_blank")
.append('circle')
.attr("r", d => Math.sqrt((d.import_count + 1) * 16))
.attr("fill", color)
.call(drag(simulation));
d3.zoom().on("zoom", (event) => big_g.attr("transform", event.transform))(svg);
node.append("title")
.text(d => d.id);
simulation.on("tick", () => {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
node
.attr("cx", d => d.x)
.attr("cy", d => d.y);
});
invalidation.then(() => simulation.stop());
return svg.node();
}