Plot.plot((() => {
const n = 5;
data.forEach(function (d) {
if (data_routes.filter(e => e.departement == d.departement)[0]){
d['proportion_pistes'] = d.pistes / data_routes.filter(e => e.departement == d.departement)[0].total
}
else{
console.log(d.departement)
d['proportion_pistes'] = 0
}
})
let this_variable = select_departement_val == "Valeur absolue" ? 'pistes' : 'proportion_pistes';
const keys = Array.from(d3.union(data.filter(D=> D.date >= d3.max(data, d => d.date)).sort(function (a,b) { return b[this_variable] - a[this_variable]}).map((d) => d.departement)));
const index = new Map(keys.map((key, i) => [key, i]));
const fx = (key) => index.get(key) % n;
const fy = (key) => Math.floor(index.get(key) / n);
const maxscale = d3.max(data, d=>d[this_variable]);
console.log(keys)
console.log(index)
return {
height: 1000,
axis: null,
grid:false,
y: {insetTop: 10},
fx: {padding: 0.20},
marks: [
Plot.frame({fill:"red"}),
Plot.areaY(data, {
x: "date",
y: this_variable,
fx: (d) => fx(d.departement),
fy: (d) => fy(d.departement),
fill:"green"
}),
Plot.text(keys, {fx, fy, frameAnchor: "top-left", dx: 0, dy: 6,
fill:"white", fontSize:14}),
]
};
})())