summaryrefslogtreecommitdiffstats
path: root/src/poly.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-08-01 13:32:56 +0100
committerwout <wout@impinc.co.uk>2013-08-01 13:32:56 +0100
commiteecebe3cdfdae38f4e0613807e7fd64359cb84fd (patch)
tree64ecf24398abedbf4ba657fd6b5905652b83129e /src/poly.js
parent21d6c0b30a530ce7746f789921c7135079f43338 (diff)
downloadsvg.js-eecebe3cdfdae38f4e0613807e7fd64359cb84fd.tar.gz
svg.js-eecebe3cdfdae38f4e0613807e7fd64359cb84fd.zip
Added animatible poly's, bumped to v0.31
Diffstat (limited to 'src/poly.js')
-rw-r--r--src/poly.js46
1 files changed, 29 insertions, 17 deletions
diff --git a/src/poly.js b/src/poly.js
index 74a5700..937960d 100644
--- a/src/poly.js
+++ b/src/poly.js
@@ -1,16 +1,12 @@
-SVG.Polyline = function(unbiased) {
+SVG.Polyline = function() {
this.constructor.call(this, SVG.create('polyline'))
-
- this.unbiased = unbiased
}
// Inherit from SVG.Shape
SVG.Polyline.prototype = new SVG.Shape
-SVG.Polygon = function(unbiased) {
+SVG.Polygon = function() {
this.constructor.call(this, SVG.create('polygon'))
-
- this.unbiased = unbiased
}
// Inherit from SVG.Shape
@@ -18,24 +14,40 @@ SVG.Polygon.prototype = new SVG.Shape
// Add polygon-specific functions
SVG.extend(SVG.Polyline, SVG.Polygon, {
- // Private: Native plot
- _plot: function(p) {
- if (Array.isArray(p))
- p = new SVG.Array(p, [[0,0]])
-
- return this.attr('points', p)
+ // Define morphable array
+ morphArray: SVG.PointArray
+ // Plot new path
+, plot: function(p) {
+ return this.attr('points', (this.points = new SVG.PointArray(p, [[0,0]])))
}
-
+ // Move by left top corner
+, move: function(x, y) {
+ return this.attr('points', this.points.move(x, y))
+ }
+ // Move by left top corner over x-axis
+, x: function(x) {
+ return x == null ? this.bbox().x : this.move(x, this.bbox().y)
+ }
+ // Move by left top corner over y-axis
+, y: function(y) {
+ return y == null ? this.bbox().y : this.move(this.bbox().x, y)
+ }
+ // Set element size to given width and height
+, size: function(width, height) {
+ return this.attr('points', this.points.size(width, height))
+ }
+
})
//
SVG.extend(SVG.Container, {
// Create a wrapped polyline element
- polyline: function(points, unbiased) {
- return this.put(new SVG.Polyline(unbiased)).plot(points)
+ polyline: function(p) {
+ return this.put(new SVG.Polyline).plot(p)
}
// Create a wrapped polygon element
-, polygon: function(points, unbiased) {
- return this.put(new SVG.Polygon(unbiased)).plot(points)
+, polygon: function(p) {
+ return this.put(new SVG.Polygon).plot(p)
}
+
}) \ No newline at end of file