chartBubble = {
let width = 975;
let height = 610;
const svg = d3.create("svg")
.attr("viewBox", [0,0, width, height]);
const state = svg.append("g")
.selectAll("path")
.data(topojson.feature(us, us.objects.states).features)
.join("path")
.attr("fill", d => color(data.get(d.properties.name)))
.attr("d", path)
.attr("cursor", "pointer");
state
.append("title")
.text(d => `${d.properties.name}
${decimal(data.get(d.properties.name))} Acres`);
state
.on('mouseover.color', function() {
d3.select(this)
.attr('stroke', '#fff')
.attr('fill-opacity', 0.5);
})
.on('mouseout.color', function() {
d3.select(this)
.attr('stroke', null)
.attr("fill-opacity", 1);
});
// state lines
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-width", 0.5)
.attr("stroke-linejoin", "round")
.attr("d", path);
// bubble map
const bubble = svg.append("g")
.selectAll("circle")
.data(data_bub
.filter(d => d.firesize)
.sort((a, b) => d3.descending(a.firesize, b.firesize)))
.enter()
.append("circle")
.attr("r", d => radius(d.firesize))
.attr("fill", "black")
.attr("fill-opacity", 0.6)
.attr("stroke", "#fff")
.attr("stroke-width", 0.5)
.attr("cursor", "pointer")
.attr("transform", d => `translate(${d})`);
bubble
.append("title")
.text(d => `Name: ${d.name}
Size: ${format(d.firesize)} Acres
Dates: ${formatdate(d.ddate)} thru ${formatdate(d.cdate)}`);
bubble
.on('mouseover.size', function (d, i) {
d3.select(this).transition()
.duration('100')
.attr("r", d => radius(d.firesize)*1.2);
})
.on('mouseover.color', function() {
d3.select(this)
.attr('stroke', '#fff')
.attr('stroke-width', 2)
.attr('fill-opacity', 0.8);
})
.on('mouseout.size', function (d, i) {
d3.select(this).transition()
.duration('200')
.attr("r", d => radius(d.firesize))
})
.on('mouseout.color', function() {
d3.select(this)
.attr('stroke', '#fff')
.attr('stroke-width', 0.5)
.attr('fill-opacity', 0.6);
});
// choropleth legend
svg.append("g")
.attr("transform", "translate(610,20)")
.append(() => legend({color,
title: 'Total Acres Burned',
width: 250,
tickFormat: '.0s'}));
// bubble legend
const legend_b = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(915,608)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data(radius.ticks(4).slice(1))
.join("g");
legend_b.append("circle")
.attr("fill", "none")
.attr("stroke", "black")
.attr("stroke-width", 0.5)
.attr("cy", d => -radius(d))
.attr("r", radius);
legend_b.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(radius.tickFormat(4, "s"));
return svg.node();
}