From 843bc5abcd0945a77362207d44b73128a8d86a3b Mon Sep 17 00:00:00 2001 From: Alessio Carrafa Date: Thu, 26 Sep 2019 17:52:13 +0200 Subject: [PATCH] added zoom and zoomBy call forward to svg-pan-zoom api --- src/SvgPanZoom.vue | 77 ++++++++++++++++++++++++++------------------ src/SvgPanZoomApi.js | 6 ++++ 2 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 src/SvgPanZoomApi.js diff --git a/src/SvgPanZoom.vue b/src/SvgPanZoom.vue index 1b42811..1ac3760 100644 --- a/src/SvgPanZoom.vue +++ b/src/SvgPanZoom.vue @@ -23,43 +23,56 @@ import { EventBus } from './EventBus'; import SvgPanZoomThumbnail from './SvgPanZoomThumbnail.vue'; +import { SvgPanZoomApi } from './SvgPanZoomApi'; + export default { - props, - components: { SvgPanZoomThumbnail }, - computed: { - has_thumbnail: function() { return this.$slots.thumbnail }, - options: function() { - let options = {}; + components: { SvgPanZoomThumbnail }, + props, + computed: { + has_thumbnail: function() { return this.$slots.thumbnail }, + options: function() { + let options = {}; - const is_defined = k => this[k] !== undefined; + const is_defined = k => this[k] !== undefined; - Object.keys(props) - .filter( is_defined ) - .forEach( k => options[k] = this[k] ); + Object.keys(props) + .filter( is_defined ) + .forEach( k => options[k] = this[k] ); - return options; - } + return options; + } + }, + data: () => ({ + spz: null, + bus: EventBus() + }), + mounted: function() { + let options = {}; + + Object.keys(props).filter( k => this[k] !== undefined ).forEach( k => options[k] = this[k] ); + + options.onZoom = (...args) => { + this.bus.$emit( 'mainZoom' ); + if( this.onZoom ) this.onZoom(args); + }; + + options.onPan = (...args) => { + this.bus.$emit( 'mainPan' ); + if( this.onPan ) this.onPan(args); + }; + + this.spz = svg_pan_zoom( this.$slots.default[0].elm , options ); + + this.$emit( 'svgpanzoom', this.spz ); + }, + methods: { + zoom: function( v ){ + this.spz.zoom( v ); }, - mounted: function() { - let options = {}; - - Object.keys(props).filter( k => this[k] !== undefined ).forEach( k => options[k] = this[k] ); - - options.onZoom = (...args) => { - this.bus.$emit( 'mainZoom' ); - if( this.onZoom ) this.onZoom(args); - }; - - options.onPan = (...args) => { - this.bus.$emit( 'mainPan' ); - if( this.onPan ) this.onPan(args); - }; - - this.spz = svg_pan_zoom( this.$slots.default[0].elm , options ); - - this.$emit( 'svgpanzoom', this.spz ); - }, - data: () => ({ spz: null, bus: EventBus() }), + zoomBy: function( v ){ + this.spz.zoomBy( v ); + } + } }; diff --git a/src/SvgPanZoomApi.js b/src/SvgPanZoomApi.js new file mode 100644 index 0000000..8959641 --- /dev/null +++ b/src/SvgPanZoomApi.js @@ -0,0 +1,6 @@ +export const SvgPanZoomApi = ( SvgPanZoomInstance ) => ({ + zoom: function( v ){ + SvgPanZoomInstance.zoom( v ); + }, + zoomBy: ( v ) => SvgPanZoomInstance.zoomBy( v ) +});