Represents a single item of type TItem
.
Remarks
Depending on which option is most convenient there are several ways to provide that item:
- item – to directly provide a single item that's already known
- source – to provide an IEnumerable<T> from which the first item is used. This is evaluated when running the algorithm and not before.
- delegate – to provide a predicate that checks whether an item should be used. The first matching one is used.
Only a single property should ever be set. When setting multiple properties to a non-null
value, some may be ignored and take precedence over others.
Functions, lists and constant values are automatically converted to SingleItem<TItem>s. For example:
// Item
new ShortestPath({ source: node1 })
// Predicate
new ShortestPath({ source: (node) => isSource(node) })
// Source
new ShortestPath({ source: graphComponent.selection.selectedNodes })
Furthermore, the conversion supports a parameter object to initialize the properties. For example:
// Create a new SingleItem from a JavaScript Map and initialize its 'item' with the given element.
// This also works for the different properties as well.
const singleItemFromItem = SingleItem.from({
item: graph.nodes.first()
})
// Or, instead of providing the specific property, the 'includes' key can be used
const singleItemFromInclude = SingleItem.from({
includes: graph.nodes.first()
})
Type Parameters
- TItem
- The type of the single item.
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.layout.SingleItem
See Also
Constructors
Constructor overload that directly sets the source that lists the item contained in this instance.
Parameters
A map of options to pass to the method.
- source - IEnumerable<TItem>
- An enumerable that lists the single item in this instance.
Constructor overload that directly sets the delegate that describes which item is 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
.
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 predicate that defines the item to use.
Remarks
The first item matching the predicate will be used for the layout or graph analysis algorithm.
This predicate will be evaluated anew for each successive invocation of the layout or graph analysis algorithm, making it possible to return a different item each time.
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 an item.
Remarks
This is the exact item that will be used for the layout or graph analysis algorithm.
Setting this property will override any previously set properties.
See Also
An IEnumerable<T> of items, the first of which is used.
Remarks
The first item from the IEnumerable<T> will be used for the layout or graph analysis algorithm.
This IEnumerable<T> will be evaluated anew for each successive invocation of the layout or graph analysis algorithm, making it possible to return a different item each time.
Setting this property will override any previously set properties.
See Also
Static Methods
Creates a SingleItem<TItem> instance from the given object by performing automatic type conversion.
Type Parameters
- TItem
- The type of the single item.
Parameters
A map of options to pass to the method.
- singleItemLike - SingleItem<TItem>
- The object to convert to a SingleItem<TItem>.
Returns
- ↪SingleItem<TItem>
- Either
singleItemLike
if it is already a SingleItem<TItem> or a new instance, initialized to /// the values found insingleItemLike
.