Author:   Lars Michelsen <[email protected]>
Date:     Mon Nov  5 19:21:29 2012 +0100
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Mon Nov  5 19:21:29 2012 +0100

Big performance improvment when rendering object in frontend after
adding the map zoom feature

---

 ChangeLog                               |    2 +
 share/frontend/nagvis-js/js/frontend.js |    8 +-
 share/frontend/nagvis-js/js/nagvis.js   |   92 ++++++++++++++++++-------------
 3 files changed, 60 insertions(+), 42 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index db4dcb4..babf050 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,8 @@ Core:
 Frontend:
   * Hiding rotations table on overview page when no rotations configured
   * Better handling of HTTP errors in ajax transactions
+  * Big performance improvment when rendering object in frontend after
+    adding the map zoom feature
   * Bugfix: Re-added "loading..." message on page redering
 
 Geomap
diff --git a/share/frontend/nagvis-js/js/frontend.js 
b/share/frontend/nagvis-js/js/frontend.js
index 125072d..670c40e 100644
--- a/share/frontend/nagvis-js/js/frontend.js
+++ b/share/frontend/nagvis-js/js/frontend.js
@@ -329,7 +329,6 @@ function getFileAgeParams(viewType, mapName) {
  */
 function getHoverUrls() {
     var aUrlParts = [];
-    var aTemplateObjects;
 
     // Loop all map objects to get the urls which need to be fetched
     for(var i in oMapObjects) {
@@ -345,13 +344,14 @@ function getHoverUrls() {
             aUrlParts.push('&url[]='+escapeUrlValues(i));
 
     // Get the needed templates via bulk request
-    aTemplateObjects = 
getBulkRequest(oGeneralProperties.path_server+'?mod=General&act=getHoverUrl',
-                                      aUrlParts, 
oWorkerProperties.worker_request_max_length, true);
+    var aTemplateObjects = 
getBulkRequest(oGeneralProperties.path_server+'?mod=General&act=getHoverUrl',
+                                          aUrlParts, 
oWorkerProperties.worker_request_max_length, true);
 
     // Set the code to global object oHoverUrls
     if(aTemplateObjects.length > 0)
         for(var i = 0, len = aTemplateObjects.length; i < len; i++)
             oHoverUrls[aTemplateObjects[i].url] = aTemplateObjects[i].code;
+    aTemplateObjects = null;
 }
 
 /**
@@ -1501,7 +1501,7 @@ function getOverviewProperties(mapName) {
  * Fetches all maps to be shown on the overview page
  */
 function getOverviewMaps() {
-    
getAsyncRequest(oGeneralProperties.path_server+'?mod=Overview&act=getOverviewMaps'
 + getViewParams(), 
+    
getAsyncRequest(oGeneralProperties.path_server+'?mod=Overview&act=getOverviewMaps'
 + getViewParams(),
                     false, parseOverviewMaps);
 }
 
diff --git a/share/frontend/nagvis-js/js/nagvis.js 
b/share/frontend/nagvis-js/js/nagvis.js
index 9da3a1d..a61349f 100644
--- a/share/frontend/nagvis-js/js/nagvis.js
+++ b/share/frontend/nagvis-js/js/nagvis.js
@@ -1267,22 +1267,65 @@ function scaleView() {
     sidebar = null;
 }
 
+var g_zoom_factor = null;
+function getZoomFactor() {
+    if(g_zoom_factor !== null)
+        return g_zoom_factor; // only compute once
+
+    var zoom = getViewParam('zoom');
+    if(zoom === null)
+        g_zoom_factor = 100;
+    else
+        g_zoom_factor = parseInt(zoom); 
+
+    return g_zoom_factor;
+}
+
+function isZoomed() {
+    return g_zoom_factor !== 100;
+}
+
 /**
  * Handles the zoom factor of the current view for a single integer which
  * might be a coordinate or a dimension of an object
  */
 function addZoomFactor(coord) {
-    var zoom = getViewParam('zoom');
-    if(zoom === null)
-        zoom = 100;
-    return parseInt(coord * parseInt(zoom) / 100);
+    return parseInt(coord * getZoomFactor() / 100);
 }
 
 function rmZoomFactor(coord) {
-    var zoom = getViewParam('zoom');
-    if(zoom === null)
-        zoom = 100;
-    return parseInt(coord / parseInt(zoom) * 100);
+    return parseInt(coord / getZoomFactor() * 100);
+}
+
+function zoomHandler(event) {
+    // Another IE specific thing: "this" points to the window element,
+    // not the raising object
+    if(this == window) {
+        var obj = img;
+    } else {
+        var obj = this;
+    }
+    
+    if(!obj)
+        return false;
+
+    // This can not be added directly to the object beacause the
+    // width/height is scaled in at least firefox automatically
+    //
+    // IE FAIL: Needs to be made visible during getting obj.width/height
+    // because IE can not tell us anything about the dimensions when
+    // the object is not visible
+    obj.style.display = 'block';
+    var width  = addZoomFactor(obj.width);
+    var height = addZoomFactor(obj.height);
+    obj.style.display = 'none';
+
+    obj.width  = width;
+    obj.height = height;
+    // Now really show the image
+    obj.style.display = 'block';
+    obj = null;
+
 }
 
 /**
@@ -1293,39 +1336,12 @@ function rmZoomFactor(coord) {
  * The '.src' attribute must be assigned afterwards
  */
 function addZoomHandler(oImage) {
+    if(!isZoomed())
+        return; // If not zoomed, no handler is needed
     oImage.style.display = 'none';
 
     var img = oImage;
-    addEvent(oImage, 'load', function(event) {
-        // Another IE specific thing: "this" points to the window element,
-        // not the raising object
-        if(this == window) {
-            var obj = img;
-        } else {
-            var obj = this;
-        }
-        
-        if(!obj)
-            return false;
-
-        // This can not be added directly to the object beacause the
-        // width/height is scaled in at least firefox automatically
-        //
-        // IE FAIL: Needs to be made visible during getting obj.width/height
-        // because IE can not tell us anything about the dimensions when
-        // the object is not visible
-        obj.style.display = 'block';
-        var width  = addZoomFactor(obj.width);
-        var height = addZoomFactor(obj.height);
-        obj.style.display = 'none';
-
-        obj.width  = width;
-        obj.height = height;
-        // Now really show the image
-        obj.style.display = 'block';
-        obj = null;
-    });
-
+    addEvent(oImage, 'load', zoomHandler);
     oImage = null;
 }
 


------------------------------------------------------------------------------
LogMeIn Central: Instant, anywhere, Remote PC access and management.
Stay in control, update software, and manage PCs from one command center
Diagnose problems and improve visibility into emerging IT issues
Automate, monitor and manage. Do more in less time with Central
http://p.sf.net/sfu/logmein12331_d2d
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to