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.

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. NodeCreator.createLabelBinding<TDataItem>, cascade with the defaults of the NodeCreator<TDataItem>.
final
Gets or sets an optional provider of a label model parameter that will be used as the label's ILabel.layoutParameter for the source data item.
conversionfinal
Function Details
A callback that provides an instance of type TValue for the given dataItem.
Parameters
dataItem: TDataItem
The data item for which a value shall be provided.
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 ILabel.preferredSize for the source data item.
conversionfinal
Function Details
A callback that provides an instance of type TValue for the given dataItem.
Parameters
dataItem: TDataItem
The data item for which a value shall be provided.
Return Value
Size
Gets or sets an optional set of bindings that will be applied to the label's ILabel.style.
Note that bindings will affect the properties of the instance created by getStyle<TDataItem>. If the style is obtained from the defaults<TDataItem> with ILabelDefaults.shareStyleInstance set to true, the properties of the same instance are overwritten each time. To get fresh copies, set ILabelDefaults.shareStyleInstance to false.
conversionfinal
Gets or sets an optional provider of an ILabelStyle instance that will be used as the label's ILabel.style for the source data item.
By default the defaults<TDataItem>' ILabelDefaults.style will be used. Note that ILabelDefaults.shareStyleInstance will be ignored if this provider returns a value. Use the styleBindings<TDataItem> to reconfigure properties of the style instances.
conversionfinal
Function Details
A callback that provides an instance of type TValue for the given dataItem.
Parameters
dataItem: TDataItem
The data item for which a value shall be provided.
Return Value
ILabelStyle
Gets or sets an optional provider of an object that will be used as the label's ITagOwner.tag for the source data item.
By default the source data item itself will be used as the tag.
conversionfinal
Function Details
A callback that provides an instance of type TValue for the given dataItem.
Parameters
dataItem: TDataItem
The data item for which a value shall be provided.
Return Value
any
Gets or sets an optional provider of the text that will be used as the label's ILabel.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
Function Details
A callback that provides an instance of type TValue for the given dataItem.
Parameters
dataItem: TDataItem
The data item for which a value shall be provided.
Return Value
string

Methods

Adds an event handler for a given event type.
final

Parameters

type: string
A string which represents the type of the event to register as listed in events.
listener: function(EventArgs, this): void
The function which will be invoked when the event is raised.
options?: ListenerOptions
Options which specify how the listener will be invoked.
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 | null
The newly added label.
Called from addLabel<TDataItem> 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 | null
The preferred size of the label.
tag: ILabel['tag'] | null
The tag of the node.

Return Value

ILabel
The newly added label.
Resolves the preferredSizeBindings<TDataItem> against the given dataItem and applies them to the given label preferredSize.
The preferredSizeProvider<TDataItem> 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.
Resolves the styleBindings<TDataItem> against the given dataItem and applies them to the given label style.
The styleProvider<TDataItem> 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 ILabel.layoutParameter instance or null by resolving layoutParameterProvider<TDataItem> on the data item.
protected

Parameters

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

Return Value

ILabelModelParameter | null
The value to use or null in case the defaults should be used.
Obtains a ILabel.preferredSize or null by resolving the preferredSizeProvider<TDataItem> on the data item.
protected

Parameters

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

Return Value

Size | null
The value to use or null in case the defaults should be used.
Obtains an ILabelStyle instance or null by resolving the styleProvider<TDataItem>.
In case of null, the defaults<TDataItem> are used.
protected

Parameters

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

Return Value

ILabelStyle | null
The value to use or null in case the defaults should be used.
Obtains an object to use as ITagOwner.tag by resolving the tagProvider<TDataItem> 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 | null
The value to use or null in case the defaults should be used.

See Also

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

Parameters

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

Return Value

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

See Also

API
textProvider
Resolves the layoutParameterProvider<TDataItem> on the given data item.

By default, it only delegates to getLayoutParameter<TDataItem>.

This method is called by updateLayoutParameter<TDataItem>.

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<TDataItem>, or the default layout parameter, if getLayoutParameter<TDataItem> returns null.
This method is called by updatePreferredSize<TDataItem>.
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.
Resolves the styleProvider<TDataItem> and then applies the style bindings.
This method is called by updateStyle<TDataItem>.
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<TDataItem>, or the default style, if getStyle<TDataItem> returns null.
Resolves the tagProvider<TDataItem> on the given data item.

By default, it only delegates to getTag<TDataItem>.

This method is called by updateLayoutParameter<TDataItem>.

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 | null
Returns the updated tag object.
Resolves the textProvider<TDataItem> on the given data item.

By default, it only delegates to getText<TDataItem>.

This method is called by updateLayoutParameter<TDataItem>.

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<TDataItem> 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<TDataItem> 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.
Adds an event handler for a given event type.
final

Parameters

type: string
A string which represents the type of the event to register as listed in events.
listener: function(EventArgs, this): void
The function which will be invoked when the event is raised.
options?: ListenerOptions
Options which specify how the listener will be invoked.
Updates the label.

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

To update other aspects of the label instance, call the respective update methods when the label is updated or override 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.
Updates the ILabel.layoutParameter of the label with the given dataItem by calling getUpdatedLayoutParameter<TDataItem> 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 ILabel.preferredSize of the label with the given dataItem by calling getUpdatedPreferredSize<TDataItem> 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<TDataItem> 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 ITagOwner.tag of the label with the given dataItem by calling getUpdatedTag<TDataItem> 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 ILabel.text of the label with the given dataItem by calling getUpdatedText<TDataItem> 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
final
Gets the object the ItemEventArgs.item<T> has been created from.
graph: IGraph
final
Gets the graph that can be used to modify the ItemEventArgs.item<T>.
item: TItem
final
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
final
Gets the object the ItemEventArgs.item<T> has been created from.
graph: IGraph
final
Gets the graph that can be used to modify the ItemEventArgs.item<T>.
item: TItem
final
Gets the item that is the subject of the event.

See Also

API
label-added