sprotty icon indicating copy to clipboard operation
sprotty copied to clipboard

Avoid/disable automatic changes of (macro) layout

Open m-morelli opened this issue 3 years ago • 3 comments

Hello, I've managed to prototype a VS Code extension with an Xtext-based language server and a Sprotty diagram for a simple DSL.

The next step is to avoid the layout changes that are automatically applied to the diagram, even for basic model modifications.

As an example, let's say that I have the Xtext model below and that I'm happy with the graphic arrangement of the corresponding nodes in the Sprotty diagram.

1

Now, if I just enter a (empty) new line in the textual model, the layout is automatically adjusted and the graphic arrangement I was happy with is gone.

2

The doc says that "the server is responsible for the macro layout, that is the arrangement of the main model elements (e.g. nodes and edges) with the goal of optimizing visual clarity and readability". So, I've switched off the server layout (needsServerLayout: false), but I still get automatic changes, the only difference being that now all the blocks are moved to the same position, in the top left corner of the diagram (see below).

3

Any suggestions on how to completely disable this automatic arrangement of nodes and edges?

Thanks!

m-morelli avatar Jul 22 '22 10:07 m-morelli

The scenario you are aiming for is very complex. When a text change is processed, a brand new instance of the diagram model is generated, erasing any manual changes the user has made in the frontend. In order to retain the manual positions, you'd need to send position information to the backend after every move, and store that information somewhere. This "somewhere" can be in the source model itself (e.g. annotations or comments to the respective blocks) or a separate file (e.g. hello.btext.layout) in a format of your choice (JSON, XML etc.)

spoenemann avatar Aug 11 '22 15:08 spoenemann

Thanks for your answer. Any example to start with?

m-morelli avatar Aug 13 '22 09:08 m-morelli

No, unfortunately I don't have a ready-to-use example for this scenario. To capture position changes, you could override DiagramServerProxy.commitModel so it sends the model to the backend with a custom action.

spoenemann avatar Aug 15 '22 05:08 spoenemann