aboutsummaryrefslogtreecommitdiffstats
path: root/src/element.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-01-29 21:20:58 +0100
committerwout <wout@impinc.co.uk>2014-01-29 21:20:58 +0100
commit5b6736666dd85f8a063b87e6c6483ea47be4391c (patch)
tree139b35c98807ac36cad095af13ef45495958b78f /src/element.js
parent9688054367938f1e9240c2d8572e94bb0149bc77 (diff)
downloadsvg.js-5b6736666dd85f8a063b87e6c6483ea47be4391c.tar.gz
svg.js-5b6736666dd85f8a063b87e6c6483ea47be4391c.zip
Added SVG.PathArray, updated data() and bumped to v1.0rc1
Diffstat (limited to 'src/element.js')
-rwxr-xr-xsrc/element.js48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/element.js b/src/element.js
index ad0fc4a..50edc85 100755
--- a/src/element.js
+++ b/src/element.js
@@ -63,9 +63,11 @@ SVG.extend(SVG.Element, {
}
// Set element size to given width and height
, size: function(width, height) {
+ var p = this._proportionalSize(width, height)
+
return this.attr({
- width: new SVG.Number(width)
- , height: new SVG.Number(height)
+ width: new SVG.Number(p.width)
+ , height: new SVG.Number(p.height)
})
}
// Clone element
@@ -277,10 +279,6 @@ SVG.extend(SVG.Element, {
if (o.x != 0 || o.y != 0)
transform.push('translate(' + new SVG.Number(o.x / o.scaleX) + ' ' + new SVG.Number(o.y / o.scaleY) + ')')
- /* add offset translation */
- if (this._offset && this._offset.x != 0 && this._offset.y != 0)
- transform.push('translate(' + (-this._offset.x) + ' ' + (-this._offset.y) + ')')
-
/* update transformations, even if there are none */
if (transform.length == 0)
this.node.removeAttribute('transform')
@@ -338,28 +336,6 @@ SVG.extend(SVG.Element, {
return this
}
- // Store data values on svg nodes
-, data: function(a, v, r) {
- if (arguments.length < 2) {
- try {
- return JSON.parse(this.attr('data-' + a))
- } catch(e) {
- return this.attr('data-' + a)
- }
-
- } else {
- this.attr(
- 'data-' + a
- , v === null ?
- null :
- r === true || typeof v === 'string' || typeof v === 'number' ?
- v :
- JSON.stringify(v)
- )
- }
-
- return this
- }
// Get bounding box
, bbox: function() {
return new SVG.BBox(this)
@@ -425,5 +401,21 @@ SVG.extend(SVG.Element, {
return o
}
+ // Private: calculate proportional width and height values when necessary
+, _proportionalSize: function(width, height) {
+ if (width == null || height == null) {
+ var box = this.bbox()
+
+ if (height == null)
+ height = box.height / box.width * width
+ else if (width == null)
+ width = box.width / box.height * height
+ }
+
+ return {
+ width: width
+ , height: height
+ }
+ }
}) \ No newline at end of file