summaryrefslogtreecommitdiffstats
path: root/src/viewbox.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2014-01-22 14:53:01 +0100
committerwout <wout@impinc.co.uk>2014-01-22 14:53:01 +0100
commit0bec3f4b0eedfa603ed0b92e151315dfc92b42c2 (patch)
tree8874b09f62fc08f9538ba577a8706ddf2e12b286 /src/viewbox.js
parentc9678562e1ba5c010ba15aa036f6ca86386c5b65 (diff)
downloadsvg.js-0bec3f4b0eedfa603ed0b92e151315dfc92b42c2.tar.gz
svg.js-0bec3f4b0eedfa603ed0b92e151315dfc92b42c2.zip
Fix in viewbox
Diffstat (limited to 'src/viewbox.js')
-rwxr-xr-xsrc/viewbox.js27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/viewbox.js b/src/viewbox.js
index 43849f2..aec60a3 100755
--- a/src/viewbox.js
+++ b/src/viewbox.js
@@ -1,14 +1,31 @@
SVG.ViewBox = function(element) {
var x, y, width, height
+ , wm = 1 /* width multiplier */
+ , hm = 1 /* height multiplier */
, box = element.bbox()
, view = (element.attr('viewBox') || '').match(/-?[\d\.]+/g)
+
+ /* get dimensions of current node */
+ width = new SVG.Number(element.width())
+ height = new SVG.Number(element.height())
+
+ /* find nearest non-percentual dimensions */
+ while (width.unit == '%') {
+ wm *= width.value
+ width = new SVG.Number(element instanceof SVG.Doc ? element.parent.offsetWidth : element.width())
+ }
+ while (height.unit == '%') {
+ hm *= height.value
+ height = new SVG.Number(element instanceof SVG.Doc ? element.parent.offsetHeight : element.height())
+ }
- /* clone attributes */
+ /* ensure defaults */
this.x = box.x
this.y = box.y
- this.width = element.node.clientWidth || element.attr('width')
- this.height = element.node.clientHeight || element.attr('height')
+ this.width = width * wm
+ this.height = height * hm
+ this.zoom = 1
if (view) {
/* get width and height from viewbox */
@@ -27,11 +44,9 @@ SVG.ViewBox = function(element) {
this.y = y
this.width = width
this.height = height
+
}
- /* ensure a default zoom value */
- this.zoom = this.zoom || 1
-
}
//