Skip to content

Commit

Permalink
fix(line): using sampling with lttb, NaN point should not be filtered.
Browse files Browse the repository at this point in the history
…close apache#14689
  • Loading branch information
fuchunhui committed Jan 26, 2022
1 parent ddc57f4 commit 1661f9b
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/data/DataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ class DataStore {
let area;
let nextRawIndex;

const newIndices = new (getIndicesCtor(this._rawCount))(Math.ceil(len / frameSize) + 2);
const newIndices = new (getIndicesCtor(this._rawCount))(len);

// First frame use the first data.
newIndices[sampledIndex++] = currentRawIndex;
Expand Down Expand Up @@ -965,12 +965,14 @@ class DataStore {
maxArea = -1;

nextRawIndex = frameStart;
const appendNaNList = [];
// Find a point from current frame that construct a triangel with largest area with previous selected point
// And the average of next frame.
for (let idx = frameStart; idx < frameEnd; idx++) {
const rawIndex = this.getRawIndex(idx);
const y = dimStore[rawIndex] as number;
if (isNaN(y)) {
appendNaNList.push(rawIndex);
continue;
}
// Calculate triangle area over three buckets
Expand All @@ -983,6 +985,10 @@ class DataStore {
}
}

if (appendNaNList.length && appendNaNList.length !== frameEnd - frameStart) {
newIndices[sampledIndex++] = appendNaNList[0]; // append first NaN point in every bucket
}

newIndices[sampledIndex++] = nextRawIndex;

currentRawIndex = nextRawIndex; // This a is the next a (chosen b)
Expand All @@ -991,7 +997,12 @@ class DataStore {
// First frame use the last data.
newIndices[sampledIndex++] = this.getRawIndex(len - 1);
target._count = sampledIndex;
target._indices = newIndices;

const _newIndices = new (getIndicesCtor(this._rawCount))(sampledIndex);
for (let idx = 0; idx < sampledIndex; idx++) {
_newIndices[idx] = newIndices[idx];
}
target._indices = _newIndices;

target.getRawIndex = this._getRawIdx;
return target;
Expand Down
170 changes: 170 additions & 0 deletions test/line-sampling.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1661f9b

Please sign in to comment.