ObjectProfile / Roassal3

The Roassal Visualization Engine
MIT License
95 stars 52 forks source link

how to make a force based layout with GraphViz? #294

Closed bergel closed 3 years ago

bergel commented 4 years ago

Using the force based layout I have:

image

Using GraphViz I have:

image

It seems that GraphViz does not use a force based layout. Is there a way to configure the used layout?

bergel commented 4 years ago

Here is the code I used:

c := RSCanvas new.

shapes := Collection withAllSubclasses collect: [ :cls | RSEllipse new size: 20; model: cls ].
c addAll: shapes.
eb := RSEdgeBuilder line.
eb canvas: c.
eb shapes: shapes.
eb connectToAll: #dependentClasses.

RSForceBasedLayout new charge: -300; on: c nodes.
"RSGraphVizLayout on: c nodes."
c @ RSCanvasController
akevalion commented 3 years ago

Here an update

c := RSCanvas new.

shapes := Collection withAllSubclasses collect: [ :cls | RSEllipse new size: 20; model: cls ].
c addAll: shapes.
eb := RSEdgeBuilder line.
eb canvas: c.
eb shapes: shapes.
eb connectToAll: #dependentClasses.

"RSForceBasedLayout new charge: -300; on: c nodes."
RSGraphVizLayout neato on: c nodes.
c @ RSCanvasController

image

akevalion commented 3 years ago

Consider

allTime := OrderedCollection new.
1 to: 30 do: [ :i | 
time := [
c := RSCanvas new.
classes := Collection withAllSubclasses collect: [ :cls | RSEllipse new model: cls ].

c addAll: classes.
RSNormalizer size shapes: classes; normalize: #numberOfMethods.
eb := RSEdgeBuilder line.
eb shapes: classes.
eb connectToAll: #dependentClasses.

c nodes @ RSDraggable.
layout := RSForceBasedLayout new.
layout nodes: c nodes.
layout edges: c edges.
layout start.
c nodes do: [ :node | (layout mockElementAt: node)
    charge: node width * -10;
    weight: node width ].
c edges do: [ :edge | (layout mockEdgeAt: edge)
    strength: 1;
    length: (edge from width + edge to width) ].
layout runLayoutSimply.

"RSGraphVizLayout neato on: c nodes."
c @ RSCanvasController.
c
] timeToRun.
allTime add: time.
].
allTime average.

RSForceBasedLayout average time (ms) 611 RSGraphVizLayout average time (ms) 437

But RSGraphVizLayout does not work well with a lot of nodes, the execution stops for some reason in OSSubprocess. If you pause the execution and then resumed it works well. But this is kind odd.