summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-07-25 13:09:30 +0100
committerwout <wout@impinc.co.uk>2013-07-25 13:09:30 +0100
commit58f10a25dbee327f496eacbf7944a561708de5ea (patch)
tree89647de589f46d40aaf01258240f8d6ad9390322 /src
parent494535622842ac8636a85c485b3057e8aa0dc5a7 (diff)
downloadsvg.js-58f10a25dbee327f496eacbf7944a561708de5ea.tar.gz
svg.js-58f10a25dbee327f496eacbf7944a561708de5ea.zip
Added SVG.Array and bumped to v0.29
Diffstat (limited to 'src')
-rw-r--r--src/array.js32
-rw-r--r--src/container.js2
-rw-r--r--src/element.js6
-rw-r--r--src/number.js2
-rw-r--r--src/poly.js12
5 files changed, 42 insertions, 12 deletions
diff --git a/src/array.js b/src/array.js
new file mode 100644
index 0000000..a955db9
--- /dev/null
+++ b/src/array.js
@@ -0,0 +1,32 @@
+// Module for array conversion
+SVG.Array = function(array, fallback) {
+ this.value = array || []
+
+ if (this.value.length == 0 && fallback)
+ this.value = fallback
+}
+
+SVG.extend(SVG.Array, {
+ // Convert array to string
+ toString: function() {
+ var array = []
+
+ /* detect array type */
+ if (Array.isArray(this.value[0])) {
+ /* it is a poly point string */
+ for (var i = 0, il = this.value.length; i < il; i++)
+ array.push(this.value[i].join(','))
+
+ } else {
+ /* it's a regular array */
+ array = this.value
+ }
+
+ return array.join(' ')
+ }
+ // Real value
+, valueOf: function() {
+ return this.value
+ }
+
+}) \ No newline at end of file
diff --git a/src/container.js b/src/container.js
index f928c54..e42001f 100644
--- a/src/container.js
+++ b/src/container.js
@@ -98,7 +98,7 @@ SVG.extend(SVG.Container, {
[v.x, v.y, v.width, v.height] :
[].slice.call(arguments)
- return this.attr('viewBox', v.join(' '))
+ return this.attr('viewBox', v)
}
// Remove all elements in this container
, clear: function() {
diff --git a/src/element.js b/src/element.js
index 3425b81..e6a7cd7 100644
--- a/src/element.js
+++ b/src/element.js
@@ -157,10 +157,14 @@ SVG.extend(SVG.Element, {
else if (a == 'stroke')
this._stroke = v
- /* ensure hex color */
+ /* ensure full hex color */
if (SVG.Color.test(v) || SVG.Color.isRgb(v))
v = new SVG.Color(v)
+ /* parse array values */
+ else if (Array.isArray(v))
+ v = new SVG.Array(v)
+
/* set give attribute on node */
n != null ?
this.node.setAttributeNS(n, a, v.toString()) :
diff --git a/src/number.js b/src/number.js
index 19d70eb..e45a8c6 100644
--- a/src/number.js
+++ b/src/number.js
@@ -38,7 +38,7 @@ SVG.Number = function(value) {
SVG.extend(SVG.Number, {
// Stringalize
toString: function() {
- return (this.unit == '%' ? this.value * 100 : this.value) + this.unit
+ return (this.unit == '%' ? ~~(this.value * 1e8) / 1e6 : this.value) + this.unit
}
, // Convert to primitive
valueOf: function() {
diff --git a/src/poly.js b/src/poly.js
index 8dd4696..74a5700 100644
--- a/src/poly.js
+++ b/src/poly.js
@@ -20,16 +20,10 @@ SVG.Polygon.prototype = new SVG.Shape
SVG.extend(SVG.Polyline, SVG.Polygon, {
// Private: Native plot
_plot: function(p) {
- if (Array.isArray(p)) {
- var i, l, points = []
-
- for (i = 0, l = p.length; i < l; i++)
- points.push(p[i].join(','))
-
- p = points.length > 0 ? points.join(' ') : '0,0'
- }
+ if (Array.isArray(p))
+ p = new SVG.Array(p, [[0,0]])
- return this.attr('points', p || '0,0')
+ return this.attr('points', p)
}
})