|| | |||Browse by category|
http://www.kbpublisher.com - http://www.kbpublisher.com
[b]text[/b] - Bold text.
[u]text[/u] - Underline text.
[i]text[/i] - Italic text.
[color=green]text[/color] - Colored text.
[url]kbpublisher.com[/url] - kbpublisher.com
[url=kbpublisher.com]text[/url] - text
[email]email@example.com[/email] - firstname.lastname@example.org
[h1]text[/h1] - Caption text.
- item 1
- item 2
- item 1
- item 2
How can I perform layout on views with transformers different than the identity?
Since JViews 5.0, the layout algorithm can process a graph in the untransformed coordinate system of the manager, or in the transformed coordinate system of the view. The chosen coordinate system affects the way how the given spacing parameters of the layout algorithm are interpreted, and how nonzoomable objects (such as
IlvMarker) are arranged.
For example, consider a hierarchical layout with horizontal offset 40 on a graph that contains a nonzoomable
IlvMarker of size 8 displayed in a view that demagnifies by half:
To process the layout in view coordinates, call the following method:
This means that the distance between nodes will appear as 40 units on the screen. Internally, however, coordinates are always stored in manager coordinates. In manager coordinates, the node distance is 80. It appears to be 40 on the screen due to the view demagnification. This works as well with nonzoomable objects.
To process the layout in manager coordinates, call the following method:
The node distance calculated from the stored coordinates in manager coordinates is now 40 units. This distance is demagnified by the view, hence the nodes appear to be only 20 units apart on the screen. However, nonzoomable objects will appear wrongly on the screen, because the layout arranged the objects around the
IlvMarker as if it has size 8 in manager coordinates, assuming that the marker is demagnified in the same way as all other objects when displayed on the screen. So, the layout looks good if the marker is drawn with size 4 on the screen, but since it is a nonzoomable object, it is drawn with size 8.
By default, layout is processed in inverse view coordinates. You can set this by
In this case, the stored coordinates at the nodes are now such that the node distance in manager coordinates is 40 units, like the mode MANAGER_COORDINATES. However, nonzoomable objects are now treated correctly, because the layout applies the inverse transformation to the size of the nonzoomable objects in order to calculate its position. Since the nonzoomable marker is drawn at size 8, the layout assumes it has virtually the size 16 during the coordinate calculation, which would give size 8 on the screen due to theview demagnification. So, the layout algorithm simulates what would happen if nonzoomable objects were actually zoomable, and due to this simulation is able to calculate the optimal layout.
As rule of thumb:
- If all objects are zoomable, use manager coordinates, which is fast.
- If at least one object is nonzoomable, use view coordinates or inverse view coordinates. Which one you choose depends on how the layout spacing parameters should be interpreted.
- The coordinates mode set on the layout instance is used while layout is running. You can also set the coordinates mode on the
IlvGrapherAdapterinstance. This is used on operations on the adapter when layout is not running. In most applications, it is suitable to set both modes to the same value.
If you use view coordinates or inverse view coordinates, the reference transformer of the
IlvGrapherAdapter is taken into account. By default, the transformer of the first view attached to a grapher is considered to be the reference transformer. If this does not fit your application, you must specify the reference transformer by yourself by using the method
Sample code to specify the reference transformer:
- Variant 1
IlvGrapher grapher = new IlvGrapher(); ... layout.attach(grapher); layout.setCoordinatesMode(IlvGraphLayout.VIEW_COORDINATES); IlvGrapherAdapter adapter = (IlvGrapherAdapter)layout.getGraphModel(); adapter.setCoordinatesMode(IlvGraphLayout.VIEW_COORDINATES); adapter.setReferenceTransformer(myView.getTransformer());
- Variant 2
IlvGrapher grapher = new IlvGrapher(); ... IlvGrapherAdapter adapter = new IlvGrapherAdapter(grapher); layout.attach(adapter); layout.setCoordinatesMode(IlvGraphLayout.INVERSE_VIEW_COORDINATES); adapter.setCoordinatesMode(IlvGraphLayout.INVERSE_VIEW_COORDINATES); adapter.setReferenceTransformer(myView.getTransformer());
The other main procedure to specify the transformer to be used by the layout algorithm is to indicate a reference view as the source of all the information regarding the transformer. By setting a reference view (
IlvGrapherAdapter.setReferenceView(IlvManagerView view)), the graph model is informed of the source of the transformer to be used during layout (so the
IlvManagerView.getTransformer() is used to get the transformer).
- Variant 3
IlvGrapher grapher = new IlvGrapher(); ... layout.attach(grapher); layout.setCoordinatesMode(IlvGraphLayout.VIEW_COORDINATES); IlvGrapherAdapter adapter = (IlvGrapherAdapter)layout.getGraphModel(); adapter.setCoordinatesMode(IlvGraphLayout.VIEW_COORDINATES); adapter.setReferenceView(myView);
Note 1: The reference view or the reference transformer are not taken into account when the coordinates mode is MANAGER_COORDINATES.
Note 2: Until JViews 5.0, the coordinates mode could not be set explicitly. The only coordinates mode available was the default mode
INVERSE_VIEW_COORDINATES. Starting from JViews 3.0, you can perform a graph layout which takes into account the transformations by setting the reference transformer and/or the reference view. For details on how to use these, see the answer above that describes the
MANAGER_COORDINATES situation in JViews 5.0.