Skip to Content
React API

React API

Create editable data with useCausalDocument({ initialDataset, onChange? }) and pass document instead of dataset. useCausalDocumentState(document) subscribes to revisions and history availability. useCausal() adds edit, selection, query, view and dataset-JSON io; edit is null in legacy dataset mode. CausalEditor accepts a shared document and exposes api.edit and api.selection. See document commands for current contracts and limitations.

This reference covers the primary integration APIs in the current source workspace. The linked TypeScript source is the authority for additional exports.

import { … } from "@cytocausal/react"

Import @cytocausal/react/styles.css once. Current package peer dependency: React 19. Graph views require a browser and a sized container; keep the starter’s client-only loading boundary.

CausalWorkspace / CausalProvider

CausalWorkspace composes a graph and sidebar. It inherits provider props except children and className, then adds title, extra sidebar children, depthControl (false) and showDirections for debugging. CausalProvider shares state with your own child components and accepts className.

PropDefault and contract
dataset / documentExactly one; legacy dataset mode is read-only for commands
initialVersionFirst snapshot
initialSelected, initialLinkNo selection; link overrides nodes
maxSelectedInfinity
initialBaseline"previous"; "first" / snapshot id
shareInUrlWorkspace true; Provider false
layoutSaved positions if all nodes have them, otherwise automatic
layouts, initialLayoutNamed layouts replace layout; first name by default
themes, schemeDefault light/dark themes; system scheme unless set
labelsPartial<CausalLabels>
styleOptionsCausalStyleOptions
graphOptionsreadableLabels, focusZoom, maxDepth, defaultDepth
loopOptionsInitial maxLength 4, limit 1000 unless loopSettings supplied
loopSettings{ title, description, maxLength, limit }

Initial props seed state; they are not controlled values. Keep configuration objects stable across renders. shareInUrl reads and writes view state in the current address; turn it off for embedded examples. To switch an entire loaded dataset, remount with a new key.

useCausal

const { snapshot, version, setVersion, graph, exportImage } = useCausal();

Call inside CausalProvider. setVersion(id, { focus }) can preserve a focused node/link as versions change. graph exposes selection and navigation; exportImage() downloads the graph. Other state includes dataset, issues, scheme, theme, baseline, contributor filtering, showChanges and URL sharing. Consult the inferred CausalState type for the complete surface.

Composition components

ComponentPurpose
CausalGraphProvider-connected graph; radial menu and zoom controls
NodeSearch, SelectionPanelFind nodes; read selection details and paths
NodeDetails, LinkDetailsInspect nodes, links and evidence
VersionSwitcher, VersionTimeline, VersionDiffNavigate versions and inspect changes
ContributorFilterFilter attributed content
CyclePanel, LoopList, PathListCycle controls and route results
Legend, DepthControl, LayoutSwitcher, ZoomControlsGraph controls

Complete composition example · Component guide

GraphView / useCausalGraph

const graph = useCausalGraph(); <GraphView dataset={dataset} snapshotId="draft" onReady={graph.attach} />

GraphView requires dataset and snapshotId; it owns the Cytoscape instance lifecycle. onReady receives each new instance. useCausalGraph owns interaction state and can be used without a provider. Connect attach to onReady.

GraphView propDefault / type
layoutautoLayout; stable object
stylesheetcreateCausalStyle(lightTheme)
maxZoom2
animateSnapshots, animateLayoutsfalse
positionCacheRefObject<Record<string, Positions>>
anchorPositionsPositions
onLayoutComplete(positions: Positions) => void
renderTooltip, renderLinkTooltipCustom previews
tooltipDelay300 ms

Hook options: maxSelected defaults to unlimited, selectable to true, maxDepth to 2 and defaultDepth to 1. focusZoom is optional; without it focusing does not change zoom. Use the returned focus, selected, selectedLink, clear and route controls to wire your interface.

CompareView

<CompareView dataset={dataset} left="draft" right="reviewed" />

Requires both snapshot ids. Matches nodes with followNodes, aligns the right graph to the left and synchronises view movement by default (sync=true). format(id) labels the panes; onReady(cy, snapshotId) exposes instances. Also accepts shared layout, stylesheet, motion, maxZoom and positionCache props.

CausalProvider.tsx  · GraphView.tsx  · CompareView.tsx 

CausalEditor

A browser-only Author / Explore editor. Import @cytocausal/react/editor.css alongside shared styles. Give its host a height (for example 720px); desktop minimum height is 560px.

PropContract
initialDatasetRequired; validated and cloned once. At least one snapshot. Later prop changes are ignored.
onChange(dataset)Detached document after edits, undo or redo. No initial, selection-only, mode-only or snapshot-navigation notification. No persistence.
initialNodeStyle"text" (default) or "dot"; initial value only.
onNodeStyleChange(style)Appearance preference callback; not a document edit.
header(api), toolbar(api)Render host controls with the current CausalEditorApi.
footer, classNameOptional React content and editor surface class.
refReact 19 ref exposing CausalEditorApi.

The API exposes:

  • getDataset(): detached copy including authored positions.
  • replaceDataset(dataset): validate, cancel pending gestures and replace as one undoable edit. Emits onChange and selects the first snapshot.
  • replaceDataset(dataset, { resetHistory: true }): start a new session, clearing pending edits, selection, camera and history. Retains node style. No onChange notification: the host already owns the loaded data. Invalid input throws before replacement.
  • renameDataset(name): commit a trimmed, nonempty name.
  • undo(), redo(), canUndo, canRedo: document history available in Author mode. Up to 50 committed undo steps; a new edit clears redo.

Selection, camera and history belong to each mounted editor. Switching modes preserves selection and camera; temporary Explore positions are restored to authored positions on return. History is not persisted. Do not call replaceDataset for every onChange echo: update host state or save externally without resetting the session.

Last updated on