Published
Edited
Oct 5, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function splitRectangle(rect, splitProbability = prob) {
if (CSRandom.value() >= 1 - splitProbability) {
let rects;
// Split horizontally
if (CSRandom.value() >= wght) {
rects = splitRectangleAcrossAxis('x', rect);
} else {
// split vertically
rects = splitRectangleAcrossAxis('y', rect);
}
if (rects) {
return rects.map(r => splitRectangle(r)).flat();
}
}
return [rect];
}
Insert cell
function splitRectangleAcrossAxis(axis, rect) {
console.log(axis);
const { u, v, w, h } = rect;

if (axis === 'x' && w > uvCellSize) {
const splitSize = CSRandom.value() > 0.5 ? uvCellSize : w - uvCellSize;
return [
{ u, v, w: splitSize, h },
{ u: u + splitSize, v, w: w - splitSize, h }
];
}
if (axis === 'y' && h > uvCellSize) {
const splitSize = CSRandom.value() > 0.5 ? uvCellSize : h - uvCellSize;
return [
{ u, v, w, h: splitSize },
{ u, v: v + splitSize, w, h: h - splitSize }
];
}
}
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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