user2368558
user2368558

Reputation: 81

Can we restrict the zoom level in mxGraph?

I am using mxGraph to create some workflows in my application. By default the zoom In factor is 1.2. I want to restrict zooming after a certain level. How can this be achieved ?

Here goes my JSNI code:

  private native void zoomInGraph(JavaScriptObject graph) /*-{
        var scale = $wnd.mxGraphView.prototype.getScale();
        if (scale != null && scale < 5){
             graph.zoomIn();
  }
         }-*/;

Everytime scale returns the value as 1. I assumed after zooming in the scale value would change. Please suggest how can I achieve it.

Upvotes: 1

Views: 2353

Answers (2)

Younes Meridji
Younes Meridji

Reputation: 309

This is my solution in java:

void zoomIn(){
   if(scale < 5 && scale > 0)
       graph.getView.setScale(scale);
}

Upvotes: 0

Lucas
Lucas

Reputation: 2652

I figured out the solution to this question in Java.

@Override
public void zoomIn()
{
    mxGraphView view = graph.getView();
    double scale = view.getScale();
    if (scale > ZOOM_IN_THRESHOLD)
    { 
        // Don't zoom in past a certain point.
        return;
    }
    else
    {
        zoom(zoomFactor);
    }
}

Upvotes: 0

Related Questions