Using a Data Provider Key - DP_KEY (version 1.x)
Tips & TricksSummary
Description
Many layout algorithms let you add additional information for the layout using data provider keys, named something like PREFERRED_EDGE_LENGTH_DP_KEY. This mechanism lets you control many aspects of the resulting layout. Here's how to do it.
Generally, a data provider maps instances of a type K to instances of a type V. For example, PREFERRED_EDGE_LENGTH_DP_KEY maps all edges (yfiles.graph.IEdge) to a number which represents the preferred edge length.
First you should know which types to use. You get this information from the API documentation of the data provider key. If the key and value types of a certain data provider key are not clear to you, please send us a support mail.
The code should look like this:
graph.mapperRegistry.addMapperWithTagAndGetter(yfiles.graph.IEdge.$class, yfiles.lang.Number.$class, yfiles.organic.SmartOrganicLayouter.PREFERRED_EDGE_LENGTH_DP_KEY, function(edge) {
// return data here
return edge.tag.length || 20;
});
The code above maps each edge to a preferred length that is stored in the edge tag. You can apply the same approach to every data provider key.