2014-09-02 82 views
5

有沒有一種方法可以使Roassal從一個節點繪製邊緣到自身?在Roassal中從一個節點到它自身的邊緣

我看了一堆例子,我找不到任何這樣做,只是在源代碼中添加邊緣不會產生任何結果。

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. 

在所有不產生邊緣。

+2

+1想這太 – Hendekagon 2014-09-03 02:27:57

回答

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