xdot/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]

//! Parse and draw [`xdot`](https://graphviz.org/docs/attr-types/xdot/) shapes.
//!
//! ## Example
//! ```rust
//! use xdot::parse;
//! let shapes = parse("c 7 -#ff0000 p 4 4 4 36 4 36 36 4 36");
//! ```
//!
//! ## Feature flags
#![cfg_attr(all(doc, feature = "document-features"), doc = document_features::document_features!())]

#[macro_use]
mod impl_help;
#[cfg(feature = "layout")]
mod layout;
mod xdot_parse;

#[cfg(feature = "layout")]
pub use self::layout::{draw_graph, layout_and_draw_graph, LayoutError};
#[cfg(feature = "pyo3")]
use self::xdot_parse::parse_py;
pub use self::xdot_parse::{draw, parse, shapes, ShapeDraw};

/// Known node/edge attribute names holding `xdot` draw instructions that [parse] can handle.
///
/// If the [feature flag](crate#feature-flags) `layout` is active, this is by [draw_graph] when traversing the graph.
pub static ATTR_NAMES: [&str; 6] = [
    "_draw_", "_ldraw_", "_hdraw_", "_tdraw_", "_hldraw_", "_tldraw_",
];

/// Python module TODO
#[cfg(feature = "pyo3")]
#[pyo3::pymodule]
#[pyo3(name = "xdot_rs")]
pub fn pymodule(m: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> {
    use pyo3::prelude::*;

    m.add_class::<ShapeDraw>()?;
    m.add_function(pyo3::wrap_pyfunction!(parse_py, m)?)?;
    let m_dict = m.py().import_bound("sys")?.getattr("modules")?;
    m.add_wrapped(pyo3::wrap_pymodule!(shapes::pymodule))?;
    m_dict.set_item("xdot_rs.shapes", m.getattr("shapes")?)?;
    m.add_wrapped(pyo3::wrap_pymodule!(draw::pymodule))?;
    m_dict.set_item("xdot_rs.draw", m.getattr("draw")?)?;
    Ok(())
}