The outliers were being incorrectly excluded when computing the quartiles.  I've
also added a +/-1.5 IQR whiskers computation for the Morley-Michelson example,
so it replicates the R plot exactly.
This commit is contained in:
Jason Davies 2011-04-13 23:40:00 +01:00
Родитель f9569c5aac
Коммит 12663738d9
4 изменённых файлов: 15 добавлений и 5 удалений

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

@ -17,12 +17,12 @@ d3.chart.box = function() {
var len = d.length,
min = d[0],
max = d[len-1],
whiskerIndices = whiskers.call(this, d, i),
quartileData = quartiles(d),
whiskerIndices = whiskers.call(this, d, i, quartileData),
whiskerData = whiskerIndices.map(function(i) { return d[i]; }),
firstWhisker = whiskerIndices[0],
lastWhisker = whiskerIndices[whiskerIndices.length - 1],
whiskerRange = lastWhisker - firstWhisker,
quartileData = quartiles(d.slice(firstWhisker, lastWhisker)),
outliers = d.slice(0, firstWhisker).concat(d.slice(lastWhisker + 1, len)),
g = d3.select(this);

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

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

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

@ -5,6 +5,16 @@ var w = 120,
max = Number.MIN_VALUE;
var chart = d3.chart.box()
.whiskers(function(d, i, quartiles) {
var q1 = quartiles[0],
q3 = quartiles[2],
iqr = q3 - q1,
w0 = -1,
w1 = d.length;
while (d[++w0] < q1 - iqr * 1.5);
while (d[--w1] > q3 + iqr * 1.5);
return [w0, w1];
})
.width(w - m[1] - m[3])
.height(h - m[0] - m[2]);

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

@ -16,12 +16,12 @@ d3.chart.box = function() {
var len = d.length,
min = d[0],
max = d[len-1],
whiskerIndices = whiskers.call(this, d, i),
quartileData = quartiles(d),
whiskerIndices = whiskers.call(this, d, i, quartileData),
whiskerData = whiskerIndices.map(function(i) { return d[i]; }),
firstWhisker = whiskerIndices[0],
lastWhisker = whiskerIndices[whiskerIndices.length - 1],
whiskerRange = lastWhisker - firstWhisker,
quartileData = quartiles(d.slice(firstWhisker, lastWhisker)),
outliers = d.slice(0, firstWhisker).concat(d.slice(lastWhisker + 1, len)),
g = d3.select(this);