Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic intelligent zooming - to a center point (Read 5781 times)
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
intelligent zooming - to a center point
Mar 8th, 2013 at 4:37pm
Print Post  
Did anyone already think of having an intelligent zooming in and out that keeps either the selection or the visible nodes in mid of diagram when zooming?

i.e.

if this is the mid point to keep in center:

var mid = MiddlePnt(Selection.Nodes.Count >= 1 ?
Selection.Bounds :
GetContentBounds(false, true));

and

internal Point MiddlePnt(Rect r)
{
//arithmetic mid
return new Point((r.Right - r.Left)/2, (r.Bottom - r.Top)/2);
}

how to keep this mid point in center while doing e.g. Mousewheel zoomOut() or zoomIn()? (or over dedicated button functions). NB: zoomIn() and zoomOut() do not have an agrument for specifying the center point.

===

It seems that the ScrollTo(mid) does not seem to work depending on size of diagram and/or scrollviewer positioning.

This seems to be a function that diagram might always need, so maybe there is a standard method or solution for this?

cheers
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: intelligent zooming - to a center point
Reply #1 - Mar 11th, 2013 at 7:05am
Print Post  
There is the SetZoomFactor(zoomLevel, centerPoint) method that zooms without changing the screen location of the specified diagram point.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: intelligent zooming - to a center point
Reply #2 - Mar 11th, 2013 at 10:51am
Print Post  
i think neither this function follows the pivot correctly if the diagram.bounds are not fully within the scrollviewer, i.e. probably i will have to enlarge diagram boundaries size prior to pivoting so that there is enough leeway... ?

(investigating)
  
Back to top
 
IP Logged
 
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: intelligent zooming - to a center point
Reply #3 - Mar 11th, 2013 at 3:41pm
Print Post  
Stoyo, did you publish few months ago a variant of MouseWheel handler that zooms in/out of diagram?

do you still have link to it, maybe i am missing some point about scrollviewer vieportwidth or actualwidth...
  
Back to top
 
IP Logged
 
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: intelligent zooming - to a center point
Reply #4 - Mar 11th, 2013 at 5:09pm
Print Post  
i actually foun d& reused your code from and old 2009 post:

Code
Select All
        public void SetZoom(double percentage)
        {
            ScrollViewer scrollViewer = (ScrollViewer)Parent;
            var diagramTransform = scrollViewer.TransformToVisual(DocumentPlane);

            // this point should remain centered when zooming in?
            Point scrollViewerCenter = new Point(
                scrollViewer.ActualWidth / 2, scrollViewer.ActualHeight / 2);
            Point weighPt = WeightMidPoint();

            Point diagramPointAtViewCenter = diagramTransform.Transform(weighPt); //weighPt scrollViewerCenter

            ZoomFactor = Math.Max(10, Math.Min(percentage, 200));

            Rect clientAreaSize = new Rect(0, 0, scrollViewer.ActualWidth, scrollViewer.ActualHeight);
            Rect clientAreaDiagSize = ClientToDoc(clientAreaSize);

            // ensure the diagram is always larger than the scrollviewer
            Rect newBounds = GetContentBounds(false, true);
            double diffX = Math.Max(0, clientAreaDiagSize.Width - newBounds.Width);
            double diffY = Math.Max(0, clientAreaDiagSize.Height - newBounds.Height);
            newBounds.Inflate(diffX / 2, diffY / 2);
            Bounds = newBounds;

            // make sure the diagram center is at the scrollviewer center
            ScrollX = diagramPointAtViewCenter.X - clientAreaDiagSize.Width / 2;
            ScrollY = diagramPointAtViewCenter.Y - clientAreaDiagSize.Height / 2;
        }

        //arithmetic mid
        internal Point MiddlePnt(Rect r)
        {
            return new Point((r.Right - r.Left)/2 + r.X, (r.Bottom - r.Top)/2 + r.Y);
        }

        //diagram weighted mid (selected or no)
        internal Point WeightMidPoint()
        {
            var mid = MiddlePnt(Selection.Nodes.Count >= 1 ?
                ClientToDoc(Selection.Bounds) :
                ClientToDoc(GetContentBounds(false, true)));
                //(Selection.Bounds) :
                //(GetContentBounds(false, true)));
            return mid;
        }
 



so now the behaviour uis better, but still when the user zooms too near, some spiralling happens Tongue
  
Back to top
 
IP Logged
 
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: intelligent zooming - to a center point
Reply #5 - Mar 12th, 2013 at 10:44am
Print Post  
still, the opening point stands that ScrollTo or ScrollX ScrollY cannot scroll to points that are near the diagram border at all.

so you cannot pan programmatically to a node that is near the borders of diagram.
  
Back to top
 
IP Logged
 
ulthien
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 91
Location: Munich
Joined: Nov 29th, 2011
Re: intelligent zooming - to a center point
Reply #6 - Mar 12th, 2013 at 3:48pm
Print Post  
ok found the problem on the above code:

Point diagramPointAtViewCenter = diagramTransform.Transform(weighPt); //weighPt

should be:

Point diagramPointAtViewCenter = weighPt;

and then it pans after the selection well.

===

solved Cheesy
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: intelligent zooming - to a center point
Reply #7 - Mar 13th, 2013 at 11:44am
Print Post  
Yes, you don't need to transform this point since it's already in diagram coordinates, while scrollViewerCenter from old code is in ScrollViewer's coordinates. It seems a better solution would be to make ScrollViewer accept scroll positions outside the current content range instead of artificially enlarging diagram.Bounds, then it would let you preserve positions near the edges too by simply calling SetZoomFactor. We'll see if we can override the viewer's Arrange method for next release to enable that with a custom ScrollViewer control.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint