GitHub Discussion #2209
https://github.com/clientIO/joint/discussions/2209
by Roman Bruckner
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.6.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.6.5/joint.js"></script>
</body>
</html>
JavaScript
const Link = joint.dia.Link.define('Link', {
attrs: {
line: {
connection: true,
stroke: 'white',
strokeWidth: 8,
strokeLinejoin: 'round',
},
outline: {
connection: true,
stroke: 'black',
strokeWidth: 12,
strokeLinejoin: 'round'
},
central: {
connection: true,
stroke: 'green',
strokeWidth: 4,
strokeLinejoin: 'round'
}
}
}, {
markup: [{
tagName: 'path',
selector: 'outline',
attributes: {
'fill': 'none'
}
}, {
tagName: 'path',
selector: 'line',
attributes: {
'fill': 'none'
}
}, {
tagName: 'path',
selector: 'central',
attributes: {
'fill': 'none'
}
}]
});
const cellNamespace = {
...joint.shapes,
Link
};
const graph = new joint.dia.Graph({}, {
cellNamespace
});
const paper = new joint.dia.Paper({
el: document.getElementById('paper'),
width: 800,
height: 900,
model: graph,
cellViewNamespace: cellNamespace,
gridSize: 10,
async: true,
sorting: joint.dia.Paper.sorting.APPROX,
linkPinning: false
});
// Example
const link = new Link({
source: { x: 50, y: 50 },
target: { x: 200, y: 50 }
});
link.addTo(graph);
paper.unfreeze();