PageRenderTime 182ms CodeModel.GetById 158ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 1ms

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