Struct dot_writer::Scope

source ·
pub struct Scope<'d, 'w> { /* private fields */ }
Expand description

A Scope struct represents either a graph, digraph, subgraph or cluster. Its the workhorse of the DOT writing, and can be used to create new sub-scopes, add nodes, add edges, or adjust default attributes for any of the above.

The only way to construct a top level graph or digraph scope is to call the DotWriter::graph or DotWriter::digraph functions on a new DotWriter.

Implementations

Starts a new nested subgraph, returning another Scope for writing to that subgraph.

Starts a new nested cluster subgraph, returning another Scope for writing to it. A cluster is a special case of a subgraph which groups its child nodes together. See the “Subgraphs and Clusters” section of the Graphviz documentation for more information.

Returns a struct for writing the default attributes for all subgraphs from now on.

Returns a struct for writing the default attributes for all edges from now on.

Returns a struct for writing the default attributes for all nodes from now on.

Creates a new node, with an automatic default id of the format node_x where x is an incerementing integer. You don’t have to declare nodes before using them in a call to Scope::edge, but you do have to declare them using this function if you want to set specifc attributes for this node (font etc).

The returned value can be used to get the automatically generated id, and also to set the attributes.

Creates a new node, with the specified id. You don’t have to declare nodes before using them in a call to Scope::edge, but you do have to declare them using this function if you want to set specific attributes for this node (font etc).

The returned value can be used to get the assigned name, and also to set the attributes.

Add a new edge joining start_node_id and end_node_id nodes. Note that nodes do not need to be already defined by Scope::node_auto or by Scope::node_named (unless you want to set node-specific attributes). Arguments can be just strings, or you can use the Node::id of an already defined node:

use dot_writer::DotWriter;

let mut output_bytes = Vec::new();
{
  let mut writer = DotWriter::from(&mut output_bytes);
  writer.set_pretty_print(false);
  let mut digraph = writer.digraph();
  let a = digraph.node_auto().id();
  digraph.edge(a, "b");
}
assert_eq!(
    std::str::from_utf8(&output_bytes).unwrap(),
    "digraph{node_0;node_0->b;}"
);

Add N-1 edges joining all node ids or subgraphs in the iterator, in the same manner as Scope::edge. The return value will be None if less than 2 items are passed in.

use dot_writer::DotWriter;

let mut output_bytes = Vec::new();
{
  let mut writer = DotWriter::from(&mut output_bytes);
  writer.set_pretty_print(false);
  let mut digraph = writer.digraph();
  digraph.edges(["a", "b", "c"]);
}
assert_eq!(
    std::str::from_utf8(&output_bytes).unwrap(),
    "digraph{a->b->c;}"
);

Trait Implementations

Sets an attribute. See the Graphviz documentation for a full list of available names and values. Set the arguement quote to true if the value should be written in quotes ", to escape any special characters. Note that any quote in the string need to be escaped before calling. This function does NOT check that name or value are valid DOT strings. Read more
Set the name of the font family for label text
Set arbitary html, useful for constructing more complex nodes
Set the display label for a graph, node or edge
Set the label to appear at the head of an edge
Set the label to appear at the tail of an edge
Set the edge or line color
Set the color to fill the area with
Set the color of the font used for text
Set the background color
Set the shape of a graph, subgraph, cluster or node
Set the style
Set type of arrow head for edge lines (the arrow at the destination)
Set type of arrow tail for edge lines (the arrow at the source)
Set the relative rank, which affects layout
Set the pen width for drawing lines
Set the arrow size
Set the font size
Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.