skip to main content
Diagrammer > Programmer's documentation > Using graph layout algorithms > Basic concepts > Graph layout in Rogue Wave JViews Diagrammer
 
Graph layout in Rogue Wave JViews Diagrammer
In Rogue Wave®  JViews, graphs are instances of the class IlvGrapher. These instances are called graphers. Nodes, which are instances of IlvGraphic, and links, which are instances of IlvLinkImage, “know” how to draw themselves. Nodes can be “placed” interactively or by code. To lay out a grapher to obtain a readable drawing, just compute and assign appropriate coordinates to the nodes. In some cases, you may also need to modify the shape of the links. The main task of the Graph Layout algorithms is to provide support for computing node and link coordinates—that is, laying out the graph—fully automatically.
Rogue Wave®  JViews Diagrammer provides a Swing component that encapsulates a grapher and the view that displays the grapher. JViews Diagrammer uses a model-view architecture, that is, the application objects must be provided as an SDM model, and the grapher is filled with corresponding nodes and links that are displayed in the view. The nodes and links are styled according to a style file. A style file is a CSS file, where CSS stands for Cascading Style Sheets. It has the file name extension .css. A style file specifies which instances of IlvGraphic and IlvLinkImage must be created for the diagram, and which layout algorithms and layout parameters must be used to calculate the coordinates of the nodes and links.
There are various ways to use the Graph Layout algorithms:
*In a diagram component: You specify the graph layout in CSS format. The diagram component loads this specification and automatically applies the graph layout when necessary.
*In an application that uses Rogue Wave JViews graphers: Instead of using style files, you access the API of the graph layout classes directly. This is suitable for applications that do not need the model-view architecture or styling. Using the graph layout classes directly is more powerful because you have access to internal details of the graph layout classes that are not available in style files. However, using the graph layout API directly is slightly more complex. For example, the layout algorithm is generally not applied automatically, you have to call it explicitly.
*With your own graph data structures: It is not required to use a diagram component to display a diagram, or to use a Rogue Wave JViews grapher to represent a graph. If you have implemented your own data structures or if you use some other third-party data structures that represent a graph, it is still possible to use graph layout algorithms by providing an adapter between your data structures and the graph model. This more complex application of the graph layout package is explained in Laying out a non-JViews grapher.
This documentation shows you how to style graph layouts in a diagram component by using style sheets (CSS) and how to program graph layout classes in Java™, which is necessary when you cannot use a diagram component with styling capabilities. In most cases, both ways are illustrated in parallel even though, practically, the most common situation is to use either one or the other.
Here are two examples in ascending order of difficulty.
Setting the offset between nodes
 
In CSS
Specify:
 
GraphLayout {
     horizontalNodeOffset: "20";
}
In Java
Call:
 
layout.setHorizontalNodeOffset(20);
Setting the position of a node
Example of setting the position of a node
In CSS
Specify:
 
GraphLayout {
    position : "10,10";
    rootPosition : "false";
}
In Java
Call the setPosition method as follows:
 
layout.setPosition(new IlvPoint(10, 10), false);
These examples mean two things:
*If you implement an application that uses Rogue Wave  JViews Diagrammer or the SDM engine and therefore is based on styling, you should specify the graph layout parameters in a style sheet (CSS file), and you can set the position of the top left corner by adding the above lines to your CSS file.
*If you implement an application that does not use JViews Diagrammer or the SDM engine, for example an application that works directly on instances of IlvGrapher, or on your own graph data structures, then you cannot use style sheets and you must access the graph layout instances directly as illustrated in the Java code above.
In the first case, you specify a CSS file, in the second, you write Java code.
However, it may be necessary to mix style sheets and Java code in some cases, for example when you implement your own graph layout renderer. But this case should be left to expert users who are familiar with the entire SDM and JViews Framework architectures. See Using and adding renderersin JViews Diagrammer SDKand Writing a new layout renderer to clip links.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.