Public connection path geometry: getPointOnPath(t)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- backend-api-design, testing
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 145
- Forks
- 12
- Merge medio
- 1 d 14 h
- PR fusionados (30 d)
- 43
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de gravity-ui/graph
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
gravity-ui/graph#457 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
gravity-ui/graph#455 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
gravity-ui/graph#456 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
gravity-ui/graph#431 ·
Los mantenedores suelen responder en 1 día
-
proposal
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
gravity-ui/graph#416 ·
Los mantenedores suelen responder en 1 día
Todos los issues de gravity-ui/graph
Issues similares
-
area:cli area:security bug priority:medium
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
rtk-ai/rtk#5127 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
"code source" and "numerique.gouv" links: "new window" mention duplicated in the accessible nameAbiertoaccessibility
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
numerique-gouv/lasuite-landingpage#315 ·
Los mantenedores suelen responder en 1 día
-
needs:triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
HyeokjaeChoi/vaultme#585 ·
Los mantenedores suelen responder en 1 día
-
enhancement priority/P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
beettlle/pi-smart-router#200 ·