aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2017-03-24 15:17:31 +0100
committerwout <wout@impinc.co.uk>2017-03-24 15:17:31 +0100
commit8324870a9b54a81c0339029a1bc3c2954217a6bb (patch)
tree4e98fcd79bacc20d511c42f55adaeac0d87bf074 /spec
parenta749f7aa6e37e22cc02c5ad29647e1783bb75150 (diff)
downloadsvg.js-8324870a9b54a81c0339029a1bc3c2954217a6bb.tar.gz
svg.js-8324870a9b54a81c0339029a1bc3c2954217a6bb.zip
Speed improvements for plot() on path, polygon and poly line elements.
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/path.js40
-rw-r--r--spec/spec/polygon.js34
-rw-r--r--spec/spec/polyline.js29
3 files changed, 89 insertions, 14 deletions
diff --git a/spec/spec/path.js b/spec/spec/path.js
index 50ff986..cfa416a 100644
--- a/spec/spec/path.js
+++ b/spec/spec/path.js
@@ -16,7 +16,6 @@ describe('Path', function() {
})
})
-
describe('array()', function() {
it('returns an instance of SVG.PathArray', function() {
expect(path.array() instanceof SVG.PathArray).toBeTruthy()
@@ -192,28 +191,51 @@ describe('Path', function() {
})
describe('plot()', function() {
- it('change the d attribute of the underlying path node when a string is passed', function() {
+ it('changes the d attribute of the underlying path node when a string is passed', function() {
var pathString = 'm 3,2 c 0,0 -0,13 8,14 L 5,4'
, pathArray = new SVG.PathArray(pathString)
expect(path.plot(pathString)).toBe(path)
- expect(path.attr('d')).toBe(pathArray.toString())
+ expect(path.attr('d')).toBe(pathString)
+ })
+ it('clears the array cache when a value is passed', function() {
+ path = draw.path([ ['M', 50, 60], ['A', 60, 60, 0, 0, 0, 50, -60], ['z'] ])
+ expect(path._array instanceof SVG.PathArray).toBeTruthy()
+ path.plot('m 3,2 c 0,0 -0,13 8,14 L 5,4')
+ expect(path._array).toBeUndefined()
})
+ it('applies a given path string value as is', function() {
+ var pathString = 'm 3,2 c 0,0 -0,13 8,14 L 5,4'
- it('return the path array when no arguments are passed', function () {
+ path = draw.path(pathString)
+ expect(path.attr('d')).toBe(pathString)
+ })
+ it('does not parse and cache a given string value to SVG.PathArray', function() {
+ path = draw.path('m 3,2 c 0,0 -0,13 8,14 L 5,4')
+ expect(path._array).toBeUndefined()
+ })
+ it('caches a given array value', function() {
+ path = draw.path([ ['M', 50, 60], ['A', 60, 60, 0, 0, 0, 50, -60], ['H', 100], ['L', 20, 30], ['Z'] ])
+ expect(path._array instanceof SVG.PathArray).toBeTruthy()
+ })
+ it('returns the path array when no arguments are passed', function () {
expect(path.plot()).toBe(path.array())
})
})
+ describe('clear()', function() {
+ it('clears the cached SVG.PathArray instance', function() {
+ path = draw.path(svgPath)
+ path.clear()
+ expect(path._array).toBeUndefined()
+ })
+ })
+
describe('toString()', function() {
it('renders path array correctly to string', function() {
- path = path.plot('M 50 60 A 60 60 0 0 0 50 -60 H 100 V 100 L 20 30 C 10 20 30 40 50 60 ')
+ path = path.plot(['M', 50, 60, 'A', 60, 60, 0, 0, 0, 50, -60, 'H', 100, 'V', 100, 'L', 20, 30, 'C', 10, 20, 30, 40, 50, 60 ])
expect(path.node.getAttribute('d')).toBe('M50 60A60 60 0 0 0 50 -60H100V100L20 30C10 20 30 40 50 60 ')
})
- it('renders path array correctly to string', function() {
- path = path.plot('M 50 60 A 60 60 1 1 0 50 -60 H 100 V 100 L 20 30 C 10 20 30 40 50 60 ')
- expect(path.node.getAttribute('d')).toBe('M50 60A60 60 1 1 0 50 -60H100V100L20 30C10 20 30 40 50 60 ')
- })
})
describe('length()', function() {
diff --git a/spec/spec/polygon.js b/spec/spec/polygon.js
index 34d0969..789c3b9 100644
--- a/spec/spec/polygon.js
+++ b/spec/spec/polygon.js
@@ -185,18 +185,44 @@ describe('Polygon', function() {
})
})
-
describe('plot()', function() {
- it('change the points attribute of the underlying polygon node when a string is passed', function() {
+ it('changes the points attribute of the underlying polygon node when a string is passed', function() {
var pointString = '100,50 75,20 200,100'
, pointArray = new SVG.PointArray(pointString)
expect(polygon.plot(pointString)).toBe(polygon)
expect(polygon.attr('points')).toBe(pointArray.toString())
})
-
- it('return the point array when no arguments are passed', function () {
+ it('returns the point array when no arguments are passed', function () {
expect(polygon.plot()).toBe(polygon.array())
})
+ it('clears the array cache when a value is passed', function() {
+ polygon = draw.polygon([100,50,75,20,200,100])
+ expect(polygon._array instanceof SVG.PointArray).toBeTruthy()
+ polygon.plot('100,50 75,20 200,100')
+ expect(polygon._array).toBeUndefined()
+ })
+ it('applies a given polygon string value as is', function() {
+ var polyString = '100,50,75,20,200,100'
+
+ polygon = draw.polygon(polyString)
+ expect(polygon.attr('points')).toBe(polyString)
+ })
+ it('does not parse and cache a given string value to SVG.PointArray', function() {
+ polygon = draw.polygon('100,50 75,20 200,100')
+ expect(polygon._array).toBeUndefined()
+ })
+ it('caches a given array value', function() {
+ polygon = draw.polygon([100,50,75,20,200,100])
+ expect(polygon._array instanceof SVG.PointArray).toBeTruthy()
+ })
+ })
+
+ describe('clear()', function() {
+ it('clears the cached SVG.PointArray instance', function() {
+ polygon = draw.polygon([100,50,75,20,200,100])
+ polygon.clear()
+ expect(polygon._array).toBeUndefined()
+ })
})
})
diff --git a/spec/spec/polyline.js b/spec/spec/polyline.js
index aa7120c..ca516bd 100644
--- a/spec/spec/polyline.js
+++ b/spec/spec/polyline.js
@@ -193,9 +193,36 @@ describe('Polyline', function() {
expect(polyline.plot(pointString)).toBe(polyline)
expect(polyline.attr('points')).toBe(pointArray.toString())
})
-
it('return the point array when no arguments are passed', function () {
expect(polyline.plot()).toBe(polyline.array())
})
+ it('clears the array cache when a value is passed', function() {
+ polyline = draw.polyline([100,50,75,20,200,100])
+ expect(polyline._array instanceof SVG.PointArray).toBeTruthy()
+ polyline.plot('100,50 75,20 200,100')
+ expect(polyline._array).toBeUndefined()
+ })
+ it('applies a given polyline string value as is', function() {
+ var polyString = '100,50,75,20,200,100'
+
+ polyline = draw.polyline(polyString)
+ expect(polyline.attr('points')).toBe(polyString)
+ })
+ it('does not parse and cache a given string value to SVG.PointArray', function() {
+ polyline = draw.polyline('100,50 75,20 200,100')
+ expect(polyline._array).toBeUndefined()
+ })
+ it('caches a given array value', function() {
+ polyline = draw.polyline([100,50,75,20,200,100])
+ expect(polyline._array instanceof SVG.PointArray).toBeTruthy()
+ })
+ })
+
+ describe('clear()', function() {
+ it('clears the cached SVG.PointArray instance', function() {
+ polyline = draw.polyline([100,50,75,20,200,100])
+ polyline.clear()
+ expect(polyline._array).toBeUndefined()
+ })
})
})