From d999fd15bb83e02594182d8fc276ef27e32ac6fa Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 16 Nov 2021 09:43:00 +0800 Subject: [PATCH] fix(line): fix bezier cp calculate wrong in monotone smooth --- src/chart/line/poly.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/chart/line/poly.ts b/src/chart/line/poly.ts index ed38bed258..181c215696 100644 --- a/src/chart/line/poly.ts +++ b/src/chart/line/poly.ts @@ -136,18 +136,20 @@ function drawSegment( if (smoothMonotone === 'x') { lenPrevSeg = Math.abs(dx0); lenNextSeg = Math.abs(dx1); - cpx1 = x - lenPrevSeg * smooth; + const dir = vx > 0 ? 1 : -1; + cpx1 = x - dir * lenPrevSeg * smooth; cpy1 = y; - nextCpx0 = x + lenPrevSeg * smooth; + nextCpx0 = x + dir * lenNextSeg * smooth; nextCpy0 = y; } else if (smoothMonotone === 'y') { lenPrevSeg = Math.abs(dy0); lenNextSeg = Math.abs(dy1); + const dir = vy > 0 ? 1 : -1; cpx1 = x; - cpy1 = y - lenPrevSeg * smooth; + cpy1 = y - dir * lenPrevSeg * smooth; nextCpx0 = x; - nextCpy0 = y + lenPrevSeg * smooth; + nextCpy0 = y + dir * lenNextSeg * smooth; } else { lenPrevSeg = Math.sqrt(dx0 * dx0 + dy0 * dy0);