JointJS - Absolute Port Position

by Roman Bruckner

HTML

<html>
<head>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jointjs/3.5.5/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.5/joint.js"></script>
    
    </body>
</html>

CSS

.joint-paper {
  display: inline-block;
  border: 1px solid gray;
}

JavaScript

const shapes = { ...joint.shapes };
var graph = new joint.dia.Graph({}, { cellNamespace: shapes });
var paper = new joint.dia.Paper({
    el: document.getElementById('paper'),
    width: 800,
    height: 600,
    model: graph,
    cellViewNamespace: shapes
});

const r1 = new joint.shapes.standard.Rectangle({
    position: { x: 100, y: 100 },
    size: { width: 200, height: 100 },
    z: -1,
    attrs: {
        body: {
            stroke: '#333',
            fill: '#ffff'
        }
    },
    ports: {
        groups: {
            bottom: {
                position: 'absolute',
                markup: [{
                    tagName: 'rect',
                    selector: 'portBody'
                }, {
                    tagName: 'text',
                    selector: 'portLabel'
                }],
                attrs: {
                    portBody: {
                        width: 'calc(w)',
                        height: 'calc(h)',
                        fill: '#fff',
                        stroke: '#333',
                        strokeWidth: 2,
                    },
                    portLabel: {
                        x: 'calc(0.5 * w)',
                        y: 'calc(0.5 * h)',
                        textAnchor: 'middle',
                        textVerticalAnchor: 'middle',
                        textWrap: {
                            width: -10,
                            ellipsis: true
                        },
                        fill: '#666',
                        fontSize: 14,                        
                        fontFamily: 'sans-serif',
                    }
                }
            }
        }
    }
});

const portWidths = [20, 20, 80, 40];
const portGap = 10;

let x = 0;

const ports = portWidths.map((portWidth, index) => {
    const port = {
        size: { width: portWidth, height: 20 },
        args: { x, y: '100%' },
        attrs: {
            portLabel: {
                text: portWidth < 40 ? index :...