Page History
...
LayoutOption
declares a layout option. The attributetype
defines the type of values you may assign to this option, e.g. boolean, string or enumeration values. Additionaly, the attributedefault
may carry a default value which generally provides good layout results. As said before, a layout option is related to specific types of graph elements, specified by the attributeappliesTo
. It may be empty, meaning, an option can be applied to any element, or contain a comma separated list of compatible element types. The attributeid
declares the identifier of the layout option. You can use it to specify a layout option directly in the source graph by annotating a specific graph element. The way you realize the annotation is dependent on the model you use. For example, if you use a KGraph model, you could do it like the following listing shows:Code Block theme Eclipse language java // Retrieve the graph model somehow KNode graph = ... // Get the layout related information from the root node KShapeLayout shapeLayout = graph.getData(KShapeLayout.class); // Create a property which is used to define the layout algorithm and // use KLay layered as the default algorithm IProperty<String> algorithm = new Property<String>( "de.cau.cs.kieler.algorithm", "de.cau.cs.kieler.klay.layered" ); // Annotate the root node of the graph model with the layout option // represented by the property and use the default algorithm KLay // layered shapeLayout.setProperty(algorithm, algorithm.getDefault()); // Alternatively, you can use a different algorithm like the graphviz DOT shapeLayout.setProperty(algorithm, "de.cau.cs.kieler.graphviz.dot");
You could alternatively use the
options
parameter of thegraphLayout
operation to declare a specific layout algorithm, as you can see in the next listing. ThelayoutServicePort
instance the example uses resembles the proxy necessary to interact with the layout server. You will see how you can create such a proxy in How to use the service based layout in your project.Code Block theme Eclipse language java // Retrieve the graph model somehow KNode graph = ... // Get the models XMI notation String source = modelToXmi(graph); // Create the options list List<GraphLayoutOption> options = new ArrayList<GraphLayoutOption>(); // Declare the option defining the algorithm to be used GraphLayoutOption option = new GraphLayoutOption(); option.setId("de.cau.cs.kieler.algorithm"); option.setValue("de.cau.cs.kieler.klay.layered"); // Add the option declaring the layout algorithm to the list options.add(option); // Invoke the service String result = layoutServicePort.graphLayout( source, // the source model "de.cau.cs.kieler.kgraph", // we use the KGraph format null, // we want the service to return the result in KGraph format options // we use the options list to specify the algorithm to be used ); // Get the layouted model KNode layout = xmiToModel(result);
When an option represents an enumeration, it associates a
RemoteEnum
element. It defines the possible assignments you can make to the option.
...