/**
  * Construct a new 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)
 {
     parent::__construct();
     $this->setSize($width, $height);
     $this->name = $name;
     $this->timeout = $timeout;
     // Clean sometimes all the cache
     if (mt_rand(0, 5000) === 0) {
         awGraph::cleanCache();
     }
     if ($this->name !== NULL) {
         $file = ARTICHOW . "/cache/" . $this->name . "-time";
         if (is_file($file)) {
             $type = awGraph::cleanGraphCache($file);
             if ($type === NULL) {
                 awGraph::deleteFromCache($this->name);
             } else {
                 header("Content-Type: image/" . $type);
                 readfile(ARTICHOW . "/cache/" . $this->name . "");
                 exit;
             }
         }
     }
     $this->title = new awLabel(NULL, new awTuffy(16), NULL, 0);
     $this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM);
 }
Esempio n. 2
0
 /**
  * Construct a new 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)
 {
     parent::__construct();
     $this->setSize($width, $height);
     if (ARTICHOW_CACHE) {
         $this->name = $name;
         $this->timeout = $timeout;
         // Clean sometimes all the cache
         if (mt_rand(0, 5000) === 0) {
             awGraph::cleanCache();
         }
         // Take the graph from the cache if possible
         if ($this->name !== NULL) {
             $this->fileCache = ARTICHOW_CACHE_DIRECTORY . "/" . $this->name;
             $this->fileCacheTime = $this->fileCache . "-time";
             if (is_file($this->fileCache)) {
                 $type = awGraph::cleanGraphCache($this->fileCacheTime);
                 if ($type === NULL) {
                     awGraph::deleteFromCache($this->name);
                 } else {
                     header("Content-Type: image/" . $type);
                     echo file_get_contents($this->fileCache);
                     exit;
                 }
             }
         }
     }
     $this->title = new awLabel(NULL, new awTuffy(16), NULL, 0);
     $this->title->setAlign(awLabel::CENTER, awLabel::BOTTOM);
 }
Esempio n. 3
0
	/**
	 * Change title alignment
	 *
	 * @param int $alignment New Alignment
	 */
	public function setTitleAlignment($alignment) {
	
		switch($alignment) {
		
			case awLabel::TOP :
				$this->setTitlePosition(1);
				$this->title->setAlign(NULL, awLabel::BOTTOM);
				break;
		
			case awLabel::BOTTOM :
				$this->setTitlePosition(0);
				$this->title->setAlign(NULL, awLabel::TOP);
				break;
		
			case awLabel::LEFT :
				$this->setTitlePosition(0);
				$this->title->setAlign(awLabel::LEFT);
				break;
		
			case awLabel::RIGHT :
				$this->setTitlePosition(1);
				$this->title->setAlign(awLabel::RIGHT);
				break;
		
		}
	
	}
Esempio n. 4
0
	/**
	 * Change title alignment
	 *
	 * @param int $alignment New Alignment
	 */
	 function setTitleAlignment($alignment) {
	
		switch($alignment) {
		
			case LABEL_TOP :
				$this->setTitlePosition(1);
				$this->title->setAlign(NULL, LABEL_BOTTOM);
				break;
		
			case LABEL_BOTTOM :
				$this->setTitlePosition(0);
				$this->title->setAlign(NULL, LABEL_TOP);
				break;
		
			case LABEL_LEFT :
				$this->setTitlePosition(0);
				$this->title->setAlign(LABEL_LEFT);
				break;
		
			case LABEL_RIGHT :
				$this->setTitlePosition(1);
				$this->title->setAlign(LABEL_RIGHT);
				break;
		
		}
	
	}
 /**
  * Build the component
  */
 function awComponent()
 {
     // Component legend
     $this->legend = new awLegend();
     $this->padding = new awSide(25, 25, 25, 25);
     $this->space = new awSide(0, 0, 0, 0);
     // Component title
     $this->title = new awLabel(NULL, new awTuffy(10), NULL, 0);
     $this->title->setAlign(LABEL_CENTER, LABEL_TOP);
 }
 /**
  * Build the component
  */
 public function __construct()
 {
     // Component legend
     $this->legend = new awLegend();
     $this->padding = new awSide(25, 25, 25, 25);
     $this->space = new awSide(0, 0, 0, 0);
     // Component title
     $this->title = new awLabel(NULL, new awTuffy(10), NULL, 0);
     $this->title->setAlign(awLabel::CENTER, awLabel::TOP);
 }
 public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing)
 {
     $count = count($this->values);
     $sum = array_sum($this->values);
     $width = $x2 - $x1;
     $height = $y2 - $y1;
     if ($aliasing) {
         $x = $width / 2;
         $y = $height / 2;
     } else {
         $x = $width / 2 + $x1;
         $y = $height / 2 + $y1;
     }
     $position = $this->angle;
     $values = array();
     $parts = array();
     $angles = 0;
     if ($aliasing) {
         $side = new awSide(0, 0, 0, 0);
     }
     foreach ($this->values as $key => $value) {
         $angle = $value / $sum * 360;
         if ($key === $count - 1) {
             $angle = 360 - $angles;
         }
         $angles += $angle;
         if (array_key_exists($key, $this->explode)) {
             $middle = 360 - ($position + $angle / 2);
             $posX = $this->explode[$key] * cos($middle * M_PI / 180);
             $posY = $this->explode[$key] * sin($middle * M_PI / 180) * -1;
             if ($aliasing) {
                 $explode = new awPoint($posX * 2, $posY * 2);
                 $side->set(max($side->left, $posX * -2), max($side->right, $posX * 2), max($side->top, $posY * -2), max($side->bottom, $posY * 2));
             } else {
                 $explode = new awPoint($posX, $posY);
             }
         } else {
             $explode = new awPoint(0, 0);
         }
         $values[$key] = array($position, $position + $angle, $explode);
         $color = $this->colors[$key % count($this->colors)];
         $parts[$key] = new awPiePart($color);
         // Add part to the legend
         $legend = array_key_exists($key, $this->legendValues) ? $this->legendValues[$key] : $key;
         $this->legend->add($parts[$key], $legend, awLegend::BACKGROUND);
         $position += $angle;
     }
     if ($aliasing) {
         $mainDrawer = $drawer;
         $x *= 2;
         $y *= 2;
         $width *= 2;
         $height *= 2;
         $this->size *= 2;
         $image = new awImage();
         $image->border->hide();
         $image->setSize($width + $side->left + $side->right, $height + $side->top + $side->bottom + $this->size + 1);
         $drawer = $image->getDrawer($width / $image->width, $height / $image->height, ($width / 2 + $side->left) / $image->width, ($height / 2 + $side->top) / $image->height);
     }
     // Draw 3D effect
     for ($i = $this->size; $i > 0; $i--) {
         foreach ($values as $key => $value) {
             $color = clone $this->colors[$key % count($this->colors)];
             $color->brightness(-50);
             list($from, $to, $explode) = $value;
             $drawer->filledArc($color, $explode->move($x, $y + $i), $width, $height, $from, $to);
             $color->free();
             unset($color);
             if ($this->border instanceof awColor) {
                 $point = $explode->move($x, $y);
                 if ($i === $this->size) {
                     $drawer->arc($this->border, $point->move(0, $this->size), $width, $height, $from, $to);
                 }
             }
         }
     }
     foreach ($values as $key => $value) {
         $color = $this->colors[$key % count($this->colors)];
         list($from, $to, $explode) = $value;
         $drawer->filledArc($color, $explode->move($x, $y), $width, $height, $from, $to);
         if ($this->border instanceof awColor) {
             $point = $explode->move($x, $y);
             $drawer->arc($this->border, $point, $width, $height, $from, $to);
         }
     }
     if ($aliasing) {
         $x = $x / 2 + $x1;
         $y = $y / 2 + $y1;
         $width /= 2;
         $height /= 2;
         $this->size /= 2;
         foreach ($values as $key => $value) {
             $old = $values[$key][2];
             $values[$key][2] = new awPoint($old->x / 2, $old->y / 2);
         }
         $mainDrawer->copyResizeImage($image, new awPoint($x1 - $side->left / 2, $y1 - $side->top / 2), new awPoint($x1 - $side->left / 2 + $image->width / 2, $y1 - $side->top / 2 + $image->height / 2), new awPoint(0, 0), new awPoint($image->width, $image->height), TRUE);
         $drawer = $mainDrawer;
     }
     // Get labels values
     $pc = array();
     foreach ($this->values as $key => $value) {
         $pc[$key] = round($value / $sum * 100, $this->precision);
     }
     if ($this->label->count() === 0) {
         // Check that there is no user defined values
         $this->label->set($pc);
     }
     $position = 0;
     foreach ($pc as $key => $value) {
         // Limit number of labels to display
         if ($position === $this->number) {
             break;
         }
         if (is_null($this->minimum) === FALSE and $value < $this->minimum) {
             continue;
         }
         $position++;
         list($from, $to, $explode) = $values[$key];
         $angle = $from + ($to - $from) / 2;
         $angleRad = (360 - $angle) * M_PI / 180;
         $point = new awPoint($x + $explode->x + cos($angleRad) * ($width / 2 + $this->position), $y + $explode->y - sin($angleRad) * ($height / 2 + $this->position));
         $angle %= 360;
         // We don't display labels on the 3D effect
         if ($angle > 0 and $angle < 180) {
             $point = $point->move(0, -1 * sin($angleRad) * $this->size);
         }
         if ($angle >= 45 and $angle < 135) {
             $this->label->setAlign(awLabel::CENTER, awLabel::BOTTOM);
         } else {
             if ($angle >= 135 and $angle < 225) {
                 $this->label->setAlign(awLabel::RIGHT, awLabel::MIDDLE);
             } else {
                 if ($angle >= 225 and $angle < 315) {
                     $this->label->setAlign(awLabel::CENTER, awLabel::TOP);
                 } else {
                     $this->label->setAlign(awLabel::LEFT, awLabel::MIDDLE);
                 }
             }
         }
         $this->label->draw($drawer, $point, $key);
     }
 }
Esempio n. 8
0
function dis_chart_bar_multiple($chart) {
  global $chart_colors;

  $title = $chart["title"];
  $xlabels = $chart["xlabels"];
  $values = $chart["plots"]["values"];
  $labels = $chart["plots"]["labels"];
  $legends = $chart["plots"]["legends"];
  $new_bar = $chart["plots"]["new_bar"];

  $graph = new Graph(600, 250);
  $graph->setAntiAliasing(TRUE);
  $graph->setBackgroundColor(new Color(240, 240, 240));
  $group = new PlotGroup;
  $group->grid->hideVertical();
  $group->setPadding(45, 22 ,30, 40);
  $group->setSpace(3, 3, NULL, NULL);
  $group->legend->setAlign(NULL, LEGEND_TOP);
  $group->legend->setPosition(1,0);

  // X axis Labels infos
  $xlabel = new Label($xlabels);
  $group->axis->bottom->setlabelText($xlabels);

  // Title infos
  if ($title != "") {
    $graph->title->set("$title");
  }

  $num = 0;
  $nb_bars = array_sum($new_bar);
  $num_bar = 0;

  // $num_plot is the plot number
  // $num_bar is the bar number (1 bar can cumul more than one plot)
  foreach ($values as $num_plot => $plot_values) {
    // Chart infos : colors, size, shadow
    if ($new_bar[$num_plot] == 1) {
      $num_bar++;
    }
    $plot = new BarPlot($plot_values, $num_bar, $nb_bars);
    $plot->setBarColor(new Color($chart_colors[$num_plot][0], $chart_colors[$num_plot][1], $chart_colors[$num_plot][2]));
    $plot->setBarSize(0.6);
    if ($new_bar[$num_plot] == 1) {
      $plot->barShadow->setSize(2);
      $plot->barShadow->smooth(TRUE);
      // Labels infos
      $label = new Label($labels[$num_plot]);
      $label->setFont(new Tuffy(8));
      $label->setAlign(NULL, LABEL_TOP);
      $plot->label = $label;
    }
    $group->add($plot);
    $group->legend->add($plot, utf8_decode($legends[$num_plot]), LEGEND_BACKGROUND);
  }

  $graph->add($group);
  $graph->draw();
}