2 " * The code below is based on SVGPan Library 1.2 and was modified for doxygen\n"
3 " * to support both zooming and panning via the mouse and via embedded bottons.\n"
5 " * This code is licensed under the following BSD license:\n"
7 " * Copyright 2009-2010 Andrea Leofreddi <a.leofreddi@itcharm.com>. All rights reserved.\n"
9 " * Redistribution and use in source and binary forms, with or without modification, are\n"
10 " * permitted provided that the following conditions are met:\n"
12 " * 1. Redistributions of source code must retain the above copyright notice, this list of\n"
13 " * conditions and the following disclaimer.\n"
15 " * 2. Redistributions in binary form must reproduce the above copyright notice, this list\n"
16 " * of conditions and the following disclaimer in the documentation and/or other materials\n"
17 " * provided with the distribution.\n"
19 " * THIS SOFTWARE IS PROVIDED BY Andrea Leofreddi ``AS IS'' AND ANY EXPRESS OR IMPLIED\n"
20 " * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n"
21 " * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Andrea Leofreddi OR\n"
22 " * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n"
23 " * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n"
24 " * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON\n"
25 " * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\n"
26 " * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\n"
27 " * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
29 " * The views and conclusions contained in the software and documentation are those of the\n"
30 " * authors and should not be interpreted as representing official policies, either expressed\n"
31 " * or implied, of Andrea Leofreddi.\n"
34 "var root = document.documentElement;\n"
35 "var state = 'none';\n"
37 "var stateTf = root.createSVGMatrix();\n"
38 "var cursorGrab = ' url(\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAMAAAAolt3jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAlQTFRFAAAA////////c3ilYwAAAAN0Uk5T//8A18oNQQAAAD1JREFUeNp0zlEKACAIA9Bt9z90bZBZkQj29qFBEuBOzQHSnWTTyckEfqUuZgFvslH4ch3qLCO/Kr8cAgwATw4Ax6XRCcoAAAAASUVORK5CYII=\"), move';\n"
39 "var zoomSteps = 10;\n"
41 "var zoomOutFactor;\n"
47 "if (!window) window=this;\n"
50 " * Show the graph in the middle of the view, scaled to fit \n"
54 " if (window.innerHeight) // Firefox\n"
56 " windowWidth = window.innerWidth;\n"
57 " windowHeight = window.innerHeight;\n"
59 " else if (document.documentElement.clientWidth) // Chrome/Safari\n"
61 " windowWidth = document.documentElement.clientWidth\n"
62 " windowHeight = document.documentElement.clientHeight\n"
64 " if (!windowWidth || !windowHeight) // failsafe\n"
66 " windowWidth = 800;\n"
67 " windowHeight = 600;\n"
69 " minZoom = Math.min(Math.min(viewHeight,windowHeight)/viewHeight,Math.min(viewWidth,windowWidth)/viewWidth);\n"
70 " maxZoom = minZoom+1.5;\n"
71 " zoomInFactor = Math.pow(maxZoom/minZoom,1.0/zoomSteps);\n"
72 " zoomOutFactor = 1.0/zoomInFactor;\n"
74 " var g = svgDoc.getElementById('viewport');\n"
77 " var bb = g.getBBox(); // this can throw an exception if css { display: none }\n"
78 " var tx = (windowWidth-viewWidth*minZoom+8)/(2*minZoom);\n"
79 " var ty = viewHeight+(windowHeight-viewHeight*minZoom)/(2*minZoom);\n"
80 " var a = 'scale('+minZoom+') rotate(0) translate('+tx+' '+ty+')';\n"
81 " g.setAttribute('transform',a);\n"
87 " * Register handlers\n"
89 "function init(evt) \n"
91 " svgDoc = evt.target.ownerDocument;\n"
92 " if (top.window && top.window.registerShow) // register show function in html doc for dynamic sections\n"
94 " top.window.registerShow(sectionId,show);\n"
98 " setAttributes(root, {\n"
99 " \"onmousedown\" : \"handleMouseDown(evt)\",\n"
100 " \"onmousemove\" : \"handleMouseMove(evt)\",\n"
101 " \"onmouseup\" : \"handleMouseUp(evt)\"\n"
104 " if (window.addEventListener)\n"
106 " if (navigator.userAgent.toLowerCase().indexOf('webkit') >= 0 || \n"
107 " navigator.userAgent.toLowerCase().indexOf(\"opera\") >= 0 || \n"
108 " navigator.appVersion.indexOf(\"MSIE\") != -1)\n"
110 " window.addEventListener('mousewheel', handleMouseWheel, false); // Chrome/Safari/IE9\n"
114 " window.addEventListener('DOMMouseScroll', handleMouseWheel, false); // Others\n"
119 "window.onresize=function()\n"
121 " if (svgDoc) { show(); }\n"
125 " * Instance an SVGPoint object with given event coordinates.\n"
127 "function getEventPoint(evt) \n"
129 " var p = root.createSVGPoint();\n"
130 " p.x = evt.clientX;\n"
131 " p.y = evt.clientY;\n"
136 " * Sets the current transform matrix of an element.\n"
138 "function setCTM(element, matrix) \n"
140 " var s = \"matrix(\" + matrix.a + \",\" + matrix.b + \",\" + matrix.c + \",\" + matrix.d + \",\" + matrix.e + \",\" + matrix.f + \")\";\n"
141 " element.setAttribute(\"transform\", s);\n"
145 " * Sets attributes of an element.\n"
147 "function setAttributes(element, attributes)\n"
149 " for (i in attributes)\n"
150 " element.setAttributeNS(null, i, attributes[i]);\n"
153 "function doZoom(g,point,zoomFactor)\n"
155 " var p = point.matrixTransform(g.getCTM().inverse());\n"
156 " var k = root.createSVGMatrix().translate(p.x, p.y).scale(zoomFactor).translate(-p.x, -p.y);\n"
157 " var n = g.getCTM().multiply(k);\n"
158 " var s = Math.max(n.a,n.d);\n"
159 " if (s>maxZoom) n=n.translate(p.x,p.y).scale(maxZoom/s).translate(-p.x,-p.y);\n"
160 " else if (s<minZoom) n=n.translate(p.x,p.y).scale(minZoom/s).translate(-p.x,-p.y);\n"
162 " stateTf = stateTf.multiply(n.inverse());\n"
166 " * Handle mouse move event.\n"
168 "function handleMouseWheel(evt) \n"
170 " if (!evt) evt = window.evt;\n"
171 " if (!evt.shiftKey) return; // only zoom when shift is pressed\n"
172 " if (evt.preventDefault) evt.preventDefault();\n"
173 " evt.returnValue = false;\n"
175 " if (state!='pan')\n"
178 " if (evt.wheelDelta)\n"
180 " delta = evt.wheelDelta / 7200; // Opera/Chrome/IE9/Safari\n"
184 " delta = evt.detail / -180; // Mozilla\n"
186 " var svgDoc = evt.target.ownerDocument;\n"
187 " var g = svgDoc.getElementById(\"viewport\");\n"
188 " var p = getEventPoint(evt);\n"
189 " doZoom(g,p,1+delta);\n"
194 " * Handle mouse move event.\n"
196 "function handleMouseMove(evt) \n"
198 " if(evt.preventDefault)\n"
199 " evt.preventDefault();\n"
201 " evt.returnValue = false;\n"
203 " var g = svgDoc.getElementById(\"viewport\");\n"
205 " if (state == 'pan') \n"
208 " var p = getEventPoint(evt).matrixTransform(stateTf);\n"
209 " setCTM(g,stateTf.inverse().translate(p.x - stateOrigin.x, p.y - stateOrigin.y));\n"
214 " * Handle click event.\n"
216 "function handleMouseDown(evt) \n"
218 " if(evt.preventDefault)\n"
219 " evt.preventDefault();\n"
220 " evt.returnValue = false;\n"
221 " var g = svgDoc.getElementById(\"viewport\");\n"
223 " stateTf = g.getCTM().inverse();\n"
224 " stateOrigin = getEventPoint(evt).matrixTransform(stateTf);\n"
225 " g.style.cursor = cursorGrab;\n"
229 " * Handle mouse button release event.\n"
231 "function handleMouseUp(evt) \n"
233 " if (evt.preventDefault) evt.preventDefault();\n"
234 " evt.returnValue = false;\n"
235 " var g = svgDoc.getElementById(\"viewport\");\n"
236 " g.style.cursor = \"default\";\n"
237 " // Quit pan mode\n"
242 " * Dumps a matrix to a string (useful for debug).\n"
244 "function dumpMatrix(matrix) \n"
246 " var s = \"[ \" + matrix.a + \", \" + matrix.c + \", \" + matrix.e + \"\\n \" + matrix.b + \", \" + matrix.d + \", \" + matrix.f + \"\\n 0, 0, 1 ]\";\n"
251 " * Handler for pan buttons\n"
253 "function handlePan(x,y)\n"
255 " var g = svgDoc.getElementById(\"viewport\");\n"
256 " setCTM(g,g.getCTM().translate(x*20/minZoom,y*20/minZoom));\n"
260 " * Handle reset button\n"
262 "function handleReset()\n"
268 " * Handler for zoom buttons\n"
270 "function handleZoom(evt,direction)\n"
272 " var g = svgDoc.getElementById(\"viewport\");\n"
273 " var factor = direction=='in' ? zoomInFactor : zoomOutFactor;\n"
274 " var m = g.getCTM();\n"
275 " var p = root.createSVGPoint();\n"
276 " p.x = windowWidth/2;\n"
277 " p.y = windowHeight/2;\n"
278 " doZoom(g,p,factor);\n"
281 "function serializeXmlNode(xmlNode) \n"
283 " if (typeof window.XMLSerializer != \"undefined\") {\n"
284 " return (new window.XMLSerializer()).serializeToString(xmlNode);\n"
285 " } else if (typeof xmlNode.xml != \"undefined\") {\n"
286 " return xmlNode.xml;\n"
292 " * Handler for print function\n"
294 "function handlePrint(evt)\n"
296 " evt.returnValue = false;\n"
297 " var g = svgDoc.getElementById(\"graph\");\n"
298 " var xs = serializeXmlNode(g);\n"
300 " var w = window.open('about:blank','_blank','width='+windowWidth+',height='+windowHeight+\n"
301 " ',toolbar=0,status=0,menubar=0,scrollbars=0,resizable=0,location=0,directories=0');\n"
302 " var d = w.document;\n"
303 " d.write('<html xmlns=\"http://www.w3.org/1999/xhtml\" '+\n"
304 " 'xmlns:svg=\"http://www.w3.org/2000/svg\" '+\n"
305 " 'xmlns:xlink=\"http://www.w3.org/1999/xlink\">');\n"
306 " d.write('<head><title>Print SVG</title></head>');\n"
307 " d.write('<body style=\"margin: 0px; padding: 0px;\" onload=\"window.print();\">');\n"
308 " d.write('<div id=\"svg\" style=\"width:'+windowWidth+'px; height:'+windowHeight+'px;\">'+xs+'</div>');\n"
309 " d.write('</body>');\n"
310 " d.write('</html>');\n"
313 " alert('Failed to open popup window needed for printing!\\n'+e.message);\n"