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
โ”‚   โ””โ”€โ”€ examples/
โ”‚       โ””โ”€โ”€ demo.py              # Example usage
โ”œโ”€โ”€ 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.1.1.tar.gz (10.5 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.1.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: netx_vis-0.1.1.tar.gz
  • Upload date:
  • Size: 10.5 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.1.1.tar.gz
Algorithm Hash digest
SHA256 3245abfe9f5ec9fd325bd97597f2cea70ec113ddeb3add3192c6d7db2861db77
MD5 6b63ff859fab97ffdbf955b9e6f872d4
BLAKE2b-256 b340af1e3b78acec7812deab8f84a446d964f120530958ca61e484583a672ccc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: netx_vis-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.9 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2fc046b4e5dc94ed38fae37c94f15c282e57d2282ce3d28a91480286c8784071
MD5 211e4e26954c0b0fae2fdc6cca870c0e
BLAKE2b-256 330d2a265c2a653a6a681459d364b9d2a0d05d1a295f8c702b00a8e34fccbe8e

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