documentationfor yFiles for HTML 2.6

Labels

A label adds information to a graph element by providing a caption. It is modeled by interface ILabel. It has to belong to (i.e. added to) a label owner, modeled by the ILabelOwner interface. The three interfaces INode, IEdge, and IPort extend this interface. In this manual we sometimes refer to labels at nodes, edges, and ports as node labels, edge labels, and port labels, respectively. Note that a label owner can have an arbitrary number of labels.

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

Property Setter Method Description
ILabel.textIGraph.setLabelTextThe text which is displayed by the label.
ILabel.ownercannot be changed after creationThe node, edge, or port this label belongs to.
ILabel.layoutParameterIGraph.setLabelLayoutParameterAn ILabelModelParameter which defines the location of the label. See the section about label models.
ILabel.styleIGraph.setStyleThe label’s style. See section Visualization of Graph Elements: Styles.
ILabel.preferredSizeIGraph.setLabelPreferredSizeThe label’s preferred size. The actual size of the label might differ depending on the layoutParameter
ILabel.tagILabel.tagAn object of arbitrary type which 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. Note that 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

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

addLabel
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.

You can only modify or remove labels which are part of the current graph instance. Trying to modify or remove a label which 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) take care to modify and remove labels only with the graph the label belongs to.