Draw2D:如何将端口用作多个连接的源/目标?

时间:2013-02-08 19:04:55

标签: javascript html5-canvas draw2d-js

所以,我正在尝试将我的课程构建为个人项目,我决定使用Draw2D,因为我认为它非常完整。我将这些课程表示为矩形并在它们之间建立联系,以显示哪些课程是其他课程的先决条件,如下所示:

Course list with dependencies 我遇到的问题是,当尝试将同一个端口作为两个连接的源时,它只需要一个而忽略另一个。有任何想法吗?以下是一个快速示例:

$(window).load(function () {
    // Create the paint area. The id in the constructor must be
    // an existing DIV 
    var canvas = new draw2d.Canvas("gfx_holder");

    // create and add two nodes which contains Ports (In and OUT)
    var start = new draw2d.shape.node.Hub();
    var startLocator = new draw2d.layout.locator.BottomLocator(start);
    var startLocator2 = new draw2d.layout.locator.BottomLocator(start);

    var startPort = start.createPort("output", startLocator);
    var end   = new draw2d.shape.node.End();
    var end2   = new draw2d.shape.node.End();

    canvas.addFigure( start, 400,100);
    canvas.addFigure( end, 200,150);
    canvas.addFigure( end2, 600,150);

    var c = new draw2d.Connection();
    c.setTargetDecorator(new draw2d.decoration.connection.ArrowDecorator());
    c.setSource(startPort);
    c.setTarget(end.getInputPort(0));
    canvas.addFigure(c);


    var c2 = new draw2d.Connection();
    c2.setTargetDecorator(new draw2d.decoration.connection.ArrowDecorator());
    c2.setSource(startLocator2);
    c2.setTarget(end2.getInputPort(0));
    canvas.addFigure(c2);
});

1 个答案:

答案 0 :(得分:2)

我怀疑你的问题出在setSource函数调用中。

c.setSource(startPort);
c2.setSource(startLocator2);

似乎有一个端口,另一个是定位器。