Use an instance of the ServerSideLayout class to execute graph layout on the server side,
as in the following sample code:
var treeLayout = new ibm_ilog.graphlayout.tree.TreeLayout(); graph.setNodeLayout(treeLayout); var serverLayout = new ibm_ilog.graphlayout.ServerSideLayout(graph, url); var deferred = serverLayout.layout();
The constructor for the ServerSideLayout instance
has two arguments. Pass the name of the graph that you want to lay
out in the graph argument, and the
URL for the server-side graph layout service in the url argument.
When you call the layout method on
the ServerSideLayout instance, the layout is executed asynchronously
on the server.
Note
As in all multithreaded applications, you must design
your application for asynchronous graph layout execution. Your application
must not modify the graph while the layout is running. Otherwise,
all the changes made on the client side are overwritten when the layout
completes.
The layout method returns
immediately to the current thread, without waiting for the graph layout
execution to complete. The user interface of the browser stays active,
and your application can continue with other processing. When the
graph layout execution completes, the new node positions and link
shapes are applied to the graph automatically.
When you configure node layout and link layout algorithms,
use the same methods
(Graph.setNodeLayout and Graph.setLinkLayout) whether you perform the graph
layout from the client or server side. However, do not use Graph.performGraphLayout or Diagram.performGraphLayout calls to execute graph layout
on the server side, These are for client-side graph layout only.
Adding callbacks
The layout method returns
a dojo.Deferred object that can be
used to notify you when the layout finishes. Call the addCallback method
of the dojo.Deferred object to provide
the notification. The following example disables a button during execution
of the layout, then enables it when the layout is finished:
dijit.byId("layoutButton").attr("disabled", true); var deferred = serverLayout.layout(); deferred.addCallback(function(){ dijit.byId("layoutButton").attr("disabled", false); });
You can also use the dojo.Deferred object
to notify you if an error occurs during graph layout execution. Call
the addErrback method for layout
error notification, as in the following example:
deferred.addErrback(function(e){ alert(e); dijit.byId("layoutButton").attr("disabled", false); });
Stopping the server-side graph layout execution
You can stop server-side graph layout execution by calling
the stop method of the ServerSideLayout object.
It cancels the server request without modifying the graph on the client
side:
serverLayout.stop();