0

我使用jointjs / rappid。

我想在移动单元格时更改端口的属性(例如 inPort 的颜色:in0_2)。如何访问这些属性?

单元格示例:http ://www.epro.de/exchange/virtual-reality/jointjs/celltest.jpg

我想这很容易 - 我尝试了不同的方法,但找不到解决方案。

有什么提示吗?

我使用以下代码来创建单元和端口。

var graph =  new joint.dia.Graph;
var paper =  new joint.dia.Paper({
        el: $('#paper-container'),
            width: 1000,
            height: 1000,
            gridSize: 10,
            drawGrid: true,
            model: graph,

        });


var l_st0 = myShapes ();
l_st0.set ('inPorts',(['in0_1', 'in0_2']));
l_st0.set ('outPorts',(['outx']));
l_st0.attr ('.label/text','MinTest');
l_st0.position (100,100); 

graph.addCell(l_st0);

l_st0.on ('change:position', function() { 
    console.log (" change port color ");
});

 function myShapes (){

joint.shapes.devs.GenericBasic  = joint.shapes.devs.Model.extend({
portMarkup: '<rect class="port-body"/>',
  defaults: joint.util.deepSupplement({
    type: 'devs.GenericBasic',
    inPorts: [],
    outPorts: [],

    attrs: {

        '.label': {
            'ref-x': .5,
            'ref-y': 5,
            'font-size': 12,
            'text-anchor': 'middle',
            fill: '#000'
        },
        '.body': {
            'ref-width': '100%',
            'ref-height': '100%',
            stroke: '#000'
        }
    },
    ports: {
        groups: {
            'in': {
                attrs: {
                    '.port-label': {
                        'font-size': 12,
                        'text-anchor': 'start',
                        x:  -10,
                        fill: '#000000'
                    },
                    '.port-body': {
                         stroke: '#000000',
                        'text-anchor': 'start',
                        x:-20,
                        width: 20,
                        height: 0.5
                    }
                },
                label: {
                    position: {
                        name: 'right',
                        args: {
                             y: 0
                        }
                    }
                } 
            },
            'out': {
                  attrs: {
                    '.port-label': {
                        'font-size': 12,
                        fill: '#000',
                        'text-anchor': 'start',
                        x: -40
                    },
                    '.port-body': {
                        stroke: '#000000',
                        width: 20,
                        height: 0.5
                    }
                },
                label: {
                    position: {
                        name: 'right',
                        args: {
                            y: 0
                        }
                    }
                }
            }
        }
    }

}, joint.shapes.devs.Model.prototype.defaults) 

});


joint.shapes.devs.GenericModelView = joint.shapes.devs.ModelView;

var mx = new joint.shapes.devs.GenericBasic ({
  size: { width: 80, height: 100 },
 attrs: {
    rect: {
            stroke: 'black', 
            'stroke-width': 1
        },
} 
});

return mx;
}
4

1 回答 1

1

我以这种方式解决了它 - 就像在jointjs文档中描述的那样。

l_st0.on ('change:position', function() {     
//optimization is missing
   var l_portsIn = this.get ('inPorts');
   if (l_portsIn.length>0){
       this.portProp (l_portsIn[0],'attrs/rect',{stroke: 'red' });
   }
}
于 2016-10-24T15:21:24.447 回答