Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2 from mrhatt/master

Translate support and scaling X and Y axis separately
  • Loading branch information...
commit 764f3b1d6f1f8e257fd1e630e381af3e1ee4ba8a 2 parents 5f5e3d2 + c061a4b
@rhyolight rhyolight authored
Showing with 20 additions and 5 deletions.
  1. +2 −0  README
  2. +18 −5 raphael.group.js
View
2  README
@@ -1,3 +1,5 @@
+This is an updated version of the Raphael.group.js plugin. It adds support for moving groups and scaling the X and Y axis independently.
+
WARNING: These plugins were not tested in IE, and I don't care.
These are plugins I've created for the RaphaelJS library (raphaeljs.com) for my own personal use. Feel free to use them as well.
View
23 raphael.group.js
@@ -13,15 +13,15 @@ Raphael.fn.group = function() {
r.canvas.appendChild(group);
- function updateScale(transform, scale) {
- var scaleString = 'scale(' + scale + ')';
+ function updateScale(transform, scaleX, scaleY) {
+ var scaleString = 'scale(' + scaleX + ' ' + scaleY + ')';
if (!transform) {
return scaleString;
}
if (transform.indexOf('scale(') < 0) {
return transform + ' ' + scaleString;
}
- return transform.replace(/scale\(-?[0-9]+(\.[0-9][0-9]*)?\)/, scaleString);
+ return transform.replace(/scale\(-?[0-9]*?\.?[0-9]*?\ -?[0-9]*?\.?[0-9]*?\)/, scaleString);
}
function updateRotation(transform, rotation) {
@@ -34,11 +34,19 @@ Raphael.fn.group = function() {
}
return transform.replace(/rotate\(-?[0-9]+(\.[0-9][0-9]*)?\)/, rotateString);
}
+
+ function updateTranslation(transform, x, y) {
+ var translateString = 'translate(' + x + ' ' + y + ')';
+ if (!transform) {
+ return translateString;
+ }
+ return transform.replace(/translate\(-?[0-9]*?\.?[0-9]*?\ -?[0-9]*?\.?[0-9]*?\)/, translateString);
+ }
inst = {
- scale: function (newScale) {
+ scale: function (newScaleX, newScaleY) {
var transform = group.getAttribute('transform');
- group.setAttribute('transform', updateScale(transform, newScale));
+ group.setAttribute('transform', updateScale(transform, newScaleX, newScaleY));
return this;
},
rotate: function(deg) {
@@ -60,6 +68,11 @@ Raphael.fn.group = function() {
pushOneRaphaelVector(item)
return this;
},
+ translate: function(newTranslateX, newTranslateY) {
+ var transform = group.getAttribute('transform');
+ group.setAttribute('transform', updateTranslation(transform, newTranslateX, newTranslateY));
+ return this;
+ },
getBBox: function() {
return set.getBBox();
},
Please sign in to comment.
Something went wrong with that request. Please try again.