function bars(svg) {
let bar = svg.append("g")
.attr("fill-opacity", 0.8)
.selectAll("rect");
return ([date, data], transition) => bar = bar
.data(data.slice(0, n), d => d.name)
.join(
enter => enter.append("rect")
.attr("fill", function(d) {
if (d.name == "Coal") {
return "#2F3235";
} else if (d.name == "Renewable energies") {
return "#B3E024";
} else if (d.name == "Electricity") {
return "#3676B0";
} else if (d.name == "Natural gases") {
return "#E0B900";
} else if (d.name == "Petroleum Products") {
return "#994952";
} else if (d.name == "District heating") {
return "#0096B1";
} else if (d.name == "Wood") {
return "#996633";
} else if (d.name == "Garbage and industrial waste") {
return "#666F77";
} else if (d.name == "PtX") {
return "#EFBACA";
}
})
.attr("height", y.bandwidth())
.attr("x", x(0))
.attr("y", d => y((prev.get(d) || d).rank))
.attr("width", d => x((prev.get(d) || d).value) - x(0)),
update => update,
exit => exit.transition(transition).remove()
.attr("y", d => y((next.get(d) || d).rank))
.attr("width", d => x((next.get(d) || d).value) - x(0))
)
.call(bar => bar.transition(transition)
.attr("y", d => y(d.rank))
.attr("width", d => x(d.value) - x(0)));
}