- CEdgeCreator<TDataItem>
Remarks
These data items can be any business or arbitrary data which should be represented by edges.
EdgeCreator<TDataItem> allows for conveniently binding properties of the data item to the properties of the created IEdge to control aspects like the styling.
This class can be used both standalone as well as in conjunction with any of the GraphBuilders, e.g. GraphBuilder.
In the context of the GraphBuilder, it is responsible to create the items from the associated EdgesSource<TDataItem>s.
Type Parameters
TDataItem
- The type of the data items in the source.
Examples
An EdgeCreator<TDataItem> can either be used with an EdgesSource<TDataItem> in conjunction with a GraphBuilder
const builder = new GraphBuilder()
const edgeCreator = builder.createEdgesSource(
edgeData,
(item) => item.from,
(item) => item.to,
).edgeCreator
edgeCreator.defaults.shareStyleInstance = false
edgeCreator.defaults.style = new PolylineEdgeStyle()
edgeCreator.styleBindings.addBinding('stroke', (item) =>
item.assistant ? 'darkred' : 'darkorange',
)
builder.buildGraph()or it can be used standalone. In that case, its createEdge<TDataItem> method can be used to create edges.
const edgeCreator = new EdgeCreator<EdgeData>()
edgeCreator.defaults.shareStyleInstance = false
edgeCreator.defaults.style = new PolylineEdgeStyle()
edgeCreator.styleBindings.addBinding('stroke', (item) =>
item.assistant ? 'darkred' : 'darkorange',
)
const edge = edgeCreator.createEdge(
graph,
sourceNode,
targetNode,
dataItem,
)See Also
Developer's Guide
Members
Constructors
Properties
Gets or sets an optional provider of an object that will be used as the edge's IEdge.bends locations for the source data item.
Function Details
TValue for the given dataItem.- dataItem: TDataItem
- The data item for which a value shall be provided.
See Also
Developer's Guide
API
- getBends
Gets or sets a set of IEdgeDefaults that will be used for the edges and edge labels.
GraphBuilders, e.g. GraphBuilder, cascade with the defaults of the GraphBuilder's GraphBuilder.graph.See Also
Developer's Guide
Gets or sets an optional set of bindings that will be applied to the edge's IEdge.style.
true, the properties of the same instance are overwritten each time. To get fresh copies, set IEdgeDefaults.shareStyleInstance to false.See Also
Developer's Guide
API
- applyStyleBindings
Gets or sets an optional provider of an IEdgeStyle instance that will be used as the edge's IEdge.style for the source data item.
Function Details
TValue for the given dataItem.- dataItem: TDataItem
- The data item for which a value shall be provided.
See Also
Developer's Guide
API
- getStyle
Gets or sets an optional provider of an object that will be used as the edge's ITagOwner.tag for the source data item.
Function Details
TValue for the given dataItem.- dataItem: TDataItem
- The data item for which a value shall be provided.
- any
See Also
Developer's Guide
API
- getTag
Methods
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.
Type Parameters
TLabelDataItem
- The type of the data items in the source.
Parameters
- dataProvider: function(TDataItem): anyconversion
- A function that provides the label data items from the data item.
Function Details
A callback that provides an instance of typeTValuefor the givendataItem.Parameters- dataItem: TDataItem
- The data item for which a value shall be provided.
Return Value- any
- labelsSource: LabelsSource<TLabelDataItem>
- The source to which the data is added.
See Also
Resolves the styleBindings<TDataItem> against the given dataItem and applies them to the given edge style.
dataItem and applies them to the given edge style.Parameters
- graph: IGraph
- The managed graph.
- edge: IEdge
- The edge to update.
- dataItem: TDataItem
- The data item that is used.
Creates an edge in the graph with the values of the bindings resolved against the dataItem.
dataItem.Parameters
- graph: IGraph
- The graph to create the edge in.
- source: INode
- The source node.
- target: INode
- The target node.
- dataItem: TDataItem
- The data item from which the edge is created.
Return Value
- IEdge
- The newly created edge.
Examples
const edgeCreator = new EdgeCreator<EdgeData>()
edgeCreator.defaults.shareStyleInstance = false
edgeCreator.defaults.style = new PolylineEdgeStyle()
edgeCreator.styleBindings.addBinding('stroke', (item) =>
item.assistant ? 'darkred' : 'darkorange',
)
const edge = edgeCreator.createEdge(
graph,
sourceNode,
targetNode,
dataItem,
)createEdgeCore
(graph: IGraphsource: INodetarget: INodestyle: IEdgeStyletag: IEdge['tag'] | null): IEdgeprotectedCalled from createEdge<TDataItem> and performs the actual edge creation in the graph.
createEdgeCore
(Parameters
- graph: IGraph
- The graph to create the edge in.
- source: INode
- The source node.
- target: INode
- The target node.
- style: IEdgeStyle
- The style of the edge.
- tag: IEdge['tag'] | null
- The tag of the edge.
Return Value
- IEdge
- The newly created edge.
Creates a binding for labels that will be added to edges created by this instance.
text. Note that the item type of the returned LabelCreator<TDataItem> is the same as for this EdgeCreator<TDataItem>.Parameters
- text?: function(TDataItem): stringconversion
- An optional provider for the ILabel.text property. If the provider returns
nullorundefinedno label will be created. To force creation of an empty label the provider must return an empty string instead.Function Details
A callback that provides an instance of typeTValuefor the givendataItem.Parameters- dataItem: TDataItem
- The data item for which a value shall be provided.
Return Value- string
Return Value
- LabelCreator<TDataItem>
- A new LabelCreator<TData> instance that can be further configured.
Examples
Without further configuration createLabelBinding<TDataItem> creates labels with the text provided by the given text and the graph's default label LabelDefaults.style.
edgesSource.edgeCreator.createLabelBinding(
(edgeObject) => edgeObject.name,
)The returned LabelCreator<TDataItem> can be used to configure the label appearance further. Note that the data item it uses is the data item for the owning edge:
const labelCreator = edgesSource.edgeCreator.createLabelBinding(
(edgeObject) => edgeObject.name,
)
labelCreator.styleProvider = (edgeObject) =>
edgeObject.edgeType === 'Main' ? mainLabelStyle : defaultLabelStyleIt is also possible to ignore the provided text and create an icon instead, using the IconLabelStyle:
const labelCreator = edgesSource.edgeCreator.createLabelBinding()
// to avoid empty labels to be created return null for missing image URL
labelCreator.textProvider = (edgeObject) =>
typeof edgeObject.imageUrl !== 'undefined' ? ' ' : null
labelCreator.styleProvider = (edgeObject) =>
new IconLabelStyle({
href: edgeObject.imageUrl,
iconSize: new Size(16, 16),
iconPlacement: ExteriorNodeLabelModel.LEFT,
})createLabelsSource
<TLabelDataItem> (data: function(TDataItem): any, id?: function(TLabelDataItem, any): any): LabelsSource<TLabelDataItem>Creates a new source of label data items that will be added to edges created by this instance.
createLabelsSource
<TLabelDataItem> (data: function(TDataItem): any, id?: function(TLabelDataItem, any): any): LabelsSource<TLabelDataItem>data introduces a new item type for the returned LabelsSource<TDataItem>. Also note that the data is expected to return an IEnumerable<T> of that type.Type Parameters
TLabelDataItem
- The type of the data items in the source.
Parameters
- data: function(TDataItem): anyconversion
- A function that provides a collection of label data items from the edge data item.
Function Details
A callback that provides an instance of typeTValuefor the givendataItem.Parameters- dataItem: TDataItem
- The data item for which a value shall be provided.
Return Value- any
- id?: function(TLabelDataItem, any): anyconversion
- An optional function that yields an id for each label data item that is provided from the label data provider. This id is used to identify the labels during updateLabels<TDataItem>.
Function Details
A callback that provides an unique identifier for thedataItem.Parameters- dataItem: TLabelDataItem
- The value that will be passed in.
- canonicalId: any
- The original canonical id of the value. For data arrays and iterables this is the index into the collection. For Maps and data objects this is the key associated with a value.
Return Value- any
Return Value
- LabelsSource<TLabelDataItem>
- A new LabelsSource<TDataItem> instance whose LabelCreator<TDataItem> can be configured further.
Examples
A simple usage of createLabelsSource<TDataItem> note that a LabelCreator.textProvider<TDataItem> has to be configured on the returned LabelsSource<TDataItem>'s LabelsSource.labelCreator<TDataItem>.
const labelsSource = edgesSource.edgeCreator.createLabelsSource(
(edgeObject) => edgeObject.labels,
)
labelsSource.labelCreator.textProvider = (labelObject) =>
labelObject.textThe label objects might encode more information which can be used for individual styling of the labels:
const labelsSource = edgesSource.edgeCreator.createLabelsSource(
(edgeObject) => edgeObject.labels,
)
labelsSource.labelCreator.styleProvider = (labelObject) =>
labelObject.style === 'Orange'
? orangeLabelStyle
: defaultLabelStyle
labelsSource.labelCreator.textProvider = (labelObject) =>
labelObject.textObtains an Point array by resolving the bendsProvider<TDataItem>.
Parameters
- dataItem: TDataItem
- The data item on which the provider is resolved.
Return Value
- IEnumerable<Point> | null
- The value to use or
nullin case no bend locations are given.
See Also
null, the defaults<TDataItem> are used.Parameters
- dataItem: TDataItem
- The data item on which the provider is resolved.
Return Value
- IEdgeStyle | null
- The value to use or
nullin case the defaults should be used.
See Also
Parameters
- dataItem: TDataItem
- The data item on which the provider is resolved.
Return Value
- any | null
- The value to use or
nullin case the defaults should be used.
See Also
API
- tagProvider
Resolves the bendsProvider<TDataItem> on the given data item.
Parameters
- graph: IGraph
- The managed graph.
- edge: IEdge
- The edge for which the new tag should be obtained.
- dataItem: TDataItem
- The data item that is used.
Return Value
- IEnumerable<Point> | null
- Returns the updated bends object.
Resolves the styleProvider<TDataItem> and then applies the style bindings.
Parameters
- graph: IGraph
- The managed graph.
- edge: IEdge
- The edge to update.
- dataItem: TDataItem
- The data item that is used.
Return Value
- IEdgeStyle
- 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.
Parameters
- graph: IGraph
- The managed graph.
- edge: IEdge
- The edge 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.
Triggers the edge-created<TDataItem> event.
Parameters
- graph: IGraph
- The graph in which the edge has been created.
- edge: IEdge
- The edge that has been created.
- dataItem: TDataItem
- The data item from which the edge has been created.
Triggers the edge-updated<TDataItem> event.
Parameters
- graph: IGraph
- The graph in which the edge has been updated.
- edge: IEdge
- The edge that has been updated.
- dataItem: TDataItem
- The data item with which the edge has been updated.
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 bends of the edge with the given dataItem by calling getUpdatedBends<TDataItem> and updating the bends on the edge in the graph.
edge with the given dataItem by calling getUpdatedBends<TDataItem> and updating the bends on the edge in the graph.Parameters
- graph: IGraph
- The managed graph.
- edge: IEdge
- The edge to update.
- dataItem: TDataItem
- The data item that is used for the update.
By default, this method only fires the edge-updated<TDataItem> event.
To update other aspects of the edge instance, call the respective update methods when the edge is updated or override this method.
// configure the EdgeCreator to update non-structural aspects
edgeCreator.addEventListener('edge-updated', (evt) => {
edgeCreator.updateBends(evt.graph, evt.item, evt.dataItem)
edgeCreator.updateLabels(evt.graph, evt.item, evt.dataItem)
edgeCreator.updateStyle(evt.graph, evt.item, evt.dataItem)
edgeCreator.updateTag(evt.graph, evt.item, evt.dataItem)
})Note that existing labels whose properties (e.g. text) may change have to be configured similarly.
Parameters
- graph: IGraph
- The graph that contains the edge.
- edge: IEdge
- The edge to update.
- dataItem: TDataItem
- The data item with which the edge should be updated.
See Also
Can be used to update the labels of the edge that have been added with this EdgeCreator<TDataItem>.
// configure the LabelCreators to update non-structural aspects
const labelCreator1 = edgeCreator.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 = edgeCreator.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 managed graph.
- edge: IEdge
- The edge whose labels to update.
- dataItem: TDataItem
- The edge data item with which the edge's labels should be updated.
Updates the style of the edge with the given dataItem by calling getUpdatedStyle<TDataItem> and applying the style to the edge in the graph.
edge with the given dataItem by calling getUpdatedStyle<TDataItem> and applying the style to the edge in the graph.Parameters
- graph: IGraph
- The managed graph.
- edge: IEdge
- The edge to update.
- dataItem: TDataItem
- The data item that is used for the update.
Updates the ITagOwner.tag of the edge with the given dataItem by calling getUpdatedTag<TDataItem> and setting the new tag on the edge.
edge with the given dataItem by calling getUpdatedTag<TDataItem> and setting the new tag on the edge.Parameters
- graph: IGraph
- The managed graph.
- edge: IEdge
- The edge to update.
- dataItem: TDataItem
- The data item that is used for the update.
Events
Occurs when a edge has been created.
Properties of GraphBuilderItemEventArgs<IEdge, TDataItem>
- dataItem: TDataItemfinal
- Gets the object the ItemEventArgs.item<T> has been created from.
- graph: IGraphfinal
- Gets the graph that can be used to modify the ItemEventArgs.item<T>.
- item: TItemfinal
- Gets the item that is the subject of the event.
See Also
API
- edge-updated
Occurs when a edge has been updated.
Properties of GraphBuilderItemEventArgs<IEdge, TDataItem>
- dataItem: TDataItemfinal
- Gets the object the ItemEventArgs.item<T> has been created from.
- graph: IGraphfinal
- Gets the graph that can be used to modify the ItemEventArgs.item<T>.
- item: TItemfinal
- Gets the item that is the subject of the event.
See Also
Developer's Guide
API
- edge-created