documentationfor yFiles for HTML 3.0.0.3

Labels

A label adds information to a graph element by providing a caption. It is modeled by interface ILabel. It belongs to a label owner, modeled by the ILabelOwner interface. The three interfaces INode, IEdge, and IPort extend this interface. In this manual, labels at nodes, edges, and ports are sometimes referred to as node labels, edge labels, and port labels. A label owner can have multiple labels.

Interface ILabel exposes the following read-only properties, which can be modified by IGraph’s methods:

Property Setter Method Description

ILabel.text

IGraph.setLabelText

The text displayed by the label.

ILabel.owner

cannot be changed after creation

The node, edge, or port that this label belongs to.

ILabel.layoutParameter

IGraph.setLabelLayoutParameter

An ILabelModelParameter that defines the location of the label. See the section about label models.

ILabel.style

IGraph.setStyle

The label’s style. See section Visualizing Graph Elements.

ILabel.preferredSize

IGraph.setLabelPreferredSize

The label’s preferred size. The actual size of the label might differ depending on the layoutParameter

ILabel.tag

ILabel.tag

An object of arbitrary type that can be used to bind user data to this label. See Storing Business Data for Graph Elements.

The following image shows labels at nodes and edges with different styles and location model parameters. Edge labels can be axis-aligned or rotated with the edge, depending on their label model. See the section about label models.

Node labels and edge labels
graph model labels example

Even though labels are kept in their owner’s labels collection, you can only add or remove them by using IGraph’s methods.

addLabel(owner: ILabelOwner, text: string, layoutParameter: ILabelModelParameter, style: ILabelStyle, preferredSize: Size, tag: Object): ILabel

Creates a new label for the given owner. The new label’s properties will get the default values as defined in the label defaults if they are not passed as parameters.

remove(item: IModelItem): void

Removes the given label from the graph.

Important
You can only modify or remove labels that are part of the current graph instance. Trying to modify or remove a label that already has been removed will result in an exception. Also, if your use case involves several IGraph instances (especially if you are using filtering or folding) be careful to modify and remove labels only with the graph the label belongs to.