Link Intersection (view vs model)
by Roman Bruckner
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.7.0/joint.css" />
</head>
<body>
<!-- content -->
<div id="paper"></div>
<!-- dependencies -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.4.0/backbone.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.7.0/joint.js"></script>
</body>
</html>
JavaScript
const graph = new joint.dia.Graph({}, {
cellNamespace: joint.shapes
});
const paper = new joint.dia.Paper({
el: document.getElementById('paper'),
width: 800,
height: 900,
model: graph,
cellViewNamespace: joint.shapes,
gridSize: 10,
async: true,
frozen: true,
sorting: joint.dia.Paper.sorting.APPROX,
linkPinning: false,
snapLinks: true
});
// Example
const json = {
cells: [
{
type: 'standard.Rectangle',
position: { x: 1350, y: 250 },
size: { width: 50, height: 20 },
angle: 0,
id: '72a4c4ec-9348-4a9a-94e4-7d1f35feea2f',
z: 1,
attrs: {
body: {
strokeWidth: 0,
stroke: '#31d0c6',
fill: 'transparent',
strokeDasharray: '0',
},
label: {
fontSize: 15,
fill: '#000000',
text: 'Tree',
fontFamily: 'Roboto Condensed',
fontWeight: 'Bold',
strokeWidth: 0,
},
root: {
dataTooltipPosition: 'left',
dataTooltipPositionSelector: '.joint-stencil',
},
},
},
{
type: 'standard.Rectangle',
position: { x: 1420, y: 390 },
size: { width: 50, height: 20 },
angle: 0,
id: 'a56cdb4d-b089-4f37-9a99-5ed4ca8b5ed5',
z: 2,
attrs: {
body: {
strokeWidth: 0,
stroke: '#31d0c6',
fill: 'transparent',
strokeDasharray: '0',
},
label: {
fontSize: 15,
fill: '#000000',
text: 'leaf',
fontFamily: 'Roboto Condensed',
fontWeight:...