chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
let zupanije = svg
.selectAll('path')
.data(sortedFeatures)
.enter()
.append("path")
.attr("fill", "white")
.attr('class', d => d.properties.NAZIV.replace(/\s/g, ""))
.attr("stroke", "steelblue")
.attr("stroke-width", 1.2)
.attr("stroke-linejoin", "round")
.attr("d", d => path(d));
let transitions = [];
sortedFeatures.forEach((d, i) => {
transitions.push(
svg
.select(`.${d.properties.NAZIV.replace(/\s/g, "")}`)
.transition()
.delay(d => 1000 + i * 100)
.duration(2000)
.attr('transform', d => {
let centroid = path.centroid(d);
let row = Math.floor(i / numCols);
let col = i % numCols;
return `translate(${col * colWidth +
colWidth / 2 -
centroid[0]},${row * rowHeight + rowHeight / 2 - centroid[1]})`;
})
.style('fill', 'lightsteelblue')
.end()
);
});
Promise.all(transitions).then(() => {
svg
.selectAll('text')
.data(sortedFeatures)
.enter()
.append('text')
.style('font-size', 11)
.style('fill', 'steelblue')
.style('text-anchor', 'middle')
.attr('transform', (d, i) => {
let row = Math.floor(i / numCols) + 1;
let col = i % numCols;
return `translate(${col * colWidth + colWidth / 2},${row * rowHeight -
10})`;
})
.text((d, i) => {
let name = d.properties.NAZIV.toLowerCase();
return name.charAt(0).toUpperCase() + name.slice(1);
})
.attr('opacity', 0)
.transition()
.duration(1000)
.attr('opacity', 1);
});
return svg.node();
}