chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
svg.append("g")
.call(grid);
svg.append("g")
.attr("stroke", "white")
.selectAll("circle")
.data(nested)
.join("circle")
.attr("class", "bubbles")
.sort((a, b) => d3.descending(a.value.fatalities, b.value.fatalities))
.attr("cx", d => x(d.value.victims))
.attr("cy", d => y(d.value.occurrences))
.attr("r", d => z(d.value.fatalities))
.attr("fill", d => myColor(d.value.victims))
.attr("fill-opacity", 0.6)
.on("mouseover", function(d){
d3.select(this)
.style("cursor", "pointer")
.attr("stroke-width", 3)
.attr("stroke","#FFF5B1");
const rect = this.getBoundingClientRect();
showTooltip(d, rect.x, rect.y);
})
.on("mouseout", function(d){
d3.select(this)
.style("cursor", "default")
.attr("stroke-width", 1)
.attr("stroke","white");
hideTooltip();
});
svg.append("g")
.selectAll('text')
.data(nested.filter(function (n){return n.value.victims > 90;}))
.enter()
.append('text')
.attr('x', d => x(d.value.victims -15))
.attr('y', d => y(d.value.occurrences))
.attr('font-family', 'sans-serif')
.attr("font-size", 12)
.attr('fill', 'black')
.text(d => d.key);
console.log(svg.selectAll('text'))
return svg.node();
}