stormvogel.html_generation

Javascript/HTML code generation functions, used by the JSVisualization. Depends on having vis-network-9.1.9-patched.js, and svgcanvas.js in the stormvogel folder.

Functions

generate_html(→ str)

Generate HTML that renders the network.

generate_dark_mode_js(→ str)

Generate JS code that reads CSS custom properties and applies them to the vis.js network.

generate_init_js(→ str)

Generate JS code that initializes a NetworkWrapper object, and store it in nw_{name}.

generate_network_wrapper_js(→ str)

Generate JS code that defines the NetworkWrapper class.

Module Contents

stormvogel.html_generation.generate_html(nodes_js: str, edges_js: str, options_js: str, name: str, height: int | str) str

Generate HTML that renders the network.

Two scripts are generated:
  1. One that defines the NetworkWrapper class.

  2. One that initializes a NetworkWrapper object with the specified nodes, edges, and options. This NetworkWrapper object is stored as a global variable nw_{name}. nw_{name}.network is the vis.js network.

Parameters:
  • nodes_js – JS code that generates the nodes DataSet.

  • edges_js – JS code that generates the edges DataSet.

  • options_js – JS code that generates the options object.

  • name – The name of the network. Used to create a unique variable name.

  • height – Height of the network div. Either an integer (pixels) or a CSS string like "100%".

Returns:

An HTML string that renders the network.

stormvogel.html_generation.generate_dark_mode_js(name: str) str

Generate JS code that reads CSS custom properties and applies them to the vis.js network.

vis.js renders on a canvas so colors cannot be set via CSS alone; this reads the CSS custom properties (which handle light/dark via media queries) and forwards them to vis.js via network.setOptions().

Parameters:

name – The name of the NetworkWrapper variable (nw_{name}).

Returns:

A JS code string that syncs vis.js colors with the CSS custom properties.

stormvogel.html_generation.generate_init_js(nodes_js: str, edges_js: str, options_js: str, name: str) str

Generate JS code that initializes a NetworkWrapper object, and store it in nw_{name}.

Parameters:
  • nodes_js – JS code that generates the nodes DataSet.

  • edges_js – JS code that generates the edges DataSet.

  • options_js – JS code that generates the options object.

  • name – The name of the network. Used to create a unique variable name.

Returns:

A JS code string that initializes a NetworkWrapper object.

stormvogel.html_generation.generate_network_wrapper_js() str

Generate JS code that defines the NetworkWrapper class.

Returns:

A JS code string defining the NetworkWrapper class.