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): fix areaStyle skewing in stepped line series and incorrect connectNull behavior #20092

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions src/chart/line/LineView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,19 @@ function getStackedOnPoints(
return points;
}

/**
* Filter the null data and extend data for step considering `stepTurnAt`
*
* @param points data to convert, that may containing null
* @param basePoints base data to reference, used only for areaStyle points
* @param coordSys coordinate system
* @param stepTurnAt 'start' | 'end' | 'middle' | true
* @param connectNulls whether to connect nulls
* @returns converted point positions
*/
function turnPointsIntoStep(
points: ArrayLike<number>,
basePoints: ArrayLike<number> | null,
coordSys: Cartesian2D | Polar,
stepTurnAt: 'start' | 'end' | 'middle',
connectNulls: boolean
Expand All @@ -163,12 +174,18 @@ function turnPointsIntoStep(
const nextPt: number[] = [];
const filteredPoints = [];
if (connectNulls) {
for (i = 0; i < points.length; i += 2) {
if (!isNaN(points[i]) && !isNaN(points[i + 1])) {
filteredPoints.push(points[i], points[i + 1]);
}
}
points = filteredPoints;
for (i = 0; i < points.length; i += 2) {
/**
* For areaStyle of stepped lines, `stackedOnPoints` should be
* filtered the same as `points` so that the base axis values
* should stay the same as the lines above. See #20021
*/
const reference = basePoints || points;
if (!isNaN(reference[i]) && !isNaN(reference[i + 1])) {
filteredPoints.push(points[i], points[i + 1]);
}
}
points = filteredPoints;
}
for (i = 0; i < points.length - 2; i += 2) {
nextPt[0] = points[i + 2];
Expand Down Expand Up @@ -717,12 +734,11 @@ class LineView extends ChartView {
);

if (step) {
// TODO If stacked series is not step
points = turnPointsIntoStep(points, coordSys, step, connectNulls);

if (stackedOnPoints) {
stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step, connectNulls);
stackedOnPoints = turnPointsIntoStep(stackedOnPoints, points, coordSys, step, connectNulls);
}
// TODO If stacked series is not step
points = turnPointsIntoStep(points, null, coordSys, step, connectNulls);
}

polyline = this._newPolyline(points);
Expand Down Expand Up @@ -801,11 +817,11 @@ class LineView extends ChartView {
else {
// Not do it in update with animation
if (step) {
// TODO If stacked series is not step
points = turnPointsIntoStep(points, coordSys, step, connectNulls);
if (stackedOnPoints) {
stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step, connectNulls);
stackedOnPoints = turnPointsIntoStep(stackedOnPoints, points, coordSys, step, connectNulls);
}
// TODO If stacked series is not step
points = turnPointsIntoStep(points, null, coordSys, step, connectNulls);
}

polyline.setShape({
Expand Down Expand Up @@ -1337,10 +1353,10 @@ class LineView extends ChartView {
let stackedOnNext = diff.stackedOnNext;
if (step) {
// TODO If stacked series is not step
current = turnPointsIntoStep(diff.current, coordSys, step, connectNulls);
stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step, connectNulls);
next = turnPointsIntoStep(diff.next, coordSys, step, connectNulls);
stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step, connectNulls);
stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, diff.current, coordSys, step, connectNulls);
current = turnPointsIntoStep(diff.current, null, coordSys, step, connectNulls);
stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, diff.next, coordSys, step, connectNulls);
next = turnPointsIntoStep(diff.next, null, coordSys, step, connectNulls);
}
// Don't apply animation if diff is large.
// For better result and avoid memory explosion problems like
Expand Down
105 changes: 105 additions & 0 deletions test/line-step.html

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