Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Resizing diagram smaller can go horribly wrong (Read 4694 times)
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Resizing diagram smaller can go horribly wrong
Oct 30th, 2013 at 1:23am
Print Post  
When I use the pinch gesture to make the diagram smaller, it can suddenly start getting smaller and smaller, even though I am no longer moving my fingers. The entire diagram quickly shrinks down to a small square in the upper left corner of the screen, and that's it - there is no way to get it back to a viewable size again.

This on an Acer Iconia B1-A71 tablet running Android 4.1.2 and in landscape orientation.

Edit: More information: It seems to happen when the diagram is initially too large to be shown in the viewing area. When I use the pinch gesture it works fine, making more and more of the diagram visible, until the diagram is completely visible, and then it goes crazy and shrinks down to almost nothing in the upper left corner of the viewing area.

Edit 2: No, it can also happen even if the diagram is initially small enough to be completely visible.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Resizing diagram smaller can go horribly wrong
Reply #1 - Oct 30th, 2013 at 1:18pm
Print Post  
There's 1% lower limit for the zoom level, but I suppose we should factor the diagram.Bounds size in to prevent the zoomed view becoming only a few pixels large. For the time being you could try handling DiagramListener.viewportChanged event and reset ZoomFactor to a larger value if you detect it became too small.
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Resizing diagram smaller can go horribly wrong
Reply #2 - Nov 2nd, 2013 at 4:06am
Print Post  
OK, that seems to work. Here's what I've done:

Code (Java)
Select All
    // Method used to prevent the diagram from shrinking too much when being resized. See here:
    // http://mindfusion.eu/Forum/YaBB.pl?num=1383096222
    @Override
    public void viewportChanged() {
        RectF r = _mindFusionDiagram.getBounds();
        float zoomLimitX = _diagramView.getWidth() / r.width();
        float zoomLimitY = _diagramView.getHeight() / r.height();
        float zoomLimit = Math.min(zoomLimitX,  zoomLimitY) * 100;
        if (zoomLimit > _diagramView.getZoomFactor()) {
            _diagramView.setZoomFactor(zoomLimit);
        }
    }
 



This requires that the DiagramView be defined in the layout with

Code
Select All
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
 



I.e., don't specify "wrap_content" for either width or height.

Only problem with this is that in order to use the viewportChanged() event method you have to define about 80 other methods belonging to the DiagramListener interface. Is there any way to avoid that? (I'm very new to Java.)

Thanks for the solution.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Resizing diagram smaller can go horribly wrong
Reply #3 - Nov 2nd, 2013 at 8:15am
Print Post  
Derive from the DiagramAdapter class, which already provides empty implementations of DiagramListener methods:

Code
Select All
diagram.addDiagramListener(new DiagramAdapter()
{
	@Override
	public void viewportChanged()
	{
	...
	}
}); 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Resizing diagram smaller can go horribly wrong
Reply #4 - Nov 2nd, 2013 at 2:38pm
Print Post  
OK, thanks.
  
Back to top
 
IP Logged
 
Rennie
Full Member
***
Offline


I Love MindFusion!

Posts: 108
Location: Copenhagen, Denmark
Joined: Jul 17th, 2012
Re: Resizing diagram smaller can go horribly wrong
Reply #5 - Nov 6th, 2013 at 1:28pm
Print Post  
Just for the record, this is what I'm doing now:

Code (Java)
Select All
        // Method used to prevent the diagram from shrinking too much when being resized. See here:
        // http://mindfusion.eu/Forum/YaBB.pl?num=1383096222
        @Override
        public void viewportChanged() {
            float currentZoom = _diagramView.getZoomFactor();
            if (currentZoom < 100) {
                RectF r = _mindFusionDiagram.getBounds();
                float zoomLimitX = _diagramView.getWidth() / r.width();
                float zoomLimitY = _diagramView.getHeight() / r.height();
                float zoomLimit = Math.min(zoomLimitX, zoomLimitY) * 100;
                if (zoomLimit > currentZoom) {
                    _diagramView.setZoomFactor(zoomLimit);
                }
            }
        }
 

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