Skip to content

Web Component API Reference ​

Complete API reference for the <graphty-element> Web Component.

Overview ​

The Graphty class is a Lit-based Web Component that provides declarative graph visualization through HTML attributes and element properties.

TIP

For usage patterns and examples, see the Web Component Guide.

Properties ​

The Web Component exposes these properties for declarative configuration:

Data Properties ​

PropertyAttributeTypeDescription
nodeDatanode-dataArray<object>Array of node objects
edgeDataedge-dataArray<object>Array of edge objects
nodeIdPathnode-id-pathstringJMESPath to node ID (default: "id")
edgeSrcIdPathedge-src-id-pathstringJMESPath to the edge source ID. Unset by default, which means the element looks for source, then src, then from
edgeDstIdPathedge-dst-id-pathstringJMESPath to the edge target ID. Unset by default; see above
edgeIdPathedge-id-pathstringJMESPath to an edge's own identifier, for data that carries one. Unset by default, which means a repeat is decided by its ordered endpoint pair alone. It does not name the edge -- Edge.id is always the element's counter
repeatedEdgesrepeated-edgesDuplicatePolicyWhat a second edge record naming a pair the graph already holds does: keep (default, a second edge), first, last, sum, min, max, or error

Layout Properties ​

PropertyAttributeTypeDescription
layoutlayoutstringLayout algorithm name
layoutConfiglayout-configobjectLayout algorithm options

Display Properties ​

PropertyAttributeTypeDescription
viewModeview-mode'2d' | '3d' | 'vr' | 'ar'Rendering mode
backgroundbackgroundGraphBackgroundConfigA flat colour, or a skybox image
startingCameraDistancestarting-camera-distancenumberHow far the camera starts out. Unset (the default) frames the graph to fit; set, it places the camera and turns automatic framing off
autoFrameauto-framebooleanFrame the graph after each load and layout change. On by default; auto-frame="false" leaves the camera where it is. zoomToFit() frames either way
zoomToPointerzoom-to-pointerbooleanThe mouse wheel zooms toward the point under the pointer. Off by default (toward the view's center); a view preference, not saved in a project
labelDeclutterlabel-declutterbooleanHide a node label that would overlap another until the reader zooms in. Off by default; a view preference, not saved in a project
renderOnDemandrender-on-demandbooleanDraw a frame only when the picture can have changed; a still graph is not redrawn. Off by default; a view preference, not saved in a project
lightinglightingLightingHow 3D nodes are lit: "studio" (default), "headlight", "matte" or "flat". Switchable at runtime; a view preference, not saved in a project

What nodes and edges look like is not a property: it is the layer stack on element.session.styles. See the styling guide.

Acceleration Properties ​

PropertyAttributeTypeDescription
accelerationacceleration'auto' | 'off' | 'required'Whether to use a hardware accelerator; required refuses the CPU path
accelerationMinNodesacceleration-min-nodesnumberNode count at or above which accelerated work uses the accelerator; unset, layouts use it from 0 and traversals from a measured floor

Where the work actually ran is element.session.capabilities.acceleration, and every transition of it is mirrored as a graphty-capabilities-change DOM event. See the acceleration guide.

Data Source Properties ​

PropertyAttributeTypeDescription
dataSourcedata-sourcestringData source type
dataSourceConfigdata-source-configobjectData source configuration

XR Properties ​

PropertyAttributeTypeDescription
xr-XRConfigVR/AR configuration

Debug Properties ​

PropertyAttributeTypeDescription
enableDetailedProfilingenable-detailed-profilingbooleanEnable performance profiling
runAlgorithmsOnLoadrun-algorithms-on-loadbooleanRun the algorithmsOnLoad list once data loads; on by presence
algorithmsOnLoad(property only)Array<string | AlgorithmOnLoad>Algorithms to run once data loads: names, or { algorithm, params?, style?, seed?, as? }

Methods ​

The Web Component provides these methods for imperative control:

View Mode ​

MethodParametersReturnsDescription
getViewMode()-ViewModeGet current view mode
setViewMode(mode)mode: ViewModePromise<void>Set view mode
isVRSupported()-Promise<boolean>Check VR availability
isARSupported()-Promise<boolean>Check AR availability

Screenshot & Video ​

MethodParametersReturnsDescription
captureScreenshot(options?)ScreenshotOptionsPromise<ScreenshotResult>Capture screenshot
canCaptureScreenshot(options?)ScreenshotOptionsPromise<CapabilityCheck>Check screenshot support
captureAnimation(options)AnimationOptionsPromise<AnimationResult>Capture video
cancelAnimationCapture()-booleanCancel ongoing capture
isAnimationCapturing()-booleanCheck if capturing
estimateAnimationCapture(options)AnimationOptionsPromise<CaptureEstimate>Estimate capture

Camera Control ​

MethodParametersReturnsDescription
getCameraState()-CameraStateGet camera state
setCameraState(state, options?)CameraState, CameraAnimationOptionsPromise<void>Set camera state
setCameraPosition(pos, options?){x, y, z}, CameraAnimationOptionsPromise<void>Set camera position (3D)
setCameraTarget(target, options?){x, y, z}, CameraAnimationOptionsPromise<void>Set camera target (3D)
setCameraZoom(zoom, options?)number, CameraAnimationOptionsPromise<void>Set zoom (2D)
setCameraPan(pan, options?){x, y}, CameraAnimationOptionsPromise<void>Set pan (2D)
resetCamera(options?)CameraAnimationOptionsPromise<void>Reset to default
zoomStep(direction, options?)"in" | "out", CameraAnimationOptionsPromise<void>One zoom step (2D and 3D)
zoomToNodes(ids, options?)string | number | (string | number)[], CameraAnimationOptionsPromise<void>Frame these nodes (2D and 3D)
zoomToSelection(options?)CameraAnimationOptionsPromise<void>Look at the selected nodes

Camera Presets ​

MethodParametersReturnsDescription
saveCameraPreset(name)stringvoidSave current state as preset
loadCameraPreset(name, options?)string, CameraAnimationOptionsPromise<void>Load preset
getCameraPresets()-Record<string, CameraState>Get all presets
exportCameraPresets()-Record<string, CameraState>Export user presets as JSON
importCameraPresets(presets)Record<string, CameraState>voidImport presets from JSON

Export ​

MethodParametersReturnsDescription
exportGraph(format, options?)FormatId, ExportGraphOptionsPromise<ExportResult>Write the graph in a format with canExport: true; the result holds the loss notes, text() and bytes
downloadGraph(format, options?)FormatId, ExportGraphOptions & { fileName? }Promise<ExportResult>Export and download the file as <project name><extension>; "graphty" downloads a project copy and never changes project.dirty

Graph Access ​

PropertyTypeDescription
graphGraphAccess the underlying Graph instance

Events ​

The Web Component emits standard DOM events:

typescript
element.addEventListener("graph-settled", (e) => {
    console.log("Layout complete");
});

element.addEventListener("node-click", (e) => {
    console.log("Clicked:", e.detail.node.id);
});

See the Events Guide for the complete event reference.

Generated Reference ​

For complete type definitions and detailed API documentation:

  • Graphty Class - Full TypeDoc reference. Graphty is the class of the <graphty-element> element, and what document.querySelector returns.