Skip to content

Commit

Permalink
chore: improve .dot debug API (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q authored Oct 3, 2023
1 parent 44a64b6 commit 9cb1f00
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,22 @@ pub fn collect_array<const N: usize, T: Debug>(arr: &[T]) -> [&T; N] {
// Test only utils
#[cfg(test)]
pub(crate) mod test {
#[allow(unused_imports)]
use crate::HugrView;

/// Open a browser page to render a dot string graph.
///
/// This can be used directly on the output of `Hugr::dot_string`
#[cfg(not(ci_run))]
pub(crate) fn viz_dotstr(dotstr: &str) {
pub(crate) fn viz_dotstr(dotstr: impl AsRef<str>) {
let mut base: String = "https://dreampuf.github.io/GraphvizOnline/#".into();
base.push_str(&urlencoding::encode(dotstr));
base.push_str(&urlencoding::encode(dotstr.as_ref()));
webbrowser::open(&base).unwrap();
}

/// Open a browser page to render a HugrView's dot string graph.
#[cfg(not(ci_run))]
pub(crate) fn viz_hugr(hugr: &impl HugrView) {
viz_dotstr(hugr.dot_string());
}
}

0 comments on commit 9cb1f00

Please sign in to comment.