function dodgeAttr(selection, name, value, separation) {
console.log(selection.data(), "selection", name, value);
const V = dodge(selection.data().map(value), separation);
selection.attr(name, (_, i) => V[i]);
function dodge(V, separation, maxiter = 10, maxerror = 1e-1) {
console.log(V);
const n = V.length;
if (!V.every(isFinite)) throw new Error("invalid position");
if (!(n > 1)) return V;
let I = d3.range(V.length);
for (let iter = 0; iter < maxiter; ++iter) {
I.sort((i, j) => d3.ascending(V[i], V[j]));
let error = 0;
for (let i = 1; i < n; ++i) {
let delta = V[I[i]] - V[I[i - 1]];
if (delta < separation) {
delta = (separation - delta) / 2;
error = Math.max(error, delta);
V[I[i - 1]] -= delta;
V[I[i]] += delta;
}
}
if (error < maxerror) break;
}
return V;
}
}