Skip to content

Commit

Permalink
histogram: deal with the degenerate domain without throwing an except…
Browse files Browse the repository at this point in the history
…ion.

A histogram with a domain that has an extent of exactly 0 currently causes
the generated histogram to barf with an "undefined does not have .y" exception.

In order to avoid clients having to special case this degenerate case, modified
the loop so that the empty array is returned instead, in this case.

try {
    var
        scale=d3.scale.linear().domain([0,0]);

    d3.layout.histogram().bins(scale.ticks(3))([0]);
    console.log("ok");
} catch (e) {
    console.log("failed");
    throw e;
}

Signed-off-by: Jon Seymour <[email protected]>
  • Loading branch information
jonseymour committed Mar 23, 2012
1 parent 1196f55 commit bf151c2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/layout/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ d3.layout.histogram = function() {
x = values[i];
if ((x >= range[0]) && (x <= range[1])) {
bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
bin.y += k;
bin.push(data[i]);
if (bin) {
bin.y += k;
bin.push(data[i]);
}
}
}

Expand Down

0 comments on commit bf151c2

Please sign in to comment.