From bf151c2877f5a19f2ae2d79651b87fa940418c41 Mon Sep 17 00:00:00 2001 From: Jon Seymour Date: Fri, 23 Mar 2012 23:30:08 +1100 Subject: [PATCH] histogram: deal with the degenerate domain without throwing an exception. 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 --- src/layout/histogram.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/layout/histogram.js b/src/layout/histogram.js index 3ef2483a..9438bb00 100644 --- a/src/layout/histogram.js +++ b/src/layout/histogram.js @@ -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]); + } } }