Reset Zoom

How to reset the diagram to the initial view programmatically?

Suppose, i have zoomed-in and now want go back to the original view which was visible firstly, when diagram was loaded.

Original View:

Zoomed-In View:

Required Reset View (Original View):

You’ll have to save the diagram position and scale after loading in order to set them back. Of course the view might not look the same or might not be possible if your users have moved objects.

Note that CommandHandler has resetZoom, also. (myDiagram.commandHandler.resetZoom()) The user can type Ctrl-0 to invoke that command.

Thanks @simon!

Let me check this out.

Thanks @simon!

Here, myDiagram.commandHandler.resetZoom() works for me.

Is it possible to reset position as well ?

if yes, how?

Did you try what Simon suggested earlier in this topic?

Sorry, couldn’t do that.

Could you please suggest how to save the position and restore it back?

Remember the values of Diagram.scale and Diagram.position in two variables. When you want to restore those two properties, set Diagram.scale first, because changing the scale is likely to change the Diagram.position.

Thanks @walter

This solution : myDiagram.commandHandler.resetZoom(), and, save-restore Diagram.scale and Diagram.position values works for me.