Public
Edited
Apr 7, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const svg = d3.select(DOM.svg(width, height));
const gCenter = svg.append("g")
.classed("center", true)
.attr("transform", `translate(${center.x},${center.y})`);

const simulation = d3.forceSimulation(data.nodes)
.force("center", d3.forceCenter())
.force("collide", d3.forceCollide().radius(radius).strength(collideStrength))
.force("links", d3.forceLink(data.links))
.force("charge", d3.forceManyBody());

console.log(data)

gCenter.selectAll("line")
.data(data.links)
.join("line")
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y)
.attr("stroke", "#ccc")
.attr("stroke-width", d => d.value);

gCenter.selectAll("circle")
.data(data.nodes)
.join("circle")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", d => d.value)
return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more