More efficient degenerate bin check.

This commit is contained in:
Mike Bostock 2012-03-29 22:07:11 -07:00
Родитель 80628239d5
Коммит 39a74f49ae
4 изменённых файлов: 19 добавлений и 15 удалений

14
d3.v2.js поставляемый
Просмотреть файл

@ -5894,12 +5894,14 @@ d3.layout.histogram = function() {
}
// Fill the bins, ignoring values outside the range.
i = -1; while(++i < n) {
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 (m > 0) {
i = -1; while(++i < n) {
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]);
}
}
}

4
d3.v2.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -24,11 +24,11 @@ d3.layout.histogram = function() {
}
// Fill the bins, ignoring values outside the range.
i = -1; while(++i < n) {
x = values[i];
if ((x >= range[0]) && (x <= range[1])) {
bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
if (bin) {
if (m > 0) {
i = -1; while(++i < n) {
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]);
}

Просмотреть файл

@ -69,8 +69,10 @@ suite.addBatch({
{x: 2, y: 2, dx: 1}
]);
},
"can handle degenerate domain": function(histogram) {
var h = histogram().bins(d3.scale.linear().domain([0,0]).ticks(3));
"returns the empty array with fewer than two bins": function(histogram) {
var h = histogram().bins([1]);
assert.deepEqual(h([0]), []);
var h = histogram().bins([]);
assert.deepEqual(h([0]), []);
}
}