Public connection path geometry: getPointOnPath(t)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend-api-design, testing
Hướng nghiên cứu
Start by reading the connection implementations in packages/graph/src/components/canvas/connections/, especially bezierHelpers.ts and the createPath() methods for BaseConnection, BlockConnection, MultipointConnection, and BezierMultipointConnection. Then inspect GraphConnectionPO in packages/graph-playwright/src and its tests; implement the query to match each rendered path and verify the listed unit and E2E cases. Done means the public API, documentation, tests, and page object all satisfy the acceptance criteria.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Part of #396. Follow-up to #398.
Goal
Give connection components a public, typed way to answer "where is the point at fraction t of this connection's rendered path?", and make GraphConnectionPO in @gravity-ui/graph-playwright use it instead of its own copy of the bezier math.
#398 moved the page objects into @gravity-ui/graph-playwright without changing their behaviour. The geometry query listed there (item 4 of "Internals and implicit contracts touched today") was left out because it is a new core feature, not part of the extraction. This issue covers that part.
Target branch: v2. Depends on #398 (the package must exist).
Problem
GraphConnectionPO.getPointOnCurve() currently:
- reads
getViewComponent().connectionPoints(start and end only) plus theuseBezierConnections/bezierConnectionDirectionconfig flags insideevaluate; - re-implements
generateBezierParams/getPointOfBezierCurvefrompackages/graph/src/components/canvas/connections/bezierHelpers.tson the Node side.
This is wrong when the rendered path is not "one segment between two ports":
MultipointConnectiondrawscurvePolyline(points)throughTMultipointConnection.points; the page object ignorespointsand computes a point on the start–end chord, which can be far from the stroke.click()/hover()then miss the connection.BezierMultipointConnectiondraws a bezier or a straight line per segment; same problem.- Custom connection components (configured through
settings.connection) can draw anything; the page object can't know their shape. - Any change to the bezier helpers in core silently diverges from the copy in the page object.
Only the component that builds the path knows its geometry, so the query belongs on the component.
Responsibility
Core does:
- Expose
getPointOnPath(t)onBaseConnectionand implement it for every built-in connection component, matching whatcreatePath()draws. - Keep the implementation pure: no canvas access, no rendering side effects, no allocations beyond the returned point. Safe to call from
evaluatein tests and from application code (label placement, tooltips, custom overlays).
Core does not:
- Guarantee arc-length (constant-speed) parameterization.
tfollows the curve parameter, see the contract below. - Account for rounded polyline corners (
curvePolylinecorner radius) or line width. A returned point may be up to the corner radius away from the stroke at a polyline vertex; anywhere else it is on the path. - Change the existing hit-testing, arrow or label code. Reusing the query there is possible later and out of scope here.
@gravity-ui/graph-playwright does:
- Call
view.getPointOnPath(t)insideevaluateand return the result asGraphPoint. - Drop its own bezier math and stop reading
useBezierConnections/bezierConnectionDirection.
Contract
class BaseConnection {
/**
* Point at fraction `t` of the rendered connection path, in world coordinates.
* `t = 0` is the source end, `t = 1` the target end.
* Returns `undefined` when the connection has no geometry yet
* (ports not resolved, multipoint connection with fewer than 2 points) or `t` is not finite.
* `t` outside [0, 1] is clamped.
*/
public getPointOnPath(t: number): TPoint | undefined;
}
Per component:
| Component | Path | t mapping |
|---|---|---|
BaseConnection (default) |
straight segment connectionPoints[0] → [1] |
linear interpolation |
BlockConnection, useBezier: false |
straight segment (same as createPath()) |
linear interpolation |
BlockConnection, useBezier: true |
cubic bezier from generateBezierParams(start, end, bezierDirection) |
getPointOfBezierCurve(start, end, t, bezierDirection) — same value the arrow uses at t = 0.5 |
MultipointConnection with points (≥ 2) |
polyline through points |
t spread across segments proportionally to segment length; linear inside a segment |
MultipointConnection without points |
falls back to BlockConnection |
as above |
BezierMultipointConnection |
per segment: straight if aligned with bezierDirection, bezier otherwise (same rule as createPath()) |
t spread across segments proportionally to segment chord length; inside a segment, linear or bezier parameter |
Rules:
- The query must follow the same branch as
createPath()for the current props/state. A subclass that overridescreatePath()with a different shape should overridegetPointOnPath()too; this is stated in the JSDoc and indocs/connections/. - Zero-length segments are skipped; a path with total length 0 returns its single point for any
t. - The method is public and documented in
packages/graph/docs/connections/(canvas connection system) next tocreatePath()/getPath().
Core changes
BaseConnection.getPointOnPath(t): straight interpolation betweenconnectionPoints;undefinedwithout geometry.BlockConnection.getPointOnPath(t): bezier branch via the existinggetPointOfBezierCurve(bezierHelpers.ts); straight branch viasuper.MultipointConnection.getPointOnPath(t): polyline overgetPoints(); fallback tosuperwhen there are no points;undefinedfor one point.BezierMultipointConnection.getPointOnPath(t): per-segment bezier/straight usinggenerateBezierParams, with the sameisStraightSegmentrule ascreatePath(). Extract that rule (and the segment iteration) into a shared helper so path building and the query cannot diverge.- Optional, if it falls out naturally: a small pure helper in
bezierHelpers.ts(e.g.getPointOnPolyline(points, t)) reused by both multipoint classes. - Unit tests next to the components (
*.test.ts, Jest +jest-canvas-mock).
@gravity-ui/graph-playwright changes
-
GraphConnectionPO.getPointOnCurve(time)becomes a singleevaluate:const point = view.getPointOnPath(time); if (!point) throw new Error(`Connection ${connectionId} has no rendered geometry.`); return { x: point.x, y: point.y };Public names stay the same (
getPointOnCurve,curveTimeoption,click()/hover()); the[0, 1]range check stays on the Node side. -
Remove the duplicated bezier math and the
getConfigFlag("useBezierConnections" | "bezierConnectionDirection")reads. -
"Core API used inside page callbacks" in the package README / #398 contract:
Connectionsrow becomesgetConnectionState(id)→$selected,getViewComponent().getPointOnPath(t);Settingsrow loses the two connection flags. -
Peer range
@gravity-ui/graphmust point at a core version that hasgetPointOnPath(workspace dependency inside the monorepo; set the minimum version on release).
Migration
- Core: additive, no breaking change. Custom connection components that override
createPath()should also overridegetPointOnPath(); otherwise they inherit the parent's geometry (note indocs/migration-guides/v1-to-v2.md, "Connections" section). @gravity-ui/graph-playwright:getPointOnCurve()/click()/hover()now follow the actual rendered path. For straight and single-bezier connections the result is unchanged; for multipoint and custom connections tests may hit a different (correct) point. This is the behaviour note already promised in #398's migration section; it lands with this issue.- In-repo callers:
apps/e2epage objects that extendGraphConnectionPOneed no change unless they readconnectionPointsdirectly.
Acceptance criteria
-
BaseConnection.getPointOnPath(t: number): TPoint | undefinedis public, typed, documented (JSDoc +docs/connections/), and implemented forBlockConnection,MultipointConnection,BezierMultipointConnection. - Unit tests: straight connection (t = 0, 0.5, 1; clamping;
undefinedwithout geometry and for non-finitet). - Unit tests:
BlockConnectionwith bezier,bezierDirection"horizontal"and"vertical", values equalgetPointOfBezierCurvefor the same endpoints; endpoints returned exactly at t = 0 and t = 1. - Unit tests:
MultipointConnectionwith 0 (fallback), 1 (undefined), 2 and ≥ 3 points, including a zero-length segment; vertices hit at the expectedt. - Unit tests:
BezierMultipointConnectionwith mixed straight and bezier segments in both directions. -
GraphConnectionPO.getPointOnCurve()callsgetPointOnPathinsideevaluate; no bezier math or connection config flags remain inpackages/graph-playwright/src. - E2E (
apps/e2e, viaGraphConnectionPO):click()selects a bezier connection (horizontal and vertical);click()selects aMultipointConnectionwhosepointsroute away from the start–end chord (fails with the old implementation);hover()on the multipoint connection sets the hovered state. - Package contract still passes: the built
@gravity-ui/graph-playwrighthas no runtime import of@gravity-ui/graph. - Existing build, typecheck, lint, strict (zero debt) and required CI checks stay green.
- Ngôn ngữ chính
- TypeScript
- Star
- 145
- Fork
- 12
- Merge trung bình
- 1 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 43
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của gravity-ui/graph
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
gravity-ui/graph#457 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
gravity-ui/graph#455 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
gravity-ui/graph#456 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
gravity-ui/graph#431 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
proposal
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
gravity-ui/graph#416 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của gravity-ui/graph
Issue tương tự
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openclaw/openclaw#199885 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
feature needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
BoardGamesEmpire/board-games-empire-backend#1306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
sequant-io/sequant#1689 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100