// JointJS Performance tips
// Overall goals
// -------------
// 1. reduce number of DOM elements (See async.html demo)
// 2. avoid asking the browser for element bounding boxes as much as possible
// Number of elements 0 - ?
var COUNT = 5000;
var RELATIONS = 1;
// Async rendering true/false
// true: does not block the UI
var ASYNC = true;
var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
el: document.getElementById('canvas'),
model: graph,
async: ASYNC,
frozen: true,
// Avoid using joint.dia.Paper.sorting.EXACT
// It's extremely slow for large amounts of elements.
// There is no big difference between sorting APPROX and NONE in terms of performance.
sorting: joint.dia.Paper.sorting.APPROX,
// To avoid measuring of the SVGElement magnet size, you can calculate
// the anchor point for the links manually.
/* defaultConnectionPoint: {
name: 'anchor'
},
*//* defaultAnchor: (view, _0, _1, _2, endType) => {
const bbox = view.model.getBBox();
return endType === 'source' ? bbox.bottomMiddle() : bbox.topMiddle();
}, */
defaultRouter: { name: 'orthogonal' }
});
var Shape = joint.shapes.standard.Rectangle;
var Link = joint.shapes.standard.Link;
var el = new Shape({ size: { width: 300, height: 200 }});
var l = new Link();
var cells = [];
var startTime = new Date();
function showResult() {
var duration = (new Date() - startTime) / 1000;
document.getElementById('perf').textContent = (COUNT + ' elements and ' + COUNT / 2 * RELATIONS + ' links rendered in ' + duration + 's');
}
// Prefer resetCells() over `addCells()` to add elements in bulk.
// SVG as oppose to HTML does not know `z-index` attribute.
// The "z" coordinate is determined by the order of the sibling elements. The JointJS
// paper makes sure the DOM elements are sorted based on the "z" stored on each element model.
/* graph.resetCells(cells, {
// sort: false // do not sort cells in the graph
});
paper.scale(0.2);
paper.fitToContent({...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.