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 <jon.seymour@gmail.com>
This commit is contained in:
Родитель
1196f55b43
Коммит
bf151c2877
|
@ -28,10 +28,12 @@ d3.layout.histogram = function() {
|
|||
x = values[i];
|
||||
if ((x >= range[0]) && (x <= range[1])) {
|
||||
bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
|
||||
if (bin) {
|
||||
bin.y += k;
|
||||
bin.push(data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bins;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче