简体   繁体   中英

How to trigger mxGraph zoomin and zoomout functions in my own buttons?

I have developing the diagramming application using mxGraph. In the diagram editor I've my own zoom in and zoom out buttons as below.

放大 缩小

My question is how to call the following mxGrpah functions in my own zoom in/zoom out buttons?

/**
 * Function: zoomIn
 * 
 * Zooms into the graph by <zoomFactor>.
 */
Graph.prototype.zoomIn = function() {
    // Switches to 1% zoom steps below 15%
    if (this.view.scale < 0.15) {
        this.zoom((this.view.scale + 0.01) / this.view.scale);
    } else {
        // Uses to 5% zoom steps for better grid rendering in webkit
        // and to avoid rounding errors for zoom steps
        this.zoom((Math.round(this.view.scale * this.zoomFactor * 20) / 20) / this.view.scale);
    }
};

/**
 * Function: zoomOut
 * 
 * Zooms out of the graph by <zoomFactor>.
 */
Graph.prototype.zoomOut = function() {
    // Switches to 1% zoom steps below 15%
    if (this.view.scale <= 0.15) {
        this.zoom((this.view.scale - 0.01) / this.view.scale);
    } else {
        // Uses to 5% zoom steps for better grid rendering in webkit
        // and to avoid rounding errors for zoom steps
        this.zoom((Math.round(this.view.scale * (1 / this.zoomFactor) * 20) / 20) / this.view.scale);
    }
};

I totally forgot to use my graph object which one I'm using for all the graph operations. Since the graph already equipped with ZoomIn() and ZoomOut() methods.

I just called as below.

universalGraph.zoomIn();
universalGraph.zoomOut();

//universalGraph is my graph object variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM