winkjs / wink-statistics

Fast & numerically stable statistical analysis
http://winkjs.org/wink-statistics/
MIT License
46 stars 7 forks source link

custom beans in histogram #26

Closed hugonr closed 5 years ago

hugonr commented 5 years ago

actually its not an issue, but a contribution:

there is no way to make custom bins, so i did this:

var histogram = function ( sortedData, dataPrecision, accessor, maxBins = null ) {

and before choose between Freedman–Diaconis or Sturges' Rule:

    // Compute `bins` and `binWidth`.
    if ((binWidth === 0)) {
        rs.mad = mad(sortedData, accessor);
        binWidth = 2 * rs.mad;
    }

    // start custom code
    if (maxBins){
        if (binWidth > maxBins){
            binWidth = maxBins;
        }
    }
    // end custom code

    if (binWidth > 0) {

better to read like this if you are using it to make a graph.

cheers and sorry my bad english.

rachnachakraborty commented 5 years ago

Hello @hugonr,

Thank you for sharing the need to have custom bins. We will schedule the inclusion of your code in the next release of the package.

Shall keep you posted.

Cheers! Rachna PS: never mind the english, its the spirit which counts:-)