GitHub Discussion #2028
https://github.com/clientIO/joint/discussions/2028
highighterSelector
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,
linkPinning: false,
defaultLink: () => new joint.shapes.standard.DoubleLink(),
// add `selector: []` which is the "no path" applied on the magnet
// i.e. disabling the smart magnet finding
defaultConnectionPoint: { name: 'boundary', args: { selector: [] } }
});
// Example
const el1 = new joint.shapes.standard.Rectangle({
position: {
x: 10,
y: 170
},
size: {
width: 100,
height: 90
}
});
const el2 = new joint.shapes.uml.Class({
position: {
x: 300,
y: 10
},
size: {
width: 100,
height: 90
}
});
const el3 = new joint.shapes.standard.Ellipse({
position: {
x: 300,
y: 325
},
size: {
width: 100,
height: 90
},
attrs: {
root: {
// explicitely set the magnet to the ellipse
// otherwise a gap will appear between the link and ellipse
// because the magnet will be the wrapping group
magnetSelector: 'body'
}
}
});
const l1 = new joint.shapes.standard.Link({
source: {
id: el1.id
},
target: {
id: el2.id
}
});
const l2 = new joint.shapes.standard.Link({
source: {
id: el1.id
},
target: {
id: el3.id
}
});
graph.resetCells([el1, el2, el3, l1, l2]);