Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
vizoxide - An idiomatic GraphViz wrapper for Rust
A comprehensive, memory-safe Rust wrapper for the GraphViz graph visualization library. This crate provides an ergonomic, idiomatic Rust interface for creating, manipulating, and rendering graphs.
Features
- Memory-safe wrapping of GraphViz's C API with proper RAII patterns
- Builder patterns for fluent, expressive graph creation
- Complete layout control with support for all GraphViz engines
- Extensive rendering options including SVG, PNG, PDF, and more
- Rich attribute handling with predefined constants for common graph, node, and edge attributes
- Comprehensive error handling with descriptive error types
- Iterator support for traversing nodes and edges
Prerequisites
This crate requires the GraphViz library to be installed on your system. Installation instructions vary by platform:
Linux
sudo apt-get install graphviz libgraphviz-dev
macOS
brew install graphviz
Windows
Download and install from GraphViz's official site or use:
choco install graphviz
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
Basic Usage
use ;
use ;
use ;
use Error;
Core Concepts
Context
A Context represents the GraphViz runtime environment. It's required for layout and rendering operations:
let context = new?;
Graphs
Create directed or undirected graphs:
// Directed graph
let directed = new?;
// Undirected graph
let undirected = new?;
// Strict graph (no duplicate edges)
let strict = new_with_strictness?;
Nodes & Edges
Nodes and edges are the building blocks of graphs:
// Add nodes
let node1 = graph.add_node?;
let node2 = graph.add_node?;
// Add an edge
let edge = graph.add_edge?;
Attributes
Customize the appearance of graphs, nodes, and edges with attributes:
// Set attributes directly
graph.set_attribute?;
node.set_attribute?;
edge.set_attribute?;
// Check and remove attributes
if node.has_attribute?
// Get attribute value
let shape = node.get_attribute?;
The attr module provides constants for common attribute names:
use ;
// Use predefined attribute constants
graph_obj.set_attribute?;
node_obj.set_attribute?;
edge_obj.set_attribute?;
Builder Pattern
The crate supports a fluent builder pattern for creating graph elements:
// Create a graph with the builder
let graph = builder
.directed
.strict
.attribute
.build?;
// Create a node with attributes
let start = graph.create_node
.attribute
.attribute
.attribute
.build?;
// Create an edge with attributes
let edge = graph.create_edge
.attribute
.attribute
.build?;
Layout Engines
GraphViz supports various layout algorithms:
// Basic layout application
apply_layout?;
// Other available engines
apply_layout?; // Spring model
apply_layout?; // Force-directed
apply_layout?; // Circular
apply_layout?; // Radial
apply_layout?; // Multiscale
Layout Settings
Customize layout behavior with predefined or custom settings:
// Using predefined layout settings
let radial_settings = radial_layout;
radial_settings.apply?;
// Using custom layout settings
let custom_settings = new
.with_overlap
.with_splines
.with_nodesep
.with_ranksep;
custom_settings.apply?;
Rendering
Render to File
render_to_file?;
render_to_file?;
render_to_file?;
Render to Memory
// Render to string (for text formats like SVG, DOT)
let svg_string = render_to_string?;
// Render to bytes (for any format)
let png_bytes = render_to_bytes?;
// Render to a writer
let mut buffer = new;
render_to_writer?;
Supported Formats
The crate supports all GraphViz output formats including:
- Vector formats: SVG, PDF, PS, EPS
- Raster formats: PNG, JPEG, GIF, BMP
- Text formats: DOT, XDOT, JSON, Plain
- And many more accessible via
Formatenum
Graph Traversal
Iterate over nodes and edges:
// Iterate through all nodes
for node in graph.nodes
// Check graph properties
println!;
println!;
println!;
Advanced Usage
Custom Plugins
// Create a context with custom plugin settings
let context = new_with_plugins?;
Render Options
// Customize rendering with options
let options = new
.with_anti_alias
.with_transparency
.with_dpi
.with_background
.with_scale;
// Apply options when rendering
render_with_options?;
Examples
The crate includes several examples demonstrating various features:
simple_graph- Basic graph creation and renderingcomplex_graph_with_build_pattern- Using the builder patternedge_builder_with_multiple_attributes- Working with edge attributespredefined_layout_settings- Using predefined layoutscreating_context_with_plugins- Working with GraphViz pluginsiterating_over_nodes_and_edges- Graph traversalrender_graph_to_string_and_bytes- In-memory renderingcustom_layout_settings- Advanced layout configurationmodifying_attributes_and_removing_them- Attribute manipulationrender_graph_to_writer- Rendering to custom output
Run any example with:
cargo run --example example_name
Error Handling
The crate uses the GraphvizError type to represent various error conditions:
match result
License
This crate is available under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.