Skip to content

Commit

Permalink
Fixed #15, also fixed some typos in the documentation and comments. C…
Browse files Browse the repository at this point in the history
…hanged version to 1.0.3
  • Loading branch information
DanielHoffmann committed Oct 12, 2015
1 parent 60c12b8 commit 3ede6b4
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 72 deletions.
53 changes: 37 additions & 16 deletions README.md
Expand Up @@ -13,8 +13,6 @@ jQuery plugin to enable pan and zoom in SVG images either programmatically or th
- Mousewheel zooming keeps the cursor over the same coordinates relative to the image (A.K.A. GoogleMaps-like zoom)
- Limiting the navigable area



# Requirements

jQuery
Expand All @@ -29,22 +27,31 @@ The viewBox is an attribute of SVG images that defines the area of the SVG that
```javascript
var svgPanZoom= $("svg").svgPanZoom(options)
```
If the selection has more than one element `svgPanZoom` will return an array with an SvgPanZoom object for each image in the same order of the selection. If only one element is selected then the return is a single SvgPanZoom object. If no elements are selected the above call returns `null`

If the selection has more than one element `svgPanZoom` will return an array with a SvgPanZoom object for each image in the same order of the selection. If only one element is selected then the return is a single SvgPanZoom object. If no elements are selected the above call returns `null`

The returned SvgPanZoom object contains all options, these options can be overriden at any time directly, for example to disable mouseWheel events simply:

```javascript
svgPanZoom.events.mouseWheel= false
```


the SvgPanZoom object also has methods for manipulating the viewBox programmatically. For example:

```javascript
svgPanZoom.zoomIn()
```

will zoomIn the image using options.zoomFactor.

# Building
This project requires coffeescript to be installed in order to build.

`coffee -m --compile --output compiled/ src/`

# Options

```javascript
Options:
{
Expand All @@ -54,10 +61,10 @@ Options:
drag: boolean (true), // enables drag and drop to move the SVG events
dragCursor: string "move" // cursor to use while dragging the SVG
},
animationTime: number (300) // time in milliseconds to use as default for animations. Set 0 to remove the animation
zoomFactor: 0.25 // how much to zoom-in or zoom-out
maxZoom: 3 //maximum zoom in, must be a number bigger than 1
panFactor: 100 // how much to move the viewBox when calling .panDirection() methods
animationTime: number (300), // time in milliseconds to use as default for animations. Set 0 to remove the animation
zoomFactor: number (0.25), // how much to zoom-in or zoom-out
maxZoom: number (3), //maximum zoom in, must be a number bigger than 1
panFactor: (number (100), // how much to move the viewBox when calling .panDirection() methods
initialViewBox: { // the initial viewBox, if null or undefined will try to use the viewBox set in the svg tag. Also accepts string in the format "X Y Width Height"
x: number (0) // the top-left corner X coordinate
y: number (0) // the top-left corner Y coordinate
Expand All @@ -73,40 +80,50 @@ Options:
}
```
# Methods
#### pan
- pan
```javascript
svgPanZoom.panLeft(amount, animationTime)
svgPanZoom.panRight(amount, animationTime)
svgPanZoom.panUp(amount, animationTime)
svgPanZoom.panDown(amount, animationTime)
```
Moves the SVG viewBox in the specified direction. Parameters:
- amount: Number, optional. How much to move the viewBox, defaults to options.panFactor.
- animationTime: Number, optional. How long the animation should last, defaults to options.animationTime.
#### zoom
- zoom
```javascript
svgPanZoom.zoomIn(animationTime)
svgPanZoom.zoomOut(animationTime)
```
Zooms the viewBox. Parameters:
- animationTime: Number, optional. How long the animation should last, defaults to options.animationTime.
#### reset
- reset
```javascript
svgPanZoom.reset()
```
Resets the SVG to options.initialViewBox values.
#### getViewBox
- getViewBox
```javascript
svgPanZoom.getViewBox()
```
Returns the viewbox in this format:
```javascript
{
x: number
Expand All @@ -116,24 +133,28 @@ Returns the viewbox in this format:
}
```
#### setViewBox
- setViewBox
```javascript
svgPanZoom.setViewBox(x, y, width, height, animationTime)
```
Changes the viewBox to the specified coordinates. Will respect the `options.limits` adapting the viewBox if needed (moving or reducing it to fit into `options.limits`
- x: Number, the new x coodinate of the top-left corner
- y: Number, the new y coodinate of the top-left corner
- width: Number, the new width of the viewBox
- height: Number, the new height of the viewBox
- animationTime: Number, optional. How long the animation should last, defaults to options.animationTime.
#### setCenter
- setCenter
```javascript
svgPanZoom.setCenter(x, y, animationTime)
```
Sets the center of the SVG. Parameters:
- x: Number, the new x coodinate of the center
- y: Number, the new y coodinate of the center
- x: Number, the new x coordinate of the center
- y: Number, the new y coordinate of the center
- animationTime: Number, optional. How long the animation should last, defaults to options.animationTime.
Expand All @@ -143,5 +164,5 @@ Sets the center of the SVG. Parameters:
- Only works in SVGs inlined in the HTML. You can use $.load() to load the SVG image in the page using AJAX and call $().svgPanZoom() in the callback
- Touch pinch events to zoom not yet supported
- This plugin does not create any controls (like arrows to move the image) on top of the SVG. These controls are simple to create manually and they can programmatically call the methods to move the image.
- This plugin does not create any controls (like arrows to move the image) on top of the SVG. These controls are simple to create manually and they can call the methods to move the image.
- Do not manipulate the SVG viewBox attribute manually, use SvgPanZoom.setViewBox() instead
2 changes: 1 addition & 1 deletion bower.json
@@ -1,6 +1,6 @@
{
"name": "jquery-svg-pan-zoom",
"version": "1.0.2",
"version": "1.0.3",
"homepage": "https://github.com/DanielHoffmann/jquery-svg-pan-zoom",
"authors": [
"Daniel Hoffmann Bernardes"
Expand Down
80 changes: 54 additions & 26 deletions compiled/jquery.svg.pan.zoom.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3ede6b4

Please sign in to comment.