documentationfor yFiles for HTML 2.6

ItemCollection<TItem>

Provides different ways to define the items in a collection for use with LayoutData.

Inheritance Hierarchy

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

Properties

Static Methods