Skip to content

Commit

Permalink
Use count for consistency.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 4, 2019
1 parent 35f9d72 commit 10b0530
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/threshold/freedmanDiaconis.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {map} from "../array.js";
import ascending from "../ascending.js";
import number from "../number.js";
import count from "../count.js";
import quantile from "../quantile.js";

export default function(values, min, max) {
values = map.call(values, number).sort(ascending);
return Math.ceil((max - min) / (2 * (quantile(values, 0.75) - quantile(values, 0.25)) * Math.pow(values.length, -1 / 3)));
return Math.ceil((max - min) / (2 * (quantile(values, 0.75) - quantile(values, 0.25)) * Math.pow(count(values), -1 / 3)));
}
3 changes: 2 additions & 1 deletion src/threshold/scott.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import count from "../count.js";
import deviation from "../deviation.js";

export default function(values, min, max) {
return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(values.length, -1 / 3)));
return Math.ceil((max - min) / (3.5 * deviation(values) * Math.pow(count(values), -1 / 3)));
}
4 changes: 3 additions & 1 deletion src/threshold/sturges.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import count from "../count.js";

export default function(values) {
return Math.ceil(Math.log(values.length) / Math.LN2) + 1;
return Math.ceil(Math.log(count(values)) / Math.LN2) + 1;
}
7 changes: 7 additions & 0 deletions test/threshold/freedmanDiaconic-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var tape = require("tape"),
arrays = require("../../");

tape("thresholdFreedmanDiaconis(values, min, max) returns the expected result", function(test) {
test.equal(arrays.thresholdFreedmanDiaconis([4, 3, 2, 1, NaN], 1, 4), 2);
test.end();
});
7 changes: 7 additions & 0 deletions test/threshold/scott-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var tape = require("tape"),
arrays = require("../../");

tape("thresholdScott(values, min, max) returns the expected result", function(test) {
test.equal(arrays.thresholdScott([4, 3, 2, 1, NaN], 1, 4), 2);
test.end();
});
7 changes: 7 additions & 0 deletions test/threshold/sturges-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var tape = require("tape"),
arrays = require("../../");

tape("thresholdSturges(values, min, max) returns the expected result", function(test) {
test.equal(arrays.thresholdSturges([4, 3, 2, 1, NaN], 1, 4), 3);
test.end();
});

0 comments on commit 10b0530

Please sign in to comment.