summaryrefslogtreecommitdiffstats
path: root/src/viewbox.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2013-02-20 19:10:03 +0100
committerwout <wout@impinc.co.uk>2013-02-20 19:10:03 +0100
commitae878fd63077d4c95f2de9053a6f0951b55239eb (patch)
tree5dba7bd42a8b5702faeb6cc12d2b4d4099841e51 /src/viewbox.js
parent5020240e4029a61a9620f21d7be4d9764e7723d1 (diff)
downloadsvg.js-ae878fd63077d4c95f2de9053a6f0951b55239eb.tar.gz
svg.js-ae878fd63077d4c95f2de9053a6f0951b55239eb.zip
Created separate classes for SVG.ViewBox anSVG.BBox0.6
Diffstat (limited to 'src/viewbox.js')
-rw-r--r--src/viewbox.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/viewbox.js b/src/viewbox.js
new file mode 100644
index 0000000..b6ccfab
--- /dev/null
+++ b/src/viewbox.js
@@ -0,0 +1,35 @@
+
+SVG.ViewBox = function(element) {
+ var 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
+
+ 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
+ }
+
+ /* calculate zoom accoring to viewbox */
+ this.scale = (this.width / this.height > width / height) ?
+ this.height / height :
+ this.width / width
+
+ } else {
+ this.scale = 1
+ }
+
+} \ No newline at end of file