C

LabelCreator<TDataItem>

This class can be used to create and update ILabels based on data items.
Inheritance Hierarchy

Remarks

These data items can be any business or arbitrary data which should be represented by labels.

LabelCreator<TDataItem> allows to conveniently bind properties of the data item to the properties of the created ILabel to control aspects like layout and styling.

In the context of the GraphBuilder, it is responsible to create the labels from the associated NodesSource<TDataItem>s and EdgesSource<TDataItem>s.

Type Parameters

TDataItem

The type of the data items in the source.

See Also

Developer's Guide

Members

Show:

Constructors

Creates a new creator for labels.

Parameters

Properties

Gets or sets a set of ILabelDefaults that will be used for the labels.
The defaults of instances of this class created by e.g. createLabelBinding, cascade with the defaults of the NodeCreator<TDataItem>.
final

See Also

Developer's Guide
Gets or sets an optional provider of a label model parameter that will be used as the label's layoutParameter for the source data item.
Gets or sets an optional binding that will be applied to the label.
Gets or sets an optional provider of the size that will be used as the label's preferredSize for the source data item.
Gets or sets an optional set of bindings that will be applied to the label's style.
Note that bindings will affect the properties of the instance created by getStyle. If the style is obtained from the defaults with shareStyleInstance set to true, the properties of the same instance are overwritten each time. To get fresh copies, set shareStyleInstance to false.
conversionfinal

See Also

Developer's Guide
API
applyStyleBindings
Gets or sets an optional provider of an ILabelStyle instance that will be used as the label's style for the source data item.
By default the defaults' style will be used. Note that shareStyleInstance will be ignored if this provider returns a value. Use the styleBindings to reconfigure properties of the style instances.
conversionfinal

See Also

Developer's Guide
API
getStyle
Gets or sets an optional provider of an object that will be used as the label's tag for the source data item.
By default the source data item itself will be used as the tag.
conversionfinal

See Also

Developer's Guide
API
getTag
Gets or sets an optional provider of the text that will be used as the label's text for the source data item.
If the provider returns null or undefined no label will be created. To force creation of an empty label, the provider must return an empty string instead.
conversionfinal

See Also

Developer's Guide
API
getText

Methods

Adds a label on the given ILabelOwner with the values of the bindings resolved against the dataItem.

This method will use the various helper methods in this class to determine the values for the label's properties.

If the dataItem doesn't provide a label, this method returns null.

Parameters

graph: IGraph
The graph.
owner: ILabelOwner
The owner to which the label should be added.
dataItem: TDataItem
The data item for which to create the label.

Return Value

ILabel
The newly added label.

See Also

API
getLayoutParameter, getPreferredSize, getText, getStyle, getTag, applyPreferredSizeBindings, applyStyleBindings
Called from addLabel and performs the actual label creation in the graph.
protected

Parameters

graph: IGraph
The graph to create the node in.
owner: ILabelOwner
The owner to which the label should be added.
text: string
The label's text.
layoutParameter: ILabelModelParameter
The layout parameter of the label.
style: ILabelStyle
The style of the label.
preferredSize: Size
The preferred size of the label.
tag: ILabel['tag']
The tag of the node.

Return Value

ILabel
The newly added label.
Resolves the preferredSizeBindings against the given dataItem and applies them to the given label preferredSize.
The preferredSizeProvider is not evaluated by this method.
final

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used.

See Also

API
updatePreferredSize
Resolves the styleBindings against the given dataItem and applies them to the given label style.
The styleProvider is not evaluated by this method.
final

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used.

See Also

API
updateStyle
Obtains a layoutParameter instance or null by resolving layoutParameterProvider on the data item.
protected

Parameters

dataItem: TDataItem
The data item on which the provider is resolved.

Return Value

ILabelModelParameter
The value to use or null in case the defaults should be used.

See Also

API
layoutParameterProvider
Obtains a preferredSize or null by resolving the preferredSizeProvider on the data item.
protected

Parameters

dataItem: TDataItem
The data item on which the provider is resolved.

Return Value

Size
The value to use or null in case the defaults should be used.

See Also

API
preferredSizeProvider
Obtains an ILabelStyle instance or null by resolving the styleProvider.
In case of null, the defaults are used.
protected

Parameters

dataItem: TDataItem
The data item on which the provider is resolved.

Return Value

ILabelStyle
The value to use or null in case the defaults should be used.

See Also

API
styleProvider, styleBindings
Obtains an object to use as tag by resolving the tagProvider on the data item.
The tag can be any value and does not need to be related to the original source data item or its ID.
protected

Parameters

dataItem: TDataItem
The data item on which the provider is resolved.

Return Value

any
The value to use or null in case the defaults should be used.

See Also

API
tagProvider
Obtains a string to use as text or null by resolving the textProvider on the data item.
protected

Parameters

dataItem: TDataItem
The data item on which the provider is resolved.

Return Value

string
The value to use or null in case no text should be added.

See Also

API
textProvider
Resolves the layoutParameterProvider on the given data item.

By default, it only delegates to getLayoutParameter.

This method is called by updateLayoutParameter.

protected

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used.

Return Value

ILabelModelParameter
The new layout parameter instance. Either the value returned by getLayoutParameter, or the default layout parameter, if getLayoutParameter returns null.
This method is called by updatePreferredSize.
protected

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label for which the size should be updated.
dataItem: TDataItem
The data item that is used.

Return Value

Size
Returns the label's new preferred size.
This method is called by updateStyle.
protected

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used.

Return Value

ILabelStyle
The updated style instance. Either the value returned by getStyle, or the default style, if getStyle returns null.
Resolves the tagProvider on the given data item.

By default, it only delegates to getTag.

This method is called by updateLayoutParameter.

protected

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label for which the new tag should be obtained.
dataItem: TDataItem
The data item that is used.

Return Value

any
Returns the updated tag object.
Resolves the textProvider on the given data item.

By default, it only delegates to getText.

This method is called by updateLayoutParameter.

protected

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label for which the new text should be obtained.
dataItem: TDataItem
The data item that is used.

Return Value

string
Returns the new text.
Triggers the label-added event.
protected

Parameters

graph: IGraph
The graph in which the label has been added.
dataItem: TDataItem
The data item from which the label has been created.
label: ILabel
The label that has been added.
Triggers the label-updated event.
protected

Parameters

graph: IGraph
The graph in which the label has been updated.
dataItem: TDataItem
The data item with which the label has been updated.
label: ILabel
The label that has been updated.
Updates the label.

By default, this method only fires the label-updated event.

To update other aspects of the label instance, call the respective update methods when the label is updated or overwrite this method:

// configure the LabelCreators to update non-structural aspects
const labelCreator1 = nodeCreator.createLabelBinding((item) => item.name)
labelCreator1.addEventListener('label-updated', (evt) => {
  labelCreator1.updateText(evt.graph, evt.item, evt.dataItem)
  labelCreator1.updateStyle(evt.graph, evt.item, evt.dataItem)
  labelCreator1.updatePreferredSize(evt.graph, evt.item, evt.dataItem)
  labelCreator1.updateLayoutParameter(evt.graph, evt.item, evt.dataItem)
  labelCreator1.updateTag(evt.graph, evt.item, evt.dataItem)
})
// each LabelCreator has to be configured
const labelCreator2 = nodeCreator.createLabelBinding(
  (item) => item.description,
)
labelCreator2.addEventListener('label-updated', (evt) => {
  // only update properties which may change
  labelCreator2.updateText(evt.graph, evt.item, evt.dataItem)
})

Parameters

graph: IGraph
The graph that contains the edge.
label: ILabel
The label to update.
dataItem: TDataItem
The data item with which the label should be updated.

Return Value

boolean
true if the label has been updated. If false the label information has been removed from dataItem and therefore the label will be removed, too.

See Also

API
updateLayoutParameter, updatePreferredSize, updateStyle, updateText, updateTag, applyStyleBindings, applyPreferredSizeBindings
Updates the layoutParameter of the label with the given dataItem by calling getUpdatedLayoutParameter and setting the new parameter on the label.
final

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used for the update.
Updates the preferredSize of the label with the given dataItem by calling getUpdatedPreferredSize and setting the new size on the label.
final

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used for the update.
Updates the style of the label with the given dataItem by calling getUpdatedStyle and applying the style to the node in the graph.
final

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used for the update.
Updates the tag of the label with the given dataItem by calling getUpdatedTag and setting the new tag on the label.
final

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used for the update.
Updates the text of the label with the given dataItem by calling getUpdatedText and setting the new text on the label.
final

Parameters

graph: IGraph
The managed graph.
label: ILabel
The label to update.
dataItem: TDataItem
The data item that is used for the update.

Events

Occurs when a label has been added.

Properties of

GraphBuilderItemEventArgs<ILabel, TDataItem>
dataItem: TDataItem
Gets the object the item has been created from.
graph: IGraph
Gets the graph that can be used to modify the item.
item: TItem
Gets the item that is the subject of the event.

See Also

API
label-updated
Occurs when a label has been updated.

Properties of

GraphBuilderItemEventArgs<ILabel, TDataItem>
dataItem: TDataItem
Gets the object the item has been created from.
graph: IGraph
Gets the graph that can be used to modify the item.
item: TItem
Gets the item that is the subject of the event.

See Also

API
label-added