Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edge from a node to itself in Roassal

Is there a way to make Roassal draw an edge from one node to itself?

I looked at a bunch of the examples and I cannot find any that does that, and simply adding an edge in the source code produces nothing.

i.e.

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.

produces no edges at all.

like image 348
BoriS Avatar asked Oct 21 '22 02:10

BoriS


1 Answers

I'm not sure if Roassal implements that kind of edge. I tried the same in Roassal2 and although the edge is created it is not showed. It seems that it creates a line where the origin and the end is the same point.

As a workaround you could reuse Bezier lines by specifying a different behaviour for that case:


   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 ]

Then you can run in a workspace:


| 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

You should see this:

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

like image 195
Leonel Merino Avatar answered Jan 02 '23 19:01

Leonel Merino