How to create a custom form in JointJs, which consists of two or more basic shapes?

I want to create a form in Joint JS.

Which I could initialize and lets say that the rectangle and the circle are the same shape.

As far as I know, only the path method is something close.

+4
source share
1 answer

I just came to an answer. I needed to extend the joint.dia.Element class. Here is the code that draws a rectangle with two circles (extension):

joint.shapes.basic.myShape = joint.dia.Element.extend({

            markup: '<g class="rotatable"><g class="scalable"><rect class="outer"/><circle class="inner"/><circle class="inner1"/></g></g>',
            defaults: joint.util.deepSupplement({
                type: "basic",
                size: {
                    width: 20,
                    height: 20
                },
                attrs: {
                    ".outer": {
                        stroke: 'black',
                        'fill-opacity': 1,
                        width: 10,
                        height: 15
                    },
                    ".inner": {
                        transform: "translate(10, 10)",
                        r: 8,
                        fill: "#000000"
                    },
                    ".inner1": {
                        transform: "translate(10, 10)",
                        r: 6,
                        fill: "#fff"
                    }
                }
            }, joint.dia.Element.prototype.defaults)
});

initialization (for a stencil, but directly to the graph it is also possible to use graph.addCell):

 var r1 = new joint.shapes.basic.myShape({
            size: {
                width: 60,
                height: 60
            }
        });

 stencilData.load([r1], 'basic');
+4
source

All Articles