map = {
let width = 720;
let height = 360;
let mode = 0;
let svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("width", width)
.attr("height", height);
let bg = svg
.append('rect')
.attr("x", 0)
.attr("y", 0)
.attr("width", width)
.attr("height", height);
let longitudeScale = d3
.scaleLinear()
.domain([-150, -60])
.range([0, width]);
let latitudeScale = d3
.scaleLinear()
.domain([10, 55])
.range([height, 0]);
let monthScale = d3
.scaleLinear()
.domain([1, 12])
.range([0, 1]);
svg
.selectAll('.butterflies')
.data(monarchsNA2017)
.enter()
.append("circle")
.attr("cx", d => longitudeScale(parseFloat(d.decimalLongitude)))
.attr("cy", d => latitudeScale(parseFloat(d.decimalLatitude)))
.attr('r', 1.4)
.attr('fill', d => d3.interpolatePlasma(monthScale(parseInt(d.month))))
.attr('opacity', .5)
.attr('class', 'butterflies');
svg.on('click', function() {
if (mode == 0) {
svg
.selectAll('.butterflies')
.data(monarchsNA2017)
.transition()
.duration(5000)
.delay((d, i) => i * 100)
.attr('cx', d => width / 2)
.attr('fill', d =>
d3.interpolateViridis(monthScale(parseInt(d.month)))
);
mode = 1;
} else {
svg
.selectAll('.butterflies')
.data(monarchsNA2017)
.transition()
.duration(5000)
.delay((d, i) => i * 100)
.attr("cx", d => longitudeScale(parseFloat(d.decimalLongitude)))
.attr('fill', d => d3.interpolatePlasma(monthScale(parseInt(d.month))));
mode = 0;
}
});
return svg.node();
}