Skip to content

Commit

Permalink
fix hist generator
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Dec 1, 2018
1 parent 278ed00 commit 6955ccb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/internal/math.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {ICategory} from '../model';
import {ISequence} from './interable';
import {bisectLeft} from 'd3-array';

export interface INumberBin {
x0: number;
Expand Down Expand Up @@ -265,6 +266,7 @@ export function computeNormalizedStats(arr: ISequence<number>, numberOfBins?: nu

const bin1 = 0 + binWidth;
const binN = 1 - binWidth;
const binEnds = bins.map((d) => d.x1);

const toBin = (v: number) => {
if (v < bin1) {
Expand All @@ -273,7 +275,7 @@ export function computeNormalizedStats(arr: ISequence<number>, numberOfBins?: nu
if (v >= binN) {
return count - 1;
}
return Math.max(Math.min(Math.round(v * (count - 1)), count - 1), 0);
return bisectLeft(binEnds, v);
};
return new LazyBoxPlotData(arr, {bins, toBin});
}
Expand Down

0 comments on commit 6955ccb

Please sign in to comment.