backend
D3.js backend for interactive web-based network visualization.
Template-driven HTML generation using D3.js library for rich interactive visualizations. Supports both static and temporal networks with embedded JavaScript, and CSS styling.
!!! abstract "Features": - Interactive HTML output with drag-and-drop node movement - Template-based architecture for extensibility - Both static and temporal network support - Jupyter notebook integration with inline display
D3jsBackend
¶
Bases: pathpyG.visualisations.plot_backend.PlotBackend
D3.js backend for interactive web visualization with template system.
Generates self-contained HTML files with embedded D3.js visualizations using modular template architecture. Supports both static and temporal networks with rich interactivity and web-standard compatibility.
Features
- Template-driven HTML generation (CSS + JavaScript + data)
- Multiple output modes: standalone HTML, Jupyter display, browser
- JSON data serialization with proper type conversion
Example
Template Architecture
Uses modular templates for extensibility:
styles.css: Visual styling and responsive designsetup.js: Environment detection and D3.js loadingnetwork.js: Core network visualization logicstatic.js/temporal.js: Plot-type specific functionality
Web Standards
Generates standards-compliant HTML5 with SVG graphics, compatible with all modern browsers without plugins.
Source code in src/pathpyG/visualisations/_d3js/backend.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
__init__
¶
Initialize D3.js backend with plot validation and configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plot
|
pathpyG.visualisations.pathpy_plot.PathPyPlot
|
PathPyPlot instance (NetworkPlot or TemporalNetworkPlot) |
required |
show_labels
|
bool
|
Whether to display node labels in visualization |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If plot type not supported by D3.js backend |
Supported Plot Types
- NetworkPlot: Static network visualization
- TemporalNetworkPlot: Animated temporal network evolution
Source code in src/pathpyG/visualisations/_d3js/backend.py
get_template
¶
Load and combine JavaScript templates for visualization.
Assembles modular JavaScript code by combining core network functionality with plot-type specific features. Enables clean separation of concerns and extensible template architecture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_dir
|
str
|
Directory containing JavaScript template files |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Combined JavaScript code for visualization |
Template Composition
Core Template (network.js): Base network visualization logic
Plot Templates: Type-specific functionality:
static.js: Force simulation and interaction for static networkstemporal.js: Timeline controls and animation for temporal networks
Extensibility
New plot types can be added by creating additional JavaScript templates following the established patterns.
Source code in src/pathpyG/visualisations/_d3js/backend.py
save
¶
Save interactive visualization as standalone HTML file.
Creates self-contained HTML file with embedded D3.js visualization, complete with styling, JavaScript, and data. File can be opened in any web browser or served from web servers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Output HTML file path |
required |
Deployment Ready
Generated HTML files are standalone and can be:
- Opened directly in browsers
- Served from web servers
- Embedded in websites or documentation
- Shared without additional dependencies
Source code in src/pathpyG/visualisations/_d3js/backend.py
show
¶
Display visualization in appropriate environment.
Automatically detects environment and displays visualization: - Jupyter notebooks: Inline HTML display with IPython widgets - Scripts/terminals: Opens temporary HTML file in system browser
Environment Detection
Uses pathpyG config to detect interactive environment and choose appropriate display method automatically.
Source code in src/pathpyG/visualisations/_d3js/backend.py
to_html
¶
Generate complete standalone HTML visualization.
Assembles full HTML document using template system with embedded CSS, JavaScript, and data. Creates unique DOM IDs to prevent conflicts when multiple visualizations exist on same page.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Complete HTML document with embedded visualization |
HTML Structure
- CSS Styles: Embedded styling
- DOM Container: Unique div element for visualization
- D3.js Library: CDN or local library loading
- Setup Code: Environment detection and module loading
- Data/Config: JSON-serialized network and configuration
- Visualization: Plot-specific JavaScript execution
Library Loading
Supports both CDN and local (default) D3.js library embedding
based on d3js_local configuration parameter.
Source code in src/pathpyG/visualisations/_d3js/backend.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
to_json
¶
Serialize network data and configuration to JSON strings.
Processes both data and configuration through preparation methods and converts to JSON format suitable for JavaScript consumption.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[str, str]
|
(data_json, config_json) string pair for template injection |
Template Integration
JSON strings are injected directly into JavaScript templates
as const data = {...} and const config = {...} declarations.