Some fixes, thanks Arturo.

This commit is contained in:
mdtrooper 2016-02-17 15:36:44 +01:00
parent c5f6259fce
commit fb3b4d8a6f
2 changed files with 45 additions and 4 deletions

View File

@ -83,15 +83,43 @@ abstract class Map {
abstract function printJSInit();
public function writeJSGraph() {
?>
<script type="text/javascript">
<?php
echo "var nodes = " . json_encode($this->nodes) . ";";
echo "var edges = " . json_encode($this->edges) . ";";
?>
</script>
<?php
}
public function show() {
foreach ($this->requires_js as $js) {
echo "<script type='text/javascript' src='$js'></script>" . "\n";
}
$this->writeJSContants();
$this->writeJSGraph();
?>
<div id="map" data-id="<?php echo $this->id;?>" >
<svg style="border: 2px solid red;" pointer-events="all" width="<?php echo $this->width;?>px" height="<?php echo $this->height;?>px">
<?php
if ($this->width == 0) {
$width = "100%";
}
else {
$width = $this->width . "px";
}
if ($this->height == 0) {
$height = "500px";
}
else {
$height = $this->height . "px";
}
?>
<svg style="border: 2px solid red;" pointer-events="all" width="<?php echo $width;?>" height="<?php echo $height;?>">
</svg>
</div>
@ -99,6 +127,16 @@ abstract class Map {
$this->printJSInit();
}
public function writeJSContants() {
?>
<script type="text/javascript">
<?php
?>
</script>
<?php
}
public function getType() {
return $this->type;
}

View File

@ -43,6 +43,8 @@ class Networkmap extends Map {
$filter = json_decode($dbValues['filter'], true);
$this->filter = $filter;
if (!isset($this->filter['only_snmp_modules']))
$this->filter['only_snmp_modules'] = false;
switch ($dbValues['source_data']) {
case MAP_SOURCE_GROUP:
@ -111,6 +113,7 @@ class Networkmap extends Map {
$line = preg_replace('/[ ]+/', ' ', $line);
if (preg_match('/^node.*$/', $line) != 0) {
$items = explode(' ', $line);
$graphviz_id = $items[1];
$nodes[$graphviz_id]['x'] = $items[2] * 100; //200 is for show more big
@ -119,13 +122,13 @@ class Networkmap extends Map {
}
foreach ($nodes as $graphviz_id => $node) {
$graph->$nodes[$graphviz_id] = $node;
$this->nodes[$graphviz_id] = $node;
}
foreach ($edges as $edge) {
$graph->nodes[] = array('type' => ITEM_TYPE_EDGE_NETWORKMAP);
$this->nodes[] = array('type' => ITEM_TYPE_EDGE_NETWORKMAP);
$edge['id_item'] = key(end($graph->nodes[]));
$graph->edges[] = $edge;
$this->edges[] = $edge;
}
}