Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix make visualization nodes filled by default #765

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions hamilton/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,20 @@ def _get_node_style(node_type: str) -> Dict[str, str]:
if node_type == "config":
node_style = dict(
shape="note",
style="",
style="filled",
fontname=fontname,
)
elif node_type == "input":
node_style = dict(
shape="rectangle",
margin="0.15",
style="dashed",
style="filled,dashed",
fontname=fontname,
)
elif node_type == "materializer":
node_style = dict(
shape="cylinder",
style="filled",
margin="0.15,0.1",
fontname=fontname,
)
Expand Down Expand Up @@ -383,6 +384,7 @@ def _get_legend(
label="Legend",
rank="same", # makes the legend perpendicular to the main DAG
fontname="helvetica",
fillcolor="#ffffff",
),
)

Expand Down Expand Up @@ -420,6 +422,14 @@ def _get_legend(
ranksep="0.4",
compound="true",
concentrate="true",
style="filled",
# bgcolor="transparent",
),
node_attr=dict(
fillcolor="#ffffff",
),
edge_attr=dict(
# color="#ffffff",
),
)
# we need to update the graph_attr dict instead of overwriting it
Expand Down
17 changes: 9 additions & 8 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,8 @@ def test_function_graph_display(tmp_path: pathlib.Path):
expected_set = set(
[
'\t\tfunction [fillcolor="#b4d8e4" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]\n',
"\t\tgraph [fontname=helvetica label=Legend rank=same]\n",
"\t\tinput [fontname=Helvetica margin=0.15 shape=rectangle style=dashed]\n",
'\t\tgraph [fillcolor="#ffffff" fontname=helvetica label=Legend rank=same]\n',
'\t\tinput [fontname=Helvetica margin=0.15 shape=rectangle style="filled,dashed"]\n',
'\t\toutput [fillcolor="#FFC857" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]\n',
"\tA -> B\n",
"\tA -> C\n",
Expand All @@ -711,7 +711,8 @@ def test_function_graph_display(tmp_path: pathlib.Path):
'\tC [label=<<b>C</b><br /><br /><i>int</i>> fillcolor="#b4d8e4" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]\n',
"\t_A_inputs -> A\n",
# commenting out input node: '\t_A_inputs [label=<<table border="0"><tr><td>c</td><td>int</td></tr><tr><td>b</td><td>int</td></tr></table>> fontname=Helvetica margin=0.15 shape=rectangle style=dashed]\n',
"\tgraph [compound=true concentrate=true rankdir=LR ranksep=0.4]\n",
"\tgraph [compound=true concentrate=true rankdir=LR ranksep=0.4 style=filled]\n",
'\tnode [fillcolor="#ffffff"]\n',
"\tsubgraph cluster__legend {\n",
"\t}\n",
"// Dependency Graph\n",
Expand All @@ -726,7 +727,6 @@ def test_function_graph_display(tmp_path: pathlib.Path):
render_kwargs={"view": False},
node_modifiers=node_modifiers,
)

dot = dot_file_path.open("r").readlines()
dot_set = set(dot)

Expand Down Expand Up @@ -964,17 +964,18 @@ def test_create_graphviz_graph():
"// Dependency Graph",
"",
"digraph {",
"\tgraph [compound=true concentrate=true rankdir=LR ranksep=0.4 ratio=1]",
'\tnode [fillcolor="#ffffff"]',
"\tgraph [compound=true concentrate=true rankdir=LR ranksep=0.4 ratio=1 style=filled]",
'\tB [label=<<b>B</b><br /><br /><i>int</i>> fillcolor="#FFC857" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]',
'\tC [label=<<b>C</b><br /><br /><i>int</i>> fillcolor="#b4d8e4" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]',
'\tA [label=<<b>A</b><br /><br /><i>int</i>> fillcolor="#b4d8e4" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]',
"\tA -> B",
"\tA -> C",
'\t_A_inputs [label=<<table border="0"><tr><td>b</td><td>int</td></tr><tr><td>b</td><td>int</td></tr></table>> fontname=Helvetica margin=0.15 shape=rectangle style=dashed]',
'\t_A_inputs [label=<<table border="0"><tr><td>b</td><td>int</td></tr><tr><td>b</td><td>int</td></tr></table>> fontname=Helvetica margin=0.15 shape=rectangle style="filled,dashed"]',
"\t_A_inputs -> A",
"\tsubgraph cluster__legend {",
"\t\tgraph [fontname=helvetica label=Legend rank=same]",
"\t\tinput [fontname=Helvetica margin=0.15 shape=rectangle style=dashed]",
'\t\tgraph [fillcolor="#ffffff" fontname=helvetica label=Legend rank=same]',
'\t\tinput [fontname=Helvetica margin=0.15 shape=rectangle style="filled,dashed"]',
'\t\tfunction [fillcolor="#b4d8e4" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]',
'\t\toutput [fillcolor="#FFC857" fontname=Helvetica margin=0.15 shape=rectangle style="rounded,filled"]',
"\t}",
Expand Down