Link Selection
by Roman Bruckner
HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.5.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.5.4/joint.js"></script>
</body>
</html>
JavaScript
var graph = new joint.dia.Graph({}, {
cellNamespace: joint.shapes
});
const paper = new joint.dia.Paper({
el: document.getElementById('paper'),
width: 800,
height: 900,
model: graph,
defaultConnectionPoint: { name: 'boundary' },
cellViewNamespace: joint.shapes
});
var el1 = new joint.shapes.standard.Circle({
position: {
x: 10,
y: 10
},
size: {
width: 50,
height: 50
},
attrs: {
label: {
text: 'A'
}
}
});
var el2 = new joint.shapes.standard.Rectangle({
position: {
x: 100,
y: 200
},
size: {
width: 50,
height: 50
},
attrs: {
label: {
text: 'B'
}
}
});
var el3 = new joint.shapes.standard.Path({
position: {
x: 300,
y: 100
},
size: {
width: 50,
height: 50
},
attrs: {
body: {
refD: 'M 1 0 2 1 1 2 0 1 z'
},
label: {
text: 'C'
}
}
});
var l1 = new joint.shapes.standard.Link({
source: { id: el1.id },
target: { id: el2.id },
router: { name: 'orthogonal' }
});
var l2 = new joint.shapes.standard.Link({
source: { id: el2.id },
target: { id: el3.id },
connector: { name: 'smooth' },
vertices: [{ x: 300, y: 300 }]
});
graph.addCells([el1, el2, el3, l1, l2]);
paper.on('blank:pointerdown', function(evt, x, y) {
const bbox = new g.Rect(x, y, 1, 1);
const rect = V('rect', {
'stroke': 'blue',
'fill': 'blue',
'fill-opacity': 0.1,
});
rect.attr(bbox.toJSON());
rect.appendTo(this.svg);
evt.data = {
rect,
ox: x,
oy: y,
bbox
};
});
paper.on('blank:pointermove', function(evt, x, y) {
const {
ox,
oy,
rect
} = evt.data;
const bbox = new g.Rect(ox, oy, x - ox, y - oy);
if (bbox.width === 0) bbox.width = 1;
if (bbox.height === 0) bbox.height = 1;
bbox.normalize();
rect.attr(bbox.toJSON());
evt.data.bbox = bbox;
});
var frames = [];
paper.on('blank:pointerup', function(evt) {
const {
rect,
bbox
} = evt.data;
rect.remove();
const...