/hobbit/web/zoom.js

http://github.com/brinkman83/bashrc · JavaScript · 712 lines · 442 code · 145 blank · 125 comment · 96 complexity · 3b454d1473e4ce17b76d31102f83e5e8 MD5 · raw file

  1. <script type="text/javascript">
  2. <!--
  3. /*
  4. This code was taken from the "Cacti" project by Henrik Storner, and
  5. modified slightly for use with the "Hobbit" monitor project
  6. (see hobbitmon.sourceforge.net)
  7. The original copyright notice follows.
  8. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  9. + Bonsai: A more user friendly zoom function for Cacti +
  10. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11. + Copyright (C) 2004 Eric Steffen +
  12. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  13. + This program is free software; you can redistribute it and/or +
  14. + modify it under the terms of the GNU General Public License +
  15. + as published by the Free Software Foundation; either version 2 +
  16. + of the License, or (at your option) any later version. +
  17. + +
  18. + This program is distributed in the hope that it will be useful, +
  19. + but WITHOUT ANY WARRANTY; without even the implied warranty of +
  20. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
  21. + GNU General Public License for more details. +
  22. + +
  23. + You should have received a copy of the GNU General Public License +
  24. + along with this program; if not, write to the Free Software +
  25. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +
  26. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  27. + email : eric.steffen@gmx.net +
  28. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  29. zoom.js version 0.4
  30. */
  31. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  32. // Global constant
  33. var cURLBase = "hobbitgraph.sh?action=selzoom&graph=custom";
  34. // Global variables
  35. var gZoomGraphName = "zoomGraphImage";
  36. var gZoomGraphObj;
  37. var gMouseObj;
  38. var gUrlObj;
  39. var gBrowserObj;
  40. // Objects declaration
  41. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  42. /*++++++++++++++++++++++++++++++++ urlObj +++++++++++++++++++++++++++++++++*/
  43. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  44. function urlObj(url) {
  45. var urlBaseAndParameters;
  46. urlBaseAndParameters = url.split("?");
  47. this.urlBase = urlBaseAndParameters[0];
  48. this.urlParameters = urlBaseAndParameters[1].split("&");
  49. this.getUrlBase = urlObjGetUrlBase;
  50. this.getUrlParameterValue = urlObjGetUrlParameterValue;
  51. }
  52. /*++++++++++++++++++++++++ urlObjGetUrlBase +++++++++++++++++++++++++++++++*/
  53. function urlObjGetUrlBase() {
  54. return this.urlBase;
  55. }
  56. /*++++++++++++++++++++ urlObjGetUrlParameterValue +++++++++++++++++++++++++*/
  57. function urlObjGetUrlParameterValue(parameter) {
  58. var i;
  59. var fieldAndValue;
  60. var value;
  61. i = 0;
  62. while (this.urlParameters [i] != undefined) {
  63. fieldAndValue = this.urlParameters[i].split("=");
  64. if (fieldAndValue[0] == parameter) {
  65. value = fieldAndValue[1];
  66. }
  67. i++;
  68. }
  69. return value;
  70. }
  71. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  72. /*+++++++++++++++++++++++++++++++ mouseObj ++++++++++++++++++++++++++++++++*/
  73. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  74. function mouseObj() {
  75. this.startedX = 0;
  76. this.startedY = 0;
  77. this.stoppedX = 0;
  78. this.stoppedY = 0;
  79. this.currentX = 0;
  80. this.currentY = 0;
  81. this.dragging = false;
  82. this.setEvent = mouseObjSetEvent;
  83. this.leftButtonPressed = mouseObjLeftButtonPressed;
  84. this.rightButtonPressed = mouseObjRightButtonPressed;
  85. this.getCurrentPosition = mouseObjGetCurrentPosition;
  86. this.saveCurrentToStartPosition = mouseObjSaveCurrentToStartPosition;
  87. this.saveCurrentToStopPosition = mouseObjSaveCurrentToStopPosition;
  88. }
  89. /*++++++++++++++++++++++++ mouseObjSetEvent +++++++++++++++++++++++++++++++*/
  90. function mouseObjSetEvent(theEvent) {
  91. if (gBrowserObj.browser == "Netscape") {
  92. this.event = theEvent;
  93. } else {
  94. this.event = window.event;
  95. }
  96. }
  97. /*++++++++++++++++++++++++ mouseObjLeftMouseButton +++++++++++++++++++++++++++++++*/
  98. function mouseObjLeftButtonPressed() {
  99. var LeftButtonPressed = false;
  100. //alert ("Button Pressed");
  101. if (gBrowserObj.browser == "Netscape") {
  102. LeftButtonPressed = (this.event.which == 1);
  103. //alert ("Net");
  104. } else {
  105. LeftButtonPressed = (this.event.button == 1);
  106. }
  107. return LeftButtonPressed;
  108. }
  109. /*++++++++++++++++++++++++ mouseObjRightMouseButton +++++++++++++++++++++++++++++++*/
  110. function mouseObjRightButtonPressed() {
  111. var RightButtonPressed = false;
  112. //alert ("Button Pressed");
  113. if (gBrowserObj.browser == "Netscape") {
  114. RightButtonPressed = (this.event.which == 3);
  115. //alert ("Net");
  116. } else {
  117. RightButtonPressed = (this.event.button == 2);
  118. }
  119. return RightButtonPressed;
  120. }
  121. /*+++++++++++++++++++ mouseObjGetCurrentPosition ++++++++++++++++++++++++++*/
  122. function mouseObjGetCurrentPosition() {
  123. this.currentX = this.event.clientX + document.body.scrollLeft;
  124. this.currentY = this.event.clientY + document.body.scrollTop;
  125. // alert (this.currentX + "\n" + this.currentY);
  126. }
  127. /*+++++++++++++++++ mouseObjSaveCurrentToStartPosition ++++++++++++++++++++*/
  128. function mouseObjSaveCurrentToStartPosition() {
  129. this.startedX = this.currentX;
  130. this.startedY = this.currentY;
  131. }
  132. /*++++++++++++++++++ mouseObjSaveCurrentToStopPosition ++++++++++++++++++++*/
  133. function mouseObjSaveCurrentToStopPosition() {
  134. this.stoppedX = this.currentX;
  135. this.stoppedY = this.currentY;
  136. }
  137. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  138. /*+++++++++++++++++++++++++++++ zoomGraphObj ++++++++++++++++++++++++++++++*/
  139. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  140. function zoomGraphObj(zoomGraphName) {
  141. // We use 3 zones. The first (zoomGraph) represent the entire graph image.
  142. // The second (zoomBox) represent the graph itself.
  143. // The last zone (zoomSensitiveZone) represent the area where the user can
  144. // launch the zoom function
  145. this.zoomGraphName = zoomGraphName;
  146. this.imgObject = document.getElementById(this.zoomGraphName);
  147. gUrlObj = new urlObj(this.imgObject.src);
  148. this.zoomGraphLeft = 0;
  149. this.zoomGraphTop = 0;
  150. this.zoomGraphRight = 0;
  151. this.zoomGraphBottom = 0;
  152. this.zoomGraphWidth = 0;
  153. this.zoomGraphHeight = 0;
  154. this.zoomBoxLeft = 0;
  155. this.zoomBoxTop = 0;
  156. this.zoomBoxRight = 0;
  157. this.zoomBoxBottom = 0;
  158. this.zoomBoxWidth = 0;
  159. this.zoomBoxHeight = 0;
  160. this.zoomSensitiveZoneLeft = 0;
  161. this.zoomSensitiveZoneTop = 0;
  162. this.zoomSensitiveZoneRight = 0;
  163. this.zoomSensitiveZoneBottom = 0;
  164. this.zoomSensitiveZoneWith = 0;
  165. this.zoomSensitiveZoneHeight = 0;
  166. this.refresh = zoomGraphObjRefresh;
  167. this.drawSelection = zoomGraphObjDrawSelection;
  168. this.refresh();
  169. }
  170. /*+++++++++++++++++++++++++++ zoomGraphObjRefresh +++++++++++++++++++++++++*/
  171. function zoomGraphObjRefresh() {
  172. // Constants
  173. var cZoomBoxName = "zoomBox";
  174. // Distance from top edge of image to top of graph
  175. var cZoomBoxTopOffsetWOText = 17 - 1; // With no text (was: 15)
  176. var cZoomBoxTopOffsetWText = 34 - 1; // With text (was: 17)
  177. // Distance from right edge of image to right edge of graph
  178. var cZoomBoxRightOffset = -16;
  179. var cZoomSensitiveZoneName = "zoomSensitiveZone";
  180. var cZoomSensitiveZoneOffset = 12;
  181. // Variables
  182. var imgObject;
  183. // var imgSource;
  184. var imgAlt;
  185. var divObject;
  186. var left;
  187. var top;
  188. var width;
  189. var height;
  190. var zoomBoxWidth;
  191. var zoomBoxHeight;
  192. imgObject = this.imgObject;
  193. //imgSource = imgObject.src;
  194. imgAlt = imgObject.alt;
  195. width = imgObject.width;
  196. height = imgObject.height;
  197. zoomBoxWidth = parseInt(gUrlObj.getUrlParameterValue("graph_width")) + 1;
  198. zoomBoxHeight = parseInt(gUrlObj.getUrlParameterValue("graph_height")) + 1;
  199. // Get absolute graph position
  200. // start with the image's coordinates and walk through it's
  201. // ancestory of elements (tables, div's, spans, etc...) until
  202. // we're at the top. Along the way we add in each element's
  203. // coordinates to get the final answer
  204. left = 0;
  205. top = 0;
  206. do
  207. {
  208. left += imgObject.offsetLeft;
  209. top += imgObject.offsetTop;
  210. imgObject = imgObject.offsetParent;
  211. }
  212. while(imgObject);
  213. this.zoomGraphLeft = left;
  214. this.zoomGraphTop = top;
  215. this.zoomGraphRight = left + width;
  216. this.zoomGraphBottom = top + height;
  217. this.zoomGraphWidth = width;
  218. this.zoomGraphHeight = height;
  219. this.zoomBoxRight = this.zoomGraphRight + cZoomBoxRightOffset;
  220. if(imgAlt == "") {
  221. this.zoomBoxTop = this.zoomGraphTop + cZoomBoxTopOffsetWOText;
  222. }
  223. else {
  224. this.zoomBoxTop = this.zoomGraphTop + cZoomBoxTopOffsetWText;
  225. }
  226. this.zoomBoxLeft = this.zoomBoxRight - zoomBoxWidth;
  227. this.zoomBoxBottom = this.zoomBoxTop + zoomBoxHeight;
  228. this.zoomBoxWidth = zoomBoxWidth;
  229. this.zoomBoxHeight = zoomBoxHeight;
  230. // this.drawSelection(this.zoomBoxLeft, this.zoomBoxTop, this.zoomBoxRight, this.zoomBoxBottom);
  231. this.drawSelection(0, 0, 0, 0); // reset selection
  232. divObject = document.getElementById(cZoomBoxName);
  233. divObject.style.left = this.zoomBoxLeft;
  234. divObject.style.top = this.zoomBoxTop;
  235. divObject.style.width = this.zoomBoxWidth;
  236. divObject.style.height = this.zoomBoxHeight;
  237. this.zoomSensitiveZoneLeft = this.zoomBoxLeft - cZoomSensitiveZoneOffset;
  238. this.zoomSensitiveZoneTop = this.zoomBoxTop - cZoomSensitiveZoneOffset;
  239. this.zoomSensitiveZoneRight = this.zoomBoxRight + cZoomSensitiveZoneOffset;
  240. this.zoomSensitiveZoneBottom = this.zoomBoxBottom + cZoomSensitiveZoneOffset;
  241. this.zoomSensitiveZoneWidth = this.zoomSensitiveZoneRight - this.zoomSensitiveZoneLeft;
  242. this.zoomSensitiveZoneHeight = this.zoomSensitiveZoneBottom - this.zoomSensitiveZoneTop;
  243. divObject = document.getElementById(cZoomSensitiveZoneName);
  244. divObject.style.left = this.zoomSensitiveZoneLeft;
  245. divObject.style.top = this.zoomSensitiveZoneTop;
  246. divObject.style.width = this.zoomSensitiveZoneWidth;
  247. divObject.style.height = this.zoomSensitiveZoneHeight;
  248. }
  249. /*++++++++++++++++++++++ zoomGraphObjDrawSelection ++++++++++++++++++++++++*/
  250. function zoomGraphObjDrawSelection (x1, y1, x2, y2) {
  251. var cZoomBoxName = "zoomBox";
  252. var divObject;
  253. // Calculate relative to zoomBox
  254. x1 = x1 - this.zoomBoxLeft;
  255. x2 = x2 - this.zoomBoxLeft;
  256. y1 = y1 - this.zoomBoxTop;
  257. y2 = y2 - this.zoomBoxTop;
  258. var minX = Math.min(x1, x2);
  259. var maxX = Math.max(x1, x2) + 1;
  260. var minY = Math.min(y1, y2);
  261. var maxY = Math.max(y1, y2) + 1;
  262. divObject = document.getElementById(cZoomBoxName);
  263. divObject.style.clip ="rect(" + minY + "px " + maxX + "px " + maxY + "px " + minX + "px)";
  264. }
  265. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  266. /*++++++++++++++++++++ standard functions definition ++++++++++++++++++++++*/
  267. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  268. /*
  269. BrowserDetector()
  270. Parses User-Agent string into useful info.
  271. Source: Webmonkey Code Library
  272. (http://www.hotwired.com/webmonkey/javascript/code_library/)
  273. Author: Richard Blaylock
  274. Author Email: blaylock@wired.com
  275. Usage: var bd = new BrowserDetector(navigator.userAgent);
  276. */
  277. // Utility function to trim spaces from both ends of a string
  278. function Trim(inString) {
  279. var retVal = "";
  280. var start = 0;
  281. while ((start < inString.length) && (inString.charAt(start) == ' ')) {
  282. ++start;
  283. }
  284. var end = inString.length;
  285. while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
  286. --end;
  287. }
  288. retVal = inString.substring(start, end);
  289. return retVal;
  290. }
  291. function BrowserDetector(ua) {
  292. // Defaults
  293. this.browser = "Unknown";
  294. this.platform = "Unknown";
  295. this.version = "";
  296. this.majorver = "";
  297. this.minorver = "";
  298. uaLen = ua.length;
  299. // ##### Split into stuff before parens and stuff in parens
  300. var preparens = "";
  301. var parenthesized = "";
  302. i = ua.indexOf("(");
  303. if (i >= 0) {
  304. preparens = Trim(ua.substring(0,i));
  305. parenthesized = ua.substring(i+1, uaLen);
  306. j = parenthesized.indexOf(")");
  307. if (j >= 0) {
  308. parenthesized = parenthesized.substring(0, j);
  309. }
  310. }
  311. else {
  312. preparens = ua;
  313. }
  314. // ##### First assume browser and version are in preparens
  315. // ##### override later if we find them in the parenthesized stuff
  316. var browVer = preparens;
  317. var tokens = parenthesized.split(";");
  318. var token = "";
  319. // # Now go through parenthesized tokens
  320. for (var i=0; i < tokens.length; i++) {
  321. token = Trim(tokens[i]);
  322. //## compatible - might want to reset from Netscape
  323. if (token == "compatible") {
  324. //## One might want to reset browVer to a null string
  325. //## here, but instead, we'll assume that if we don't
  326. //## find out otherwise, then it really is Mozilla
  327. //## (or whatever showed up before the parens).
  328. //## browser - try for Opera or IE
  329. }
  330. else if (token.indexOf("MSIE") >= 0) {
  331. browVer = token;
  332. }
  333. else if (token.indexOf("Opera") >= 0) {
  334. browVer = token;
  335. }
  336. //'## platform - try for X11, SunOS, Win, Mac, PPC
  337. else if ((token.indexOf("X11") >= 0) || (token.indexOf("SunOS") >= 0) ||
  338. (token.indexOf("Linux") >= 0)) {
  339. this.platform = "Unix";
  340. }
  341. else if (token.indexOf("Win") >= 0) {
  342. this.platform = token;
  343. }
  344. else if ((token.indexOf("Mac") >= 0) || (token.indexOf("PPC") >= 0)) {
  345. this.platform = token;
  346. }
  347. }
  348. var msieIndex = browVer.indexOf("MSIE");
  349. if (msieIndex >= 0) {
  350. browVer = browVer.substring(msieIndex, browVer.length);
  351. }
  352. var leftover = "";
  353. if (browVer.substring(0, "Mozilla".length) == "Mozilla") {
  354. this.browser = "Netscape";
  355. leftover = browVer.substring("Mozilla".length+1, browVer.length);
  356. }
  357. else if (browVer.substring(0, "Lynx".length) == "Lynx") {
  358. this.browser = "Lynx";
  359. leftover = browVer.substring("Lynx".length+1, browVer.length);
  360. }
  361. else if (browVer.substring(0, "MSIE".length) == "MSIE") {
  362. this.browser = "IE";
  363. leftover = browVer.substring("MSIE".length+1, browVer.length);
  364. }
  365. else if (browVer.substring(0, "Microsoft Internet Explorer".length) ==
  366. "Microsoft Internet Explorer") {
  367. this.browser = "IE"
  368. leftover = browVer.substring("Microsoft Internet Explorer".length+1,
  369. browVer.length);
  370. }
  371. else if (browVer.substring(0, "Opera".length) == "Opera") {
  372. this.browser = "Opera"
  373. leftover = browVer.substring("Opera".length+1, browVer.length);
  374. }
  375. leftover = Trim(leftover);
  376. // # Try to get version info out of leftover stuff
  377. i = leftover.indexOf(" ");
  378. if (i >= 0) {
  379. this.version = leftover.substring(0, i);
  380. }
  381. else
  382. {
  383. this.version = leftover;
  384. }
  385. j = this.version.indexOf(".");
  386. if (j >= 0) {
  387. this.majorver = this.version.substring(0,j);
  388. this.minorver = this.version.substring(j+1, this.version.length);
  389. }
  390. else {
  391. this.majorver = this.version;
  392. }
  393. } // function BrowserCap
  394. /*++++++++++++++++++++++++++ initBonsai ++++++++++++++++++++++++++*/
  395. function initBonsai() {
  396. gBrowserObj = new BrowserDetector(navigator.userAgent);
  397. //alert("Browser: " + gBrowserObj.browser + "\nPlatform: " + gBrowserObj.platform + "\nVersion: " + gBrowserObj.version + "\nMajorVer: " + gBrowserObj.majorver + "\nMinorVer: " + gBrowserObj.minorver);
  398. /* gUrlObj = new urlObj(document.URL);*/
  399. gZoomGraphObj = new zoomGraphObj(gZoomGraphName);
  400. gMouseObj = new mouseObj();
  401. initEvents();
  402. }
  403. /*+++++++++++++++++++++++++++ insideZoomBox +++++++++++++++++++++++++++++++*/
  404. function insideZoomBox() {
  405. var szLeft = gZoomGraphObj.zoomSensitiveZoneLeft;
  406. var szTop = gZoomGraphObj.zoomSensitiveZoneTop;
  407. var szRight = gZoomGraphObj.zoomSensitiveZoneRight;
  408. var szBottom = gZoomGraphObj.zoomSensitiveZoneBottom;
  409. var mpX = gMouseObj.currentX;
  410. var mpY = gMouseObj.currentY;
  411. return ((mpX >= szLeft) && (mpX <= szRight) && (mpY >= szTop) && (mpY <= szBottom));
  412. }
  413. /*++++++++++++++++++++++++++++ initEvents +++++++++++++++++++++++++++++++++*/
  414. function initEvents() {
  415. document.onmousemove = onMouseMouveEvent;
  416. document.onmousedown = onMouseDownEvent;
  417. document.onmouseup = onMouseUpEvent;
  418. window.onresize = windowOnResizeEvent;
  419. if (gBrowserObj.browser == "Netscape") {
  420. document.captureEvents(Event.MOUSEMOVE);
  421. document.captureEvents(Event.MOUSEDOWN);
  422. document.captureEvents(Event.MOUSEUP);
  423. }
  424. }
  425. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  426. /*+++++++++++++++++++++ events functions definition +++++++++++++++++++++++*/
  427. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  428. /*+++++++++++++++++++++++++++ onMouseDownEvent ++++++++++++++++++++++++++++*/
  429. function onMouseDownEvent(e) {
  430. gMouseObj.setEvent(e);
  431. gMouseObj.getCurrentPosition();
  432. if (insideZoomBox()) {
  433. if ((gMouseObj.leftButtonPressed()) && (!gMouseObj.dragging)) {
  434. gMouseObj.dragging = true;
  435. gMouseObj.saveCurrentToStartPosition();
  436. gZoomGraphObj.drawSelection(gMouseObj.currentX, gMouseObj.currentY, gMouseObj.currentX, gMouseObj.currentY);
  437. } else if (gMouseObj.rightButtonPressed()) {
  438. var test = true;
  439. }
  440. }
  441. }
  442. /*+++++++++++++++++++++++++++ onMouseMouveEvent +++++++++++++++++++++++++++*/
  443. function onMouseMouveEvent(e) {
  444. gMouseObj.setEvent(e);
  445. if (gMouseObj.dragging) {
  446. gMouseObj.getCurrentPosition();
  447. gZoomGraphObj.drawSelection(gMouseObj.startedX, gMouseObj.startedY, gMouseObj.currentX, gMouseObj.currentY);
  448. }
  449. }
  450. /*+++++++++++++++++++++++++++++ onMouseUpEvent ++++++++++++++++++++++++++++*/
  451. function onMouseUpEvent(e) {
  452. var graphStart;
  453. var graphEnd;
  454. var graphTop;
  455. var graphBottom;
  456. var haveGraphLimits;
  457. var newGraphStart;
  458. var newGraphEnd;
  459. var newGraphTop;
  460. var newGraphBottom;
  461. var idxStr;
  462. var countStr;
  463. gMouseObj.setEvent(e);
  464. graphStart = parseInt(gUrlObj.getUrlParameterValue("graph_start"));
  465. graphEnd = parseInt(gUrlObj.getUrlParameterValue("graph_end"));
  466. graphTop = parseInt(gUrlObj.getUrlParameterValue("upper"));
  467. graphBottom = parseInt(gUrlObj.getUrlParameterValue("lower"));
  468. haveGraphLimits = (gUrlObj.getUrlParameterValue("upper") != undefined) && (gUrlObj.getUrlParameterValue("lower") != undefined);
  469. idxStr = "";
  470. countStr = "";
  471. if ((gMouseObj.rightButtonPressed()) && (insideZoomBox())) {
  472. // This causes a zoom-out event. We dont care about Y-axis zooming here.
  473. var Timespan = graphEnd - graphStart;
  474. gMouseObj.dragging = false;
  475. newGraphEnd = graphEnd + Timespan * 2;
  476. newGraphStart = graphStart - Timespan * 2;
  477. var urlBase = cURLBase;
  478. var host = gUrlObj.getUrlParameterValue("host");
  479. var service = gUrlObj.getUrlParameterValue("service");
  480. var dispName = gUrlObj.getUrlParameterValue("disp");
  481. var firstIdx = gUrlObj.getUrlParameterValue("first");
  482. var idxCount = gUrlObj.getUrlParameterValue("count");
  483. var graphWidth = gUrlObj.getUrlParameterValue("graph_width");
  484. var graphHeight = gUrlObj.getUrlParameterValue("graph_height");
  485. var bgColor = gUrlObj.getUrlParameterValue("color");
  486. if (firstIdx != "") {
  487. idxStr = "&first=" + firstIdx;
  488. }
  489. if (idxCount != "") {
  490. countStr = "&count=" + idxCount;
  491. }
  492. open(urlBase + "&host=" + host + "&service=" + service + "&disp=" + dispName + idxStr + countStr + "&graph_start=" + newGraphStart + "&graph_end=" + newGraphEnd + "&graph_height=" + graphHeight + "&graph_width=" + graphWidth + "&color=" + bgColor, "_self");
  493. }
  494. if ((gMouseObj.leftButtonPressed()) && (gMouseObj.dragging)) {
  495. // This is the zoom-to-the-selection-box handling
  496. gMouseObj.getCurrentPosition();
  497. gMouseObj.saveCurrentToStopPosition();
  498. gMouseObj.dragging = false;
  499. var x1 = gMouseObj.startedX - gZoomGraphObj.zoomBoxLeft;
  500. var x2 = gMouseObj.stoppedX - gZoomGraphObj.zoomBoxLeft;
  501. var y1 = gMouseObj.startedY - gZoomGraphObj.zoomBoxTop;
  502. var y2 = gMouseObj.stoppedY - gZoomGraphObj.zoomBoxTop;
  503. var minX = Math.min(x1, x2);
  504. var maxX = Math.max(x1, x2);
  505. var minY = Math.min(y1, y2);
  506. var maxY = Math.max(y1, y2);
  507. if (minX < 0) {
  508. minX = 0;
  509. }
  510. if (maxX > gZoomGraphObj.zoomBoxWidth) {
  511. maxX = gZoomGraphObj.zoomBoxWidth;
  512. }
  513. if (minY < 0) {
  514. minY = 0;
  515. }
  516. if (maxY > gZoomGraphObj.zoomBoxHeight) {
  517. maxY = gZoomGraphObj.zoomBoxHeight;
  518. }
  519. if ((minX != maxX) || (minY != maxY)) {
  520. var OnePixelX = (graphEnd - graphStart) / gZoomGraphObj.zoomBoxWidth; // Represent # of seconds for 1 pixel on the graph
  521. var newURL;
  522. newGraphEnd = Math.round(graphEnd - (gZoomGraphObj.zoomBoxWidth - maxX) * OnePixelX);
  523. newGraphStart = Math.round(graphStart + minX * OnePixelX);
  524. var urlBase = cURLBase;
  525. var host = gUrlObj.getUrlParameterValue("host");
  526. var service = gUrlObj.getUrlParameterValue("service");
  527. var dispName = gUrlObj.getUrlParameterValue("disp");
  528. var firstIdx = gUrlObj.getUrlParameterValue("first");
  529. var idxCount = gUrlObj.getUrlParameterValue("count");
  530. var graphWidth = gUrlObj.getUrlParameterValue("graph_width");
  531. var graphHeight = gUrlObj.getUrlParameterValue("graph_height");
  532. var bgColor = gUrlObj.getUrlParameterValue("color");
  533. if (firstIdx != "") {
  534. idxStr = "&first=" + firstIdx;
  535. }
  536. if (idxCount != "") {
  537. countStr = "&count=" + idxCount;
  538. }
  539. newURL = urlBase + "&host=" + host + "&service=" + service + "&disp=" + dispName + idxStr + countStr + "&graph_start=" + newGraphStart + "&graph_end=" + newGraphEnd + "&graph_height=" + graphHeight + "&graph_width=" + graphWidth + "&color=" + bgColor;
  540. if (haveGraphLimits) {
  541. var OnePixelY = (graphTop - graphBottom) / gZoomGraphObj.zoomBoxHeight; // Represent # of units on Y axis for 1 pixel on the graph
  542. newGraphTop = graphTop - minY * OnePixelY;
  543. newGraphBottom = graphBottom + (gZoomGraphObj.zoomBoxHeight - maxY) * OnePixelY;
  544. // alert("graphTop: " + graphTop + "\ngraphBottom: " + graphBottom + "\nBoxHeight: " + gZoomGraphObj.zoomBoxHeight + "\nminY: " + minY + "\nmaxY: " + maxY + "\nonePixelY: " + OnePixelY + "\nnewGraphTop:" + newGraphTop + "\nnewGraphBottom: " + newGraphBottom + "\n");
  545. newURL = newURL + "&upper=" + newGraphTop + "&lower=" + newGraphBottom;
  546. }
  547. open(newURL, "_self");
  548. }
  549. }
  550. }
  551. /*+++++++++++++++++++++++++++ windowOnResizeEvent +++++++++++++++++++++++++*/
  552. function windowOnResizeEvent() {
  553. gZoomGraphObj.refresh();
  554. }
  555. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  556. /*++++++++++++++++++++++++++++++ main script ++++++++++++++++++++++++++++++*/
  557. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
  558. window.onload = initBonsai;
  559. // end of script
  560. //-->
  561. </script>