From 8324870a9b54a81c0339029a1bc3c2954217a6bb Mon Sep 17 00:00:00 2001 From: wout Date: Fri, 24 Mar 2017 15:17:31 +0100 Subject: Speed improvements for plot() on path, polygon and poly line elements. --- src/path.js | 13 +++++++++---- src/poly.js | 7 ++++++- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/path.js b/src/path.js index 0c70a47..e5504bb 100644 --- a/src/path.js +++ b/src/path.js @@ -13,11 +13,16 @@ SVG.Path = SVG.invent({ , array: function() { return this._array || (this._array = new SVG.PathArray(this.attr('d'))) } - // Plot new poly points - , plot: function(p) { - return (p == null) ? + // Plot new path + , plot: function(d) { + return (d == null) ? this.array() : - this.attr('d', (this._array = new SVG.PathArray(p))) + this.clear().attr('d', typeof d == 'string' ? d : (this._array = new SVG.PathArray(d))) + } + // Clear array cache + , clear: function() { + delete this._array + return this } // Move by left top corner , move: function(x, y) { diff --git a/src/poly.js b/src/poly.js index af1f075..269b112 100644 --- a/src/poly.js +++ b/src/poly.js @@ -42,7 +42,12 @@ SVG.extend(SVG.Polyline, SVG.Polygon, { , plot: function(p) { return (p == null) ? this.array() : - this.attr('points', (this._array = new SVG.PointArray(p))) + this.clear().attr('points', typeof p == 'string' ? p : (this._array = new SVG.PointArray(p))) + } + // Clear array cache +, clear: function() { + delete this._array + return this } // Move by left top corner , move: function(x, y) { -- cgit v1.2.3