Public connection path geometry: getPointOnPath(t)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 42/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- backend-api-design, testing
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 145
- Fork
- 12
- Merge medio
- 1g 14h
- PR unite (30g)
- 43
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di gravity-ui/graph
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
gravity-ui/graph#457 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
gravity-ui/graph#455 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
gravity-ui/graph#456 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
gravity-ui/graph#431 ·
I maintainer di solito rispondono entro 1 giorno
-
proposal
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
gravity-ui/graph#416 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di gravity-ui/graph
Issue simili
-
area:cli area:security bug priority:medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
rtk-ai/rtk#5127 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
"code source" and "numerique.gouv" links: "new window" mention duplicated in the accessible nameApertaaccessibility
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
numerique-gouv/lasuite-landingpage#315 ·
I maintainer di solito rispondono entro 1 giorno
-
needs:triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
HyeokjaeChoi/vaultme#585 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement priority/P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
beettlle/pi-smart-router#200 ·