Public
Edited
1 fork
16 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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more