Graph

class understand.Graph

Bases: object

Graph plugin graph object

A graph object is provided to a graph plugin’s init(graph) and draw(graph, target) functions and represents the root of a graph. Clusters are also represented as Graph objects. Use the root graph to set default Graphviz attributes, define and retrieve custom options and provide a legend. Use any graph object (the root or clusters) to add nodes, edges and clusters. You can also set graphviz attributes for the graph object.

Methods Summary

cache

Return a cache that can be used to store, retrieve, and share data.

cluster

Add a cluster subgraph to the graph.

db

Return the database associated with this graph.

default

Set graph defaults.

edge

Add an edge between two nodes in the graph.

is_aborted

Return True if an abort has been requested.

legend

Return the Legend object associated with this graph.

node

Add a node to the graph.

options

Return the Options object associated with this graph.

set

Set graph attribute.

Methods Documentation

cache(id) understand.Cache

Return a cache that can be used to store, retrieve, and share data. Caches are globally accessible and modifiable from all plugins so graph plugins would normally use this only to access built-in caches. This function may return None if caching is not available.

Return type:

understand.Cache

Returns:

a cache object or None

cluster([label[, arch]]) understand.Graph

Add a cluster subgraph to the graph.

Parameters:
  • label (str or None) – optional, a label for the cluster

  • arch (understand.Arch or None) – an architecture to sync

Return type:

understand.Graph

Returns:

the new cluster

db() understand.Db

Return the database associated with this graph.

Return type:

understand.Db

Returns:

the database

default(name, value[, kinds]) None

Set graph defaults.

Parameters:
  • name (str) – the attribute name

  • value (str) – the attribute value

  • kinds (str or None) – optional, the kinds this applies to. Valid kinds are “graph”, “node”, and “edge”. This defaults to “graph,node,edge” when not provided, applying to all three kinds.

Return type:

None

Reference Graphviz for available attributes.

# set the default color for nodes and graphs but not edges
graph.default("color","blue","node,graph")
edge(node1, node2[, label]) understand.Edge

Add an edge between two nodes in the graph.

Parameters:
  • node1 (understand.Node) – the tail (source) node of the edge

  • node2 (understand.Node) – the head (destination) node of the edge

  • label (str or None) – optional, a label for the edge

Return type:

understand.Edge

Returns:

the new edge

is_aborted() bool

Return True if an abort has been requested.

Return type:

bool

Returns:

True if an abort has been requested

legend() understand.Legend

Return the Legend object associated with this graph.

Return type:

understand.Legend

Returns:

the legend object for the graph

Defining a legend is optional. Legends are only visible in the Understand GUI and can be toggled on and off from the graph toolbar.

node([label[, ent]]) understand.Node

Add a node to the graph.

Parameters:
  • label (str) – The node’s label

  • ent (understand.Ent or None) – an entity to sync

Return type:

understand.Node

Returns:

the new node

Providing an ent argument is equivalent to calling sync on the returned node object:

node = graph.node("label")
node.sync(ent)
options() understand.Options

Return the Options object associated with this graph.

Return type:

understand.Options

Returns:

the associated options

Defined options will appear in the context menu of the graph. Retrieve the values using lookup. Note that graph options only support define, not any of the ui Option methods such as <understand.Options.checkbox>().

set(name, value) None

Set graph attribute.

Parameters:
  • name (str) – the attribute name

  • value (str) – the attribute value

Return type:

None

Refer to Graphviz for available attributes. Unlike default, this sets the attribute for this graph object only.