Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 7069

Force-directed layout required many iterations to "complete"

$
0
0

@rliiack wrote:

Per my understanding, setting isValidLayout to false triggers the diagram to do the layout:
myDiagram.layout = GoJs(ImportForceDirectedLayout, { isValidLayout: false });
Here is ImportForceDirectedLayout:

    function ImportForceDirectedLayout() {
        go.ForceDirectedLayout.call(this);
        this.defaultElectricalCharge = 50;
        this.defaultGravitationalMass = 1;
        this.defaultSpringLength = 150;
        this.defaultSpringStiffness = .05; // default 0.05
        this.maxIterations = 10000;
    }
    go.Diagram.inherit(ImportForceDirectedLayout, go.ForceDirectedLayout);

    ImportForceDirectedLayout.prototype.needsClusterLayout = function() { return true; };
    ImportForceDirectedLayout.prototype.makeNetwork = function(coll) {
        var net = go.ForceDirectedLayout.prototype.makeNetwork.call(this, coll);
        net.vertexes.each(function(v) { v.isFixed = ((v.node.data.category === 'attributes' || v.node.data.category === 'self')) });
        return net;
    };

"attributes" are the rectangular box attached to the nodes. "self" are edges whose source and target are the same.

After triggering a new diagram to be laid out for the first time, I got a rather unpleasant result:

Each time I trigger the layout, the nodes goes a little further apart. After triggering the force-directed layout about 20 times, I got a fairly reasonable layout:

Why is force-directed doing considerably better each time I trigger it? More importantly, how do I get it to finish the first time? I realize "finish" for force-directed layout may not mean an aesthetically pleasing diagram, but it is hard to believe that bulk of nodes in the the first iteration has locally minimum energy.

I played with force-directed layout properties for a bit. While they do improve the initial layout, they do not change the behavior that continuously running force-directed layout leads to considerably better layout.

Thanks in advance.

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 7069

Trending Articles