{
const svg = d3.select(DOM.svg(width, height))
const circle_radius = 12;
const collide_radius = 17;
const x = d3.scaleLinear()
.domain([0, d3.max(data, d => d.year_2015)]).nice()
.range([margin.left, width - margin.right])
const y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.year_2015)]).nice()
.range([ margin.top, height - margin.bottom])
let simulation = d3.forceSimulation().nodes(data)
.force('center', d3.forceCenter(width/2,height/2))
.force('charge', d3.forceManyBody().strength(2))
.force('collision', d3.forceCollide().radius( d => collide_radius))
.on('tick',ticked)
let selection = svg.selectAll('g').data(data)
let enterSelection = selection.enter().append('g')
let circles = enterSelection.append('circle')
.attr('fill-opacity', 0)
.attr('stroke', d => colorScale(d.year_2015))
.attr('r', circle_radius)
let text = enterSelection.append('text')
.text(d => d.country).attr('dy', '.25em')
.attr("text-anchor", "middle")
.attr('fill', d => colorScale(d.year_2015))
selection = selection.merge(enterSelection)
simulation.nodes(data)
.force('x', d3.forceX( ).x( d => x(d.year_2015)))
.force('y', d3.forceY( ).y( d => y(d.year_2015)))
function ticked(){
selection.attr("transform", function(d) {return "translate(" + d.x + "," + d.y + ")" });
}
return svg.node( )
}