layout/topo/placer/
place.rs

1//! This module contains the implementation of the placer, which assigns the
2//! final (x,y) coordinates to all of the elements in the graph.
3
4#[cfg(feature = "log")]
5extern crate log;
6
7use crate::topo::layout::VisualGraph;
8use crate::topo::placer::bk::BK;
9use crate::topo::placer::edge_fixer;
10use crate::topo::placer::move_between_rows;
11use crate::topo::placer::simple;
12use crate::topo::placer::verifier;
13
14#[derive(Debug)]
15pub struct Placer<'a> {
16    vg: &'a mut VisualGraph,
17}
18
19impl<'a> Placer<'a> {
20    pub fn new(vg: &'a mut VisualGraph) -> Self {
21        Self { vg }
22    }
23
24    pub fn layout(&mut self, no_layout: bool) {
25        #[cfg(feature = "log")]
26        log::info!("Starting layout of {} nodes. ", self.vg.num_nodes());
27
28        // We implement left-to-right layout by transposing the graph.
29        let need_transpose = !self.vg.orientation().is_top_to_bottom();
30        if need_transpose {
31            #[cfg(feature = "log")]
32            log::info!("Placing nodes in Left-to-right mode.");
33            self.vg.transpose();
34        } else {
35            #[cfg(feature = "log")]
36            log::info!("Placing nodes in Top-to-Bottom mode.");
37        }
38
39        move_between_rows::do_it(self.vg);
40
41        // Adjust the boxes within the line (along y) and assign consecutive X
42        // coordinates.
43        simple::do_it(self.vg);
44
45        // Check that the spacial order of the blocks matches the order in the
46        // rank.
47        verifier::do_it(self.vg);
48
49        if no_layout {
50            #[cfg(feature = "log")]
51            log::info!("Skipping the layout phase.");
52            // Finalize left-to-right graphs.
53            if need_transpose {
54                self.vg.transpose();
55            }
56            return;
57        }
58
59        BK::new(self.vg).do_it();
60
61        verifier::do_it(self.vg);
62
63        edge_fixer::do_it(self.vg);
64
65        // Finalize left-to-right graphs.
66        if need_transpose {
67            self.vg.transpose();
68        }
69    }
70}