graphviz-rust
graphviz-rust copied to clipboard
Provide example usage of SubgraphAttributes
let subgraph_nodes: Vec<Stmt> = //...
subgraph!(subgraph_id.as_u128(), subgraph_nodes)
Works for me, but my subgraphs have no color or border. I want to assign SubgraphAttributes::label in order to attempt to make the subgraphs visible. What is the valid syntax for that?
Yeah. Truly, there are no macros associated with graph attr. I created an issue for that.
Meanwhile,
In case, if you want to have a border for the subgraph, then the clusters need to be used. Thus, the id should have the prefix cluster.
For now, you can manually create graph attributes like this:
let attrs = GraphAttributes::new("graph", vec![
SubgraphAttributes::style("dotted".to_owned()),
SubgraphAttributes::color(color_name::green),
SubgraphAttributes::label("sandwich".to_owned()),
]);
or using attr!:
let attrs = GraphAttributes::new("graph", vec![
attr!("style","bold"),
attr!("color","green"),
attr!("label", "sandwich"),
]);
The complete example:
#[test]
fn issue_with_node_test() {
let attrs = GraphAttributes::new("graph", vec![
SubgraphAttributes::style("dotted".to_owned()),
SubgraphAttributes::color(color_name::green),
SubgraphAttributes::label("sandwich".to_owned()),
]);
let food = subgraph!("cluster_sandwich";
edge!(node_id!("bread") => node_id!("ham") => node_id!("salat")),
attrs
);
let g = graph!(strict di id!("t"); edge!(node_id!("food") => food));
let string = g.print(&mut Default::default());
println!("{}",string);
}
prints :
strict digraph t {
food -> subgraph cluster_sandwich {
bread -> ham -> salat
graph[style=bold,color=green,label=sandwich]
}
}
I added the attrs! macro.
The example now can look like this:
let food = subgraph!("cluster_sandwich";
edge!(node_id!("bread") => node_id!("ham") => node_id!("salat")),
attrs!(graph; attr!("style", "bold"), attr!("color","green"), attr!("label", "sandwich"))
);