Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
32d7e14
Updating to latest Snap version
ibrierley Feb 11, 2017
a3d26ae
Fixed transforms on applied element
ibrierley Feb 11, 2017
a70ca5a
updated example
ibrierley Feb 11, 2017
4ea33d8
Updated README with Raphael original examples
ibrierley Feb 11, 2017
7611b8d
updated quotes
ibrierley Feb 11, 2017
bce536c
updated link
ibrierley Feb 11, 2017
a804fc9
testing change
ibrierley Feb 12, 2017
098a30c
fix on v2
ibrierley Feb 12, 2017
252d117
fixes for ft
ibrierley Feb 12, 2017
b0eb881
fixed putting orig transform when showing handles
ibrierley Feb 12, 2017
1d5b2c4
fixed bug with elements without transforms not working correct
ibrierley Feb 14, 2017
2013918
fixed bug with elements without transforms not working correct
ibrierley Feb 14, 2017
dce90fd
rewrote the basic drag stuff to try and account for transforms
ibrierley Feb 17, 2017
fee0ea0
testing loaded objects with transforms
ibrierley Feb 17, 2017
0f450cb
test example to load
ibrierley Feb 17, 2017
d3c4dad
fixes for nested transforms
ibrierley Feb 20, 2017
83eb3cd
testing svg
ibrierley Mar 1, 2017
c728cfd
latest updates fixing transforms
ibrierley Mar 1, 2017
1f9423d
added discDistance option
ibrierley Mar 2, 2017
af5a87a
added 2nd axis in
ibrierley Mar 2, 2017
6c72f3f
Merge branch 'master' of https://github.com/ibrierley/Snap.svg.FreeTr…
ibrierley Mar 2, 2017
167084a
added 2nd axis
ibrierley Mar 2, 2017
b069d28
Merge branch 'master' of https://github.com/ibrierley/Snap.svg.FreeTr…
ibrierley Mar 2, 2017
8d66d46
latest fixes from dev
ibrierley Mar 15, 2017
41d73a4
Merge branch 'master' of https://github.com/ibrierley/Snap.svg.FreeTr…
ibrierley Mar 15, 2017
44028be
Update README.md
ibrierley Jul 29, 2022
4b0c8f1
Create FUNDING.yml
ibrierley Jul 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ko_fi: ian00
157 changes: 156 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,161 @@
Snap.svg.FreeTransform
====================

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/F1F8E2YBE)

Free transform tool for [Snap.svg](http://snapsvg.io/) elements and sets with many options. Supports snap-to-grid dragging, scaling and rotating with a specified interval and range.

*Licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).*
Example can be found at http://svg.dabbles.info/Snap.svg.FreeTransform/

Raphael version that this was based from can be found at https://github.com/AliasIO/Raphael.FreeTransform

Forked from https://github.com/danny-toi/Snap.svg.FreeTransform (will try and feed back updates)


Options
-------

#### `animate: true | { delay: num, easing: string } | false`

Animate transformations. Works best in combination with `apply()` (see the functions section below).

Default: `{ delay: 700, easing: 'linear' }`


#### `attrs: { fill: hex, stroke: hex }`

Sets the attributes of the handles.

Default: `{ fill: '#fff', stroke: '#000' }`


#### `customCorners: { size: num, distance: num, corners: [ { action: string: image: string }, ... ] } | false

Specify custom images and events for corner handles.

The corners array should contain 4 objects, one for each corner starting top left going clockwise.

Valid actions: `drag`, `rotate`, `scale` or a custom string. Actions are emitted as events in the callback.

Default: `false`


#### `boundary: { x: int, y: int, width: int, height: int } | false`

Limits the drag area of the handles.

Default: dimensions of the paper


#### `distance: num`

Sets the distance of the handles from the center of the element (`num` times radius).

Default: `1.3`


#### `drag: true | [ 'center', 'self' ] | false`

Enables/disables dragging.

Default: `[ 'center', 'self' ]`


#### `draw: [ 'bbox', 'circle' ]`

Additional elements to draw.

Default: `false`


#### `keepRatio: true | [ 'axisX', 'axisY', 'bboxCorners', 'bboxSides' ] | false`

Scale axes together or individually.

Default: `false`


#### `range: { rotate: [ num, num ], scale: [ num, num ] }`

Limit the range of transformation.

Default: `{ rotate: [ -180, 180 ], scale: [ 0, 99999 ] }`


#### `rotate: true | [ 'axisX', 'axisY', 'self' ]|false`

Enables/disables rotating.

Default: `[ 'axisX', 'axisY' ]`


#### `scale: true | [ 'axisX', 'axisY', 'bboxCorners', 'bboxSides' ] | false`

Enables/disables scaling.

Default: `[ 'axisX', 'axisY', 'bboxCorners', 'bboxSides' ]`


#### `snap: { rotate: num, scale: num, drag: num }`:

Snap transformations to num degrees (rotate) or pixels (scale, drag).

Default: `{ rotate: 0, scale: 0, drag: 0 }`


#### `snapDist: { rotate: num, scale: num, drag: num }`

Snap distance in degrees (rotate) or pixels (scale, drag).

Default: `{ rotate: 0, scale: 0, drag: 7 }`


#### `size: num | { axes: num, bboxCorners: num, bboxSides: num, center: num }`

Sets the radius of the handles in pixels.

Default: `5`


Callback
--------

A callback function can be specified to capture changes and events.


Functions
---------

#### `apply()`

Programmatically apply transformations (see the example above).


#### `hideHandles( opts )`

Removes handles but keeps values set by the plugin in memory. By
default removes all drag events from the elements. If you'd like to
keep then while the handles are hidden, pass ``{undrag: false}`` to
hideHandles().


#### `showHandles()`

Shows handles hidden with `hideHandles()`.


#### `setOpts( object, function )`

Update options and callback.


#### `unplug()`

Removes handles and deletes all values set by the plugin.


#### `updateHandles()`

Updates handles to reflect the element's transformations.

*Licensed under the [MIT license](http://www.opensource.org/licenses/mit-license.php).*
25 changes: 22 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,32 @@
<script type="text/javascript">
var paper = Snap('#main-container'),
object = paper
.rect(50, 50, 200, 200)
.rect(50, 50, 100, 50)
.attr({
cursor: 'move',
fill: '#1e609d'
fill: '#1e609d',
transform: 't200,200'
});

paper.freeTransform(object);
var ft = paper.freeTransform(object, { snap: { rotate: 1 }, size: 8, draw: 'bbox' });

ft.attrs.rotate = 45;
ft.attrs.scale.x = 1;
ft.apply();

object.data('ftStatus', 1);

object.dblclick( function() {

if( object.data('ftStatus' ) ) {
ft.hideHandles();
object.data('ftStatus',0);
} else {
ft.showHandles();
object.data('ftStatus',1);
}

});
</script>
</body>
</html>
58 changes: 58 additions & 0 deletions multiple.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<html>
<head>
<title>Free transform tool for Snap.svg elements</title>
<style type="text/css">
#main-container {
position: fixed;
background-color: #ddd;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<svg id="main-container"></svg>

<script src="snap.svg-min.js"></script>
<script src="snap.svg.free_transform.js"></script>

<style>
# .ftdisc { fill: grey; }
# .fthandle { fill: grey; }
# .ftcentercircle { fill: red; }
# .ftbbox { stroke-width: 10; }
# .ftaxisline { stroke-width: 10; }
</style>

<script type="text/javascript">
var s = Snap('#main-container');

Snap.load( "test.svg", function( frag ) {
var g = s.g();
g.append(frag);

var allG = s.selectAll('.myG');

allG.forEach( function( el ) {
var x = s.freeTransform( el, { snap: { rotate: 1 }, size: 8, draw: 'bbox' });
} );

// var allR = s.selectAll('.myrects');

// allR.forEach( function( el ) {
// var x = s.freeTransform( el, { snap: { rotate: 1 }, size: 8, draw: 'bbox' });
// } );



} );


// var ft = paper.freeTransform(object, { snap: { rotate: 1 }, size: 8, draw: 'bbox' });


</script>
</body>
</html>
23 changes: 12 additions & 11 deletions snap.svg-min.js

Large diffs are not rendered by default.

Loading