function staggered({ render, ...options } = {}) {
let facets;
let G = new Map();
return Plot.transform(
{
...options,
render: (index, scales, values, dimensions, context, next) => {
const fi = index.fi ?? 0;
if (!G.has(fi)) {
const g = (render ?? next)(
facets[fi],
scales,
values,
dimensions,
context,
render ? next : undefined
);
G.set(fi, g);
if (fi === 0) {
const style = context.document.createElement("style");
style.textContent =
".pointed {font-size: 10px; font-weight: 700; fill: currentColor}";
g.append(style);
}
for (const node of g.childNodes) {
const i = node.__data__;
node.setAttribute("y", 9 * (i % 10));
}
}
const g = G.get(fi);
const test = new Set(index);
for (const node of g.childNodes) {
const i = node.__data__;
if (test.has(i)) node.classList.add("pointed");
else node.classList.remove("pointed");
}
return g;
}
},
(data, _facets) => ({ data, facets: (facets = _facets) })
);
}