Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(line): using sampling with lttb, NaN point should not be filtered. #16431

Merged
merged 6 commits into from
Feb 18, 2022
20 changes: 18 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);
fuchunhui marked this conversation as resolved.
Show resolved Hide resolved

// 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,10 @@ class DataStore {
}
}

if (countNaN > 0 && countNaN < frameEnd - frameStart) {
fuchunhui marked this conversation as resolved.
Show resolved Hide resolved
newIndices[sampledIndex++] = firstNaNIndex; // append first NaN point in every bucket
}

newIndices[sampledIndex++] = nextRawIndex;

currentRawIndex = nextRawIndex; // This a is the next a (chosen b)
Expand All @@ -991,7 +1002,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;
fuchunhui marked this conversation as resolved.
Show resolved Hide resolved

target.getRawIndex = this._getRawIdx;
return target;
Expand Down
192 changes: 192 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.

1 change: 1 addition & 0 deletions test/runTest/actions/line-sampling.json

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