SubGraph Collapsed Bounds relative to Handle

I want a subgraph when collapsed not positioned with the handle “as center”, but with the handle as the “left upper point”.

How can I change this behaviour?

I attach two screenshots from the Subgraph App Demo

The expanded subgraph:

The collapsed subgrah, which is “centered” around the handle.
Iwould like to have it positioned at the sketched position.

Kind Regards

You started with CustomSubGraph, right? CustomSubGraph uses a CollapsedObject for when it is collapsed, so you must have changed that. Without knowing what changes you’ve made, it’s hard for me to say.



Note that both TreeSubGraph and MultiPortSubgraph (the other two types in SubGraphApp) both have exactly the collapse behavior you want (or at least what I think you want).

You are right, the collapse behaviour of MultiPortSubGraph in the Demo is what I want.
I use the CustomSubGraph from the Demo application.
What changes do you mean?
Does your version of the SubGraphApp-Demo provide another collapse behaviour than mine?

If no: What causes the different collapse behaviour compared with MultiPortSubGraph?

If yes: Can I download somewhere the uptodate CustomSubGraph.cs?

Sorry for the slow reply…



From your screenshots, it looks like you have taken CustomSubGraph and removed the override for CreateCollapsedObject.



Is that right?



If it is… then to get the collapse positioning you want, you also have to remove the override for ComputeCollapsedSize.

In the version of CustomSubGraph I downloaded some months ago the code is:

// If you want to display an image when collapsed,
// add this override (or set CollapsedObject)

// protected override GoObject CreateCollapsedObject() {
// GoImage img = new GoImage();
// img.Selectable = false;
// img.Visible = false;
// img.Printable = false;
// img.Name = …
// img.Size = new SizeF(img.Image.Width, img.Image.Height);
// this.CollapsedSize = img.Size;
// return img;
// }

so there was and is no override of CreateCollapsedObject.
I commented the method ComputeCollapsedSize now, but the result keeps the same.

If you can’t reproduce the problem from my screenshots with your version of CustomSubGraph resp. SubGraphApp, perhaps you could send me your version by email?

Oops, you’re right about CreateCollapsedObject… sorry, I was looking at a copy of the code that I had played with.



but commenting out ComputeCollapsedSize did give me the result you want… curious. I will email you my copy.

Ok, now it works, if the content node has a long label.
But if the SubgraphNode itself has a long label, there is the same behaviour as before, if I want to show the complete label and comment therefore the code in PrepareCollapse and FinishCommand.

So, how can I have the collapsed subgraph always right below the handle?

Try setting subgraph.CollapsedLabelSpot to GoObject.TopLeft or GoObject.BottomLeft and see if that suits your needs.

Thanks for the hint. That leads into the right direction!

I tried CollapsedLabelSpot TopLeft and BottomLeft.
And TopLeft is near to my needs, although it positions the label above the handle.
I tried also CollapsedLabelSpot=MiddleLeft, but that led to the label on the left side of the handle (other than TopLeft and BottomLeft).

There remains another problem when having a Subgraph inside another Subgraph. The layout of the collapsed outer subgraph then depends on the collapsed state of the inner subgraph. If the inner subgraph was collapsed, too, then the collapsed outer subgraph looks relative ok (the large empty area would not be necessary - the label could be drawn here as well),

but if the inner subgraph was expanded, there are now empty areas on the left and the bottom of the handle in the collapsed outer subgraph.

From my point of view it would be convenient and easy to understand,
if there were two properties CollapsedLabelSpot and CollapsedObjectSpot,
which define the relationship between handle and Label resp. “Invisible Objects Area” of Collapsed Subgraph
such that “TopLeft” means "top left corner of Label resp. Object is positioned at the Handles position (and the same for “MiddleLeft” etc.

Perhaps there is even already a work around available to get this behaviour ?Wink

OK… there are a little more than an infinite number of options here.



Why CollapsedLabelSpot = MiddleLeft is so weird, I don’t understand. I saw that too. But here is a better option, I think…



first, if you are trying to keep things similar between expanded and collapsed, you may want to set Margins the same in both (although you may already have this…)





this.CollapsedTopLeftMargin = this.TopLeftMargin;

this.CollapsedBottomRightMargin = this.BottomRightMargin;



and try this trick to have the collapsed label not move:



public override void LayoutLabel() {

if (this.IsExpanded)

base.LayoutLabel();

}



I’ve tried this, and the results look good to me, although you can be the final judge… (note CollapsedLabelSpot has no meaning anymore with the above override)

Well, that trick seems to do the job!

When collapsing subgraphs, which include uncollapsed subgraphs there seem to remain some space on the left of the handle, but all in all it looks much better than the approaches before.

I modified the trick a little bit to avoid very wide and flat collapsed subgraphs in my hierarchical model (about 7 levels of subgraphs):

  public override void LayoutLabel()
  {
     if (this.IsExpanded) base.LayoutLabel();
     else Label.Position = new PointF(Handle.Position.X + 20, Handle.Position.Y);
  }

and I am planning to build in some mechanisms to collapse recursively.

Things can be so easy if one knows what to do.
Thank you very much!