pub struct Graph { /* private fields */ }Implementations§
Source§impl Graph
impl Graph
Sourcepub fn from_str(&mut self, graph_config: &str)
pub fn from_str(&mut self, graph_config: &str)
Appends graph structure elements from a graph configuration.
§Example
use dynalgo::graph::Graph;
let config = "A, B, A - B 0";
let mut graph = Graph::new();
graph.from_str(config);
assert!(graph.nodes() == vec!['A', 'B']);Sourcepub fn add_node(&mut self, name: char, xy: Option<(i16, i16)>)
pub fn add_node(&mut self, name: char, xy: Option<(i16, i16)>)
Adds a node to the graph structure, with an optional (x,y) freezed position (freezed coords of the element representation in SVG context). So the (x,y) position won’t change when automatic layout algo runs.
Sourcepub fn delete_node(&mut self, node: char)
pub fn delete_node(&mut self, node: char)
Deletes a node from the graph structure.
Sourcepub fn add_link(
&mut self,
node_from: char,
node_to: char,
bidirectional: bool,
value: i8,
)
pub fn add_link( &mut self, node_from: char, node_to: char, bidirectional: bool, value: i8, )
Adds a link between two nodes. The link can be defined as bidirectional or not.
Sourcepub fn delete_link(&mut self, node_from: char, node_to: char)
pub fn delete_link(&mut self, node_from: char, node_to: char)
Deletes a link.
Sourcepub fn adjacency_list(&self) -> BTreeMap<char, BTreeMap<char, i8>>
pub fn adjacency_list(&self) -> BTreeMap<char, BTreeMap<char, i8>>
Returns the adjacency list.
§Example
use dynalgo::graph::Graph;
let config = "A
B
A - B 0";
let mut graph = Graph::new();
graph.from_str(config);
for (node_from, neighbors) in graph.adjacency_list() {
for (node_to, link_value) in neighbors {
println!("Can go from {} to {} (link value is {}).", node_from, node_to, link_value);
}
}Sourcepub fn adjacency_matrix(&self) -> BTreeMap<char, BTreeMap<char, Option<i8>>>
pub fn adjacency_matrix(&self) -> BTreeMap<char, BTreeMap<char, Option<i8>>>
Returns the adjacency matrix.
§Example
use dynalgo::graph::Graph;
let config = "A
B
A - B 0";
let mut graph = Graph::new();
graph.from_str(config);
let adjacency_matrix = graph.adjacency_matrix();
for node_from in graph.nodes().iter() {
for node_to in graph.nodes().iter() {
let link_value = adjacency_matrix[&node_from][&node_to];
if link_value.is_some() {
println!("Can go from {} to {} (link value is {}).", node_from, node_to, link_value.unwrap());
}
}
}Sourcepub fn neighbors(&self, node: char) -> Vec<char>
pub fn neighbors(&self, node: char) -> Vec<char>
Returns accessible nodes.
§Example
use dynalgo::graph::Graph;
let config = "A
B
A - B 0";
let mut graph = Graph::new();
graph.from_str(config);
for neighbor in graph.neighbors('A') {
println!("Can go from 'A' to {}.", neighbor);
}Sourcepub fn swap_nodes(&mut self, node_1: char, node_2: char)
pub fn swap_nodes(&mut self, node_1: char, node_2: char)
Swap two nodes in the graph structure and its graphic representation.
Sourcepub fn resume(&mut self)
pub fn resume(&mut self)
Reactivates the auto animation option.
When this option is activated, each graph structure change causes graphic animation (the animations are rendered one after the other). By default, the option is activated when a graph is created.
When this option is deactivated, all pending animations occur during the same period (i.e. not one after the other) when you manually call the anim_step() or anim_resume()functions.
Sourcepub fn step(&mut self, duration_ms: u32)
pub fn step(&mut self, duration_ms: u32)
Creates an animation that show the evolution between the last represented state (when anim_pause() function was called previously) and the current state. The pending animations are rendered simultaneously (i.e. not one after the other).
The anim_pause() function must have been called previously.
After calling anim_step() function, auto animation option still is deactivated.
Sourcepub fn render(&self, html_file_name: &str) -> Result<(), Error>
pub fn render(&self, html_file_name: &str) -> Result<(), Error>
Renders the graph animation in SVG SMIL format into a HTML file.
Sourcepub fn to_html(pages: Vec<(&str, Vec<&Graph>)>) -> Result<(), Error>
pub fn to_html(pages: Vec<(&str, Vec<&Graph>)>) -> Result<(), Error>
Renders graphs animations in SVG SMIL format into multiple HTML files. Each HTML page contains a menu to access other pages (if there is more than one page).
Sourcepub fn duration(&self) -> u32
pub fn duration(&self) -> u32
Returns the total duration in milliseconds of rendered animations since the graph was created.
Sourcepub fn node_position(&self, node: char) -> (i32, i32, bool)
pub fn node_position(&self, node: char) -> (i32, i32, bool)
Returns the current x,y coords (and freezed tag) of the node in the SVG graphic context.
Sourcepub fn move_node(&mut self, node: char, xy: (i32, i32))
pub fn move_node(&mut self, node: char, xy: (i32, i32))
Changes and freezes the x,y coords of the SVG node representation. The node position will not change when automatic layout algo runs.
Sourcepub fn hide_labels(&mut self, hide: bool)
pub fn hide_labels(&mut self, hide: bool)
Hides nodes labels
Sourcepub fn unfreeze_node(&mut self, node: char)
pub fn unfreeze_node(&mut self, node: char)
Unfreezes the node position (coords in SVG graphic context), so the current position will change when automatic layout algo runs.
Sourcepub fn color_link(
&mut self,
node_from: char,
node_to: char,
color: (u8, u8, u8),
)
pub fn color_link( &mut self, node_from: char, node_to: char, color: (u8, u8, u8), )
Changes the link stroke color.
Sourcepub fn color_value(
&mut self,
node_from: char,
node_to: char,
color: (u8, u8, u8),
)
pub fn color_value( &mut self, node_from: char, node_to: char, color: (u8, u8, u8), )
Changes the link value color.
Sourcepub fn speed(&mut self, speed_factor: f64)
pub fn speed(&mut self, speed_factor: f64)
Changes the animation speed (from 0.1 to 10.0). Default value is 1.0
Sourcepub fn node_radius(&self) -> u8
pub fn node_radius(&self) -> u8
Returns the radius of nodes