Roassal3
Roassal3 copied to clipboard
How to make large nodes away from small
Is there a way to make a arge node more "repulsive" than a smaller node?
r := Random seed: 42.
values := Dictionary new.
1 to: 4 do: [ :i | values at: i put: (r nextInt: 50) + 10 ].
assoc := { 1 -> 2 . 1 -> 3 . 3 -> 4 }.
c := RSCanvas new.
nodes := RSCircle models: (1 to: 4) forEach: [ :s :o | s size: (values at: o); color: Color gray translucent ].
c addAll: nodes.
nodes @ RSDraggable @ RSPopup.
lb := RSLineBuilder line.
lb canvas: c.
lb useAssociations: assoc.
RSForceBasedLayout on: nodes.
c @ RSCanvasController
This script gives:

The big nodes is above the small nodes.... It would be great to have large nodes away from the small nodes.
I have added a boolean accessor to automatically set the charge and the length of each node and line
r := Random seed: 42.
values := Dictionary new.
1 to: 4 do: [ :i | values at: i put: (r nextInt: 50) + 10 ].
assoc := { 1 -> 2 . 1 -> 3 . 3 -> 4 }.
c := RSCanvas new.
nodes := RSCircle models: (1 to: 4) forEach: [ :s :o | s size: (values at: o); color: Color gray translucent ].
c addAll: nodes.
nodes @ RSDraggable @ RSPopup.
lb := RSLineBuilder line.
lb canvas: c.
lb useAssociations: assoc.
i:= RSForceLayoutSteppingInteraction new.
i layout
autoRepulse: true.
c @ RSCanvasController; @ i.
c

We have RSSimpleForceBasedLayout