2
0

olsr-viz.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  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. var x = this.n1.x*scale;
  89. var y = this.n1.y*scale;
  90. var dx = this.n2.x*scale - x;
  91. var dy = this.n2.y*scale - y;
  92. x += xoff*scale + 75;
  93. y += yoff*scale + 15;
  94. var 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. var d = Math.sqrt(dx*dx+dy*dy);
  109. for (var 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. var 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(var 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. var 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(var i = 0;i<newnodes.length;i++){
  258. var n = newnodes[i];
  259. if(n.placed){continue;}
  260. var sp;
  261. if(sp = getCookie("node_"+n.ip)) {
  262. var xy = sp.split("x");
  263. debug_writeln("sp: "+sp+" xy[0]: "+xy[0]+" xy[1]: "+xy[1]);
  264. n.x = parseFloat(xy[0]);
  265. n.y = parseFloat(xy[1]);
  266. }
  267. else if(n.weight>1){
  268. // see if we find already placed nodes
  269. var ox=0, oy=0;
  270. var dx=0, dy=0;
  271. var c=0;
  272. for(var e in n.edges){
  273. if(nodes[e] && nodes[e].placed){
  274. if(!ox && !oy) {
  275. ox = nodes[e].x;
  276. oy = nodes[e].y;
  277. }
  278. else {
  279. dx += nodes[e].x - ox;
  280. dy += nodes[e].y - oy;
  281. }
  282. c++;
  283. }
  284. }
  285. if(c>0) {
  286. n.x = ox + dx/c + Math.random()*iel/2-iel/4;
  287. n.y = oy + dy/c + Math.random()*iel/2-iel/4;
  288. }
  289. }
  290. else {
  291. // begin somewhere
  292. n.x = Math.random()*400;
  293. n.y = Math.random()*400;
  294. }
  295. n.placed = true;
  296. nc++;
  297. }
  298. newnodes.length=0;
  299. return nc;
  300. }
  301. /******** HNA CLASS ********/
  302. function hna(gw,net,mask) {
  303. this.gw = gw;
  304. this.net = net;
  305. this.mask = mask;
  306. return this;
  307. }
  308. function touch_hna(node,net,mask) {
  309. var h = node.hna[net];
  310. if(!h) {
  311. h = new hna(node.ip,net,mask);
  312. node.hna[net] = h;
  313. }
  314. h.lastseen = now_secs;
  315. return h;
  316. }
  317. /******** VIZ SETUP AND SETTINGS ********/
  318. function viz_setup(iframeid,maindivid,nodedivid,edgedivid) {
  319. // assign a reference to the
  320. // object to our global variable IFrameObj.
  321. IFrameObj=document.getElementById(iframeid);
  322. if (document.frames) {
  323. // this is for IE5 Mac, because it will only
  324. // allow access to the document object
  325. // of the IFrame if we access it through
  326. // the document.frames array
  327. IFrameObj = document.frames[iframeid];
  328. }
  329. draginit();
  330. maindiv=document.getElementById(maindivid);
  331. nodediv=document.getElementById(nodedivid);
  332. edgediv=document.getElementById(edgedivid);
  333. // autosave on exit?
  334. var autosave;
  335. if((autosave = getCookie("prefs_autosave"))) {
  336. auto_save = parseInt(autosave);
  337. }
  338. viz_autosave(auto_save);
  339. // maximum metric of surrounding nodes
  340. var mmx;
  341. if(mmx = getCookie("prefs_maxmetric")) {
  342. set_maxmetric(mmx,true,true);
  343. }
  344. // scale of view
  345. var savescale;
  346. if((savescale = getCookie("prefs_scale")) &&
  347. (savescale = parseFloat(savescale))) {
  348. set_scale(savescale,true);
  349. }
  350. // scroll - FIXME
  351. /*
  352. if(val = getCookie("prefs_innerview")) {
  353. iv = val.split("x");
  354. if (iv[0] && (iv[0] = parseInt(iv[0])) &&
  355. iv[1] && (iv[2] = parseInt(iv[2])) &&
  356. iv[3] && (iv[3] = parseInt(iv[3])) &&
  357. iv[4] && (iv[4] = parseInt(iv[4])))
  358. {
  359. maindiv.scrollLeft = iv[0] + "px";
  360. maindiv.scrollHeight = iv[1] + "px";
  361. }
  362. }
  363. */
  364. }
  365. function viz_save()
  366. {
  367. // let cookie survive a month
  368. var exp = new Date();
  369. exp.setTime(exp.getTime() + 2592000000);
  370. // save node positions
  371. for(var ip in nodes)
  372. {
  373. if(nodes[ip].metric > maxmetric) {
  374. continue;
  375. }
  376. setCookie("node_"+ip,nodes[ip].x+"x"+nodes[ip].y,exp);
  377. }
  378. // save maxmetric
  379. setCookie("prefs_maxmetric",maxmetric,exp);
  380. // save zooming
  381. setCookie("prefs_scale",scale,exp);
  382. // save scroll - FIXME
  383. setCookie("prefs_innerview",
  384. parseInt(maindiv.scrollLeft)+"x"+parseInt(maindiv.scrollTop)+"x"+
  385. parseInt(vwidth*scale)+"x"+parseInt(vheight*scale),exp);
  386. }
  387. function viz_autosave(autosave)
  388. {
  389. auto_save = autosave;
  390. if(auto_save) {
  391. document.body.onunload=viz_save;
  392. }
  393. else {
  394. deleteCookie("prefs_autosave");
  395. }
  396. }
  397. function viz_reset()
  398. {
  399. deleteAllCookies();
  400. for(var ip in nodes) {
  401. delete nodes[ip];
  402. }
  403. for(var e in edges) {
  404. delete edges[e];
  405. }
  406. viz_update();
  407. }
  408. var updateTimer = 0;
  409. function viz_update() {
  410. if (updateTimer) {
  411. clearTimeout(updateTimer);
  412. }
  413. now_secs = new Date().getTime()/1000;
  414. callToServer(cgi_url);
  415. }
  416. function viz_callback() {
  417. if (updateTimer) {
  418. clearTimeout(updateTimer);
  419. }
  420. if(place_new_nodes() > 0 && auto_declump) {
  421. declump();
  422. }
  423. refresh();
  424. updateTimer = setTimeout('viz_update()', 5000);
  425. }
  426. var refresh_running = false;
  427. function refresh() {
  428. if(refresh_running) {
  429. return;
  430. }
  431. refresh_running = true;
  432. var nh = "";
  433. // refresh nodes
  434. nh = "";
  435. for (var n in nodes) {
  436. if(nodes[n].isDead()) {
  437. nodes[n].cleanup();
  438. delete nodes[n];
  439. }
  440. else {
  441. nh += nodes[n].getHTML();
  442. }
  443. }
  444. nodediv.innerHTML = nh;
  445. // refresh edges
  446. nh = "";
  447. for (var e in edges) {
  448. if(edges[e].isDead()) {
  449. edges[e].cleanup();
  450. delete edges[e];
  451. }
  452. else {
  453. nh += edges[e].getHTML();
  454. }
  455. }
  456. edgediv.innerHTML = nh;
  457. refresh_running = false;
  458. }
  459. function set_showdesc(doit)
  460. {
  461. showdesc = doit;
  462. if(!noupdate) refresh();
  463. }
  464. function set_autodeclump(doit)
  465. {
  466. auto_declump = doit;
  467. if(doit) {
  468. declump();
  469. }
  470. else {
  471. clearTimeout(dclTimer);
  472. }
  473. }
  474. function set_scale(inscale,noupdate)
  475. {
  476. if(!inscale) {
  477. inscale = parseFloat(document.getElementById("zoom").value/2);
  478. }
  479. scale = Math.round(inscale*100)/100;
  480. if(!scale || scale<0.1) {
  481. scale = 0.1;
  482. }
  483. document.getElementById("zoom").value = scale*2;
  484. if(!noupdate) refresh();
  485. }
  486. function set_maxmetric(inmetric,noupdate,noconfirm)
  487. {
  488. inmetric = parseInt(inmetric);
  489. 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?")) {
  490. maxmetric = inmetric;
  491. }
  492. document.getElementById("maxmetric").value = maxmetric;
  493. if(!noupdate) refresh();
  494. }
  495. // k = area / nodes
  496. function fr(x) {
  497. return Math.pow((iel*iel)/x,2);
  498. }
  499. function fa(x) {
  500. return Math.pow((x*x)/iel,2);
  501. }
  502. var dclTimer = 0;
  503. var declump_running = false;
  504. function declump(t) {
  505. var dx;
  506. var dy;
  507. var d;
  508. // clear declump timer
  509. if(dclTimer) {
  510. clearTimeout(dclTimer);
  511. }
  512. if(declump_running) {
  513. return;
  514. }
  515. declump_running = true;
  516. // nodes
  517. var nc = 0;
  518. for (var ip1 in nodes) {
  519. nodes[ip1].fr_x=0;
  520. nodes[ip1].fr_y=0;
  521. nodes[ip1].fa_x=0;
  522. nodes[ip1].fa_y=0;
  523. nodes[ip1].x_next = nodes[ip1].x;
  524. nodes[ip1].y_next = nodes[ip1].y;
  525. nodes[ip1].randdisplace = 0;
  526. }
  527. for (var ip1 in nodes) {
  528. if(nodes[ip1].metric > maxmetric || nodes[ip1].pinned) {
  529. continue;
  530. }
  531. for (var ip2 in nodes) {
  532. if (nodes[ip2].metric > maxmetric || ip1 == ip2) {
  533. continue;
  534. }
  535. dx = (nodes[ip1].x_next - nodes[ip2].x_next);
  536. dy = (nodes[ip1].y_next - nodes[ip2].y_next);
  537. d = Math.sqrt(dx*dx+dy*dy);
  538. d = Math.max(d-optsize,(d+optsize)/optsize);
  539. nodes[ip1].fr_x += (dx/d) * fr(d);
  540. nodes[ip1].fr_y += (dy/d) * fr(d);
  541. }
  542. dx = nodes[ip1].fr_x;
  543. dy = nodes[ip1].fr_y;
  544. d = Math.sqrt(dx*dx+dy*dy);
  545. var md = Math.min(d,iel/nodes[ip1].weight);
  546. nodes[ip1].x_next += (dx / d) * md;
  547. nodes[ip1].y_next += (dy / d) * md;
  548. nc++;
  549. }
  550. // edges
  551. var ec = 0;
  552. for (var e in edges) {
  553. if (!edges[e].n1 || !edges[e].n2 ||
  554. edges[e].n1.metric > maxmetric || edges[e].n2.metric > maxmetric) {
  555. continue;
  556. }
  557. dx = (edges[e].n1.x_next - edges[e].n2.x_next);
  558. dy = (edges[e].n1.y_next - edges[e].n2.y_next);
  559. d = Math.sqrt(dx*dx+dy*dy);
  560. // d = Math.max(d-optsize,(d+optsize)/optsize);
  561. edges[e].n1.fa_x -= (dx/d) * fa(d);
  562. edges[e].n1.fa_y -= (dy/d) * fa(d);
  563. edges[e].n2.fa_x += (dx/d) * fa(d);
  564. edges[e].n2.fa_y += (dy/d) * fa(d);
  565. ec++;
  566. }
  567. // displacement
  568. var xmin=-20;
  569. var ymin=-20;
  570. var xmax=20;
  571. var ymax=20;
  572. var dsum=0;
  573. for (var ip in nodes) {
  574. if(nodes[ip].metric > maxmetric || nodes[ip].pinned) {
  575. continue;
  576. }
  577. dx = nodes[ip].fa_x;
  578. dy = nodes[ip].fa_y;
  579. d = Math.sqrt(dx*dx+dy*dy);
  580. dx = (dx / d) * Math.min(d,iel/nodes[ip].weight) * 0.75 + nodes[ip].dx_last * 0.25;
  581. dy = (dy / d) * Math.min(d,iel/nodes[ip].weight) * 0.75 + nodes[ip].dy_last * 0.25;
  582. nodes[ip].dx_last = dx;
  583. nodes[ip].dy_last = dy;
  584. nodes[ip].x_next += dx;
  585. nodes[ip].y_next += dy;
  586. if(!nodes[ip].x_next || !nodes[ip].y_next) {
  587. continue;
  588. }
  589. dx = (nodes[ip].x - nodes[ip].x_next);
  590. dy = (nodes[ip].y - nodes[ip].y_next);
  591. dsum += Math.sqrt(dx*dx+dy*dy);
  592. nodes[ip].x = nodes[ip].x_next;
  593. nodes[ip].y = nodes[ip].y_next;
  594. xmin = Math.min(xmin,nodes[ip].x);
  595. xmax = Math.max(xmax,nodes[ip].x);
  596. ymin = Math.min(ymin,nodes[ip].y);
  597. ymax = Math.max(ymax,nodes[ip].y);
  598. }
  599. vwidth=(xmax-xmin);
  600. vheight=(ymax-ymin);
  601. xoff=-xmin;
  602. yoff=-ymin;
  603. /*
  604. document.getElementById('debug').innerHTML = "<br>" +
  605. "offset: " + xoff + "x" + yoff + " dsum: " + dsum + "<br>" +
  606. "nc: " + nc + " ec: " + ec + "xmax: " + xmax + " xmin: " + xmin + "<br>" +
  607. "optsize: " + optsize + "<br>";
  608. */
  609. refresh();
  610. if(auto_declump) {
  611. dclTimer = setTimeout("declump()", dsum>ncount ? dcl_timeout : dcllow_timeout );
  612. }
  613. declump_running = false;
  614. }
  615. //Das Objekt, das gerade bewegt wird.
  616. var dragip = null;
  617. // Position, an der das Objekt angeklickt wurde.
  618. var dragx = 0;
  619. var dragy = 0;
  620. // Mausposition
  621. var posx = 0;
  622. var posy = 0;
  623. function draginit() {
  624. // Initialisierung der ãberwachung der Events
  625. document.onmousemove = drag;
  626. document.onmouseup = dragstop;
  627. }
  628. function dragstart(element) {
  629. //Wird aufgerufen, wenn ein Objekt bewegt werden soll.
  630. dragip = element.id.split("_")[1];
  631. dragx = posx - element.offsetLeft;
  632. dragy = posy - element.offsetTop;
  633. var n = nodes[dragip];
  634. if(n) {
  635. n.pinned = true;
  636. }
  637. }
  638. function dragstop() {
  639. //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
  640. var n = nodes[dragip];
  641. if(n) {
  642. n.pinned = false;
  643. }
  644. refresh();
  645. dragip=null;
  646. }
  647. function drag(ereignis) {
  648. //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.
  649. posx = document.all ? window.event.clientX : ereignis.pageX;
  650. posy = document.all ? window.event.clientY : ereignis.pageY;
  651. if(dragip != null) {
  652. var n = nodes[dragip];
  653. if(n) {
  654. n.x = (posx - dragx)/scale - xoff;
  655. n.y = (posy - dragy)/scale - yoff;
  656. }
  657. var e = document.getElementById('node_'+dragip);
  658. e.style.left = parseInt((n.x+xoff)*scale) + "px";
  659. e.style.top = parseInt((n.y+yoff)*scale) + "px";
  660. }
  661. }
  662. function debug_writeln(line)
  663. {
  664. document.getElementById('debug').innerHTML = line + "<br>" + document.getElementById('debug').innerHTML;
  665. }
  666. /**
  667. * Sets a Cookie with the given name and value.
  668. *
  669. * name Name of the cookie
  670. * value Value of the cookie
  671. * [expires] Expiration date of the cookie (default: end of current session)
  672. * [path] Path where the cookie is valid (default: path of calling document)
  673. * [domain] Domain where the cookie is valid
  674. * (default: domain of calling document)
  675. * [secure] Boolean value indicating if the cookie transmission requires a
  676. * secure transmission
  677. */
  678. function setCookie(name, value, expires, path, domain, secure) {
  679. document.cookie= name + "=" + escape(value) +
  680. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  681. ((path) ? "; path=" + path : "") +
  682. ((domain) ? "; domain=" + domain : "") +
  683. ((secure) ? "; secure" : "");
  684. }
  685. /**
  686. * Gets the value of the specified cookie.
  687. *
  688. * name Name of the desired cookie.
  689. *
  690. * Returns a string containing value of specified cookie,
  691. * or null if cookie does not exist.
  692. */
  693. function getCookie(name)
  694. {
  695. var results = document.cookie.match ( name + '=(.*?)(;|$)' );
  696. if (results) {
  697. return unescape(results[1]);
  698. }
  699. return null;
  700. }
  701. /**
  702. * Deletes the specified cookie.
  703. *
  704. * name name of the cookie
  705. * [path] path of the cookie (must be same as path used to create cookie)
  706. * [domain] domain of the cookie (must be same as domain used to create cookie)
  707. */
  708. function deleteCookie(name, path, domain) {
  709. if (getCookie(name)) {
  710. document.cookie = name + "=" +
  711. ((path) ? "; path=" + path : "") +
  712. ((domain) ? "; domain=" + domain : "") +
  713. "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  714. }
  715. }
  716. function deleteAllCookies() {
  717. var cookies = document.cookie.split("; ");
  718. for(var i=0;i<cookies.length;i++) {
  719. deleteCookie(cookies[i].split("=")[0]);
  720. }
  721. }