Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The central operation of KWebS is graphLayout, which is shown in the listing below. It calculates the layout of a graph that you deliver in serial notation as the serializedGraph parameter. This parameter is declaring a general serial notation. The server has to know the underlying meta model and form of serialization, therefore, you have to define the format you used to submit your graph with the informat parameter. In general, when the server has calculated the layout, it delivers the graph for which the layout was calculated in the same format that you chose to submit your source graph. Alternatively, you can define a different output format with the parameter outformat and the server performs the necessary translation.

At the moment, KWebS supports six different formats:

...

There is a wiki page explaining the currently supported graph formats.

Code Block
themeEclipse
languagejava
/**
 * Calculating the layout of a graph with KWebS
 * 
 * @param serializedGraph the serial notation of the source graph
 * @param informat the format of the source graph
 * @param outformat the optional format of the result
 * @param options the optional layout options
 * 
 * @return the serial notation of the graph with calculated layout either
 *         in the format of the source graph or a format chosen by the user
 */
String graphLayout(
    String serializedGraph,          
    String informat,                 
    String outformat,               
    List<GraphLayoutOption> options 
);

...

  • LayoutOption declares a layout option. The attribute type defines the type of values you may assign to this option, e.g. boolean, string or enumeration values. Additionaly, the attribute default 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 attribute appliesTo. It may be empty, meaning, an option can be applied to any element, or contain a comma separated list of compatible element types. The attribute id 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
    themeEclipse
    languagejava
    // 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 the graphLayout operation to declare a specific layout algorithm, as you can see in the next listing. The layoutServicePort 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
    themeEclipse
    languagejava
    // 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.

...