1

ポートの位置を操作するために多くのことを読んだ後、別の問題を発見しました: 画像に示されているように、図の下にあるポートを選択したときです。

ここに画像の説明を入力

ここに画像の説明を入力

私の質問は次のとおりです。ポートを図の上部に保つにはどうすればよいですか? これは私のコードです:

var leftLocator = new draw2d.layout.locator.InputPortLocator();
var rightLocator = new draw2d.layout.locator.OutputPortLocator();

leftLocator.relocate = function(index, figure) {
  var width = figure.getParent().getWidth();
  var height = figure.getParent().getHeight();

  var x = width / 4;
  var y = height / 2;

  figure.setPosition(x, y);
}

rightLocator.relocate = function(index, figure) {
  var width = figure.getParent().getWidth();
  var height = figure.getParent().getHeight();

  var x = width * 3 / 4;
  var y = height / 2;

  figure.setPosition(x, y);
}

elemento.createPort("input", leftLocator);
elemento.createPort("output", rightLocator);
4

2 に答える 2

2

onDragStart イベントで「toFront」メソッドを使用して解決策を見つけました。

OutputPortFigure = draw2d.OutputPort.extend({
  NAME: 'OutputPortFigure',
  init: function() { ... },
  onMouseEnter: function() { ... },
  onMouseLeave: function() { ... },
  onDragStart: function(x, y, shiftKey, ctrlKey) {
    this._super(x, y, shiftKey, ctrlKey);
    this.toFront(this.getParent());
  },
});
于 2014-10-14T13:34:50.180 に答える
0

私は自分のフィギュアのいくつかで同じ問題を抱えていました。

役立つ解決策を見つけましたが、それは私が考える最善の解決策ではありません。

ポートを保持する非表示の図を作成します (親の図が変更されたときに子の図のサイズを変更する再描画メソッドを実装します)

var Hidden = draw2d.SetFigure.extend({
    NAME: "Hidden",
    init : function()
    {
        this._super();

        this.addPort(new draw2d.InputPort('port1'), new draw2d.layout.locator.InputPortLocator());
        this.addPort(new draw2d.OutputPort('port2'), new draw2d.layout.locator.OutputPortLocator());

        this.setDimension(300,150);
        this.setAlpha(0);
    },
    onDoubleClick: function(){
    }
});

var Test = draw2d.SetFigure.extend({
    NAME: "Test",
    init : function()
    {
        this._super();

        this.hidden = new Hidden();
        this.addFigure(this.hidden, new draw2d.layout.locator.CenterLocator(this));

        this.setAlpha(0.8);
        this.setDimension(300,150);
        this.setRadius(10);
        this.setStroke(3);
        this.label.setColor("#0d0d0d");
        this.label.setFontColor("#0d0d0d");
        this.addFigure(this.label, new draw2d.layout.locator.CenterLocator(this));

        this.tooltip = null;
    },
    repaint: function(attributes){
        this._super(attributes);
        if(this.hidden != undefined) this.hidden.setDimension(this.getWidth(), this.getHeight());
    },
    onDoubleClick: function(){
    }
});

あなたがより良い解決策を持っているなら、私はそれを見てうれしいです:)

ループ接続を持つことができる図を実装していたときにこれを発見しました

于 2014-09-18T12:52:06.410 に答える