如何在我自己的按钮中触发 mxGraph 放大和缩小功能?

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

我已经使用 mxGraph 开发了图表应用程序。在图表编辑器中,我有自己的放大和缩小按钮,如下所示。

我的问题是如何在我自己的 in/zoom 缩小按钮中调用以下 mxGrpah 函数?

/**
 * 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);
    }
};

你应该使用

mxGraph.zoomTo(value)

https://jgraph.github.io/mxgraph/docs/js-api/files/view/mxGraph-js.html#mxGraph.zoomTo

我完全忘记使用我用于所有图形操作的图形对象。 由于图形已经配备了 ZoomIn() 和 ZoomOut() 方法。

我刚刚打了如下电话

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

//universalGraph is my graph object variable