xdot/
lib.rs

1#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]
2
3//! Parse and draw [`xdot`](https://graphviz.org/docs/attr-types/xdot/) shapes.
4//!
5//! ## Example
6//! ```rust
7//! use xdot::parse;
8//! let shapes = parse("c 7 -#ff0000 p 4 4 4 36 4 36 36 4 36");
9//! ```
10//!
11//! ## Feature flags
12#![cfg_attr(all(doc, feature = "document-features"), doc = document_features::document_features!())]
13
14#[macro_use]
15mod impl_help;
16#[cfg(feature = "layout")]
17mod layout;
18mod xdot_parse;
19
20#[cfg(feature = "layout")]
21pub use self::layout::{LayoutError, draw_graph, layout_and_draw_graph};
22#[cfg(feature = "pyo3")]
23use self::xdot_parse::parse_py;
24pub use self::xdot_parse::{ShapeDraw, draw, parse, shapes};
25
26/// Known node/edge attribute names holding `xdot` draw instructions that [parse] can handle.
27///
28/// If the [feature flag](crate#feature-flags) `layout` is active, this is by [draw_graph] when traversing the graph.
29pub static ATTR_NAMES: [&str; 6] = [
30    "_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_",
31];
32
33/// Python module TODO
34#[cfg(feature = "pyo3")]
35#[pyo3::pymodule]
36#[pyo3(name = "xdot_rs")]
37pub fn pymodule(m: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> {
38    use pyo3::prelude::*;
39
40    m.add_class::<ShapeDraw>()?;
41    m.add_function(pyo3::wrap_pyfunction!(parse_py, m)?)?;
42    let m_dict = m.py().import("sys")?.getattr("modules")?;
43    m.add_wrapped(pyo3::wrap_pymodule!(shapes::pymodule))?;
44    m_dict.set_item("xdot_rs.shapes", m.getattr("shapes")?)?;
45    m.add_wrapped(pyo3::wrap_pymodule!(draw::pymodule))?;
46    m_dict.set_item("xdot_rs.draw", m.getattr("draw")?)?;
47    Ok(())
48}