| Crates.io | visgraph |
| lib.rs | visgraph |
| version | 0.1.0 |
| created_at | 2025-11-08 17:57:08.057688+00 |
| updated_at | 2025-11-08 17:57:08.057688+00 |
| description | Visualize Graphs as Images with one Function Call. |
| homepage | |
| repository | https://github.com/raoulluque/visgraph |
| max_upload_size | |
| id | 1923104 |
| size | 888,781 |
¹
visgraph is an easy-to-use Rust library for visualizing graphs using various layout algorithms and exporting them to image formats like PNG or even SVG.
The current implementation uses SVG as an intermediate format, allowing for high-quality rendering and scalability, in order to be able to use resvg.
The various layout algorithms that are supported can be found in the
layout module documentation.
Supports Rust 1.68 and later. This will only change on major releases.
For more examples, see the examples directory.
// This example is taken from examples/default_settings.rs
use petgraph::graph::UnGraph;
use visgraph::{graph_to_img, graph_to_svg, settings::Settings};
// Create a complete graph with 4 nodes. //----|
let mut complete_graph = UnGraph::new_undirected(); //|
let num_nodes = 4; //|
let nodes: Vec<_> = (0..num_nodes) //|
.map(|_| complete_graph.add_node(())) //| This code just
.collect(); //| creates a graph
//| to be visualized
for i in 0..num_nodes { //|
for j in (i + 1)..num_nodes { //|
complete_graph.add_edge(nodes[i], nodes[j], ()); //|
} //|
} //----|
// This is the actual functionality of this lib:
// Save the graph as an SVG (using default settings in this case):
graph_to_svg(
&complete_graph,
&Settings::default(),
"examples/results/default_settings.svg",
)
.unwrap();
// The graph can also be saved as a PNG image (requires the "img" feature):
graph_to_img(
&complete_graph,
&Settings::default(),
"examples/results/default_settings.png",
)
.unwrap();
For the result, see examples/results/default_settings.png.
There are several customization options available for rendering the graph. These can be set using the
SettingsBuilder struct.
visgraphs performance can be greatly improved by enabling optimizations. To do so, either build
your entire project in release mode, or enable optimizations for just visgraph by adding the
following to your Cargo.toml:
[profile.dev.package.visgraph]
opt-level = 3
visgraph currently only has a single feature:
img: Enables exporting graphs to PNG using resvg. Enabling this feature adds
a dependency on the resvg crate and thus increases compile times.First, see if the answer to your question can be found in the API documentation. If the answer is not there, feel free to ask your question on the discussions page. I'd be happy to try to answer your question. If you find a bug, or have a feature request, please open an issue.
🦕 Thanks for your help improving the project! There's no contribution guide yet, but feel free to open an issue if you'd like to help out or just open a PR directly and we can discuss the changes there.
This tools purpose is mostly fast dev-time graph visualization. If you need more advanced graph visualization capabilities, consider using one of the following tools:
petgraph graphs in egui applications.petgraph has built-in support for exporting to the DOT format used by Graphviz.Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0 or the MIT license, at your option. This file may not be copied, modified, or distributed except according to those terms.
¹Image generated using visgraph, see examples/circular_layout.rs.