diff options
author | Rémi Tétreault <tetreault.remi@gmail.com> | 2017-02-22 00:20:09 -0500 |
---|---|---|
committer | Rémi Tétreault <tetreault.remi@gmail.com> | 2017-02-22 00:20:09 -0500 |
commit | 669c10a76ebd164c147d7f896fa162784c0b49df (patch) | |
tree | 7e8a86edc4b6bdcfb478347ef25e2a854b852f20 /spec | |
parent | 2d11717fe6ccd6b420f2faa5d56e3064e8574d18 (diff) | |
download | svg.js-669c10a76ebd164c147d7f896fa162784c0b49df.tar.gz svg.js-669c10a76ebd164c147d7f896fa162784c0b49df.zip |
Allow 0 to be passed without unit
This commit finish fixing issue #552. It makes it unnecessary to specify a
unit with 0 when interacting with another SVG.Number that has a unit.
This was accomplished by modifying the operation methods of SVG.Number to
allow them to use the unit of the passed number when this number as no unit.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/fx.js | 67 | ||||
-rw-r--r-- | spec/spec/number.js | 30 |
2 files changed, 97 insertions, 0 deletions
diff --git a/spec/spec/fx.js b/spec/spec/fx.js index b8357db..3875681 100644 --- a/spec/spec/fx.js +++ b/spec/spec/fx.js @@ -1841,6 +1841,48 @@ describe('FX', function() { fx.step() expect(text.textPath().attr('startOffset')).toBe(morph.at(1).toString()) }) + + it('should allow 0 to be specified without unit', function () { + // This code snippet come from issue #552 + + var gradient = draw.gradient('linear', function(stop) { + s1 = stop.at(0, '#33235b') + s2 = stop.at(0.5, '#E97639') + s3 = stop.at(1, '#33235b') + }) + + var r1, r2; + var fill = draw.pattern('300%', '100%', function(add) { + r1 = add.rect('150%', '100%').fill(gradient) + r2 = add.rect('150%', '100%').fill(gradient) + }); + fill.attr({patternUnits: 'userSpaceOnUse'}) + + r1.attr('x', 0).animate('0.5s').attr('x', '150%') + r2.attr('x', '-150%').animate('0.5s').attr('x', 0) + + var text = draw.text('Manifesto').move('50%', '50%').fill(fill) + text.font({ + size: 70 + , anchor: 'middle' + , leading: 1 + }) + + r1.fx.start() + r2.fx.start() + + jasmine.clock().tick(250) // Have the animation be half way + r1.fx.step() + r2.fx.step() + expect(r1.attr('x')).toBe('75%') + expect(r2.attr('x')).toBe('-75%') + + jasmine.clock().tick(250) // Have the animation reach its end + r1.fx.step() + r2.fx.step() + expect(r1.attr('x')).toBe('150%') + expect(r2.attr('x')).toBe('0%') + }) }) @@ -1928,5 +1970,30 @@ describe('FX', function() { fx.step() expect(rect.style('stroke-width')).toBe(morph.at(1).toString()) }) + + it('should allow 0 to be specified without a unit', function () { + var r1 = draw.rect(100,100).move(200,200) + , r2 = draw.rect(100,100).move(400,400) + + r1.style('stroke-width', '100%').animate(500).style('stroke-width', 0) + r2.style('stroke-width', 0).animate(500).style('stroke-width', '100%') + + r1.fx.start() + r2.fx.start() + expect(r1.style('stroke-width')).toBe('100%') + expect(r2.style('stroke-width')).toBe('0%') + + jasmine.clock().tick(250) // Have the animation be half way + r1.fx.step() + r2.fx.step() + expect(r1.style('stroke-width')).toBe('50%') + expect(r2.style('stroke-width')).toBe('50%') + + jasmine.clock().tick(250) // Have the animation reach its end + r1.fx.step() + r2.fx.step() + expect(r1.style('stroke-width')).toBe('0%') + expect(r2.style('stroke-width')).toBe('100%') + }) }) }) diff --git a/spec/spec/number.js b/spec/spec/number.js index 890bb2c..e999187 100644 --- a/spec/spec/number.js +++ b/spec/spec/number.js @@ -127,6 +127,12 @@ describe('Number', function() { it('adds a given pixel value', function() { expect(number.plus('83px').valueOf()).toBe(83) }) + it('use the unit of this number as the unit of the returned number by default', function (){ + expect(new SVG.Number('12s').plus('3%').unit).toBe('s') + }) + it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() { + expect(number.plus('15%').unit).toBe('%') + }) }) describe('minus()', function() { @@ -139,6 +145,12 @@ describe('Number', function() { it('subtracts a given pixel value', function() { expect(number.minus('85px').valueOf()).toBe(-85) }) + it('use the unit of this number as the unit of the returned number by default', function (){ + expect(new SVG.Number('12s').minus('3%').unit).toBe('s') + }) + it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() { + expect(number.minus('15%').unit).toBe('%') + }) }) describe('times()', function() { @@ -154,6 +166,12 @@ describe('Number', function() { it('multiplies with a given pixel value', function() { expect(number.times('85px').valueOf()).toBe(340) }) + it('use the unit of this number as the unit of the returned number by default', function (){ + expect(new SVG.Number('12s').times('3%').unit).toBe('s') + }) + it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() { + expect(number.times('15%').unit).toBe('%') + }) }) describe('divide()', function() { @@ -169,6 +187,12 @@ describe('Number', function() { it('divides by a given pixel value', function() { expect(number.divide('45px').valueOf()).toBe(2) }) + it('use the unit of this number as the unit of the returned number by default', function (){ + expect(new SVG.Number('12s').divide('3%').unit).toBe('s') + }) + it('use the unit of the passed number as the unit of the returned number when this number as no unit', function() { + expect(number.divide('15%').unit).toBe('%') + }) }) describe('morph()', function() { @@ -207,6 +231,12 @@ describe('Number', function() { var morphed = number.morph(destination).at(0.72) expect(morphed.toString()).toBe('72%') }) + it('use the unit of the destination number as the unit of the returned number by default', function() { + expect(new SVG.Number('100s').morph('50%').at(0.5).unit).toBe('%') + }) + it('use the unit of this number as the unit of the returned number when the destination number as no unit', function() { + expect(expect(new SVG.Number('100s').morph(50).at(0.5).unit).toBe('s')) + }) }) }) |