We are using GoView v 1.1 for Winforms( .NET 2.0).I have a case where there are large number of nodes in the View document but only a few are visible at any point in time.
What I would like achieve is the AutoLayout of the visible nodes ONLY.
Things that I did:
set the TopLeft and Size for the Document to be the same as the GoView.DisplayRectangle
- created this class
public class MyLayout : GoLayoutForceDirected { public MyLayout() { }
protected override bool IsFixed(GoLayoutNetworkNode pNode) { if (pNode.GoObject != null) { //MyClass inherits from GoNode if (pNode.GoObject is MyClass && pNode.GoObject.Visible) return false; } return false; } }
and the calling code is here:
MyLayout layout = new MyLayout(); layout.Document = goView.Document; layout.Network = null; layout.PerformLayout(); CenterViewInDocument();
It still moves the hidden nodes(visible = false). Is there anything else I can do to solve this?
Many thanks! Filip
Do you realize that your IsFixed predicate always returns false?
Did you also want to check whether the pNode.GoObject’s Bounds intersects with your GoView.DocExtent? That isn’t clear from what you describe as your requirements.
Another consideration, which I believe not to be part of your requirements, is that you might want nodes that are not Visible (or just not in view?) not to have any influence in the force-directed layout. Saying that a node is “fixed” in position means it doesn’t move, but it still exerts forces on nearby nodes and nodes that are connected to it via links. But if you don’t want them to have any influence at all, it’s best to simply remove them from the IGoLayoutNetwork being used by the layout.
Walter,<?:namespace prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p> Sorry about that predicate.I had the correct version in my code but I posted the wrong one on the site.Also the GoView version we use is 2.4<o:p></o:p> Problem: Browse trough a collection of objects(A, B, C…).Each object has a display of nodes on the GoView and the user can arrange these nodes in any way they want.This layout gets saved in an XML file.
Suppose we arranged by hand nodes for A, B, C… and saved this to the XML file<o:p></o:p> When returning to the object A the layout of its nodes is loaded from the XML file and displayed in the GoView.Should the user change this layout we save it again. As you can imagine, at any point in time there are a lot of nodes on the Document, but just the ones linked to the selected object in the collection are displayed.The other ones are hidden(visible = false).So if I have object A selected, I can only see its nodes, and so on.
If the user de clutters the nodes by hand everything works fine. If the user uses auto-layout on object C for instance, then when returning to object A its nodes are moved far and away. I am new to the GoView and I tried what I told you but I couldn’t solve this. I should mention that there are no scroll bars and I tried to make the View and Document the same size because nodes should not go beyond the visible area.
I hope I explained it properly.Any help is appreciated.Thanks!
Yes, I suggest just doing a layout on a GoLayoutNetwork corresponding to just the nodes and links that are Visible.
The whole point of GoLayoutNetwork is to allow layout on subsets of a document. But if you leave or set the GoLayout.Network property to null, then it automatically creates a GoLayoutNetwork that contains GoLayoutNetworkNodes and GoLayoutNetworkLinks corresponding to all the nodes and links of the document.
So if the user chooses node A, you create a new GoLayoutNetwork and add node A and all of its visible connected links and nodes, assign the Network property, and then PerformLayout. Layout always works only on the nodes and links that are in the GoLayoutNetwork. So if you don’t have anything in there corresponding to not-Visible links or nodes, it’s as if they didn’t exist.
Now it works better, thanks.Still there are some problems for me. - How do I make sure that my document is always the same size as the viewable area of the GoView?Sometimes my GoView is 400, 300 and I have nodes exceeding these limits and there is even some scrolling even though I have no scroll bars in place.I would like to nodes to be displayed within the viewable area only.
This code: goView.Document.TopLeft = new PointF (goView.DisplayRectangle.X, goView.DisplayRectangle.Y); goView.Document.Size = goView.DisplayRectangle.Size;
combined with no scroll bars doesn’t do it. Thanks!
You need to figure out what’s most important to your application if you want to have all objects be visible: changing the GoView.DocScale, or moving the objects to fit in the GoView.DocExtent.
For the former case, try calling GoView.RescaleToFit.
For the latter case, you’ll need to move all the nodes to fit within an area of size GoView.DocExtentSize, and then
RectangleF bounds = doc.ComputeBounds(); doc.TopLeft = bounds.Location; doc.Size = bounds.Size; view.DocPosition = bounds.Location;
Oh, and if you haven’t already seen it, there’s code in LayoutDemo and in the Layout User Guide describing how you can set up a “force field” around a rectangular area to “discourage” nodes from leaving. However, you’ll need to make sure that all the nodes start in that area.