From 866658cded5b92ddb2681dead1ebaf111d712fcc Mon Sep 17 00:00:00 2001 From: cassiopc Date: Mon, 6 Aug 2012 11:09:10 +0200 Subject: init --- boca-1.5.0/src/libchart/classes/VerticalChart.php | 169 ++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 boca-1.5.0/src/libchart/classes/VerticalChart.php (limited to 'boca-1.5.0/src/libchart/classes/VerticalChart.php') diff --git a/boca-1.5.0/src/libchart/classes/VerticalChart.php b/boca-1.5.0/src/libchart/classes/VerticalChart.php new file mode 100644 index 0000000..cdb4117 --- /dev/null +++ b/boca-1.5.0/src/libchart/classes/VerticalChart.php @@ -0,0 +1,169 @@ +setLabelMarginLeft(50); + $this->setLabelMarginRight(30); + $this->setLabelMarginTop(40); + $this->setLabelMarginBottom(50); + } + + /** + * Print the axis + * + * @access private + */ + + function printAxis() + { + // Check if some points were defined + + if(!$this->sampleCount) + return; + + $minValue = $this->axis->getLowerBoundary(); + $maxValue = $this->axis->getUpperBoundary(); + $stepValue = $this->axis->getTics(); + + // Vertical axis + + for($value = $minValue; $value <= $maxValue; $value += $stepValue) + { + $y = $this->graphBRY - ($value - $minValue) * ($this->graphBRY - $this->graphTLY) / ($this->axis->displayDelta); + + imagerectangle($this->img, $this->graphTLX - 3, $y, $this->graphTLX - 2, $y + 1, $this->axisColor1->getColor($this->img)); + imagerectangle($this->img, $this->graphTLX - 1, $y, $this->graphTLX, $y + 1, $this->axisColor2->getColor($this->img)); + + $this->text->printText($this->img, $this->graphTLX - 5, $y, $this->textColor, $value, $this->text->fontCondensed, $this->text->HORIZONTAL_RIGHT_ALIGN | $this->text->VERTICAL_CENTER_ALIGN); + } + + // Horizontal Axis + + $columnWidth = ($this->graphBRX - $this->graphTLX) / $this->sampleCount; + + reset($this->point); + + for($i = 0; $i <= $this->sampleCount; $i++) + { + $x = $this->graphTLX + $i * $columnWidth; + + imagerectangle($this->img, $x - 1, $this->graphBRY + 2, $x, $this->graphBRY + 3, $this->axisColor1->getColor($this->img)); + imagerectangle($this->img, $x - 1, $this->graphBRY, $x, $this->graphBRY + 1, $this->axisColor2->getColor($this->img)); + + if($i < $this->sampleCount) + { + $point = current($this->point); + next($this->point); + + $text = $point->getX(); + + $this->text->printDiagonal($this->img, $x + $columnWidth * 1 / 3, $this->graphBRY + 10, $this->textColor, $text); + } + } + } + + /** + * Print the bars + * + * @access private + */ + + function printBar() + { + // Check if some points were defined + + if(!$this->sampleCount) + return; + + reset($this->point); + + $minValue = $this->axis->getLowerBoundary(); + $maxValue = $this->axis->getUpperBoundary(); + $stepValue = $this->axis->getTics(); + + $columnWidth = ($this->graphBRX - $this->graphTLX) / $this->sampleCount; + + for($i = 0; $i < $this->sampleCount; $i++) + { + $x = $this->graphTLX + $i * ($this->graphBRX - $this->graphTLX) / $this->sampleCount; + + $point = current($this->point); + next($this->point); + + $value = $point->getY(); + + $ymin = $this->graphBRY - ($value - $minValue) * ($this->graphBRY - $this->graphTLY) / ($this->axis->displayDelta); + + $this->text->printText($this->img, $x + $columnWidth / 2, $ymin - 5, $this->textColor, $value, $this->text->fontCondensed, $this->text->HORIZONTAL_CENTER_ALIGN | $this->text->VERTICAL_BOTTOM_ALIGN); + + // Vertical bar + + $x1 = $x + $columnWidth * 1 / 5; + $x2 = $x + $columnWidth * 4 / 5; + + imagefilledrectangle($this->img, $x1, $ymin, $x2, $this->graphBRY - 1, $this->barColor2->getColor($this->img)); + imagefilledrectangle($this->img, $x1 + 1, $ymin + 1, $x2 - 4, $this->graphBRY - 1, $this->barColor1->getColor($this->img)); + } + } + + /** + * Render the chart image + * + * @access public + * @param string name of the file to render the image to (optional) + */ + + function render($fileName = null) + { + $this->computeBound(); + $this->computeLabelMargin(); + $this->createImage(); + $this->printLogo(); + $this->printTitle(); + $this->printAxis(); + $this->printBar(); + + if(isset($fileName)) + imagepng($this->img, $fileName); + else + imagepng($this->img); + } + } +?> -- cgit v1.2.3