chart = {
console.log(nodes);
const simulation = d3.forceSimulation(nodes)
.force('charge', d3.forceManyBody().strength(-10))
.force('center', d3.forceCenter(width /2, height /2))
.force('link', d3.forceLink().links(links).id(function(d,i) {
return d.name
}).distance(d=>linkScale(links[d.index].distance)));
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const link = svg.append("g")
.attr("stroke-opacity", 0.1)
.selectAll("line")
.data(links)
.join("line")
.attr("stroke", 'lightgrey')
.attr("stroke-width", '2');
const node = svg.append("g")
.attr("stroke", "#fff")
.attr("stroke-width", 1.5)
.selectAll("circle")
.data(nodes)
.join("circle")
.attr("r", 5)
.attr("fill", d=> { if(d.name === parameter.airport){return"orange"}
else{ return "lightblue" }
})
.call(drag(simulation));
var texts = svg.selectAll(".texts")
.data(nodes)
.join("text")
.attr("dy", -4)
.attr("font-family", "sans-serif")
.attr('font-size', '10px')
.attr('text-anchor', 'middle')
.text( d => d.name);
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);
texts
.attr("x", d => d.x)
.attr("y", d => d.y);
});
invalidation.then(() => simulation.stop());
return svg.node();
}