1
0

olsr-viz.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. /*
  2. Copyright (c) 2006, Lorenz Schori <lo@znerol.ch>
  3. All rights reserved (Naja: Ich hab' trotzdem was geaendert. Sven-Ola). (Naja:
  4. diese Rechte garantiert dir die BSD-Lizenz ja ausdrücklich. Lorenz)
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. - Redistributions of source code must retain the above copyright notice, this
  8. list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. - Neither the name of the <ORGANIZATION> nor the names of its contributors may
  13. be used to endorse or promote products derived from this software without
  14. specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  19. FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. OLSR-Viz is inspired by Wi-viz: http://wiviz.natetrue.com
  26. Changes:
  27. 2007-10-04: Added hostname display option -- Stefan Katerkamp <stefan@katerkamp.de>.
  28. 2007-10-04: Optimized display by moving presentation css out of js -- lo
  29. 2010-12-11: Changed some paths to make it work with Kamikaze and Luci -- soma
  30. */
  31. var cgi_url = "/cgi-bin/vizdata.sh";
  32. var maxmetric = 3;
  33. var iconvariant = "-mini";
  34. var nodes = new Array();
  35. var ncount = 0;
  36. var newnodes = new Array();
  37. var edges = new Array();
  38. var iel = 220; // ideal edge length
  39. var optsize = 10; // boundingbox around nodes
  40. var vwidth = 0;
  41. var vheight = 0;
  42. var xoff = 0;
  43. var yoff = 0;
  44. var scale = 1.0;
  45. var idle_timeout = 15;
  46. var erase_timeout = 60;
  47. var dcl_timeout = 250;
  48. var dcllow_timeout = 500;
  49. var auto_declump = true;
  50. var showdesc = true;
  51. var auto_save = 1;
  52. var now_secs = 5;
  53. // dom elements
  54. var IFrameObj;
  55. var maindiv;
  56. var nodediv;
  57. var edgediv;
  58. /******* CALL TO SERVER ********/
  59. function callToServer(URL) {
  60. var IFrameDoc;
  61. if (IFrameObj.document) {
  62. // For IE5 + opera
  63. IFrameDoc = IFrameObj.document;
  64. }
  65. else if (IFrameObj.contentDocument) {
  66. // For NS6
  67. IFrameDoc = IFrameObj.contentDocument;
  68. }
  69. else if (IFrameObj.contentWindow) {
  70. // For IE5.5 and IE6
  71. IFrameDoc = IFrameObj.contentWindow.document;
  72. }
  73. else {
  74. // opera? hmmmm
  75. return true;
  76. }
  77. IFrameDoc.location.replace(URL);
  78. return false;
  79. }
  80. /******** EDGE CLASS ********/
  81. function edge(n1,n2){
  82. this.getHTML = function()
  83. {
  84. var nh = "";
  85. if(this.n1.metric > maxmetric || this.n2.metric > maxmetric) {
  86. return "";
  87. }
  88. x = this.n1.x*scale;
  89. y = this.n1.y*scale;
  90. dx = this.n2.x*scale - x;
  91. dy = this.n2.y*scale - y;
  92. x += xoff*scale + 75;
  93. y += yoff*scale + 15;
  94. imgtag = "<img src='/luci-static/resources/olsr-viz/dot_"
  95. if (this.etx > 0 && this.etx < 2) {
  96. imgtag += "good.gif'";
  97. }
  98. else if(this.etx > 2 && this.etx < 5) {
  99. imgtag += "ok.gif'";
  100. }
  101. else if(this.etx > 5 && this.etx < 10) {
  102. imgtag += "weak.gif'";
  103. }
  104. else {
  105. imgtag += "down.gif'";
  106. }
  107. imgtag += " alt='ETX: " + this.etx + "' title='ETX: " + this.etx + "' ";
  108. d = Math.sqrt(dx*dx+dy*dy);
  109. for (j = 0; j < d; j += 15) {
  110. nh += imgtag + "style='top:"
  111. + parseInt(y+dy * j / d) + "px; left:"
  112. + parseInt(x+dx * j / d) + "px; "
  113. + "width: 4px; height: 4px; position: absolute; z-index: 2' >";
  114. }
  115. nh += "<div style='top:"
  116. + parseInt(y+dy * 0.5 - 5) + "px; left:"
  117. + parseInt(x+dx * 0.5 - 24) + "px; "
  118. + "position: absolute; z-index: 3; width: 48px; text-align: center;' >"
  119. + "<span class='label etx' >" + this.etx + "</span></div>";
  120. return nh;
  121. }
  122. this.isIdle = function()
  123. {
  124. return (now_secs - this.lastseen > idle_timeout);
  125. }
  126. this.isDead = function()
  127. {
  128. return (now_secs - this.lastseen > erase_timeout);
  129. }
  130. this.cleanup = function()
  131. {
  132. if(this.n1 && this.n1.weight) {
  133. this.n1.weight--;
  134. }
  135. if(this.n2 && this.n2.weight) {
  136. this.n2.weight--;
  137. }
  138. if(this.n1 && this.n2) {
  139. delete this.n1.edges[n2.ip];
  140. delete this.n2.edges[n1.ip];
  141. }
  142. }
  143. this.n1 = n1;
  144. this.n2 = n2;
  145. // setup edges within node objects
  146. this.n1.weight++;
  147. this.n1.edges[n2.ip] = this;
  148. this.n2.weight++;
  149. this.n2.edges[n1.ip] = this;
  150. return this;
  151. }
  152. function getEdgeKey(ip1,ip2)
  153. {
  154. key = "";
  155. if(ip1 > ip2) {
  156. key = ip2 + "-" + ip1;
  157. }
  158. else {
  159. key = ip1 + "-" + ip2;
  160. }
  161. return key;
  162. }
  163. function touch_edge(n1,n2,etx)
  164. {
  165. var key = getEdgeKey(n1.ip,n2.ip);
  166. var e = edges[key];
  167. if(!e) {
  168. e = new edge(n1,n2);
  169. edges[key] = e;
  170. }
  171. e.etx = etx;
  172. e.lastseen = now_secs;
  173. return e;
  174. }
  175. /******** NODE CLASS ********/
  176. function node(ip) {
  177. this.getHTML = function()
  178. {
  179. var nh;
  180. if(this.metric > maxmetric) {
  181. return "";
  182. }
  183. var igw = 0;
  184. for(h in this.hna) {
  185. if(h == "0.0.0.0") {
  186. igw = 1;
  187. break;
  188. }
  189. }
  190. nh =
  191. "<div id='node_" + this.ip + "' onmousedown='dragstart(this)' style="
  192. + "'top: " + parseInt((this.y+yoff)*scale) + "px; "
  193. + "left: " + parseInt((this.x+xoff)*scale) + "px; "
  194. + "width: 150px; height: 1px; z-index: 4; "
  195. + "position: absolute; background-color: transparent;' >"
  196. + "<div><img src='/luci-static/resources/olsr-viz/node"+(igw ? "-hna" : "")+iconvariant + ".gif'"
  197. + " alt='node " + this.ip + "' style='border: none;'><br>"
  198. + "<a href='http://" + this.ip + "/'>"
  199. + "<span class='label ip'>" + this.ip + "</span></a>"
  200. + (showdesc && this.desc != "" ?
  201. "<br><span class='label desc'>" + this.desc + "</span>" : "")
  202. + "</div></div>";
  203. return nh;
  204. }
  205. this.isIdle = function()
  206. {
  207. return (now_secs - this.lastseen > idle_timeout);
  208. }
  209. this.isDead = function()
  210. {
  211. return (now_secs - this.lastseen > erase_timeout);
  212. }
  213. this.cleanup = function()
  214. {
  215. ncount--;
  216. }
  217. this.set_metric = function(metric) {
  218. this.metric = metric;
  219. return this;
  220. }
  221. this.set_desc = function(desc) {
  222. this.desc = desc
  223. return this;
  224. }
  225. this.update = function() {
  226. this.lastseen = now_secs;
  227. return this;
  228. }
  229. this.ip = ip;
  230. this.x = 0;
  231. this.y = 0;
  232. this.dx_last=0;
  233. this.dy_last=0;
  234. this.placed = false;
  235. this.weight = 0;
  236. this.edges = new Array();
  237. this.hna = new Array();
  238. this.pinned = false;
  239. this.metric = 999;
  240. this.desc = "";
  241. ncount++;
  242. return this;
  243. }
  244. function touch_node(ip) {
  245. n = nodes[ip];
  246. if(!n) {
  247. n = new node(ip);
  248. nodes[ip] = n;
  249. // newnodes.push(n);
  250. // push and pop not supported in old ie. shit.
  251. newnodes[newnodes.length] = n;
  252. }
  253. return n;
  254. }
  255. function place_new_nodes() {
  256. var nc = 0;
  257. for(i = 0;i<newnodes.length;i++){
  258. n = newnodes[i];
  259. if(n.placed){continue;}
  260. if(sp = getCookie("node_"+n.ip)) {
  261. xy = sp.split("x");
  262. debug_writeln("sp: "+sp+" xy[0]: "+xy[0]+" xy[1]: "+xy[1]);
  263. n.x = parseFloat(xy[0]);
  264. n.y = parseFloat(xy[1]);
  265. }
  266. else if(n.weight>1){
  267. // see if we find allredy placed nodes
  268. ox=0,oy=0;dx=0,dy=0;c=0;
  269. for(e in n.edges){
  270. if(nodes[e] && nodes[e].placed){
  271. if(!ox && !oy) {
  272. ox = nodes[e].x;
  273. oy = nodes[e].y;
  274. }
  275. else {
  276. dx += nodes[e].x - ox;
  277. dy += nodes[e].y - oy;
  278. }
  279. c++;
  280. }
  281. }
  282. if(c>0) {
  283. n.x = ox + dx/c + Math.random()*iel/2-iel/4;
  284. n.y = oy + dy/c + Math.random()*iel/2-iel/4;
  285. }
  286. }
  287. else {
  288. // beginn somewhere
  289. n.x = Math.random()*400;
  290. n.y = Math.random()*400;
  291. }
  292. n.placed = true;
  293. nc++;
  294. }
  295. newnodes.length=0;
  296. return nc;
  297. }
  298. /******** HNA CLASS ********/
  299. function hna(gw,net,mask) {
  300. this.gw = gw;
  301. this.net = net;
  302. this.mask = mask;
  303. return this;
  304. }
  305. function touch_hna(node,net,mask) {
  306. h = node.hna[net];
  307. if(!h) {
  308. h = new hna(node.ip,net,mask);
  309. node.hna[net] = h;
  310. }
  311. h.lastseen = now_secs;
  312. return h;
  313. }
  314. /******** VIZ SETUP AND SETTINGS ********/
  315. function viz_setup(iframeid,maindivid,nodedivid,edgedivid) {
  316. // assign a reference to the
  317. // object to our global variable IFrameObj.
  318. IFrameObj=document.getElementById(iframeid);
  319. if (document.frames) {
  320. // this is for IE5 Mac, because it will only
  321. // allow access to the document object
  322. // of the IFrame if we access it through
  323. // the document.frames array
  324. IFrameObj = document.frames[iframeid];
  325. }
  326. draginit();
  327. maindiv=document.getElementById(maindivid);
  328. nodediv=document.getElementById(nodedivid);
  329. edgediv=document.getElementById(edgedivid);
  330. // autosave on exit?
  331. if((autosave = getCookie("prefs_autosave"))) {
  332. auto_save = parseInt(autosave);
  333. }
  334. viz_autosave(auto_save);
  335. // maximum metric of surrounding nodes
  336. if(mmx = getCookie("prefs_maxmetric")) {
  337. set_maxmetric(mmx,true,true);
  338. }
  339. // scale of view
  340. if((savescale = getCookie("prefs_scale")) &&
  341. (savescale = parseFloat(savescale))) {
  342. set_scale(savescale,true);
  343. }
  344. // scroll - FIXME
  345. /*
  346. if(val = getCookie("prefs_innerview")) {
  347. iv = val.split("x");
  348. if (iv[0] && (iv[0] = parseInt(iv[0])) &&
  349. iv[1] && (iv[2] = parseInt(iv[2])) &&
  350. iv[3] && (iv[3] = parseInt(iv[3])) &&
  351. iv[4] && (iv[4] = parseInt(iv[4])))
  352. {
  353. maindiv.scrollLeft = iv[0] + "px";
  354. maindiv.scrollHeight = iv[1] + "px";
  355. }
  356. }
  357. */
  358. }
  359. function viz_save()
  360. {
  361. // let cookie survive a month
  362. exp = new Date();
  363. exp.setTime(exp.getTime() + 2592000000);
  364. // save node positions
  365. for(ip in nodes)
  366. {
  367. if(nodes[ip].metric > maxmetric) {
  368. continue;
  369. }
  370. setCookie("node_"+ip,nodes[ip].x+"x"+nodes[ip].y,exp);
  371. }
  372. // save maxmetric
  373. setCookie("prefs_maxmetric",maxmetric,exp);
  374. // save zooming
  375. setCookie("prefs_scale",scale,exp);
  376. // save scroll - FIXME
  377. setCookie("prefs_innerview",
  378. parseInt(maindiv.scrollLeft)+"x"+parseInt(maindiv.scrollTop)+"x"+
  379. parseInt(vwidth*scale)+"x"+parseInt(vheight*scale),exp);
  380. }
  381. function viz_autosave(autosave)
  382. {
  383. auto_save = autosave;
  384. if(auto_save) {
  385. document.body.onunload=viz_save;
  386. }
  387. else {
  388. deleteCookie("prefs_autosave");
  389. }
  390. }
  391. function viz_reset()
  392. {
  393. deleteAllCookies();
  394. for(ip in nodes) {
  395. delete nodes[ip];
  396. }
  397. for(e in edges) {
  398. delete edges[e];
  399. }
  400. viz_update();
  401. }
  402. var updateTimer = 0;
  403. function viz_update() {
  404. if (updateTimer) {
  405. clearTimeout(updateTimer);
  406. }
  407. now_secs = new Date().getTime()/1000;
  408. callToServer(cgi_url);
  409. }
  410. function viz_callback() {
  411. if (updateTimer) {
  412. clearTimeout(updateTimer);
  413. }
  414. if(place_new_nodes() > 0 && auto_declump) {
  415. declump();
  416. }
  417. refresh();
  418. updateTimer = setTimeout('viz_update()', 5000);
  419. }
  420. var refresh_running = false;
  421. function refresh() {
  422. if(refresh_running) {
  423. return;
  424. }
  425. refresh_running = true;
  426. var nh = "";
  427. // refresh nodes
  428. nh = "";
  429. for (var n in nodes) {
  430. if(nodes[n].isDead()) {
  431. nodes[n].cleanup();
  432. delete nodes[n];
  433. }
  434. else {
  435. nh += nodes[n].getHTML();
  436. }
  437. }
  438. nodediv.innerHTML = nh;
  439. // refresh edges
  440. nh = "";
  441. for (var e in edges) {
  442. if(edges[e].isDead()) {
  443. edges[e].cleanup();
  444. delete edges[e];
  445. }
  446. else {
  447. nh += edges[e].getHTML();
  448. }
  449. }
  450. edgediv.innerHTML = nh;
  451. refresh_running = false;
  452. }
  453. function set_showdesc(doit)
  454. {
  455. showdesc = doit;
  456. if(!noupdate) refresh();
  457. }
  458. function set_autodeclump(doit)
  459. {
  460. auto_declump = doit;
  461. if(doit) {
  462. declump();
  463. }
  464. else {
  465. clearTimeout(dclTimer);
  466. }
  467. }
  468. function set_scale(inscale,noupdate)
  469. {
  470. if(!inscale) {
  471. inscale = parseFloat(document.getElementById("zoom").value/2);
  472. }
  473. scale = Math.round(inscale*100)/100;
  474. if(!scale || scale<0.1) {
  475. scale = 0.1;
  476. }
  477. document.getElementById("zoom").value = scale*2;
  478. if(!noupdate) refresh();
  479. }
  480. function set_maxmetric(inmetric,noupdate,noconfirm)
  481. {
  482. inmetric = parseInt(inmetric);
  483. if(inmetric > 0 || !noconfirm || confirm("warning. setting the maximum metric to zero can lead to expensive calculations if you are connected to a network with many nodes. do you want to proceed?")) {
  484. maxmetric = inmetric;
  485. }
  486. document.getElementById("maxmetric").value = maxmetric;
  487. if(!noupdate) refresh();
  488. }
  489. // k = area / nodes
  490. function fr(x) {
  491. return Math.pow((iel*iel)/x,2);
  492. }
  493. function fa(x) {
  494. return Math.pow((x*x)/iel,2);
  495. }
  496. var dclTimer = 0;
  497. var declump_running = false;
  498. function declump(t) {
  499. // clear declump timer
  500. if(dclTimer) {
  501. clearTimeout(dclTimer);
  502. }
  503. if(declump_running) {
  504. return;
  505. }
  506. declump_running = true;
  507. // nodes
  508. nc = 0;
  509. for (var ip1 in nodes) {
  510. nodes[ip1].fr_x=0;
  511. nodes[ip1].fr_y=0;
  512. nodes[ip1].fa_x=0;
  513. nodes[ip1].fa_y=0;
  514. nodes[ip1].x_next = nodes[ip1].x;
  515. nodes[ip1].y_next = nodes[ip1].y;
  516. nodes[ip1].randdisplace = 0;
  517. }
  518. for (var ip1 in nodes) {
  519. if(nodes[ip1].metric > maxmetric || nodes[ip1].pinned) {
  520. continue;
  521. }
  522. for (ip2 in nodes) {
  523. if (nodes[ip2].metric > maxmetric || ip1 == ip2) {
  524. continue;
  525. }
  526. dx = (nodes[ip1].x_next - nodes[ip2].x_next);
  527. dy = (nodes[ip1].y_next - nodes[ip2].y_next);
  528. d = Math.sqrt(dx*dx+dy*dy);
  529. d = Math.max(d-optsize,(d+optsize)/optsize);
  530. nodes[ip1].fr_x += (dx/d) * fr(d);
  531. nodes[ip1].fr_y += (dy/d) * fr(d);
  532. }
  533. dx = nodes[ip1].fr_x;
  534. dy = nodes[ip1].fr_y;
  535. d = Math.sqrt(dx*dx+dy*dy);
  536. md = Math.min(d,iel/nodes[ip1].weight);
  537. nodes[ip1].x_next += (dx / d) * md;
  538. nodes[ip1].y_next += (dy / d) * md;
  539. nc++;
  540. }
  541. // edges
  542. ec = 0;
  543. for (var e in edges) {
  544. if (!edges[e].n1 || !edges[e].n2 ||
  545. edges[e].n1.metric > maxmetric || edges[e].n2.metric > maxmetric) {
  546. continue;
  547. }
  548. dx = (edges[e].n1.x_next - edges[e].n2.x_next);
  549. dy = (edges[e].n1.y_next - edges[e].n2.y_next);
  550. d = Math.sqrt(dx*dx+dy*dy);
  551. // d = Math.max(d-optsize,(d+optsize)/optsize);
  552. edges[e].n1.fa_x -= (dx/d) * fa(d);
  553. edges[e].n1.fa_y -= (dy/d) * fa(d);
  554. edges[e].n2.fa_x += (dx/d) * fa(d);
  555. edges[e].n2.fa_y += (dy/d) * fa(d);
  556. ec++;
  557. }
  558. // displacement
  559. xmin=-20;ymin=-20;xmax=20;ymax=20;dsum=0;
  560. for (var ip in nodes) {
  561. if(nodes[ip].metric > maxmetric || nodes[ip].pinned) {
  562. continue;
  563. }
  564. dx = nodes[ip].fa_x;
  565. dy = nodes[ip].fa_y;
  566. d = Math.sqrt(dx*dx+dy*dy);
  567. dx = (dx / d) * Math.min(d,iel/nodes[ip].weight) * 0.75 + nodes[ip].dx_last * 0.25;
  568. dy = (dy / d) * Math.min(d,iel/nodes[ip].weight) * 0.75 + nodes[ip].dy_last * 0.25;
  569. nodes[ip].dx_last = dx;
  570. nodes[ip].dy_last = dy;
  571. nodes[ip].x_next += dx;
  572. nodes[ip].y_next += dy;
  573. if(!nodes[ip].x_next || !nodes[ip].y_next) {
  574. continue;
  575. }
  576. dx = (nodes[ip].x - nodes[ip].x_next);
  577. dy = (nodes[ip].y - nodes[ip].y_next);
  578. dsum += Math.sqrt(dx*dx+dy*dy);
  579. nodes[ip].x = nodes[ip].x_next;
  580. nodes[ip].y = nodes[ip].y_next;
  581. xmin = Math.min(xmin,nodes[ip].x);
  582. xmax = Math.max(xmax,nodes[ip].x);
  583. ymin = Math.min(ymin,nodes[ip].y);
  584. ymax = Math.max(ymax,nodes[ip].y);
  585. }
  586. vwidth=(xmax-xmin);
  587. vheight=(ymax-ymin);
  588. xoff=-xmin;
  589. yoff=-ymin;
  590. /*
  591. document.getElementById('debug').innerHTML = "<br>" +
  592. "offset: " + xoff + "x" + yoff + " dsum: " + dsum + "<br>" +
  593. "nc: " + nc + " ec: " + ec + "xmax: " + xmax + " xmin: " + xmin + "<br>" +
  594. "optsize: " + optsize + "<br>";
  595. */
  596. refresh();
  597. if(auto_declump) {
  598. dclTimer = setTimeout("declump()", dsum>ncount ? dcl_timeout : dcllow_timeout );
  599. }
  600. declump_running = false;
  601. }
  602. //Das Objekt, das gerade bewegt wird.
  603. var dragip = null;
  604. // Position, an der das Objekt angeklickt wurde.
  605. var dragx = 0;
  606. var dragy = 0;
  607. // Mausposition
  608. var posx = 0;
  609. var posy = 0;
  610. function draginit() {
  611. // Initialisierung der ãberwachung der Events
  612. document.onmousemove = drag;
  613. document.onmouseup = dragstop;
  614. }
  615. function dragstart(element) {
  616. //Wird aufgerufen, wenn ein Objekt bewegt werden soll.
  617. dragip = element.id.split("_")[1];
  618. dragx = posx - element.offsetLeft;
  619. dragy = posy - element.offsetTop;
  620. n = nodes[dragip];
  621. if(n) {
  622. n.pinned = true;
  623. }
  624. }
  625. function dragstop() {
  626. //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
  627. n = nodes[dragip];
  628. if(n) {
  629. n.pinned = false;
  630. }
  631. refresh();
  632. dragip=null;
  633. }
  634. function drag(ereignis) {
  635. //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.
  636. posx = document.all ? window.event.clientX : ereignis.pageX;
  637. posy = document.all ? window.event.clientY : ereignis.pageY;
  638. if(dragip != null) {
  639. n = nodes[dragip];
  640. if(n) {
  641. n.x = (posx - dragx)/scale - xoff;
  642. n.y = (posy - dragy)/scale - yoff;
  643. }
  644. e = document.getElementById('node_'+dragip);
  645. e.style.left = parseInt((n.x+xoff)*scale) + "px";
  646. e.style.top = parseInt((n.y+yoff)*scale) + "px";
  647. }
  648. }
  649. function debug_writeln(line)
  650. {
  651. document.getElementById('debug').innerHTML = line + "<br>" + document.getElementById('debug').innerHTML;
  652. }
  653. /**
  654. * Sets a Cookie with the given name and value.
  655. *
  656. * name Name of the cookie
  657. * value Value of the cookie
  658. * [expires] Expiration date of the cookie (default: end of current session)
  659. * [path] Path where the cookie is valid (default: path of calling document)
  660. * [domain] Domain where the cookie is valid
  661. * (default: domain of calling document)
  662. * [secure] Boolean value indicating if the cookie transmission requires a
  663. * secure transmission
  664. */
  665. function setCookie(name, value, expires, path, domain, secure) {
  666. document.cookie= name + "=" + escape(value) +
  667. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  668. ((path) ? "; path=" + path : "") +
  669. ((domain) ? "; domain=" + domain : "") +
  670. ((secure) ? "; secure" : "");
  671. }
  672. /**
  673. * Gets the value of the specified cookie.
  674. *
  675. * name Name of the desired cookie.
  676. *
  677. * Returns a string containing value of specified cookie,
  678. * or null if cookie does not exist.
  679. */
  680. function getCookie(name)
  681. {
  682. var results = document.cookie.match ( name + '=(.*?)(;|$)' );
  683. if (results) {
  684. return unescape(results[1]);
  685. }
  686. return null;
  687. }
  688. /**
  689. * Deletes the specified cookie.
  690. *
  691. * name name of the cookie
  692. * [path] path of the cookie (must be same as path used to create cookie)
  693. * [domain] domain of the cookie (must be same as domain used to create cookie)
  694. */
  695. function deleteCookie(name, path, domain) {
  696. if (getCookie(name)) {
  697. document.cookie = name + "=" +
  698. ((path) ? "; path=" + path : "") +
  699. ((domain) ? "; domain=" + domain : "") +
  700. "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  701. }
  702. }
  703. function deleteAllCookies() {
  704. cookies = document.cookie.split("; ");
  705. for(i=0;i<cookies.length;i++) {
  706. deleteCookie(cookies[i].split("=")[0]);
  707. }
  708. }