-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydroflow_lang): open mermaid/dot graph in browser (#923)
* `HydroflowGraph::open_mermaid()` opens https://mermaid.live/ * `HydroflowGraph::open_dot()` opens https://dreampuf.github.io/GraphvizOnline/ Behind a new `hydroflow/debugging`/`hydroflow_lang/debugging` feature gate.
- Loading branch information
1 parent
488d6dd
commit e7ea6d8
Showing
5 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#![cfg(feature = "debugging")] | ||
|
||
use std::fmt::Write; | ||
use std::io::Result; | ||
|
||
use super::HydroflowGraph; | ||
|
||
impl HydroflowGraph { | ||
/// Opens this as a mermaid graph in the [mermaid.live](https://mermaid.live) browser editor. | ||
pub fn open_mermaid(&self) -> Result<()> { | ||
let mermaid_src = self.to_mermaid(); | ||
let state = serde_json::json!({ | ||
"code": mermaid_src, | ||
"mermaid": serde_json::json!({ | ||
"theme": "default" | ||
}), | ||
"autoSync": true, | ||
"updateDiagram": true | ||
}); | ||
let state_json = serde_json::to_vec(&state)?; | ||
let state_base64 = data_encoding::BASE64URL.encode(&state_json); | ||
webbrowser::open(&format!( | ||
"https://mermaid.live/edit#base64:{}", | ||
state_base64 | ||
)) | ||
} | ||
|
||
/// Opens this as dot/graphviz graph in the [Graphviz Online](https://dreampuf.github.io/GraphvizOnline/#) | ||
/// browser editor. | ||
pub fn open_dot(&self) -> Result<()> { | ||
let dot_src = self.to_dot(); | ||
let mut url = "https://dreampuf.github.io/GraphvizOnline/#".to_owned(); | ||
for byte in dot_src.bytes() { | ||
// Lazy percent encoding: https://en.wikipedia.org/wiki/Percent-encoding | ||
write!(url, "%{:02x}", byte).unwrap(); | ||
} | ||
webbrowser::open(&url) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters