Perforce JViews Diagrammer Code Example: Expand and collapse graph (Java SDK version)
Description
This sample shows how to expand and collapse a graph.
This sample uses the graphic framework, but it does not use
the IlvDiagrammer
component or CSS.
How to Use the Code Example
- A collapsed subgraph is indicated by a yellow folder symbol. It can be expanded using the expand interactor.
-
The following buttons are available in the toolbar:
- Pan the view by dragging.
- Expand or collapse a subgraph by clicking it.
- Zoom in on an area by selecting the area to be magnified.
- Zoom in.
- Zoom out.
- Make the entire graph visible.
- When a subgraph is expanded, it usually requires more space. There are different strategies for adapting the remaining nodes to the expanded node. You can control these strategies using the "Expansion Adjustment Mode" at the bottom of the application.
- Some adjustment modes shift the links and may require an additional link layout. You can select a link layout at the bottom of the application. If a link layout is selected, it is applied during the expand or collapse operation.
- The adjustment mode "none" expands and collapses subgraphs without any adjustment. An expanded subgraph may overlap neighboring nodes.
- The adjustment modes "orthogonal ..." and "radial ..." are useful when you do not want to perform a full layout to resolve any overlaps. These adjustment modes shift the nodes and links away to create space for the expanded subgraph without performing any graph layout. The assumption is that the nodes in the expanded subgraph have predefined positions that do not require a graph layout.
- The modes "radial ..." perform a radial shifting around the expanded node. This gives a uniform result, but orthogonality is not preserved. The result is not suitable most of the time if you want to perform an incremental Hierarchical Layout afterwards (for instance, to route the links). However, it is suitable as a starting position for an incremental Uniform Length Edges Layout.
- The modes "orthogonal ..." perform an orthogonal shifting around the expanded node. This sometimes creates horizontal or vertical stripes of unused space. These modes are compatible with an incremental Hierarchical Layout. Orthogonality is mostly preserved, but orthogonal links may become nonorthogonal when nodes must be shifted in different directions.
- The adjustment mode "none + incremental layout" performs an incremental hierarchical layout when a subgraph is expanded or collapsed. This produces a more balanced result than any other adjustment mode and it avoids stripes of unused space, but it is only suitable in applications where graph layout is allowed. The disadvantage of this mode is that it is slower than any other mode.
- The adjustment mode "custom (stable)" performs a custom policy with a link layout integrated into the adjustment. This mode is included only to illustrate how to define your own adjustment policy.
- The modes "... with links" also shift the bends of the links, while the modes "... without links" do not shift the links, but you can optionally perform a link layout afterwards.
- The modes "orthogonal ..." and "radial ..." are useful if you expand only a few subgraphs. They work best if you expand only one subgraph at a time. If you expand several subgraphs then collapse them again, you may end up with nodes at different positions. In this case, the mode is called unstable. Only the "... stable ..." modes are stable. Even in the stable modes, a slight shift in coordinates is unavoidable due to rounding errors during calculations.
- You can see the problem of stability best with the unstable modes "radial with links" and "radial recursive with links". Expand several subgraphs and then collapse them in a different order. Compare this with the stable mode "radial stable with links".
- The modes "orthogonal with links", "orthogonal without links", "radial with links", and "radial without links" work only with nesting depth 1. If the nesting depth is larger, use the "... recursive ..." or "... stable ..." modes, which are slower but better for deeply nested graphs.
How to Run the Code Example as an Application
This code example can
be run as an application.
The installation directory contains
an executable JAR file,
expandcollapse.jar
,
that allows you to execute the code example with a double click from a
file browser. Note that if you are using Internet Explorer, you can
open the installation directory
and execute the JAR file from the browser. This
technique may not work in other Web browsers.
Alternatively, you
can run the code example application from the command line.
First check that the Ant utility is properly configured. If not, see the
instructions on how to configure Ant for Perforce JViews.
Then, go to the installation directory
of the code example and type:
ant run
Topics Covered
- Expand and Collapse
- Grapher
- Graph Layout
Installation Directory
The Expand and collapse graph (Java SDK version) code example is installed here.
Classes Involved
- ilog.views.IlvExpandCollapseUtil
- ilog.views.interactor.IlvExpandCollapseInteractor
- ilog.views.IlvGrapher
- ilog.views.IlvGraphic
- ilog.views.IlvGraphicEnumeration
- ilog.views.IlvLinkImage
- ilog.views.IlvManagerView
- ilog.views.IlvApplyObject
- ilog.views.swing.IlvJScrollManagerView
- ilog.views.swing.IlvJManagerViewControlBar
- ilog.views.graphlayout.IlvGraphLayout
- ilog.views.graphlayout.IlvGrapherAdapter
- ilog.views.graphlayout.IlvNodeSideFilter
- ilog.views.graphlayout.hierarchical.IlvHierarchicalLayout
- ilog.views.graphlayout.link.IlvLinkLayout