From f62abe3909676248c1928354b0690f90a4f7f97e Mon Sep 17 00:00:00 2001 From: xuying <33517362+tangying1027@users.noreply.github.com> Date: Thu, 2 Jan 2025 17:22:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20EndView=E5=8A=A8=E7=94=BB=E4=BD=BF?= =?UTF-8?q?=E7=94=A8offsetDistance=E5=AF=B9=E4=B8=8D=E9=BD=90=20(#2029)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: xuying.xu --- packages/f2/src/components/line/lineView.tsx | 60 ++++++++++++++++---- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/packages/f2/src/components/line/lineView.tsx b/packages/f2/src/components/line/lineView.tsx index 627dca9a1..07f4a7381 100644 --- a/packages/f2/src/components/line/lineView.tsx +++ b/packages/f2/src/components/line/lineView.tsx @@ -1,5 +1,5 @@ import { createRef, jsx } from '@antv/f-engine'; -import { deepMix } from '@antv/util'; +import { deepMix, isArray } from '@antv/util'; function concatPoints(children) { let result = []; @@ -10,6 +10,35 @@ function concatPoints(children) { return result; } +function formatPoint(point) { + const { y } = point; + return { + x: point.x, + y: isArray(y) ? y[1] : y, + }; +} + +function getPoint(points, t: number) { + const formatedPoints = points.map((p) => formatPoint(p)); + const firstPoint = formatedPoints[0]; + const lastPoint = formatedPoints[formatedPoints.length - 1]; + const xOffset = lastPoint.x - firstPoint.x; + const x = firstPoint.x + xOffset * t; + + for (let i = 1; i < formatedPoints.length; i++) { + const point = formatedPoints[i]; + const prevPoint = formatedPoints[i - 1]; + if (x >= prevPoint.x && x <= point.x) { + // x 在 2 点之间的比例,根据比例再算出 y 的值 + const ratio = (x - prevPoint.x) / (point.x - prevPoint.x); + return { + x, + y: prevPoint.y + (point.y - prevPoint.y) * ratio, + }; + } + } +} + export default (props) => { const { records, coord, animation, endView: EndView, clip } = props; @@ -76,7 +105,7 @@ export default (props) => { return ( { return [point.x, point.y]; @@ -102,21 +131,30 @@ export default (props) => { {EndView ? ( { + child.moveTo(point.x, point.y); + }); }, + // property: ['offsetDistance'], + // start: { + // offsetDistance: 0, + // }, + // end: { + // offsetDistance: 1, + // }, }, }, animation