vue-svg-pan-zoom/README.md

140 lines
4.1 KiB
Markdown
Raw Permalink Normal View History

2018-01-15 23:32:25 +00:00
# vue-svg-pan-zoom : Vue component for SVG-Pan-Zoom
2018-01-23 01:12:54 +00:00
This module is a very simple [Vue](https://vuejs.org/) component providing the
goodness of [SVG-Pan-Zoom](https://github.com/ariutta/svg-pan-zoom) for SVG elements.
2018-01-15 23:32:25 +00:00
2018-01-23 00:58:11 +00:00
/!\ WARNING: the module is young, basic, probably will have its
API change with no notice, and likely to have
2018-01-15 23:32:25 +00:00
bugs. Use at your own risk, send patches for my eternal gratitude.
## Basic Use
In a Single File Component:
<template>
<SvgPanZoom
style="width: 500px; height: 500px; border:1px solid black;"
:zoomEnabled="true"
:controlIconsEnabled="true"
:fit="false"
:center="true"
>
<svg>
<circle x="10" y="10" r="5" />
</svg>
</SvgPanZoom>`
</template>
<script>
import SvgPanZoom from 'vue-svg-pan-zoom';
export default {
components: { SvgPanZoom },
};
</script>
### Notes
2018-03-16 16:24:59 +00:00
Currently the `SvgPanZoom` component only works with a `svg` child -- `embed` won't work.
2018-01-15 23:32:25 +00:00
2018-03-16 16:24:59 +00:00
### Props
`SvgPanZoom` accepts as props all `svg-pan-zoom` options:
2018-01-15 23:32:25 +00:00
2018-01-23 00:58:11 +00:00
| attribute | default |
| --------- | -------- |
| zoomEnabled | true |
| controlIconsEnabled | false |
| fit | true |
| panEnabled | true |
| dblClickZoomEnabled | true |
| mouseWheelZoomEnabled | true |
| preventMouseEventsDefault | true |
| contain | false |
| center | true |
| viewportSelector | .svg-pan-zoom_viewport |
| zoomScaleSensitivity | 0.2 |
| minZoom | 0.5 |
| maxZoom | 10 |
| refreshRate | auto |
| beforeZoom | |
| onZoom | |
| beforePan | |
| onPan | |
| onUpdatedCTM | |
| customEventsHandler | |
| eventsListenerElement | |
2018-01-15 23:32:25 +00:00
2018-03-16 16:24:59 +00:00
### svgpanzoom object
To access the created `svgpanzoom` javascript object, you can
listen to the `svgpanzoom` event on the `SvgPanZoom` component.
```js
<template>
<div>
<input type="button" value="center me" @click="center" />
<SvgPanZoom style="width: 500px; height: 500px; border:1px solid black;"
:fit="false"
@svgpanzoom="registerSvgPanZoom"
>
<RawTiger />
</SvgPanZoom>
</div>
</template>
<script>
import RawTiger from './RawTiger.vue';
import SvgPanZoom from 'vue-svg-pan-zoom';
export default {
components: { SvgPanZoom, RawTiger },
data: () => ({ svgpanzoom: null }),
methods: {
registerSvgPanZoom(svgpanzoom) {
this.svgpanzoom = svgpanzoom;
},
center() {
if( !this.svgpanzoom ) return;
this.svgpanzoom.center();
}
},
}
</script>
```
2018-01-15 23:32:25 +00:00
## Use with thumbnails
In a Single File Component:
<template>
<SvgPanZoom
style="width: 300px; height: 500px; border:1px solid black; "
>
<svg> ... </svg>
<svg slot="thumbnail"> ... </svg>
2018-01-15 23:32:25 +00:00
</SvgPanZoom>
</template>
<script>
import SvgPanZoom from 'vue-svg-pan-zoom';
2018-01-15 23:32:25 +00:00
export default {
components: { SvgPanZoom },
2018-01-15 23:32:25 +00:00
};
</script>
Just like the main `SvgPanZoom`component, the `thumbnail` slot needs to
2018-01-23 00:58:11 +00:00
be assigned to a `svg` node -- `embed` won't work.
2018-01-15 23:32:25 +00:00
### Storybook demos
2018-01-23 01:02:52 +00:00
To run [Storybook](https://github.com/storybooks/storybook) stories duplicating the demos of
2018-01-15 23:32:25 +00:00
the main `SVG-Pan-Zoom` project, do
$ yarn install --dev
$ yarn storybook