<?php
include ("plotter/jpgraph/src/jpgraph.php");
include ("plotter/jpgraph/src/jpgraph_canvas.php");
include ("plotter/jpgraph/src/jpgraph_canvtools.php");
include ("plotter/jpgraph/src/jpgraph_iconplot.php");
//FIXME: very coupled with field name in database.
//it should be using getField from the class definition
//different with plotter.. mapplotter get data not from database
Class MapPlotter{
// Define work space
private $xmax=20;
private $ymax=20;
//the actual graph canvas
private $g;
//image maps to return so the icon is clickable
private $imagemaps;
//data is an array of stdobject from database
public function __construct(){
// Setup a basic canvas we can work
$this->g = new CanvasGraph(800,550,'auto');
$this->g->SetMargin(5,5,5,5);
$this->g->SetMarginColor("#ccccff");
// We need to stroke the plotarea and margin before we add the
// text since we otherwise would overwrite the text.
$this->g->InitFrame();
$this->imagemaps = '';
}
//should be invoked after all set process
public function getImageMaps(){
return '<MAP NAME="MyMap">'.$this->imagemaps.'</MAP>';
}
//want to rush drawing the map.. here it is ;)
public function setAgent($data){
for($i=0;$i<sizeof($data);$i++){
$this->addHost($data[$i]);
}
}
public function setNet($data){
for($i=0;$i<sizeof($data);$i++){
$this->addNet($data[$i]);
}
}
//data1 and data2 must have the same length
public function setRelation($data1,$data2,$obj){
for($i=0;$i<sizeof($data1);$i++){
$this->addLine($data1[$i],$data2[$i],$obj[$i]);
}
}
public function addHost($agent){
//test icon
$icon = new IconPlot('/www/htdocs/ajaxmonyet/gen_picts/mainframe.gif',$agent->x,$agent->y,0.4,90);
$this->g->Add($icon);
$t1 = new Text(' '.$agent->name."\n ".$agent->message);
$t1->SetPos($agent->x,$agent->y);
$t1->SetFont(FF_FONT1,FS_NORMAL);
$t1->SetBox($agent->color,'white',true);
$t1->ParagraphAlign("left");
$t1->SetColor("black");
$this->g->AddText($t1);
if($agent->url!=''){
$this->imagemaps .= '<AREA SHAPE="rect" COORDS="'.$agent->x.','.$agent->y.','.($agent->x+85).','.($agent->y+25).
'" HREF="'.$agent->url.'">';
}
}
//FIXME: currently monitoring is ping. alternative packet, bandwith, etc
public function addLine($agent1,$agent2,$objmonitor){
$this->g->img->SetColor($objmonitor->color);
$this->g->img->Line($agent1->x+30,$agent1->y,$agent2->x+30,$agent2->y);
$this->g->img->SetColor($objmonitor->color);
$x = ($agent1->x+60+$agent2->x)/2;
$y = ($agent1->y+$agent2->y)/2;
$this->g->img->FilledRectangle($x,$y,$x+5,$y+5);
//what's color for disabled agent?
if($objmonitor->color!="brown"){
$this->imagemaps .= '<AREA SHAPE="rect" COORDS="'.$x.','.$y.','.($x+5).','.($y+5).
'" HREF="javascript:sndReqPOST(\'systemstat/laststat\',\'id=p_'.$objmonitor->monitor_id.'\')">';
}
}
public function addNet($net){
$this->g->img->SetColor('#6e89aa');
$this->g->img->FilledRectangle($net->x,$net->y,$net->x+120,$net->y+5);
$t1 = new Text($net->name);
$t1->SetPos($net->x,$net->y+7);
$t1->SetFont(FF_FONT1,FS_NORMAL);
$this->g->AddText($t1);
}
public function attach(){
// Create a new scale
$scale = new CanvasScale($this->g);
$scale->Set(0,$this->xmax,0,$this->ymax);
//set timestamp and signature
$t1 = new Text(date('d.m.Y G:i:s'));
$t1->SetColor('gray');
$t1->SetPos(10,530);
$t1->SetFont(FF_FONT1,FS_NORMAL);
$this->g->AddText($t1);
$file = rand(2,20000).'networkmap.png';
$this->g->Stroke('/www/htdocs/ajaxmonyet/tmp/'.$file);
return $file;
}
}
?>