Skip to main content

NetworkPlot

Struct NetworkPlot 

Source
pub struct NetworkPlot {
    pub nodes: Vec<NetworkNode>,
    pub edges: Vec<NetworkEdge>,
    pub directed: bool,
    pub layout: NetworkLayout,
    pub node_radius: f64,
    pub edge_opacity: f64,
    pub show_labels: bool,
    pub legend_label: Option<String>,
    pub label_size: Option<u32>,
    pub repel_labels: bool,
    pub label_inside: bool,
    /* private fields */
}
Expand description

A network / graph diagram.

Fields§

§nodes: Vec<NetworkNode>§edges: Vec<NetworkEdge>§directed: bool

Draw arrowheads on edges (default false).

§layout: NetworkLayout

Node placement algorithm (default NetworkLayout::ForceDirected).

§node_radius: f64

Base node radius in pixels (default 8.0).

§edge_opacity: f64

Edge stroke opacity 0.0–1.0 (default 0.6).

§show_labels: bool

Render node labels (default false).

§legend_label: Option<String>

If set, generate a legend with one entry per unique group.

§label_size: Option<u32>

Override label font size (pixels).

§repel_labels: bool

Apply label repulsion to avoid overlap (default false).

§label_inside: bool

Render node labels centred inside the node circle instead of beside it (default false). Font size is auto-scaled to fit within the node radius; white text is used for contrast.

Implementations§

Source§

impl NetworkPlot

Source

pub fn new() -> Self

Source

pub fn with_edge<S: Into<String>>( self, source: S, target: S, weight: impl Into<f64>, ) -> Self

Add an edge, auto-creating source and target nodes by label if needed.

Source

pub fn with_edge_color<S: Into<String>, C: Into<String>>( self, source: S, target: S, weight: impl Into<f64>, color: C, ) -> Self

Add an edge with an explicit colour.

Source

pub fn with_edge_label<S: Into<String>, L: Into<String>>( self, source: S, target: S, weight: impl Into<f64>, label: L, ) -> Self

Add an edge with a text label rendered at its midpoint.

Source

pub fn with_edge_styled<S: Into<String>, C: Into<String>, L: Into<String>>( self, source: S, target: S, weight: impl Into<f64>, color: C, label: L, ) -> Self

Add an edge with both an explicit colour and a text label.

Source

pub fn with_edge_curved<S: Into<String>>( self, source: S, target: S, weight: impl Into<f64>, curve: f64, ) -> Self

Add a curved edge via quadratic-bezier arc.

curve is a signed perpendicular offset as a fraction of edge length. Positive bends left of the travel direction (perp = (−uy, ux)); negative bends right.

Source

pub fn with_edge_curved_label<S: Into<String>, L: Into<String>>( self, source: S, target: S, weight: impl Into<f64>, curve: f64, label: L, ) -> Self

Add a curved edge with a text label rendered at the curve’s midpoint.

Source

pub fn with_edge_curved_styled<S: Into<String>, C: Into<String>, L: Into<String>>( self, source: S, target: S, weight: impl Into<f64>, curve: f64, color: C, label: L, ) -> Self

Add a curved edge with an explicit colour and a text label.

Source

pub fn with_edges<S, V, I>(self, edges: I) -> Self
where S: Into<String>, V: Into<f64>, I: IntoIterator<Item = (S, S, V)>,

Bulk-add edges from an iterator of (source, target, weight).

Source

pub fn with_matrix<S, L>(self, matrix: Vec<Vec<f64>>, labels: L) -> Self
where S: Into<String>, L: IntoIterator<Item = S>,

Build a network from an N×N adjacency matrix.

Non-zero entries become edges; the value is used as the weight. The matrix is stored and edges are expanded by resolve_matrix (called automatically by render_multiple), so .with_directed() can be called before or after this method.

If you call compute_positions directly (e.g. to inspect the layout), call resolve_matrix() first.

Source

pub fn resolve_matrix(&mut self)

Expand a pending adjacency matrix into edges. Called automatically by render_multiple; safe to call multiple times (no-op after the first).

Source

pub fn with_node<S: Into<String>>(self, label: S) -> Self

Declare a node explicitly (no-op if it already exists).

Source

pub fn with_node_color<S: Into<String>, C: Into<String>>( self, label: S, color: C, ) -> Self

Set the colour for a node, creating it if absent.

Source

pub fn with_node_size<S: Into<String>>(self, label: S, size: f64) -> Self

Set the size for a node, creating it if absent.

Source

pub fn with_node_group<S: Into<String>, G: Into<String>>( self, label: S, group: G, ) -> Self

Set the group for a node, creating it if absent.

Source

pub fn with_node_shape<S: Into<String>>( self, label: S, shape: NodeShape, ) -> Self

Set the marker shape for a node, creating it if absent.

Source

pub fn with_node_position<S: Into<String>>( self, label: S, x: f64, y: f64, ) -> Self

Fix a node’s position in normalised [0, 1] space.

Source

pub fn with_directed(self) -> Self

Draw directed edges with arrowheads.

Source

pub fn with_layout(self, layout: NetworkLayout) -> Self

Set the layout algorithm.

Source

pub fn with_node_radius(self, r: f64) -> Self

Set the base node radius in pixels.

Source

pub fn with_edge_opacity(self, opacity: f64) -> Self

Set edge stroke opacity (0.0–1.0).

Source

pub fn with_labels(self) -> Self

Show node labels beside each node.

Source

pub fn with_repel_labels(self) -> Self

Enable label repulsion so overlapping labels push apart.

Source

pub fn with_labels_inside(self) -> Self

Render node labels centred inside each node. Also enables show_labels. Font size is auto-scaled to fit the node radius; white text is used for contrast against the node fill.

Source

pub fn with_legend<S: Into<String>>(self, label: S) -> Self

Show a legend; one entry per unique group. If no groups have been assigned the legend falls back to one entry per node, which can be large — prefer using with_node_group to keep the legend compact.

Source

pub fn with_label_size(self, size: u32) -> Self

Override the label font size.

Source

pub fn compute_positions(&self) -> Vec<(f64, f64)>

Compute node positions in [0, 1] × [0, 1] space.

Disconnected components are laid out independently, then tiled side-by-side (like igraph’s component_wise approach).

Call resolve_matrix first if a matrix was provided via with_matrix, or this will only see edges added via with_edge/with_edges.

Trait Implementations§

Source§

impl Clone for NetworkPlot

Source§

fn clone(&self) -> NetworkPlot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NetworkPlot

Source§

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

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

impl Default for NetworkPlot

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<NetworkPlot> for Plot

Source§

fn from(p: NetworkPlot) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

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.