vote_map_animation_to_scatter = {
const svg = d3
.select(DOM.svg(width, height))
.style("width", "100%")
.style("height", "auto");
svg.append("g").attr("class", "axis").style("opacity", 0).call(xAxis);
svg.append("g").attr("class", "axis").style("opacity", 0).call(yAxis);
svg
.append("g")
.selectAll("circle")
.data(municipalities)
.enter()
.append("circle")
.attr("opacity", 0)
.attr("id", (d) => `circle-${d.rank}`)
.attr("fill", (county) => {
if (!county.properties.votes.kgk || !county.properties.votes.zoky) {
return "white";
} else if (county.properties.votes.kgk > county.properties.votes.zoky) {
return color(
county.properties.votes.kgk / county.properties.votes.count
);
} else {
return color(
-county.properties.votes.zoky / county.properties.votes.count
);
}
})
.attr("cx", (d) => (d.properties.centroid ? d.properties.centroid[0] : 0))
.attr("cy", (d) => (d.properties.centroid ? d.properties.centroid[1] : 0))
.attr("r", (d) => d.properties.radius)
.style("stroke", "white")
.append("title")
.text((d) => {
if (d.properties.jls.dohodak == null) return "";
else {
return [
d.properties.name,
`Dohodak ${d3.format(".2s")(d.properties.jls.dohodak)}`,
`Obrazovanje ${d3.format(".2f")(d.properties.jls.obrazovanje)} `,
`Zoky ${d3.format(".1%")(
d.properties.votes.zoky / d.properties.votes.count
)} glasova`,
`KGK ${d3.format(".1%")(
d.properties.votes.kgk / d.properties.votes.count
)} glasova`
].join("\n");
}
});
let opcine = svg
.append("g")
.selectAll("path")
.data(municipalities)
.enter()
.append("path")
.attr("id", (d) => `path-${d.rank}`)
.attr("class", "countyShape")
.attr("fill", (county) => {
if (!county.properties.votes.kgk || !county.properties.votes.zoky) {
return "white";
} else if (county.properties.votes.kgk > county.properties.votes.zoky) {
return color(
county.properties.votes.kgk / county.properties.votes.count
);
} else {
return color(
-county.properties.votes.zoky / county.properties.votes.count
);
}
})
.attr("d", path)
.attr("stroke", "white")
.attr("stroke-width", 0.5);
opcine
.transition()
.delay((d) => d.rank * 2)
.duration(4000)
// .style('opacity', 0.2)
.attrTween("d", function (d, i) {
//return flubber.toCircle(path(d), d.x, d.y, d.properties.radius, {
return flubber.toCircle(
path(d),
d.properties.centroid[0],
d.properties.centroid[1],
d.properties.radius,
{
maxSegmentLength: 2
}
);
})
.on("end", (transition, d) => {
// console.log(transition, d);
d3.select(`#path-${d}`).lower();
d3.select(`#circle-${d}`).attr("opacity", 1);
})
.remove();
svg
.selectAll("circle")
.transition()
.delay((d) => {
// console.log('tranz circle', d);
return 7000 + d.rank * 2;
})
.duration(5000)
//.style('opacity', 1)
.attr("r", (d) =>
d.properties.jls.razvijenost_rank == null ? 0 : d.properties.radius
)
.attr("cx", (d) => x(d.properties.jls.obrazovanje))
.attr("cy", (d) => y(d.properties.jls.dohodak));
svg
.selectAll(".axis")
.transition()
.delay((d) => {
return 7000;
})
.duration(5000)
.style("opacity", 1);
return svg.node();
}