Push all ultimate elements to the bottom of the graph
All checks were successful
/ build (push) Successful in 1m6s
All checks were successful
/ build (push) Successful in 1m6s
In dot rendering, put all ultimate elements (those that nothing further depends on) on the same rank, meaning the very bottom. This helps to visualize our ultimate goals more easily and also shows elements that are probably a requisite to something else that has not yet been modelled.
This commit is contained in:
parent
1f889245af
commit
9519414929
|
@ -160,6 +160,16 @@ impl Tree {
|
|||
Subtree::new_for_element(self, element)
|
||||
}
|
||||
|
||||
pub fn iter_ultimate_elements<'a>(&'a self) -> impl Iterator<Item = ElementIndex> + 'a {
|
||||
self.graph.node_indices().filter(|index| {
|
||||
// If there are no incoming edges, then this is an ultimate element!
|
||||
self.graph
|
||||
.neighbors_directed(*index, petgraph::Direction::Incoming)
|
||||
.next()
|
||||
.is_none()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_dot(&self) -> String {
|
||||
let dot = petgraph::dot::Dot::with_attr_getters(
|
||||
&self.graph,
|
||||
|
@ -173,9 +183,16 @@ impl Tree {
|
|||
&|_g, (_, element)| element.to_dot_node_attributes(None),
|
||||
);
|
||||
|
||||
let ultimate_elements: Vec<_> = self
|
||||
.iter_ultimate_elements()
|
||||
.map(|idx| idx.index().to_string())
|
||||
.collect();
|
||||
let ultimate_element_list = ultimate_elements.join("; ");
|
||||
|
||||
format!(
|
||||
r#"digraph {{
|
||||
ranksep=1.2
|
||||
{{ rank=same; {ultimate_element_list}; }}
|
||||
{:?}
|
||||
}}
|
||||
"#,
|
||||
|
|
Loading…
Reference in a new issue