JointJS+ changelog v4.2.0
Overview
Version 4.2 brings 7 new applications, improved layout-driven editing, a powerful Layers API, and major performance improvements for large diagrams.
Guided layout-driven diagram editing
This release focuses on structured, guided diagram editing, with automatic node placement rather than free drag-and-drop.
In such applications, the underlying data model is often simpler than the visual representation. To address this, we introduce a pattern where the data model serves as the single source of truth, and the diagram graph is automatically generated from it (see diagram below).
This approach is especially useful when a single data change triggers multiple visual updates, such as rearranging elements via automatic layout or updating node styles (e.g. marking a task as at risk
after changing due date). It lets you keep your data model minimal while the graph handles the visual representation.
For seamless integration, we:
-
Updated our CommandManager and Inspector to work smoothly with any mvc.Model (our data model).
-
Added graph.syncCells() to efficiently update diagrams from JSON.
-
Focused on automatic layouts - the alpha and omega of structured diagram editing:
- Introduced a layout adapter for Microsoft Automatic Graph Layout (MSAGL) with support for orthogonal/parallel links.
- DirectedGraph now supports the disableOptimalOrderHeuristic option to preserve sibling order during layout.
- Added a new ELKJS example that makes it easier to layout an existing diagram, setting the stage for a future adapter package.
Three of the seven new applications introduced in this release leverage this pattern (AI Agent Builder, Fishbone, PERT Chart).
The example below demonstrates how this works: you can connect elements, remove elements and links, and create new elements by clicking a node.
Implementation details...
The core of this implementation is the DiagramData model, which holds a minimal representation of the diagram in a JSON-like structure. It captures only the essential information about nodes and their relationships, without any visual details.
The buildGraph() function is responsible for translating the DiagramData model into a full-fledged dia.Graph. It creates elements and links based on the data, applies automatic layout using DirectedGraph.layout(), and adds the cells to the graph.
User interactions (like connecting nodes, removing elements, or adding new nodes) update the DiagramData model. For example:
- When a user connects two nodes, the
toarray of the source node inDiagramDatais updated to include the target node's ID. - When a user removes an element, the corresponding entry is deleted from
DiagramData. - When a user adds a new node, a new entry is created in
DiagramDatawith default properties.
The CommandManager listens to changes in the DiagramData model and records them as commands, enabling undo/redo functionality for all user actions that modify the diagram data.
If you check example.json, you will see that only essential information is stored:
{
"start": {
"label": "New support ticket",
"to": [{ "id": "ai-agent" }]
},
"ai-agent": {
"to": [
{ "label": "Solved", "id": "action-1" },
{ "label": "Needs human support", "id": "action-3" }
],
"label": "Customer support AI agent"
},
"action-1": {
"to": [{ "id": "action-2" }],
"label": "Update Ticket"
},
"action-2": {
"to": [],
"label": "Send to Slack"
},
"action-3": {
"to": [{ "id": "decision-1" }],
"label": "Create Issue"
},
"decision-1": {
"to": [
{ "label": "Low priority", "id": "action-4" },
{ "label": "High priority", "id": "action-5" }
],
"label": "Check priority"
},
"action-4": {
"to": [],
"label": "Send to Slack"
},
"action-5": {
"to": [],
"label": "Send SMS"
}
}
Layers API
In version 4.2, we've also made significant changes to the core of the library. The Graph has been refactored, as the new Layers API required a rethink of the existing architecture. The graph now has a collection of layers, with each layer maintaining its own attributes and a collection of cells, each within the layer's own stacking context for z-index ordering. Events bubble up from the cell, through layers, to the graph, all in a backwards-compatible manner.
Applications can now enable layer support, allowing users to add/remove layers, toggle visibility, and control interactivity. This is the straightforward use case, but layers also unlock additional possibilities:
- Treat layers as groups of cells with their own stacking context. This allows grouping a container and its cells into a layer, ensuring that children always follow the container when its z-index changes, without interference from other elements.
- On the view side, cells within a layer are now children of a dedicated
<g/>element. You can apply CSS variables, filters, or clip-paths to individual layers, and animate collapse/expansion of containers (see experimental example).
Here is an example of the new layers API in action:
Optimized rendering and memory management
The Paper has been tuned to optimize memory usage by lazy-loading views and disposing of those no longer needed (e.g. out-of-viewport, collapsed branches).
On top of that, we improved:
- Enhanced autoFreeze mechanism to reduce CPU usage on empty render loops.
- Add built-in virtual rendering support, leveraging the SearchGraph to quickly find and display only views currently in the viewport.
- Support offscreen rendering avoiding unnecessary reflows and DOM measurements.
These changes lay the groundwork for HTMLCanvas rendering, improving performance when displaying large diagrams where all nodes must be shown at once (e.g. bird's-eye view, minimap). See experimental example (when you zoom out enough, the rendering switches to canvas).
We made other improvements and bug fixes across the library. See details below!