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) {
const nodes = Array.from(index, (i) => ({
y: sy(Y[i]),
i
}));
nodes.sort((a, b) => a.y - b.y);
let boxes = [];
nodes.forEach((node, idx) => {
boxes.push({ y: node.y, i0: idx, i1: idx });
while (boxes.length > 1) {
let b = boxes[boxes.length - 2];
let c = boxes[boxes.length - 1];
let d = overlapDistance(b, c, RADIUS);
if (d < 0) break;
const sb = boxSize(b),
sc = boxSize(c);
b.y += sc * RADIUS - (d * sc) / (sb + sc);
b.i1 = c.i1;
boxes.pop();
}
});
for (const b of boxes) {
let y = b.y - RADIUS * (boxSize(b) - 1);
for (let idx = b.i0; idx <= b.i1; idx++) {
let node = nodes[idx];
Y[node.i] = y;
y += RADIUS * 2;
}
}
}
return { data, facets, channels: { y: { value: Y } } };
}
)