map = {
const svg = d3
.create("svg")
.attr("width", w)
.attr("height", h)
.attr("viewBox", [0, 0, w, h])
.attr("class", "italy");
let margin = 0;
svg
.append("path")
.datum(provinces)
.attr("d", path);
const g = svg
.selectAll(".subunit")
.data(provinces.features)
.enter()
.append("path")
.attr("class", function(d) {
return "subunit";
})
.attr("d", path);
const bubble = svg
.selectAll(".bubble")
.data(data[mutable index])
.enter()
.append("circle")
.attr("transform", function(d) {
return "translate(" + projection([d.long, d.lat]) + ")";
})
.attr("class", "bubble")
.attr("fill-opacity", 0.5)
.attr("fill", "red")
.attr("r", d => radius(+d.totale_casi));
bubble.append("title");
const tip = svg
.append("text")
.style("pointer-events", "none")
.style("text-anchor", "middle");
bubble.on("mouseenter", event => {
const value = event.target.__data__;
const pointer = d3.pointer(event, this);
tip
.attr("x", 300)
.attr("y", 500)
.text(
d =>
`${value.denominazione_provincia}: ${numFormat(
+value.totale_casi
)} cases`
);
});
bubble.on("mouseout", event => {
tip.text("");
});
const wrapper = html`<div class="wrapper"></div>`;
wrapper.append(svg.node());
const zoom = d3
.zoom()
.scaleExtent([0.5, 4])
.on("zoom", zoomed);
function zoomed({ transform }) {
g.attr("transform", transform);
svg.attr("transform", transform);
}
svg.call(zoom);
return Object.assign(wrapper, {
update(i) {
const t = svg
.transition()
.duration(i === 0 ? 0 : delay)
.ease(d3.easeLinear);
bubble
.data(data[i])
.call(b => {
b.transition(t)
.attr("fill", "red")
.attr("r", d => radius(+d.totale_casi));
})
.select("title")
.text(
d =>
`${d.denominazione_provincia}: ${numFormat(+d.totale_casi)} cases`
);
}
});
}