JointJS Link Anchor
by Roman Bruckner
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.5.5/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.5.5/joint.js"></script>
</body>
</html>
CSS
.joint-paper {
display: inline-block;
border: 1px solid gray;
}
JavaScript
const graph = new joint.dia.Graph();
const paper = new joint.dia.Paper({
el: document.getElementById('paper'),
width: 800,
height: 800,
model: graph,
async: true,
interactive: { linkMove: false },
defaultAnchor: {
name: 'modelCenter'
},
defaultConnectionPoint: {
name: 'boundary',
},
defaultRouter: {
name: 'normal'
}
});
var el1 = new joint.shapes.standard.Rectangle({
position: { x: 100, y: 100 },
size: { width: 100, height: 100 }
});
var el2 = new joint.shapes.standard.Rectangle({
position: { x: 100, y: 230 },
size: { width: 100, height: 100 }
});
var el3 = new joint.shapes.standard.Rectangle({
position: { x: 100, y: 370 },
size: { width: 100, height: 100 }
});
var el4 = new joint.shapes.standard.Rectangle({
position: { x: 100, y: 500 },
size: { width: 100, height: 100 }
});
var link1 = new joint.shapes.standard.Link({
source: { id: el1.id },
target: { id: el4.id },
vertices: [{
x: 500, y: 250
}, {
x: 500, y: 450
}]
});
var link2 = new joint.shapes.standard.Link({
source: { id: el2.id },
target: { id: link1.id },
});
var link3 = new joint.shapes.standard.Link({
source: { id: el3.id },
target: { id: link1.id },
});
graph.resetCells([
el1, el2, el3, el4, link1, link2, link3
]);
link3.findView(paper).addTools(new joint.dia.ToolsView({
tools: [
new joint.linkTools.TargetAnchor()
]
}));