Skip to content

Commit 060eaa7

Browse files
committed
Fix example and make it independent of pipefunc
1 parent f0256f3 commit 060eaa7

File tree

1 file changed

+79
-21
lines changed

1 file changed

+79
-21
lines changed

example.ipynb

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,83 @@
1111
"%env ANYWIDGET_HMR=1"
1212
]
1313
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from graphviz_anywidget import GraphvizAnyWidget, graphviz_widget"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"dot_source = \"\"\"\n",
30+
"// Graph Visualization\n",
31+
"digraph {\n",
32+
" graph [rankdir=LR]\n",
33+
" node [shape=rectangle]\n",
34+
" \n",
35+
" // Input nodes\n",
36+
" a [label=\"a\" color=black fillcolor=\"#90EE90\" fontname=Helvetica height=0.5 margin=0.05 penwidth=1 shape=rectangle style=\"filled,dashed\" width=0.75]\n",
37+
" b [label=\"b\" color=black fillcolor=\"#90EE90\" fontname=Helvetica height=0.5 margin=0.05 penwidth=1 shape=rectangle style=\"filled,dashed\" width=0.75]\n",
38+
" x [label=\"x = 1\" color=black fillcolor=\"#90EE90\" fontname=Helvetica height=0.5 margin=0.05 penwidth=1 shape=rectangle style=\"filled,dashed\" width=0.75]\n",
39+
" \n",
40+
" // Function nodes\n",
41+
" \"f(...) → c\" [label=\"f(...)\\nc\" color=black fillcolor=\"#87CEEB\" fontname=Helvetica height=0.5 margin=0.05 penwidth=1 shape=box style=\"filled,rounded\" width=0.75]\n",
42+
" \"g(...) → d\" [label=\"g(...)\\nd\" color=black fillcolor=\"#87CEEB\" fontname=Helvetica height=0.5 margin=0.05 penwidth=1 shape=box style=\"filled,rounded\" width=0.75]\n",
43+
" \"h(...) → e\" [label=\"h(...)\\ne\" color=black fillcolor=\"#87CEEB\" fontname=Helvetica height=0.5 margin=0.05 penwidth=1 shape=box style=\"filled,rounded\" width=0.75]\n",
44+
" \n",
45+
" // Edges\n",
46+
" \"f(...) → c\" -> \"g(...) → d\" [label=c color=\"#87CEEB\" fontcolor=transparent fontname=Helvetica penwidth=1.01]\n",
47+
" \"f(...) → c\" -> \"h(...) → e\" [label=c color=\"#87CEEB\" fontcolor=transparent fontname=Helvetica penwidth=1.01]\n",
48+
" \"g(...) → d\" -> \"h(...) → e\" [label=d color=\"#87CEEB\" fontcolor=transparent fontname=Helvetica penwidth=1.01]\n",
49+
" a -> \"f(...) → c\" [label=a color=\"#90EE90\" fontcolor=transparent fontname=Helvetica penwidth=1.01]\n",
50+
" b -> \"f(...) → c\" [label=b color=\"#90EE90\" fontcolor=transparent fontname=Helvetica penwidth=1.01]\n",
51+
" b -> \"g(...) → d\" [label=b color=\"#90EE90\" fontcolor=transparent fontname=Helvetica penwidth=1.01]\n",
52+
" x -> \"g(...) → d\" [label=\"x=1\" color=\"#90EE90\" fontcolor=transparent fontname=Helvetica penwidth=1.01]\n",
53+
" x -> \"h(...) → e\" [label=\"x=1\" color=\"#90EE90\" fontcolor=transparent fontname=Helvetica penwidth=1.01]\n",
54+
" \n",
55+
" // Legend\n",
56+
" subgraph cluster_legend {\n",
57+
" graph [color=black fillcolor=lightgrey fontcolor=black fontsize=20 label=Legend rankdir=LR style=filled]\n",
58+
" legend_0 [label=Argument color=black fillcolor=\"#90EE90\" fontname=Helvetica height=0.5 penwidth=1 shape=rectangle style=\"filled,dashed\" width=0.75]\n",
59+
" legend_1 [label=PipeFunc color=black fillcolor=\"#87CEEB\" fontname=Helvetica height=0.5 penwidth=1 shape=box style=\"filled,rounded\" width=0.75]\n",
60+
" legend_0 -> legend_1 [style=invis]\n",
61+
" }\n",
62+
"}\n",
63+
"\"\"\""
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"graphviz_widget(dot_source)"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"metadata": {},
79+
"outputs": [],
80+
"source": [
81+
"GraphvizAnyWidget(dot_source=dot_source)"
82+
]
83+
},
84+
{
85+
"cell_type": "markdown",
86+
"metadata": {},
87+
"source": [
88+
"The dot source above can also be generated by the PipeFunc package which is available on PyPI."
89+
]
90+
},
1491
{
1592
"cell_type": "code",
1693
"execution_count": null,
@@ -37,27 +114,8 @@
37114
"\n",
38115
"pipeline = Pipeline([f, g, h])\n",
39116
"\n",
40-
"dot_source = pipeline.visualize_graphviz(return_type=\"graphviz\").source"
41-
]
42-
},
43-
{
44-
"cell_type": "code",
45-
"execution_count": null,
46-
"metadata": {},
47-
"outputs": [],
48-
"source": [
49-
"from graphviz_anywidget import GraphvizWidget, graph_widget\n",
50-
"\n",
51-
"graph_widget(dot_string=dot_source)"
52-
]
53-
},
54-
{
55-
"cell_type": "code",
56-
"execution_count": null,
57-
"metadata": {},
58-
"outputs": [],
59-
"source": [
60-
"GraphvizWidget(dot_source=dot_source)"
117+
"dot_source = pipeline.visualize_graphviz(return_type=\"graphviz\").source\n",
118+
"graphviz_widget(dot_source)"
61119
]
62120
}
63121
],

0 commit comments

Comments
 (0)