/** * Init the drawing of the component */ public function init(awDrawer $drawer) { // Set component background $background = $this->getBackground(); if ($background !== NULL) { $p1 = new awPoint(0, 0); $p2 = new awPoint($this->w - 1, $this->h - 1); if ($background instanceof awImage) { $drawer->copyImage($background, $p1, $p2); } else { $drawer->filledRectangle($background, new awLine($p1, $p2)); } } }
/** * Draw the label * * @param awDrawer $drawer * @param awPoint $p Label center * @param int $key Text position in the array of texts (default to zero) */ public function drawSpecial(awDrawer $drawer, awPoint $p, $key = 0, $theText) { $theTextAW = new awText($theText); if ($key % $this->interval !== 0) { return; } // Hide all labels if ($this->hide) { return; } // Key is hidden if (array_key_exists($key, $this->hideKey)) { return; } // Hide first label if ($key === 0 and $this->hideFirst) { return; } // Hide last label if ($key === count($this->texts) - 1 and $this->hideLast) { return; } $text = $theTextAW; if ($text !== NULL) { // Value must be hidden if (in_array($text->getText(), $this->hideValue)) { return; } $x = $p->x; $y = $p->y; // Get padding list($left, $right, $top, $bottom) = $text->getPadding(); $font = $text->getFont(); $width = $font->getTextWidth($text); $height = $font->getTextHeight($text); switch ($this->hAlign) { case awLabel::RIGHT: $x -= $width + $right; break; case awLabel::CENTER: $x -= ($width - $left + $right) / 2; break; case awLabel::LEFT: $x += $left; break; } switch ($this->vAlign) { case awLabel::TOP: $y -= $height + $bottom; break; case awLabel::MIDDLE: $y -= ($height - $top + $bottom) / 2; break; case awLabel::BOTTOM: $y += $top; break; } $drawer->string($theTextAW, $this->move->move($x, $y)); } }
private function smoothFuture(awDrawer $drawer, awColor $color, $width, $height) { if ($this->smooth) { for ($i = 0; $i < $this->size; $i++) { for ($j = 0; $j <= $i; $j++) { $drawer->point($color, new awPoint($i, $this->size - $j - 1)); } } for ($i = 0; $i < $this->size; $i++) { for ($j = 0; $j <= $i; $j++) { $drawer->point($color, new awPoint($width - $this->size + $j, $height - $i - 1)); } } } }
public function drawComponent(awDrawer $drawer, $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) { $drawer->line($this->lineColor, new awLine($prev, $point, $this->lineStyle, $this->lineThickness)); } $prev = $point; } $this->lineColor->free(); } // 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)); $drawer->line($this->impulse, new awLine($zero, $point, awLine::SOLID, 1)); } } } // Draw marks and labels foreach ($polygon->all() as $key => $point) { $this->mark->draw($drawer, $point); $this->label->draw($drawer, $point, $key); } }
protected function line(awDrawer $drawer) { $drawer->line($this->color, $this->line); }
/** * Draw border as an ellipse * * @param awDrawer $drawer * @param awPoint $center Ellipse center * @param int $width Ellipse width * @param int $height Ellipse height */ public function ellipse(awDrawer $drawer, awPoint $center, $width, $height) { // Border is hidden if ($this->hide) { return; } switch ($this->style) { case awLine::SOLID: $drawer->ellipse($this->color, $center, $width, $height); break; default: trigger_error("Dashed and dotted borders and not yet implemented on ellipses", E_USER_ERROR); break; } }
protected function drawTick(awDrawer $drawer, awPoint $p, $from, $to) { // echo $this->size.':'.$angle.'|<b>'.cos($angle).'</b>/'; // The round avoid some errors in the calcul // For example, 12.00000008575245 becomes 12 $p1 = $p; $p2 = $p; if ($from !== NULL) { $p1 = $p1->move(round($this->size * cos($from), 6), round($this->size * sin($from) * -1, 6)); } if ($to !== NULL) { $p2 = $p2->move(round($this->size * cos($to), 6), round($this->size * sin($to) * -1, 6)); } //echo $p1->x.':'.$p2->x.'('.$p1->y.':'.$p2->y.')'.'/'; $vector = new awVector($p1, $p2); $drawer->line($this->color, $vector); }
public function drawComponent(awDrawer $drawer, $x1, $y1, $x2, $y2, $aliasing) { if ($this->lineMode === awLinePlot::MIDDLE) { $inc = $this->xAxis->getDistance(0, 1) / 2; } else { $inc = 0; } $p1 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStart, $this->lineValue)); $p2 = awAxis::toPosition($this->xAxis, $this->yAxis, new awPoint($this->lineStop, $this->lineValue)); $drawer->line($this->lineColor, new awLine($p1->move($inc, 0), $p2->move($inc, 0), $this->lineStyle, $this->lineThickness)); $this->lineColor->free(); }
private function drawGrid(awDrawer $drawer, awColor $color, $nx, $ny, $x1, $y1, $x2, $y2, $type, $space, $hInterval, $vInterval) { list($left, $right, $top, $bottom) = $space; $width = $x2 - $x1 - $left - $right; $height = $y2 - $y1 - $top - $bottom; foreach ($nx as $key => $n) { if ($key % $vInterval === 0) { $pos = (int) round($x1 + $left + $n * $width); $drawer->line($color, new awLine(new awPoint($pos, $y1), new awPoint($pos, $y2), $type)); } } foreach ($ny as $key => $n) { if ($key % $hInterval === 0) { $pos = (int) round($y1 + $top + $n * $height); $drawer->line($color, new awLine(new awPoint($x1, $pos), new awPoint($x2, $pos), $type)); } } }
public function draw(awDrawer $drawer) { if ($this->hide) { return; } $count = $this->count(); // No legend to print if ($count === 0) { return; } // Get text widths and heights of each element of the legend $widths = array(); $heights = array(); $texts = array(); for ($i = 0; $i < $count; $i++) { list(, $title, ) = $this->legends[$i]; $text = new awText($title, $this->textFont, $this->textColor, 0); $font = $text->getFont(); $widths[$i] = $font->getTextWidth($text) + $this->textMargin->left + $this->textMargin->right; $heights[$i] = $font->getTextHeight($text); $texts[$i] = $text; } // Maximum height of the font used $heightMax = array_max($heights); // Get number of columns if ($this->columns !== NULL) { $columns = $this->columns; } else { if ($this->rows !== NULL) { $columns = ceil($count / $this->rows); } else { $columns = $count; } } // Number of rows $rows = (int) ceil($count / $columns); // Get maximum with of each column $widthMax = array(); for ($i = 0; $i < $count; $i++) { // Get column width $column = $i % $columns; if (array_key_exists($column, $widthMax) === FALSE) { $widthMax[$column] = $widths[$i]; } else { $widthMax[$column] = max($widthMax[$column], $widths[$i]); } } $width = $this->padding[0] + $this->padding[1] - $this->space; for ($i = 0; $i < $columns; $i++) { $width += $this->space + 5 + 10 + $widthMax[$i]; } $height = ($heightMax + $this->space) * $rows - $this->space + $this->padding[2] + $this->padding[3]; // Look for legends position list($x, $y) = $drawer->getSize(); $p = new awPoint($this->position->x * $x, $this->position->y * $y); switch ($this->hAlign) { case awLegend::CENTER: $p->x -= $width / 2; break; case awLegend::RIGHT: $p->x -= $width; break; } switch ($this->vAlign) { case awLegend::MIDDLE: $p->y -= $height / 2; break; case awLegend::BOTTOM: $p->y -= $height; break; } // Draw legend shadow $this->shadow->draw($drawer, $p, $p->move($width, $height), awShadow::OUT); // Draw legends base $this->drawBase($drawer, $p, $width, $height); // Draw each legend for ($i = 0; $i < $count; $i++) { list($component, $title, $type) = $this->legends[$i]; $column = $i % $columns; $row = (int) floor($i / $columns); // Get width of all previous columns $previousColumns = 0; for ($j = 0; $j < $column; $j++) { $previousColumns += $this->space + 10 + 5 + $widthMax[$j]; } // Draw legend text $drawer->string($texts[$i], $p->move($this->padding[0] + $previousColumns + 10 + 5 + $this->textMargin->left, $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $heights[$i] / 2)); // Draw legend icon switch ($type) { case awLegend::LINE: case awLegend::MARK: case awLegend::MARKONLY: // Get vertical position $x = $this->padding[0] + $previousColumns; $y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $component->getLegendLineThickness(); // Draw two lines if ($component->getLegendLineColor() !== NULL) { $color = $component->getLegendLineColor(); if ($color instanceof awColor and $type !== awLegend::MARKONLY) { $drawer->line($color, new awLine($p->move($x, $y + $component->getLegendLineThickness() / 2), $p->move($x + 10, $y + $component->getLegendLineThickness() / 2), $component->getLegendLineStyle(), $component->getLegendLineThickness())); $color->free(); unset($color); } } if ($type === awLegend::MARK or $type === awLegend::MARKONLY) { $mark = $component->getLegendMark(); if ($mark !== NULL) { $mark->draw($drawer, $p->move($x + 5.5, $y + $component->getLegendLineThickness() / 2)); } unset($mark); } break; case awLegend::BACKGROUND: // Get vertical position $x = $this->padding[0] + $previousColumns; $y = $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - 5; $from = $p->move($x, $y); $to = $p->move($x + 10, $y + 10); $background = $component->getLegendBackground(); if ($background !== NULL) { $drawer->filledRectangle($component->getLegendBackground(), new awLine($from, $to)); // Draw rectangle border $this->border->rectangle($drawer, $from->move(0, 0), $to->move(0, 0)); } unset($background, $from, $to); break; } } // Draw legend text /* $drawer->string( $texts[$i], $p->move( $this->padding[0] + $previousColumns + 10 + 5 + $this->textMargin->left, $this->padding[2] + $row * ($heightMax + $this->space) + $heightMax / 2 - $heights[$i] / 2 ) );*/ $text1 = new awText('Weekly', new Tuffy(8), new Color(0, 0, 0, 0), 0); $text2 = new awText('Monthly', new Tuffy(8), new Color(0, 0, 0, 0), 0); $text3 = new awText('Yearly', new Tuffy(8), new Color(0, 0, 0, 0), 0); $point1 = new awPoint(412, 7); $point2 = new awPoint(412, 30); $point3 = new awPoint(412, 54); $drawer->string($text1, $point1); $drawer->string($text2, $point2); $drawer->string($text3, $point3); }