Skip to content

Commit 0a14de3

Browse files
committed
Replace pygraphviz with neo4j-viz for pipeline visualization
This commit replaces pygraphviz with neo4j-viz for pipeline visualization, providing a more interactive HTML-based visualization experience. The changes include: - Updated the Pipeline.draw() method to generate HTML output using neo4j-viz - Added a new get_neo4j_viz_graph() method while maintaining backward compatibility - Updated dependencies in pyproject.toml to use neo4j-viz instead of pygraphviz - Updated documentation and examples to reflect the change from PNG to HTML output - Updated unit tests to work with the new visualization implementation - Added stub file for neo4j-viz to make mypy happy
1 parent 2d62e4c commit 0a14de3

File tree

8 files changed

+1501
-994
lines changed

8 files changed

+1501
-994
lines changed

docs/source/user_guide_pipeline.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,26 @@ Pipelines can be visualized using the `draw` method:
111111
pipe = Pipeline()
112112
# ... define components and connections
113113
114-
pipe.draw("pipeline.png")
114+
pipe.draw("pipeline.html")
115115
116-
Here is an example pipeline rendering:
116+
Here is an example pipeline rendering as an interactive HTML visualization:
117117

118-
.. image:: images/pipeline_no_unused_outputs.png
119-
:alt: Pipeline visualisation with hidden outputs if unused
118+
.. code:: python
120119
120+
# To view the visualization in a browser
121+
import webbrowser
122+
webbrowser.open("pipeline.html")
121123
122124
By default, output fields which are not mapped to any component are hidden. They
123-
can be added to the canvas by setting `hide_unused_outputs` to `False`:
125+
can be added to the visualization by setting `hide_unused_outputs` to `False`:
124126

125127
.. code:: python
126128
127-
pipe.draw("pipeline.png", hide_unused_outputs=False)
128-
129-
Here is an example of final result:
130-
131-
.. image:: images/pipeline_full.png
132-
:alt: Pipeline visualisation
129+
pipe.draw("pipeline_full.html", hide_unused_outputs=False)
130+
131+
# To view the full visualization in a browser
132+
import webbrowser
133+
webbrowser.open("pipeline_full.html")
133134
134135
135136
************************

examples/customize/build_graph/pipeline/visualization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,5 @@ async def run(self, number: IntDataModel) -> IntDataModel:
5454
pipe.connect("times_two", "addition", {"a": "times_two.value"})
5555
pipe.connect("times_ten", "addition", {"b": "times_ten.value"})
5656
pipe.connect("addition", "save", {"number": "addition"})
57-
pipe.draw("graph.png")
58-
pipe.draw("graph_full.png", hide_unused_outputs=False)
57+
pipe.draw("graph.html")
58+
pipe.draw("graph_full.html", hide_unused_outputs=False)

neo4j-viz.README.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Graph Visualization for Python by Neo4j
2+
3+
[![Latest version](https://img.shields.io/pypi/v/neo4j-viz)](https://pypi.org/project/neo4j-viz/)
4+
[![PyPI downloads month](https://img.shields.io/pypi/dm/neo4j-viz)](https://pypi.org/project/neo4j-viz/)
5+
![Python versions](https://img.shields.io/pypi/pyversions/neo4j-viz)
6+
[![Documentation](https://img.shields.io/badge/Documentation-latest-blue)](https://neo4j.com/docs/nvl-python/preview/)
7+
[![Discord](https://img.shields.io/discord/787399249741479977?label=Chat&logo=discord)](https://discord.gg/neo4j)
8+
[![Community forum](https://img.shields.io/website?down_color=lightgrey&down_message=offline&label=Forums&logo=discourse&up_color=green&up_message=online&url=https%3A%2F%2Fcommunity.neo4j.com%2F)](https://community.neo4j.com)
9+
[![License](https://img.shields.io/pypi/l/neo4j-viz)](https://pypi.org/project/neo4j-viz/)
10+
11+
`neo4j-viz` is a Python package for creating interactive graph visualizations based on data from Neo4j products.
12+
13+
The output is of type `IPython.display.HTML` and can be viewed directly in a Jupyter Notebook, Streamlit.
14+
Alternatively, you can export the output to a file and view it in a web browser.
15+
16+
The package wraps the [Neo4j Visualization JavaScript library (NVL)](https://neo4j.com/docs/nvl/current/).
17+
18+
Proper documentation is forthcoming.
19+
20+
> [!WARNING]
21+
> This package is still in development and the API is subject to change.
22+
23+
![Example Graph](examples/example_cora_graph.png)
24+
25+
## Some notable features
26+
27+
- Easy to import graphs represented as:
28+
- projections in the Neo4j Graph Data Science (GDS) library
29+
- pandas DataFrames
30+
- Node features:
31+
- Sizing
32+
- Colors
33+
- Captions
34+
- Pinning
35+
- Relationship features:
36+
- Colors
37+
- Captions
38+
- Graph features:
39+
- Zooming
40+
- Panning
41+
- Moving nodes
42+
- Using different layouts
43+
- Additional convenience functionality for:
44+
- Resizing nodes, optionally including scale normalization
45+
- Coloring nodes based on a property
46+
- Toggle whether nodes should be pinned or not
47+
48+
Please note that this list is by no means exhaustive.
49+
50+
## Getting started
51+
52+
### Installation
53+
54+
Simply install with pip:
55+
56+
```sh
57+
pip install neo4j-viz
58+
```
59+
60+
### Basic usage
61+
62+
We will use a small toy graph representing the purchase history of a few people and products.
63+
64+
We start by instantiating the [Nodes](https://neo4j.com/docs/nvl-python/preview/api-reference/node.html) and
65+
[Relationships](https://neo4j.com/docs/nvl-python/preview/api-reference/relationship.html) we want in our graph.
66+
The only mandatory fields for a node are the "id", and "source" and "target" for a relationship.
67+
But the other fields can optionally be used to customize the appearance of the nodes and relationships in the
68+
visualization.
69+
70+
Lastly we create a
71+
[VisualizationGraph](https://neo4j.com/docs/nvl-python/preview/api-reference/visualization-graph.html) object with the
72+
nodes and relationships we created, and call its `render` method to display the graph.
73+
74+
```python
75+
from neo4j_viz import Node, Relationship, VisualizationGraph
76+
77+
nodes = [
78+
Node(id=0, size=10, caption="Person"),
79+
Node(id=1, size=10, caption="Product"),
80+
Node(id=2, size=20, caption="Product"),
81+
Node(id=3, size=10, caption="Person"),
82+
Node(id=4, size=10, caption="Product"),
83+
]
84+
relationships = [
85+
Relationship(
86+
source=0,
87+
target=1,
88+
caption="BUYS",
89+
),
90+
Relationship(
91+
source=0,
92+
target=2,
93+
caption="BUYS",
94+
),
95+
Relationship(
96+
source=3,
97+
target=2,
98+
caption="BUYS",
99+
),
100+
]
101+
102+
VG = VisualizationGraph(nodes=nodes, relationships=relationships)
103+
104+
VG.render()
105+
```
106+
107+
This will return a `IPython.display.HTML` object that can be rendered in a Jupyter Notebook or streamlit application.
108+
109+
### Examples
110+
111+
For some Jupyter Notebook and streamlit examples, checkout the [/examples](/examples) directory.
112+
113+
## Contributing
114+
115+
If you would like to contribute to this project, please follow our [Contributor Guidelines](./CONTRIBUTING.md).

0 commit comments

Comments
 (0)