Skip to content

Commit

Permalink
fix data hists
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Dec 16, 2018
1 parent f8cac30 commit 96ca53f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
24 changes: 16 additions & 8 deletions src/internal/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export function normalizedStatsBuilder(numberOfBins: number): IBuilder<number, I
let high = numberOfBins - 1;
// binary search
while (low < high) {
const center = Math.floor(high + low) / 2;
const center = Math.floor((high + low) / 2);
if (v < hist[center].x1) {
high = center;
} else {
Expand Down Expand Up @@ -777,6 +777,10 @@ export function dateValueCacheBuilder(length: number) {
};
}

export function dateValueCache2Value(v: number) {
return v === MISSING_DATE ? null : new Date(v);
}

export function categoricalValueCacheBuilder(length: number, categories: {name: string}[]) {
const vs = createIndexArray(length, categories.length + 1);
const name2index = new Map<string, number>();
Expand All @@ -790,6 +794,10 @@ export function categoricalValueCacheBuilder(length: number, categories: {name:
};
}

export function categoricalValueCache2Value<T extends {name: string}>(v: number, categories: T[]) {
return v === 0 ? null : categories[v - 1];
}


function sortWorkerMain(self: IPoorManWorkerScope) {
const refs = new Map<string, UIntTypedArray | Float32Array | Int32Array>();
Expand Down Expand Up @@ -826,13 +834,12 @@ function sortWorkerMain(self: IPoorManWorkerScope) {
// tslint:disable-next-line:prefer-for-of
for (let ii = 0; ii < indices.length; ++ii) {
const v = data[indices[ii]];
b.push(v === MISSING_DATE ? null : new Date(v));
b.push(dateValueCache2Value(v));
}
} else {
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < data.length; ++i) {
const v = data[i];
b.push(v === MISSING_DATE ? null : new Date(v));
b.push(dateValueCache2Value(data[i]));
}
}
self.postMessage(<IDateStatsMessageResponse>{
Expand All @@ -851,14 +858,12 @@ function sortWorkerMain(self: IPoorManWorkerScope) {
if (indices) {
// tslint:disable-next-line:prefer-for-of
for (let ii = 0; ii < indices.length; ++ii) {
const v = data[indices[ii]];
b.push(v === 0 ? null : cats[v - 1]!);
b.push(categoricalValueCache2Value(data[indices[ii]], cats));
}
} else {
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < data.length; ++i) {
const v = data[i];
b.push(v === 0 ? null : cats[v - 1]!);
b.push(categoricalValueCache2Value(data[i], cats));
}
}

Expand Down Expand Up @@ -932,6 +937,7 @@ function sortWorkerMain(self: IPoorManWorkerScope) {
if (typeof r.uid !== 'number' || typeof r.type !== 'string') {
return;
}
debugger;
const h = msgHandlers[r.type];
if (h) {
h(r);
Expand All @@ -949,5 +955,7 @@ export const WORKER_BLOB = createWorkerCodeBlob([
asc.toString(),
desc.toString(),
sortComplex.toString(),
dateValueCache2Value.toString(),
categoricalValueCache2Value.toString(),
toFunctionBody(sortWorkerMain)
]);
15 changes: 12 additions & 3 deletions src/provider/ScheduledTasks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {getNumberOfBins, IAdvancedBoxPlotData, ICategoricalStatistics, IDateStatistics, ISortMessageResponse, IStatistics, toIndexArray, WORKER_BLOB} from '../internal';
import {getNumberOfBins, IAdvancedBoxPlotData, ICategoricalStatistics, IDateStatistics, ISortMessageResponse, IStatistics, toIndexArray, WORKER_BLOB, dateValueCache2Value, categoricalValueCache2Value} from '../internal';
import {ISequence} from '../internal/interable';
import TaskScheduler, {ABORTED, oneShotIterator} from '../internal/scheduler';
import {WorkerTaskScheduler} from '../internal/worker';
import Column, {ICategoricalLikeColumn, IDataRow, IDateColumn, IGroup, IndicesArray, INumberColumn, IOrderedGroup, isCategoricalLikeColumn, isDateColumn, isNumberColumn, Ranking, UIntTypedArray} from '../model';
import Column, {ICategoricalLikeColumn, IDataRow, IDateColumn, IGroup, IndicesArray, INumberColumn, IOrderedGroup, isCategoricalLikeColumn, isDateColumn, isNumberColumn, Ranking, UIntTypedArray, isCategoricalColumn} from '../model';
import {IRenderTask} from '../renderer/interfaces';
import {sortDirect} from './DirectRenderTasks';
import {CompareLookup} from './sort';
Expand Down Expand Up @@ -396,7 +396,16 @@ export class ScheduleRenderTasks extends ARenderTasks implements IRenderTaskExec
}
return (col: Column) => {
const v = this.valueCacheData.get(col.id);
return v ? v[dataIndex] : undefined;
if (!v) {
return undefined;
}
if (isDateColumn(col)) {
return dateValueCache2Value(v[dataIndex]);
}
if (isCategoricalColumn(col)) {
return categoricalValueCache2Value(v[dataIndex], col.categories);
}
return v[dataIndex];
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/provider/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class ARenderTasks {
let chunkCounter = currentChunkSize;
const data = this.data;
for (; i < data.length && chunkCounter > 0; ++i, --chunkCounter) {
builder.push(acc(data[i++]));
builder.push(acc(data[i]));
}
if (i < data.length) { // need another round
return ANOTHER_ROUND;
Expand Down

0 comments on commit 96ca53f

Please sign in to comment.