From 264c100153fc45cedf94a8cc8a0174fae12e1fe8 Mon Sep 17 00:00:00 2001 From: wout Date: Sun, 24 Mar 2013 21:03:14 +0100 Subject: Added unbiased option to plotable elements --- src/container.js | 12 ++++++------ src/path.js | 4 +++- src/plotable.js | 12 +++++++++--- src/poly.js | 8 ++++++-- 4 files changed, 24 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/container.js b/src/container.js index 63822e4..08a52c8 100644 --- a/src/container.js +++ b/src/container.js @@ -90,16 +90,16 @@ SVG.extend(SVG.Container, { return this.put(new SVG.Line().plot(x1, y1, x2, y2)) } // Create a wrapped polyline element -, polyline: function(points) { - return this.put(new SVG.Polyline).plot(points) +, polyline: function(points, unbiased) { + return this.put(new SVG.Polyline(unbiased)).plot(points) } // Create a wrapped polygon element -, polygon: function(points) { - return this.put(new SVG.Polygon).plot(points) +, polygon: function(points, unbiased) { + return this.put(new SVG.Polygon(unbiased)).plot(points) } // Create a wrapped path element -, path: function(data) { - return this.put(new SVG.Path).plot(data) +, path: function(data, unbiased) { + return this.put(new SVG.Path(unbiased)).plot(data) } // Create image element, load image and set its size , image: function(source, width, height) { diff --git a/src/path.js b/src/path.js index ab5221a..b328d92 100644 --- a/src/path.js +++ b/src/path.js @@ -1,5 +1,7 @@ -SVG.Path = function() { +SVG.Path = function(unbiased) { this.constructor.call(this, SVG.create('path')) + + this.unbiased = unbiased } // Inherit from SVG.Shape diff --git a/src/plotable.js b/src/plotable.js index 023d769..b4efe77 100644 --- a/src/plotable.js +++ b/src/plotable.js @@ -25,10 +25,16 @@ SVG.extend(SVG.Polyline, SVG.Polygon, SVG.Path, { /* native plot */ this._plot(data) - /* get and store the actual offset of the element */ + /* store offset */ this._offset = this.transform({ scaleX: 1, scaleY: 1 }).bbox() - this._offset.x -= this.trans.x - this._offset.y -= this.trans.y + + /* get and store the actual offset of the element */ + if (this.unbiased) { + this._offset.x = this._offset.y = 0 + } else { + this._offset.x -= this.trans.x + this._offset.y -= this.trans.y + } return this.transform({ scaleX: x, scaleY: y }) } diff --git a/src/poly.js b/src/poly.js index 16a1cae..5c458f0 100644 --- a/src/poly.js +++ b/src/poly.js @@ -1,12 +1,16 @@ -SVG.Polyline = function() { +SVG.Polyline = function(unbiased) { this.constructor.call(this, SVG.create('polyline')) + + this.unbiased = unbiased } // Inherit from SVG.Shape SVG.Polyline.prototype = new SVG.Shape -SVG.Polygon = function() { +SVG.Polygon = function(unbiased) { this.constructor.call(this, SVG.create('polygon')) + + this.unbiased = unbiased } // Inherit from SVG.Shape -- cgit v1.2.3