NetiPlot

Vanilla JS Class

NetiPlot is a framework-agnostic class that manages its own DOM structure. Use it in any environment without React.

Basic usage

import { NetiPlot } from '@jonmodell/netiplot/vanilla'

const container = document.getElementById('network')

const net = new NetiPlot(container, {
  graph: {
    nodes: [
      { id: 'a', label: 'Alpha' },
      { id: 'b', label: 'Beta' },
    ],
    edges: [{ id: 'e1', from: 'a', to: 'b' }],
  },
  options: {
    nodes: { showLabels: true },
    edges: { arrowheads: true },
  },
})

The container must have an explicit width and height. position: relative is set automatically if not already applied.

Instance methods

MethodDescription
setGraph(graph, shapes?)Replace graph data. Triggers layout if nodes/edges changed.
setOptions(options)Update options.
zoom(level)'in' | 'out' | 'all' | 'selection'
fit()Zoom to fit all nodes.
getCamera()Returns current PanScaleState.
getNodePositions()Returns Record<id, { x, y }>.
destroy()Removes all DOM elements and cleans up event listeners.

Hover tooltips

The vanilla class uses a callback-based hover API (no React):

const net = new NetiPlot(container, {
  graph,
  hover: {
    nodeRenderer: (node) => `<strong>${node.label}</strong>`,  // HTML string or HTMLElement
    edgeRenderer: (edge) => `Edge: ${edge.id}`,
    delay: 500,
  },
})

The tooltip div has class netiplot-tooltip — style it however you like.

Constructor config

FieldTypeDescription
graphNetiPlotGraphRequired. Nodes and edges.
optionsNetiPlotOptionsDisplay and behaviour options.
shapesNetiPlotShapeDefinition[]Background shapes.
layouterNetiPlotLayouterCustom layout algorithm.
shouldRunLayouterShouldRunLayouterPredicate for layout re-runs.
onMouseNetiPlotMouseHandlerMouse event callback.
nodeDrawingFunctionNodeDrawingFunctionCustom canvas draw per node.
shapeDrawingFunctionShapeDrawingFunctionCustom canvas draw per shape.
imagesNetiPlotImageMapImage map for node icons.
identifierstringStable instance ID.
hoverNetiPlotHoverConfigTooltip configuration.