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
sourceimpl<'d, 'w> Scope<'d, 'w>
impl<'d, 'w> Scope<'d, 'w>
sourcepub fn subgraph(&mut self) -> Scope<'_, 'w>
pub fn subgraph(&mut self) -> Scope<'_, 'w>
Starts a new nested subgraph, returning another Scope for writing to that subgraph.
sourcepub fn cluster(&mut self) -> Scope<'_, 'w>
pub fn cluster(&mut self) -> Scope<'_, 'w>
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.
sourcepub fn graph_attributes(&mut self) -> AttributesList<'_, 'w>
pub fn graph_attributes(&mut self) -> AttributesList<'_, 'w>
Returns a struct for writing the default attributes for all subgraphs from now on.
sourcepub fn edge_attributes(&mut self) -> AttributesList<'_, 'w>
pub fn edge_attributes(&mut self) -> AttributesList<'_, 'w>
Returns a struct for writing the default attributes for all edges from now on.
sourcepub fn node_attributes(&mut self) -> AttributesList<'_, 'w>
pub fn node_attributes(&mut self) -> AttributesList<'_, 'w>
Returns a struct for writing the default attributes for all nodes from now on.
sourcepub fn node_auto(&mut self) -> Node<'_, 'w>
pub fn node_auto(&mut self) -> Node<'_, 'w>
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.
sourcepub fn node_named<S: Into<String>>(&mut self, id: S) -> Node<'_, 'w>
pub fn node_named<S: Into<String>>(&mut self, id: S) -> Node<'_, 'w>
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.
sourcepub fn edge<S, E>(&mut self, start_node_id: S, end_node_id: E) -> EdgeList<'_, 'w>where
S: AsRef<[u8]>,
E: AsRef<[u8]>,
pub fn edge<S, E>(&mut self, start_node_id: S, end_node_id: E) -> EdgeList<'_, 'w>where
S: AsRef<[u8]>,
E: AsRef<[u8]>,
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;}"
);
sourcepub fn edges<I, E>(&mut self, items: I) -> Option<EdgeList<'_, 'w>>where
I: IntoIterator<Item = E>,
E: AsRef<[u8]>,
pub fn edges<I, E>(&mut self, items: I) -> Option<EdgeList<'_, 'w>>where
I: IntoIterator<Item = E>,
E: AsRef<[u8]>,
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
sourceimpl<'d, 'w> Attributes for Scope<'d, 'w>
impl<'d, 'w> Attributes for Scope<'d, 'w>
sourcefn set(&mut self, name: &str, value: &str, quote: bool) -> &mut Self
fn set(&mut self, name: &str, value: &str, quote: bool) -> &mut Self
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