5

有没有办法让 Roassal 从一个节点到自身绘制一条边?

我查看了一堆示例,但找不到任何这样做的示例,并且仅在源代码中添加一条边不会产生任何结果。

IE

view shape rectangle size: 1.
view nodes: (1 to: 5).
view shape arrowedLine.
view 
    edges:  ((OrderedCollection new) add: (1->1); add: (2->2); add: (3->3); add: (4->4); add: (5->5); yourself)
    from: #key 
    to: #value.
view circleLayout.

根本不产生边缘。

4

1 回答 1

3

我不确定 Roassal 是否实现了这种优势。我在 Roassal2 中尝试了相同的方法,虽然创建了边缘,但没有显示。似乎它创建了一条线,其中起点和终点是同一点。

作为一种解决方法,您可以通过为这种情况指定不同的行为来重用贝塞尔线:


   RTDirectedLine>>pointsFrom: from To: to
   | point mid |
   from = to
        ifTrue: [ 
            mid := to * (1 - offset) + (from * offset).
            point := from + (50 @ 50).
            ^ Array with: from - (10 @ 0) with: point with: to - (0 @ 10) ]
        ifFalse: [ 
            mid := to * (1 - offset) + (from * offset).
            point := from + (mid - from) rightRotated.
            ^ Array with: from with: point with: to ]

然后您可以在工作区中运行:


| b |
b := RTGraphBuilder new.
b nodes 
    size: 20; 
    color: Color gray.
b edges 
    directed;
    connectTo: #yourself.

b layout circle.
b addAll: (1 to:5).

b open.
b view canvas

你应该看到这个:

http://cdn.imghack.se/images/1aaea2de365d0a16818ec8bcf991348a.png

于 2014-09-05T13:05:01.250 回答