Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic TreeLayout Diagram - ScrollViewer and Alignment problems (Read 11708 times)
nagarjuna
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Jan 3rd, 2014
TreeLayout Diagram - ScrollViewer and Alignment problems
Jan 7th, 2014 at 7:20am
Print Post  
Hi,

Im using TreeLayout to Layout a diagram with few nodes.

but,

I am having problems with having scrollviewer & aligning the tree to the center of the diagram

1.using scrollviewer is only showing the vertical scrollbar, horizontal scrollbar is not being shown

2.how do i align the tree to the center of the diagram?
(or)
make the root node to the center(so that its position can be kept the same in the TreeLayout, thereby making the tree still centered?

I have programmatically set the Bounds for the rootNode(such that it appears center) and set the TreeLayout.KeepRootPosition to true, but still, after the no of items increase - the horizontal scrollbar doesnt appear and the root node keeps shifting


here's the xaml file and code behind :

Code (HTML)
Select All
        <Grid x:Name="LayoutRoot" Background="White">
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <mindfusion:Diagram x:Name="diagram" Loaded="diagramm_Loaded"></mindfusion:Diagram>
        </ScrollViewer>
    </Grid> 



Code (Java)
Select All
        private ShapeNode rootNode;

        private TreeLayout treeLayout;

        public MainPage()
        {
            InitializeComponent();
        }

        private void diagramm_Loaded(object sender, RoutedEventArgs e)
        {
            this.rootNode = new ShapeNode(this.diagram);
            this.rootNode.Bounds = new Rect(new Point(this.diagram.Bounds.Width / 2 - this.rootNode.Bounds.Width / 2, this.rootNode.Bounds.Y), new Size(this.rootNode.Bounds.Width, this.rootNode.Bounds.Height));
            this.diagram.Nodes.Add(this.rootNode);

            //// add 12 children nodes under the root node
            ShapeNode child;
            for (int i = 0; i < 12; i++)
            {
                child = new ShapeNode(this.rootNode);
                this.AddChild(this.rootNode, child);
            }

            //if (this.treeLayout == null)
            {
                this.treeLayout = new TreeLayout(this.rootNode, TreeLayoutType.Centered, false, TreeLayoutLinkType.Straight, TreeLayoutDirections.TopToBottom, 100, 100, true, new Size(0, 0), true);
            }

            treeLayout.Arrange(this.diagram);
        }

        private void AddChild(DiagramNode parent, DiagramNode child)
        {
            this.diagram.Nodes.Add(child);
            DiagramLink link = new DiagramLink(this.diagram, parent, child);
            this.diagram.Links.Add(link);
        } 



Could someone help me with this?

Thank you,
Nagarjuna
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TreeLayout Diagram - ScrollViewer and Alignment problems
Reply #1 - Jan 7th, 2014 at 8:59am
Print Post  
Hi,

Call Diagram.ResizeToFitItems() after TreeLayout.Arrange().

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nagarjuna
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Jan 3rd, 2014
Re: TreeLayout Diagram - ScrollViewer and Alignment problems
Reply #2 - Jan 7th, 2014 at 1:46pm
Print Post  
wow!, that helped with the HorizontalScrollBar

but, that is not helping with positioning the tree properly!!

every time a new node gets added - the Tree shifts its position

can the rootNode's position be kept fixed(at the center of the whole diagram)?

thank you..
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TreeLayout Diagram - ScrollViewer and Alignment problems
Reply #3 - Jan 7th, 2014 at 2:37pm
Print Post  
KeepRootPosition should preserve the diagram coordinates of the root node, but once you resize the diagram, its scroll position might change and the node will move to a different screen position. Try setting diagram.ScrollX = rootNode.GetCenter().X - scrollViewer.ActualWidth / 2 after resizing the diagram to make sure that node is centered visually.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nagarjuna
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Jan 3rd, 2014
Re: TreeLayout Diagram - ScrollViewer and Alignment problems
Reply #4 - Jan 8th, 2014 at 7:42am
Print Post  
Hi Stoyo,

sorry, but that is not helping!!

I think there is some misunderstanding, I might have not made it clear...

I dont want the rootnode to appear center to the VisualScreen(i.e no necessity of manually moving the scrollbar such that the rootnode appears at the center of visual screen)

I want the rootnode to not shift its position(which will be at the center of the whole screen width, not the visual screen)


My requirement is this :-
1.A tree whose root node which initially sits at Top-Center position.
2.Upon expanding the Tree - the root node should not change its position(it should be fixed).
3.if the diagram takes more space - then scrollbars will be helping to navigate to particular place in the tree

without the Diagram.ResizeToFitItems() call, both 1 & 2 are possible. its only that in requirement 3 - the horizontal scroll bar is not appearing.


even If i used Diagram.ResizeToFitTItems(), i believe its supposed to just adjust the width/height, but, why is it repositioning the tree nodes(especially the root node) even when the horizontalscrollbar is not activated?
(i.e in the beginning, where there are few nodes and the width is sufficient and horizontal scrollbar is not activated - i still see that the root node gets shifted upon ading child nodes)

thank you
Nagarjuna
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TreeLayout Diagram - ScrollViewer and Alignment problems
Reply #5 - Jan 8th, 2014 at 12:00pm
Print Post  
You will have to save and restore the scroll position then. Restoring scroll position might not work if the diagram grows smaller (e.g. old scroll X gets outside new bounds), so instead of calling ResizeToFitItems, create a union of current diagram.Bounds and the new diagram content rect:

Code
Select All
var scrollX = diagram.ScrollX;
var scrollY = diagram.ScrollY;

var tl = new TreeLayout
{
	Root = e.Node,
	KeepRootPosition = true
};
tl.Arrange(diagram);

var newBounds = diagram.Bounds;
newBounds.Union(diagram.GetContentBounds(false, true));
diagram.Bounds = newBounds;

diagram.ScrollX = scrollX;
diagram.ScrollY = scrollY;
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nagarjuna
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 6
Joined: Jan 3rd, 2014
Re: TreeLayout Diagram - ScrollViewer and Alignment problems
Reply #6 - Jan 9th, 2014 at 6:20am
Print Post  
hi,

yeah, that helps (although, the root node still keeps shifting a bit, i guess i just have to live with that  Smiley)

thanks for all the help
Nagarjuna
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: TreeLayout Diagram - ScrollViewer and Alignment problems
Reply #7 - Jan 9th, 2014 at 7:16am
Print Post  
I can see it shift only if you start with a diagram.Bounds smaller than the scroll viewer's size. ScrollViewer does no let you change scroll position when its content is smaller. If you start with a large enough initial diagram.Bounds, the root should stay fixed on screen with the code above.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint