It is better to create your own shape, which has a rectangle, image and text. This gives you great flexibility, and you do not need to have two elements to express one form. Your shape, decorated with a small image in the upper left corner, might look like this:
joint.shapes.basic.DecoratedRect = joint.shapes.basic.Generic.extend({ markup: '<g class="rotatable"><g class="scalable"><rect/></g><image/><text/></g>', defaults: joint.util.deepSupplement({ type: 'basic.DecoratedRect', size: { width: 100, height: 60 }, attrs: { 'rect': { fill: '#FFFFFF', stroke: 'black', width: 100, height: 60 }, 'text': { 'font-size': 14, text: '', 'ref-x': .5, 'ref-y': .5, ref: 'rect', 'y-alignment': 'middle', 'x-alignment': 'middle', fill: 'black' }, 'image': { 'ref-x': 2, 'ref-y': 2, ref: 'rect', width: 16, height: 16 } } }, joint.shapes.basic.Generic.prototype.defaults) });
And you can use it like this on your charts:
var decoratedRect = new joint.shapes.basic.DecoratedRect({ position: { x: 150, y: 80 }, size: { width: 100, height: 60 }, attrs: { text: { text: 'My Element' }, image: { 'xlink:href': 'http://placehold.it/16x16' } } }); graph.addCell(decoratedRect);
Notice how the form is indicated, the important bits are the markup , type and attrs objects that reference SVG elements in the markup using regular CSS selectors (there are only tags here, but you can use classes if you want). For the image tag, we use special JointJS attributes for relative positioning ( ref , ref-x and ref-y ). With these attributes, we position the image relative to the upper left corner of the rect element, and we move it 2px from the top edge ( ref-y ) and 2px from the left edge ( ref-x ).
One note. It is important that the type ('basic.DecoratedRect') attribute matches the namespace in which the form is defined in ( joint.shapes.basic.DecoratedRect ). This is because when JointJS rebuilds the graphs from JSON, it looks at the type attribute and does a simple search in the joint.shapes namespace to see if a form specific to this type exists.