Convert NetworkX graphs to interactive HTML visualizations
Project description
NetworkX HTML Viewer ๐ฏ
Convert your NetworkX graphs into beautiful, interactive HTML visualizations with just one line of code!
โจ Click any node or edge to see all its properties in a sidebar - perfect for exploring complex networks with rich metadata.
๐ Features
- ๐ฏ Interactive Property Viewing: Click nodes/edges to see all their attributes
- ๐จ Beautiful UI: Modern, professional interface with sidebar property panel
- ๐ Zoom & Pan: Explore large graphs with smooth zoom and pan controls
- ๐ฎ Drag Nodes: Rearrange graph layout by dragging nodes
- ๐ท๏ธ Toggle Labels: Show/hide node labels as needed
- ๐ Graph Statistics: Display node count, edge count, and graph type
- ๐จ Force-Directed Layout: Automatic layout using D3.js physics simulation
- ๐พ Export Ready: Generates standalone HTML files
- ๐ง Highly Customizable: Adjust dimensions, styling, and behavior
๐ฆ Installation
pip install netx-vis
๐ฎ Quick Start
import networkx as nx
from networkx_html_viewer import convert_networkx_to_html
# Create a sample graph with properties
G = nx.Graph()
G.add_node("A", label="Node A", type="central", value=100, category="important")
G.add_node("B", label="Node B", type="peripheral", value=50, category="normal")
G.add_edge("A", "B", weight=0.8, relation="strong", type="primary")
# Convert to interactive HTML - that's it! ๐
html_file = convert_networkx_to_html(
graph=G,
output_file="my_network.html",
title="My Amazing Network",
width=1200,
height=800
)
print(f"Interactive graph saved to: {html_file}")
# Open the HTML file in your browser and start exploring!
๐ฏ Interactive Features
Once you open the HTML file in your browser:
- ๐ต Click any node (colored circles) to see all its properties
- ๐ Click any edge (lines) to see connection details
- ๐ฑ๏ธ Drag nodes to rearrange the layout
- ๐ Zoom with mouse wheel or trackpad
- ๐ค Pan by dragging empty space
- ๐ท๏ธ Toggle labels with the button
- ๐ Reset view to recenter the graph
- ๐ฅ Reheat simulation to restart the physics
๐ง Advanced Usage
Using the Class Interface
from networkx_html_viewer import NetworkXHTMLConverter
# Create converter with custom dimensions
converter = NetworkXHTMLConverter(width=1600, height=1000)
# Convert graph
html_file = converter.convert(
G,
output_file="advanced_graph.html",
title="Advanced Network Analysis"
)
# Or get HTML content as string (for embedding in web apps)
html_content = converter.preview(G, title="Preview Graph")
Working with Complex Graphs
import networkx as nx
# Create a more complex graph
G = nx.karate_club_graph()
# Add custom properties to nodes
for node in G.nodes():
G.nodes[node]['club'] = G.nodes[node].get('club', 'unknown')
G.nodes[node]['degree'] = G.degree(node)
G.nodes[node]['betweenness'] = nx.betweenness_centrality(G)[node]
# Add properties to edges
for edge in G.edges():
G.edges[edge]['weight'] = G.edges[edge].get('weight', 1.0)
G.edges[edge]['edge_betweenness'] = nx.edge_betweenness_centrality(G)[edge]
# Add graph-level properties
G.graph['name'] = 'Karate Club Network'
G.graph['description'] = 'Social network of a university karate club'
G.graph['nodes'] = G.number_of_nodes()
G.graph['edges'] = G.number_of_edges()
# Convert to HTML
convert_networkx_to_html(G, "karate_club.html", "Karate Club Social Network")
Supported Graph Types
All NetworkX graph types are supported:
nx.Graph()- Undirected graphsnx.DiGraph()- Directed graphsnx.MultiGraph()- Undirected multigraphsnx.MultiDiGraph()- Directed multigraphs
๐จ Customization Options
# Customize dimensions and output
converter = NetworkXHTMLConverter(
width=1920, # Canvas width in pixels
height=1080 # Canvas height in pixels
)
# The HTML template automatically adapts to your graph:
# - Node sizes scale with number of properties
# - Edge thickness reflects property count
# - Colors are automatically assigned
# - Layout adjusts to graph structure
๐ What Properties Are Displayed?
The viewer shows ALL properties from your NetworkX graph:
- Node Properties: Any attributes you add to nodes
- Edge Properties: Any attributes you add to edges
- Graph Properties: Graph-level metadata
- Computed Properties: Centrality measures, clustering coefficients, etc.
Example of rich property data:
# Nodes can have any properties
G.add_node("user123",
name="Alice Johnson",
age=29,
location="San Francisco",
followers=1250,
verified=True,
interests=["AI", "Python", "Networks"]
)
# Edges can have any properties
G.add_edge("user123", "user456",
relationship="friend",
strength=0.8,
since="2019-03-15",
interactions=247,
platforms=["twitter", "linkedin"]
)
# All of this will be displayed when you click!
๐ ๏ธ Development Setup
# Clone repository
git clone https://github.com/olsihoxha/netx-vis.git
cd netx-vis
# Install in development mode
pip install -e .
# Install development dependencies
pip install pytest black flake8 mypy
# Run tests
pytest tests/
# Format code
black networkx_html_viewer/
๐ Package Structure
netx-vis/
โโโ networkx_html_viewer/
โ โโโ __init__.py # Package initialization
โ โโโ converter.py # Main converter class
โ โโโ templates/
โ โโโ graph_template.html # HTML template with D3.js
โโโ tests/
โ โโโ test_converter.py # Unit tests
โโโ setup.py # Package configuration
โโโ requirements.txt # Dependencies
โโโ README.md # This file
โโโ LICENSE # MIT License
โโโ MANIFEST.in # Package data files
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with D3.js for interactive visualizations
- Inspired by the NetworkX community
- Thanks to all contributors and users!
Made with โค๏ธ for the NetworkX community
Convert your graphs. Explore your data. Share your insights. ๐ฏ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file netx_vis-0.1.2.tar.gz.
File metadata
- Download URL: netx_vis-0.1.2.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
edbe0d956a2b070dd363c3fc6715cd54792bb564a316d2dd182b43b2bf529fd0
|
|
| MD5 |
3e20d0013b0182483a13be20f2869451
|
|
| BLAKE2b-256 |
db632eb90ce90bcba831db7e8653dd830ab57f5a0c49060bb301d43719ee834e
|
File details
Details for the file netx_vis-0.1.2-py3-none-any.whl.
File metadata
- Download URL: netx_vis-0.1.2-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
33671962fb53547da49083fc3403aef622af7c452caa7dfba93fe1b240880aba
|
|
| MD5 |
35f96b57845fb820c5ea2dbf3e402505
|
|
| BLAKE2b-256 |
7c08ea81ebcca912f84ab1c0b69b80773323fa4e26aa1877f083c1b93f84763b
|