GitHub Discussion #2123
https://github.com/clientIO/joint/discussions/2123
by Roman Bruckner
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.6.2/joint.css" />
</head>
<body>
<!-- content -->
<div id="paper"></div>
<!-- dependencies -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.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.2/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,
sorting: joint.dia.Paper.sorting.APPROX,
});
// Example
const Link = joint.dia.Link.define('Link', {
attrs: {
root: {
cursor: 'pointer'
},
line: {
connection: true,
stroke: '#333333',
strokeWidth: 2,
strokeLinejoin: 'round',
},
wrapper: {
connection: true,
strokeWidth: 10,
strokeLinejoin: 'round'
},
targetArrowhead: {
atConnectionRatio: 1,
d: 'M -20 -20 2 0 -20 20 z',
stroke: '#333',
fill: '#fff',
strokeWidth: 2
}
}
}, {
markup: joint.util.svg`
<path @selector="wrapper" fill="none" stroke="transparent" stroke-linecap="round"/>
<path @selector="line" fill="none"/>
<path @selector="targetArrowhead"/>
`
});
const l1 = new Link({
source: {
x: 100, y: 100
},
target: {
x: 300, y: 200
}
});
graph.resetCells([l1]);
paper.on('link:pointerdown', function(linkView, evt) {
console.log('arrowhead clicked');
});