diff options
author | Saivan <savian@me.com> | 2018-03-05 02:24:43 +1100 |
---|---|---|
committer | Saivan <savian@me.com> | 2018-03-05 02:24:43 +1100 |
commit | 4a03212d2dfac7079d51bd98faefe423889761cf (patch) | |
tree | 7cc09f4340d98ffc8317ab40b47028810b8cb167 /spec | |
parent | c64401369e6a2e066c9a38abd7b0e385555fe36d (diff) | |
download | svg.js-4a03212d2dfac7079d51bd98faefe423889761cf.tar.gz svg.js-4a03212d2dfac7079d51bd98faefe423889761cf.zip |
Fixed recommendations by @Fuzzyma regarding transforms
This commit fixes a number of issues with transformations:
- Removed move/dmove/etc... on groups
- Sugar was being passed origin instead of ox, oy
- Updated the changelog
- Removed parseMatrix in favor of new SVG.Matrix()
- .matrix is the getter for a matrix, not .transform
- added a [02:24:41] Using gulpfile ~/Desktop/svg/svg.js/gulpfile.js
[02:24:41] Starting 'lint'...
[02:24:43] Finished 'lint' after 2.32 s directive
Diffstat (limited to 'spec')
-rw-r--r-- | spec/SpecRunner.html | 2 | ||||
-rw-r--r-- | spec/spec/element.js | 18 | ||||
-rw-r--r-- | spec/spec/group.js | 116 | ||||
-rw-r--r-- | spec/spec/point.js | 4 | ||||
-rw-r--r-- | spec/spec/sugar.js | 30 |
5 files changed, 26 insertions, 144 deletions
diff --git a/spec/SpecRunner.html b/spec/SpecRunner.html index 118f7bb..5cd5f4f 100644 --- a/spec/SpecRunner.html +++ b/spec/SpecRunner.html @@ -69,7 +69,6 @@ <script src="spec/event.js"></script> <script src="spec/fx.js"></script> <script src="spec/gradient.js"></script> - <script src="spec/group.js"></script> <script src="spec/helper.js"></script> <script src="spec/hyperlink.js"></script> <script src="spec/image.js"></script> @@ -78,7 +77,6 @@ <script src="spec/mask.js"></script> <script src="spec/matrix.js"></script> <script src="spec/number.js"></script> - <script src="spec/nested.js"></script> <script src="spec/path.js"></script> <script src="spec/pattern.js"></script> <script src="spec/point.js"></script> diff --git a/spec/spec/element.js b/spec/spec/element.js index d6e2783..41f2af4 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -196,7 +196,7 @@ describe('Element', function() { it('gets the current transformation matrix', function() { expect(rect.transform()).toEqual(jasmine.objectContaining({ - a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, matrix: new SVG.Matrix(rect), + a: 1, b: 0, c: 0, d: 1, e: 0, f: 0, scaleX: 1, scaleY: 1, shear: 0, rotate: 0, translateX: 0, translateY: 0, })) @@ -421,11 +421,11 @@ describe('Element', function() { }) it('moves the element to other parent while maintaining the same visal representation', function() { - expect(window.roundMatrix(rect1.toParent(nested).transform('matrix'))) - .toEqual(new SVG.Matrix(2, 0, 0, 2, 120, 120)) + expect(window.roundMatrix(rect1.toParent(nested).matrix())) + .toEqual(new SVG.Matrix(2, 0, 0, 2, 70, 70)) expect(rect1.parent()).toEqual(nested) - expect(window.roundMatrix(rect2.toParent(g2).transform('matrix'))) - .toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, -120, -120)) + expect(window.roundMatrix(rect2.toParent(g2).matrix())) + .toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, -95, -95)) expect(rect2.parent()).toEqual(g2) }) }) @@ -477,8 +477,8 @@ describe('Element', function() { expect(g1.node.parentNode).toBeFalsy() expect(g2.node.parentNode).toBeFalsy() - expect(window.roundMatrix(rect1.transform().matrix)).toEqual(new SVG.Matrix(2, 0, 0, 2, 120, 120)) - expect(window.roundMatrix(rect2.transform().matrix)).toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, 20, 20)) + expect(window.roundMatrix(rect1.matrix())).toEqual(new SVG.Matrix(2, 0, 0, 2, 70, 70)) + expect(window.roundMatrix(rect2.matrix())).toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, 45, 45)) }) it('ungroups everything to the doc root when called on SVG.Doc / does not ungroup defs/parser', function() { @@ -491,8 +491,8 @@ describe('Element', function() { expect(g2.node.parentNode).toBeFalsy() expect(nested.node.parentNode).toBeFalsy() - expect(window.roundMatrix(rect1.transform().matrix)).toEqual(new SVG.Matrix(2, 0, 0, 2, 120, 120)) - expect(window.roundMatrix(rect2.transform().matrix)).toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, 20, 20)) + expect(window.roundMatrix(rect1.matrix())).toEqual(new SVG.Matrix(2, 0, 0, 2, 70, 70)) + expect(window.roundMatrix(rect2.matrix())).toEqual(new SVG.Matrix(0.5, 0, 0, 0.5, 45, 45)) expect(draw.children().length).toBe(3+parserInDoc) // 2 * rect + defs }) diff --git a/spec/spec/group.js b/spec/spec/group.js deleted file mode 100644 index 4d5ff36..0000000 --- a/spec/spec/group.js +++ /dev/null @@ -1,116 +0,0 @@ -describe('Group', function() { - var group - - beforeEach(function() { - group = draw.group().move(50, 50) - group.rect(100,100) - }) - - afterEach(function() { - draw.clear() - }) - - describe('x()', function() { - it('returns the value of x without an argument', function() { - expect(group.x()).toBe(50) - }) - it('sets the value of x with the first argument', function() { - group.x(123) - var box = group.gbox() - expect(box.x).toBe(123) - }) - it('sets the value of x correctly when called multiple times', function() { - group.x(10).x(100).x(13) - var box = group.gbox() - expect(box.x).toBe(13) - }) - it('sets the value of x correctly when the first argument is a string number', function(){ - group.x('123') - var box = group.gbox() - expect(box.x).toBe(123) - }) - }) - - describe('y()', function() { - it('returns the value of y without an argument', function() { - expect(group.y()).toBe(50) - }) - it('sets the value of y with the first argument', function() { - group.y(345) - var box = group.gbox() - expect(box.y).toBe(345) - }) - it('sets the value of y correctly when called multiple times', function() { - group.y(1).y(10).y(15) - var box = group.gbox() - expect(box.y).toBe(15) - }) - it('sets the value of y correctly when the first argument is a string number', function(){ - group.y('124') - var box = group.gbox() - expect(box.y).toBe(124) - }) - }) - - describe('cx()', function() { - it('returns the value of cx without an argument', function() { - expect(group.cx()).toBe(100) - }) - it('sets the value of cx with the first argument', function() { - group.cx(123) - var box = group.gbox() - expect(box.cx).toBe(123) - }) - }) - - describe('cy()', function() { - it('returns the value of cy without an argument', function() { - expect(group.cy()).toBe(100) - }) - it('sets the value of cy with the first argument', function() { - group.cy(345) - var box = group.gbox() - expect(box.cy).toBe(345) - }) - }) - - describe('move()', function() { - it('sets the x and y position', function() { - group.move(123,456) - expect(group.node.getAttribute('transform')).toBe('matrix(1,0,0,1,123,456)') - }) - }) - - describe('center()', function() { - it('sets the cx and cy position', function() { - group.center(321,567) - var box = group.gbox() - expect(box.cx).toBe(321) - expect(box.cy).toBe(567) - }) - }) - - describe('dx()', function() { - it('moves the x positon of the element relative to the current position', function() { - group.move(50,60) - group.dx(100) - expect(group.node.getAttribute('transform')).toBe('matrix(1,0,0,1,150,60)') - }) - }) - - describe('dy()', function() { - it('moves the y positon of the element relative to the current position', function() { - group.move(50,60) - group.dy(120) - expect(group.node.getAttribute('transform')).toBe('matrix(1,0,0,1,50,180)') - }) - }) - - describe('dmove()', function() { - it('moves the x and y positon of the element relative to the current position', function() { - group.move(50, 60) - group.dmove(80, 25) - expect(group.node.getAttribute('transform')).toBe('matrix(1,0,0,1,130,85)') - }) - }) -}) diff --git a/spec/spec/point.js b/spec/spec/point.js index 8eacb84..a41f2ee 100644 --- a/spec/spec/point.js +++ b/spec/spec/point.js @@ -26,11 +26,11 @@ describe('Point', function() { }) describe('with only x given', function() { - it('creates a point using the given value for both x and y', function() { + it('sets the y value to 0', function() { var point = new SVG.Point(7) expect(point.x).toBe(7) - expect(point.y).toBe(7) + expect(point.y).toBe(0) }) }) diff --git a/spec/spec/sugar.js b/spec/spec/sugar.js index b51e948..5dc4f65 100644 --- a/spec/spec/sugar.js +++ b/spec/spec/sugar.js @@ -56,7 +56,7 @@ describe('Sugar', function() { it('redirects to transform()', function() { rect.rotate(1,2,3) - expect(rect.transform).toHaveBeenCalledWith({ rotate: 1, origin: [2, 3] }, true) + expect(rect.transform).toHaveBeenCalledWith({ rotate: 1, ox: 2, oy:3 }, true) }) }) @@ -75,27 +75,27 @@ describe('Sugar', function() { it('redirects to transform() with no argument', function() { rect.skew() - expect(rect.transform).toHaveBeenCalledWith({ skew: [undefined, undefined], origin: [undefined, undefined] }, true) + expect(rect.transform).toHaveBeenCalledWith({ skew: [undefined, undefined], ox: undefined, oy: undefined }, true) }) it('redirects to transform() with one argument', function() { rect.skew(5) - expect(rect.transform).toHaveBeenCalledWith({ skew: 5, origin: [undefined, undefined] }, true) + expect(rect.transform).toHaveBeenCalledWith({ skew: 5, ox: undefined, oy: undefined }, true) }) it('redirects to transform() with two argument', function() { rect.skew(5, 6) - expect(rect.transform).toHaveBeenCalledWith({ skew: [5, 6], origin: [undefined, undefined] }, true) + expect(rect.transform).toHaveBeenCalledWith({ skew: [5, 6], ox: undefined, oy: undefined}, true) }) it('redirects to transform() with three arguments', function() { rect.skew(5, 6, 7) - expect(rect.transform).toHaveBeenCalledWith({ skew: 5, origin: [6, 7] }, true) + expect(rect.transform).toHaveBeenCalledWith({ skew: 5, ox: 6, oy: 7 }, true) }) it('redirects to transform() with four arguments', function() { rect.skew(5, 6, 7, 8) - expect(rect.transform).toHaveBeenCalledWith({ skew: [5, 6], origin: [7, 8] }, true) + expect(rect.transform).toHaveBeenCalledWith({ skew: [5, 6], ox: 7, oy: 8 }, true) }) }) @@ -114,27 +114,27 @@ describe('Sugar', function() { it('redirects to transform() with no argument', function() { rect.scale() - expect(rect.transform).toHaveBeenCalledWith({ scale: [undefined, undefined], origin: [undefined, undefined] }, true) + expect(rect.transform).toHaveBeenCalledWith({ scale: [undefined, undefined], ox: undefined, oy: undefined }, true) }) it('redirects to transform() with one argument', function() { rect.scale(5) - expect(rect.transform).toHaveBeenCalledWith({ scale: 5, origin: [undefined, undefined]}, true) + expect(rect.transform).toHaveBeenCalledWith({ scale: 5, ox: undefined, oy: undefined}, true) }) it('redirects to transform() with two argument', function() { rect.scale(5, 6) - expect(rect.transform).toHaveBeenCalledWith({ scale: [5, 6], origin: [undefined, undefined] }, true) + expect(rect.transform).toHaveBeenCalledWith({ scale: [5, 6], ox: undefined, oy: undefined }, true) }) it('redirects to transform() with three arguments', function() { rect.scale(5, 6, 7) - expect(rect.transform).toHaveBeenCalledWith({ scale: 5, origin: [6, 7] }, true) + expect(rect.transform).toHaveBeenCalledWith({ scale: 5, ox: 6, oy: 7 }, true) }) it('redirects to transform() with four arguments', function() { rect.scale(5, 6, 7, 8) - expect(rect.transform).toHaveBeenCalledWith({ scale: [5, 6], origin: [7, 8] }, true) + expect(rect.transform).toHaveBeenCalledWith({ scale: [5, 6], ox: 7, oy: 8 }, true) }) }) @@ -171,19 +171,19 @@ describe('Sugar', function() { }) it('redirects to transform()', function() { - rect.flip('x',2) - expect(rect.transform).toHaveBeenCalledWith({ flip: 'x', origin: [2, 0] }, true) + rect.flip('x', 2) + expect(rect.transform).toHaveBeenCalledWith({ flip: 'x', ox: 2, oy: 0 }, true) }) it('sets flip to "both" when calling without anything', function() { rect.flip() - expect(rect.transform).toHaveBeenCalledWith({ flip: 'both', origin: [0, 0] }, true) + expect(rect.transform).toHaveBeenCalledWith({ flip: 'both', ox: 0, oy: 0 }, true) }) // this works because only x and y are valid flip values. Evereything else flips on both axis it('sets flip to number and offset to number when called with offset only', function() { rect.flip(5) - expect(rect.transform).toHaveBeenCalledWith({ flip: "both", origin: [5, 5] }, true) + expect(rect.transform).toHaveBeenCalledWith({ flip: "both", ox: 5, oy: 5 }, true) }) }) |