Imported Upstream version 0.4.8
[platform/upstream/libsmi.git] / tools / dump-svg-script.h
1 const char *code =
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"
12 "\n"
13 "function MoveObj(evt)\n"
14 "{\n"
15 "    if (active) {\n"
16 "       var roundx, roundy;\n"
17 "       var curtrans=svgroot.currentTranslate;\n"
18 "       var ctx=curtrans.x;\n"
19 "       var cty=curtrans.y;\n"
20 "\n"
21 "       x=evt.clientX()\n"
22 "       y=evt.clientY()\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"
27 "\n"
28 "       moveObj.setAttribute(\"transform\",\"translate(\"+roundx+\",\"+roundy+\")\");\n"
29 "    }\n"
30 "}\n"
31 "\n"
32 "function ClickObj(evt)\n"
33 "{\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"
38 "    active=true;\n"
39 "}\n"
40 "\n"
41 "function OutOfObj(evt)\n"
42 "{\n"
43 "    if (active) {\n"
44 "       active=false;\n"
45 "       findAdjacentEdges();\n"
46 "    }\n"
47 "}\n"
48 "\n"
49 "function findAdjacentEdges()\n"
50 "{\n"
51 "    var rectl, rectlid, i, nodenames;\n"
52 "    rectl = rect;\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"
58 "       }\n"
59 "    }\n"
60 "}\n"
61 "\n"
62 "function repaintEdge(edge, nodenames, j)\n"
63 "{\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"
67 "\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"
80 "       }\n"
81 "    }\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"
93 "       }\n"
94 "    }\n"
95 "\n"
96 "    alpha = Math.atan((nodesy-nodeey)/(nodesx-nodeex));\n"
97 "    if (alpha < 0)\n"
98 "       alpha += Math.PI;\n"
99 "\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"
108 "       } else {\n"
109 "           edgesx = nodesx - nodesw/2;\n"
110 "       }\n"
111 "       if (nodesy < nodeey) {\n"
112 "           edgesy = nodesy - 0 + Math.abs(nodesw*Math.tan(alpha)/2);\n"
113 "       } else {\n"
114 "           edgesy = nodesy - Math.abs(nodesw*Math.tan(alpha)/2);\n"
115 "       }\n"
116 "    } else {\n"
117 "       //intersection at top or bottom border\n"
118 "       if (nodesy < nodeey) {\n"
119 "           edgesy = nodesy - 0 + nodesh/2;\n"
120 "       } else {\n"
121 "           edgesy = nodesy - nodesh/2;\n"
122 "       }\n"
123 "       if (nodesx < nodeex) {\n"
124 "           edgesx = nodesx - 0 + Math.abs(nodesh/(2*Math.tan(alpha)));\n"
125 "       } else {\n"
126 "           edgesx = nodesx - Math.abs(nodesh/(2*Math.tan(alpha)));\n"
127 "       }\n"
128 "    }\n"
129 "\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"
138 "       } else {\n"
139 "           edgeex = nodeex - nodeew/2;\n"
140 "       }\n"
141 "       if (nodesy > nodeey) {\n"
142 "           edgeey = nodeey - 0 + Math.abs(nodeew*Math.tan(alpha)/2);\n"
143 "       } else {\n"
144 "           edgeey = nodeey - Math.abs(nodeew*Math.tan(alpha)/2);\n"
145 "       }\n"
146 "    } else {\n"
147 "       //intersection at top or bottom border\n"
148 "       if (nodesy > nodeey) {\n"
149 "           edgeey = nodeey - 0 + nodeeh/2;\n"
150 "       } else {\n"
151 "           edgeey = nodeey - nodeeh/2;\n"
152 "       }\n"
153 "       if (nodesx > nodeex) {\n"
154 "           edgeex = nodeex - 0 + Math.abs(nodeeh/(2*Math.tan(alpha)));\n"
155 "       } else {\n"
156 "           edgeex = nodeex - Math.abs(nodeeh/(2*Math.tan(alpha)));\n"
157 "       }\n"
158 "    }\n"
159 "\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"
165 "\n"
166 "    if (sx < ex) {\n"
167 "       if (revert[j] == 1) {\n"
168 "           revert[j] = 0;\n"
169 "           flipEdgeMarks(edge);\n"
170 "       }\n"
171 "       edge.setAttribute(\"d\",\"M \"+sx+\" \"+sy+\" \"+ex+\" \"+ey);\n"
172 "    } else {\n"
173 "       if (revert[j] == 0) {\n"
174 "           revert[j] = 1;\n"
175 "           flipEdgeMarks(edge);\n"
176 "       }\n"
177 "       edge.setAttribute(\"d\",\"M \"+ex+\" \"+ey+\" \"+sx+\" \"+sy);\n"
178 "    }\n"
179 "}\n"
180 "\n"
181 "function flipEdgeMarks(edge)\n"
182 "{\n"
183 "    var attr, i, j, done, textpaths, pathnamei, offset;\n"
184 "\n"
185 "    //revert start- and end-markers\n"
186 "    attr = edge.attributes;\n"
187 "    done = 0;\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"
192 "                   done = 1;\n"
193 "               }\n"
194 "           }\n"
195 "           if (done == 0) {\n"
196 "               //start->end\n"
197 "               edge.removeAttribute(\"marker-start\");\n"
198 "               edge.setAttribute(\"marker-end\",\"url(#arrowend)\");\n"
199 "               break;\n"
200 "           }\n"
201 "       }\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"
205 "                   done = 1;\n"
206 "               }\n"
207 "           }\n"
208 "           if (done == 0) {\n"
209 "               //end->start\n"
210 "               edge.removeAttribute(\"marker-end\");\n"
211 "               edge.setAttribute(\"marker-start\",\"url(#arrowstart)\");\n"
212 "               break;\n"
213 "           }\n"
214 "       }\n"
215 "    }\n"
216 "\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"
224 "       }\n"
225 "    }\n"
226 "}\n"
227 "\n"
228 "function getSVGDoc(load_evt)\n"
229 "{\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"
236 "    }\n"
237 "    texte=svgdoc.getElementById(\"tooltip\").getElementsByTagName(\"text\");\n"
238 "}\n"
239 "\n"
240 "function ShowTooltipMZ(mousemove_event,txt)\n"
241 "{\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"
253 "    maxbreite=0;\n"
254 "    for (i=0;i<tmp.length;i++) {\n"
255 "       if (tmp[i]==\"\")\n"
256 "           continue;\n"
257 "       tttelem.childNodes.item(0).data=tmp[i];\n"
258 "       if (maxbreite<tttelem.getComputedTextLength())\n"
259 "           maxbreite=tttelem.getComputedTextLength();\n"
260 "    }\n"
261 "    curtrans=svgroot.currentTranslate;\n"
262 "    ctx=curtrans.x;\n"
263 "    cty=curtrans.y;\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"
277 "       } else {\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"
282 "       }\n"
283 "    }\n"
284 "    svgdoc.getElementById(\"tooltip\").style.setProperty(\"visibility\",\"visible\");\n"
285 "}\n"
286 "\n"
287 "function HideTooltip()\n"
288 "{\n"
289 "    svgdoc.getElementById(\"ttl\").style.setProperty(\"visibility\",\"hidden\");\n"
290 "    svgdoc.getElementById(\"tooltip\").style.setProperty(\"visibility\",\"hidden\");\n"
291 "}\n"
292 "\n"
293 "function ZoomControl()\n"
294 "{\n"
295 "    var curzoom;\n"
296 "    curzoom=svgroot.currentScale;\n"
297 "    svgdoc.getElementById(\"tooltip\").setAttribute(\"transform\",\n"
298 "                                                       \"scale(\"+1/curzoom+\")\");\n"
299 "    zoom=1/curzoom;\n"
300 "}\n"
301 "\n"
302 "function collapse(evt)\n"
303 "{\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"
316 "        }\n"
317 "        if (attr.item(i).nodeName == \"id\") {\n"
318 "            targetID = attr.item(i).nodeValue.substr(2);\n"
319 "        }\n"
320 "    }\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"
325 "    } else {\n"
326 "        showHiddenInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr);\n"
327 "        collapsed[0][targetID] = 0;\n"
328 "    }\n"
329 "}\n"
330 "\n"
331 "function showHiddenInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr)\n"
332 "{\n"
333 "    var i, k, l, m, nextObj, nextX, nextY, gapY=0, clickedID;\n"
334 "    //change clicked text\n"
335 "    obj.firstChild.data=\"--\";\n"
336 "    targetID++;\n"
337 "    nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
338 "    if (nextObj == null)\n"
339 "        return;\n"
340 "    //show child texts again\n"
341 "    for (;;) {\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"
350 "            }\n"
351 "        }\n"
352 "        if (nextX > targetX) {\n"
353 "            nextObj.style.setProperty(\"visibility\",\"visible\");\n"
354 "            gapY += 15;\n"
355 "            if (collapsed[0][targetID] == 1) {\n"
356 "                targetID = collapsed[1][targetID];\n"
357 "            } else {\n"
358 "                targetID++;\n"
359 "            }\n"
360 "            nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
361 "            if (nextObj == null)\n"
362 "                break;\n"
363 "        } else {\n"
364 "            break;\n"
365 "        }\n"
366 "    }\n"
367 "    if (nextObj == null)\n"
368 "        return;\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"
379 "            }\n"
380 "        }\n"
381 "        nextY = nextY - 1 + gapY + 1;\n"
382 "        nextObj.setAttribute(\"transform\",\"translate(\"+nextX+\",\"+nextY+\")\");\n"
383 "        targetID++;\n"
384 "        nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
385 "    }\n"
386 "}\n"
387 "\n"
388 "function hideInfos(evt, obj, svgdoc, targetX, targetY, targetID, attr)\n"
389 "{\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"
394 "    targetID++;\n"
395 "    nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
396 "    if (nextObj == null)\n"
397 "        return;\n"
398 "    //wipe out child texts\n"
399 "    for (;;) {\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"
408 "            }\n"
409 "        }\n"
410 "        if (nextX > targetX) {\n"
411 "            nextObj.style.setProperty(\"visibility\",\"hidden\");\n"
412 "            gapY += 15;\n"
413 "            if (collapsed[0][targetID] == 1) {\n"
414 "                targetID = collapsed[1][targetID];\n"
415 "            } else {\n"
416 "                targetID++;\n"
417 "            }\n"
418 "            nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
419 "            if (nextObj == null)\n"
420 "                break;\n"
421 "        } else {\n"
422 "            break;\n"
423 "        }\n"
424 "    }\n"
425 "    //save next uncollapsed element in array\n"
426 "    collapsed[1][clickedID] = targetID;\n"
427 "    if (nextObj == null)\n"
428 "        return;\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"
439 "            }\n"
440 "        }\n"
441 "        nextY -= gapY;\n"
442 "        nextObj.setAttribute(\"transform\",\"translate(\"+nextX+\",\"+nextY+\")\");\n"
443 "        targetID++;\n"
444 "        nextObj = svgdoc.getElementById(\"MI\"+targetID);\n"
445 "    }\n"
446 "}\n"
447 "\n"
448 "function init(evt)\n"
449 "{\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"
456 "    }\n"
457 "    for (i=0; i<%i; i++) {\n"
458 "       name[i] = \"\";\n"
459 "       clickStatus[i] = 0;\n"
460 "       redCount[i] = 0;\n"
461 "       salmonCount[i] = 0;\n"
462 "    }\n"
463 "    getSVGDoc(evt);\n"
464 "\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"
478 "           }\n"
479 "       }\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"
488 "           }\n"
489 "       }\n"
490 "       if (nodesx > nodeex) {\n"
491 "           revert[j] = 1;\n"
492 "       } else {\n"
493 "           revert[j] = 0;\n"
494 "       }\n"
495 "    }\n"
496 "}\n"
497 "\n"
498 "function setStatus(evt, color1, color2)\n"
499 "{\n"
500 "    var clickObj = evt.getTarget();\n"
501 "    var clickObjName = clickObj.getAttribute('id');\n"
502 "\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"
507 "           break;\n"
508 "       }\n"
509 "       if (name[i] != clickObjName)\n"
510 "           continue;\n"
511 "       break;\n"
512 "    }\n"
513 "\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"
518 "    } else {\n"
519 "       clickStatus[i] = 0;\n"
520 "       clickObj.setAttribute(\"style\",\"fill: \"+color2);\n"
521 "    }\n"
522 "\n"
523 "    //adjust color-counter\n"
524 "    if (color1 == 'red') {\n"
525 "       if (clickStatus[i] == 1) {\n"
526 "           redCount[i]++;\n"
527 "       } else {\n"
528 "           redCount[i]--;\n"
529 "       }\n"
530 "    }\n"
531 "    if (color1 == 'salmon') {\n"
532 "       if (clickStatus[i] == 1) {\n"
533 "           salmonCount[i]++;\n"
534 "       } else {\n"
535 "           salmonCount[i]--;\n"
536 "       }\n"
537 "    }\n"
538 "\n"
539 "    if (clickStatus[i] == 0 && salmonCount[i] > 0) {\n"
540 "       clickObj.setAttribute(\"style\",\"fill: salmon\");\n"
541 "    }\n"
542 "}\n"
543 "\n"
544 "function changeColor(evt, targetObjName, color1, color2)\n"
545 "{\n"
546 "    var clickObj = evt.getTarget();\n"
547 "    var clickObjName = clickObj.getAttribute('id');\n"
548 "    var targetObj = svgDocument.getElementById(targetObjName);\n"
549 "\n"
550 "    //find i corresponding to the clicked object\n"
551 "    for (i=0; i<%i; i++) {\n"
552 "       if (name[i] != clickObjName)\n"
553 "           continue;\n"
554 "       break;\n"
555 "    }\n"
556 "\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"
561 "           break;\n"
562 "       }\n"
563 "       if (name[j] != targetObjName)\n"
564 "           continue;\n"
565 "       break;\n"
566 "    }\n"
567 "\n"
568 "    //adjust color-counter\n"
569 "    if (color1 == 'red') {\n"
570 "       if (clickStatus[i] == 1) {\n"
571 "           redCount[j]++;\n"
572 "       } else {\n"
573 "           redCount[j]--;\n"
574 "       }\n"
575 "    }\n"
576 "    if (color1 == 'salmon') {\n"
577 "       if (clickStatus[i] == 1) {\n"
578 "           salmonCount[j]++;\n"
579 "       } else {\n"
580 "           salmonCount[j]--;\n"
581 "       }\n"
582 "    }\n"
583 "}\n"
584 "\n"
585 "function colorText(targetObjName, color)\n"
586 "{\n"
587 "    var targetObj = svgDocument.getElementById(targetObjName);\n"
588 "\n"
589 "    //find i corresponding to the target object\n"
590 "    for (i=0; i<%i; i++) {\n"
591 "       if (name[i] != targetObjName)\n"
592 "           continue;\n"
593 "       break;\n"
594 "    }\n"
595 "\n"
596 "    //color text\n"
597 "    if (i == %i) {\n"
598 "       targetObj.setAttribute(\"style\",\"fill: \"+color);\n"
599 "       return;\n"
600 "    }\n"
601 "    if (redCount[i] == 0 && salmonCount[i] == 0) {\n"
602 "       targetObj.setAttribute(\"style\",\"fill: \"+color);\n"
603 "    }\n"
604 "    if (salmonCount[i] > 0) {\n"
605 "       if (color == 'red') {\n"
606 "           targetObj.setAttribute(\"style\",\"fill: red\");\n"
607 "       } else {\n"
608 "           if (redCount[i] > 0) {\n"
609 "               targetObj.setAttribute(\"style\",\"fill: red\");\n"
610 "           } else {\n"
611 "               targetObj.setAttribute(\"style\",\"fill: salmon\");\n"
612 "           }\n"
613 "       }\n"
614 "    }\n"
615 "}\n"
616 ;