Problem with PrepareExpand


I can read in the doc for GoSubGraph:

This method will first set the State to Expanding, and then call PrepareExpand for any preparatory work

However, with my tests with an overridden version of PrepareExpand, it looks like Expand does not call this function.

Could you please confirm me wether this is a bug in the doc, a bug in GoDiagram, or a bug in my test program?


GoSubGraph.Expand always calls PrepareExpand, unless the Expand method is just a no-op because either GoSubGraph.Collapsible is false or the GoSubGraph.State is not GoSubGraphState.Collapsed.

Ok, so the problem seems to be the following: When created, the GoSubGraph is in the Expanded state. Initializing in this state does not imply any call to PrepareExpand (that is understandable).

Then I read some data from a file to see if the subgraph should be expanded or not, and depending on this data, I call expand or collapse. This call to expand is effectively a no-op, since the graph was initialized as expanded.

In my case, however, I have some work that only has to be done when (if?) the graph is expanded (loading the subgraph content). So putting this code in prepareExpand is just not a solution. I wonder what would be the best solution :

  • Overriding Expand and move that initialisation code here, before calling base class Expand.
  • Change the code to that the initial state is collapsed, since it is what fits my model best. Is there a way to do so ? I might just call Collapse at the beginning of the constructor, then read my config file and potentially call Expand, but I don’t know why, this looks unnatural to me.

Best regards,

I’m not sure what’s best in your case, but I would certainly think that during initialization you should do whatever is needed to get the effect you want.
In other words, maybe that code doesn’t belong in your class, but just in the code that initializes and/or loads instances of your class.