コード例 #1
0
 public function drawComponent(awDriver $driver, $x1, $y1, $x2, $y2, $aliasing)
 {
     $count = count($this->datay);
     // Get start and stop values
     list($start, $stop) = $this->getLimit();
     // Build the polygon
     $polygon = new awPolygon();
     for ($key = 0; $key < $count; $key++) {
         $x = $this->datax[$key];
         $y = $this->datay[$key];
         if ($y !== NULL) {
             $p = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($x, $y));
             $polygon->set($key, $p);
         } else {
             if ($this->linkNull === FALSE) {
                 $polygon->set($key, NULL);
             }
         }
     }
     // Link points if needed
     if ($this->link) {
         $prev = NULL;
         foreach ($polygon->all() as $point) {
             if ($prev !== NULL and $point !== NULL) {
                 $driver->line($this->lineColor, new awLine($prev, $point, $this->lineStyle, $this->lineThickness));
             }
             $prev = $point;
         }
     }
     // Draw impulses
     if ($this->impulse instanceof awColor) {
         foreach ($polygon->all() as $key => $point) {
             if ($point !== NULL) {
                 $zero = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($key, 0));
                 $driver->line($this->impulse, new awLine($zero, $point, awLine::SOLID, 1));
             }
         }
     }
     // Draw marks and labels
     foreach ($polygon->all() as $key => $point) {
         $this->mark->draw($driver, $point);
         $this->label->draw($driver, $point, $key);
     }
 }
コード例 #2
0
ファイル: gd.class.php プロジェクト: greench/prestashop
 protected function polygonLinearGradient(awLinearGradient $gradient, awPolygon $polygon)
 {
     $count = $polygon->count();
     if ($count >= 4) {
         $left = $polygon->get(0);
         $right = $polygon->get($count - 1);
         if ($gradient->angle === 0) {
             // Get polygon maximum and minimum
             $offset = $polygon->get(0);
             $max = $min = $offset->y;
             for ($i = 1; $i < $count - 1; $i++) {
                 $offset = $polygon->get($i);
                 $max = max($max, $offset->y);
                 $min = min($min, $offset->y);
             }
             $this->init($gradient, $max - $min);
             $prev = $polygon->get(1);
             $sum = 0;
             for ($i = 2; $i < $count - 1; $i++) {
                 $current = $polygon->get($i);
                 $interval = 1;
                 if ($i !== $count - 2) {
                     $current->x -= $interval;
                 }
                 if ($current->x - $prev->x > 0) {
                     // Draw rectangle
                     $x1 = $prev->x;
                     $x2 = $current->x;
                     $y1 = max($prev->y, $current->y);
                     $y2 = $left->y;
                     $gradient = new awLinearGradient($this->color($max - $min - ($y2 - $y1)), $this->color($max - $min), 0);
                     if ($y1 > $y2) {
                         $y2 = $y1;
                     }
                     $this->driver->filledRectangle($gradient, awLine::build($x1, $y1, $x2, $y2));
                     $top = $prev->y < $current->y ? $current : $prev;
                     $bottom = $prev->y >= $current->y ? $current : $prev;
                     $gradient = new awLinearGradient($this->color($bottom->y - $min), $this->color($max - $min - ($y2 - $y1)), 0);
                     $gradientDriver = new awGDGradientDriver($this->driver);
                     $gradientDriver->drawFilledFlatTriangle($gradient, new awPoint($prev->x, min($prev->y, $current->y)), $top, new awPoint($current->x, min($prev->y, $current->y)));
                     unset($gradientDriver);
                     $sum += $current->x - $prev->x;
                 }
                 $prev = $current;
                 $prev->x += $interval;
             }
         } elseif ($gradient->angle === 90) {
             $width = $right->x - $left->x;
             $this->init($gradient, $width);
             $pos = 1;
             $next = $polygon->get($pos++);
             $this->next($polygon, $pos, $prev, $next);
             for ($i = 0; $i <= $width; $i++) {
                 $x = $left->x + $i;
                 $y1 = round($prev->y + ($next->y - $prev->y) * (($i + $left->x - $prev->x) / ($next->x - $prev->x)));
                 $y2 = $left->y;
                 // Draw line
                 $color = $this->color($i);
                 // YaPB : PHP does not handle alpha on lines
                 $this->driver->filledRectangle($color, awLine::build($x, $y1, $x, $y2));
                 unset($color);
                 // Jump to next point
                 if ($next->x == $i + $left->x) {
                     $this->next($polygon, $pos, $prev, $next);
                 }
             }
         }
     } elseif ($count === 3) {
         $this->drawFilledTriangle($gradient, $polygon);
     }
 }
コード例 #3
0
ファイル: LinePlot.class.php プロジェクト: greench/prestashop
 protected function drawArea(awDriver $driver, awPolygon $polygon)
 {
     $starts = array();
     foreach ($this->areas as $area) {
         list($start) = $area;
         $starts[$start] = TRUE;
     }
     // Draw filled areas
     foreach ($this->areas as $area) {
         list($start, $stop, $background) = $area;
         $polygonArea = new awPolygon();
         $p = $this->xAxisPoint($start);
         $polygonArea->append($p);
         for ($i = $start; $i <= $stop; $i++) {
             $p = clone $polygon->get($i);
             if ($i === $stop and array_key_exists($stop, $starts)) {
                 $p = $p->move(-1, 0);
             }
             $polygonArea->append($p);
         }
         $p = $this->xAxisPoint($stop);
         if (array_key_exists($stop, $starts)) {
             $p = $p->move(-1, 0);
         }
         $polygonArea->append($p);
         // Draw area
         $driver->filledPolygon($background, $polygonArea);
     }
 }
コード例 #4
0
 /**
  * Draw a polygon with a background
  *
  * @param mixed $background Background (can be a color or a gradient)
  * @param Polygon A polygon
  */
 public function filledPolygon($background, awPolygon $polygon)
 {
     $shape = new SWFShape();
     if ($background instanceof awColor) {
         list($red, $green, $blue, $alpha) = $this->getColor($background);
         $shape->setRightFill($red, $green, $blue, $alpha);
     } elseif ($background instanceof awGradient) {
         list($flashGradient, $style) = $this->getGradient($background);
         $fill = $shape->addFill($flashGradient, $style);
         list($xMin, $xMax) = $polygon->getBoxXRange();
         list($yMin, $yMax) = $polygon->getBoxYRange();
         if ($background->angle === 0) {
             $fill->scaleTo(($yMax - $yMin) / 1600);
         } else {
             $fill->scaleTo(($xMax - $xMin) / 1600);
         }
         $fill->moveTo($xMin + ($xMax - $xMin) / 2, $yMin + ($yMax - $yMin) / 2);
         $shape->setRightFill($fill);
     }
     $points = $polygon->all();
     $count = count($points);
     if ($count > 1) {
         $prev = $points[0];
         $shape->movePenTo($prev->x, $prev->y);
         for ($i = 1; $i < $count; $i++) {
             $current = $points[$i];
             $shape->drawLineTo($current->x, $current->y);
         }
         // Close the polygon
         $shape->drawLineTo($prev->x, $prev->y);
         $this->movie->add($shape);
     }
 }
コード例 #5
0
ファイル: Mark.class.php プロジェクト: rhertzog/lcs
 function drawRhombus($point)
 {
     list($x, $y) = $point->getLocation();
     $rhombus = new awPolygon();
     // Set default style and thickness
     $rhombus->setStyle(POLYGON_SOLID);
     $rhombus->setThickness(1);
     // Top of the rhombus
     $rhombus->append(new awPoint($x, $y - $this->size / 2));
     // Right of the rhombus
     $rhombus->append(new awPoint($x + $this->size / 2, $y));
     // Bottom of the rhombus
     $rhombus->append(new awPoint($x, $y + $this->size / 2));
     // Left of the rhombus
     $rhombus->append(new awPoint($x - $this->size / 2, $y));
     $this->driver->filledPolygon($this->fill, $rhombus);
     if ($this->border->visible()) {
         $this->border->polygon($this->driver, $rhombus);
     }
 }
コード例 #6
0
 /**
  * Draws the last line of a Polygon, between the first and last point
  * 
  * @param awDriver $driver A Driver object
  * @param awPolygon $polygon The polygon object to close
  */
 private function closePolygon(awDriver $driver, awPolygon $polygon)
 {
     $first = $polygon->get(0);
     $last = $polygon->get($polygon->count() - 1);
     $line = new awLine($first, $last, $this->style, $polygon->getThickness());
     $driver->line($this->color, $line);
 }
コード例 #7
0
 /**
  * Returns TRUE if the line is going all the way from the left side
  * to the right side of the polygon surrounding box.
  * 
  * @param $polygon Polygon A Polygon object
  * @return bool
  */
 public function isLeftToRight(awPolygon $polygon)
 {
     list($xMin, $xMax) = $polygon->getBoxXRange();
     list($yMin, $yMax) = $polygon->getBoxYRange();
     if ($this->isVertical()) {
         return FALSE;
     } else {
         if ($this->p1->x < $this->p2->x) {
             $left = $this->p1;
             $right = $this->p2;
         } else {
             $left = $this->p2;
             $right = $this->p1;
         }
     }
     return $this->isOnBoxLeftSide($left, $yMin, $yMax, $xMin) and $this->isOnBoxRightSide($right, $yMin, $yMax, $xMax);
 }