Inside the function updateMapColor
, the colors of a world map change based on the input year. I have tried to animate the color change over multiple years by calling updateMapColor
, but it is not working.
Do I need to incorporate setInterval
? If so, could someone please explain why? What might be causing the issue?
d3.select('body').append('button').attr({
class: "button",
id: "animateMap"
})
.text("Animate the map")
.on("click", function (d) {
for (i = 0; i < yearArray.length; i++) {
updateMapColor(yearArray[i]);
}
})
var updateMapColor = function (y) {
year = y;
var rankingList = {};
coloredWorldMap.transition().duration(700).attr('fill', function (d) {
a = d;
x = d3.values(tennis).filter(function (d) {
return (d.DATE == year);
});
rankingList = x;
x = d3.values(x).filter(function (d) {
return (d.COUNTRY_ID == a.id);
});
if (x.length != 0) {
if (x[0].COUNT == 0) {
return "#fff";
}
else {
return colorScale(x[0].COUNT);
}
}
else {
return '#fff';
}
return colorScale(x[0].COUNT);
});
}