Public
Edited
Mar 11, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
f = (zs) => {
let batches = [];
for (let z of zs) {
batches.push({ size: 1, mean: z });
while (batches.length > 1) {
let b = batches[batches.length - 2];
let c = batches[batches.length - 1];
if (b.mean < c.mean) break;
b.mean = (b.mean * b.size + c.mean * c.size) / (b.size + c.size);
b.size = b.size + c.size;
batches.pop();
}
}
let xs = [];
for (const batch of batches)
for (let i = 0; i < batch.size; i++) xs.push(batch.mean);
return xs;
}
Insert cell
Insert cell
g = (ys, radius) => {
let zs = ys.map((y, i) => y - i * radius * 2);
return f(zs).map((x, i) => x + i * radius * 2);
}
Insert cell
Insert cell
occlusionY = (options) =>
Plot.initializer(
options,
(
data,
facets,
{ y: { value: Y }, text: { value: T } },
{ y: sy },
dimensions,
context
) => {
let RADIUS = 5.5;
for (const index of facets) {
// Sort the nodes and call the label placement function g
const nodes = Array.from(index, (i) => ({
y: sy(Y[i]),
i
}));
nodes.sort((a, b) => a.y - b.y);
const positions = g(
nodes.map((d) => d.y),
RADIUS
);
positions.forEach((p, i) => {
Y[nodes[i].i] = p;
});
}
return { data, facets, channels: { y: { value: Y } } };
}
)
Insert cell
Insert cell
Insert cell
receipts = FileAttachment("gdp-receipts.csv").csv({ typed: true })
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