From 533fde6c4d18d9dac65f3c51aea24ba6d1fe6e0b Mon Sep 17 00:00:00 2001 From: Anthony D'Alessio Date: Wed, 14 Aug 2024 22:50:17 -0500 Subject: [PATCH] fix(line): Removal of partial connections around null values for step lines with connectNulls=false --- src/chart/line/LineView.ts | 14 ++++++++++---- test/line-step.html | 10 +++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/chart/line/LineView.ts b/src/chart/line/LineView.ts index be4ff3571e..3250a35ec0 100644 --- a/src/chart/line/LineView.ts +++ b/src/chart/line/LineView.ts @@ -181,7 +181,9 @@ function turnPointsIntoStep( case 'end': stepPt[baseIndex] = nextPt[baseIndex]; stepPt[1 - baseIndex] = pt[1 - baseIndex]; - stepPoints.push(stepPt[0], stepPt[1]); + if (!isNaN(nextPt[1 - baseIndex])) { + stepPoints.push(stepPt[0], stepPt[1]); + } break; case 'middle': const middle = (pt[baseIndex] + nextPt[baseIndex]) / 2; @@ -189,14 +191,18 @@ function turnPointsIntoStep( stepPt[baseIndex] = stepPt2[baseIndex] = middle; stepPt[1 - baseIndex] = pt[1 - baseIndex]; stepPt2[1 - baseIndex] = nextPt[1 - baseIndex]; - stepPoints.push(stepPt[0], stepPt[1]); - stepPoints.push(stepPt2[0], stepPt2[1]); + if (!isNaN(nextPt[1 - baseIndex]) && !isNaN(pt[1 - baseIndex])) { + stepPoints.push(stepPt[0], stepPt[1]); + stepPoints.push(stepPt2[0], stepPt2[1]); + } break; default: // default is start stepPt[baseIndex] = pt[baseIndex]; stepPt[1 - baseIndex] = nextPt[1 - baseIndex]; - stepPoints.push(stepPt[0], stepPt[1]); + if (!isNaN(pt[1 - baseIndex])) { + stepPoints.push(stepPt[0], stepPt[1]); + } } } // Last points diff --git a/test/line-step.html b/test/line-step.html index 7e07d0dec5..21f4f7af26 100644 --- a/test/line-step.html +++ b/test/line-step.html @@ -72,21 +72,21 @@ type: 'line', step: 'start', connectNulls: false, - data: [120, null, 101, null, 90, 230, 210], + data: [400, 450, 425, null, 400, 450, 400], }, { name: 'Step Middle', type: 'line', step: 'middle', - connectNulls: true, - data: [220, 282, null, 234, null, 430, 410], + connectNulls: false, + data: [300, 350, null, 250, 200, 300, 250], }, { name: 'Step End', type: 'line', - step: 'middle', + step: 'end', connectNulls: true, - data: [450, null, null, null, 590, 530, 510], + data: [100, 200, 150, null, 100, 50, 100], }, ], };