I am trying to change the diagram layout dynamically from TreeLayout to ForceDirected layout using the following code. The line of code I thought would work gets a compile error. How can I make the layout change? AnimationTime property and LayoutDiagram() work.
That’s not an enum, but a class, so you need to allocate it:
myDiagram.Layout = new ForceDirectedLayout();
You can “zoom” by setting the DiagramPanel.Scale property.
At any time you can do:
myDiagram.Panel.Scale = 0.5;
If you just want the diagram to start off at that scale:
<go:Diagram InitialScale=“0.5” … />
If you want the diagram to always be zoomed-to-fit, set:
<go:Diagram Stretch=“Uniform” … />
or set the DiagramPanel.Stretch property.
(FYI, this is what the default ControlTemplate for Overview does.)
If you want the diagram to be zoomed-to-fit only initially:
<go:Diagram InitialStretch=“Uniform” …/>
or set the Diagram.InitialStretch property.
If you want to only do it once in a while, you can calculate the scale you want and set the DiagramPanel.Scale. By default it does:
Rect oldbounds = this.DiagramBounds;
double xscale = this.ViewportWidth/Math.Max(oldbounds.Width, 1);
double yscale = this.ViewportHeight/Math.Max(oldbounds.Height, 1);
xscale = Math.Min(xscale, 1);
yscale = Math.Min(yscale, 1);
this.Scale = Math.Min(xscale, yscale);
I suppose an alternative is to set DiagramPanel.Stretch to Uniform and then immediately back to Unstretched again.