Skip to content

Commit

Permalink
updating changelog and making scale chainable
Browse files Browse the repository at this point in the history
  • Loading branch information
runemadsen committed Nov 10, 2015
1 parent 664e9c9 commit 59256a7
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 10 additions & 0 deletions src/group.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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?
Expand Down
1 change: 1 addition & 0 deletions src/shapes/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Circle {

scale(scalar) {
this.vars.radius *= scalar;
return this;
}

copy(parent) {
Expand Down
1 change: 1 addition & 0 deletions src/shapes/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Ellipse {
scale(scalar) {
this.vars.width *= scalar;
this.vars.height *= scalar;
return this;
}

copy(parent) {
Expand Down
1 change: 1 addition & 0 deletions src/shapes/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Expand Down
1 change: 1 addition & 0 deletions src/shapes/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions src/shapes/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ class Polygon {
this.vars.vectors = map(this.vars.vectors, function(vec) {
return vec.multiply(scalar);
});
return this;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/shapes/rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Rectangle {
scale(scalar) {
this.vars.width *= scalar;
this.vars.height *= scalar;
return this;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/shapes/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Text {

scale(scalar) {
this.vars.fontSize *= scalar;
return this;
}

}
Expand Down
1 change: 1 addition & 0 deletions src/shapes/triangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Triangle {
this.vars.y2 *= scalar;
this.vars.x3 *= scalar;
this.vars.y3 *= scalar;
return this;
}

}
Expand Down
20 changes: 20 additions & 0 deletions test/shared/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});

});

0 comments on commit 59256a7

Please sign in to comment.