Exemple #1
0
 /**
  * Construct a new awgraph
  *
  * @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)
  */
 function awGraph($width = NULL, $height = NULL, $name = NULL, $timeout = 0)
 {
     parent::awImage();
     $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();
         }
         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(LABEL_CENTER, LABEL_BOTTOM);
 }
Exemple #2
0
 public function create()
 {
     $legend = $this->getArg('legend');
     $y = $this->getArg('y');
     if ($y === NULL) {
         awImage::drawError("Class LightLinePattern: Argument 'y' must not be NULL.");
     }
     $plot = new LinePlot($y);
     $plot->setSize(0.7, 1);
     $plot->setCenter(0.35, 0.5);
     $plot->setPadding(35, 15, 35, 30);
     $plot->setColor(new Orange());
     $plot->setFillColor(new LightOrange(80));
     $plot->grid->setType(Line::DASHED);
     $plot->mark->setType(Mark::CIRCLE);
     $plot->mark->setFill(new MidRed());
     $plot->mark->setSize(6);
     $plot->legend->setPosition(1, 0.5);
     $plot->legend->setAlign(Legend::LEFT);
     $plot->legend->shadow->smooth(TRUE);
     if ($legend !== NULL) {
         $plot->legend->add($plot, $legend, Legend::MARK);
     }
     return $plot;
 }
 /**
  * Load a pattern
  *
  * @param string $pattern Pattern name
  * @return Component
  */
 public static function get($pattern)
 {
     $file = ARTICHOW_PATTERN . DIRECTORY_SEPARATOR . $pattern . '.php';
     if (is_file($file)) {
         require_once $file;
         $class = $pattern . 'Pattern';
         if (class_exists($class)) {
             return new $class();
         } else {
             awImage::drawError("Class Pattern: Class '" . $class . "' does not exist.");
         }
     } else {
         awImage::drawError("Class Pattern: Pattern '" . $pattern . "' does not exist.");
     }
 }
 function create()
 {
     $group = new PlotGroup();
     $group->setSpace(2, 2, 2, 0);
     $group->setPadding(30, 10, NULL, NULL);
     $group->grid->hideVertical(TRUE);
     $group->grid->setType(LINE_DASHED);
     $yForeground = $this->getArg('yForeground');
     $yBackground = $this->getArg('yBackground');
     $legendForeground = $this->getArg('legendForeground');
     $legendBackground = $this->getArg('legendBackground');
     $colorForeground = $this->getArg('colorForeground', new LightBlue(10));
     $colorBackground = $this->getArg('colorBackground', new Orange(25));
     if ($yForeground === NULL) {
         awImage::drawError("Class BarDepthPattern: Argument 'yForeground' must not be NULL.");
     }
     // Background
     if ($yBackground !== NULL) {
         $plot = $this->getPlot($yBackground, 6);
         $plot->setBarColor($colorBackground);
         $group->add($plot);
         if ($legendBackground !== NULL) {
             $group->legend->add($plot, $legendBackground, LEGEND_BACKGROUND);
         }
     }
     // Foreground
     $plot = $this->getPlot($yForeground, 0);
     $plot->setBarColor($colorForeground);
     $group->add($plot);
     if ($legendForeground !== NULL) {
         $group->legend->add($plot, $legendForeground, LEGEND_BACKGROUND);
     }
     $group->axis->bottom->hideTicks(TRUE);
     $group->legend->shadow->setSize(0);
     $group->legend->setAlign(LEGEND_CENTER);
     $group->legend->setSpace(6);
     $group->legend->setTextFont(new Tuffy(8));
     $group->legend->setPosition(0.5, 0.1);
     $group->legend->setBackgroundColor(new Color(255, 255, 255, 10));
     $group->legend->setColumns(2);
     return $group;
 }
Exemple #5
0
 function getTextHeight(&$text)
 {
     $font = $text->getFont();
     if ($this->isCompatibleWithFont($font) === FALSE) {
         awImage::drawError('Class MingDriver: Incompatible font type (\'' . get_class($font) . '\')');
     }
     // Ming only supports FileFont
     $fontDriver = $this->fileFontDriver;
     return $fontDriver->getTextHeight($text, $this);
 }
 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);
     }
 }
Exemple #7
0
 private function getGDAverageWidth(awFileFont $font)
 {
     $text = "azertyuiopqsdfghjklmmmmmmmwxcvbbbn,;:!?.";
     $box = imagettfbbox($font->size, 0, $font->font . '.' . $font->getExtension(), $text);
     if ($box === FALSE) {
         awImage::drawError("Class FileFontDriver: Unable to get font average width.");
     }
     list(, , $x2, $y2, , , $x1, $y1) = $box;
     return abs($x2 - $x1) / strlen($text);
 }
Exemple #8
0
 /**
  * Draw border as an ellipse
  *
  * @param $driver
  * @param $center Ellipse center
  * @param int $width Ellipse width
  * @param int $height Ellipse height
  */
 function ellipse($driver, $center, $width, $height)
 {
     // Border is hidden
     if ($this->hide) {
         return;
     }
     switch ($this->style) {
         case LINE_SOLID:
             $driver->ellipse($this->color, $center, $width, $height);
             break;
         default:
             awImage::drawError("Class Border: Dashed and dotted borders and not yet implemented on ellipses.");
             break;
     }
 }
Exemple #9
0
 private function checkArray(&$array)
 {
     if (is_array($array) === FALSE) {
         awImage::drawError("Class Pie: You tried to set values that are not an array.");
     }
     foreach ($array as $key => $value) {
         if (is_numeric($value) === FALSE) {
             unset($array[$key]);
         }
     }
     if (count($array) < 1) {
         awImage::drawError("Class Pie: Your graph must have at least 1 value.");
     }
 }
Exemple #10
0
	/**
	 * Draw an image here
	 *
	 * @param awImage $image Image
	 * @param int $d1 Destination top-left position
	 * @param int $d2 Destination bottom-right position
	 * @param int $s1 Source top-left position
	 * @param int $s2 Source bottom-right position
	 * @param bool $resample Resample image ? (default to TRUE)
	 */
	public function copyResizeImage(awImage $image, awPoint $d1, awPoint $d2, awPoint $s1, awPoint $s2, $resample = TRUE) {
		
		if($resample) {
			$function = 'imagecopyresampled';
		} else {
			$function = 'imagecopyresized';
		}
		
		$drawer = $image->getDrawer();
	
		$function(
			$this->resource,
			$drawer->resource,
			$this->x + $d1->x, $this->y + $d1->y,
			$s1->x, $s1->y,
			$d2->x - $d1->x, $d2->y - $d1->y,
			$s2->x - $s1->x, $s2->y - $s1->y
		);
	
	}
 /**
  * Construct a new awAntiSpam image
  *
  * @param string $string A string to display
  */
 public function __construct($string = '')
 {
     parent::__construct();
     $this->string = (string) $string;
 }
Exemple #12
0
 private function checkArray(&$array)
 {
     if (is_array($array) === FALSE) {
         awImage::drawError("Class Plot: You tried to set a value that is not an array.");
     }
     foreach ($array as $key => $value) {
         if (is_numeric($value) === FALSE and is_null($value) === FALSE) {
             awImage::drawError("Class Plot: Expected numeric values for the plot.");
         }
     }
     if (count($array) < 1) {
         awImage::drawError("Class Plot: Your plot must have at least 1 value.");
     }
 }
 /**
  * Center Y values of the axis
  *
  * @param awAxis $axis An axis
  * @param float $value The reference value on the axis
  */
 public function setYCenter(awAxis $axis, $value)
 {
     // Check vector angle
     if ($this->line->isHorizontal() === FALSE) {
         awImage::drawError("Class Axis: setYCenter() can only be used on horizontal axes.");
     }
     $p = $axis->getPointFromValue($value);
     $this->line->setY($p->y, $p->y);
 }
Exemple #14
0
 protected function ellipseLinearGradient(awGradient $gradient, $x1, $y1, $x2, $y2)
 {
     // Gauche->droite : 90°
     if ($y1 - $y2 > 0) {
         if ($y1 - $y2 != $x2 - $x1) {
             awImage::drawError("Class GDGradientDriver: Linear gradients are only implemented on circle, not ellipses.");
         }
         $r = ($x2 - $x1) / 2;
         // Init gradient
         $this->init($gradient, $x2 - $x1);
         for ($i = -$r; $i <= $r; $i++) {
             $h = sin(acos($i / $r)) * $r;
             $color = $this->color($i + $r);
             if ($gradient->angle === 90) {
                 // Print the line
                 $p1 = new awPoint($x1 + $i + $r, round(max($y2 + $r - $h + 1, $y2)));
                 $p2 = new awPoint($x1 + $i + $r, round(min($y1 - $r + $h - 1, $y1)));
             } else {
                 // Print the line
                 $p1 = new awPoint(round(max($x1 + $r - $h + 1, $x1)), $y2 + $i + $r);
                 $p2 = new awPoint(round(min($x2 - $r + $h - 1, $x2)), $y2 + $i + $r);
             }
             $this->driver->filledRectangle($color, new awLine($p1, $p2));
             unset($color);
         }
     }
 }
Exemple #15
0
 /**
  * Add a filled area
  *
  * @param int $start Begining of the area
  * @param int $end End of the area
  * @param mixed $background Background color or gradient of the area
  */
 public function setFilledArea($start, $stop, $background)
 {
     if ($stop <= $start) {
         awImage::drawError("Class LinePlot: End position can not be greater than begin position in setFilledArea().");
     }
     $this->areas[] = array((int) $start, (int) $stop, $background);
 }
 /**
  * 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, $alternativeSize = 0)
 {
     parent::__construct();
     $this->setSize($width, $height, $alternativeSize);
     $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);
 }
Exemple #17
0
 function drawError($message)
 {
     static $errorWriting;
     if ($errorWriting) {
         return;
     }
     $errorWriting = TRUE;
     $message = wordwrap($message, 40, "\n", TRUE);
     $width = 400;
     $height = max(100, 40 + 22.5 * (substr_count($message, "\n") + 1));
     $image = new awImage();
     $image->setSize($width, $height);
     $image->setDriver('gd');
     $driver = $image->getDriver();
     $driver->init($image);
     // Display title
     $driver->filledRectangle(new awWhite(), new awLine(new awPoint(0, 0), new awPoint($width, $height)));
     $driver->filledRectangle(new awRed(), new awLine(new awPoint(0, 0), new awPoint(110, 25)));
     $text = new awText("Artichow error", new awFont3(), new awWhite(), 0);
     $driver->string($text, new awPoint(5, 6));
     // Display red box
     $driver->rectangle(new awRed(), new awLine(new awPoint(0, 25), new awPoint($width - 90, $height - 1)));
     // Display error image
     $file = ARTICHOW_IMAGE . DIRECTORY_SEPARATOR . 'error.png';
     $imageError = new awFileImage($file);
     $driver->copyImage($imageError, new awPoint($width - 81, $height - 81), new awPoint($width - 1, $height - 1));
     // Draw message
     $text = new awText(strip_tags($message), new awFont2(), new awBlack(), 0);
     $driver->string($text, new awPoint(10, 40));
     $image->send();
     exit;
 }
 private function drawImage(awImage $image, $return = FALSE, $header = TRUE)
 {
     // Send headers to the browser
     if ($header === TRUE) {
         $image->sendHeaders();
     }
     if ($return) {
         ob_start();
     }
     $this->movie->output();
     if ($return) {
         return ob_get_clean();
     }
 }
Exemple #19
0
function errorHandlerArtichow($level, $message, $file, $line)
{
    awImage::drawError($message . ' in ' . $file . ' on line ' . $line . '.');
}
Exemple #20
0
 private function cache($data)
 {
     if (ARTICHOW_CACHE and $this->name !== NULL) {
         if (is_writable(ARTICHOW_CACHE_DIRECTORY) === FALSE) {
             awImage::drawError("Class Graph: Cache directory is not writable.");
         }
         file_put_contents($this->fileCache, $data);
         file_put_contents($this->fileCacheTime, $this->timeout . "\n" . $this->getFormatString());
     }
 }
Exemple #21
0
 /**
  * Construct a new awAntiSpam image
  *
  * @param string $string A string to display
  */
 function awAntiSpam($string = '')
 {
     parent::awImage();
     $this->string = (string) $string;
 }