Limit the zoom factor when executing FitToPage

I want to limit the zoom factor when executing FitToPage to avoid having big diagrams (one node i.e.).  In an older version of the Diagram, the zoom factor didn't change when executing FitToPage but the latest version does it.

If I execute the following code, and if my diagram has only one node, the result current zoom goes i.e. to 7.
IGraphInfo graphinfo = pRoute.Info as IGraphInfo;
graphinfo.Commands.FitToPage.Execute(new FitToPageParameter()
{
    Margin = new Thickness(15),
    FitToPage = FitToPage.FitToPage
});

How can I execute FitToPage and at the same time limit the result to not exceed the Zoom Factor of 2.  Is It possible?

5 Replies 1 reply marked as answer

KR Karkuvel Rajan Shanmugavel Syncfusion Team January 18, 2021 06:16 AM UTC

Hi Lopez, 
 
Requirement: Need to limit the Current Zoom Value when we execute FitToPage with single Node in the Diagram. 
 
We can control the CurrentZoom value when we execute FitToPage with SingleNode in the Diagram with CanZoomIn property of the FitToPageParameter. In SfDiagram, if we have elements with their boundary region is small when compared  to viewport region we have done the ZoomIn operation and fit the small diagram into the page when execute FitToPage. If you don’t want this behavior the please set the CanZoomIn property of the FitToPageParameter as false. 
 
Please find the code example below. 
 
 
            (Diagram.Info as IGraphInfo).Commands.FitToPage.Execute(new FitToPageParameter()  
            {  
                FitToPage = FitToPage.FitToPage,  
                Margin = new Thickness(15),  
                CanZoomIn = false 
            }); 
 
 
Please find more details about fit to page command in below page. 
 
 
Regards, 
Karkuvel Rajan S 



FL Francisco Lopez January 19, 2021 01:55 AM UTC

Hi Karkuvel ,
I have tried as you suggested but it doesn't work.  
As you can see in the following image, if I have a single node, it gets zoomed using the maximum vertical/horizontal space available which doesn't look good (Current Zoom Factor after FitToPage command is 11).


What I want to is to limit the maximum zoom factor, so i.e. when I execute the FitToPage command, it should only zoom the diagram up to zoom factor = 2.  The following image show my diagram after zoomed manually (Ctrl + Mouse Scroll) to ZoomFactor = 2.


Thanks in advance.



KR Karkuvel Rajan Shanmugavel Syncfusion Team January 19, 2021 09:55 AM UTC

Hi Lopez, 
 
Requirement: Need to limit the Current Zoom value when we execute FitToPage with single node in the Diagram. 
 
From the provided images we assume that you have tried to execute FitToPage with the max zoom of 2. But when execute FitToPage the current zoom value goes above the max zoom value. In our control we have only used the FitToPage command to fit the diagram objects into the page irrespective of the Min and Max Zoom values. This is the default behavior in Visio too. So for your requirement we have provided a solution with  the ZoomCommand and FitToPage command. Please find the sample in below link. 
 
 
Sample Description: In the above sample we have used the ViewPortChanged event to get the viewport and content bounds value. With those values we are able to calculate the zoom value. With that zoom value we have decide whether to execute Zoom command or FitToPage command.  
 
Regards, 
Karkuvel Rajan S  


Marked as answer

FL Francisco Lopez January 19, 2021 03:53 PM UTC

Hi Karkuvel,

I implement some changes base on the solutions you provided me and it is working in the way I wanted.
Thanks for your help and prompt reply

Regards,
Francisco


KR Karkuvel Rajan Shanmugavel Syncfusion Team January 20, 2021 04:22 AM UTC

Hi Lopez, 
 
We are glad that your query is resolved, Please let us know if you need any further assistance. 
 
Regards, 
Karkuvel Rajan S 


Loader.
Up arrow icon