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§
Source§impl<'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.
use dot_writer::{DotWriter, Color, Attributes};
let dot_string = DotWriter::write_string(|writer| {
writer.set_pretty_print(false);
let mut digraph = writer.digraph();
let a = digraph.node_auto().id();
let b = {
let mut node = digraph.node_auto();
node.set_color(Color::Red);
node.id()
};
digraph.edge(a, b);
});
assert_eq!(
dot_string,
"digraph{node_0;node_1[color=red];node_0->node_1;}"
);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.
use dot_writer::{DotWriter, Color, Attributes};
let dot_string = DotWriter::write_string(|writer| {
writer.set_pretty_print(false);
let mut digraph = writer.digraph();
let a = digraph.node_named("alpha").id();
let b = {
let mut node = digraph.node_named("beta");
node.set_color(Color::Red);
node.id()
};
digraph.edge(a, b);
});
assert_eq!(
dot_string,
"digraph{alpha;beta[color=red];alpha->beta;}"
);Sourcepub fn edge<F, T>(&mut self, from_node_id: F, to_node_id: T) -> EdgeList<'_, 'w>
pub fn edge<F, T>(&mut self, from_node_id: F, to_node_id: T) -> EdgeList<'_, 'w>
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>>
pub fn edges<I, E>(&mut self, items: I) -> Option<EdgeList<'_, 'w>>
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§
Source§impl<'d, 'w> Attributes for Scope<'d, 'w>
impl<'d, 'w> Attributes for Scope<'d, 'w>
Source§fn 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.