chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
geojson.features = geojson.features.sort(
(a, b) => +a.properties.SIFRA - +b.properties.SIFRA
);
geojson.features.forEach(zupanija => (zupanija.properties.selected = false));
let zupanije = svg
.selectAll('path')
.data(geojson.features)
.enter()
.append("path")
.attr("fill", "steelblue")
.style("cursor", "pointer")
.attr('class', d => d.properties.NAZIV)
.attr("stroke", "white")
.attr("stroke-width", 1)
.attr("stroke-linejoin", "round")
.attr("d", d => path(d))
.on("click", (event, d) => {
d.properties.selected = true;
d3.select(`.${d.properties.NAZIV}`).attr('fill', 'lightsteelblue');
transform();
});
var transform = () => {
let transitions = [];
transitions.push(
svg
.selectAll('path')
.transition()
.delay((d, i) => 500 + i * 100)
.duration(2000)
.attrTween('d', function(d, i) {
return flubber.toRect(
path(d),
xOffset,
y(d.properties.NAZIV),
lengthScale(geojson.features[i].properties.length),
barHeight
);
})
.end()
);
Promise.all(transitions).then(() => {
const gy = svg.append("g").call(yAxis);
let bars = svg
.append("g")
.selectAll("rect")
.data(geojson.features)
.join("rect")
.attr("fill", d =>
d.properties && d.properties.selected ? "lightsteelblue" : "steelblue"
)
.attr('opacity', 1)
.style("mix-blend-mode", "multiply")
.attr("x", xOffset)
.attr("y", (d, i) => y(d.properties.NAZIV))
.attr("width", (d, i) =>
lengthScale(geojson.features[i].properties.length)
)
.attr("height", barHeight);
svg
.selectAll('path')
.remove();
reorder(bars, gy);
});
};
function reorder(bars, gy) {
geojson.features.sort((a, b) => a.properties.length - b.properties.length);
y.domain(geojson.features.map(d => d.properties.NAZIV));
const t = svg.transition().duration(1000);
bars
.data(geojson.features, d => d.properties.NAZIV)
.order()
.transition(t)
.delay((d, i) => i * 20)
.attr("y", d => {
console.log('idem za ', d, ' postaviti y na ', y(d.properties.NAZIV));
return y(d.properties.NAZIV);
});
gy.transition(t)
.call(yAxis)
.selectAll(".tick")
.delay((d, i) => i * 20);
return svg.node();
}
return svg.node();
}