GOJS 状态图中的自动定位节点

Auto position nodes in statechart in GOJS

我想根据GOJS中的节点数为状态图自动计算"loc"值(定位值eg.loc =“10 10”)。是否有任何特定的属性或命令可以做到这一点?

GoJS有Layouts的自动Node和Link定位的概念

可以创建您自己的布局,根据自定义条件定位节点。有关于制作自己的布局的介绍 here and examples in the extensions gallery

设置Diagram.layout to an instance of ForceDirectedLayout.

所以只需将这一行添加到 StateChart.html 中的 Diagram 的初始化中即可:

layout: $(go.ForceDirectedLayout),

根据您希望布局发生的时间,您可能对设置 Layout.isInitial to false and/or setting Layout.isOngoing to false. Read more at the Introduction to Layouts 页面感兴趣。