Skip to main content
Version: 4.3

@joint/router-avoid

@joint/router-avoid routes JointJS links with libavoid, a C++ library for automatic, obstacle-avoiding orthogonal connector routing, compiled to WebAssembly via libavoid-js.

info

The avoid router is not a built-in router. There is no router: { name: 'avoid' } attribute to set on a link.

libavoid maintains a single incremental router shared by the whole graph: every element is an obstacle, every link is a connector, and moving an obstacle reroutes the connectors affected by it. The package wraps that engine in a RouterService which listens to a dia.Graph and writes each computed route straight onto the link's vertices and source/target anchors. Once a link is connected to two tracked elements, it is routed automatically.

The package exposes two functions - initAvoidRouter() and loadAvoidRouter() - plus the RouterService type they produce. RouterService is exported as a type only; instances are always created through initAvoidRouter().

import { initAvoidRouter } from '@joint/router-avoid';

const avoidRouter = await initAvoidRouter(graph, { shapeBufferDistance: 20 });
avoidRouter.start();

Loaded as a script tag rather than via ESM, the same functions live on joint.routers.avoid.

See the learn section for installation steps and examples.