Skip to content

Commit

Permalink
Merge pull request #16431 from fuchunhui/fix-14689
Browse files Browse the repository at this point in the history
fix(line): using sampling with lttb, NaN point should not be filtered.
  • Loading branch information
pissang authored Feb 18, 2022
2 parents 949d160 + 6ba672d commit fdfb46c
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 1 deletion.
16 changes: 15 additions & 1 deletion 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))(Math.min((Math.ceil(len / frameSize) + 2) * 2, len));

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

nextRawIndex = frameStart;

let firstNaNIndex = -1;
let countNaN = 0;
// 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)) {
countNaN++;
if (firstNaNIndex < 0) {
firstNaNIndex = rawIndex;
}
continue;
}
// Calculate triangle area over three buckets
Expand All @@ -983,6 +990,13 @@ class DataStore {
}
}

if (countNaN > 0 && countNaN < frameEnd - frameStart) {
// Append first NaN point in every bucket.
// It is necessary to ensure the correct order of indices.
newIndices[sampledIndex++] = Math.min(firstNaNIndex, nextRawIndex);
nextRawIndex = Math.max(firstNaNIndex, nextRawIndex);
}

newIndices[sampledIndex++] = nextRawIndex;

currentRawIndex = nextRawIndex; // This a is the next a (chosen b)
Expand Down
294 changes: 294 additions & 0 deletions test/line-sampling.html

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

1 change: 1 addition & 0 deletions test/runTest/actions/__meta__.json

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

Loading

0 comments on commit fdfb46c

Please sign in to comment.