Provides different ways to define a mapping from items to values for use with LayoutData.
Remarks
Only one of the provided ways to define a mapping can be used at the same time, therefore only one of the properties mapper, delegate and constant should be set on each instance.
This class supports LayoutData implementations and does not usually have to be instantiated by client code explicitly. Instances of this class are properties of concrete LayoutData implementations.
Functions, IMapper<K,V>s and constant values are automatically converted to ItemMapping<TItem,TValue>s. For example:
// Constant
new HierarchicLayoutData({
sourcePortCandidates: [
PortCandidate.createCandidate('east', 0),
PortCandidate.createCandidate('west', 0)
]
})
// Delegate
new HierarchicLayoutData({
sourcePortCandidates: () =>
ICollection.from(
east
? [PortCandidate.createCandidate('east', 0)]
: [PortCandidate.createCandidate('west', 0)]
)
})
// Mapper
new HierarchicLayoutData({ sourceGroupIds: new Mapper() })
// or a JavaScript Map
new HierarchicLayoutData({ sourceGroupIds: new Map() })
Furthermore, the conversion supports a parameter object to initialize the properties. For example:
// Create a new ItemMapping from a JavaScript Map and initialize its 'mapper' with the new Map.
// This also works for the different properties as well.
const mappingFromMapper = ItemMapping.from({
mapper: new Map()
})
// Or, instead of providing the specific property, the 'includes' key can be used
const mappingWithIncludes = ItemMapping.from({
includes: new Map()
})
Type Parameters
- TItem
- The type of the items that are mapped.
- TValue
- The type of the values the items are mapped to.
Type Details
- yfiles module
- view-layout-bridge
- yfiles-umd modules
- view-layout-bridge
- Legacy UMD name
- yfiles.layout.ItemMapping
See Also
Constructors
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.
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
Gets or sets an IMapper<K,V> that realizes the mapping.
Remarks
See Also
Static Methods
Creates a ItemMapping<TItem,TValue> 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.
Parameters
A map of options to pass to the method.
- itemMappingLike - ItemMapping<TItem,TValue>
- The object to convert to a ItemMapping<TItem,TValue>.
Returns
- ↪ItemMapping<TItem,TValue>
- Either
itemMappingLike
if it is already a ItemMapping<TItem,TValue> or a new instance, initialized to /// the values found initemMappingLike
.