diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e231bc..4f976ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.11 + +- Adding `scale()` to all shapes +- Adding `scale()` to groups + ## 0.2.10 - Removing colorString library to shrink size of library. diff --git a/package.json b/package.json index e70f340..de74bff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rune.js", - "version" : "0.2.10", + "version" : "0.2.11", "description": "A JavaScript library for programming graphic design systems with SVG", "repository": { "type": "git", diff --git a/src/group.js b/src/group.js index 131697a..1ffdf3e 100644 --- a/src/group.js +++ b/src/group.js @@ -1,5 +1,6 @@ import without from "lodash/array/without" import assign from "lodash/object/assign" +import each from "lodash/collection/each" import { Moveable } from "./mixins" import Utils from './utils' import Vector from './vector' @@ -35,6 +36,15 @@ class Group { return copy; } + scale(scalar) { + each(this.children, function(child) { + child.vars.x *= scalar; + child.vars.y *= scalar; + child.scale(scalar); + }); + return this; + } + } // Should we figure out a better way to do mixins for ES6? diff --git a/src/shapes/circle.js b/src/shapes/circle.js index 42b149a..54ea001 100644 --- a/src/shapes/circle.js +++ b/src/shapes/circle.js @@ -24,6 +24,7 @@ class Circle { scale(scalar) { this.vars.radius *= scalar; + return this; } copy(parent) { diff --git a/src/shapes/ellipse.js b/src/shapes/ellipse.js index 20b3390..9022d00 100644 --- a/src/shapes/ellipse.js +++ b/src/shapes/ellipse.js @@ -44,6 +44,7 @@ class Ellipse { scale(scalar) { this.vars.width *= scalar; this.vars.height *= scalar; + return this; } copy(parent) { diff --git a/src/shapes/line.js b/src/shapes/line.js index bbbb3e3..43b5ba5 100644 --- a/src/shapes/line.js +++ b/src/shapes/line.js @@ -29,6 +29,7 @@ class Line { var vec = end.sub(start).multiply(scalar).add(start); this.vars.x2 = vec.x; this.vars.y2 = vec.y; + return this; } } diff --git a/src/shapes/path.js b/src/shapes/path.js index 39b52f4..f338bc0 100644 --- a/src/shapes/path.js +++ b/src/shapes/path.js @@ -175,6 +175,7 @@ class Path { this.vars.anchors = map(this.vars.anchors, function(anchor) { return anchor.multiply(scalar); }); + return this; } fillRule(val) { this.vars.fillRule = val; return this; } diff --git a/src/shapes/polygon.js b/src/shapes/polygon.js index 5662b61..6bfb88f 100644 --- a/src/shapes/polygon.js +++ b/src/shapes/polygon.js @@ -182,6 +182,7 @@ class Polygon { this.vars.vectors = map(this.vars.vectors, function(vec) { return vec.multiply(scalar); }); + return this; } } diff --git a/src/shapes/rectangle.js b/src/shapes/rectangle.js index 6892e4b..c53a0e2 100644 --- a/src/shapes/rectangle.js +++ b/src/shapes/rectangle.js @@ -40,6 +40,7 @@ class Rectangle { scale(scalar) { this.vars.width *= scalar; this.vars.height *= scalar; + return this; } } diff --git a/src/shapes/text.js b/src/shapes/text.js index 1bc5059..cab7fa9 100644 --- a/src/shapes/text.js +++ b/src/shapes/text.js @@ -42,6 +42,7 @@ class Text { scale(scalar) { this.vars.fontSize *= scalar; + return this; } } diff --git a/src/shapes/triangle.js b/src/shapes/triangle.js index 81e10c5..4f39873 100644 --- a/src/shapes/triangle.js +++ b/src/shapes/triangle.js @@ -35,6 +35,7 @@ class Triangle { this.vars.y2 *= scalar; this.vars.x3 *= scalar; this.vars.y3 *= scalar; + return this; } } diff --git a/test/shared/group.js b/test/shared/group.js index 1456f45..7cc75ad 100644 --- a/test/shared/group.js +++ b/test/shared/group.js @@ -105,4 +105,24 @@ describe("Rune.Group", function() { }); + describe("scale()", function() { + + it("scales children groups and shapes", function() { + var g = new Rune.Group(10, 15); + var childGroup = new Rune.Group(20, 25); + var childShape = new Rune.Circle(30, 35, 40); + g.add(childGroup); + g.add(childShape); + g.scale(2); + expect(g.vars.x).toEqual(10); + expect(g.vars.y).toEqual(15); + expect(childGroup.vars.x).toEqual(40); + expect(childGroup.vars.y).toEqual(50); + expect(childShape.vars.x).toEqual(60); + expect(childShape.vars.y).toEqual(70); + expect(childShape.vars.radius).toEqual(80); + }); + + }); + });