Provides different ways to define the items in a collection for use with LayoutData.
Remarks
Only one of the provided ways to define a collection can be used at the same time, therefore only one of the properties item, items, mapper, and delegate should be set on each instance.
Items in the excludes property are explicitly excluded from this collection, even if they are included in one of the item, items, mapper, or delegate properties.
This class supports LayoutData implementations and does not usually have to be used explicitly.
Functions, IMapper<K,V>s, lists and single items are automatically converted to ItemCollection<TItem>s. For example:
// Delegate
new TreeLayoutData({ assistantNodes: (node) => isAssistant(node) })
// Item
new TreeLayoutData({ assistantNodes: node1 })
// Items
new TreeLayoutData({ assistantNodes: [node1, node2] })
// Mapper
new TreeLayoutData({ assistantNodes: new Mapper() })
// or a JavaScript Map
new TreeLayoutData({ assistantNodes: new Map() })
// Source
new TreeLayoutData({ assistantNodes: graphComponent.selection.selectedNodes })
Furthermore, the conversion supports a parameter object to initialize the properties. For example:
// This provides a convenient way of specifying the subgraph for the algorithm:
const shortestPath1 = new ShortestPath({
// single source - single sink
source: startNode,
sink: endNode,
// only consider elliptical nodes in the graph
subgraphNodes: (node) =>
node.style instanceof ShapeNodeStyle &&
node.style.shape === ShapeNodeShape.ELLIPSE
})
// This provides a convenient way of specifying the excluded elements of the ItemCollection:
const shortestPath2 = new ShortestPath({
// single source - single sink
source: startNode,
sink: endNode,
subgraphNodes: {
// only consider elliptical nodes in the graph
includes: (node) =>
node.style instanceof ShapeNodeStyle &&
node.style.shape === ShapeNodeShape.ELLIPSE,
// but ignore the first node, regardless of its shape
excludes: graph.nodes.first()
}
})
// Create a new ItemCollection from a JavaScript Map and initialize its 'mapper' with the new Map.
// This also works for the other properties as well.
const collectionFromMapper = ItemCollection.from({
mapper: new Map()
})
// Or, instead of providing the specific property, the 'includes' key can be used
const collectionWithIncludes = ItemCollection.from({
includes: new Map()
})
// This provides a convenient way of specifying the subgraph for the algorithm:
const shortestPath1 = new ShortestPath({
// single source - single sink
source: startNode,
sink: endNode,
// only consider elliptical nodes in the graph
subgraphNodes: (node) =>
node.style instanceof ShapeNodeStyle &&
node.style.shape === ShapeNodeShape.ELLIPSE
})
// This provides a convenient way of specifying the excluded elements of the ItemCollection:
const shortestPath2 = new ShortestPath({
// single source - single sink
source: startNode,
sink: endNode,
subgraphNodes: {
// only consider elliptical nodes in the graph
includes: (node: INode) =>
node.style instanceof ShapeNodeStyle &&
node.style.shape === ShapeNodeShape.ELLIPSE,
// but ignore the first node, regardless of its shape
excludes: graph.nodes.first()
}
})
// Create a new ItemCollection from a JavaScript Map and initialize its 'mapper' with the new Map.
// This also works for the other properties as well.
const collectionFromMapper = ItemCollection.from({
mapper: new Map()
})
// Or, instead of providing the specific property, the 'includes' key can be used
const collectionWithIncludes = ItemCollection.from({
includes: new Map()
})
Type Parameters
- TItem
- The type of the items in the collection.
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.layout.ItemCollection
See Also
Constructors
Constructor overload that directly sets the items that hold the items are contained in this instance.
Parameters
A map of options to pass to the method.
- items - ICollection<TItem>
- An enumerable that holds the elements in this instance.
- excludes - ItemCollection<TItem>
- A collection of items which are explicitly excluded from this collection.
Constructor overload that directly sets the source that lists which items are contained in this instance.
Parameters
A map of options to pass to the method.
- source - IEnumerable<TItem>
- An enumerable that lists the elements in this instance.
- excludes - ItemCollection<TItem>
- A collection of items which are explicitly excluded from this collection.
Constructor overload that directly sets the mapper that describes which items are contained in this instance.
Parameters
A map of options to pass to the method.
- mapper - IMapper<TItem,boolean>
- An IMapper<K,V>that implements the mapping.
- excludes - ItemCollection<TItem>
- A collection of items which are explicitly excluded from this collection.
Constructor overload that directly sets the delegate that describes which items are contained in this instance.
Parameters
A map of options to pass to the method.
- delegate - function(TItem):boolean
- A delegate that implements the mapping.
Signature Details
function(obj: TItem) : boolean
Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.Parameters
- obj - TItem
- The object to compare against the criteria defined within the method represented by this delegate.
Returns
- boolean
true
if obj meets the criteria defined within the method represented by this delegate; otherwise,false
.
- excludes - ItemCollection<TItem>
- A collection of items which are explicitly excluded from this collection.
Constructor overload that directly sets the single item.
Parameters
A map of options to pass to the method.
- item - TItem
- The single item contained in this instance.
Properties
Gets or sets a delegate from the items to a boolean value.
Remarks
The returned boolean value describes whether an item is contained in the collection.
Setting this property will override any previously set properties.
Signature Details
function(obj: TItem) : boolean
Parameters
- obj - TItem
- The object to compare against the criteria defined within the method represented by this delegate.
Returns
- boolean
true
if obj meets the criteria defined within the method represented by this delegate; otherwise,false
.
See Also
Gets or sets a collection of items.
Remarks
This property is initialized by default and the returned collection can be used directly to add items.
Setting this property will override any previously set properties.
See Also
Gets or sets a mapping from the items to a boolean value.
Remarks
This property does not get initialized by default and needs to be set to a new instance by the user, if required.
The mapped boolean value specifies whether an item is contained in the collection.
Setting this property will override any previously set properties.
See Also
Get or sets an enumerable of items.
Remarks
This collection contains exactly the items in the given enumerable.
Setting this property will override any previously set properties.
See Also
Static Methods
Creates an ItemCollection<TItem> instance from the given object by performing automatic type conversion.
Type Parameters
- TItem
- The type of the items in the collection.
Parameters
A map of options to pass to the method.
- itemCollectionLike - ItemCollection<TItem>
- The object to convert to an ItemCollection<TItem>.
Returns
- ↪ItemCollection<TItem>
- Either
itemCollectionLike
if it is already an ItemCollection<TItem> or a new instance, initialized to the values found initemCollectionLike
.