pub struct Dot<'a, G>where
G: IntoEdgeReferences + IntoNodeReferences,{ /* private fields */ }Expand description
Dot implements output to graphviz .dot format for a graph.
Formatting and options are rather simple, this is mostly intended for debugging. Exact output may change.
§Examples
use petgraph::Graph;
use petgraph::dot::{Dot, Config};
let mut graph = Graph::<_, ()>::new();
graph.add_node("A");
graph.add_node("B");
graph.add_node("C");
graph.add_node("D");
graph.extend_with_edges(&[
(0, 1), (0, 2), (0, 3),
(1, 2), (1, 3),
(2, 3),
]);
println!("{:?}", Dot::with_config(&graph, &[Config::EdgeNoLabel]));
// In this case the output looks like this:
//
// digraph {
// 0 [label="\"A\""]
// 1 [label="\"B\""]
// 2 [label="\"C\""]
// 3 [label="\"D\""]
// 0 -> 1 [ ]
// 0 -> 2 [ ]
// 0 -> 3 [ ]
// 1 -> 2 [ ]
// 1 -> 3 [ ]
// 2 -> 3 [ ]
// }
// If you need multiple config options, just list them all in the slice.Implementations§
Source§impl<'a, G> Dot<'a, G>where
G: IntoNodeReferences + IntoEdgeReferences,
impl<'a, G> Dot<'a, G>where
G: IntoNodeReferences + IntoEdgeReferences,
Sourcepub fn with_config(graph: G, config: &'a [Config]) -> Self
pub fn with_config(graph: G, config: &'a [Config]) -> Self
Create a Dot formatting wrapper with custom configuration.
Sourcepub fn with_attr_getters(
graph: G,
config: &'a [Config],
get_edge_attributes: &'a dyn Fn(G, G::EdgeRef) -> String,
get_node_attributes: &'a dyn Fn(G, G::NodeRef) -> String,
) -> Self
pub fn with_attr_getters( graph: G, config: &'a [Config], get_edge_attributes: &'a dyn Fn(G, G::EdgeRef) -> String, get_node_attributes: &'a dyn Fn(G, G::NodeRef) -> String, ) -> Self
Create a Dot that uses the given functions to generate edge and node attributes.
NOTE: Config::EdgeNoLabel and Config::NodeNoLabel should be set if you intend to
generate your own label attributes.
The getter functions should return an attribute list as a String. For example, if you
want to calculate a label for a node, then return "label = \"your label here\"".
Each function should take as arguments the graph and that graph’s EdgeRef or NodeRef, respectively.
Check the documentation for the graph type to see how it implements IntoNodeReferences.
The Graphviz docs list the available attributes.
Note that some attribute values, such as labels, should be strings and must be quoted. These can be
written using escapes ("label = \"foo\"") or raw strings (r#"label = "foo""#).
For example, using a Graph<&str, &str> where we want the node labels to be the nodes’ weights
shortened to 4 characters, and all the edges are colored blue with no labels:
use petgraph::Graph;
use petgraph::dot::{Config, Dot};
let mut deps = Graph::<&str, &str>::new();
let pg = deps.add_node("petgraph");
let fb = deps.add_node("fixedbitset");
let qc = deps.add_node("quickcheck");
let rand = deps.add_node("rand");
let libc = deps.add_node("libc");
deps.extend_with_edges(&[(pg, fb), (pg, qc), (qc, rand), (rand, libc), (qc, libc)]);
println!(
"{:?}",
Dot::with_attr_getters(
&deps,
&[Config::EdgeNoLabel, Config::NodeNoLabel],
&|_, _| "color = blue".to_string(),
&|_, (_, s)| format!(r#"label = "{}""#, s.chars().take(4).collect::<String>()),
)
);
// This outputs:
// digraph {
// 0 [ label = "petg"]
// 1 [ label = "fixe"]
// 2 [ label = "quic"]
// 3 [ label = "rand"]
// 4 [ label = "libc"]
// 0 -> 1 [ color = blue]
// 0 -> 2 [ color = blue]
// 2 -> 3 [ color = blue]
// 3 -> 4 [ color = blue]
// 2 -> 4 [ color = blue]
// }Trait Implementations§
Source§impl<G> Debug for Dot<'_, G>where
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp,
G::EdgeWeight: Debug,
G::NodeWeight: Debug,
impl<G> Debug for Dot<'_, G>where
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp,
G::EdgeWeight: Debug,
G::NodeWeight: Debug,
Source§impl<G> Display for Dot<'_, G>where
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp,
G::EdgeWeight: Display,
G::NodeWeight: Display,
impl<G> Display for Dot<'_, G>where
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp,
G::EdgeWeight: Display,
G::NodeWeight: Display,
Source§impl<G> LowerHex for Dot<'_, G>where
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp,
G::EdgeWeight: LowerHex,
G::NodeWeight: LowerHex,
impl<G> LowerHex for Dot<'_, G>where
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp,
G::EdgeWeight: LowerHex,
G::NodeWeight: LowerHex,
Source§impl<G> UpperHex for Dot<'_, G>where
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp,
G::EdgeWeight: UpperHex,
G::NodeWeight: UpperHex,
impl<G> UpperHex for Dot<'_, G>where
G: IntoEdgeReferences + IntoNodeReferences + NodeIndexable + GraphProp,
G::EdgeWeight: UpperHex,
G::NodeWeight: UpperHex,
Auto Trait Implementations§
impl<'a, G> !RefUnwindSafe for Dot<'a, G>
impl<'a, G> !Send for Dot<'a, G>
impl<'a, G> !Sync for Dot<'a, G>
impl<'a, G> !UnwindSafe for Dot<'a, G>
impl<'a, G> Freeze for Dot<'a, G>where
G: Freeze,
impl<'a, G> Unpin for Dot<'a, G>where
G: Unpin,
impl<'a, G> UnsafeUnpin for Dot<'a, G>where
G: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more