/** * Get max value for X axis * * @return float $value */ public function getXMax() { return ceil(is_null($this->xMax) ? array_max($this->datax) : (double) $this->xMax) + ($this->getXCenter() ? 1 : 0); }
public function draw(awDriver $driver) { 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] = $driver->getTextWidth($text) + $this->textMargin->left + $this->textMargin->right; $heights[$i] = $driver->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) = $driver->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($driver, $p, $p->move($width, $height), awShadow::OUT); // Draw legends base $this->drawBase($driver, $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 $driver->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) { $driver->line($color, new awLine($p->move($x, $y + $component->getLegendLineThickness() / 2), $p->move($x + 10, $y + $component->getLegendLineThickness() / 2), $component->getLegendLineStyle(), $component->getLegendLineThickness())); unset($color); } } if ($type === awLegend::MARK or $type === awLegend::MARKONLY) { $mark = $component->getLegendMark(); if ($mark !== NULL) { $mark->draw($driver, $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) { $driver->filledRectangle($component->getLegendBackground(), new awLine($from, $to)); // Draw rectangle border $this->border->rectangle($driver, $from->move(0, 0), $to->move(0, 0)); } unset($background, $from, $to); break; } } }
public function getXMax() { return array_max($this->datax) + 1; }
$plot->barShadow->setSize(3); $plot->barShadow->setPosition(SHADOW_RIGHT_TOP); $plot->barShadow->setColor(new Color(180, 180, 180, 10)); $plot->barShadow->smooth(TRUE); $mois = array('Jan', 'Fév', 'Mar', 'Avr', 'Mai', 'Jun', 'Juil', 'Août', 'Sept', 'Oct', 'Nov', 'Déc'); $label = array(); foreach ($mois as $m) { $label[] = $m; } $label[] = ' '; foreach ($mois as $m) { $label[] = $m; } $plot->xAxis->setLabelText($label); /* ICI */ $max = array_max($values); $yValues = array(); for ($i = 0; $i <= $max; $i++) { $yValues[] = $i; } $plot->yAxis->setLabelText($yValues); // Image::drawError(var_export($yValues, TRUE)); $plot->yAxis->setLabelText($yValues); $plot->setPadding(30, 5, 20, 15); $labelAvant = new Label("2005"); $labelAvant->setFont(new TTFFont(ARTICHOW_FONT . '/TuffyBold.ttf', 12)); $labelAvant->move(180, 10); $labelMaintenant = new Label("2006"); $labelMaintenant->setFont(new TTFFont(ARTICHOW_FONT . '/TuffyBold.ttf', 12)); $labelMaintenant->move(450, 10); $graph->add($plot);
/** * 返回数组中的最大值 */ public static function max($array) { return array_max($array); }
/** * Draw image */ public function draw() { $fonts = array(ARTICHOW_FONT . DIRECTORY_SEPARATOR . 'Tuffy.ttf', ARTICHOW_FONT . DIRECTORY_SEPARATOR . 'TuffyBold.ttf', ARTICHOW_FONT . DIRECTORY_SEPARATOR . 'TuffyItalic.ttf', ARTICHOW_FONT . DIRECTORY_SEPARATOR . 'TuffyBoldItalic.ttf'); $sizes = array(12, 12.5, 13, 13.5, 14, 15, 16, 17, 18, 19); $widths = array(); $heights = array(); $texts = array(); for ($i = 0; $i < strlen($this->string); $i++) { $fontKey = array_rand($fonts); $sizeKey = array_rand($sizes); $font = new awTTFFont($fonts[$fontKey], $sizes[$sizeKey]); $text = new awText($this->string[$i], $font, NULL, mt_rand(-15, 15)); $widths[] = $font->getTextWidth($text); $heights[] = $font->getTextHeight($text); $texts[] = $text; } $width = array_sum($widths); $height = array_max($heights); $totalWidth = $width + 10 + count($texts) * 10; $totalHeight = $height + 20; $this->setSize($totalWidth, $totalHeight); $this->create(); for ($i = 0; $i < strlen($this->string); $i++) { $this->drawer->string($texts[$i], new awPoint(5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10, 10 + ($height - $heights[$i]) / 2)); } $this->drawNoise($totalWidth, $totalHeight); $this->send(); }
/** * Draw image */ public function draw() { $fonts = array('Tuffy', 'TuffyBold', 'TuffyItalic', 'TuffyBoldItalic'); $sizes = array(12, 12.5, 13, 13.5, 14, 15, 16, 17, 18, 19); $widths = array(); $heights = array(); $texts = array(); // Set up a temporary driver to allow font size calculations... $this->setSize(10, 10); $driver = $this->getDriver(); for ($i = 0; $i < strlen($this->string); $i++) { $fontKey = array_rand($fonts); $sizeKey = array_rand($sizes); $font = new awTTFFont($fonts[$fontKey], $sizes[$sizeKey]); $text = new awText($this->string[$i], $font, NULL, mt_rand(-15, 15)); $widths[] = $driver->getTextWidth($text); $heights[] = $driver->getTextHeight($text); $texts[] = $text; } // ... and get rid of it. $this->driver = NULL; $width = array_sum($widths); $height = array_max($heights); $totalWidth = $width + 10 + count($texts) * 10; $totalHeight = $height + 20; $this->setSize($totalWidth, $totalHeight); $this->create(); for ($i = 0; $i < strlen($this->string); $i++) { $this->driver->string($texts[$i], new awPoint(5 + array_sum(array_slice($widths, 0, $i)) + $widths[$i] / 2 + $i * 10, 10 + ($height - $heights[$i]) / 2)); } $this->drawNoise($totalWidth, $totalHeight); $this->send(); }