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: boolDraw arrowheads on edges (default false).
layout: NetworkLayoutNode placement algorithm (default NetworkLayout::ForceDirected).
node_radius: f64Base node radius in pixels (default 8.0).
edge_opacity: f64Edge stroke opacity 0.0–1.0 (default 0.6).
show_labels: boolRender 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: boolApply label repulsion to avoid overlap (default false).
label_inside: boolRender 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
impl NetworkPlot
pub fn new() -> Self
Sourcepub fn with_edge<S: Into<String>>(
self,
source: S,
target: S,
weight: impl Into<f64>,
) -> Self
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.
Sourcepub fn with_edge_color<S: Into<String>, C: Into<String>>(
self,
source: S,
target: S,
weight: impl Into<f64>,
color: C,
) -> Self
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.
Sourcepub fn with_edge_label<S: Into<String>, L: Into<String>>(
self,
source: S,
target: S,
weight: impl Into<f64>,
label: L,
) -> Self
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.
Sourcepub 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
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.
Sourcepub fn with_edge_curved<S: Into<String>>(
self,
source: S,
target: S,
weight: impl Into<f64>,
curve: f64,
) -> Self
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.
Sourcepub 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
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.
Sourcepub 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
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.
Sourcepub fn with_edges<S, V, I>(self, edges: I) -> Self
pub fn with_edges<S, V, I>(self, edges: I) -> Self
Bulk-add edges from an iterator of (source, target, weight).
Sourcepub fn with_matrix<S, L>(self, matrix: Vec<Vec<f64>>, labels: L) -> Self
pub fn with_matrix<S, L>(self, matrix: Vec<Vec<f64>>, labels: L) -> Self
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.
Sourcepub fn resolve_matrix(&mut self)
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).
Sourcepub fn with_node<S: Into<String>>(self, label: S) -> Self
pub fn with_node<S: Into<String>>(self, label: S) -> Self
Declare a node explicitly (no-op if it already exists).
Sourcepub fn with_node_color<S: Into<String>, C: Into<String>>(
self,
label: S,
color: C,
) -> Self
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.
Sourcepub fn with_node_size<S: Into<String>>(self, label: S, size: f64) -> Self
pub fn with_node_size<S: Into<String>>(self, label: S, size: f64) -> Self
Set the size for a node, creating it if absent.
Sourcepub fn with_node_group<S: Into<String>, G: Into<String>>(
self,
label: S,
group: G,
) -> Self
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.
Sourcepub fn with_node_shape<S: Into<String>>(
self,
label: S,
shape: NodeShape,
) -> Self
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.
Sourcepub fn with_node_position<S: Into<String>>(
self,
label: S,
x: f64,
y: f64,
) -> Self
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.
Sourcepub fn with_directed(self) -> Self
pub fn with_directed(self) -> Self
Draw directed edges with arrowheads.
Sourcepub fn with_layout(self, layout: NetworkLayout) -> Self
pub fn with_layout(self, layout: NetworkLayout) -> Self
Set the layout algorithm.
Sourcepub fn with_node_radius(self, r: f64) -> Self
pub fn with_node_radius(self, r: f64) -> Self
Set the base node radius in pixels.
Sourcepub fn with_edge_opacity(self, opacity: f64) -> Self
pub fn with_edge_opacity(self, opacity: f64) -> Self
Set edge stroke opacity (0.0–1.0).
Sourcepub fn with_labels(self) -> Self
pub fn with_labels(self) -> Self
Show node labels beside each node.
Sourcepub fn with_repel_labels(self) -> Self
pub fn with_repel_labels(self) -> Self
Enable label repulsion so overlapping labels push apart.
Sourcepub fn with_labels_inside(self) -> Self
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.
Sourcepub fn with_legend<S: Into<String>>(self, label: S) -> Self
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.
Sourcepub fn with_label_size(self, size: u32) -> Self
pub fn with_label_size(self, size: u32) -> Self
Override the label font size.
Sourcepub fn compute_positions(&self) -> Vec<(f64, f64)>
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
impl Clone for NetworkPlot
Source§fn clone(&self) -> NetworkPlot
fn clone(&self) -> NetworkPlot
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NetworkPlot
impl Debug for NetworkPlot
Source§impl Default for NetworkPlot
impl Default for NetworkPlot
Source§impl From<NetworkPlot> for Plot
impl From<NetworkPlot> for Plot
Source§fn from(p: NetworkPlot) -> Self
fn from(p: NetworkPlot) -> Self
Auto Trait Implementations§
impl Freeze for NetworkPlot
impl RefUnwindSafe for NetworkPlot
impl Send for NetworkPlot
impl Sync for NetworkPlot
impl Unpin for NetworkPlot
impl UnsafeUnpin for NetworkPlot
impl UnwindSafe for NetworkPlot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.