Custom Selection Translation With Embedding

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

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,
    embeddingMode: true
});

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: 200,
        height: 200
    },
    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]);


var SelectionView = joint.mvc.View.extend({
    svgElement: true,
    tagName: 'g',
    className: 'selection',
    frames: null,
    options: {
        collection: null,
        paper: null,
    },
    init: function() {
        this.frames = {};
        this.mount();
        this.startListening();
    },
    mount: function() {
        const {
            paper
        } = this.options;
        paper.layers.appendChild(this.el);
    },
    startListening:...