vote_bubble_map = {
const svg = d3.select(DOM.svg(width, height)).style("background", "white");
addDefsAndBlurs(svg);
const canvasRectWidth = width * 0.73;
svg
.append("rect")
.attr("width", width)
.attr("x", 0)
.attr("y", 0)
.attr("height", height)
.attr("fill", "#FFF8E7");
const labelOffset = 120;
svg
.append("text")
.attr("x", labelOffset)
.attr("y", 40)
.attr("fill", "#546767")
.attr("text-anchor", "start")
.attr("font-size", 24)
.style("opacity", 1)
.text(`Lokalni izbori 2021. (prvi krug)`);
svg
.append("text")
.attr("x", labelOffset)
.attr("y", 65)
.attr("fill", "#546767")
.attr("text-anchor", "start")
.attr("font-size", 16)
.style("opacity", 1)
.text(`Veličina kruga odgovara broju glasova relativnog pobjednika.`);
let credit = svg
.append("text")
.attr("x", labelOffset)
.attr("y", 85)
.attr("fill", "#546767")
.attr("text-anchor", "start")
.attr("font-size", 12)
.style("opacity", 1)
.text(`Autor: @velimirgasp`);
const mapGroup = svg.append("g").attr("transform", "translate(30,50)");
const paths = mapGroup
.selectAll("path")
.data(topojson.feature(croatia, croatia.objects["hrvatska"]).features)
.enter()
.append("path")
.attr("fill", "white")
.attr("stroke", "lightgrey")
.attr("stroke-linejoin", "round")
.attr("d", path);
mapGroup
.selectAll("circle")
.data(municipalities)
.enter()
.append("circle")
.attr("opacity", 0.7)
.attr("naziv", (d) => d.properties.name)
.attr("fill", (county, index) => {
if (!county.properties.votes.pobjednik) {
console.log("nemam:", county);
return "none";
} else if (
county.properties.votes.pobjednik.stranke.indexOf("HDZ") > -1
) {
return "grey";
} else if (
county.properties.votes.pobjednik.stranke.indexOf("SDP") > -1
) {
return "grey";
} else if (
county.properties.votes.pobjednik.stranke.indexOf("IDS") > -1
) {
return "grey";
} else {
return "#d09e00";
}
})
.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) => {
let retval = d.properties.radius;
if (!retval || retval < 1) console.log("nemam radius", d);
return retval;
})
.style("stroke", "white")
.style("stroke-width", 0.4)
.append("title")
.text((d) => {
let retval = d.properties.name;
if (d.properties.votes.pobjednik) {
retval += `
${d.properties.votes.pobjednik.stranke}
${d3.format(",")(d.properties.votes.pobjednik.glasova)}`;
}
return retval;
});
return svg.node();
}