olsr-viz.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  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 maxmetric = 3;
  32. var iconvariant = "-mini";
  33. var nodes = new Array();
  34. var ncount = 0;
  35. var newnodes = new Array();
  36. var edges = new Array();
  37. var iel = 220; // ideal edge length
  38. var optsize = 10; // boundingbox around nodes
  39. var vwidth = 0;
  40. var vheight = 0;
  41. var xoff = 0;
  42. var yoff = 0;
  43. var scale = 1.0;
  44. var idle_timeout = 15;
  45. var erase_timeout = 60;
  46. var dcl_timeout = 250;
  47. var dcllow_timeout = 500;
  48. var auto_declump = true;
  49. var showdesc = true;
  50. var auto_save = 1;
  51. var now_secs = 5;
  52. // dom elements
  53. var IFrameObj;
  54. var mainDiv;
  55. var nodeDiv;
  56. var edgeDiv;
  57. var zoomInput;
  58. var maxmetricInput;
  59. var debugSpan;
  60. /******** EDGE CLASS ********/
  61. function edge(n1, n2) {
  62. this.getHTML = function () {
  63. var nh = "";
  64. if (this.n1.metric > maxmetric || this.n2.metric > maxmetric) {
  65. return "";
  66. }
  67. var x = this.n1.x * scale;
  68. var y = this.n1.y * scale;
  69. var dx = this.n2.x * scale - x;
  70. var dy = this.n2.y * scale - y;
  71. x += xoff * scale + 75;
  72. y += yoff * scale + 15;
  73. var imgtag = "<img src='/luci-static/resources/olsr-viz/dot_"
  74. if (this.etx > 0 && this.etx < 2) {
  75. imgtag += "good.gif'";
  76. }
  77. else if (this.etx > 2 && this.etx < 5) {
  78. imgtag += "ok.gif'";
  79. }
  80. else if (this.etx > 5 && this.etx < 10) {
  81. imgtag += "weak.gif'";
  82. }
  83. else {
  84. imgtag += "down.gif'";
  85. }
  86. imgtag += " alt='ETX: " + this.etx + "' title='ETX: " + this.etx + "' ";
  87. var d = Math.sqrt(dx * dx + dy * dy);
  88. for (var j = 0; j < d; j += 15) {
  89. nh += imgtag + "style='top:"
  90. + parseInt(y + dy * j / d) + "px; left:"
  91. + parseInt(x + dx * j / d) + "px; "
  92. + "width: 4px; height: 4px; position: absolute; z-index: 2' >";
  93. }
  94. nh += "<div style='top:"
  95. + parseInt(y + dy * 0.5 - 5) + "px; left:"
  96. + parseInt(x + dx * 0.5 - 24) + "px; "
  97. + "position: absolute; z-index: 3; width: 48px; text-align: center;' >"
  98. + "<span class='label etx' >" + this.etx + "</span></div>";
  99. return nh;
  100. }
  101. this.isIdle = function () {
  102. return (now_secs - this.lastseen > idle_timeout);
  103. }
  104. this.isDead = function () {
  105. return (now_secs - this.lastseen > erase_timeout);
  106. }
  107. this.cleanup = function () {
  108. if (this.n1 && this.n1.weight) {
  109. this.n1.weight--;
  110. }
  111. if (this.n2 && this.n2.weight) {
  112. this.n2.weight--;
  113. }
  114. if (this.n1 && this.n2) {
  115. delete this.n1.edges[n2.ip];
  116. delete this.n2.edges[n1.ip];
  117. }
  118. }
  119. this.n1 = n1;
  120. this.n2 = n2;
  121. // setup edges within node objects
  122. this.n1.weight++;
  123. this.n1.edges[n2.ip] = this;
  124. this.n2.weight++;
  125. this.n2.edges[n1.ip] = this;
  126. return this;
  127. }
  128. function getEdgeKey(ip1, ip2) {
  129. var key = "";
  130. if (ip1 > ip2) {
  131. key = ip2 + "-" + ip1;
  132. }
  133. else {
  134. key = ip1 + "-" + ip2;
  135. }
  136. return key;
  137. }
  138. function touch_edge(n1, n2, etx) {
  139. var key = getEdgeKey(n1.ip, n2.ip);
  140. var e = edges[key];
  141. if (!e) {
  142. e = new edge(n1, n2);
  143. edges[key] = e;
  144. }
  145. e.etx = etx;
  146. e.lastseen = now_secs;
  147. return e;
  148. }
  149. /******** NODE CLASS ********/
  150. function node(ip) {
  151. this.getHTML = function () {
  152. var nh;
  153. if (this.metric > maxmetric) {
  154. return "";
  155. }
  156. var igw = 0;
  157. for (var h in this.hna) {
  158. if (h == "0.0.0.0") {
  159. igw = 1;
  160. break;
  161. }
  162. }
  163. nh =
  164. "<div id='node_" + this.ip + "' onmousedown='dragstart(this)' style="
  165. + "'top: " + parseInt((this.y + yoff) * scale) + "px; "
  166. + "left: " + parseInt((this.x + xoff) * scale) + "px; "
  167. + "width: 150px; height: 1px; z-index: 4; "
  168. + "position: absolute; background-color: transparent;' >"
  169. + "<div><img src='/luci-static/resources/olsr-viz/node" + (igw ? "-hna" : "") + iconvariant + ".gif'"
  170. + " alt='node " + this.ip + "' style='border: none;'><br />"
  171. + "<a href='http://" + this.ip + "/'>"
  172. + "<span class='label ip'>" + this.ip + "</span></a>"
  173. + (showdesc && this.desc != "" ?
  174. "<br /><span class='label desc'>" + this.desc + "</span>" : "")
  175. + "</div></div>";
  176. return nh;
  177. }
  178. this.isIdle = function () {
  179. return (now_secs - this.lastseen > idle_timeout);
  180. }
  181. this.isDead = function () {
  182. return (now_secs - this.lastseen > erase_timeout);
  183. }
  184. this.cleanup = function () {
  185. ncount--;
  186. }
  187. this.set_metric = function (metric) {
  188. this.metric = metric;
  189. return this;
  190. }
  191. this.set_desc = function (desc) {
  192. this.desc = desc
  193. return this;
  194. }
  195. this.update = function () {
  196. this.lastseen = now_secs;
  197. return this;
  198. }
  199. this.ip = ip;
  200. this.x = 0;
  201. this.y = 0;
  202. this.dx_last = 0;
  203. this.dy_last = 0;
  204. this.placed = false;
  205. this.weight = 0;
  206. this.edges = new Array();
  207. this.hna = new Array();
  208. this.pinned = false;
  209. this.metric = 999;
  210. this.desc = "";
  211. ncount++;
  212. return this;
  213. }
  214. function touch_node(ip) {
  215. var n = nodes[ip];
  216. if (!n) {
  217. n = new node(ip);
  218. nodes[ip] = n;
  219. // newnodes.push(n);
  220. // push and pop not supported in old ie. shit.
  221. newnodes[newnodes.length] = n;
  222. }
  223. return n;
  224. }
  225. function place_new_nodes() {
  226. var nc = 0;
  227. for (var i = 0; i < newnodes.length; i++) {
  228. var n = newnodes[i];
  229. if (n.placed) { continue; }
  230. var sp;
  231. if (sp = getCookie("node_" + n.ip)) {
  232. var xy = sp.split("x");
  233. debug_writeln(("sp: " + sp + " xy[0]: " + xy[0] + " xy[1]: " + xy[1]));
  234. n.x = parseFloat(xy[0]);
  235. n.y = parseFloat(xy[1]);
  236. }
  237. else if (n.weight > 1) {
  238. // see if we find already placed nodes
  239. var ox = 0, oy = 0;
  240. var dx = 0, dy = 0;
  241. var c = 0;
  242. for (var e in n.edges) {
  243. if (nodes[e] && nodes[e].placed) {
  244. if (!ox && !oy) {
  245. ox = nodes[e].x;
  246. oy = nodes[e].y;
  247. }
  248. else {
  249. dx += nodes[e].x - ox;
  250. dy += nodes[e].y - oy;
  251. }
  252. c++;
  253. }
  254. }
  255. if (c > 0) {
  256. n.x = ox + dx / c + Math.random() * iel / 2 - iel / 4;
  257. n.y = oy + dy / c + Math.random() * iel / 2 - iel / 4;
  258. }
  259. }
  260. else {
  261. // begin somewhere
  262. n.x = Math.random() * 400;
  263. n.y = Math.random() * 400;
  264. }
  265. n.placed = true;
  266. nc++;
  267. }
  268. newnodes.length = 0;
  269. return nc;
  270. }
  271. /******** HNA CLASS ********/
  272. function hna(gw, net, mask) {
  273. this.gw = gw;
  274. this.net = net;
  275. this.mask = mask;
  276. return this;
  277. }
  278. function touch_hna(node, net, mask) {
  279. var h = node.hna[net];
  280. if (!h) {
  281. h = new hna(node.ip, net, mask);
  282. node.hna[net] = h;
  283. }
  284. h.lastseen = now_secs;
  285. return h;
  286. }
  287. /******** VIZ SETUP AND SETTINGS ********/
  288. function viz_setup(iframe, maindiv, nodediv, edgediv, debugspan, zoominput, maxmetricinput) {
  289. // assign a reference to the
  290. // object to our global variable IFrameObj.
  291. IFrameObj = iframe;
  292. draginit();
  293. mainDiv = maindiv;
  294. nodeDiv = nodediv;
  295. edgeDiv = edgediv;
  296. debugSpan = debugspan;
  297. zoomInput = zoominput;
  298. maxmetricInput = maxmetricinput;
  299. // autosave on exit?
  300. var autosave;
  301. if ((autosave = getCookie("prefs_autosave"))) {
  302. auto_save = parseInt(autosave);
  303. }
  304. viz_autosave(auto_save);
  305. // maximum metric of surrounding nodes
  306. var mmx = (getCookie("prefs_maxmetric"))||3;
  307. set_maxmetric(mmx, true, true);
  308. // scale of view
  309. var savescale;
  310. if ((savescale = getCookie("prefs_scale")) &&
  311. (savescale = parseFloat(savescale))) {
  312. set_scale(savescale, true);
  313. }
  314. else {
  315. set_scale(2.0, true);
  316. }
  317. // scroll - FIXME
  318. /*
  319. if(val = getCookie("prefs_innerview")) {
  320. iv = val.split("x");
  321. if (iv[0] && (iv[0] = parseInt(iv[0])) &&
  322. iv[1] && (iv[2] = parseInt(iv[2])) &&
  323. iv[3] && (iv[3] = parseInt(iv[3])) &&
  324. iv[4] && (iv[4] = parseInt(iv[4])))
  325. {
  326. maindiv.scrollLeft = iv[0] + "px";
  327. maindiv.scrollHeight = iv[1] + "px";
  328. }
  329. }
  330. */
  331. }
  332. function viz_save() {
  333. // let cookie survive a month
  334. var exp = new Date();
  335. exp.setTime(exp.getTime() + 2592000000);
  336. // save node positions
  337. for (var ip in nodes) {
  338. if (nodes[ip].metric > maxmetric) {
  339. continue;
  340. }
  341. // setCookie("node_"+ip,nodes[ip].x+"x"+nodes[ip].y,exp);
  342. }
  343. // save maxmetric
  344. setCookie("prefs_maxmetric", maxmetric, exp);
  345. // save zooming
  346. setCookie("prefs_scale", scale, exp);
  347. // save scroll - FIXME
  348. setCookie("prefs_innerview",
  349. parseInt(mainDiv.scrollLeft) + "x" + parseInt(mainDiv.scrollTop) + "x" +
  350. parseInt(vwidth * scale) + "x" + parseInt(vheight * scale), exp);
  351. }
  352. function viz_autosave(autosave) {
  353. auto_save = autosave;
  354. if (auto_save) {
  355. document.body.onunload = viz_save;
  356. }
  357. else {
  358. deleteCookie("prefs_autosave");
  359. }
  360. }
  361. function viz_reset() {
  362. deleteAllCookies();
  363. for (var ip in nodes) {
  364. delete nodes[ip];
  365. }
  366. for (var e in edges) {
  367. delete edges[e];
  368. }
  369. window.location.reload();
  370. }
  371. var updateTimer = 0;
  372. function viz_update() {
  373. if (updateTimer) {
  374. clearTimeout(updateTimer);
  375. }
  376. now_secs = new Date().getTime() / 1000;
  377. }
  378. function viz_callback() {
  379. if (updateTimer) {
  380. clearTimeout(updateTimer);
  381. }
  382. if (place_new_nodes() > 0 && auto_declump) {
  383. declump();
  384. }
  385. refresh();
  386. updateTimer = setTimeout('viz_update()', 5000);
  387. }
  388. var refresh_running = false;
  389. function refresh() {
  390. if (refresh_running) {
  391. return;
  392. }
  393. refresh_running = true;
  394. var nh = "";
  395. // refresh nodes
  396. nh = "";
  397. for (var n in nodes) {
  398. if (nodes[n].isDead()) {
  399. nodes[n].cleanup();
  400. delete nodes[n];
  401. }
  402. else {
  403. nh += nodes[n].getHTML();
  404. }
  405. }
  406. nodeDiv.innerHTML = nh;
  407. // refresh edges
  408. nh = "";
  409. for (var e in edges) {
  410. if (edges[e].isDead()) {
  411. edges[e].cleanup();
  412. delete edges[e];
  413. }
  414. else {
  415. nh += edges[e].getHTML();
  416. }
  417. }
  418. edgeDiv.innerHTML = nh;
  419. refresh_running = false;
  420. }
  421. function set_showdesc(doit) {
  422. showdesc = doit;
  423. if (!noupdate) refresh();
  424. }
  425. function set_autodeclump(doit) {
  426. auto_declump = doit;
  427. if (doit) {
  428. declump();
  429. }
  430. else {
  431. clearTimeout(dclTimer);
  432. }
  433. }
  434. function set_scale(inscale, noupdate) {
  435. if (!inscale) {
  436. inscale = parseFloat(zoomInput.value / 2);
  437. }
  438. scale = Math.round(inscale * 100) / 100;
  439. if (!scale || scale < 0.1) {
  440. scale = 0.1;
  441. }
  442. zoomInput.value = scale * 2;
  443. if (!noupdate) refresh();
  444. }
  445. function set_maxmetric(inmetric, noupdate, noconfirm) {
  446. inmetric = parseInt(inmetric);
  447. 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?")) {
  448. maxmetric = inmetric;
  449. }
  450. maxmetricInput.value = maxmetric;
  451. if (!noupdate) refresh();
  452. }
  453. // k = area / nodes
  454. function fr(x) {
  455. return Math.pow((iel * iel) / x, 2);
  456. }
  457. function fa(x) {
  458. return Math.pow((x * x) / iel, 2);
  459. }
  460. var dclTimer = 0;
  461. var declump_running = false;
  462. function declump(t) {
  463. var dx;
  464. var dy;
  465. var d;
  466. // clear declump timer
  467. if (dclTimer) {
  468. clearTimeout(dclTimer);
  469. }
  470. if (declump_running) {
  471. return;
  472. }
  473. declump_running = true;
  474. // nodes
  475. var nc = 0;
  476. for (var ip1 in nodes) {
  477. nodes[ip1].fr_x = 0;
  478. nodes[ip1].fr_y = 0;
  479. nodes[ip1].fa_x = 0;
  480. nodes[ip1].fa_y = 0;
  481. nodes[ip1].x_next = nodes[ip1].x;
  482. nodes[ip1].y_next = nodes[ip1].y;
  483. nodes[ip1].randdisplace = 0;
  484. }
  485. for (var ip1 in nodes) {
  486. if (nodes[ip1].metric > maxmetric || nodes[ip1].pinned) {
  487. continue;
  488. }
  489. for (var ip2 in nodes) {
  490. if (nodes[ip2].metric > maxmetric || ip1 == ip2) {
  491. continue;
  492. }
  493. dx = (nodes[ip1].x_next - nodes[ip2].x_next);
  494. dy = (nodes[ip1].y_next - nodes[ip2].y_next);
  495. d = Math.sqrt(dx * dx + dy * dy);
  496. d = Math.max(d - optsize, (d + optsize) / optsize);
  497. nodes[ip1].fr_x += (dx / d) * fr(d);
  498. nodes[ip1].fr_y += (dy / d) * fr(d);
  499. }
  500. dx = nodes[ip1].fr_x;
  501. dy = nodes[ip1].fr_y;
  502. d = Math.sqrt(dx * dx + dy * dy);
  503. var md = Math.min(d, iel / nodes[ip1].weight);
  504. nodes[ip1].x_next += (dx / d) * md;
  505. nodes[ip1].y_next += (dy / d) * md;
  506. nc++;
  507. }
  508. // edges
  509. var ec = 0;
  510. for (var e in edges) {
  511. if (!edges[e].n1 || !edges[e].n2 ||
  512. edges[e].n1.metric > maxmetric || edges[e].n2.metric > maxmetric) {
  513. continue;
  514. }
  515. dx = (edges[e].n1.x_next - edges[e].n2.x_next);
  516. dy = (edges[e].n1.y_next - edges[e].n2.y_next);
  517. d = Math.sqrt(dx * dx + dy * dy);
  518. // d = Math.max(d-optsize,(d+optsize)/optsize);
  519. edges[e].n1.fa_x -= (dx / d) * fa(d);
  520. edges[e].n1.fa_y -= (dy / d) * fa(d);
  521. edges[e].n2.fa_x += (dx / d) * fa(d);
  522. edges[e].n2.fa_y += (dy / d) * fa(d);
  523. ec++;
  524. }
  525. // displacement
  526. var xmin = -20;
  527. var ymin = -20;
  528. var xmax = 20;
  529. var ymax = 20;
  530. var dsum = 0;
  531. for (var ip in nodes) {
  532. if (nodes[ip].metric > maxmetric || nodes[ip].pinned) {
  533. continue;
  534. }
  535. dx = nodes[ip].fa_x;
  536. dy = nodes[ip].fa_y;
  537. d = Math.sqrt(dx * dx + dy * dy);
  538. dx = (dx / d) * Math.min(d, iel / nodes[ip].weight) * 0.75 + nodes[ip].dx_last * 0.25;
  539. dy = (dy / d) * Math.min(d, iel / nodes[ip].weight) * 0.75 + nodes[ip].dy_last * 0.25;
  540. nodes[ip].dx_last = dx;
  541. nodes[ip].dy_last = dy;
  542. nodes[ip].x_next += dx;
  543. nodes[ip].y_next += dy;
  544. if (!nodes[ip].x_next || !nodes[ip].y_next) {
  545. continue;
  546. }
  547. dx = (nodes[ip].x - nodes[ip].x_next);
  548. dy = (nodes[ip].y - nodes[ip].y_next);
  549. dsum += Math.sqrt(dx * dx + dy * dy);
  550. nodes[ip].x = nodes[ip].x_next;
  551. nodes[ip].y = nodes[ip].y_next;
  552. xmin = Math.min(xmin, nodes[ip].x);
  553. xmax = Math.max(xmax, nodes[ip].x);
  554. ymin = Math.min(ymin, nodes[ip].y);
  555. ymax = Math.max(ymax, nodes[ip].y);
  556. }
  557. vwidth = (xmax - xmin);
  558. vheight = (ymax - ymin);
  559. xoff = -xmin;
  560. yoff = -ymin;
  561. /*
  562. document.getElementById('debug').innerHTML = "<br />" +
  563. "offset: " + xoff + "x" + yoff + " dsum: " + dsum + "<br />" +
  564. "nc: " + nc + " ec: " + ec + "xmax: " + xmax + " xmin: " + xmin + "<br />" +
  565. "optsize: " + optsize + "<br />";
  566. */
  567. refresh();
  568. if (auto_declump) {
  569. dclTimer = setTimeout("declump()", dsum > ncount ? dcl_timeout : dcllow_timeout);
  570. }
  571. declump_running = false;
  572. }
  573. //Das Objekt, das gerade bewegt wird.
  574. var dragip = null;
  575. // Position, an der das Objekt angeklickt wurde.
  576. var dragx = 0;
  577. var dragy = 0;
  578. // Mausposition
  579. var posx = 0;
  580. var posy = 0;
  581. function draginit() {
  582. // Initialisierung der ãberwachung der Events
  583. document.onmousemove = drag;
  584. document.onmouseup = dragstop;
  585. }
  586. function dragstart(element) {
  587. //Wird aufgerufen, wenn ein Objekt bewegt werden soll.
  588. dragip = element.id.split("_")[1];
  589. dragx = posx - element.offsetLeft;
  590. dragy = posy - element.offsetTop;
  591. var n = nodes[dragip];
  592. if (n) {
  593. n.pinned = true;
  594. }
  595. }
  596. function dragstop() {
  597. //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
  598. var n = nodes[dragip];
  599. if (n) {
  600. n.pinned = false;
  601. }
  602. refresh();
  603. dragip = null;
  604. }
  605. function drag(ereignis) {
  606. //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.
  607. posx = document.all ? window.event.clientX : ereignis.pageX;
  608. posy = document.all ? window.event.clientY : ereignis.pageY;
  609. if (dragip != null) {
  610. var n = nodes[dragip];
  611. if (n) {
  612. n.x = (posx - dragx) / scale - xoff;
  613. n.y = (posy - dragy) / scale - yoff;
  614. }
  615. var e = document.getElementById('node_' + dragip);
  616. e.style.left = parseInt((n.x + xoff) * scale) + "px";
  617. e.style.top = parseInt((n.y + yoff) * scale) + "px";
  618. }
  619. }
  620. function debug_writeln(line) {
  621. debugSpan.innerHTML = line + "<br />" + debugSpan.innerHTML;
  622. }
  623. /**
  624. * Sets a Cookie with the given name and value.
  625. *
  626. * name Name of the cookie
  627. * value Value of the cookie
  628. * [expires] Expiration date of the cookie (default: end of current session)
  629. * [path] Path where the cookie is valid (default: path of calling document)
  630. * [domain] Domain where the cookie is valid
  631. * (default: domain of calling document)
  632. * [secure] Boolean value indicating if the cookie transmission requires a
  633. * secure transmission
  634. */
  635. function setCookie(name, value, expires, path, domain, secure) {
  636. document.cookie = name + "=" + escape(value) +
  637. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  638. ((path) ? "; path=" + path : "") +
  639. ((domain) ? "; domain=" + domain : "") +
  640. ((secure) ? "; secure" : "");
  641. }
  642. /**
  643. * Gets the value of the specified cookie.
  644. *
  645. * name Name of the desired cookie.
  646. *
  647. * Returns a string containing value of specified cookie,
  648. * or null if cookie does not exist.
  649. */
  650. function getCookie(name) {
  651. var results = document.cookie.match(name + '=(.*?)(;|$)');
  652. if (results) {
  653. return unescape(results[1]);
  654. }
  655. return null;
  656. }
  657. /**
  658. * Deletes the specified cookie.
  659. *
  660. * name name of the cookie
  661. * [path] path of the cookie (must be same as path used to create cookie)
  662. * [domain] domain of the cookie (must be same as domain used to create cookie)
  663. */
  664. function deleteCookie(name, path, domain) {
  665. if (getCookie(name)) {
  666. document.cookie = name + "=" +
  667. ((path) ? "; path=" + path : "") +
  668. ((domain) ? "; domain=" + domain : "") +
  669. "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  670. }
  671. }
  672. function deleteAllCookies() {
  673. var cookies = document.cookie.split("; ");
  674. for (var i = 0; i < cookies.length; i++) {
  675. deleteCookie(cookies[i].split("=")[0]);
  676. }
  677. }