Creating a circle object with a port

I am trying to create a circle with a port, I am implementing a workflow and I need to create a start circle and an end circle with a port, but no success so far.

I can create a circle, but without ports, the getPortAttrs method is called.

joint.shapes.devs.CircleModel = joint.shapes.basic.Generic.extend(_.extend({}, joint.shapes.basic.PortsModelInterface, {
    markup: '<g class="rotatable"><g class="scalable"><circle class="body"/> </g> <g class="inPorts"/> <g class="outPorts"/> </g>',
    portMarkup: '<g class="port<%= id %>"> <circle class="port-body"/> <text class="port-label"/> </g>',
    defaults: joint.util.deepSupplement({
        type: 'devs.CircleModel',
        size: { width: 20, height: 20 },
        inPorts: [],
        outPorts: [],
        attrs: {
            '.': { magnet: true },
            '.body': {
                transform: 'translate(10, 10)',
                r: 10,
                'stroke-width': 2,
                stroke: 'green',
                fill: 'green'
            },
            '.port-body': {
                r: 5,
                magnet: true,
                stroke: 'black'
            },
            '.inPorts .port-label': { dy:-30, x: 4 },
            '.outPorts .port-label':{ dy: 15, x: 4 }
        }
    }, joint.dia.Element.prototype.defaults),

    getPortAttrs: function (portName, index, total, selector, type) {
        var attrs = {};
        var portClass = 'port' + index;
        var portSelector = selector + '>.' + portClass;
        var portTextSelector = portSelector + '>.port-label';
        var portCircleSelector = portSelector + '>.port-body';
        attrs[portTextSelector] = { text: portName };
        attrs[portCircleSelector] = { port: { id: portName || _.uniqueId(type) , type: type } };
        attrs[portSelector] = { ref: '.body', 'ref-x': (index + 0.5) * (1 / total) };
        if (selector === '.outPorts') { attrs[portSelector]['ref-dy'] = 0; }
        return attrs;
    }
}));

      

+3


source to share





All Articles