Source for file Graph.class.php
Documentation is available at Graph.class.php 
 * This work is hereby released into the Public Domain.  
 * To view a copy of the public domain dedication,  
 * visit http://creativecommons.org/licenses/publicdomain/ or send a letter to  
 * Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.  
require_once dirname(__FILE__ ). "/Image.class.php";  
define("GRAPH_DRAW_RETURN", 1);  
define("GRAPH_DRAW_DISPLAY", 2);  
 * @package linea21.externals  
  private $components =  array();  
   * Some labels to add to the component  
   * Time file cache location  
   * Drawing mode to return the graph  
   * Drawing mode to display the graph  
   * @param int $width Graph width  
   * @param int $height Graph height  
   * @param string $name Graph name for the cache (must be unique). Let it null to not use the cache.  
   * @param int $timeout Cache timeout (unix timestamp)  
  public function __construct($width =  NULL, $height =  NULL, $name =  NULL, $timeout =  0) {  
      // Clean sometimes all the cache  
      // Take the graph from the cache if possible  
      if($this->name !==  NULL) {  
        $this->fileCacheTime =  $this->fileCache. "-time";  
          $type =  awGraph::cleanGraphCache($this->fileCacheTime);  
            header("Content-Type: image/". $type);  
   * Delete a graph from the cache  
   * @param string $name Graph name  
   * @return bool TRUE on success, FALSE on failure  
   * Delete all graphs from the cache  
        if($file !==  '.' and $file !=  '..') {  
      foreach($glob as $file) {  
        $type =  awGraph::cleanGraphCache($file);  
   * Enable/Disable Graph timing  
    $this->timing = (bool) $timing;  
   * Add a component to the graph  
   * @param awComponent $component   
  public function add(awComponent $component) {  
    $this->components[] =  $component;  
   * Add a label to the component  
   * @param int $x Position on X axis of the center of the text  
   * @param int $y Position on Y axis of the center of the text  
  public function addLabel(awLabel $label, $x, $y) {  
   * Add a label to the component with absolute position  
   * @param awPoint $point Text position  
  public function addAbsLabel(awLabel $label, awPoint $point) {  
   * Build the graph and draw component on it  
   * @param string $mode Display mode (can be a file name)  
  public function draw($mode =  Graph::DRAW_DISPLAY) {  
    foreach($this->components as $component) {  
    // Put the graph in the cache if needed  
      case Graph::DRAW_DISPLAY :   
      case Graph::DRAW_RETURN :   
  private function drawLabels() {  
    foreach($this->labels as $array) {  
      if(count($array) ===  3) {  
        // Text in relative position  
        list ($label, $x, $y) =  $array; 
        // Text in absolute position  
        list ($label, $point) =  $array; 
      $label->draw($driver, $point);  
  private function drawTitle() {  
    $this->title->draw($driver, $point);  
  private function drawTiming($time) {  
    $label->set("(". sprintf("%.3f", $time). " s)");  
    $label->setPadding(1, 0, 0, 0);  
    $label->setBackgroundColor(new awColor(230, 230, 230, 25));  
    $label->draw($driver, new awPoint(5, $driver->imageHeight -  5));  
  private function cache($data) {  
  private static function cleanGraphCache($file) {  
    if($time !==  0 and $time <  time()) {  
 * To preserve PHP 4 compatibility  
  return (float) $usec + (float) $sec;  
 
 
        
       |