Git Product home page Git Product logo

vue-svg-pan-zoom's Introduction

vue-svg-pan-zoom : Vue component for SVG-Pan-Zoom

This module is a very simple Vue component providing the goodness of SVG-Pan-Zoom for SVG elements.

/!\ WARNING: the module is young, basic, probably will have its API change with no notice, and likely to have 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

Currently the SvgPanZoom component only works with a svg child -- embed won't work.

Props

SvgPanZoom accepts as props all svg-pan-zoom options:

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

svgpanzoom object

To access the created svgpanzoom javascript object, you can listen to the svgpanzoom event on the SvgPanZoom component.

<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>

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>
  </SvgPanZoom>
</template>

<script>
import SvgPanZoom from "vue-svg-pan-zoom";

export default {
  components: { SvgPanZoom }
};
</script>

Just like the main SvgPanZoomcomponent, the thumbnail slot needs to be assigned to a svg node -- embed won't work.

Storybook demos

To run Storybook stories duplicating the demos of the main SVG-Pan-Zoom project, do

$ yarn install --dev
$ yarn storybook

vue-svg-pan-zoom's People

Contributors

alexanderyw avatar smhmd avatar yanick avatar

Watchers

 avatar

Forkers

drantos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.