aboutsummaryrefslogtreecommitdiffstats
path: root/src/viewbox.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-02-20 20:23:44 +0100
committerwout <wout@impinc.co.uk>2013-02-20 20:23:44 +0100
commit1e183700e2582271256a279ac3e8843037e0f713 (patch)
tree45c10497c50a044cf632d49b144b1b73a5b12abd /src/viewbox.js
parentb2ac1419a015cf1d00ce5bb7b536cd1906e25c17 (diff)
downloadsvg.js-1e183700e2582271256a279ac3e8843037e0f713.tar.gz
svg.js-1e183700e2582271256a279ac3e8843037e0f713.zip
Fix in viewbox fallback
Diffstat (limited to 'src/viewbox.js')
-rw-r--r--src/viewbox.js35
1 files changed, 17 insertions, 18 deletions
diff --git a/src/viewbox.js b/src/viewbox.js
index 0e24e97..71e0a04 100644
--- a/src/viewbox.js
+++ b/src/viewbox.js
@@ -1,35 +1,34 @@
SVG.ViewBox = function(element) {
- var width, height
+ var x, y, width, height
, box = element.bbox()
, view = (element.attr('viewBox') || '').match(/[\d\.]+/g)
/* clone attributes */
this.x = box.x
this.y = box.y
- this.width = box.width
- this.height = box.height
+ this.width = element.node.offsetWidth
+ this.height = element.node.offsetHeight
+ this.zoom = 1
if (view) {
/* get width and height from viewbox */
- width = parseFloat(view[2])
- height = parseFloat(view[3])
-
- /* calculate real pixel dimensions on parent SVG.Doc element */
- if (element instanceof SVG.Doc) {
- this.x = 0
- this.y = 0
- this.width = element.node.offsetWidth
- this.height = element.node.offsetHeight
- }
+ x = parseFloat(view[0])
+ y = parseFloat(view[1])
+ width = parseFloat(view[2]) - x
+ height = parseFloat(view[3]) - y
/* calculate zoom accoring to viewbox */
- this.zoom = (this.width / this.height > width / height) ?
+ this.zoom = ((this.width / this.height) > (width / height)) ?
this.height / height :
this.width / width
-
- } else {
- this.zoom = 1
+
+ /* calculate real pixel dimensions on parent SVG.Doc element */
+ if (element instanceof SVG.Doc) {
+ this.x = x
+ this.y = y
+ this.width = width
+ this.height = height
+ }
}
-
} \ No newline at end of file