Scale SVGMarker With the Link
Using `markerUnits` within the `targetMarker`
by Roman Bruckner
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.4.4/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.4.4/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,
async: true,
sorting: joint.dia.Paper.sorting.APPROX
});
const Link = joint.dia.Link.define('Link', {
attrs: {
line: {
connection: true,
fill: 'none',
targetMarker: {
'stroke-width': 1,
'markerUnits': 'strokeWidth', // the default is `userSpaceOnUse`
'd': 'M 1,-1 0,0 1,1 Z'
// fill: 'blue', if not defined, we use 'stroke' of the line`
// stroke: 'blue', if not defined, we use 'stroke' of the line`
}
},
}
}, {
markup: [{
tagName: 'path',
selector: 'wrapper',
}, {
tagName: 'path',
selector: 'line',
}]
});
const link1 = new Link({
attrs: {
line: {
stroke: 'red',
strokeWidth: 2
}
}
});
link1.source(new g.Point(50, 50));
link1.target(new g.Point(300, 50));
link1.addTo(graph);
const link2 = new Link({
attrs: {
line: {
stroke: 'blue',
strokeWidth: 4
}
}
});
link2.source(new g.Point(50, 150));
link2.target(new g.Point(300, 150));
link2.addTo(graph);
const link3 = new Link({
attrs: {
line: {
stroke: 'green',
strokeWidth: 6
}
}
});
link3.source(new g.Point(50, 250));
link3.target(new g.Point(300, 250));
link3.addTo(graph);