mbostock/d3 — Issue #493: Zero Duration race condition causes NaN problem.
Author: the-jxc
Created: 2012-02-07 03:07:36+00:00
State: open

The following code would periodically cause **Error: Invalid value for attribute cy="NaN"**

var c = clip_group.selectAll ("circle." + bcls).data (points);
c.transition ().duration (this.config.transition)
.attr ("cx", function (d, i) { return x (d.x - fmi + 0.5); })
.attr ("cy", function (d, i) { return y (d.y); })

The problem appears to be in the transition tick handler. Specifically:

function tick(elapsed) {
if (lock.active !== id) return stop();

var t = (elapsed - delay) / duration,
e = ease(t),
n = tweened.length;

If duration is zero, this causes a divide by zero, giving NaN. It didn't happen all the time. I'm guessing that sometimes the timing meant that the tick didn't always fire. But when it did, bad things would happen.

A simple way to make this code more robust would be:

var t = (duration == 0) ? 1 : ((elapsed - delay) / duration),
e = ease(t),
n = tweened.length;

This is around line 2042 or so in d3.js.