vue-diagram-editor icon indicating copy to clipboard operation
vue-diagram-editor copied to clipboard

How to access and call the methods for zooming

Open mickey58github opened this issue 3 years ago • 5 comments

Hi, your Vue diagram editor is an excellent piece of work! I would like to call the methods for zooming from a button in my code. I have installed your vue-diagram-editor NPM package and it works fine. Your API docs refers to the methods of package "svg-pan-zoom", but it remains unclear to me how I can invoke those methods. Could you update your API doc or paste here an example how to access this other package and call those zooming methods, like zoom() or zoomBy()? Thanks, Michael

mickey58github avatar May 05 '21 21:05 mickey58github

Hi @mickey58github. I apologize for the delay. Indeed, not all the mods from the "svg-pan-zoom" library have been proxied yet. I will try to add them in the future. While you can do this hack:

if (this.$refs.diagram.$refs.diagram.spz) {
    this.$refs.diagram.$refs.diagram.spz.zoom();
}

max-kut avatar May 11 '21 17:05 max-kut

Hi, @max-kut - thanks for taking care of my question. I'll try this out - though my experience is that code that relies on $refs is sometimes unreliable, especially during initial loading of a page/component, when the $refs get assigned in some rather mysterious order and timing ;-)

mickey58github avatar May 11 '21 17:05 mickey58github

I totally agree. I think you can expand the condition a little (it's still a hack):

if (this.$refs.diagram && this.$refs.diagram.$refs.diagram &&  this.$refs.diagram.$refs.diagram.spz) {
    this.$refs.diagram.$refs.diagram.spz.zoom();
}

max-kut avatar May 11 '21 17:05 max-kut

Thanks. Honestly, I don't understand yet what these nested $refs do, like .$refs.diagram.$refs.diagram - can you elaborate on that a bit'?

mickey58github avatar May 11 '21 17:05 mickey58github

About of $refs

max-kut avatar May 12 '21 06:05 max-kut