aboutsummaryrefslogtreecommitdiffstats
path: root/src/viewbox.js
diff options
context:
space:
mode:
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
-
}
//