Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }

Implementations§

Source§

impl Graph

Source

pub fn new() -> Graph

Creates an empty graph structure.

Source

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']);
Source

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.

Source

pub fn delete_node(&mut self, node: char)

Deletes a node from the graph structure.

Adds a link between two nodes. The link can be defined as bidirectional or not.

Deletes a link.

Returns the links names list.

Source

pub fn nodes(&self) -> Vec<char>

Returns the nodes names list.

Source

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);
    }
}
Source

pub fn directed(&self) -> bool

Returns True if the graph is directed

Source

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());
        }
    }
}
Source

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);
}
Source

pub fn swap_nodes(&mut self, node_1: char, node_2: char)

Swap two nodes in the graph structure and its graphic representation.

Source

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.

Source

pub fn pause(&mut self)

Deactivates the auto animation option.

Source

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.

Source

pub fn sleep(&mut self, duration_ms: u32)

Delay the next animation.

Source

pub fn paused(&self) -> bool

Indicates whether the animation is paused or not

Source

pub fn render(&self, html_file_name: &str) -> Result<(), Error>

Renders the graph animation in SVG SMIL format into a HTML file.

Source

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).

Source

pub fn duration(&self) -> u32

Returns the total duration in milliseconds of rendered animations since the graph was created.

Source

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.

Source

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.

Source

pub fn fill_node(&mut self, node: char, color: (u8, u8, u8))

Changes the node fill color.

Source

pub fn color_node(&mut self, node: char, color: (u8, u8, u8))

Changes the node stroke color.

Source

pub fn hide_labels(&mut self, hide: bool)

Hides nodes labels

Source

pub fn color_label(&mut self, node: char, color: (u8, u8, u8))

Changes the node label color.

Source

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.

Changes the link stroke color.

Source

pub fn color_value( &mut self, node_from: char, node_to: char, color: (u8, u8, u8), )

Changes the link value color.

Source

pub fn speed(&mut self, speed_factor: f64)

Changes the animation speed (from 0.1 to 10.0). Default value is 1.0

Source

pub fn node_radius(&self) -> u8

Returns the radius of nodes

Source

pub fn sequence(&self) -> Vec<(char, (usize, usize))>

Returns the graph sequence (outdegree increasing order).

Trait Implementations§

Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Graph

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Graph, String>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.