const char *code = "//The scripts for the tooltip and moveobj are based on work from\n" "//SVG - Learning By Coding - http://www.datenverdrahten.de/svglbc/\n" "//Author: Dr. Thomas Meinike 11/03 - thomas@handmadecode.de\n" "var svgdoc,svgroot,paths,revert;\n" "var collapsed = new Array(2);\n" "var name = new Array(%i);\n" "var clickStatus = new Array(%i);\n" "var redCount = new Array(%i);\n" "var salmonCount = new Array(%i);\n" "var moveObj,rect,x,y,attr1,attr2,wert1,wert2,zoom=1,active=false;\n" "\n" "function MoveObj(evt)\n" "{\n" " if (active) {\n" " var roundx, roundy;\n" " var curtrans=svgroot.currentTranslate;\n" " var ctx=curtrans.x;\n" " var cty=curtrans.y;\n" "\n" " x=evt.clientX()\n" " y=evt.clientY()\n" " wert1=(x-ctx)*zoom*%.2f+%.2f+attr1-5;\n" " wert2=(y-cty)*zoom*%.2f+%.2f+attr2-5;\n" " roundx=Math.round(wert1*100)/100;\n" " roundy=Math.round(wert2*100)/100;\n" "\n" " moveObj.setAttribute(\"transform\",\"translate(\"+roundx+\",\"+roundy+\")\");\n" " }\n" "}\n" "\n" "function ClickObj(evt)\n" "{\n" " rect=evt.target.parentNode.getElementsByTagName(\"rect\").item(0);\n" " moveObj=evt.target.parentNode;\n" " attr1=rect.getAttribute(\"width\")/2;\n" " attr2=rect.getAttribute(\"height\")/2;\n" " active=true;\n" "}\n" "\n" "function OutOfObj(evt)\n" "{\n" " if (active) {\n" " active=false;\n" " findAdjacentEdges();\n" " }\n" "}\n" "\n" "function findAdjacentEdges()\n" "{\n" " var rectl, rectlid, i, nodenames;\n" " rectl = rect;\n" " rectlid = rectl.getAttribute(\"id\");\n" " for (i=0; i Math.PI-beta && alpha < Math.PI+beta)\n" " || alpha > 2*Math.PI-beta) {\n" " //intersection at left or right border\n" " if (nodesx < nodeex) {\n" " edgesx = nodesx - 0 + nodesw/2;\n" " } else {\n" " edgesx = nodesx - nodesw/2;\n" " }\n" " if (nodesy < nodeey) {\n" " edgesy = nodesy - 0 + Math.abs(nodesw*Math.tan(alpha)/2);\n" " } else {\n" " edgesy = nodesy - Math.abs(nodesw*Math.tan(alpha)/2);\n" " }\n" " } else {\n" " //intersection at top or bottom border\n" " if (nodesy < nodeey) {\n" " edgesy = nodesy - 0 + nodesh/2;\n" " } else {\n" " edgesy = nodesy - nodesh/2;\n" " }\n" " if (nodesx < nodeex) {\n" " edgesx = nodesx - 0 + Math.abs(nodesh/(2*Math.tan(alpha)));\n" " } else {\n" " edgesx = nodesx - Math.abs(nodesh/(2*Math.tan(alpha)));\n" " }\n" " }\n" "\n" " //calculate intersection of edge and endNode\n" " beta = Math.atan(nodeeh/nodeew);\n" " if (alpha < beta\n" " || (alpha > Math.PI-beta && alpha < Math.PI+beta)\n" " || alpha > 2*Math.PI-beta) {\n" " //intersection at left or right border\n" " if (nodesx > nodeex) {\n" " edgeex = nodeex - 0 + nodeew/2;\n" " } else {\n" " edgeex = nodeex - nodeew/2;\n" " }\n" " if (nodesy > nodeey) {\n" " edgeey = nodeey - 0 + Math.abs(nodeew*Math.tan(alpha)/2);\n" " } else {\n" " edgeey = nodeey - Math.abs(nodeew*Math.tan(alpha)/2);\n" " }\n" " } else {\n" " //intersection at top or bottom border\n" " if (nodesy > nodeey) {\n" " edgeey = nodeey - 0 + nodeeh/2;\n" " } else {\n" " edgeey = nodeey - nodeeh/2;\n" " }\n" " if (nodesx > nodeex) {\n" " edgeex = nodeex - 0 + Math.abs(nodeeh/(2*Math.tan(alpha)));\n" " } else {\n" " edgeex = nodeex - Math.abs(nodeeh/(2*Math.tan(alpha)));\n" " }\n" " }\n" "\n" " //set new edge coordinates\n" " sx=Math.round(edgesx*100)/100;\n" " ex=Math.round(edgeex*100)/100;\n" " sy=Math.round(edgesy*100)/100;\n" " ey=Math.round(edgeey*100)/100;\n" "\n" " if (sx < ex) {\n" " if (revert[j] == 1) {\n" " revert[j] = 0;\n" " flipEdgeMarks(edge);\n" " }\n" " edge.setAttribute(\"d\",\"M \"+sx+\" \"+sy+\" \"+ex+\" \"+ey);\n" " } else {\n" " if (revert[j] == 0) {\n" " revert[j] = 1;\n" " flipEdgeMarks(edge);\n" " }\n" " edge.setAttribute(\"d\",\"M \"+ex+\" \"+ey+\" \"+sx+\" \"+sy);\n" " }\n" "}\n" "\n" "function flipEdgeMarks(edge)\n" "{\n" " var attr, i, j, done, textpaths, pathnamei, offset;\n" "\n" " //revert start- and end-markers\n" " attr = edge.attributes;\n" " done = 0;\n" " for (i=0;iend\n" " edge.removeAttribute(\"marker-start\");\n" " edge.setAttribute(\"marker-end\",\"url(#arrowend)\");\n" " break;\n" " }\n" " }\n" " if (attr.item(i).nodeName == \"marker-end\") {\n" " for (j=i;jstart\n" " edge.removeAttribute(\"marker-end\");\n" " edge.setAttribute(\"marker-start\",\"url(#arrowstart)\");\n" " break;\n" " }\n" " }\n" " }\n" "\n" " //revert cardinalities\n" " textpaths = svgdoc.getElementsByTagName(\"textPath\");\n" " for (i=0;i targetX) {\n" " nextObj.style.setProperty(\"visibility\",\"visible\");\n" " gapY += 15;\n" " if (collapsed[0][targetID] == 1) {\n" " targetID = collapsed[1][targetID];\n" " } else {\n" " targetID++;\n" " }\n" " nextObj = svgdoc.getElementById(\"MI\"+targetID);\n" " if (nextObj == null)\n" " break;\n" " } else {\n" " break;\n" " }\n" " }\n" " if (nextObj == null)\n" " return;\n" " //move following texts downwards\n" " while (nextObj != null) {\n" " attr = nextObj.attributes;\n" " for (i=0;i targetX) {\n" " nextObj.style.setProperty(\"visibility\",\"hidden\");\n" " gapY += 15;\n" " if (collapsed[0][targetID] == 1) {\n" " targetID = collapsed[1][targetID];\n" " } else {\n" " targetID++;\n" " }\n" " nextObj = svgdoc.getElementById(\"MI\"+targetID);\n" " if (nextObj == null)\n" " break;\n" " } else {\n" " break;\n" " }\n" " }\n" " //save next uncollapsed element in array\n" " collapsed[1][clickedID] = targetID;\n" " if (nextObj == null)\n" " return;\n" " //move following texts upwards\n" " while (nextObj != null) {\n" " attr = nextObj.attributes;\n" " for (i=0;i nodeex) {\n" " revert[j] = 1;\n" " } else {\n" " revert[j] = 0;\n" " }\n" " }\n" "}\n" "\n" "function setStatus(evt, color1, color2)\n" "{\n" " var clickObj = evt.getTarget();\n" " var clickObjName = clickObj.getAttribute('id');\n" "\n" " //find i corresponding to the clicked object\n" " for (i=0; i<%i; i++) {\n" " if (name[i] == \"\") {\n" " name[i] = clickObjName;\n" " break;\n" " }\n" " if (name[i] != clickObjName)\n" " continue;\n" " break;\n" " }\n" "\n" " //toggle click status, color clicked object\n" " if (clickStatus[i] == 0) {\n" " clickStatus[i] = 1;\n" " clickObj.setAttribute(\"style\",\"fill: \"+color1);\n" " } else {\n" " clickStatus[i] = 0;\n" " clickObj.setAttribute(\"style\",\"fill: \"+color2);\n" " }\n" "\n" " //adjust color-counter\n" " if (color1 == 'red') {\n" " if (clickStatus[i] == 1) {\n" " redCount[i]++;\n" " } else {\n" " redCount[i]--;\n" " }\n" " }\n" " if (color1 == 'salmon') {\n" " if (clickStatus[i] == 1) {\n" " salmonCount[i]++;\n" " } else {\n" " salmonCount[i]--;\n" " }\n" " }\n" "\n" " if (clickStatus[i] == 0 && salmonCount[i] > 0) {\n" " clickObj.setAttribute(\"style\",\"fill: salmon\");\n" " }\n" "}\n" "\n" "function changeColor(evt, targetObjName, color1, color2)\n" "{\n" " var clickObj = evt.getTarget();\n" " var clickObjName = clickObj.getAttribute('id');\n" " var targetObj = svgDocument.getElementById(targetObjName);\n" "\n" " //find i corresponding to the clicked object\n" " for (i=0; i<%i; i++) {\n" " if (name[i] != clickObjName)\n" " continue;\n" " break;\n" " }\n" "\n" " //find j corresponding to the target object\n" " for (j=0; j<%i; j++) {\n" " if (name[j] == \"\") {\n" " name[j] = targetObjName;\n" " break;\n" " }\n" " if (name[j] != targetObjName)\n" " continue;\n" " break;\n" " }\n" "\n" " //adjust color-counter\n" " if (color1 == 'red') {\n" " if (clickStatus[i] == 1) {\n" " redCount[j]++;\n" " } else {\n" " redCount[j]--;\n" " }\n" " }\n" " if (color1 == 'salmon') {\n" " if (clickStatus[i] == 1) {\n" " salmonCount[j]++;\n" " } else {\n" " salmonCount[j]--;\n" " }\n" " }\n" "}\n" "\n" "function colorText(targetObjName, color)\n" "{\n" " var targetObj = svgDocument.getElementById(targetObjName);\n" "\n" " //find i corresponding to the target object\n" " for (i=0; i<%i; i++) {\n" " if (name[i] != targetObjName)\n" " continue;\n" " break;\n" " }\n" "\n" " //color text\n" " if (i == %i) {\n" " targetObj.setAttribute(\"style\",\"fill: \"+color);\n" " return;\n" " }\n" " if (redCount[i] == 0 && salmonCount[i] == 0) {\n" " targetObj.setAttribute(\"style\",\"fill: \"+color);\n" " }\n" " if (salmonCount[i] > 0) {\n" " if (color == 'red') {\n" " targetObj.setAttribute(\"style\",\"fill: red\");\n" " } else {\n" " if (redCount[i] > 0) {\n" " targetObj.setAttribute(\"style\",\"fill: red\");\n" " } else {\n" " targetObj.setAttribute(\"style\",\"fill: salmon\");\n" " }\n" " }\n" " }\n" "}\n" ;