flow_rs_core/auto_layout/
config.rs1const DEFAULT_SMALL_GRAPH_THRESHOLD: usize = 10;
5const DEFAULT_TRANSITION_DURATION: f64 = 0.5;
6
7#[derive(Debug, Clone, Copy, PartialEq)]
9pub enum AutoLayoutStrategy {
10 Smart,
12 HierarchyFirst,
14 ForceDirectedFirst,
16 SimpleFirst,
18}
19
20#[derive(Debug, Clone)]
25pub struct AutoLayoutConfig {
26 pub strategy: AutoLayoutStrategy,
28 pub small_graph_threshold: usize,
30 pub enable_transitions: bool,
32 pub transition_duration: f64,
34 pub force_relayout_on_change: bool,
36}
37
38impl Default for AutoLayoutConfig {
39 fn default() -> Self {
40 Self {
41 strategy: AutoLayoutStrategy::Smart,
42 small_graph_threshold: DEFAULT_SMALL_GRAPH_THRESHOLD,
43 enable_transitions: true,
44 transition_duration: DEFAULT_TRANSITION_DURATION,
45 force_relayout_on_change: false,
46 }
47 }
48}
49
50impl AutoLayoutConfig {
51 pub fn builder() -> AutoLayoutConfigBuilder {
53 AutoLayoutConfigBuilder::new()
54 }
55}
56
57#[derive(Debug)]
59pub struct AutoLayoutConfigBuilder {
60 config: AutoLayoutConfig,
61}
62
63impl AutoLayoutConfigBuilder {
64 pub fn new() -> Self {
66 Self {
67 config: AutoLayoutConfig::default(),
68 }
69 }
70
71 pub fn strategy(mut self, strategy: AutoLayoutStrategy) -> Self {
73 self.config.strategy = strategy;
74 self
75 }
76
77 pub fn small_graph_threshold(mut self, threshold: usize) -> Self {
79 self.config.small_graph_threshold = threshold;
80 self
81 }
82
83 pub fn enable_transitions(mut self, enable: bool) -> Self {
85 self.config.enable_transitions = enable;
86 self
87 }
88
89 pub fn transition_duration(mut self, duration: f64) -> Self {
91 self.config.transition_duration = duration.max(0.0);
92 self
93 }
94
95 pub fn force_relayout_on_change(mut self, force: bool) -> Self {
97 self.config.force_relayout_on_change = force;
98 self
99 }
100
101 pub fn build(self) -> AutoLayoutConfig {
103 self.config
104 }
105}