Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Calculate and set ZoomFactor dynamically based on the size of the graph (Read 1511 times)
LGK
YaBB Newbies
*
Offline



Posts: 30
Location: Boston, MA
Joined: Mar 29th, 2012
Calculate and set ZoomFactor dynamically based on the size of the graph
May 10th, 2012 at 6:38pm
Print Post  
What would be the correct approach to calculate the ZoomFactor of the diagram based on the size of the graph? The goal is to display a complete view of the entire graph on page load in the case when the graph is too large to fit nicely within the specified diagram div box.

Consider the following scenario:

  1. I have set the Diagram height and width to 800px and 600px (respectively).
  2. I have a large diagram consisting of 50+ nodes and ZoomFactor=100.

This setup would require the user to either use the scroll bars of the diagram's DIV, or zoom out in order to explore the graph. Instead, I would like to dynamically recalculate and set the ZoomFactor of the diagram, so that when the page is loaded, the user would be able to see the entire large graph at a glance (although the nodes may end up very tiny for large graphs).

Many thanks!
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Calculate and set ZoomFactor dynamically based on the size of the graph
Reply #1 - May 11th, 2012 at 5:50am
Print Post  
It should look like this ~

Code
Select All
var viewRect = view.ClientToDoc(new Rectangle(800, 600));
var sx = viewRect.Width / diagram.Bounds.Width;
var sy = viewRect.Height / diagram.Bounds.Height;
var newZoom = Math.Min(sx, sy) * 100;
if (newZoom < 100)
    view.ZoomFactor = newZoom; 

  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint