Index: /trunk/web/addons/toga/conf.php
===================================================================
--- /trunk/web/addons/toga/conf.php	(revision 110)
+++ /trunk/web/addons/toga/conf.php	(revision 111)
@@ -14,4 +14,11 @@
 $SMALL_CLUSTERIMAGE_NODEWIDTH = 11;
 
+// How to mark nodes with a job in clusterimage
+// allcpus when all cpu's are in use
+// singlecpu when less than all cpus are in use
+//
+$JOB_NODE_MARKING_ALLCPUS = "J";
+$JOB_NODE_MARKING_SINGLECPU = "j";
+
 // XML Datasource for Toga
 // by default localhost's gmetad
Index: /trunk/web/addons/toga/image.php
===================================================================
--- /trunk/web/addons/toga/image.php	(revision 110)
+++ /trunk/web/addons/toga/image.php	(revision 111)
@@ -6,8 +6,9 @@
 
 $view = $httpvars->getHttpVar( "view" );
+$clustername = $httpvars->getClusterName();
 
 function drawSmallClusterImage() {
 
-	$ic = new ClusterImage();
+	$ic = new ClusterImage( $clustername );
 	$ic->draw();
 }
Index: /trunk/web/addons/toga/libtoga.php
===================================================================
--- /trunk/web/addons/toga/libtoga.php	(revision 110)
+++ /trunk/web/addons/toga/libtoga.php	(revision 111)
@@ -187,4 +187,5 @@
 
 		$jobs = &$this->jobs;
+		$nodes = &$this->nodes;
 
 		if ( $attrs[TN] ) {
@@ -211,5 +212,8 @@
 			$location = $attrs[LOCATION];
 
-			$this->gotNode( $hostname, $location, null );
+			if( !isset( $this->nodes[$hostname] ) )
+				$this->nodes[$hostname] = new NodeImage( $hostname );
+
+			//$this->gotNode( $hostname, $location, null );
 
 		} else if( $name == 'METRIC' and strstr( $attrs[NAME], 'TOGA' ) ) {
@@ -244,12 +248,18 @@
 							$jobs[$jobid][$toganame] = array();
 
-						$nodes = explode( ';', $togavalue );
-
-						foreach( $nodes as $node ) {
-
-							$hostname = $node.'.'.$jobs[$jobid][domain];
-							$jobs[$jobid][$toganame][] = $hostname;
-							$this->gotNode( $hostname, null, $jobid );
-							//printf( "got job %s on node %s", $jobid, $hostname );
+						$mynodes = explode( ';', $togavalue );
+
+						foreach( $mynodes as $node ) {
+
+							//$hostname = $node.'.'.$jobs[$jobid][domain];
+							$jobs[$jobid][$toganame][] = $node;
+
+							//if( !isset( $this->nodes[$hostname] ) )
+								//$mynode = new NodeImage( $hostname );
+
+							//$the_node = $this->nodes[$hostname];
+							//$the_node->addJob( $jobid, 
+							//$this->gotNode( $hostname, null, $jobid );
+							//printf( "got node %s\n", $node );
 						}
 
@@ -258,4 +268,29 @@
 						$jobs[$jobid][$toganame] = $togavalue;
 					}
+				}
+
+				if( isset( $jobs[$jobid][domain] ) and isset( $jobs[$jobid][nodes] ) ) {
+				
+					foreach( $jobs[$jobid][nodes] as $node ) {
+
+						$host = $node.'.'.$jobs[$jobid][domain];
+				
+						if( !isset( $this->nodes[$host] ) )
+							$my_node = new NodeImage( $host );
+						else
+							$my_node = $this->nodes[$host];
+
+						if( !$my_node->hasJob( $jobid ) )
+
+							if( isset( $jobs[$jobid][ppn] ) )
+								$my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) );
+							else
+								$my_node->addJob( $jobid, 1 );
+
+						$this->nodes[$host] = $my_node;
+					}
+				} else {
+
+					printf( "no domain or nodes set for %s\n", $jobid );
 				}
 			}
@@ -332,4 +367,5 @@
 	}
 
+
 	function setLocation( $location ) {
 		$this->location = $location;
@@ -361,8 +397,8 @@
 	}
 
-	function setCoords( $x, $y ) {
-		$myimg = $this->img;
-		$myimg->setCoords( $x, $y );
-	}
+	//function setCoords( $x, $y ) {
+		//$myimg = $this->img;
+		//$myimg->setCoords( $x, $y );
+	//}
 
 	function setImage( $image ) {
@@ -388,13 +424,47 @@
 class NodeImage {
 
-	var $image, $x, $y, $hostname, $jobs;
-
-	function NodeImage( $image, $x, $y, $hostname, $multiproc_job ) {
+	var $image, $x, $y, $hostname, $jobs, $tasks;
+
+	function NodeImage( $hostname ) {
+
+		$this->jobs = array();
+		//$this->image = $image;
+		//$this->x = $x;
+		//$this->y = $y;
+		$this->tasks = 0;
+		$this->hostname = $hostname;
+		$this->cpus = $this->determineCpus();
+	}
+
+	function addJob( $jobid, $cpus ) {
+		$jobs = &$this->jobs;
+
+		$jobs[] = $jobid;
+		$this->jobs = $jobs;
+
+		$this->addTask( $cpus );
+	}
+
+	function hasJob( $jobid ) {
+
+		$jobfound = 0;
+
+		if( count( $this->jobs ) > 0 )
+			foreach( $this->jobs as $job )
+
+				if( $job == $jobid )
+					$jobfound = 1;
+
+		return $jobfound;
+	}
+
+	function addTask( $cpus ) {
+
+		$this->tasks = $this->tasks + $cpus;
+	}
+
+	function setImage( $image ) {
 
 		$this->image = $image;
-		$this->x = $x;
-		$this->y = $y;
-		$this->hostname = $hostname;
-		$this->multiproc_job = $multiproc_job;
 	}
 
@@ -412,8 +482,4 @@
 	}
 
-	function setImage( $image ) {
-		$this->image = $image;
-	}
-
 	function setLoad( $load ) {
 		$this->load = $load;
@@ -424,9 +490,11 @@
 	}
 
-	function drawNode( $load ) {
-
-		global $SMALL_CLUSTERIMAGE_NODEWIDTH;
-
-		if( !isset( $this->x ) or !isset( $this->y ) or !isset( $load ) ) {
+	function draw() {
+
+		global $SMALL_CLUSTERIMAGE_NODEWIDTH, $JOB_NODE_MARKING_ALLCPUS, $JOB_NODE_MARKING_SINGLECPU;
+
+		$this->load = $this->determineLoad();
+
+		if( !isset( $this->x ) or !isset( $this->y ) or !isset( $this->load ) ) {
 			printf( "aborting\n" );
 			printf( "x %d y %d load %f\n", $this->x, $this->y, $load );
@@ -434,7 +502,9 @@
 		}
 
-		$black_color = imageColorAllocate( &$this->image, 0, 0, 0 );
+		$black_color = imageColorAllocate( $this->image, 0, 0, 0 );
 
 		// Convert Ganglias Hexadecimal load color to a Decimal one
+		//
+		$load = $this->determineLoad();	
 		$my_loadcolor = $this->colorHex( load_color($load) );
 
@@ -443,14 +513,22 @@
 		imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color );
 		imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $my_loadcolor );
-		if( $this->multiproc_job == 2 )
-			imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), "J", $black_color );
-		else if( $this->multiproc_job == 1 )
-			imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), "j", $black_color );
-
-		// Een job markering?
-		//imageFilledEllipse( $this->image, ($this->x+9)/2, ($this->y+9)/2, 6, 6, $jobcolor );
-	}
-
-	function draw() {
+
+		$nr_jobs = count( $this->jobs );
+
+		$node_mark = null;
+
+		if( count( $this->jobs ) > 0 )
+
+			if( $this->tasks < $this->cpus )
+				$node_mark = $JOB_NODE_MARKING_SINGLECPU;
+
+			else if( $this->tasks == $this->cpus )
+				$node_mark = $JOB_NODE_MARKING_ALLCPUS;
+
+		if( $node_mark )
+			imageString( $this->image, 1, $this->x+(($size/2)-2), $this->y+(($size/2)-3), $node_mark, $black_color );
+	}
+
+	function determineCpus() {
 
 		global $metrics;
@@ -458,9 +536,16 @@
 		$cpus = $metrics[$this->hostname][cpu_num][VAL];
 		if (!$cpus) $cpus=1;
+
+		return $cpus;
+	}
+
+	function determineLoad() {
+
+		global $metrics;
+
 		$load_one = $metrics[$this->hostname][load_one][VAL];
-		$load = ((float) $load_one)/$cpus;
-		//printf( "hostname %s cpus %s load_one %s load %f\n", $this->hostname, $cpus, $load_one, $load );
-
-		$this->drawNode( $load );
+		$load = ((float) $load_one)/$this->cpus;
+
+		return $load;
 	}
 }
@@ -468,8 +553,9 @@
 class ClusterImage {
 
-	var $dataget, $image;
-
-	function ClusterImage() {
+	var $dataget, $image, $clustername;
+
+	function ClusterImage( $clustername ) {
 		$this->dataget = new DataGatherer();
+		$this->clustername = $clustername;
 	}
 
@@ -490,7 +576,8 @@
 
 		$nodes = $mydatag->getNodes();
+		$nodes_hosts = array_keys( $nodes );
 
 		$nodes_nr = count( $nodes );
-		$node_keys = array_keys( $nodes );
+		//printf( "%d nodes\n", $nodes_nr );
 
 		$nodes_size = $nodes_nr*$node_width;
@@ -527,34 +614,42 @@
 
 				$cur_node = ($n * $nodes_per_row) + ($m);
-				$host = $node_keys[$cur_node];
+				$host = $nodes_hosts[$cur_node];
+
+				if( isset( $nodes[$host] ) ) {
+
+					$nodes[$host]->setCoords( $x, $y );
+					$nodes[$host]->setImage( $image );
+					$nodes[$host]->draw();
+				}
+				
 
 				//printf( "host %s curnode %s ", $host, $cur_node );
 
-				if( isset( $nodes[$host] ) and ($cur_node < $nodes_nr) ) {
-					//printf( "image %s\n", $host );
-					$nodejobs = $nodes[$host]->getJobs();
-					$jobs = $mydatag->getJobs();
-
-					$multiproc_job = 0;
-
-					if( count( $nodejobs ) > 0 ) {
-						$multiproc_job = 1;
-
-						foreach( $nodejobs as $myjob ){
-							if( isset($jobs[$myjob]['ppn']) and $jobs[$myjob]['ppn'] > 1 )
-								$multiproc_job = 2;
-								break;
-						}
-					}
+			//	if( isset( $nodes[$host] ) and ($cur_node < $nodes_nr) ) {
+			//		//printf( "image %s\n", $host );
+			//		$nodejobs = $nodes[$host]->getJobs();
+			//		$jobs = $mydatag->getJobs();
+
+			//		$multiproc_job = 0;
+
+			//		if( count( $nodejobs ) > 0 ) {
+			//			$multiproc_job = 1;
+
+			//			foreach( $nodejobs as $myjob ){
+			//				if( isset($jobs[$myjob]['ppn']) and $jobs[$myjob]['ppn'] > 1 )
+			//					$multiproc_job = 2;
+			//					break;
+			//			}
+			//		}
 
 					//printf( "jobs %s node %s", $nrjobs, $host );
-					$node = new NodeImage( $image, $x, $y, $host, $multiproc_job );
+			//		$node = new NodeImage( $image, $x, $y, $host, $multiproc_job );
 					//$node->setHostname( $host );
-					$node->draw();
+			//		$node->draw();
 					//$nodes[$host]->setCoords( $x, $y );
 					//$nodes[$host]->setImage( &$image );
 					//$nodes[$host]->draw();
 					//$cur_node++;
-				}
+			//	}
 			}
 		}
@@ -570,5 +665,5 @@
 //$my_data->printInfo();
 
-$ic = new ClusterImage();
+$ic = new ClusterImage( "LISA Cluster" );
 $ic->draw();
 ?>
