Module: nagvis Branch: master Commit: 3c754b1155c42c1bcda999554f9c290cd1535ba9 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=3c754b1155c42c1bcda999554f9c290cd1535ba9
Author: LaMi <[email protected]> Date: Fri Jan 8 09:50:09 2010 +0100 Lines are drawn on the box_ div in WUI now. So the jsGraphic lines are deleted when removing the object from the map --- share/frontend/wui/classes/WuiMap.php | 133 ++++++++++++++++++++++--- share/userfiles/templates/default.wuiMap.html | 10 -- 2 files changed, 117 insertions(+), 26 deletions(-) diff --git a/share/frontend/wui/classes/WuiMap.php b/share/frontend/wui/classes/WuiMap.php index e51d05f..e938ab6 100644 --- a/share/frontend/wui/classes/WuiMap.php +++ b/share/frontend/wui/classes/WuiMap.php @@ -118,14 +118,10 @@ class WuiMap extends GlobalMap { $this->moveable .= "\"box_".$obj['type']."_".$obj['id']."\","; break; default: + $objCode = ''; + if($obj['type'] == 'line' || (isset($obj['view_type']) && $obj['view_type'] == 'line')) { - list($pointa_x,$pointb_x) = explode(",", $obj['x']); - list($pointa_y,$pointb_y) = explode(",", $obj['y']); - $ret .= "<script type=\"text/javascript\">myshape_background.drawLine(".$pointa_x.",".$pointa_y.",".$pointb_x.",".$pointb_y.");</script>"; - - $obj['x'] = round(($pointa_x+($pointb_x-$pointa_x)/2) - 10); - $obj['y'] = round(($pointa_y+($pointb_y-$pointa_y)/2) - 10); - $obj['icon'] = '20x20.gif'; + $objCode .= $this->parseLine($obj); } else { $this->moveable .= "\"box_".$obj['type']."_".$obj['id']."\","; } @@ -149,7 +145,9 @@ class WuiMap extends GlobalMap { } $obj = $this->fixIcon($obj); - $ret .= $this->parseIcon($obj); + + $objCode .= $this->parseIcon($obj); + $ret .= $this->parseContainer($obj, $objCode); if(isset($obj['label_show']) && $obj['label_show'] == '1') { $ret .= $this->parseLabel($obj); @@ -242,18 +240,121 @@ class WuiMap extends GlobalMap { * @return String HTML Code * @author Lars Michelsen <[email protected]> */ - function parseIcon(&$obj) { + function parseIcon($obj) { + // Add 20x20 icon in the middle of the line in case of line objects + if($obj['type'] == 'line' || (isset($obj['view_type']) && $obj['view_type'] == 'line')) { + list($x1,$x2) = explode(",", $obj['x']); + list($y1,$y2) = explode(",", $obj['y']); + + if($x1 > $x2) { + $x = $x2; + } elseif($x1 < $x2) { + $x = $x1; + } else { + $x = $x1; + } + + if($y1 > $y2) { + $y = $y2; + } elseif($y1 < $y2) { + $y = $y1; + } else { + $y = $y1; + } + + $x = round(($x1+($x2-$x1)/2) - 10) - $x; + $y = round(($y1+($y2-$y1)/2) - 10) - $y; + $style = 'style="position:absolute;left:'.$x.'px;top:'.$y.'px"'; + + $obj['icon'] = '20x20.gif'; + } else { + $x = $obj['x']; + $y = $obj['y']; + $style = ''; + } + + return "<img id=\"icon_".$obj['type']."_".$obj['id']."\" src=\"".$obj['htmlPath'].$obj['icon'].$obj['iconParams']."\" ".$style." alt=\"".$obj['type']."_".$obj['id']."\" ".$this->infoBox($obj)." />"; + } + + /** + * Parses the HTML-Code of a line + * + * @param Array $obj Array with object informations + * @return String HTML Code + * @author Lars Michelsen <[email protected]> + */ + function parseLine($obj) { $ret = ''; - - if($obj['type'] == 'service') { - $name = 'host_name'; + + $lineId = "line_".$obj['type']."_".$obj['id']; + + list($x1,$x2) = explode(",", $obj['x']); + list($y1,$y2) = explode(",", $obj['y']); + + if($x1 > $x2) { + $x = $x2; + } elseif($x1 < $x2) { + $x = $x1; } else { - $name = $obj['type'] . '_name'; + $x = $x1; } - $ret .= "<div id=\"box_".$obj['type']."_".$obj['id']."\" class=\"icon\" style=\"left:".$obj['x']."px; top:".$obj['y']."px;z-index:".$obj['z']."\">"; - $ret .= "\t\t<img src=\"".$obj['htmlPath'].$obj['icon'].$obj['iconParams']."\" alt=\"".$obj['type']."_".$obj['id']."\" ".$this->infoBox($obj).">"; - $ret .= "</div>"; + if($y1 > $y2) { + $y = $y2; + } elseif($y1 < $y2) { + $y = $y1; + } else { + $y = $y1; + } + + $ret .= "var ".$lineId." = new jsGraphics('box_".$obj['type']."_".$obj['id']."');"; + $ret .= $lineId.".setColor('#FF0000');"; + $ret .= $lineId.".setStroke(1);"; + $ret .= $lineId.".drawLine(".($x1-$x).",".($y1-$y).",".($x2-$x).",".($y2-$y).");"; + $ret .= $lineId.".paint();"; + + return $this->parseJs($ret); + } + + /** + * Parses the HTML-Code of an object container + * + * @param Array Array with object informations + * @param String HTML Code + * @return String HTML Code + * @author Lars Michelsen <[email protected]> + */ + function parseContainer($obj, $html) { + $ret = ''; + + // Take the upper left corner for lines + if($obj['type'] == 'line' || (isset($obj['view_type']) && $obj['view_type'] == 'line')) { + list($x1,$x2) = explode(",", $obj['x']); + list($y1,$y2) = explode(",", $obj['y']); + + if($x1 > $x2) { + $x = $x2; + } elseif($x1 < $x2) { + $x = $x1; + } else { + $x = $x1; + } + + if($y1 > $y2) { + $y = $y2; + } elseif($y1 < $y2) { + $y = $y1; + } else { + $y = $y1; + } + } else { + $x = $obj['x']; + $y = $obj['y']; + } + + $ret .= "\n<div id=\"box_".$obj['type']."_".$obj['id']."\" class=\"icon\" style=\"left:".$x."px;top:".$y."px;z-index:".$obj['z']."\">"; + $ret .= $html; + $ret .= "</div>\n"; return $ret; } diff --git a/share/userfiles/templates/default.wuiMap.html b/share/userfiles/templates/default.wuiMap.html index af9c6dd..68c59b9 100644 --- a/share/userfiles/templates/default.wuiMap.html +++ b/share/userfiles/templates/default.wuiMap.html @@ -16,13 +16,6 @@ var backupAvailable = {$backupAvailable}; </script> <div id="mymap" class="map"> - <script type="text/javascript"> - // Prepare line drawing when adding or moving lines - var myshape_background = new jsGraphics('mymap'); - myshape_background.setColor('#FF0000'); - myshape_background.setStroke(1); - </script> - <!-- background --> {if $backgroundImg != ''} <img id="background" src="{$backgroundImg}" style="z-index:0;" alt=""> @@ -33,9 +26,6 @@ var backupAvailable = {$backupAvailable}; </div> <script type="text/javascript"> -// Draw lines etc. on the background -myshape_background.paint(); - // build the right-click menu initjsDOMenu(); ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
