#printing

petgraph-graphml

GraphML output support for petgraph

7 stable releases

3.1.0 Jul 7, 2024
3.0.0 Aug 28, 2021
2.0.1 Feb 4, 2020
1.0.2 May 15, 2018

#19 in #printing

Download history 197/week @ 2024-07-05 28/week @ 2024-07-12 13/week @ 2024-07-19 39/week @ 2024-07-26 16/week @ 2024-08-02 12/week @ 2024-08-09 5/week @ 2024-08-16 34/week @ 2024-08-23 91/week @ 2024-08-30 47/week @ 2024-09-06 194/week @ 2024-09-13 110/week @ 2024-09-20 103/week @ 2024-09-27 181/week @ 2024-10-04 94/week @ 2024-10-11 21/week @ 2024-10-18

405 downloads per month
Used in pmrs

MIT/Apache

20KB
259 lines

GraphML output support for petgraph

docs.rs badge crates.io badge Rust CI codecov


This crate extends petgraph with GraphML output support.

This crate exports a single type GraphMl which combines a build-pattern for configuration and provides creating strings (GraphMl::to_string) and writing to writers (GraphMl::to_writer).

Usage

Add this to your Cargo.toml:

[dependencies]
petgraph-graphml = "3.1.0"

Example

For a simple graph like Graph with three nodes and two edges this is the generated GraphML output.

let graph = make_graph();
// Configure output settings
// Enable pretty printing and exporting of node weights.
// Use the Display implementation of NodeWeights for exporting them.
let graphml = GraphMl::new(&graph)
    .pretty_print(true)
    .export_node_weights_display();

assert_eq!(
    graphml.to_string(),
    r#"<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns">
  <graph edgedefault="directed">
    <node id="n0">
      <data key="weight">0</data>
    </node>
    <node id="n1">
      <data key="weight">1</data>
    </node>
    <node id="n2">
      <data key="weight">2</data>
    </node>
    <edge id="e0" source="n0" target="n1" />
    <edge id="e1" source="n1" target="n2" />
  </graph>
  <key id="weight" for="node" attr.name="weight" attr.type="string" />
</graphml>"#
);

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~2.5MB
~35K SLoC