[76] | 1 | require("./../../lib/env-js/envjs/node"); |
---|
| 2 | require("./../../d3"); |
---|
| 3 | require("./../../d3.layout"); |
---|
| 4 | |
---|
| 5 | var format = d3.format(".2f"); |
---|
| 6 | |
---|
| 7 | var histogram = d3.layout.histogram().frequency(true); |
---|
| 8 | console.log("frequency(true):"); |
---|
| 9 | console.log(" 0,0,0,1,2,2 -> " + log(histogram([0,0,0,1,2,2]))); |
---|
| 10 | console.log(""); |
---|
| 11 | |
---|
| 12 | var histogram = d3.layout.histogram().frequency(false); |
---|
| 13 | console.log("frequency(false):"); |
---|
| 14 | console.log(" 0,0,0,1,2,2 -> " + log(histogram([0,0,0,1,2,2]))); |
---|
| 15 | console.log(""); |
---|
| 16 | |
---|
| 17 | var histogram = d3.layout.histogram().bins(2); |
---|
| 18 | console.log("bins(4):"); |
---|
| 19 | console.log(" 0,0,0,1,2,2 -> " + log(histogram([0,0,0,1,2,2]))); |
---|
| 20 | console.log(""); |
---|
| 21 | |
---|
| 22 | var histogram = d3.layout.histogram().bins([0,1,2,3]); |
---|
| 23 | console.log("bins(0,1,2,3):"); |
---|
| 24 | console.log(" 0,0,0,1,2,2 -> " + log(histogram([0,0,0,1,2,2]))); |
---|
| 25 | console.log(""); |
---|
| 26 | |
---|
| 27 | function log(bins) { |
---|
| 28 | return bins.map(function(bin) { return format(bin.x) + "-" + format(bin.x + bin.dx) + ":" + format(bin.y); }).join(", "); |
---|
| 29 | } |
---|