Skip to main content

Convert NetworkX graphs to interactive HTML visualizations

Project description

NetworkX HTML Viewer ๐ŸŽฏ

PyPI version License: MIT

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:

  1. ๐Ÿ”ต Click any node (colored circles) to see all its properties
  2. ๐Ÿ”— Click any edge (lines) to see connection details
  3. ๐Ÿ–ฑ๏ธ Drag nodes to rearrange the layout
  4. ๐Ÿ” Zoom with mouse wheel or trackpad
  5. ๐Ÿค Pan by dragging empty space
  6. ๐Ÿท๏ธ Toggle labels with the button
  7. ๐Ÿ”„ Reset view to recenter the graph
  8. ๐Ÿ”ฅ 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 graphs
  • nx.DiGraph() - Directed graphs
  • nx.MultiGraph() - Undirected multigraphs
  • nx.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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netx_vis-0.2.4.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netx_vis-0.2.4-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file netx_vis-0.2.4.tar.gz.

File metadata

  • Download URL: netx_vis-0.2.4.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for netx_vis-0.2.4.tar.gz
Algorithm Hash digest
SHA256 58810927b3e6a41d40d96f1e76d710418ca8906bf12db32495ae3cbfb98cc53d
MD5 552ee2b036eb5c697aeeabdc3fa1d967
BLAKE2b-256 bb4b9c40fedab9a5857b5cee986847532895531cdc2c2a4f76e90e807b7c0b14

See more details on using hashes here.

File details

Details for the file netx_vis-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: netx_vis-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for netx_vis-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2749e0e050be8dd28807c67e8565c9afdff1ad6c5dffe8b6346a3d08d7a799e6
MD5 5ac482339e8d9c7c1249458dd3eea5fd
BLAKE2b-256 672dc876ccb046d229831c454df211df3b2dbffe7df1bf0caa8348a7e944b975

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page