Public
Edited
Jul 5, 2024
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
ensembles = cstParseRows(source, d3.autoType).children
Insert cell
groupes = Array.from(
ensembles,
({ 0: secteur, children }) =>
children.map(([groupe, nombre, color]) => ({
secteur,
groupe,
nombre,
color
}))
).flat()
Insert cell
total = d3.sum(groupes, (d) => d.nombre)
Insert cell
Insert cell
longueur = d3.scaleLinear([0, travees - 1], [ratio, 100])
Insert cell
function repartition(travees, longueur, total) {
let x = 1;
let step = 1;
let sum;
let n = 0;

const sieges = (l) => Math.round(l / x);

do {
sum = d3.sum(d3.range(travees).map(longueur).map(sieges));
if (sum === total) break;
if (sum < total) x /= Math.exp(step);
else x *= Math.exp(step);
step = step * 0.7;
} while (n++ < 10000); // fail safe

return { x, n, step, sum };
}
Insert cell
solution = repartition(travees, longueur, total)
Insert cell
x = solution.x
Insert cell
seats = {
const sieges = (l) => Math.round(l / x);
const seats = d3.sort(
d3
.range(travees)
.flatMap((travee) => {
const n = sieges(longueur(travee));
return d3.range(n).map((i) => ({ i, n, travee }));
})
.map(({ i, n, travee }) => {
const [x, y] = d3.pointRadial(
-Math.PI / 2 + Math.PI * (i / (n - 1)),
longueur(travee)
);
return { x, y, travee };
}),
({ x, y }) => Math.atan2(y, x)
);

// appliquer la répartition des sièges
let t = 0;
for (const { groupe, nombre } of groupes) {
seats.slice(t, t + nombre).forEach((d) => (d.groupe = groupe));
t += nombre;
}

return seats;
}
Insert cell
color = d3
.scaleOrdinal()
.domain(groupes.map((d) => d.groupe))
.range(groupes.map((d) => d.color))
Insert cell
import { cstParseRows } from "@mbostock/comma-separated-tree"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more