Manual
API Graph CommandsOn this page, API commands of the graph category are described. This category covers all commands to send graphs in term representation format and updates on graphs. The commands of this category are enclosed by keyword "graph(...)". Click here to get an overview of all API commands. graph(new(graphterm))Sends a graph in term representation format "graphterm" to uDraw(Graph) for visualization. This is the same format used for file representation of uDraw(Graph) graphs, i.e. the files with suffix ".udg". Note: Unlike the file format, newline characters are not allowed in term representations if sent to the API. After transmitting a graph with this command, the layout algorithm for reducing edge crossing will not be started automatically. You can either do this later using API command menu(layout(improve_all)) or by combining both steps with command graph(new_placed(...)), see below. The advantage of using the second method is that the user will not see the intermediate graph visualization where the layout algorithm is not applied. If you do not want to send the whole graph via API, you can save it to a file and use command menu(file(open_graph(...))) to load the graph from file. graph(new_placed(graphterm))This command combines graph(new(...)), (i.e. transmitting a graph) and menu(layout(improve_all)) (i.e. starting the graph layout algorithm to reduce edge crossings) in one step. The advantage of using this command (instead of the previous one) is that the user will not see the intermediate graph visualization where the layout algorithm is not applied. The parameter "graphterm" is the term representation format of the graph. If you do not want to send the whole graph via API, you can save it to a file and use command menu(file(open_graph(...))) to load the graph from file. graph(update(node_updates,edge_updates))This command can be used to update the structure of the currently loaded graph. You can remove existing nodes and edges, add new nodes or connect nodes with new edges. Here a graph update contains two lists: one for the node and one for the edge updates. After sending this command, incremental layout will be used to integrate the update into the graph to make sure that the layout remains as stable as possible. After an update, all nodes (and edges) previously selected become implicitly deselected without sending the API answer node_selections_labels(...). For the list of "node_updates", there are two different kinds of list elements which can be mixed in any order:
For the list of "edge_updates", there are three different kinds of list elements which can be mixed in any order:
graph(mixed_update(mixed_updates))Same as command graph(update(...)) above, but here the node and edge updates can be mixed in one common list where the order is not significant. Creating mixed updates is easier in many situations because the node updates must not be collected before starting with the edge updates. graph(change_attr(attr_changes))This command is used to update the attributes of nodes and edges that exist in the current graph. The semantic of this operation is either to add the attribute if it does not previously exist (for that particular node or edge) or to overwrite it otherwise. For example, the current graph has a node with attributes to specify a red background and a text "test". So the attributes of the node are:
Now study the following attribute update for that node:
After sending this list of updates as parameter of command "graph(change_attr(...))", the node will be still drawn in red (the "COLOR" attribute is not overwritten), but with text "new test" and font "times". In order to remove an attribute of a particular node or edge, you can set its value to an empty string using this API command. When removing the attribute, the default value for this attribute is used or (if the type of the node or edge has a visualization rule) the value from the corresponding visualization rule is applied. The parameter of the API command (i.e. attr_changes) is a list of attribute changes with two different kinds of list elements. Both types of elements of this API command can be mixed in any order:
graph(update_and_change_attr(node_updates,edge_updates,attr_changes))This command combines the API commands graph(update(...)) and graph(change_attr(...)) (described above) to update the structure of a graph and modify attributes of existing nodes and edges in one step. The benefit of this command instead of using the other two commands directly after each other is that the graph is not displayed between applying the updates and modifying the attributes. First the updates in "node_updates" and "edge_updates" are applied to the graph and afterwards the attributes are changed according to the parameter "attr_changes". So here it is not allowed to modify the attributes of nodes and edges that are simultaneously removed. graph(mixed_update_and_change_attr(mixed_updates,attr_changes))Same as command graph(update_and_change_attr(...)) above, but here the node and edge updates can be mixed in one common list where the order is not significant. Creating mixed updates is easier in many situations because the node updates must not be collected before starting with the edge updates. graph(change_type(type_changes))This command is used to update the type of nodes and edges that have to exist in the current graph. The parameter of the command is a list of modifications with two different kinds of list elements. Both types of elements can be mixed in any order:
This command is especially useful when several visualization rules have been supplied for different node and edge types using the visualization definition commands. Afterwards you can modify the appearance of nodes and edges by simply changing their type. |
||