JointJS - Image with text in the center

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,
  defaultConnectionPoint: {
    name: 'boundary',
  }
});


const r1 = new joint.shapes.standard.Image({
  position: {
    x: 100,
    y: 100
  },
  size: {
    width: 100,
    height: 100
  },
  attrs: {
    image: {
      href: 'https://www.fillmurray.com/640/360'
    },
    label: {
      refY: '50%',
      refY2: null,
      textVerticalAnchor: 'middle',
      fill: 'white',
      text: 'An image in the center',
      textWrap: {
         width: -10,
         height: -19
      }
    }
  }
});

r1.addTo(graph);