Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ node_modules
dist
coverage
**/*.d.ts
tests
tests
# Auto-generated bundle content (see scripts/generate-bundle-module.js)
src/standaloneBundleContent.ts
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none', varsIgnorePattern: '^_' }],
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-use-before-define': 'off',
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install -U codecov
yarn --version
yarn install

- name: Install package
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,13 @@ jobs:
with:
node-version: '18'

- name: Setup Yarn
run: |
corepack enable
corepack prepare yarn@4.6.0 --activate
echo 'nodeLinker: node-modules' > .yarnrc.yml

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m pip install -U codecov
yarn --version
yarn config set nodeLinker node-modules
YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install
yarn install

- name: Install package
run: |
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ net_vis/nbextension/index.*
# Packed lab extensions
net_vis/labextension

# Auto-generated bundle content for TypeScript
src/standaloneBundleContent.ts

VSCode

*.code-workspace
Expand Down
71 changes: 71 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,76 @@
# Changelog

## 0.6.0 (2025-12-25)

**Feature Release: Standalone HTML Export** (terapyon)

### New Features

- **HTML Export API**: Export visualizations as self-contained HTML files
- `Plotter.export_html()` method for saving graphs as standalone HTML
- Works offline without internet connection or JupyterLab
- Preserves all interactive features (zoom, pan, node selection, drag)

- **One-Click Download Button**: Download HTML directly from JupyterLab
- Download button appears in top-right corner of visualization
- Click to instantly save as `netvis_export_YYYY-MM-DD.html`
- Works independently of kernel state (client-side generation)
- No code required for quick exports

- **Export Customization**:
- Custom title and description for HTML documents
- Configurable container width (CSS values) and height (pixels)
- Default responsive layout (100% width x 600px height)

- **Flexible Output Options**:
- File export with automatic .html extension
- Automatic parent directory creation
- HTML string return for programmatic use
- Browser download trigger for remote environments (JupyterHub, Google Colab)

### API Examples

```python
from net_vis import Plotter
import networkx as nx

G = nx.karate_club_graph()
plotter = Plotter(title="Karate Club")
plotter.add_networkx(G)

# Export to file
path = plotter.export_html("my_graph.html")

# Export with customization
plotter.export_html(
"report.html",
title="Network Analysis",
description="Karate club social network",
width="800px",
height=700
)

# Get HTML string
html = plotter.export_html()

# Remote environment download
plotter.export_html("graph.html", download=True)
```

### Implementation Details

- **HTMLExporter**: Template-based HTML generation using string.Template
- **Standalone Bundle**: D3.js + rendering code bundled via webpack (~280KB)
- **Test Coverage**: 50 new tests (26 Python + 24 TypeScript) covering all export functionality
- **Error Handling**: Proper exception propagation for file system errors

### Compatibility

- All modern browsers (Chrome, Firefox, Safari, Edge)
- Offline capable (no CDN or internet dependency)
- JupyterLab: 3.x and 4.x
- Python: 3.10+

## 0.5.0 (2025-12-24)

**Major Feature Release: NetworkX Plotter API** (terapyon)
Expand Down
44 changes: 43 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

NetVis is a package for interactive visualization of Python NetworkX graphs within JupyterLab. It leverages D3.js for dynamic rendering and provides a high-level Plotter API for effortless network analysis.

**Version 0.5.0** introduces the NetworkX Plotter API, enabling direct visualization of NetworkX graph objects without manual JSON conversion.
**Version 0.6.0** adds standalone HTML export, enabling you to share visualizations as self-contained HTML files that work anywhere—no JupyterLab or internet connection required.

## Installation

Expand Down Expand Up @@ -69,6 +69,48 @@ plotter.add_networkx(
- **Styling**: Attribute-based or function-based color/label mapping
- **Automatic**: Node/edge attribute preservation in metadata

#### HTML Export (New in v0.6.0)

Export your visualizations as standalone HTML files:

```python
# Export to file
path = plotter.export_html("my_graph.html")
print(f"Exported to {path}")

# Export with customization
plotter.export_html(
"report.html",
title="Network Analysis Report",
description="Generated from NetworkX graph",
width="800px",
height=700
)

# Get HTML as string for embedding
html = plotter.export_html()
```

The exported HTML files:
- Work offline (no internet required)
- Include all interactive features (zoom, pan, node selection)
- Are self-contained (no external dependencies)
- Open in any modern browser

#### One-Click Download Button (New in v0.6.0)

When viewing a graph in JupyterLab, you'll see a download button in the top-right corner of the visualization. Click it to instantly download the graph as a standalone HTML file:

- **No code needed**: Just click the button
- **Works offline**: Button works even if the kernel is stopped
- **Auto-named**: Files are saved as `netvis_export_YYYY-MM-DD.html`

| Use Case | Method |
|----------|--------|
| Quick download | Click the download button |
| Custom filename | `plotter.export_html("my_name.html")` |
| Programmatic export | `html = plotter.export_html()` |

### Low-Level API (Advanced)

For manual control over the visualization data structure:
Expand Down
3 changes: 3 additions & 0 deletions docs/source/examples/html_export.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "../../../examples/html_export.ipynb"
}
29 changes: 28 additions & 1 deletion docs/source/examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This section contains examples of using NetVis for interactive graph visualizati
NetworkX Plotter API (Recommended)
-----------------------------------

**New in v0.5.0**: The easiest way to visualize NetworkX graphs::
The easiest way to visualize NetworkX graphs::

from net_vis import Plotter
import networkx as nx
Expand All @@ -21,6 +21,32 @@ NetworkX Plotter API (Recommended)
For comprehensive examples including custom styling, layouts, and multi-graph support, see the :ref:`NetworkX Plotter API notebook <networkx_plotter>` below.


HTML Export (New in v0.6.0)
---------------------------

Export visualizations as self-contained HTML files::

# Export to file
plotter.export_html("my_graph.html")

# Export with customization
plotter.export_html(
"report.html",
title="Network Analysis",
description="Generated from NetworkX graph",
width="800px",
height=700
)

# Get HTML as string
html = plotter.export_html()

# Browser download for remote environments
plotter.export_html("graph.html", download=True)

The exported HTML files work offline and include all interactive features. See the :ref:`HTML Export notebook <html_export>` for more examples.


Low-Level API
-------------

Expand Down Expand Up @@ -91,4 +117,5 @@ Detailed Examples
:maxdepth: 2

networkx_plotter
html_export
introduction
21 changes: 19 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Version: |release|

NetVis is a package for interactive visualization of Python NetworkX graphs within JupyterLab. It leverages D3.js for dynamic rendering and provides a high-level Plotter API for effortless network analysis.

**Version 0.5.0** introduces the NetworkX Plotter API, enabling direct visualization of NetworkX graph objects without manual JSON conversion.
**Version 0.6.0** adds standalone HTML export, enabling you to share visualizations as self-contained HTML files that work anywhere—no JupyterLab or internet connection required.


Quickstart
Expand All @@ -16,7 +16,7 @@ To get started with net_vis, install with pip::

pip install net_vis

**NetworkX Plotter API (New in v0.5.0)**::
**NetworkX Plotter API**::

from net_vis import Plotter
import networkx as nx
Expand All @@ -26,6 +26,23 @@ To get started with net_vis, install with pip::
plotter = Plotter(title="Karate Club Network")
plotter.add_networkx(G)

**HTML Export (New in v0.6.0)**::

# Export to standalone HTML file
plotter.export_html("my_graph.html")

# Export with customization
plotter.export_html(
"report.html",
title="Network Analysis",
description="Karate club social network"
)

# Get HTML as string for embedding
html = plotter.export_html()

**One-Click Download Button**: When viewing a graph in JupyterLab, click the download button (top-right corner) to instantly save the visualization as an HTML file.

**Note**: NetVis uses a MIME renderer that works automatically in JupyterLab 3.x and 4.x. Manual extension enabling is not required.


Expand Down
46 changes: 46 additions & 0 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ NetVis is a package for interactive visualization of Python NetworkX graphs with
Key Features
------------

- **Standalone HTML Export (v0.6.0)**: Export visualizations as self-contained HTML files that work offline
- **One-Click Download Button (v0.6.0)**: Download HTML directly from JupyterLab visualization with a single click
- **NetworkX Plotter API (v0.5.0)**: Direct visualization of NetworkX graphs without JSON conversion
- **Interactive D3.js Visualization**: Force-directed graph layout with interactive node dragging, zooming, and panning
- **Multiple Graph Types**: Support for Graph, DiGraph, MultiGraph, and MultiDiGraph
Expand Down Expand Up @@ -107,6 +109,50 @@ Version 0.5.0 introduces the **NetworkX Plotter API**, a high-level interface fo
See the :doc:`examples/index` for complete usage examples.


What's New in 0.6.0
-------------------

Version 0.6.0 introduces **Standalone HTML Export**, enabling you to share visualizations without JupyterLab:

**HTML Export API**
Export visualizations as self-contained HTML files::

# Export to file
plotter.export_html("my_graph.html")

# Export with customization
plotter.export_html(
"report.html",
title="Network Analysis Report",
description="Generated analysis results",
width="800px",
height=700
)

# Get HTML as string for embedding
html = plotter.export_html()

**One-Click Download Button**
When viewing a graph in JupyterLab, a download button appears in the top-right corner:

- Click the button to instantly download the visualization as HTML
- Files are automatically named ``netvis_export_YYYY-MM-DD.html``
- Works even when the kernel is stopped (client-side generation)
- No code required for quick exports

**Exported HTML Features**
- Works offline (no internet connection required)
- All JavaScript and CSS embedded inline
- Interactive features preserved (zoom, pan, node dragging)
- Opens in any modern browser (Chrome, Firefox, Safari, Edge)

**Remote Environment Support**
For JupyterHub, Google Colab, or Binder environments::

# Trigger browser download to local PC
plotter.export_html("graph.html", download=True)


Architecture (v0.4.0)
---------------------

Expand Down
Loading