Provides different ways to define a mapping from items to values that takes a context object into consideration, too.
Remarks
Only one of the provided ways to define a mapping can be used at the same time, therefore only one of the properties contextDelegate, delegate, mapper, and constant should be set on each instance.
This class supports LayoutData implementations and does not usually have to be used explicitly.
Functions, IMapper<K,V>s and constant values are automatically converted to ContextItemMapping<TItem,TValue,TContext>s. For example:
// Constant
new PartitionGridData({ cellIds: partitionGrid.createCellId(0, 0) })
// Context Delegate
new PartitionGridData({ cellIds: (node, grid) => grid.createCellId(0, 0) })
// or
const grid = new PartitionGrid(4, 4)
new PartitionGridData({ cellIds: () => grid.createCellId(0, 0) })
// Mapper
new PartitionGridData({ cellIds: new Mapper() })
// or a JavaScript Map
new PartitionGridData({ cellIds: new Map() })
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 items that are mapped.
- TValue
- The type of the values the items are mapped to.
- TContext
- The type of the context passed to the
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.layout.ContextItemMapping
Constructors
Default constructor that does not explicitly initialize any of the contextDelegate, mapper, delegate or constant properties.
Constructor overload that directly sets the delegate.
Parameters
A map of options to pass to the method.
- delegate - function(TItem):TValue
- A delegate that implements the mapping.
Signature Details
function(key: TItem) : TValue
A delegate that mimics the get access.Parameters
- key - TItem
- The key of the mapping.
Returns
- TValue
- The value or a suitable default that is associated with
key
.
Constructor overload that directly sets the mapper.
Parameters
A map of options to pass to the method.
- mapper - IMapper<TItem,TValue>
- An IMapper<K,V> that implements the mapping.
Constructor overload that directly sets a constant mapping.
Parameters
A map of options to pass to the method.
- constant - TValue
- A constant value all items are mapped to.
Properties
Gets or sets a constant value all items are mapped to.
Remarks
See Also
Defined in
Gets or sets a delegate from the items and a context object to the values.
Signature Details
function(arg1: TItem, arg2: TContext) : TValue
TResult
parameter.Parameters
- arg1 - TItem
- The first parameter of the method that this delegate encapsulates.
- arg2 - TContext
- The second parameter of the method that this delegate encapsulates.
Returns
- TValue
- The return value of the method that this delegate encapsulates.
Gets or sets a delegate that implements the mapping.
Remarks
Signature Details
function(key: TItem) : TValue
Parameters
- key - TItem
- The key of the mapping.
Returns
- TValue
- The value or a suitable default that is associated with
key
.
See Also
Defined in
Gets or sets an IMapper<K,V> that realizes the mapping.
Remarks
See Also
Defined in
Static Methods
from
<TItem,TValue,TContext>(itemMappingLike: ContextItemMapping<TItem,TValue,TContext>) : ContextItemMapping<TItem,TValue,TContext>Creates a ContextItemMapping<TItem,TValue,TContext> instance from the given object by performing automatic type conversion.
Type Parameters
- TItem
- The type of the items that are mapped.
- TValue
- The type of the values the items are mapped to.
- TContext
- The type of the context passed to the
Parameters
A map of options to pass to the method.
- itemMappingLike - ContextItemMapping<TItem,TValue,TContext>
- The object to convert to a ContextItemMapping<TItem,TValue,TContext>.
Returns
- ↪ContextItemMapping<TItem,TValue,TContext>
- Either
itemMappingLike
if it is already a ContextItemMapping<TItem,TValue,TContext> or a new instance, initialized to /// the values found initemMappingLike
.