All Projects → hueitan → Snap.svg.zpd

hueitan / Snap.svg.zpd

Licence: other
A zoom/pan/drag/rotate plugin for Snap.svg (useful for view only)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Snap.svg.zpd

use-gesture
👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.
Stars: ✭ 6,624 (+5466.39%)
Mutual labels:  drag, zoom
Flutter advanced networkimage
flutter advanced network image provider
Stars: ✭ 282 (+136.97%)
Mutual labels:  svg, zoom
Snap.svg
The JavaScript library for modern SVG graphics.
Stars: ✭ 13,346 (+11115.13%)
Mutual labels:  svg, snap
Plain Draggable
The simple and high performance library to allow HTML/SVG element to be dragged.
Stars: ✭ 362 (+204.2%)
Mutual labels:  svg, drag
React Prismazoom
A pan and zoom component for React, using CSS transformations.
Stars: ✭ 29 (-75.63%)
Mutual labels:  drag, zoom
Panzoom
A library for panning and zooming elements using CSS transforms 🔍
Stars: ✭ 1,593 (+1238.66%)
Mutual labels:  svg, zoom
subjx
Drag/Resize/Rotate Javascript library
Stars: ✭ 155 (+30.25%)
Mutual labels:  snap, drag
React Use Gesture
👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.
Stars: ✭ 5,704 (+4693.28%)
Mutual labels:  drag, zoom
React Svg Pan Zoom
👀 A React component that adds pan and zoom features to SVG
Stars: ✭ 569 (+378.15%)
Mutual labels:  svg, zoom
Panzoom
Universal pan and zoom library (DOM, SVG, Custom)
Stars: ✭ 1,003 (+742.86%)
Mutual labels:  svg, zoom
Blazor.diagrams
A fully customizable and extensible all-purpose diagrams library for Blazor
Stars: ✭ 119 (+0%)
Mutual labels:  svg, drag
Interact.js
JavaScript drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE9+)
Stars: ✭ 10,561 (+8774.79%)
Mutual labels:  snap
Elemental2
Type checked access to browser APIs for Java code.
Stars: ✭ 115 (-3.36%)
Mutual labels:  svg
Vue Graph
⚡️ Vue components based on the JUI chart available in Vue.js
Stars: ✭ 114 (-4.2%)
Mutual labels:  svg
Mocodo
Modélisation Conceptuelle de Données. Nickel. Ni souris.
Stars: ✭ 113 (-5.04%)
Mutual labels:  svg
Teenyicons
Tiny minimal 1px icons designed to fit in the smallest places.
Stars: ✭ 1,631 (+1270.59%)
Mutual labels:  svg
Tabler Icons
A set of over 1400 free MIT-licensed high-quality SVG icons for you to use in your web projects.
Stars: ✭ 10,858 (+9024.37%)
Mutual labels:  svg
Svgdragtree
一个可以通过拖放 SVG 图标,来生成拥有树状结构的视图与数据的前端组件。 SDT example:
Stars: ✭ 113 (-5.04%)
Mutual labels:  svg
React Smooth Dnd
react wrapper components for smooth-dnd
Stars: ✭ 1,560 (+1210.92%)
Mutual labels:  drag
Leader Line
Draw a leader line in your web page.
Stars: ✭ 1,872 (+1473.11%)
Mutual labels:  svg

snap.svg.zpd

A zoom/pan/drag plugin for Snap.svg

This is an adaptation of Andrea Leofreddi's SVGPan library, version 1.2.2, for use as a Snap.svg plugin.

This usually use on present view only. NOT for the purpose of Storing or Modifying the paper.

DEMO DEMO2 DEMO3

In the Wild

Drop me an issue/PR for the showcase

Install

$ npm install snap.svg.zpd --save

How The Plugin Works

The plugin will put all child elements in the svg into a group-element and apply the "global transformations" to this group - like zooming, panning or rotating the whole canvas.

When dragging is enabled, the respective transformations will be applied directly to the element that is under the mouse-cursor.

Svg manipulations after applying the plugin should take part inside of the zpd group. I.e. if you would like to add a new element that should inherit zooming and panning, you should not add it directly to the svg, but to the zpd-group within.

Usage

Include snap.svg.zpd.js after snap.svg.js

<script src="snap.svg.js"></script>
<script src="snap.svg.zpd.js"></script>

Writing the script

var paper = Snap();
var bigCircle = paper.circle(150, 150, 100);
paper.zpd();

// with options and callback
paper.zpd(options, function (err, paper) {
    console.log(paper);
});

// with callback
paper.zpd(function (err, paper) {
    console.log(paper);
});

options

zoom

true or false: enable or disable zooming (default true)

pan

true or false: enable or disable panning (default true)

panDirections

"both" | "horizontal" | "vertical": determines which axes will support panning (default "both")

drag

true or false: enable or disable dragging (default false)

zoomScale

number: Zoom sensitivity (default 0.2)

zoomThreshold

array: min and max zoom level threshold [min, max] (default null)

touch

true or false: enable or disable touch support (default true)

preventDefaultEvent

true or false: enable or disable call to preventDefault in events (default true)
or an object with these values:
    - `handleMouseOrTouchUp`: true or false: enable or disable call to preventDefault for this particular event (default true)
    - `handleMouseOrTouchDown`: true or false: enable or disable call to preventDefault for this particular event (default true)
    - `handleMouseMove`: true or false: enable or disable call to preventDefault for this particular event (default true)
    - `handleMouseWheel`: true or false: enable or disable call to preventDefault for this particular event (default true)
    - `handleTouchMove`: true or false: enable or disable call to preventDefault for this particular event (default true)

if defined as a boolean every value of the object will take the defined value

WARNING : using this option can lead to unexpected behavior.

More

paper.zpd('destroy')

paper.zpd('destroy');
Destroy all the zpd elements, events and nodes

paper.zpd('save')

paper.zpd('save');
// => return SVGMatrix {a:0.6787972450256348,b:0,c:0,d:0.6787972450256348,e:159.63783264160156,f:12.84811782836914}

paper.zpd('save', function (err, data) {
    console.log(data);
    // => return SVGMatrix {a:0.6787972450256348,b:0,c:0,d:0.6787972450256348,e:159.63783264160156,f:12.84811782836914}
});
return current <g> transform attribute (matrix) - only in pan,zoom, not for drag now

paper.zpd({ load: SVGMatrix {}})

paper.zpd({ load: {a:0.6787972450256348,b:0,c:0,d:0.6787972450256348,e:159.63783264160156,f:12.84811782836914}});
set the initial <g> transform matrix

paper.zpd('origin')

paper.zpd('origin');
back to the origin location

paper.zpd('toggle')

paper.zpd('toggle');
paper.zpd('toggle', function (err, state) { console.log(state); }); // return current enable state
By default, zpd is enabled, but you can toggle or set its activation using this function. (Useful to toggle mouse event (zpd))

zoomTo

paper.zoomTo(1.5, 3000, mina.bounce, function (err, paper) {
    console.log(paper);
});
zoom (must > 0), interval (ms optional), mina (optional), callback (optional)

panTo

paper.panTo('-1'); // go left -1 x location
paper.panTo('+0', '-1'); // go up -1 y location
paper.panTo(100,100); // go to location (x, y) (100, 100)
paper.panTo(100, 100, 3000, mina.bounce, function (err, paper) {
    console.log(paper);
});
x, y (can be number or string with + -), interval (ms optional), mina (optional), callback (optional)

rotate

paper.rotate(15);
paper.rotate(a, x, y, mina.bounce, function (err, paper) {
    console.log(paper);
});
a (rotate degree) x, y (original point), interval (ms optional), mina (optional), callback (optional)

Experimental: Edit

to add an element to the transformation matrix. select the group that contains the matrix

canvas = Snap.select('#snapsvg-zpd-'+paper.id);

create an element and add

canvas.add(element);

understanding the matrix

Basic concepts of matrix

to get the current matrix

paper.zpd('save');

return

SVGMatrix {
    a: zoom,
    b: 0,
    c: 0,
    d: zoom,
    e: offset X,
    f: offset Y
}

if you need to map one point, for example event.click (x, y)

matrix X = (original X + offsetX) / zoom
matrix Y = (original Y + offsetY) / zoom

Contributor List

Huei Tan
Ramon Saccilotto
and you!

Reference

svgpan
raphael-zpd
svg-pan-zoom

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].