Changeset 107 for trunk/web/addons/toga/toga-functions.php
- Timestamp:
- 05/18/05 10:45:43 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web/addons/toga/toga-functions.php
r106 r107 269 269 270 270 $this->hostname = $hostname; 271 $this->img = new NodeImg();271 //$this->img = new NodeImg(); 272 272 $this->jobs = array(); 273 273 } … … 330 330 } 331 331 332 class NodeIm g{332 class NodeImage { 333 333 334 334 var $image, $x, $y; 335 335 336 function NodeImg( $image = null ) { 337 338 $imageWidth = 100; 339 $imageHeight = 100; 340 341 if( !$image ) { 342 $this->image = imageCreate( $imageWidth, $imageHeight ); 343 // or die( 'Cannot initialize new image stream: is GD installed?' ); 344 } else { 345 $this->image = $image; 346 } 347 348 $background_color = imageColorAllocate( $this->image, 255, 255, 255 ); 349 $black_color = imageColorAllocate( $this->image, 0, 0, 0 ); 350 imageRectangle( $this->image, 0, 0, $imageWidth-1, $imageHeight-1, $black_color ); 351 $this->x = null; 352 $this->y = null; 336 function NodeImage( $image, $x, $y ) { 337 338 $this->image = $image; 339 $this->x = $x; 340 $this->y = $y; 353 341 } 354 342 355 343 function setCoords( $x, $y ) { 344 356 345 $this->x = $x; 357 346 $this->y = $y; … … 373 362 } 374 363 375 function drawNode( &$queuecolor, $load, &$jobcolor ) { 376 377 if( !$this->x or !$this->y or !$this->load ) { 364 function drawNode( $load ) { 365 366 if( !isset( $this->x ) or !isset( $this->y ) or !isset( $load ) ) { 367 printf( "aborting\n" ); 368 printf( "x %d y %d load %f\n", $this->x, $this->y, $load ); 378 369 return; 379 370 } 380 371 372 $queue_color = imageColorAllocate( &$this->image, 0, 102, 304 ); 373 $job_color = imageColorAllocate( &$this->image, 204, 204, 0 ); 381 374 382 375 // Convert Ganglias Hexadecimal load color to a Decimal one … … 385 378 imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+12, $this->y+12, $queuecolor ); 386 379 imageFilledRectangle( $this->image, $this->x+2, $this->y+2, $this->x+10, $this->y+10, $my_loadcolor ); 380 387 381 // Een job markering? 388 382 //imageFilledEllipse( $this->image, ($this->x+9)/2, ($this->y+9)/2, 6, 6, $jobcolor ); … … 391 385 function draw() { 392 386 393 $queue_color = imageColorAllocate( $this->image, 0, 102, 304 ); 394 $job_color = imageColorAllocate( $this->image, 204, 204, 0 ); 395 396 $this->drawNode( $queue_color, 0.1, $job_color ); 397 } 398 } 399 400 class ImageCreator { 387 $cpus = $metrics[$this->hostname]["cpu_num"][VAL]; 388 if (!$cpus) $cpus=1; 389 $load_one = $metrics[$this->hostname]["load_one"][VAL]; 390 $load = ((float) $load_one)/$cpus; 391 392 $this->drawNode( $load ); 393 } 394 } 395 396 class ClusterImage { 401 397 402 398 var $dataget, $image; 403 399 404 function ImageCreator() {400 function ClusterImage() { 405 401 $this->dataget = new DataGatherer(); 406 402 } 407 403 408 404 function draw() { 409 $mydatag = &$this->dataget;405 $mydatag = $this->dataget; 410 406 $mydatag->parseXML(); 411 407 … … 422 418 423 419 if( $nodes_size > $max_width ) { 424 $nodes_per_row = ( int) $max_width/$node_width;420 $nodes_per_row = ( (int) ($max_width/$node_width) ); 425 421 } else { 426 422 $nodes_per_row = $nodes_size; … … 429 425 430 426 if( $nodes_per_row < $nodes_nr ) { 431 $node_rows = (int) $nodes_nr/$nodes_per_row; 432 if( ((int) fmod( $node_nr, ($nodes_nr*$nodes_per_row) )) > 0 ) { 427 $node_rows = ( (int) ($nodes_nr/$nodes_per_row) ); 428 $node_rest = fmod( $nodes_nr, $nodes_per_row ); 429 //printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest ); 430 if( $node_rest > 0 ) { 433 431 $node_rows++; 432 //printf( "noderows %d\n", $node_rows ); 434 433 } 435 434 } 436 435 437 $image = imageCreate( ($nodes_per_row*$node_width), ($node_rows*$node_width) ); 438 439 $cur_node = 0; 436 //printf( "imagecreate: %dx%d", ($nodes_per_row*$node_width), ($node_rows*$node_width) ); 437 $image = imageCreateTrueColor( ($nodes_per_row*$node_width), ($node_rows*$node_width) ); 438 $colorwhite = imageColorAllocate( $image, 255, 255, 255 ); 439 imageFill( $image, 0, 0, $colorwhite ); 440 440 441 441 for( $n = 0; $n < $node_rows; $n++ ) { 442 442 443 443 for( $m = 0; $m < $nodes_per_row; $m++ ) { 444 445 $x = ($m*$node_width); 446 $y = ($m*$node_width)+($n*$node_width); 444 445 $x = ($m * $node_width); 446 $y = ($n * $node_width); 447 448 $cur_node = ($n * $nodes_per_row) + ($m + 1); 447 449 $host = $node_keys[$cur_node]; 448 //printf( "cur_node %d, host %s\n", $cur_node, $host ); 449 if( isset( $nodes[$host] ) and ($cur_node < $nodes_nr) ) { 450 $nodes[$host]->setCoords( $x, $y ); 451 $nodes[$host]->setImage( &$image ); 452 $nodes[$host]->draw(); 453 $cur_node++; 450 451 if( isset( $nodes[$host] ) and ($cur_node <= $nodes_nr) ) { 452 $node = new NodeImage( $image, $x, $y ); 453 $node->draw(); 454 //$nodes[$host]->setCoords( $x, $y ); 455 //$nodes[$host]->setImage( &$image ); 456 //$nodes[$host]->draw(); 457 //$cur_node++; 454 458 } 455 459 } … … 462 466 } 463 467 464 //$my_node = new NodeImg();465 //$my_node->drawImage();466 467 468 //$my_data = new DataGatherer(); 468 469 //$my_data->parseXML(); 469 470 //$my_data->printInfo(); 470 471 471 $ic = new ImageCreator();472 $ic = new ClusterImage(); 472 473 $ic->draw(); 473 474 ?>
Note: See TracChangeset
for help on using the changeset viewer.