解决方案是使用定位器。定位器响应布局端口
相对于它的父形状。
在您的示例中,您没有在“createPort”方法中使用定位器....在这种情况下
端口将以默认行为布局。
-> 左侧的 InputPorts
-> 右侧的输出端口
这里是一个形状的 init 方法示例,它使用定位器添加一些端口。
/**
* @constructor
* Create a new instance
*/
init:function(){
this._super();
this.inputLocator = new this.MyInputPortLocator();
this.outputLocator = new this.MyOutputPortLocator();
this.createPort("hybrid",this.inputLocator);
this.createPort("hybrid",this.inputLocator);
this.createPort("hybrid",this.outputLocator);
this.createPort("hybrid",this.outputLocator);
},
简单定位器的代码:
// custom locator for the special design of the ResistorBridge Input area
MyInputPortLocator : graphiti.layout.locator.Locator.extend({
init:function( ){
this._super();
},
relocate:function(index, figure){
var w = figure.getParent().getWidth();
var h = figure.getParent().getHeight();
figure.setPosition(w/2+1, h*index);
}
}),