diff options
Diffstat (limited to 'src/svgpan_js.h')
-rw-r--r-- | src/svgpan_js.h | 100 |
1 files changed, 62 insertions, 38 deletions
diff --git a/src/svgpan_js.h b/src/svgpan_js.h index 0714d6d..ddc3eac 100644 --- a/src/svgpan_js.h +++ b/src/svgpan_js.h @@ -1,5 +1,6 @@ "/**\n" " * The code below is based on SVGPan Library 1.2 and was modified for doxygen\n" +" * to support both zooming and panning via the mouse and via embedded bottons.\n" " *\n" " * This code is licensed under the following BSD license:\n" " *\n" @@ -46,11 +47,10 @@ "if (!window) window=this;\n" "\n" "/**\n" -" * Register handlers\n" +" * Show the graph in the middle of the view, scaled to fit \n" " */\n" -"function init(evt) \n" +"function show()\n" "{\n" -" svgDoc = evt.target.ownerDocument;\n" " if (window.innerHeight) // Firefox\n" " {\n" " windowWidth = window.innerWidth;\n" @@ -61,21 +61,39 @@ " windowWidth = document.documentElement.clientWidth\n" " windowHeight = document.documentElement.clientHeight\n" " }\n" -" else\n" +" if (!windowWidth || !windowHeight) // failsafe\n" " {\n" " windowWidth = 800;\n" " windowHeight = 600;\n" " }\n" -" minZoom = windowHeight/viewHeight;\n" -" maxZoom = 1.5;\n" +" minZoom = Math.min(windowHeight/viewHeight,windowWidth/viewWidth);\n" +" maxZoom = minZoom+1.5;\n" " zoomInFactor = Math.pow(maxZoom/minZoom,1.0/zoomSteps);\n" " zoomOutFactor = 1.0/zoomInFactor;\n" "\n" " var g = svgDoc.getElementById('viewport');\n" -" var bb = g.getBBox();\n" -" var a = 'scale('+minZoom+') rotate(0) translate('+((innerWidth-viewWidth*minZoom)/(2*minZoom))+' '+viewHeight+')';\n" +" try\n" +" {\n" +" var bb = g.getBBox(); // this can throw an exception if css { display: none }\n" +" var tx = (windowWidth-viewWidth*minZoom+8)/(2*minZoom);\n" +" var ty = viewHeight+(windowHeight-viewHeight*minZoom)/(2*minZoom);\n" +" var a = 'scale('+minZoom+') rotate(0) translate('+tx+' '+ty+')';\n" +" g.setAttribute('transform',a);\n" +" }\n" +" catch(e) {}\n" +"}\n" "\n" -" g.setAttribute('transform',a);\n" +"/**\n" +" * Register handlers\n" +" */\n" +"function init(evt) \n" +"{\n" +" svgDoc = evt.target.ownerDocument;\n" +" if (top.window && top.window.registerShow) // register show function in html doc for dynamic sections\n" +" {\n" +" top.window.registerShow(sectionId,show);\n" +" }\n" +" show();\n" "\n" " setAttributes(root, {\n" " \"onmousedown\" : \"handleMouseDown(evt)\",\n" @@ -85,36 +103,22 @@ "\n" " if (window.addEventListener)\n" " {\n" -" if (navigator.userAgent.toLowerCase().indexOf('webkit') >= 0 || navigator.userAgent.toLowerCase().indexOf(\"opera\") >= 0)\n" -" window.addEventListener('mousewheel', handleMouseWheel, false); // Chrome/Safari\n" +" if (navigator.userAgent.toLowerCase().indexOf('webkit') >= 0 || \n" +" navigator.userAgent.toLowerCase().indexOf(\"opera\") >= 0 || \n" +" navigator.appVersion.indexOf(\"MSIE\") != -1)\n" +" {\n" +" window.addEventListener('mousewheel', handleMouseWheel, false); // Chrome/Safari/IE9\n" +" }\n" " else\n" +" {\n" " window.addEventListener('DOMMouseScroll', handleMouseWheel, false); // Others\n" +" }\n" " }\n" "}\n" "\n" "window.onresize=function()\n" "{\n" -" if (svgDoc)\n" -" {\n" -" var newWindowWidth;\n" -" if (window.innerWidth) // Firefox\n" -" {\n" -" newWindowWidth = window.innerWidth;\n" -" }\n" -" else if (document.documentElement.clientWidth) // Chrome/Safari\n" -" {\n" -" newWindowWidth = document.documentElement.clientWidth\n" -" }\n" -" if (newWindowWidth)\n" -" {\n" -" var g = svgDoc.getElementById(\"viewport\");\n" -" var n = g.getCTM();\n" -" n = n.translate((newWindowWidth-windowWidth)/(2*minZoom),0);\n" -" setCTM(g, n);\n" -" stateTf = stateTf.multiply(n.inverse());\n" -" windowWidth = newWindowWidth;\n" -" }\n" -" }\n" +" if (svgDoc) { show(); }\n" "}\n" "\n" "/**\n" @@ -178,9 +182,14 @@ " {\n" " delta = evt.wheelDelta / 720; // Opera\n" " }\n" +" else if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ||\n" +" navigator.appVersion.indexOf(\"MSIE\") != -1)\n" +" {\n" +" delta = evt.wheelDelta / 7200; // Chrome/IE9\n" +" }\n" " else\n" " {\n" -" delta = evt.wheelDelta / 7200; // Chrome/Safari/Opera\n" +" delta = evt.wheelDelta / 72000; // Safari\n" " }\n" " }\n" " else\n" @@ -243,6 +252,18 @@ " state = '';\n" "}\n" "\n" +"/**\n" +" * Dumps a matrix to a string (useful for debug).\n" +" */\n" +"function dumpMatrix(matrix) \n" +"{\n" +" var s = \"[ \" + matrix.a + \", \" + matrix.c + \", \" + matrix.e + \"\\n \" + matrix.b + \", \" + matrix.d + \", \" + matrix.f + \"\\n 0, 0, 1 ]\";\n" +" return s;\n" +"}\n" +"\n" +"/**\n" +" * Handler for pan buttons\n" +" */\n" "function handlePan(x,y)\n" "{\n" " var g = svgDoc.getElementById(\"viewport\");\n" @@ -250,22 +271,25 @@ "}\n" "\n" "/**\n" -" * Dumps a matrix to a string (useful for debug).\n" +" * Handle reset button\n" " */\n" -"function dumpMatrix(matrix) \n" +"function handleReset()\n" "{\n" -" var s = \"[ \" + matrix.a + \", \" + matrix.c + \", \" + matrix.e + \"\\n \" + matrix.b + \", \" + matrix.d + \", \" + matrix.f + \"\\n 0, 0, 1 ]\";\n" -" return s;\n" +" show();\n" "}\n" "\n" +"/**\n" +" * Handler for zoom buttons\n" +" */\n" "function handleZoom(evt,direction)\n" "{\n" " var g = svgDoc.getElementById(\"viewport\");\n" " var factor = direction=='in' ? zoomInFactor : zoomOutFactor;\n" " var m = g.getCTM();\n" " var p = root.createSVGPoint();\n" -" p.x = windowWidth/2; \n" +" p.x = windowWidth/2;\n" " p.y = windowHeight/2;\n" " doZoom(g,p,factor);\n" "}\n" "\n" +"\n" |