GraphContext¶
- class understand.GraphContext¶
Bases:
objectGraph 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
defaultGraphviz attributes, define and retrieve customoptionsand provide alegend. Use any graph object (the root or clusters) to add anode, anedgeand acluster. You can alsosetgraphviz attributes for the graph object.GraphContext objects are hashable and compare equal when they refer to the same underlying Graphviz subgraph.
A read-only Graph object can be returned from draw.
Methods Summary
Return Graphviz attributes set on this graph or cluster.
Return a
cachethat can be used to store, retrieve, and share data.Add a cluster subgraph to the graph.
Return the clusters (subgraphs) directly contained in this graph.
Return the database associated with this graph.
Set graph defaults.
Add an edge between two nodes in the graph.
Return default edge attributes in effect for this graph.
Return edges directly attached to this graph or cluster.
Return this graph or cluster's id (Graphviz graph name).
Return True if an abort has been requested.
Return the Legend object associated with this graph.
Add a node to the graph.
Return default node attributes in effect for this graph.
Return nodes directly contained in this graph or cluster.
Return the Options object associated with this graph.
Set graph attribute.
Sync graph or cluster to a reference, entities, or file location.
Return this graph or cluster's current sync data.
Methods Documentation
- attributes() dict[str, str]¶
Return Graphviz attributes set on this graph or cluster.
- Return type:
dict[str, str]
- cache(id) understand.Cache¶
Return a
cachethat 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:
- Returns:
a cache object or None
- Raises:
RuntimeError – on read-only graphs returned from draw (raw graph format)
- cluster(label='', arch=None) understand.GraphContext¶
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:
- Returns:
the new cluster
- Raises:
RuntimeError – on read-only graphs returned from draw (raw graph format)
- clusters() list[understand.GraphContext]¶
Return the clusters (subgraphs) directly contained in this graph.
- Return type:
list[understand.GraphContext]
- db() understand.Db¶
Return the database associated with this graph.
- Return type:
- 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
- Raises:
RuntimeError – on read-only graphs returned from draw (raw graph format)
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:
- Returns:
the new edge
- Raises:
RuntimeError – on read-only graphs returned from draw (raw graph format)
- edge_defaults() dict[str, str]¶
Return default edge attributes in effect for this graph.
- Return type:
dict[str, str]
- edges() list[understand.Edge]¶
Return edges directly attached to this graph or cluster.
- Return type:
list[understand.Edge]
- id() str¶
Return this graph or cluster’s id (Graphviz graph name).
- Return type:
str
- is_aborted() bool¶
Return True if an abort has been requested.
- Return type:
bool
- Returns:
True if an abort has been requested
- Raises:
RuntimeError – on read-only graphs returned from draw (raw graph format)
- legend() understand.Legend¶
Return the Legend object associated with this graph.
- Return type:
- Returns:
the legend object for the graph
- Raises:
RuntimeError – if the graph was not created in a plugin context
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=None) 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:
- Returns:
the new node
- Raises:
RuntimeError – on read-only graphs returned from draw (raw graph format)
Providing an ent argument is equivalent to calling sync on the returned node object:
node = graph.node("label") node.sync(ent)
- node_defaults() dict[str, str]¶
Return default node attributes in effect for this graph.
- Return type:
dict[str, str]
- nodes() list[understand.Node]¶
Return nodes directly contained in this graph or cluster.
- Return type:
list[understand.Node]
- options() understand.Options¶
Return the Options object associated with this graph.
- Return type:
- Returns:
the associated options
- Raises:
RuntimeError – if the graph was not created in a plugin context
Defined options will appear in the context menu of the graph. Retrieve the values using
lookup. Note that graph options only supportdefine, 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
- Raises:
RuntimeError – on read-only graphs returned from draw (raw graph format)
Refer to Graphviz for available attributes. Unlike
default, this sets the attribute for this graph object only.
- sync(ref) None¶
- sync(arch) None
- sync(ent) None
- sync(ent, comparison_ent) None
- sync(file, line=0, column=0) None
Sync graph or cluster to a reference, entities, or file location.
- Parameters:
ref (understand.Ref) – a reference to sync
arch (understand.Arch) – an architecture to sync
ent (understand.Ent) – an entity to sync
comparison_ent (understand.Ent or None) – an entity from the comparison database
file (understand.Ent or str) – a file entity or file path
line (int or None) – optional, a line number
column (int or None) – optional, a column number
- Return type:
None
- Raises:
RuntimeError – on read-only graphs returned by draw (raw graph format)
Line and column numbers are 1-based.
For entity comparison, ent or comparison_ent may be None to show added/removed entities.
- synced_data() object¶
Return this graph or cluster’s current sync data.
- Return type:
understand.Ref or understand.Arch or understand.Ent or tuple[understand.Ent | None, understand.Ent | None] or dict[str, str | int | understand.Ent] or list[understand.Ref] or None
- Returns:
sync data currently associated with this object
Locations are returned as dictionaries with a “file” key and optional keys: “entity”, “line”, “column”, “end_line”, and “end_column”. Line and column numbers are 1-based.
Entity comparisons are returned as a tuple with left and right entities. Either entity may be None, usually representing an added/removed entity.
Built-in graphs have more sync types than supported from plugins. Specifically, locations can have end_line and end_column (Control Flow graphs are an example) and edges often sync a list of references.