The interface used in an IGraph implementation for labels.
Remarks
IGraph
, this item supports the lookup method that can be used to query additional aspects of the item.Examples
const graph = graphComponent.graph
const node = graph.createNodeAt(new Point(0, 0))
// add a label to the node
const label = graph.addLabel(
node,
'Some Text',
ExteriorNodeLabelModel.BOTTOM,
)
// the newly created label is part of the graph
console.log(graph.contains(label)) // true
console.log(graph.labels.size) // 1
// the label belongs to its owner
console.log(label.owner === node) // true
console.log(node.labels.size) // 1
console.log(node.labels.get(0) === label) // true
// removing the label removes it from the graph
graph.remove(label)
console.log(graph.contains(label)) // false
console.log(graph.labels.size) // 0
// and from its owner
console.log(node.labels.size) // 0
console.log(label.owner === null) // throws Error!!
console.log(graph.contains(label)) // true
graph.remove(label.owner)
console.log(graph.contains(label)) // false
Related Reading in the Developer's Guide
The graph model with all relevant types and their relationships is presented in detail in the section The Graph Model.
Using the look-up mechanism is explained in the section Service Locator Pattern: Lookup.
Type Details
- yFiles module
- view
See Also
Properties
Gets the index of the label at its owner.
Gets a snapshot of the current layout of the label.
Remarks
<0,-1>
), it coincides with its lower left corner. The positioning of the label is determined using a pair of ILabelModel and ILabelModelParameter. In order to modify the layout of a label instance, set another layoutParameter for this label or modify its associated instance.See Also
Gets the label model's parameter that determines the positioning of this label.
Remarks
Note that the label model parameter instance associated with a label instance may be shared between multiple label instances and that the modification of this instance or its model will result in a change of the positioning of all labels that are associated with the same parameter or model instance.
To change the layout parameter for instances of the default implementation that were created via the factory methods on IGraph, use the setLabelLayoutParameter method.
Examples
graph.setLabelLayoutParameter(label, InteriorNodeLabelModel.CENTER)
const parameter = label.layoutParameter
const layout = label.layout
See Also
Gets the owner of this label.
Remarks
Throws
- Exception({ name: 'InvalidOperationError' })
- if the label has no owner.
Examples
// add a label to the owner
const label = graph.addLabel(owner, 'Some Text')
// the label's Owner property is set to the owner
console.log(label.owner === owner) // true
// the label is in its owner's Labels collection
console.log(owner.labels.includes(label)) // true
See Also
Gets the preferred size of the label with respect to its current contents and the implementation of the visualization.
Remarks
Often the layout's size will be the same as the preferred size, but it's up to the implementation of the ILabelModel to interpret it differently.
To change the preferred size for instances of the default implementation that were created via the factory methods on IGraph, use the setLabelPreferredSize method.
Examples
graph.setLabelPreferredSize(label, new Size(width, height))
const size = label.preferredSize
See Also
Gets the style that is responsible for the visual representation of this node in a CanvasComponent.
Remarks
Note that the style instance associated with a label instance may be shared between multiple label instances and that the modification of this style will result in a change of the appearance of all labels that are associated with the same style instance.
To change the style for instances of the default implementation that were created via the factory methods on IGraph, use the setStyle method.
Examples
graph.setStyle(label, new LabelStyle())
const style = label.style
See Also
Gets or sets the tag object associated with this item instance.
Remarks
Property Value
Examples
owner.tag = newTag
const tag = owner.tag
See Also
Implements
Gets the text string associated with this label.
Remarks
It is up to the visualization engine to interpret this property for the visualization of the label. Normally, it will render the text into the layout of this instance.
To change the text for instances of the default implementation that were created via the factory methods on IGraph, use the setLabelText method.
Examples
graph.setLabelText(label, 'Some Text')
const text = label.text
See Also
Methods
Returns an instance that implements the given type or null
.
Remarks
null
implementations for the types, nor does it have to return the same instance any time. Also, it depends on the type and context whether the instance returned stays up to date or needs to be re-obtained for further use.Type Parameters
- T
Parameters
A map of options to pass to the method.
- type - Constructor<T>
- the type for which an instance shall be returned
Returns
- ↪T?
- an instance that is assignable to the type or
null