JointJS Documentation
repository·master·Indexed 26 days ago
https://github.com/clientio/jointA professional-grade, SVG-based JavaScript/TypeScript library for creating complex interactive diagrams, including flowcharts, BPMN models, and AI workflow builders. The library is framework-agnostic with native support for React and includes the @joint/cli for managing examples, @joint/decorators for declarative shape definition, and a Model Context Protocol (MCP) server for AI coding agents.
What's inside JointJS
- @joint/react is a modern React wrapper for JointJS. It simplifies building interactive diagrams and graphs in React apps using idiomatic components, hooks, and utilities to manage nodes, links, and interactions.
Overview of JointJS
masterJointJS is a JavaScript/TypeScript diagramming library designed for building complex, production-scale diagramming applications. It is framework-agnostic but offers first-class, native support for React.
Common use cases include:
- Workflow & Process: Flowchart editors, BPMN modelers, and activity diagrams.
- AI Workflow Builders: Node-based AI pipeline and agent builders.
- Data Modeling: ER diagrams and database schema designers.
- Industrial/SCADA: P&ID diagrams and monitoring dashboards.
- Other domains: UML, Org charts, Energy networks, and Electronic design.
Install and use JointJS Directed Graph Layout
masterThe
joint-layout-directed-graphmodule provides automatic layout capabilities for directed graphs within JointJS.Prerequisites: This library requires JointJS (version >= 4.0). Ensure JointJS is installed and configured in your project before using this layout module.
Install and use JointJS General Shapes
masterJointJS General Shapes is a collection of general ECMAScript / TypeScript shapes designed for use with JointJS.
Prerequisites: This library requires JointJS version
3.5or higher. Ensure you have JointJS installed and configured before attempting to use these shapes.Integrate JointJS with React, Angular, Vue, or Svelte
masterJointJS is framework-agnostic. While it works with any frontend stack, specific integrations are available:
- React: Offers native components and hooks via 'JointJS for React'.
- Angular, Vue, Svelte, and Salesforce Lightning: Integration guides and examples are available in the official documentation.
Use the shared ESLint configuration
masterThe@joint/eslint-configpackage provides a shared ESLint configuration designed to be used across multiple JointJS projects to avoid repetitive configuration tasks.Setup the JointJS Eclipse Layout Kernel Graph Demo
masterTo run the Eclipse Layout Kernel (ELK) Graph demo, you must first build the core JointJS library from the repository root before setting up the demo directory.
- Build JointJS: From the repository root, install dependencies and build the project.
- Run the Demo: Navigate to the demo directory, install its specific dependencies, and start the development server.
Render HTML content in JointJS diagrams
masterSince JointJS is SVG-based, you have two ways to include HTML:
- SVG
<foreignObject>: Use this for simple HTML content inside the SVG. Warning: Avoid certain CSS properties likeposition(exceptstatic),transform, andtransitionto prevent rendering issues in Safari. - HTML Overlay: Use the experimental
useHTMLOverlayprop on thePapercomponent to render real HTML outside the SVG.
const renderElement = ({ width, height }) => ( <foreignObject width={width} height={height}> <div style={{ background: 'lightgray' }}> HTML Content here </div </foreignObject> ); <GraphProvider> <Paper renderElement={renderElement} /> </GraphProvider>- SVG
Get started with @joint/react
masterOverview
@joint/reactis a React-first API for building interactive diagrams powered by JointJS. It wraps JointJS concepts into idiomatic React components and hooks.Core Concepts
- Element (Node): A visual item in your diagram (e.g., a rectangle, circle, or custom shape).
- Link (Edge): A connection between two elements.
- Graph: The data model holding all elements and links.
- GraphProvider: React context provider for managing the graph state.
- Paper: The main rendering component for nodes and links.
- Ports: Named connection points on elements for precise linking.
- MeasuredNode: Utility for auto-sizing nodes based on their content.
Setup JointJS Mock SVG plugin in Vitest
masterUse
@joint/vitest-plugin-mock-svgto mock SVG methods that are not implemented in JSDOM. This is necessary when running JointJS tests in a Vitest environment that uses JSDOM. To use it, import the plugin and add it to thepluginsarray in yourvitest.config.jsfile.import { defineConfig } from 'vitest/config'; import mockSVG from '@joint/vitest-plugin-mock-svg' export default defineConfig({ plugins: [mockSVG()], })Implement hierarchical diagrams with Atomic and Coupled shapes
masterFor hierarchical diagrams, use
devs.Atomicanddevs.Coupledshapes. Both inherit fromdevs.Modelbut differ in size and color to allow for custom logic (e.g., allowing adevs.Coupledshape to embeddevs.Atomicshapes).Key methods for hierarchical workflows:
coupled.embed(atomic): Places anatomicshape inside thecoupledshape.coupled.fitToChildren(): Resizes thecoupledshape to visually contain all its embedded elements.link.reparent(): Finds the most appropriate parent for alinkbased on its source and target elements.
Set up the JointJS Custom Embedding Demo
masterTo run the Custom Embedding demo locally, you must first build the core JointJS library from the repository root before launching the demo.
- Navigate to the repository root and install dependencies and build the project:
yarn install yarn run build - Navigate to the
packages/joint-core/demo/custom-embedding/directory. - Open
index.htmlin your web browser to view the demo.
yarn install yarn run build # Then navigate to the demo directory and run: open index.html- Navigate to the repository root and install dependencies and build the project: