Skip to content

Commit

Permalink
feat(hydroflow_lang): Render singleton references in graphvis (#1146)
Browse files Browse the repository at this point in the history
Refs: #797 #1065
  • Loading branch information
MingweiSamuel authored Apr 5, 2024
1 parent 1b19361 commit 1bde8a2
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/src/pages/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export function EditorDemo({ compileFn, examples, mermaidId }) {
noVarnames: false,
noPullPush: false,
noHandoffs: false,
noReferences: false,
opShortText: false,
});
const writeGraphConfigOnChange = (name) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ digraph {
n5v1 -> n6v1
n1v1 -> n5v1
n4v1 -> n8v1 [color=darkgreen, style=bold]
n6v1 -> n4v1 [color=red]
subgraph "cluster n1v1" {
fillcolor="#dddddd"
style=filled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linkStyle default stroke:#aaa
5v1-->6v1
1v1-->5v1
4v1==>8v1; linkStyle 5 stroke:#060
6v1--x4v1; linkStyle 6 stroke:red
subgraph sg_1v1 ["sg_1v1 stratum 0"]
1v1
5v1
Expand Down
5 changes: 4 additions & 1 deletion hydroflow_lang/src/graph/graph_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::{Color, FlowProps, GraphNodeId, GraphSubgraphId, LatticeFlowType};

/// Trait for writing textual representations of graphs, i.e. mermaid or dot graphs.
#[auto_impl(&mut, Box)]
pub trait GraphWrite {
pub(crate) trait GraphWrite {
/// Error type emitted by writing.
type Err: Error;

Expand All @@ -34,6 +34,7 @@ pub trait GraphWrite {
delay_type: Option<DelayType>,
flow_props: Option<FlowProps>,
label: Option<&str>,
is_reference: bool,
) -> Result<(), Self::Err>;

/// Begin writing a subgraph.
Expand Down Expand Up @@ -164,6 +165,7 @@ where
delay_type: Option<DelayType>,
flow_props: Option<FlowProps>,
label: Option<&str>,
_is_reference: bool,
) -> Result<(), Self::Err> {
let src_str = format!("{:?}", src_id.data());
let dest_str = format!("{:?}", dst_id.data());
Expand Down Expand Up @@ -342,6 +344,7 @@ where
delay_type: Option<DelayType>,
flow_props: Option<FlowProps>,
label: Option<&str>,
_is_reference: bool,
) -> Result<(), Self::Err> {
let lattice_flow_type = flow_props.and_then(|flow_props| flow_props.lattice_flow_type);
let mut properties = Vec::<Cow<'static, str>>::new();
Expand Down
33 changes: 30 additions & 3 deletions hydroflow_lang/src/graph/hydroflow_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{
HANDOFF_NODE_STR, HYDROFLOW,
};
use crate::diagnostic::{Diagnostic, Level};
use crate::graph::ops::null_write_iterator_fn;
use crate::graph::ops::{null_write_iterator_fn, DelayType};
use crate::graph::MODULE_BOUNDARY_NODE_STR;
use crate::pretty_span::{PrettyRowCol, PrettySpan};
use crate::process_singletons::postprocess_singletons;
Expand Down Expand Up @@ -1341,7 +1341,7 @@ impl HydroflowGraph {
}

/// Write out this `HydroflowGraph` using the given `GraphWrite`. E.g. `Mermaid` or `Dot.
pub fn write_graph<W>(
pub(crate) fn write_graph<W>(
&self,
mut graph_write: W,
write_config: &WriteConfig,
Expand Down Expand Up @@ -1456,7 +1456,31 @@ impl HydroflowGraph {
let delay_type = self
.node_op_inst(dst_id)
.and_then(|op_inst| (op_inst.op_constraints.input_delaytype_fn)(dst_port));
graph_write.write_edge(src_id, dst_id, delay_type, flow_props, label.as_deref())?;
graph_write.write_edge(
src_id,
dst_id,
delay_type,
flow_props,
label.as_deref(),
false,
)?;
}

// Write reference edges.
if !write_config.no_references {
for src_id in self.node_ids() {
for dst_id in self
.node_singleton_references(src_id)
.iter()
.copied()
.flatten()
{
let delay_type = Some(DelayType::Stratum);
let flow_props = None;
let label = None;
graph_write.write_edge(src_id, dst_id, delay_type, flow_props, label, true)?;
}
}
}

// Write subgraphs.
Expand Down Expand Up @@ -1588,6 +1612,9 @@ pub struct WriteConfig {
/// Will not render handoffs if set.
#[cfg_attr(feature = "debugging", arg(long))]
pub no_handoffs: bool,
/// Will not render singleton references if set.
#[cfg_attr(feature = "debugging", arg(long))]
pub no_references: bool,

/// Op text will only be their name instead of the whole source.
#[cfg_attr(feature = "debugging", arg(long))]
Expand Down
4 changes: 4 additions & 0 deletions website_playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,15 @@ pub fn compile_hydroflow(
no_varnames: bool,
no_pull_push: bool,
no_handoffs: bool,
no_references: bool,
op_short_text: bool,
) -> JsValue {
let write_config = WriteConfig {
no_subgraphs,
no_varnames,
no_pull_push,
no_handoffs,
no_references,
op_short_text,
};

Expand Down Expand Up @@ -164,13 +166,15 @@ pub fn compile_datalog(
no_varnames: bool,
no_pull_push: bool,
no_handoffs: bool,
no_references: bool,
op_short_text: bool,
) -> JsValue {
let write_config = WriteConfig {
no_subgraphs,
no_varnames,
no_pull_push,
no_handoffs,
no_references,
op_short_text,
};

Expand Down

0 comments on commit 1bde8a2

Please sign in to comment.