Search code examples
gojsstatechart

Auto position nodes in statechart in GOJS


I want to have "loc" value (positioning value eg. loc = "10 10") automatically calculated for statechart according to number of nodes in GOJS. Is there any specific attributes or commands to do it ?


Solution

  • Set Diagram.layout to an instance of ForceDirectedLayout.

    So just add this line to the initialization of the Diagram in StateChart.html:

    layout: $(go.ForceDirectedLayout),
    

    Depending on when you want a layout to happen, you might be interested in setting Layout.isInitial to false and/or setting Layout.isOngoing to false. Read more at the Introduction to Layouts page.