1 //The scripts for the tooltip and moveobj are based on work from
2 //SVG - Learning By Coding - http://www.datenverdrahten.de/svglbc/
3 //Author: Dr. Thomas Meinike 11/03 - thomas@handmadecode.de
4 var svgdoc,svgroot,paths,revert;
5 var collapsed = new Array(2);
6 var name = new Array(%i);
7 var clickStatus = new Array(%i);
8 var redCount = new Array(%i);
9 var salmonCount = new Array(%i);
10 var moveObj,rect,x,y,attr1,attr2,wert1,wert2,zoom=1,active=false;
16 var curtrans=svgroot.currentTranslate;
22 wert1=(x-ctx)*zoom*%.2f+%.2f+attr1-5;
23 wert2=(y-cty)*zoom*%.2f+%.2f+attr2-5;
24 roundx=Math.round(wert1*100)/100;
25 roundy=Math.round(wert2*100)/100;
27 moveObj.setAttribute("transform","translate("+roundx+","+roundy+")");
31 function ClickObj(evt)
33 rect=evt.target.parentNode.getElementsByTagName("rect").item(0);
34 moveObj=evt.target.parentNode;
35 attr1=rect.getAttribute("width")/2;
36 attr2=rect.getAttribute("height")/2;
40 function OutOfObj(evt)
48 function findAdjacentEdges()
50 var rectl, rectlid, i, nodenames;
52 rectlid = rectl.getAttribute("id");
53 for (i=0; i<paths.length; i++) {
54 nodenames = paths.item(i).getAttribute("id").split("-");
55 if (nodenames[0] == rectlid || nodenames[1] == rectlid) {
56 repaintEdge(paths.item(i), nodenames, i);
61 function repaintEdge(edge, nodenames, j)
63 var startnode, endnode, attr, i, k, l, m, alpha, beta;
64 var nodesx, nodesy, nodeex, nodeey, nodesw, nodesh, nodeew, nodeeh;
65 var edgesx, edgesy, edgeex, edgeey, sx, sy, ex, ey;
67 //extract node coordinates and dimensions
68 startnode = svgdoc.getElementById(nodenames[0]);
69 nodesw=startnode.getAttribute("width");
70 nodesh=startnode.getAttribute("height");
71 attr = startnode.parentNode.attributes;
72 for (i=0;i<attr.length;i++) {
73 if (attr.item(i).nodeName == "transform") {
74 k = attr.item(i).nodeValue.indexOf("(");
75 l = attr.item(i).nodeValue.indexOf(",");
76 m = attr.item(i).nodeValue.indexOf(")");
77 nodesx = parseFloat(attr.item(i).nodeValue.substring(k+1,l));
78 nodesy = parseFloat(attr.item(i).nodeValue.substring(l+1,m));
81 endnode = svgdoc.getElementById(nodenames[1]);
82 nodeew=endnode.getAttribute("width");
83 nodeeh=endnode.getAttribute("height");
84 attr = endnode.parentNode.attributes;
85 for (i=0;i<attr.length;i++) {
86 if (attr.item(i).nodeName == "transform") {
87 k = attr.item(i).nodeValue.indexOf("(");
88 l = attr.item(i).nodeValue.indexOf(",");
89 m = attr.item(i).nodeValue.indexOf(")");
90 nodeex = parseFloat(attr.item(i).nodeValue.substring(k+1,l));
91 nodeey = parseFloat(attr.item(i).nodeValue.substring(l+1,m));
95 alpha = Math.atan((nodesy-nodeey)/(nodesx-nodeex));
99 //calculate intersection of edge and startNode
100 beta = Math.atan(nodesh/nodesw);
102 || (alpha > Math.PI-beta && alpha < Math.PI+beta)
103 || alpha > 2*Math.PI-beta) {
104 //intersection at left or right border
105 if (nodesx < nodeex) {
106 edgesx = nodesx - 0 + nodesw/2;
108 edgesx = nodesx - nodesw/2;
110 if (nodesy < nodeey) {
111 edgesy = nodesy - 0 + Math.abs(nodesw*Math.tan(alpha)/2);
113 edgesy = nodesy - Math.abs(nodesw*Math.tan(alpha)/2);
116 //intersection at top or bottom border
117 if (nodesy < nodeey) {
118 edgesy = nodesy - 0 + nodesh/2;
120 edgesy = nodesy - nodesh/2;
122 if (nodesx < nodeex) {
123 edgesx = nodesx - 0 + Math.abs(nodesh/(2*Math.tan(alpha)));
125 edgesx = nodesx - Math.abs(nodesh/(2*Math.tan(alpha)));
129 //calculate intersection of edge and endNode
130 beta = Math.atan(nodeeh/nodeew);
132 || (alpha > Math.PI-beta && alpha < Math.PI+beta)
133 || alpha > 2*Math.PI-beta) {
134 //intersection at left or right border
135 if (nodesx > nodeex) {
136 edgeex = nodeex - 0 + nodeew/2;
138 edgeex = nodeex - nodeew/2;
140 if (nodesy > nodeey) {
141 edgeey = nodeey - 0 + Math.abs(nodeew*Math.tan(alpha)/2);
143 edgeey = nodeey - Math.abs(nodeew*Math.tan(alpha)/2);
146 //intersection at top or bottom border
147 if (nodesy > nodeey) {
148 edgeey = nodeey - 0 + nodeeh/2;
150 edgeey = nodeey - nodeeh/2;
152 if (nodesx > nodeex) {
153 edgeex = nodeex - 0 + Math.abs(nodeeh/(2*Math.tan(alpha)));
155 edgeex = nodeex - Math.abs(nodeeh/(2*Math.tan(alpha)));
159 //set new edge coordinates
160 sx=Math.round(edgesx*100)/100;
161 ex=Math.round(edgeex*100)/100;
162 sy=Math.round(edgesy*100)/100;
163 ey=Math.round(edgeey*100)/100;
166 if (revert[j] == 1) {
170 edge.setAttribute("d","M "+sx+" "+sy+" "+ex+" "+ey);
172 if (revert[j] == 0) {
176 edge.setAttribute("d","M "+ex+" "+ey+" "+sx+" "+sy);
180 function flipEdgeMarks(edge)
182 var attr, i, j, done, textpaths, pathnamei, offset;
184 //revert start- and end-markers
185 attr = edge.attributes;
187 for (i=0;i<attr.length;i++) {
188 if (attr.item(i).nodeName == "marker-start") {
189 for (j=i;j<attr.length;j++) {
190 if (attr.item(j).nodeName == "marker-end") {
196 edge.removeAttribute("marker-start");
197 edge.setAttribute("marker-end","url(#arrowend)");
201 if (attr.item(i).nodeName == "marker-end") {
202 for (j=i;j<attr.length;j++) {
203 if (attr.item(j).nodeName == "marker-start") {
209 edge.removeAttribute("marker-end");
210 edge.setAttribute("marker-start","url(#arrowstart)");
216 //revert cardinalities
217 textpaths = svgdoc.getElementsByTagName("textPath");
218 for (i=0;i<textpaths.length;i++) {
219 pathname = textpaths.item(i).getAttribute("xlink:href").replace(/#/,"");
220 if (pathname == edge.getAttribute("id")) {
221 offset = textpaths.item(i).getAttribute("startOffset").substr(0,2);
222 textpaths.item(i).setAttribute("startOffset",100 - offset + "%")
227 function getSVGDoc(load_evt)
229 svgdoc=load_evt.target.ownerDocument;
230 svgroot=svgdoc.documentElement;
231 texte=svgdoc.getElementById("tooltip").getElementsByTagName("text");
232 for (i=1; i<%i; i++) {
233 textNode=texte.item(1).cloneNode("true");
234 svgdoc.getElementById("tooltip").appendChild(textNode);
236 texte=svgdoc.getElementById("tooltip").getElementsByTagName("text");
239 function ShowTooltipMZ(mousemove_event,txt)
241 var ttrelem,tttelem,ttline,posx,posy,curtrans,ctx,cty,txt;
243 ttrelem=svgdoc.getElementById("ttr");
244 tttelem=svgdoc.getElementById("ttt");
245 ttline=svgdoc.getElementById("ttl");
246 posx=mousemove_event.clientX;
247 posy=mousemove_event.clientY;
249 texte.item(i).firstChild.data="";
250 tttelem.childNodes.item(0).data="";
253 for (i=0;i<tmp.length;i++) {
256 tttelem.childNodes.item(0).data=tmp[i];
257 if (maxbreite<tttelem.getComputedTextLength())
258 maxbreite=tttelem.getComputedTextLength();
260 curtrans=svgroot.currentTranslate;
263 ttrelem.setAttribute("x",posx-ctx+10);
264 ttrelem.setAttribute("y",posy-cty-20+10);
265 ttrelem.setAttribute("width",maxbreite*0.92+10);
266 ttrelem.setAttribute("height",tmp.length*15+3);
267 ttrelem.setAttribute("style",
268 "fill: #FFC; stroke: #000; stroke-width: 0.5px");
269 for (i=1; i<=tmp.length; i++) {
270 if (tmp[i-1]=="-- -- --") {
271 ttline.setAttribute("x1", posx-ctx+10);
272 ttline.setAttribute("y1", parseInt(i-1)*15+posy-cty);
273 ttline.setAttribute("x2", posx-ctx+10+maxbreite*0.92+10);
274 ttline.setAttribute("y2", parseInt(i-1)*15+posy-cty);
275 ttline.setAttribute("style", "stroke: #000; stroke-width: 0.5px");
277 texte.item(i).firstChild.data=tmp[i-1];
278 texte.item(i).setAttribute("x",posx-ctx+15);
279 texte.item(i).setAttribute("y",parseInt(i-1)*15+posy-cty+3);
280 texte.item(i).setAttribute("style","fill: #00E; font-size: 11px");
283 svgdoc.getElementById("tooltip").style.setProperty("visibility","visible");
286 function HideTooltip()
288 svgdoc.getElementById("ttl").style.setProperty("visibility","hidden");
289 svgdoc.getElementById("tooltip").style.setProperty("visibility","hidden");
292 function ZoomControl()
295 curzoom=svgroot.currentScale;
296 svgdoc.getElementById("tooltip").setAttribute("transform",
297 "scale("+1/curzoom+")");
301 function collapse(evt)
303 var i, k, l, m, svgdoc, obj, targetID, targetX, targetY, attr;
304 obj = evt.getTarget();
305 svgdoc = obj.ownerDocument;
306 //extract coordinates and id of the clicked text
307 attr = obj.parentNode.parentNode.attributes;
308 for (i=0;i<attr.length;i++) {
309 if (attr.item(i).nodeName == "transform") {
310 k = attr.item(i).nodeValue.indexOf("(");
311 l = attr.item(i).nodeValue.indexOf(",");
312 m = attr.item(i).nodeValue.indexOf(")");
313 targetX = attr.item(i).nodeValue.substring(k+1,l);
314 targetY = attr.item(i).nodeValue.substring(l+1,m);
316 if (attr.item(i).nodeName == "id") {
317 targetID = attr.item(i).nodeValue.substr(2);
320 //decide if we are collapsing or uncollapsing
321 if (collapsed[0][targetID] == 0) {
322 hideInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr);
323 collapsed[0][targetID] = 1;
325 showHiddenInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr);
326 collapsed[0][targetID] = 0;
330 function showHiddenInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr)
332 var i, k, l, m, nextObj, nextX, nextY, gapY=0, clickedID;
333 //change clicked text
334 obj.firstChild.data="--";
336 nextObj = svgdoc.getElementById("MI"+targetID);
339 //show child texts again
341 attr = nextObj.attributes;
342 for (i=0;i<attr.length;i++) {
343 if (attr.item(i).nodeName == "transform") {
344 k = attr.item(i).nodeValue.indexOf("(");
345 l = attr.item(i).nodeValue.indexOf(",");
346 m = attr.item(i).nodeValue.indexOf(")");
347 nextX = attr.item(i).nodeValue.substring(k+1,l);
348 nextY = attr.item(i).nodeValue.substring(l+1,m);
351 if (nextX > targetX) {
352 nextObj.style.setProperty("visibility","visible");
354 if (collapsed[0][targetID] == 1) {
355 targetID = collapsed[1][targetID];
359 nextObj = svgdoc.getElementById("MI"+targetID);
368 //move following texts downwards
369 while (nextObj != null) {
370 attr = nextObj.attributes;
371 for (i=0;i<attr.length;i++) {
372 if (attr.item(i).nodeName == "transform") {
373 k = attr.item(i).nodeValue.indexOf("(");
374 l = attr.item(i).nodeValue.indexOf(",");
375 m = attr.item(i).nodeValue.indexOf(")");
376 nextX = attr.item(i).nodeValue.substring(k+1,l);
377 nextY = attr.item(i).nodeValue.substring(l+1,m);
380 nextY = nextY - 1 + gapY + 1;
381 nextObj.setAttribute("transform","translate("+nextX+","+nextY+")");
383 nextObj = svgdoc.getElementById("MI"+targetID);
387 function hideInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr)
389 var i, k, l, m, nextObj, nextX, nextY, gapY=0;
390 clickedID = targetID;
391 //change clicked text
392 obj.firstChild.data="+";
394 nextObj = svgdoc.getElementById("MI"+targetID);
397 //wipe out child texts
399 attr = nextObj.attributes;
400 for (i=0;i<attr.length;i++) {
401 if (attr.item(i).nodeName == "transform") {
402 k = attr.item(i).nodeValue.indexOf("(");
403 l = attr.item(i).nodeValue.indexOf(",");
404 m = attr.item(i).nodeValue.indexOf(")");
405 nextX = attr.item(i).nodeValue.substring(k+1,l);
406 nextY = attr.item(i).nodeValue.substring(l+1,m);
409 if (nextX > targetX) {
410 nextObj.style.setProperty("visibility","hidden");
412 if (collapsed[0][targetID] == 1) {
413 targetID = collapsed[1][targetID];
417 nextObj = svgdoc.getElementById("MI"+targetID);
424 //save next uncollapsed element in array
425 collapsed[1][clickedID] = targetID;
428 //move following texts upwards
429 while (nextObj != null) {
430 attr = nextObj.attributes;
431 for (i=0;i<attr.length;i++) {
432 if (attr.item(i).nodeName == "transform") {
433 k = attr.item(i).nodeValue.indexOf("(");
434 l = attr.item(i).nodeValue.indexOf(",");
435 m = attr.item(i).nodeValue.indexOf(")");
436 nextX = attr.item(i).nodeValue.substring(k+1,l);
437 nextY = attr.item(i).nodeValue.substring(l+1,m);
441 nextObj.setAttribute("transform","translate("+nextX+","+nextY+")");
443 nextObj = svgdoc.getElementById("MI"+targetID);
449 var nodenames, startnode, endnode, attr, i, j, k, l, m, nodesx, nodeex;
450 collapsed[0] = new Array(%i);
451 collapsed[1] = new Array(%i);
452 for (i=0; i<%i; i++) {
456 for (i=0; i<%i; i++) {
464 //check which edges are printed from right to left
465 paths = svgdoc.getElementsByTagName("path");
466 revert = new Array(paths.length);
467 for (j=0; j<paths.length; j++) {
468 nodenames = paths.item(j).getAttribute("id").split("-");
469 startnode = svgdoc.getElementById(nodenames[0]);
470 attr = startnode.parentNode.attributes;
471 for (i=0;i<attr.length;i++) {
472 if (attr.item(i).nodeName == "transform") {
473 k = attr.item(i).nodeValue.indexOf("(");
474 l = attr.item(i).nodeValue.indexOf(",");
475 m = attr.item(i).nodeValue.indexOf(")");
476 nodesx = parseFloat(attr.item(i).nodeValue.substring(k+1,l));
479 endnode = svgdoc.getElementById(nodenames[1]);
480 attr = endnode.parentNode.attributes;
481 for (i=0;i<attr.length;i++) {
482 if (attr.item(i).nodeName == "transform") {
483 k = attr.item(i).nodeValue.indexOf("(");
484 l = attr.item(i).nodeValue.indexOf(",");
485 m = attr.item(i).nodeValue.indexOf(")");
486 nodeex = parseFloat(attr.item(i).nodeValue.substring(k+1,l));
489 if (nodesx > nodeex) {
497 function setStatus(evt, color1, color2)
499 var clickObj = evt.getTarget();
500 var clickObjName = clickObj.getAttribute('id');
502 //find i corresponding to the clicked object
503 for (i=0; i<%i; i++) {
505 name[i] = clickObjName;
508 if (name[i] != clickObjName)
513 //toggle click status, color clicked object
514 if (clickStatus[i] == 0) {
516 clickObj.setAttribute("style","fill: "+color1);
519 clickObj.setAttribute("style","fill: "+color2);
522 //adjust color-counter
523 if (color1 == 'red') {
524 if (clickStatus[i] == 1) {
530 if (color1 == 'salmon') {
531 if (clickStatus[i] == 1) {
538 if (clickStatus[i] == 0 && salmonCount[i] > 0) {
539 clickObj.setAttribute("style","fill: salmon");
543 function changeColor(evt, targetObjName, color1, color2)
545 var clickObj = evt.getTarget();
546 var clickObjName = clickObj.getAttribute('id');
547 var targetObj = svgDocument.getElementById(targetObjName);
549 //find i corresponding to the clicked object
550 for (i=0; i<%i; i++) {
551 if (name[i] != clickObjName)
556 //find j corresponding to the target object
557 for (j=0; j<%i; j++) {
559 name[j] = targetObjName;
562 if (name[j] != targetObjName)
567 //adjust color-counter
568 if (color1 == 'red') {
569 if (clickStatus[i] == 1) {
575 if (color1 == 'salmon') {
576 if (clickStatus[i] == 1) {
584 function colorText(targetObjName, color)
586 var targetObj = svgDocument.getElementById(targetObjName);
588 //find i corresponding to the target object
589 for (i=0; i<%i; i++) {
590 if (name[i] != targetObjName)
597 targetObj.setAttribute("style","fill: "+color);
600 if (redCount[i] == 0 && salmonCount[i] == 0) {
601 targetObj.setAttribute("style","fill: "+color);
603 if (salmonCount[i] > 0) {
604 if (color == 'red') {
605 targetObj.setAttribute("style","fill: red");
607 if (redCount[i] > 0) {
608 targetObj.setAttribute("style","fill: red");
610 targetObj.setAttribute("style","fill: salmon");