chart = {
const svg = d3.create("svg")
.classed("chart_svg", true)
.attr("viewBox", [0, 0, width, height2]);
var circles = svg.selectAll("circle")
.data(data, function(d){ return d ;});
const circlesEnter = circles.enter().append("circle")
.attr("r", function(d, i){ return d.r; })
.attr("cx", function(d, i){ return 250 })
.attr("cy", function(d, i){ return 175 + 25 * i + 2 * i ** 2; })
.style("fill", function(d, i){ return "#F45656";})
.style("stroke", function(d, i){ return "#F45656";})
.style("stroke-width", 10)
.style("pointer-events", "all")
.call(d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended));
circles = circles.merge(circlesEnter)
var titles = svg.selectAll('.title')
.data(centerScale.domain());
function ticked() {
circles
.attr("cx", function(d){ return d.x; })
.attr("cy", function(d){ return d.y; });
}
simulation
.nodes(data)
.on("tick", ticked);
function dragstarted(d,i) {
if (!d3.event.active) simulation.alpha(1).restart();
d.fx = d.x;
d.fy = d.y;
}
function dragged(d,i) {
d.fx = d3.event.x;
d.fy = d3.event.y;
}
function dragended(d,i) {
if (!d3.event.active) simulation.alphaTarget(0);
d.fx = null;
d.fy = null;
var me = d3.select(this)
me.classed("selected", !me.classed("selected"))
d3.selectAll("circle.selected")
.style("fill", "none")
}
function groupBubbles() {
hideTitles();
simulation.force('y', d3.forceY().strength(forceStrength).y(height2/ 2));
simulation.alpha(1).restart();
}
return svg.node();
}