Invalidate group layout on location change

Hi,

I have a set of Nodes which are position via a group layout. The layout is invalidated when the contained parts change visibility, size, but not location.

Is this a flag I can add somewhere as the documentation does not provide an easy solution to this?

(Right now I have a binding against location calling group.layout?.invalidateLayout(); which is a side effect and is not a good solution)

What would cause nodes to be moved? Try invalidating the appropriate layouts in a “SelectionMoved” DiagramEvent listener.

We have an external state which receives changes from a remote backend which are merged into the modelData so events like SelectionMoved does not trigger in this case.

The nodes in the group do not have a location, but we do have a location in the group data which all nodes in the group are relatively moved to using the group layouts doLayout function. This group location is what gets changed in the group data.

So did you want to invalidate the group’s layout when the group data’s location property changes? You could do that either with a binding or in a model Changed event listener.

Ok so if I were to use the binding method would it be something like:

new Binding('layout', 'location', () => new CustomLayout()),

Edit: Renamed Layout to CustomLayout to avoid confusion

Is your Group.layout just a direct instance of Layout? I’m surprised.

A more general possibility (I haven’t tried it) could be:

new go.Binding("layout", "location", (loc, grp) => {
  grp.layout.invalidateLayout();
  return grp.layout;
})

I just didn’t want to type the custom layout name we had, quicker to type Layout :D It is a custom layout class though. (I’ts now called CustomLayout in the previous example)

Looks like the one you proposed works better as well, I’m noticing a weird bug with our custom layout if we create a new instance each time so the invalidateLayout option seems to be the better choice in this case.

Thanks!