Skip to content

Commit

Permalink
1.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
runemadsen committed Sep 29, 2017
1 parent 612ef7b commit ba0f870
Show file tree
Hide file tree
Showing 15 changed files with 1,032 additions and 1,157 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.1.3

- `Rune.Group` can now accept `fill()`, `stroke()`, and all other styling functions. This makes it easy to have a default style for all shapes in a group.
- Massive rewrite of tests that tried to be too smart.

## 1.1.2

- `Rune.Color` objects now accepts `rgb()` and `rgba()` strings.
Expand Down
20 changes: 10 additions & 10 deletions dist/rune.js
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,7 @@ var assign = __webpack_require__(1);
var each = __webpack_require__(14);
var map = __webpack_require__(18);
var Shape = __webpack_require__(3);
var Styles = __webpack_require__(4);
var Parent = __webpack_require__(47);
var Utils = __webpack_require__(0);
var Vector = __webpack_require__(8);
Expand All @@ -2344,12 +2345,11 @@ var svg = __webpack_require__(2);
var Group = function(x, y) {
this.shape();
this.setupParent();
if(typeof x !== 'undefined') this.state.x = x;
if(typeof y !== 'undefined') this.state.y = y;
}
if (typeof x !== 'undefined') this.state.x = x;
if (typeof y !== 'undefined') this.state.y = y;
};

Group.prototype = {

add: function(child) {
this.addChild(child);
},
Expand All @@ -2360,8 +2360,8 @@ Group.prototype = {

copy: function(parent) {
var copy = new Group();
for(var i = 0; i < this.children.length; i++) {
this.children[i].copy(copy)
for (var i = 0; i < this.children.length; i++) {
this.children[i].copy(copy);
}
Utils.copyMixinVars(this, copy);
Utils.groupLogic(copy, this.parent, parent);
Expand All @@ -2378,14 +2378,14 @@ Group.prototype = {
},

render: function(opts) {
if(!this.children || this.children.length == 0) return;
if (!this.children || this.children.length == 0) return;
var attr = this.shapeAttributes({});
this.stylesAttributes(attr);
return svg('g', attr, this.renderChildren(opts));
}
};

}

assign(Group.prototype, Shape, Parent, {type: "group"});
assign(Group.prototype, Shape, Styles, Parent, { type: 'group' });

module.exports = Group;

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": "1.1.2",
"version": "1.1.3",
"description":
"A JavaScript library for programming graphic design systems with SVG",
"repository": {
Expand Down
30 changes: 15 additions & 15 deletions src/group.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var assign = require("lodash/object/assign");
var each = require("lodash/collection/each");
var map = require("lodash/collection/map");
var Shape = require("./mixins/shape");
var Parent = require("./mixins/parent");
var assign = require('lodash/object/assign');
var each = require('lodash/collection/each');
var map = require('lodash/collection/map');
var Shape = require('./mixins/shape');
var Styles = require('./mixins/styles');
var Parent = require('./mixins/parent');
var Utils = require('./utils');
var Vector = require('./vector');
var svg = require('virtual-dom/virtual-hyperscript/svg');

var Group = function(x, y) {
this.shape();
this.setupParent();
if(typeof x !== 'undefined') this.state.x = x;
if(typeof y !== 'undefined') this.state.y = y;
}
if (typeof x !== 'undefined') this.state.x = x;
if (typeof y !== 'undefined') this.state.y = y;
};

Group.prototype = {

add: function(child) {
this.addChild(child);
},
Expand All @@ -26,8 +26,8 @@ Group.prototype = {

copy: function(parent) {
var copy = new Group();
for(var i = 0; i < this.children.length; i++) {
this.children[i].copy(copy)
for (var i = 0; i < this.children.length; i++) {
this.children[i].copy(copy);
}
Utils.copyMixinVars(this, copy);
Utils.groupLogic(copy, this.parent, parent);
Expand All @@ -44,13 +44,13 @@ Group.prototype = {
},

render: function(opts) {
if(!this.children || this.children.length == 0) return;
if (!this.children || this.children.length == 0) return;
var attr = this.shapeAttributes({});
this.stylesAttributes(attr);
return svg('g', attr, this.renderChildren(opts));
}
};

}

assign(Group.prototype, Shape, Parent, {type: "group"});
assign(Group.prototype, Shape, Styles, Parent, { type: 'group' });

module.exports = Group;
123 changes: 65 additions & 58 deletions test/both/anchor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
describe("Rune.Anchor", function() {

describe('Rune.Anchor', function() {
var a1;
var v1;

Expand All @@ -8,33 +7,38 @@ describe("Rune.Anchor", function() {
v1 = new Rune.Vector(10, 15);
});

describe("add()", function() {
it("adds vector to anchor vectors", function() {
describe('add()', function() {
it('adds vector to anchor vectors', function() {
var res = a1.add(v1);
expect(res).toBeAnchorCubic(110, 120, 210, 220, 310, 320);
expect(res).toEqual(
new Rune.Anchor().setCurve(110, 120, 210, 220, 310, 320)
);
expect(res).not.toBe(a1);
});
});

describe("sub()", function() {
it("subtracts vectors", function() {
describe('sub()', function() {
it('subtracts vectors', function() {
var res = a1.sub(v1);
expect(res).toBeAnchorCubic(90, 90, 190, 190, 290, 290);
expect(res).toEqual(
new Rune.Anchor().setCurve(90, 90, 190, 190, 290, 290)
);
expect(res).not.toBe(a1);
});
});

describe("multiply()", function() {
it("multiplies vectors", function() {
describe('multiply()', function() {
it('multiplies vectors', function() {
var res = a1.multiply(2);
expect(res).toBeAnchorCubic(200, 210, 400, 410, 600, 610);
expect(res).toEqual(
new Rune.Anchor().setCurve(200, 210, 400, 410, 600, 610)
);
expect(res).not.toBe(a1);
});
});

describe("copy()", function() {

it("copies the anchor", function() {
describe('copy()', function() {
it('copies the anchor', function() {
var a = new Rune.Anchor().setCurve(100, 105, 200, 205, 300, 305);
var b = a.copy();
expect(a).toEqual(b);
Expand All @@ -43,96 +47,99 @@ describe("Rune.Anchor", function() {
expect(a.vec2 === b.vec2).toBe(false);
expect(a.vec3 === b.vec3).toBe(false);
});

});

describe("setMove()", function() {

it("creates move", function() {
describe('setMove()', function() {
it('creates move', function() {
var a = new Rune.Anchor().setMove(100, 105);
expect(a).toBeAnchorMove(100, 105);
expect(a.command).toEqual('move');
expect(a.vec1).toEqual(new Rune.Vector(100, 105));
expect(a.vec2).toBeFalsy();
expect(a.vec3).toBeFalsy();
});

});

describe("setLine()", function() {

it("creates line", function() {
describe('setLine()', function() {
it('creates line', function() {
var a = new Rune.Anchor().setLine(100, 105);
expect(a).toBeAnchorLine(100, 105);
expect(a.command).toEqual('line');
expect(a.vec1).toEqual(new Rune.Vector(100, 105));
expect(a.vec2).toBeFalsy();
expect(a.vec3).toBeFalsy();
});

});

describe("setCurve()", function() {

it("creates cubic", function() {
var a = new Rune.Anchor().setCurve(100, 105, 200, 205, 300, 305);
expect(a).toBeAnchorCubic(100, 105, 200, 205, 300, 305);
});

it("creates quad", function() {
describe('setCurve()', function() {
it('creates quad', function() {
var a = new Rune.Anchor().setCurve(100, 105, 200, 205);
expect(a).toBeAnchorQuad(100, 105, 200, 205);
expect(a.command).toEqual('quad');
expect(a.vec1).toEqual(new Rune.Vector(100, 105));
expect(a.vec2).toEqual(new Rune.Vector(200, 205));
expect(a.vec3).toBeFalsy();
});

it('creates cubic', function() {
var a = new Rune.Anchor().setCurve(100, 105, 200, 205, 300, 305);
expect(a.command).toEqual('cubic');
expect(a.vec1).toEqual(new Rune.Vector(100, 105));
expect(a.vec2).toEqual(new Rune.Vector(200, 205));
expect(a.vec3).toEqual(new Rune.Vector(300, 305));
});
});

describe("setClose()", function() {

it("creates close", function() {
describe('setClose()', function() {
it('creates close', function() {
var a = new Rune.Anchor().setClose();
expect(a).toBeAnchorClose();
expect(a.command).toEqual('close');
expect(a.vec1).toBeFalsy();
expect(a.vec2).toBeFalsy();
expect(a.vec3).toBeFalsy();
});

});

describe("vectorAt()", function() {

it("throws error for move", function() {
describe('vectorAt()', function() {
it('throws error for move', function() {
var a = new Rune.Anchor().setMove(0, 0);
expect(function() { a.vectorAt(0.5) }).toThrow(new Error("Cannot compute vectorAt for this type of anchor"));
expect(function() {
a.vectorAt(0.5);
}).toThrow(new Error('Cannot compute vectorAt for this type of anchor'));
});

it("returns vector for line", function() {
it('returns vector for line', function() {
var a = new Rune.Anchor().setLine(100, 100);
expect(a.vectorAt(0.5)).toEqualVector(50, 50);
expect(a.vectorAt(0.5)).toEqual(new Rune.Vector(50, 50));
});

it("returns vector for cubic bezier", function() {
it('returns vector for cubic bezier', function() {
var a = new Rune.Anchor().setCurve(0, 100, 100, 100, 100, 0);
expect(a.vectorAt(0.5)).toEqualVector(50, 75);
expect(a.vectorAt(0.5)).toEqual(new Rune.Vector(50, 75));
});

it("returns vector for quad bezier", function() {
it('returns vector for quad bezier', function() {
var a = new Rune.Anchor().setCurve(50, 100, 100, 0);
expect(a.vectorAt(0.5)).toEqualVector(50, 50);
expect(a.vectorAt(0.5)).toEqual(new Rune.Vector(50, 50));
});

});

describe("length()", function() {

it("returns length for move", function() {
describe('length()', function() {
it('returns length for move', function() {
var a = new Rune.Anchor().setMove(0, 0);
expect(a.length()).toEqual(0);
});

it("returns length for line", function() {
it('returns length for line', function() {
var a = new Rune.Anchor().setLine(100, 100);
expect(a.length()).toEqual(141.4213562373095);
});

it("returns length for cubic bezier", function() {
it('returns length for cubic bezier', function() {
var a = new Rune.Anchor().setCurve(0, 100, 100, 100, 100, 0);
expect(a.length()).toEqual(200);
});

it("returns length for quad bezier", function() {
it('returns length for quad bezier', function() {
var a = new Rune.Anchor().setCurve(50, 100, 100, 0);
expect(a.length()).toEqual(147.89428575453212);
});

});

});
Loading

0 comments on commit ba0f870

Please sign in to comment.