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
you should use
mxGraph.zoomTo(value)
https://jgraph.github.io/mxgraph/docs/js-api/files/view/mxGraph-js.html#mxGraph.zoomTo
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.