A class that accepts a collection of objects from the GraphBuilder to build INodes from.
Remarks
Type Parameters
- TDataItem
- The type of the data items in the source.
Type Details
- yfiles module
- view-component
- yfiles-umd modules
- All view modules
- Legacy UMD name
- yfiles.binding.NodesSource
See Also
Constructors
Creates a new source with the given nodeCreator
.
Parameters
A map of options to pass to the method.
- nodeCreator - NodeCreator<TDataItem>
- The creator that is used to create the nodes of this source.
- idProvider - function(TDataItem, Object):Object
- An optional function that yields an id for each element of the associated data collection in the GraphBuilder.
Signature Details
function(dataItem: TDataItem, canonicalId: any) : any
A callback that provides an unique identifier for thedataItem
.id provider are used in NodesSource.idProvider, EdgesSource.idProvider and LabelsSource.idProvider to identify the created nodes, edges and labels and avoid duplicate creation of items with the same ID.
The ID can also be used by parentIdProvider and sourceIdProvider and targetIdProvider to resolve the parent, source, or target nodes.
The ID is further used to identify nodes, edges, and labels during updateGraph.
Parameters
- dataItem - TDataItem
- 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.
Returns
- any
Properties
Gets or sets a provider that yields an id for each element of the associated data collection in the GraphBuilder.
Signature Details
function(dataItem: TDataItem, canonicalId: any) : any
dataItem
.id provider are used in NodesSource.idProvider, EdgesSource.idProvider and LabelsSource.idProvider to identify the created nodes, edges and labels and avoid duplicate creation of items with the same ID.
The ID can also be used by parentIdProvider and sourceIdProvider and targetIdProvider to resolve the parent, source, or target nodes.
The ID is further used to identify nodes, edges, and labels during updateGraph.
Parameters
- dataItem - TDataItem
- 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.
Returns
- any
See Also
Gets or sets the NodeCreator<TDataItem> for this source which can be used to adjust the creation behavior.
Gets or sets a provider that yields a parent id for each element of the associated data collection in the GraphBuilder.
Remarks
Signature Details
function(dataItem: TDataItem) : any
TValue
for the given dataItem
.Parameters
- dataItem - TDataItem
- The data item for which a value shall be provided.
Returns
- any
See Also
Methods
addChildNodesSource
<TChildDataItem>(childDataProvider: function(TDataItem):Object, childNodesSource: NodesSource<TChildDataItem>)Binds a collection of child data items to the given childNodesSource
.
Type Parameters
- TChildDataItem
- The type of the child data items in the source.
Parameters
A map of options to pass to the method.
- childDataProvider - function(TDataItem):Object
- A function that yields a child data item for each element of the associated data collection in the GraphBuilder.
- childNodesSource - NodesSource<TChildDataItem>
- The child node source to which the child data is bound.
addParentNodesSource
<TParentDataItem>(parentDataProvider: function(TDataItem):TParentDataItem, nodeSource: NodesSource<TParentDataItem>)Binds a provider for parents data items to the given nodeSource
.
Type Parameters
- TParentDataItem
- The type of the parent data items in the source.
Parameters
A map of options to pass to the method.
- parentDataProvider - function(TDataItem):TParentDataItem
- A function that yields a parent data item for each element of the associated data collection in the GraphBuilder.
Signature Details
function(dataItem: TDataItem) : TParentDataItem
A callback that provides an instance of typeTValue
for the givendataItem
.Parameters
- dataItem - TDataItem
- The data item for which a value shall be provided.
Returns
- TParentDataItem
- nodeSource - NodesSource<TParentDataItem>
- The node source to which the parent data is bound.
createChildNodesSource
<TChildDataItem>(childDataProvider: function(TDataItem):Object, idProvider?: function(TChildDataItem, Object):Object) : NodesSource<TChildDataItem>Registers a collection of child data items functioning as child entities for the NodeCreator<TChildDataItem> of the returned NodesSource<TChildDataItem>.
Remarks
This method can be used when nested groups and their contents are to be generated from hierarchically structured data.
const topLevelNodesSource = graphBuilder.createNodesSource(
topLevelNodesData,
(data) => data.nodeId
)
const childNodeSource = topLevelNodesSource.createChildNodesSource(
(data) => data.children
)
childNodeSource.addChildNodesSource(
(child) => child.children,
childNodeSource
)
The node defaults of this newly created source cascade with the defaults of this source.
Type Parameters
- TChildDataItem
- The type of the child data items in the source.
Parameters
A map of options to pass to the method.
- childDataProvider - function(TDataItem):Object
- A function that yields a child data item for each element of the associated data collection in the GraphBuilder.
- idProvider - function(TChildDataItem, Object):Object
- An optional function that yields an id for each element of the associated data collection in the GraphBuilder.
Signature Details
function(dataItem: TChildDataItem, canonicalId: any) : any
A callback that provides an unique identifier for thedataItem
.id provider are used in NodesSource.idProvider, EdgesSource.idProvider and LabelsSource.idProvider to identify the created nodes, edges and labels and avoid duplicate creation of items with the same ID.
The ID can also be used by parentIdProvider and sourceIdProvider and targetIdProvider to resolve the parent, source, or target nodes.
The ID is further used to identify nodes, edges, and labels during updateGraph.
Parameters
- dataItem - TChildDataItem
- 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.
Returns
- any
Returns
- ↪NodesSource<TChildDataItem>
- A new NodesSource<TDataItem> instance that can be used to further customize the creation of child nodes, e.g. provide specific style defaults.
See Also
createParentNodesSource
<TParentDataItem>(parentDataProvider: function(TDataItem):TParentDataItem, idProvider?: function(TParentDataItem, Object):Object) : NodesSource<TParentDataItem>Registers a collection of data items functioning as implicit parent entities for the NodeCreator<TParentDataItem> of the returned NodesSource<TParentDataItem>.
Remarks
This method can be used when a hierarchically structured graph should be created for this NodeSource without having to specify an explicit group node source.
const leafNodesSource = graphBuilder.createNodesSource(
leafNodesData,
(data) => data.nodeId
)
const parentSource = leafNodesSource.createParentNodesSource(
(data) => data.parent
)
This method returns a new NodesSource<TDataItem> instance which can in turn serve as input for subsequent calls to createParentNodesSource, thus enabling the creation of multi-layered hierarchies.
Calling this method creates only the immediate parent group nodes for the items in this node source. To automatically create higher hierarchy levels, use addParentNodesSource on the newly created parent node source
const leafNodesSource = graphBuilder.createNodesSource(
leafNodesData,
(data) => data.nodeId
)
const parentSource = leafNodesSource.createParentNodesSource(
(data) => data.parent
)
//Enable recursive ascent for the new parent source
parentSource.addParentNodesSource((data) => data.parent, parentSource)
The node defaults of this newly created source cascade with the defaults of this source.
Type Parameters
- TParentDataItem
- The type of the group data items in the source.
Parameters
A map of options to pass to the method.
- parentDataProvider - function(TDataItem):TParentDataItem
- A function that yields a parent data item for each element of the associated data collection in the GraphBuilder.
Signature Details
function(dataItem: TDataItem) : TParentDataItem
A callback that provides an instance of typeTValue
for the givendataItem
.Parameters
- dataItem - TDataItem
- The data item for which a value shall be provided.
Returns
- TParentDataItem
- idProvider - function(TParentDataItem, Object):Object
- An optional function that yields a unique id for each object returned by
parentDataProvider
This allows to create stable hierarchies even if the actual data items are not referentially equal.Signature Details
function(dataItem: TParentDataItem, canonicalId: any) : any
A callback that provides an unique identifier for thedataItem
.id provider are used in NodesSource.idProvider, EdgesSource.idProvider and LabelsSource.idProvider to identify the created nodes, edges and labels and avoid duplicate creation of items with the same ID.
The ID can also be used by parentIdProvider and sourceIdProvider and targetIdProvider to resolve the parent, source, or target nodes.
The ID is further used to identify nodes, edges, and labels during updateGraph.
Parameters
- dataItem - TParentDataItem
- 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.
Returns
- any
Returns
- ↪NodesSource<TParentDataItem>
- A new NodesSource<TDataItem> instance that can be used to further customize the creation of group nodes, e.g. provide specific style defaults.
See Also
Optionally obtains the id for the parent or null
given each data item for which a node is created.
Remarks
Parameters
A map of options to pass to the method.
- dataItem - TDataItem
- A single data item from the associated data collection in the GraphBuilder.
Returns
- ↪any
- The id of another node or
null
in case the node should be put in the root of the hierarchy.