function growUp({
delay = 0,
duration = 250,
stagger = duration * 2,
ease = d3.easeCubicInOut,
...options
} = {}) {
return {
...options,
render(index, scales, values, dimensions, context, next) {
const g = next(index, scales, values, dimensions, context);
const R = g.querySelectorAll("rect");
const T = Float64Array.from(R, () => 1);
const Y = Float64Array.from(R, (r) => r.getAttribute("y"));
const H = Float64Array.from(R, (r) => r.getAttribute("height"));
const start = performance.now();
(function tick(now) {
let tt = false;
for (let i = 0, n = R.length; i < n; ++i) {
const t = ease(Math.max(0, Math.min(1, (now - start - (delay + stagger * i / n)) / duration)));
if (t < 1) tt = true;
if (T[i] === t) continue;
R[i].setAttribute("y", Y[i] + H[i] * (1 - t));
R[i].setAttribute("height", H[i] * t);
T[i] = t;
}
if (tt) requestAnimationFrame(tick);
})(start);
return g;
}
};
}