2 "//The scripts for the tooltip and moveobj are based on work from\n"
3 "//SVG - Learning By Coding - http://www.datenverdrahten.de/svglbc/\n"
4 "//Author: Dr. Thomas Meinike 11/03 - thomas@handmadecode.de\n"
5 "var svgdoc,svgroot,paths,revert;\n"
6 "var collapsed = new Array(2);\n"
7 "var name = new Array(%i);\n"
8 "var clickStatus = new Array(%i);\n"
9 "var redCount = new Array(%i);\n"
10 "var salmonCount = new Array(%i);\n"
11 "var moveObj,rect,x,y,attr1,attr2,wert1,wert2,zoom=1,active=false;\n"
13 "function MoveObj(evt)\n"
16 " var roundx, roundy;\n"
17 " var curtrans=svgroot.currentTranslate;\n"
18 " var ctx=curtrans.x;\n"
19 " var cty=curtrans.y;\n"
23 " wert1=(x-ctx)*zoom*%.2f+%.2f+attr1-5;\n"
24 " wert2=(y-cty)*zoom*%.2f+%.2f+attr2-5;\n"
25 " roundx=Math.round(wert1*100)/100;\n"
26 " roundy=Math.round(wert2*100)/100;\n"
28 " moveObj.setAttribute(\"transform\",\"translate(\"+roundx+\",\"+roundy+\")\");\n"
32 "function ClickObj(evt)\n"
34 " rect=evt.target.parentNode.getElementsByTagName(\"rect\").item(0);\n"
35 " moveObj=evt.target.parentNode;\n"
36 " attr1=rect.getAttribute(\"width\")/2;\n"
37 " attr2=rect.getAttribute(\"height\")/2;\n"
41 "function OutOfObj(evt)\n"
45 " findAdjacentEdges();\n"
49 "function findAdjacentEdges()\n"
51 " var rectl, rectlid, i, nodenames;\n"
53 " rectlid = rectl.getAttribute(\"id\");\n"
54 " for (i=0; i<paths.length; i++) {\n"
55 " nodenames = paths.item(i).getAttribute(\"id\").split(\"-\");\n"
56 " if (nodenames[0] == rectlid || nodenames[1] == rectlid) {\n"
57 " repaintEdge(paths.item(i), nodenames, i);\n"
62 "function repaintEdge(edge, nodenames, j)\n"
64 " var startnode, endnode, attr, i, k, l, m, alpha, beta;\n"
65 " var nodesx, nodesy, nodeex, nodeey, nodesw, nodesh, nodeew, nodeeh;\n"
66 " var edgesx, edgesy, edgeex, edgeey, sx, sy, ex, ey;\n"
68 " //extract node coordinates and dimensions\n"
69 " startnode = svgdoc.getElementById(nodenames[0]);\n"
70 " nodesw=startnode.getAttribute(\"width\");\n"
71 " nodesh=startnode.getAttribute(\"height\");\n"
72 " attr = startnode.parentNode.attributes;\n"
73 " for (i=0;i<attr.length;i++) {\n"
74 " if (attr.item(i).nodeName == \"transform\") {\n"
75 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
76 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
77 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
78 " nodesx = parseFloat(attr.item(i).nodeValue.substring(k+1,l));\n"
79 " nodesy = parseFloat(attr.item(i).nodeValue.substring(l+1,m));\n"
82 " endnode = svgdoc.getElementById(nodenames[1]);\n"
83 " nodeew=endnode.getAttribute(\"width\");\n"
84 " nodeeh=endnode.getAttribute(\"height\");\n"
85 " attr = endnode.parentNode.attributes;\n"
86 " for (i=0;i<attr.length;i++) {\n"
87 " if (attr.item(i).nodeName == \"transform\") {\n"
88 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
89 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
90 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
91 " nodeex = parseFloat(attr.item(i).nodeValue.substring(k+1,l));\n"
92 " nodeey = parseFloat(attr.item(i).nodeValue.substring(l+1,m));\n"
96 " alpha = Math.atan((nodesy-nodeey)/(nodesx-nodeex));\n"
98 " alpha += Math.PI;\n"
100 " //calculate intersection of edge and startNode\n"
101 " beta = Math.atan(nodesh/nodesw);\n"
102 " if (alpha < beta\n"
103 " || (alpha > Math.PI-beta && alpha < Math.PI+beta)\n"
104 " || alpha > 2*Math.PI-beta) {\n"
105 " //intersection at left or right border\n"
106 " if (nodesx < nodeex) {\n"
107 " edgesx = nodesx - 0 + nodesw/2;\n"
109 " edgesx = nodesx - nodesw/2;\n"
111 " if (nodesy < nodeey) {\n"
112 " edgesy = nodesy - 0 + Math.abs(nodesw*Math.tan(alpha)/2);\n"
114 " edgesy = nodesy - Math.abs(nodesw*Math.tan(alpha)/2);\n"
117 " //intersection at top or bottom border\n"
118 " if (nodesy < nodeey) {\n"
119 " edgesy = nodesy - 0 + nodesh/2;\n"
121 " edgesy = nodesy - nodesh/2;\n"
123 " if (nodesx < nodeex) {\n"
124 " edgesx = nodesx - 0 + Math.abs(nodesh/(2*Math.tan(alpha)));\n"
126 " edgesx = nodesx - Math.abs(nodesh/(2*Math.tan(alpha)));\n"
130 " //calculate intersection of edge and endNode\n"
131 " beta = Math.atan(nodeeh/nodeew);\n"
132 " if (alpha < beta\n"
133 " || (alpha > Math.PI-beta && alpha < Math.PI+beta)\n"
134 " || alpha > 2*Math.PI-beta) {\n"
135 " //intersection at left or right border\n"
136 " if (nodesx > nodeex) {\n"
137 " edgeex = nodeex - 0 + nodeew/2;\n"
139 " edgeex = nodeex - nodeew/2;\n"
141 " if (nodesy > nodeey) {\n"
142 " edgeey = nodeey - 0 + Math.abs(nodeew*Math.tan(alpha)/2);\n"
144 " edgeey = nodeey - Math.abs(nodeew*Math.tan(alpha)/2);\n"
147 " //intersection at top or bottom border\n"
148 " if (nodesy > nodeey) {\n"
149 " edgeey = nodeey - 0 + nodeeh/2;\n"
151 " edgeey = nodeey - nodeeh/2;\n"
153 " if (nodesx > nodeex) {\n"
154 " edgeex = nodeex - 0 + Math.abs(nodeeh/(2*Math.tan(alpha)));\n"
156 " edgeex = nodeex - Math.abs(nodeeh/(2*Math.tan(alpha)));\n"
160 " //set new edge coordinates\n"
161 " sx=Math.round(edgesx*100)/100;\n"
162 " ex=Math.round(edgeex*100)/100;\n"
163 " sy=Math.round(edgesy*100)/100;\n"
164 " ey=Math.round(edgeey*100)/100;\n"
167 " if (revert[j] == 1) {\n"
169 " flipEdgeMarks(edge);\n"
171 " edge.setAttribute(\"d\",\"M \"+sx+\" \"+sy+\" \"+ex+\" \"+ey);\n"
173 " if (revert[j] == 0) {\n"
175 " flipEdgeMarks(edge);\n"
177 " edge.setAttribute(\"d\",\"M \"+ex+\" \"+ey+\" \"+sx+\" \"+sy);\n"
181 "function flipEdgeMarks(edge)\n"
183 " var attr, i, j, done, textpaths, pathnamei, offset;\n"
185 " //revert start- and end-markers\n"
186 " attr = edge.attributes;\n"
188 " for (i=0;i<attr.length;i++) {\n"
189 " if (attr.item(i).nodeName == \"marker-start\") {\n"
190 " for (j=i;j<attr.length;j++) {\n"
191 " if (attr.item(j).nodeName == \"marker-end\") {\n"
195 " if (done == 0) {\n"
197 " edge.removeAttribute(\"marker-start\");\n"
198 " edge.setAttribute(\"marker-end\",\"url(#arrowend)\");\n"
202 " if (attr.item(i).nodeName == \"marker-end\") {\n"
203 " for (j=i;j<attr.length;j++) {\n"
204 " if (attr.item(j).nodeName == \"marker-start\") {\n"
208 " if (done == 0) {\n"
210 " edge.removeAttribute(\"marker-end\");\n"
211 " edge.setAttribute(\"marker-start\",\"url(#arrowstart)\");\n"
217 " //revert cardinalities\n"
218 " textpaths = svgdoc.getElementsByTagName(\"textPath\");\n"
219 " for (i=0;i<textpaths.length;i++) {\n"
220 " pathname = textpaths.item(i).getAttribute(\"xlink:href\").replace(/#/,\"\");\n"
221 " if (pathname == edge.getAttribute(\"id\")) {\n"
222 " offset = textpaths.item(i).getAttribute(\"startOffset\").substr(0,2);\n"
223 " textpaths.item(i).setAttribute(\"startOffset\",100 - offset + \"%\")\n"
228 "function getSVGDoc(load_evt)\n"
230 " svgdoc=load_evt.target.ownerDocument;\n"
231 " svgroot=svgdoc.documentElement;\n"
232 " texte=svgdoc.getElementById(\"tooltip\").getElementsByTagName(\"text\");\n"
233 " for (i=1; i<%i; i++) {\n"
234 " textNode=texte.item(1).cloneNode(\"true\");\n"
235 " svgdoc.getElementById(\"tooltip\").appendChild(textNode);\n"
237 " texte=svgdoc.getElementById(\"tooltip\").getElementsByTagName(\"text\");\n"
240 "function ShowTooltipMZ(mousemove_event,txt)\n"
242 " var ttrelem,tttelem,ttline,posx,posy,curtrans,ctx,cty,txt;\n"
243 " var maxbreite,tmp,i;\n"
244 " ttrelem=svgdoc.getElementById(\"ttr\");\n"
245 " tttelem=svgdoc.getElementById(\"ttt\");\n"
246 " ttline=svgdoc.getElementById(\"ttl\");\n"
247 " posx=mousemove_event.clientX;\n"
248 " posy=mousemove_event.clientY;\n"
249 " for (i=1;i<=%i;i++)\n"
250 " texte.item(i).firstChild.data=\"\";\n"
251 " tttelem.childNodes.item(0).data=\"\";\n"
252 " tmp=txt.split(\"\\n\");\n"
254 " for (i=0;i<tmp.length;i++) {\n"
255 " if (tmp[i]==\"\")\n"
257 " tttelem.childNodes.item(0).data=tmp[i];\n"
258 " if (maxbreite<tttelem.getComputedTextLength())\n"
259 " maxbreite=tttelem.getComputedTextLength();\n"
261 " curtrans=svgroot.currentTranslate;\n"
264 " ttrelem.setAttribute(\"x\",posx-ctx+10);\n"
265 " ttrelem.setAttribute(\"y\",posy-cty-20+10);\n"
266 " ttrelem.setAttribute(\"width\",maxbreite*0.92+10);\n"
267 " ttrelem.setAttribute(\"height\",tmp.length*15+3);\n"
268 " ttrelem.setAttribute(\"style\",\n"
269 " \"fill: #FFC; stroke: #000; stroke-width: 0.5px\");\n"
270 " for (i=1; i<=tmp.length; i++) {\n"
271 " if (tmp[i-1]==\"-- -- --\") {\n"
272 " ttline.setAttribute(\"x1\", posx-ctx+10);\n"
273 " ttline.setAttribute(\"y1\", parseInt(i-1)*15+posy-cty);\n"
274 " ttline.setAttribute(\"x2\", posx-ctx+10+maxbreite*0.92+10);\n"
275 " ttline.setAttribute(\"y2\", parseInt(i-1)*15+posy-cty);\n"
276 " ttline.setAttribute(\"style\", \"stroke: #000; stroke-width: 0.5px\");\n"
278 " texte.item(i).firstChild.data=tmp[i-1];\n"
279 " texte.item(i).setAttribute(\"x\",posx-ctx+15);\n"
280 " texte.item(i).setAttribute(\"y\",parseInt(i-1)*15+posy-cty+3);\n"
281 " texte.item(i).setAttribute(\"style\",\"fill: #00E; font-size: 11px\");\n"
284 " svgdoc.getElementById(\"tooltip\").style.setProperty(\"visibility\",\"visible\");\n"
287 "function HideTooltip()\n"
289 " svgdoc.getElementById(\"ttl\").style.setProperty(\"visibility\",\"hidden\");\n"
290 " svgdoc.getElementById(\"tooltip\").style.setProperty(\"visibility\",\"hidden\");\n"
293 "function ZoomControl()\n"
296 " curzoom=svgroot.currentScale;\n"
297 " svgdoc.getElementById(\"tooltip\").setAttribute(\"transform\",\n"
298 " \"scale(\"+1/curzoom+\")\");\n"
302 "function collapse(evt)\n"
304 " var i, k, l, m, svgdoc, obj, targetID, targetX, targetY, attr;\n"
305 " obj = evt.getTarget();\n"
306 " svgdoc = obj.ownerDocument;\n"
307 " //extract coordinates and id of the clicked text\n"
308 " attr = obj.parentNode.parentNode.attributes;\n"
309 " for (i=0;i<attr.length;i++) {\n"
310 " if (attr.item(i).nodeName == \"transform\") {\n"
311 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
312 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
313 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
314 " targetX = attr.item(i).nodeValue.substring(k+1,l);\n"
315 " targetY = attr.item(i).nodeValue.substring(l+1,m);\n"
317 " if (attr.item(i).nodeName == \"id\") {\n"
318 " targetID = attr.item(i).nodeValue.substr(2);\n"
321 " //decide if we are collapsing or uncollapsing\n"
322 " if (collapsed[0][targetID] == 0) {\n"
323 " hideInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr);\n"
324 " collapsed[0][targetID] = 1;\n"
326 " showHiddenInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr);\n"
327 " collapsed[0][targetID] = 0;\n"
331 "function showHiddenInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr)\n"
333 " var i, k, l, m, nextObj, nextX, nextY, gapY=0, clickedID;\n"
334 " //change clicked text\n"
335 " obj.firstChild.data=\"--\";\n"
337 " nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
338 " if (nextObj == null)\n"
340 " //show child texts again\n"
342 " attr = nextObj.attributes;\n"
343 " for (i=0;i<attr.length;i++) {\n"
344 " if (attr.item(i).nodeName == \"transform\") {\n"
345 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
346 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
347 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
348 " nextX = attr.item(i).nodeValue.substring(k+1,l);\n"
349 " nextY = attr.item(i).nodeValue.substring(l+1,m);\n"
352 " if (nextX > targetX) {\n"
353 " nextObj.style.setProperty(\"visibility\",\"visible\");\n"
355 " if (collapsed[0][targetID] == 1) {\n"
356 " targetID = collapsed[1][targetID];\n"
360 " nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
361 " if (nextObj == null)\n"
367 " if (nextObj == null)\n"
369 " //move following texts downwards\n"
370 " while (nextObj != null) {\n"
371 " attr = nextObj.attributes;\n"
372 " for (i=0;i<attr.length;i++) {\n"
373 " if (attr.item(i).nodeName == \"transform\") {\n"
374 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
375 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
376 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
377 " nextX = attr.item(i).nodeValue.substring(k+1,l);\n"
378 " nextY = attr.item(i).nodeValue.substring(l+1,m);\n"
381 " nextY = nextY - 1 + gapY + 1;\n"
382 " nextObj.setAttribute(\"transform\",\"translate(\"+nextX+\",\"+nextY+\")\");\n"
384 " nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
388 "function hideInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr)\n"
390 " var i, k, l, m, nextObj, nextX, nextY, gapY=0;\n"
391 " clickedID = targetID;\n"
392 " //change clicked text\n"
393 " obj.firstChild.data=\"+\";\n"
395 " nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
396 " if (nextObj == null)\n"
398 " //wipe out child texts\n"
400 " attr = nextObj.attributes;\n"
401 " for (i=0;i<attr.length;i++) {\n"
402 " if (attr.item(i).nodeName == \"transform\") {\n"
403 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
404 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
405 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
406 " nextX = attr.item(i).nodeValue.substring(k+1,l);\n"
407 " nextY = attr.item(i).nodeValue.substring(l+1,m);\n"
410 " if (nextX > targetX) {\n"
411 " nextObj.style.setProperty(\"visibility\",\"hidden\");\n"
413 " if (collapsed[0][targetID] == 1) {\n"
414 " targetID = collapsed[1][targetID];\n"
418 " nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
419 " if (nextObj == null)\n"
425 " //save next uncollapsed element in array\n"
426 " collapsed[1][clickedID] = targetID;\n"
427 " if (nextObj == null)\n"
429 " //move following texts upwards\n"
430 " while (nextObj != null) {\n"
431 " attr = nextObj.attributes;\n"
432 " for (i=0;i<attr.length;i++) {\n"
433 " if (attr.item(i).nodeName == \"transform\") {\n"
434 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
435 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
436 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
437 " nextX = attr.item(i).nodeValue.substring(k+1,l);\n"
438 " nextY = attr.item(i).nodeValue.substring(l+1,m);\n"
442 " nextObj.setAttribute(\"transform\",\"translate(\"+nextX+\",\"+nextY+\")\");\n"
444 " nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
448 "function init(evt)\n"
450 " var nodenames, startnode, endnode, attr, i, j, k, l, m, nodesx, nodeex;\n"
451 " collapsed[0] = new Array(%i);\n"
452 " collapsed[1] = new Array(%i);\n"
453 " for (i=0; i<%i; i++) {\n"
454 " collapsed[0][i] = 0;\n"
455 " collapsed[1][i] = 0;\n"
457 " for (i=0; i<%i; i++) {\n"
459 " clickStatus[i] = 0;\n"
460 " redCount[i] = 0;\n"
461 " salmonCount[i] = 0;\n"
465 " //check which edges are printed from right to left\n"
466 " paths = svgdoc.getElementsByTagName(\"path\");\n"
467 " revert = new Array(paths.length);\n"
468 " for (j=0; j<paths.length; j++) {\n"
469 " nodenames = paths.item(j).getAttribute(\"id\").split(\"-\");\n"
470 " startnode = svgdoc.getElementById(nodenames[0]);\n"
471 " attr = startnode.parentNode.attributes;\n"
472 " for (i=0;i<attr.length;i++) {\n"
473 " if (attr.item(i).nodeName == \"transform\") {\n"
474 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
475 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
476 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
477 " nodesx = parseFloat(attr.item(i).nodeValue.substring(k+1,l));\n"
480 " endnode = svgdoc.getElementById(nodenames[1]);\n"
481 " attr = endnode.parentNode.attributes;\n"
482 " for (i=0;i<attr.length;i++) {\n"
483 " if (attr.item(i).nodeName == \"transform\") {\n"
484 " k = attr.item(i).nodeValue.indexOf(\"(\");\n"
485 " l = attr.item(i).nodeValue.indexOf(\",\");\n"
486 " m = attr.item(i).nodeValue.indexOf(\")\");\n"
487 " nodeex = parseFloat(attr.item(i).nodeValue.substring(k+1,l));\n"
490 " if (nodesx > nodeex) {\n"
498 "function setStatus(evt, color1, color2)\n"
500 " var clickObj = evt.getTarget();\n"
501 " var clickObjName = clickObj.getAttribute('id');\n"
503 " //find i corresponding to the clicked object\n"
504 " for (i=0; i<%i; i++) {\n"
505 " if (name[i] == \"\") {\n"
506 " name[i] = clickObjName;\n"
509 " if (name[i] != clickObjName)\n"
514 " //toggle click status, color clicked object\n"
515 " if (clickStatus[i] == 0) {\n"
516 " clickStatus[i] = 1;\n"
517 " clickObj.setAttribute(\"style\",\"fill: \"+color1);\n"
519 " clickStatus[i] = 0;\n"
520 " clickObj.setAttribute(\"style\",\"fill: \"+color2);\n"
523 " //adjust color-counter\n"
524 " if (color1 == 'red') {\n"
525 " if (clickStatus[i] == 1) {\n"
531 " if (color1 == 'salmon') {\n"
532 " if (clickStatus[i] == 1) {\n"
533 " salmonCount[i]++;\n"
535 " salmonCount[i]--;\n"
539 " if (clickStatus[i] == 0 && salmonCount[i] > 0) {\n"
540 " clickObj.setAttribute(\"style\",\"fill: salmon\");\n"
544 "function changeColor(evt, targetObjName, color1, color2)\n"
546 " var clickObj = evt.getTarget();\n"
547 " var clickObjName = clickObj.getAttribute('id');\n"
548 " var targetObj = svgDocument.getElementById(targetObjName);\n"
550 " //find i corresponding to the clicked object\n"
551 " for (i=0; i<%i; i++) {\n"
552 " if (name[i] != clickObjName)\n"
557 " //find j corresponding to the target object\n"
558 " for (j=0; j<%i; j++) {\n"
559 " if (name[j] == \"\") {\n"
560 " name[j] = targetObjName;\n"
563 " if (name[j] != targetObjName)\n"
568 " //adjust color-counter\n"
569 " if (color1 == 'red') {\n"
570 " if (clickStatus[i] == 1) {\n"
576 " if (color1 == 'salmon') {\n"
577 " if (clickStatus[i] == 1) {\n"
578 " salmonCount[j]++;\n"
580 " salmonCount[j]--;\n"
585 "function colorText(targetObjName, color)\n"
587 " var targetObj = svgDocument.getElementById(targetObjName);\n"
589 " //find i corresponding to the target object\n"
590 " for (i=0; i<%i; i++) {\n"
591 " if (name[i] != targetObjName)\n"
598 " targetObj.setAttribute(\"style\",\"fill: \"+color);\n"
601 " if (redCount[i] == 0 && salmonCount[i] == 0) {\n"
602 " targetObj.setAttribute(\"style\",\"fill: \"+color);\n"
604 " if (salmonCount[i] > 0) {\n"
605 " if (color == 'red') {\n"
606 " targetObj.setAttribute(\"style\",\"fill: red\");\n"
608 " if (redCount[i] > 0) {\n"
609 " targetObj.setAttribute(\"style\",\"fill: red\");\n"
611 " targetObj.setAttribute(\"style\",\"fill: salmon\");\n"