Author:   Lars Michelsen <[email protected]>
Date:     Sat Mar  9 12:53:45 2013 +0100
Committer:   Lars Michelsen <[email protected]>
Commit-Date: Sat Mar  9 12:53:45 2013 +0100

Centering labels is now possible

Implemented center and bottom as label coordinate values which are
automatically calculated depending on the rendered sizes

---

 ChangeLog                                          |    2 +
 docs/en_US/map_config_format_description.html      |    9 ++++-
 .../frontend/nagvis-js/js/NagVisStatefulObject.js  |   36 +++++++++++++------
 share/frontend/nagvis-js/js/nagvis.js              |    2 +-
 share/server/core/defines/matches.php              |    2 +
 share/server/core/mapcfg/default.php               |   22 ++++++-----
 share/server/core/sources/automap.php              |    4 +-
 7 files changed, 50 insertions(+), 27 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6c7012c..f7d9d94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@ Core:
     created on demand by URL parameters. This mode is reached by simply
     calling the map URL without "show=" parameter and a bunch of parameters
     for the global section of the map instead.
+  * Implemented center and bottom as label coordinate values which are
+    automatically calculated depending on the rendered sizes
 
 Automap:
   * Changed default behaviour of the automap concerning the root host. By
diff --git a/docs/en_US/map_config_format_description.html 
b/docs/en_US/map_config_format_description.html
index b81dafa..5922e8e 100644
--- a/docs/en_US/map_config_format_description.html
+++ b/docs/en_US/map_config_format_description.html
@@ -194,10 +194,15 @@
         <td> label_show </td><td> 0 </td><td> Enable/Disable labels for the 
maps objects </td>
         </tr>
         <tr>
-        <td> label_x </td><td> -20 </td><td> Default x-position of the labels 
in px (with prefix + or - relative to the upper left corner of the icons, 
otherwise absolute position) </td>
+        <td> label_x </td><td>center</td><td>
+        Default x-position of the labels in px (with prefix + or - relative to 
the upper left corner of the icons, otherwise absolute position).
+        Since 1.7.7 this can also be set do center, which is the new default 
option.</td>
         </tr>
         <tr>
-        <td> label_y </td><td> +20 </td><td> Default y-position of the labels 
in px (with prefix + or - relative to the upper left corner of the icons, 
otherwise absolute position) </td>
+        <td> label_y </td><td>bottom</td><td>
+        Default y-position of the labels in px (with prefix + or - relative to 
the upper left corner of the icons, otherwise absolute position).
+        Since 1.7.7 this can also be set do bottom, which is the new default 
option.
+        </td>
         </tr>
         <tr>
         <td> label_width </td><td> auto </td><td> Default width of the labels 
in px </td>
diff --git a/share/frontend/nagvis-js/js/NagVisStatefulObject.js 
b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
index ec4b8bd..d6d01a6 100644
--- a/share/frontend/nagvis-js/js/NagVisStatefulObject.js
+++ b/share/frontend/nagvis-js/js/NagVisStatefulObject.js
@@ -825,10 +825,7 @@ var NagVisStatefulObject = NagVisObject.extend({
      */
     moveLabel: function () {
         var label  = document.getElementById(this.conf.object_id + '-label');
-        var coords = this.getLabelPos();
-        label.style.top  = coords[1] + 'px';
-        label.style.left = coords[0] + 'px';
-        coords = null;
+        this.updateLabelPos(label);
         label  = null;
     },
 
@@ -887,14 +884,24 @@ var NagVisStatefulObject = NagVisObject.extend({
     },
 
     /**
-     * Calculates and returns the positions of the objects label
-     *
-     * @author Lars Michelsen <[email protected]>
+     * Calculates and applies the real positions of the objects label. It uses 
the configuration
+     * variables label_x/label_y and repositions the labels based on the 
config. The label
+     * must have been rendered and added to dom to have the dimensions of the 
object to be able
+     * to realize the center/bottom coordinate definitions.
      */
-    getLabelPos: function () {
+    updateLabelPos: function (oLabel) {
         var x = this.conf.label_x,
             y = this.conf.label_y;
 
+        if(this.conf.label_x && this.conf.label_x.toString() == 'center') {
+            var diff_x = parseInt(parseInt(oLabel.clientWidth) - 
this.getObjWidth()) / 2;
+            x = this.parseCoord(this.parseLabelCoord(this.conf.x), 'x', false) 
- diff_x;
+        }
+
+        if(this.conf.label_y && this.conf.label_y.toString() == 'bottom') {
+            y = this.parseCoord(this.conf.y, 'y', false) + this.getObjHeight();
+        }
+
         // If there is a presign it should be relative to the objects x/y
         if(this.conf.label_x && 
this.conf.label_x.toString().match(/^(?:\+|\-)/))
             x = this.parseCoord(this.parseLabelCoord(this.conf.x), 'x', false) 
+ parseFloat(this.conf.label_x);
@@ -907,7 +914,9 @@ var NagVisStatefulObject = NagVisObject.extend({
         if(!this.conf.label_y || this.conf.label_y === '' || this.conf.label_y 
=== '0')
             y = this.parseCoord(this.parseLabelCoord(this.conf.y), 'y', false);
 
-        return [ addZoomFactor(x), addZoomFactor(y) ];
+        oLabel.style.left = addZoomFactor(x) + 'px';
+        oLabel.style.top  = addZoomFactor(y) + 'px';
+        oLabel = null;
     },
 
     parseLabelCoord: function (val) {
@@ -924,14 +933,17 @@ var NagVisStatefulObject = NagVisObject.extend({
      * @author Lars Michelsen <[email protected]>
      */
     parseLabel: function (oContainer) {
-        var coords = this.getLabelPos();
-        drawNagVisTextbox(
+        var oLabel = drawNagVisTextbox(
             oContainer, this.conf.object_id + '-label', 'object_label',
             this.conf.label_background, this.conf.label_border,
-            coords[0], coords[1], this.conf.z,
+            // use object coords for initial rendering, updated by 
updateLabelPos below
+            this.parseCoord(this.conf.x, 'x', false), 
this.parseCoord(this.conf.y, 'y', false),
+            this.conf.z,
             this.conf.label_width, '', this.replaceLabelTextDynamicMacros(),
             this.conf.label_style
         );
+        this.updateLabelPos(oLabel);
+        oLabel = null;
     },
 
     unlockLabel: function () {
diff --git a/share/frontend/nagvis-js/js/nagvis.js 
b/share/frontend/nagvis-js/js/nagvis.js
index 5accefe..caf9961 100644
--- a/share/frontend/nagvis-js/js/nagvis.js
+++ b/share/frontend/nagvis-js/js/nagvis.js
@@ -1074,7 +1074,7 @@ function drawNagVisTextbox(oContainer, id, className, 
bgColor, borderColor, x, y
     }
 
     oLabelSpan = null;
-    oLabelDiv = null;
+    return oLabelDiv;
 }
 
 /**
diff --git a/share/server/core/defines/matches.php 
b/share/server/core/defines/matches.php
index b3acb27..b421b71 100644
--- a/share/server/core/defines/matches.php
+++ b/share/server/core/defines/matches.php
@@ -100,6 +100,8 @@ define('MATCH_CONTEXT_TEMPLATE_FILE', 
'/^(.+)\.context\.html$/i');
 define('MATCH_PHP_FILE', '/^(.+\.php)$/i');
 define('MATCH_INTEGER_PRESIGN', '/^[\+\-]?[0-9]+$/');
 define('MATCH_INTEGER_PRESIGN_EMPTY', '/^[\+\-]?[0-9]*$/');
+define('MATCH_LABEL_X', '/^([\+\-]?[0-9]+|center)$/');
+define('MATCH_LABEL_Y', '/^([\+\-]?[0-9]+|bottom)$/');
 define('MATCH_ORDER', '/^(?:asc|desc)$/');
 define('MATCH_TEXTBOX_WIDTH', '/^([0-9]+|auto)$/');
 define('MATCH_TEXTBOX_HEIGHT', '/^([0-9]+|auto)$/');
diff --git a/share/server/core/mapcfg/default.php 
b/share/server/core/mapcfg/default.php
index d9d42dc..4f759cb 100644
--- a/share/server/core/mapcfg/default.php
+++ b/share/server/core/mapcfg/default.php
@@ -540,17 +540,19 @@ $mapConfigVars = Array(
         'depends_value' => '1'
     ),
     'label_x' => Array(
-        'must' => 0,
-        'default' => '-20',
-        'match' => MATCH_INTEGER_PRESIGN,
-        'depends_on' => 'label_show',
-        'depends_value' => '1'),
+        'must'          => 0,
+        'default'       => 'center',
+        'match'         => MATCH_LABEL_X,
+        'depends_on'    => 'label_show',
+        'depends_value' => '1'
+    ),
     'label_y' => Array(
-        'must' => 0,
-        'default' => '+20',
-        'match' => MATCH_INTEGER_PRESIGN,
-        'depends_on' => 'label_show',
-        'depends_value' => '1'),
+        'must'          => 0,
+        'default'       => 'bottom',
+        'match'         => MATCH_LABEL_Y,
+        'depends_on'    => 'label_show',
+        'depends_value' => '1'
+    ),
     'label_width' => Array(
         'must' => 0,
         'default' => 'auto',
diff --git a/share/server/core/sources/automap.php 
b/share/server/core/sources/automap.php
index f8148a2..f8f84b9 100644
--- a/share/server/core/sources/automap.php
+++ b/share/server/core/sources/automap.php
@@ -301,8 +301,8 @@ function automap_obj($MAPCFG, &$params, &$saved_config, 
$obj_name) {
         $obj['.height']     = $size[1];
     }
 
-    $obj['label_show'] = true;
-    $obj['label_border'] = 'transparent';
+    $obj['label_show']       = true;
+    $obj['label_border']     = 'transparent';
 
     // Header menu has z-index 100, this object's label the below+1
     $obj['z']           = 98;


------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester  
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the  
endpoint security space. For insight on selecting the right partner to 
tackle endpoint security challenges, access the full report. 
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Nagvis-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nagvis-checkins

Reply via email to