aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-01-30 19:44:40 +0100
committerwout <wout@impinc.co.uk>2014-01-30 19:44:40 +0100
commitbd7e10cb46e0cb113983c69f4f48c7a42a776809 (patch)
tree37ad5746b3e66879a33b6fe85c5e5718ec58a18b /spec
parentf6fc66659d0fc391442f58e8c82f965b38995725 (diff)
downloadsvg.js-bd7e10cb46e0cb113983c69f4f48c7a42a776809.tar.gz
svg.js-bd7e10cb46e0cb113983c69f4f48c7a42a776809.zip
Added `relative()`method for relative translations
Diffstat (limited to 'spec')
-rw-r--r--spec/index.html4
-rw-r--r--spec/spec/element.js33
-rw-r--r--spec/spec/set.js29
3 files changed, 63 insertions, 3 deletions
diff --git a/spec/index.html b/spec/index.html
index f7e01ec..a702289 100644
--- a/spec/index.html
+++ b/spec/index.html
@@ -11,8 +11,8 @@
#drawing {
width: 500px;
height: 500px;
- position: absolute;
- z-index: -10;
+ position: fixed;
+ z-index: -1;
}
</style>
diff --git a/spec/spec/element.js b/spec/spec/element.js
index 22b09bf..67d12f0 100644
--- a/spec/spec/element.js
+++ b/spec/spec/element.js
@@ -314,6 +314,39 @@ describe('Element', function() {
expect(element).toBe(circle)
})
})
+
+ describe('relative()', function() {
+ var rect
+
+ beforeEach(function() {
+ rect = draw.rect(100,100).move(50,60)
+ })
+
+ afterEach(function() {
+ draw.clear()
+ })
+
+ describe('x()', function() {
+ it('moves the x positon of the element', function() {
+ rect.relative().x(100)
+ expect(rect.node.getAttribute('x')).toBe('150')
+ })
+ })
+ describe('y()', function() {
+ it('moves the y positon of the element', function() {
+ rect.relative().x(120)
+ expect(rect.node.getAttribute('x')).toBe('170')
+ })
+ })
+ describe('move()', function() {
+ it('moves the x and y positon of the element', function() {
+ rect.relative().move(80, 25)
+ expect(rect.node.getAttribute('x')).toBe('130')
+ expect(rect.node.getAttribute('y')).toBe('85')
+ })
+ })
+
+ })
})
diff --git a/spec/spec/set.js b/spec/spec/set.js
index 2a149df..b6199d7 100644
--- a/spec/spec/set.js
+++ b/spec/spec/set.js
@@ -2,8 +2,9 @@ describe('Set', function() {
var set, e1, e2, e3, e4, e5
beforeEach(function() {
+ draw.attr('viewBox', null)
set = draw.set()
- e1 = draw.rect(100,100).attr('id', 'e1')
+ e1 = draw.rect(100,100).attr('id', 'e1').move(200,250)
e2 = draw.ellipse(100,100).attr('id', 'e2')
e3 = draw.line(0,0,100,100).attr('id', 'e3')
e4 = draw.circle(50).attr('id', 'e4')
@@ -94,6 +95,32 @@ describe('Set', function() {
})
})
+ describe('bbox()', function() {
+ it('returns the bounding box of all elements', function() {
+ set.add(e1).add(e2).add(e3).add(e4).add(e5)
+
+ var box = set.bbox()
+
+ expect(box.x).toBe(0)
+ expect(box.y).toBe(0)
+ expect(box.width).toBe(300)
+ expect(box.height).toBe(350)
+ })
+ it('returns an instance of SVG.BBox', function() {
+ set.add(e1).add(e2).add(e3).add(e4).add(e5)
+
+ expect(set.bbox() instanceof SVG.BBox).toBe(true)
+ })
+ it('returns an empty bounding box wiht no members', function() {
+ var box = set.bbox()
+
+ expect(box.x).toBe(0)
+ expect(box.y).toBe(0)
+ expect(box.width).toBe(0)
+ expect(box.height).toBe(0)
+ })
+ })
+
describe('method alias', function() {
describe('attr()', function() {