Class LabelInfo
Provides enhanced label positioning for edges with anchor points and offsets.
public sealed record LabelInfo : IEquatable<LabelInfo>
- Inheritance
-
LabelInfo
- Implements
- Inherited Members
Examples
// Simple centered label
var label = new LabelInfo("Connection");
// Label near the start with offset
var startLabel = new LabelInfo("Out", LabelAnchor.Start, OffsetY: -15);
// Label near the end, shifted right
var endLabel = new LabelInfo("In", LabelAnchor.End, OffsetX: 10);
// Use with edge definition
var edge = new EdgeDefinition
{
Id = "e1",
Source = "node1",
Target = "node2",
SourcePort = "out",
TargetPort = "in",
LabelInfo = new LabelInfo("Yes", LabelAnchor.Start, OffsetY: -10)
};
Remarks
LabelInfo extends the basic Label string by adding precise positioning control. When both Label and LabelInfo are present, LabelInfo takes precedence.
This design allows backward compatibility with existing code that uses the simple Label property while enabling advanced positioning for new scenarios.
Constructors
LabelInfo(string, LabelAnchor, double, double, double)
Creates a new label info with the specified text and positioning.
public LabelInfo(string text, LabelAnchor anchor = LabelAnchor.Center, double offsetX = 0, double offsetY = 0, double perpOffset = 0)
Parameters
textstringThe label text.
anchorLabelAnchorWhere along the edge to position the label. Defaults to center.
offsetXdoubleHorizontal offset from anchor point. Defaults to 0.
offsetYdoubleVertical offset from anchor point. Defaults to 0.
perpOffsetdoublePerpendicular offset from edge path. Positive = right of edge direction. Defaults to 0.
Properties
Anchor
Where along the edge to anchor the label.
public LabelAnchor Anchor { get; init; }
Property Value
Remarks
OffsetX
Horizontal offset in pixels from the anchor point. Positive values move right.
public double OffsetX { get; init; }
Property Value
OffsetY
Vertical offset in pixels from the anchor point. Positive values move down.
public double OffsetY { get; init; }
Property Value
PerpendicularOffset
Perpendicular offset from the edge path, in pixels. Positive values offset to the "right" of the edge direction (as viewed from source to target). Negative values offset to the "left" of the edge direction.
public double PerpendicularOffset { get; init; }
Property Value
Examples
// Label 10px to the right of a horizontal edge (appears below)
var rightLabel = new LabelInfo("0.85", perpOffset: 10);
// Label 10px to the left of the edge (appears above)
var leftLabel = new LabelInfo("0.65", perpOffset: -10);
Remarks
This offset is applied perpendicular to the edge direction at the anchor point, similar to GoJS's segmentOffset behavior. The offset rotates with the edge, so a positive value always moves the label to the right side of the edge when viewed from source to target.
Use this to separate labels on adjacent parallel edges or to consistently position labels on one side of edges regardless of their direction.
Text
The text content of the label.
public string Text { get; init; }
Property Value
Methods
ToString()
Creates a simple centered label from this info (extracts just the text).
public override string ToString()
Returns
Operators
implicit operator LabelInfo(string)
Creates a LabelInfo from a simple string label (centered, no offset).
public static implicit operator LabelInfo(string text)
Parameters
textstring