Visualization controls and export reference

Start with Explore graphs and reasoning offline for complete query/sample and standalone reasoning examples. This reference describes exact controls, caps, labels and export/state boundaries. Application-owned values in the API fragments are intentionally separate from the independently runnable static-SVG example.

Entry Points

Illustrative fragment (not standalone).

 1from gestaltdb.viz.api import VizOptions, visualize_nodes_edges, visualize_query, visualize_sample
 2
 3# Explicit collections.
 4figure = visualize_nodes_edges(nodes, edges)
 5
 6# Cypher matches (matched entities are highlighted in the canvas).
 7figure = visualize_query(graph, 'MATCH (a:Person) RETURN a LIMIT 25')
 8
 9# Typed sampling around seeds (the large-graph path).
10from gestaltdb.sampling import SamplingHop, SamplingPattern
11pattern = SamplingPattern([SamplingHop("binds", direction="out", sample_size=5)])
12figure = visualize_sample(graph, ["drug-1"], pattern)
13
14# ML training batches mapped back to external IDs.
15from gestaltdb.viz.api import visualize_sampler_batch
16figure = visualize_sampler_batch(batch, snapshot)

Reasoning Results

Proof trees and derivation graphs reuse the same offline viewer with no front-end rebuild. Every reasoning node carries a readable label property, so VizOptions(node_label_property="label", edge_labels="all") is the recommended setting for both HTML and static SVG:

Illustrative fragment (not standalone).

 1from gestaltdb.viz.api import (
 2    VizOptions,
 3    visualize_claim_explanation,
 4     visualize_inference_audit,
 5     visualize_inference_chain,
 6    visualize_ontology,
 7    visualize_proof_explanation,
 8    visualize_support_set,
 9)
10
11options = VizOptions(node_label_property="label", edge_labels="all")
12
13# Graph-rule derivation from historical claim versions.
14explanation = graph.rules.explain(derived.logical_id, valid_time=50)
15figure = visualize_claim_explanation(explanation, options=options)
16
17# Archived audit without a live database handle.
18from gestaltdb.inference import export_inference
19figure = visualize_inference_audit(export_inference(explanation), options=options)
20
21# Standalone Datalog proof witness as a fact tree
22# (``EvaluationResult.explain`` / ``ProofTrace.explain``).
23figure = visualize_proof_explanation(proof_explanation, options=options)
24
25# All alternative justifications for one typed fact, with the chosen
26# ``RankedWitness`` highlighted instead of hidden.
27figure = visualize_support_set(fact, supports, witness, options=options)
28
29# Ontology hierarchy: binary axioms become typed edges, property
30# chains and intersections become explicit axiom nodes.
31figure = visualize_ontology(ontology, options=options)
32
33# The whole inference chain: property graph + proof + ontology in one
34# figure, linked by exact ID equality only.
35figure = visualize_inference_chain(nodes, edges, explanation, ontology, options=options)

Shape Vocabulary and the Inference Chain

Reasoning figures use one shape vocabulary in static SVG, the viewer, and browser exports: circles mark the data layer (property-graph nodes, asserted claims, input facts), triangles mark inferred conclusions (derived claims and facts), and squares mark schema (rules, absence checks, axiom nodes, ontology terms). Stored, structural, and lookup edges are solid; inference steps that derive a conclusion are dotted (stroke-dasharray="6 4").

visualize_inference_chain(nodes, edges, explanation, ontology) composes all three layers into one figure: the property graph, one proof or claim explanation, and one ontology revision. With link_layers=True (the default), exact-equality cross-links join the layers without inventing mappings — a statement whose subject or object equals a graph node ID gains a solid mentions edge (the same convention as the current-graph projection, which uses node IDs as fact subjects and objects), and a statement whose predicate equals an ontology property term gains a solid typed_as edge. Pass link_layers=False to render the layers side by side. Each layer is capped independently, so sample the graph layer first for very large databases.

ClaimExplanation edges keep their stored derived_by (conclusion to rule), premise (rule to premise), and absent_premise direction, so arrows read as “depends on” from the highlighted root outward. Standalone proof witnesses collapse each derivation to premise to conclusion edges typed by rule ID, so arrows follow logical support toward the highlighted root. Support sets fan out from one conclusion to one node per alternative derivation. The builders accept the same caps/ceilings as the graph path and record their provenance in meta["builder"].

Reasoning figures render in a deterministic layered tree by default: static as_svg() uses layout="tree" unless overridden, and the interactive viewer opens these artifacts already arranged (and pinned) as a tree via the payload’s suggested_layout hint, with no force-simulation lottery. The Tree layout toolbar button re-applies the arrangement on demand, while Reset layout hands control back to the force-directed simulation. The layering is longest-path-free Kahn ordering (predecessor-free nodes on top, cyclic leftovers in trailing rows), shared by the Python renderer and the viewer so both agree. Pass an explicit layout="circle" to opt out.

Options (VizOptions) cover node/edge caps (defaults 2000/5000), absolute ceilings (default twice the caps, raising VizCapExceededError with sampling guidance), iframe height, light/dark theme, force-layout charge and link distance, artifact title, and label/property visibility. Any deterministic truncation warns with TruncationWarning and is bannered in the canvas with exact counts.

Readable Labels

node_label_property selects a property to display instead of the node ID; missing or null values fall back to the ID. edge_label_property selects an edge property, falling back to the relationship type (or edge ID for untyped edges). Reserved metadata such as score is also available as a label source. label_max_length limits displayed text (default 40 characters).

edge_labels accepts "off", "selected" (the default: selected, hovered, or keyboard-focused relationships), or "all". The viewer exposes this setting independently of node-label visibility. Parallel relationships, reciprocal relationships, and self-loops have distinct directed paths and independent selection targets.

Direct SVG Output

SVG generation from Python requires no browser, JavaScript runtime, or additional dependency. It uses a deterministic circle, grid, or layered tree layout, or supplied node coordinates. Coordinates must cover every displayed node and are uniformly scaled into the output viewport. Static labels render at 13px with node radii 8–32 (fallback 12) and edge widths 1–7 (fallback 2).

Standalone example. Install with python -m pip install "gestaltdb".

 1from tempfile import TemporaryDirectory
 2from pathlib import Path
 3from gestaltdb.graphdb import Edge, Node
 4from gestaltdb.viz.api import VizOptions, visualize_nodes_edges
 5
 6figure = visualize_nodes_edges(
 7    [Node(node_id="alice", properties={"name": "Alice"}),
 8     Node(node_id="bob", properties={"name": "Bob"})],
 9    [Edge(edge_id="e1", source="alice", target="bob",
10          properties={"type": "knows"})],
11    options=VizOptions(node_label_property="name", edge_labels="all"),
12)
13svg = figure.as_svg(width=1200, height=800, layout="circle")
14with TemporaryDirectory() as tmpdir:
15    figure.save_svg(Path(tmpdir) / "graph.svg", layout="grid", background=False)

as_svg() defaults to layout="circle" for graph figures and to the payload’s suggested layout for reasoning figures ("tree"); pass an explicit layout="circle"|"grid"|"tree" to override. save_svg() and as_svg() render the Python payload and options, not the current iframe’s force layout, selection, filters, or manually dragged positions. For static relationship labels, set edge_labels="all"; static output has no hover or selection state. positions={"alice": (0, 0), "bob": (1, 0)} can be passed to either method. save() continues to write interactive HTML. PNG output is available through the browser’s Export PNG control; direct Python PNG rasterization is not provided.

Attribute Styling

VizOptions supports node_size_property, node_color_property, edge_width_property, and edge_color_property in interactive and static SVG rendering. The browser also exposes these settings under Labels and attribute styling.

Numeric node radii map to 4–24 and edge widths to 0.5–6, based on the full payload’s finite numeric values. Missing and nonnumeric values (including booleans) use the defaults 7 and 1.2. Constant numeric values map to the midpoint. Color properties are categorical; missing values fall back to the native node group or relationship type. Labels and selection provide additional identity cues when palette colors repeat.

Illustrative fragment (not standalone).

1options = VizOptions(
2    node_label_property="name",
3    node_size_property="mass",
4    node_color_property="category",
5    edge_width_property="score",
6    edge_color_property="status",
7    edge_labels="all",
8)

Image Export and Saved Views

The Export and saved view panel offers current-viewport or all-visible-content SVG/PNG output, themed or transparent backgrounds, output width/height, and PNG scale 1–4. Width/height must be integers from 1 to 8192; PNG output is limited to 32 megapixels. SVG preserves aspect ratio, so differently shaped output dimensions may introduce padding. Exports preserve active styling and filters.

Save view state downloads a versioned JSON file containing positions, pins, zoom, viewer settings, selection, filters, and active simulation membership. Load view state accepts a local file for the same embedded graph topology and validates all fields before applying changes. No server or notebook kernel communication is required. Loading a paused view restores the arrangement exactly; loading an unpaused view resumes simulation from the saved positions. The imported pan/zoom survives automatic canvas resizing until an explicit Fit visible graph or Reset layout action chooses a new viewport. Download graph JSON remains a separate data export.

To reuse saved coordinates in Python, read the view JSON and pass its positions to save_svg; this does not apply the saved viewport, selection, or filters:

Illustrative fragment (not standalone).

1import json
2state = json.loads(Path("gestaltdb-view.json").read_text())
3positions = {node["id"]: (node["x"], node["y"])
4             for node in state["layout"]["nodes"]}
5figure.save_svg("arranged.svg", positions=positions)

Canvas Features

  • D3 force layout with drag-to-pin, double-click release, pan/zoom, refit, pause, and tunable charge/link distance. Labels render at 13px with node radii 8–32 and edge widths 1–7 (same scale as static SVG).

  • Deterministic tree arrangement: reasoning artifacts open pre-arranged (and pinned) in a layered top-down tree with the simulation paused; press Resume layout to run the force simulation. The Tree layout button re-applies the arrangement on demand and Reset layout returns to force. Releasing a pin eases the node into the live simulation instead of flinging it: arrange paths cool the simulation first and unpin paths reheat gently.

  • Dragging also works while paused; fit-visible includes displayed geometry and labels. The viewer refits when its container is resized.

  • Explicit pin/unpin actions and dashed pin indicators, full-layout reset, and visible-only relayout. Relayout-visible excludes hidden nodes/relationships from the simulation until another relayout or a saved view is loaded.

  • Deterministic colorblind-safe coloring by node group and edge type, with a count legend that doubles as a visibility filter.

  • Click/keyboard selection with a properties inspector, hover tooltips, search by id/label/property, incoming/outgoing/both neighborhood focus with 1–5 hops over enabled relationship types and node filters, and a highlight overlay for Cypher matches (toggleable).

  • Client-side export: SVG snapshot, PNG raster, and JSON payload download. SVG/PNG capture the selected image scope with resolved theme and label styling. JSON contains graph data, not exploration state; view state is a separate export. Everything runs locally inside the artifact, with export errors shown inline.

  • A keyboard-friendly visible-entity selector, collapsible inspector, and responsive controls for narrower notebook cells. Native-label filtering includes secondary labels, independently of primary-group filters.

Offline Guarantee

Artifacts are single self-contained .html files: the JS/CSS bundle and the JSON payload are inlined, there are no CDN or font requests, and the markup carries an inline-only Content Security Policy. Opening a saved file over file:// with networking disabled renders fully. Full runtime dependency license/notice texts are packaged and embedded in each HTML artifact; Download third-party notices saves them locally.

Large Graphs

Never dump a whole 100k-node database into the DOM: payloads beyond the absolute ceiling raise an actionable error pointing at visualize_sample() and LIMIT-bounded visualize_query(). Caps keep the first IDs in sorted order, so repeated builds are byte-identical and truncation counts are exact.

Library contributors can find bundle-build and offline browser-test instructions in the repository’s web guide. Application rendering uses the packaged bundle and does not require that toolchain.