Using a Data Provider Key - DP_KEY (version 1.x)

Tips & Tricks

Summary

Adding additional information for a layouter using one of the `*_DP_KEY` constants.

This article was written for an older version. It is only online as a reference for customers using this old version. The information it contains is probably out of date.

The latest information can be found in the yFiles documentation

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.

Categories this article belongs to:
yFiles for HTML
Applies to:
yFiles for HTML: 1.3, 1.4
Keywords:
DP_KEY - Layouter - Options - mapperRegistry - addMapper - addMapperWithTag - addMapperWithTagAndGetter