Skip to content

Commit

Permalink
no more d3-array
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Dec 14, 2018
1 parent 0b58a79 commit 7e51388
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
"url": "https://github.com/datavisyn/lineupjs.git"
},
"devDependencies": {
"@types/d3-array": "^1.2.3",
"@types/d3-color": "^1.2.1",
"@types/d3-dispatch": "^1.0.6",
"@types/d3-scale": "^2.0.2",
Expand All @@ -98,7 +97,6 @@
"cache-loader": "^1.2.2",
"css-loader": "^1.0.0",
"cross-zip-cli": "^1.0.0",
"d3-array": "^1.2.4",
"d3-color": "^1.2.3",
"d3-dispatch": "^1.0.5",
"d3-format": "^1.3.2",
Expand Down
18 changes: 15 additions & 3 deletions src/internal/math.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {ICategory, UIntTypedArray, IndicesArray} from '../model';
import {bisectLeft} from 'd3-array';
import {IForEachAble, isIndicesAble, ISequence} from './interable';
import {IPoorManWorkerScope, toFunctionBody} from './worker';
import {createWorkerCodeBlob} from './worker';
Expand Down Expand Up @@ -287,7 +286,6 @@ export function normalizedStatsBuilder(numberOfBins: number): {push: (v: number)

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

const toBin = (v: number) => {
if (v < bin1) {
Expand All @@ -296,7 +294,21 @@ export function normalizedStatsBuilder(numberOfBins: number): {push: (v: number)
if (v >= binN) {
return numberOfBins - 1;
}
return bisectLeft(binEnds, v); // TODO find better solutions to inline
if (numberOfBins === 3) {
return 1;
}
let low = 1;
let high = numberOfBins - 1;
// binary search
while (low < high) {
const center = Math.floor(high + low) / 2;
if (v < hist[center].x1) {
high = center;
} else {
low = center + 1;
}
}
return low;
};

// filter out NaN
Expand Down

0 comments on commit 7e51388

Please sign in to comment.