コード例 #1
0
ファイル: Axis.class.php プロジェクト: remyyounes/dolibarr
	protected function drawLabels($drawer) {
		
		if($this->labelNumber !== NULL) {
			list($min, $max) = $this->range;
			$number = $this->labelNumber - 1;
			if($number < 1) {
				return;
			}
			$function = $this->rangeCallback['toValue'];
			$labels = array();
			for($i = 0; $i <= $number; $i++) {
				$labels[] = $function($i / $number, $min, $max);
			}
			$this->label->set($labels);
		}
		
		$labels = $this->label->count();
		
		for($i = 0; $i < $labels; $i++) {
		
			$p = $this->getPointFromValue($this->label->get($i));
			$this->label->draw($drawer, $p, $i);
		
		}
		
	}
コード例 #2
0
 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);
     }
 }