@reventlessdev/rescript-cytoscape
v1.0.0-alpha.1
Published
Cytoscape.js bindings for ReScript. The minimal surface (graph init, element builders, stylesheets, layouts, camera, events, graph algorithms, PNG export). Framework-agnostic — the Reventless AutoUI graph view mode lives in @reventlesslab/reventless-graph
Readme
@reventlessdev/rescript-cytoscape
ReScript bindings for Cytoscape.js — a narrow surface covering what a node-link view needs:
Cytoscape.CytoscapeBindings.make({container, elements, style, layout, …})— an instance rendering into a container element.- Element descriptors:
nodeElement({data: {id, label, parent}}),edgeElement({data: {id, source, target, label}})(parentis cytoscape's compound-node mechanism — clustering for free). - Stylesheets:
rule(~selector, [("background-color", "#333"), …]), applied at init or swapped wholesale withstyle(cy, sheet)(how a theme change lands). - Layouts:
layout(cy, {name: "dagre", rankDir: "BT"})->run. Built-in names aregrid/circle/concentric/breadthfirst/cose/preset; layereddagreand compound-awarefcoseare extensions and needuse(dagre)/use(fcose)once, first. - Camera:
fit(cy, padding),center,resize,zoom/setZoom,pan/setPan— cytoscape ships pan/zoom, nothing to build. - Events:
onSelector(cy, "tap", "node", e => Event.targetId(e)). - Algorithms:
dijkstra,aStar,neighborhood,components,degree. png(cy, {full: true})→ base64 data URI;destroy(cy)on unmount.
The package carries no Reventless and no React dependency — the AutoUI
graph view mode built on it lives in
@reventlesslab/reventless-graph.
Setup
pnpm add @reventlessdev/rescript-cytoscape cytoscape cytoscape-dagre cytoscape-fcoserescript.json:
"dependencies": ["@reventlessdev/rescript-cytoscape"]open Cytoscape.CytoscapeBindings
use(dagre) // once, before the first instance that asks for these layouts
use(fcose)Cytoscape draws to a canvas and needs no stylesheet import; the container element must have a non-zero height.
Building in this repo
pnpm run build here uses rescript-legacy: the ReScript v12 build
orchestrator still panics (UTF-8 underline bug) when invoked from a downstream
package that walks into reventless-ui's bs-dependencies. This package has no
dependencies, so build it first, then reventless-graph, then
reventless-ui last — building the downstream package walks into ui and
deletes its dev-source .res.mjs, which only a ui clean && build restores.
Never use -with-deps from a downstream package.
