@graphty/graphty-element / index / Edge
Class: Edge ​
Defined in: graphty-element/src/Edge.ts:150
Represents a directed edge between two nodes in the graph visualization. Handles rendering of edge lines, arrow heads/tails, and labels with support for various styles.
Constructors ​
Constructor ​
new Edge(
graph,srcNodeId,dstNodeId,edgeId,paint,data,opts?):Edge
Defined in: graphty-element/src/Edge.ts:514
Creates a new Edge instance connecting two nodes.
Parameters ​
graph ​
The parent graph or graph context
srcNodeId ​
The ID of the source node
dstNodeId ​
The ID of the destination node
edgeId ​
number
The element-assigned counter the store stamped into this edge's graphty.edgeId column. It becomes Edge.id, and it is what makes two edges between the same pair of nodes two different edges
paint ​
EdgePaint
The source mesh and the style to draw this edge from. Handed in rather than asked for: the session's paint is addressed by the dense index the store assigns after construction, so an edge starts from bootstrapEdgePaint() and the first style pass replaces it
data ​
Custom data associated with the edge
opts? ​
EdgeOpts = {}
Optional configuration options
Returns ​
Edge
Properties ​
arrowCap ​
arrowCap:
ArrowCap|null=null
Defined in: graphty-element/src/Edge.ts:229
This edge's head cap, as a slot in the batch that draws every cap of its appearance, and null when the style asks for none.
NOT A MESH ANY MORE. A cap was a Mesh with a ShaderMaterial of its own, then an InstancedMesh of a shared source, and is now sixteen floats in a shared array plus the seven the billboard shader reads -- so there is nothing per cap in the scene to position, enable or dispose. An ArrowCap -- a slot in ArrowCapBatch -- is what an edge holds instead, and every question the renderer asks of a cap is answered off its batch.
arrowHeadText ​
arrowHeadText:
RichTextLabel|null=null
Defined in: graphty-element/src/Edge.ts:281
arrowMesh ​
arrowMesh:
AbstractMesh|null=null
Defined in: graphty-element/src/Edge.ts:238
Never set by the element: an arrowhead is a slot in a shared batch now, not a mesh.
Deprecated ​
Use Edge.arrowCap. Will be removed in graphty-element 4.0.
arrowTailCap ​
arrowTailCap:
ArrowCap|null=null
Defined in: graphty-element/src/Edge.ts:232
This edge's tail cap, the same way.
arrowTailMesh ​
arrowTailMesh:
AbstractMesh|null=null
Defined in: graphty-element/src/Edge.ts:244
Never set by the element: an arrow tail is a slot in a shared batch now, not a mesh.
Deprecated ​
Use Edge.arrowTailCap. Will be removed in graphty-element 4.0.
arrowTailText ​
arrowTailText:
RichTextLabel|null=null
Defined in: graphty-element/src/Edge.ts:282
dstId ​
readonlydstId:NodeIdType
Defined in: graphty-element/src/Edge.ts:154
dstNode ​
dstNode:
Node
Defined in: graphty-element/src/Edge.ts:194
id ​
readonlyid:string
Defined in: graphty-element/src/Edge.ts:165
This edge's identity: the element-assigned counter the store stamped into its graphty.edgeId column, printed as a string.
It used to be the "srcId:dstId" pair string, which could not name two edges between the same pair at all -- so parallel edges were dropped -- and which collided for any node id containing a colon: an edge a:b -> c and an edge a -> b:c had the same id. The counter is unique by construction, so both of those are now two distinct edges.
label ​
label:
RichTextLabel|null=null
Defined in: graphty-element/src/Edge.ts:280
mesh ​
mesh:
AbstractMesh|PatternedLineMesh
Defined in: graphty-element/src/Edge.ts:218
The mesh this edge's line is drawn by.
NOT ALWAYS THIS EDGE'S OWN MESH ANY MORE. Every line but a patterned one -- straight or curved, 2D or 3D -- is drawn as thin instances of a batch shared by every edge of the same appearance, and this then points at the batch's mesh -- so it still answers what the line is drawn as, and it is still the thing to ask whether the renderer's geometry has been disposed under it, but disposing it or enabling it would reach every other edge in the batch. This edge's private lineBatch says which of the two an edge is, and every write below is routed through it.
opts ​
opts:
EdgeOpts
Defined in: graphty-element/src/Edge.ts:152
parentGraph ​
parentGraph:
Graph|GraphContext
Defined in: graphty-element/src/Edge.ts:151
ray ​
ray:
Ray
Defined in: graphty-element/src/Edge.ts:279
srcId ​
readonlysrcId:NodeIdType
Defined in: graphty-element/src/Edge.ts:153
srcNode ​
srcNode:
Node
Defined in: graphty-element/src/Edge.ts:195
Accessors ​
data ​
Get Signature ​
get data():
AdHocData
Defined in: graphty-element/src/Edge.ts:201
The record this edge carries, as the graph holds it: deep-frozen, so a write to it throws. A change goes through the graph (updateNodes, session.data.updateNodes, ...), which is what undo sees.
Returns ​
The record.
drawnCaps ​
Get Signature ​
get drawnCaps():
object[]
Defined in: graphty-element/src/Edge.ts:478
What this edge's arrow caps are drawn as.
THE ONLY READING OF A CAP THERE IS. A cap drawn as a thin instance has no mesh of its own in the scene and no material of its own, so the scene walk that read a cap's shape off scene.meshes by name -- which is how the story assertions have always read one -- finds one batch where it used to find one mesh per cap, and a batch's name deliberately does not say "arrow". The edge is where the answer moved to: the shape is the name the cap's mesh carried, the span is the reading a story used to take off its bounding box, and the visibility is the opacity the cap is drawn at.
Returns ​
object[]
One entry per cap this edge draws, head before tail.
drawnCentre ​
Get Signature ​
get drawnCentre():
Vector3
Defined in: graphty-element/src/Edge.ts:462
Where this edge's line is drawn, as the middle of the segment on screen.
ONE ANSWER FOR BOTH RENDERERS, which is the point of it. A patterned line carries the middle of its segment in its wrapper's position, and an edge drawn as slots in a batch carries it in the slots' matrices -- for a curve, the middle of the curve, not of its first segment. Asking the edge rather than its mesh gets the right number either way, and is the only way to get it for a batched edge, whose mesh sits at the origin and is shared with every other edge of the same appearance.
Returns ​
Vector3
The middle of the drawn line.
drawnCurve ​
Get Signature ​
get drawnCurve():
Vector3[] |null
Defined in: graphty-element/src/Edge.ts:427
The points this edge's curve is drawn through, or null when its line is not a curve.
A curve is a run of slots in a shared batch and has no mesh of its own whose vertices say how far it bows, so the points are read back out of the slots: where each segment starts, and where the last one ends.
Returns ​
Vector3[] | null
The points, in order along the curve, as fresh vectors.
drawnLine ​
Get Signature ​
get drawnLine(): {
centre:Vector3;length:number;name:string;visibility:number; } |null
Defined in: graphty-element/src/Edge.ts:391
What this edge's line is drawn as, when it is drawn from a shared batch.
THE ONLY READING OF A BATCHED LINE THERE IS. A line drawn as a thin instance has no mesh of its own in the scene and no material of its own, so the scene walk that reads an edge's appearance off scene.meshes -- which is how the story assertions have always read it -- finds one batch where it used to find one mesh per edge. The edge itself is where the answer moved to: the batch's name carries the interned appearance, exactly as the instance name did, and the length is the drawn extent the bounding box used to carry.
Returns ​
{ centre: Vector3; length: number; name: string; visibility: number; } | null
The appearance, or null for a patterned line, whose elements are read through Edge.drawnPattern.
drawnPattern ​
Get Signature ​
get drawnPattern(): readonly
ArrowCap[]
Defined in: graphty-element/src/Edge.ts:447
The elements a patterned line is drawn as -- each dash, dot or segment, in order along the line -- and none for any other line. Each is a slot in a batch shared by every element of its shape, so this is the only place to ask which shapes an edge draws.
Returns ​
readonly ArrowCap[]
The elements.
index ​
Get Signature ​
get index():
number
Defined in: graphty-element/src/Edge.ts:176
This edge's LOGICAL edge index in the element's current GraphSnapshot, assigned at add time and re-keyed through report.edgeRemap on a compacting freeze.
Every Edge has one. An edge whose endpoint ids graph-format will not store is REJECTED before a render object is built for it, so there is no such thing as an Edge with no row -- which is what makes index safe to read without a guard everywhere downstream.
Returns ​
number
The row.
Set Signature ​
set index(
row):void
Defined in: graphty-element/src/Edge.ts:180
Parameters ​
row ​
number
Returns ​
void
parallelCount ​
Get Signature ​
get parallelCount():
number
Defined in: graphty-element/src/Edge.ts:495
How many edges share this edge's ordered endpoint pair, including this one.
Returns ​
number
the count
parallelRank ​
Get Signature ​
get parallelRank():
number
Defined in: graphty-element/src/Edge.ts:375
Where this edge sits among the edges sharing its ordered endpoint pair, counting from zero.
Derived on every read from the graph store rather than stored, so a removal cannot leave it stale. Nothing draws with it yet -- two parallel edges still render as two coincident lines -- but a style layer can read it, and the geometry work that eventually separates parallel edges needs exactly this number.
Returns ​
number
the rank, or -1 for an edge the store no longer holds
Methods ​
applySessionPaint() ​
applySessionPaint(
paint):void
Defined in: graphty-element/src/Edge.ts:748
Draw this edge as the session's style stack resolved it.
Parameters ​
paint ​
EdgePaint
The source mesh and the style behind it.
Returns ​
void
dispose() ​
dispose():
void
Defined in: graphty-element/src/Edge.ts:1029
Tears down every Babylon resource this edge owns.
THE DEFECT THIS CLOSES, and it was visible on screen: no Edge.dispose existed at all. DataManager.clear() emptied its maps and called meshCache.clear(), which disposes the cached SOURCE meshes -- and Babylon disposes a source mesh's instances with it. That is why node spheres and 3D solid edge lines vanished on a dataset clear while roughly sixty grey ARROWHEADS stayed on the canvas, in rosettes where the previous dataset's edges had converged. Arrowheads are not in the MeshCache (today each is an instance of a per-scene batch that FilledArrowRenderer.instanceOf frees with its last head): they are parented to the graph-root TransformNode, which outlives every dataset, so nothing but this dispose frees them. The same was true of the patterned-line meshes (dot/dash/star/...), 2D lines, bezier curves and all three RichTextLabels.
Every dispose is guarded with isDisposed() -- matching the idiom already used in updateStyle -- because the line mesh may be an instance whose SOURCE meshCache.clear() is about to dispose, or has just disposed. PatternedLineMesh owns its own dispose logic (it disposes a per-element ShaderMaterial that Babylon's default flags would leave behind), so it is routed to that rather than to AbstractMesh.dispose.
A DISPOSED EDGE STILL RECEIVES CALLS, which is why Edge.isDisposed exists: the layout engine keeps its own edge list and UpdateManager walks it every frame regardless of what DataManager holds. Calling this twice is safe.
Returns ​
void
getInterceptPoints() ​
getInterceptPoints():
InterceptPoint
Defined in: graphty-element/src/Edge.ts:1423
Calculates ray intersection points with source and destination node meshes. Used to position edges at node surfaces rather than centers.
Returns ​
InterceptPoint
Intersection points for source, destination, and adjusted endpoint
invalidatePositionCache() ​
invalidatePositionCache():
void
Defined in: graphty-element/src/Edge.ts:605
Invalidates the position cache, forcing the edge to be recalculated on the next update. Call this when a connected node's size changes (e.g., due to selection).
Returns ​
void
isDisposed() ​
isDisposed():
boolean
Defined in: graphty-element/src/Edge.ts:1082
Reports whether Edge.dispose has run on this edge.
Note this is about the EDGE, not about edge.mesh.isDisposed(): a live edge's line mesh is disposed and rebuilt on every style change, so the mesh's own flag says nothing about whether the edge is still part of the graph.
Returns ​
boolean
True once this edge has been disposed
isRenderVisible() ​
isRenderVisible():
boolean
Defined in: graphty-element/src/Edge.ts:1090
Whether the renderer is currently drawing this edge.
Returns ​
boolean
True when it is drawn.
isSelected() ​
isSelected():
boolean
Defined in: graphty-element/src/Edge.ts:1119
Whether this edge is in the session's selection.
Returns ​
boolean
True when it is selected.
setRenderVisible() ​
setRenderVisible(
visible):boolean
Defined in: graphty-element/src/Edge.ts:1104
Say whether the renderer should draw this edge.
HIDING IS NOT DELETION: the edge keeps its row in the store, its dense index, its endpoints and its style. Showing it again re-enables the meshes it already has and invalidates the endpoint cache so the next frame recomputes where the line meets the two node surfaces -- which is a ray cast, not a layout.
Parameters ​
visible ​
boolean
What the visibility mask says about this edge.
Returns ​
boolean
True when this changed the state.
setSelected() ​
setSelected(
selected):boolean
Defined in: graphty-element/src/Edge.ts:1135
Say whether this edge is selected.
The state is recorded and nothing is drawn from it yet. An edge line in 3D is an instance of ONE batch per edge style (EdgeMesh.lineBatch interns it under edge-style-<id>), so a per-edge colour or alpha is not available without giving the selected edge a mesh of its own; see the report accompanying this change for what that needs. Recording it here rather than dropping it is what lets the renderer draw it the moment that lands, and what keeps the element -- rather than a style layer -- the owner of the answer.
Parameters ​
selected ​
boolean
What the selection mask says about this edge.
Returns ​
boolean
True when this changed the state.
transformArrowCap() ​
transformArrowCap():
EdgeLine
Defined in: graphty-element/src/Edge.ts:1251
Calculates and applies transformations for arrow head and tail meshes. Adjusts edge line endpoints to create gaps for arrows.
Returns ​
EdgeLine
Edge line positions adjusted for arrow placement
transformEdgeMesh() ​
transformEdgeMesh(
srcPoint,dstPoint):void
Defined in: graphty-element/src/Edge.ts:1196
Transforms the edge mesh to position it between source and destination points. Handles different mesh types (solid, patterned, 2D, bezier).
Parameters ​
srcPoint ​
Vector3
The source point position
dstPoint ​
Vector3
The destination point position
Returns ​
void
update() ​
update():
void
Defined in: graphty-element/src/Edge.ts:628
Updates the edge's visual representation based on current node positions and style changes. Performs dirty checking to skip updates when nodes haven't moved.
Returns ​
void
updateRays() ​
staticupdateRays(_g):void
Defined in: graphty-element/src/Edge.ts:1070
Does nothing.
Parameters ​
_g ​
Ignored
Returns ​
void
Deprecated ​
Each edge aims its own ray when it needs one, so there is no graph-wide ray update any more. Will be removed in graphty-element 4.0.
updateStyle() ​
updateStyle():
void
Defined in: graphty-element/src/Edge.ts:717
Rebuild this edge's line, arrow caps and label from the paint it is currently drawn from.
A REBUILD REQUEST, NOT A STYLE CHANGE: the 2D/3D switch makes it with every mesh already disposed. What to draw is the style stack's answer; WHETHER to draw is the caller's.
Returns ​
void