summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-08-02 14:07:19 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-08-02 14:07:19 +0000
commit97902f4d7de3482cf110950544cc4a186dd84b11 (patch)
treef2e064cc92d0f5c3645aa312b6737f556f71dfe7 /src
parent21a3467e539669f6b8935db0668891a7507b3675 (diff)
downloadzetacomponents-graph-97902f4d7de3482cf110950544cc4a186dd84b11.zip
zetacomponents-graph-97902f4d7de3482cf110950544cc4a186dd84b11.tar.gz
- Added basic 3d renderer
# Several unresolved rendering issues - Fixed filled line charts in 2d renderer
Diffstat (limited to 'src')
-rw-r--r--src/charts/line.php9
-rw-r--r--src/graph_autoload.php5
-rw-r--r--src/interfaces/chart.php2
-rw-r--r--src/interfaces/renderer.php4
-rw-r--r--src/renderer/2d.php28
-rw-r--r--src/renderer/3d.php1314
-rw-r--r--src/structs/color.php20
7 files changed, 1303 insertions, 79 deletions
diff --git a/src/charts/line.php b/src/charts/line.php
index 733c1f7..b0ba8c0 100644
--- a/src/charts/line.php
+++ b/src/charts/line.php
@@ -81,8 +81,12 @@ class ezcGraphLineChart extends ezcGraphChart
$boundings->y0 += $yAxisSpace;
$boundings->y1 -= $yAxisSpace;
+ $yAxisNullPosition = $this->elements['yAxis']->getCoordinate( false );
+
+ $nr = count( $this->data );
foreach ( $this->data as $data )
{
+ --$nr;
// Determine fill color for dataset
if ( $this->options->fillLines !== false )
{
@@ -108,9 +112,12 @@ class ezcGraphLineChart extends ezcGraphChart
$data->color->default,
( $lastPoint === false ? $point : $lastPoint ),
$point,
+ $nr,
+ count( $this->data ),
$data->symbol[$key],
$data->color[$key],
- $fillColor
+ $fillColor,
+ $yAxisNullPosition
);
$lastPoint = $point;
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index f1ef3a8..217f27e 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -26,9 +26,10 @@ return array(
'ezcGraphUnknownColorDefinitionException' => 'Graph/exceptions/unknown_color_definition.php',
'ezcGraphRenderer' => 'Graph/interfaces/renderer.php',
- 'ezcGraphRenderer2D' => 'Graph/renderer/2d.php',
+ 'ezcGraphRenderer2d' => 'Graph/renderer/2d.php',
'ezcGraphRenderer2dOptions' => 'Graph/options/renderer_2d.php',
- 'ezcGraphRenderer3D' => 'Graph/renderer/3d.php',
+ 'ezcGraphRenderer3d' => 'Graph/renderer/3d.php',
+ 'ezcGraphRenderer3dOptions' => 'Graph/options/renderer_3d.php',
'ezcGraphInvalidRendererException' => 'Graph/exceptions/invalid_renderer.php',
'ezcGraphAxisLabelRenderer' => 'Graph/interfaces/axis_label_renderer.php',
diff --git a/src/interfaces/chart.php b/src/interfaces/chart.php
index ac50029..2411fad 100644
--- a/src/interfaces/chart.php
+++ b/src/interfaces/chart.php
@@ -78,7 +78,7 @@ abstract class ezcGraphChart implements ArrayAccess
// Define standard renderer and driver
$this->driver = new ezcGraphSvgDriver();
- $this->renderer = new ezcGraphRenderer2D();
+ $this->renderer = new ezcGraphRenderer2d();
$this->renderer->setDriver( $this->driver );
}
diff --git a/src/interfaces/renderer.php b/src/interfaces/renderer.php
index 01f628c..5abb86f 100644
--- a/src/interfaces/renderer.php
+++ b/src/interfaces/renderer.php
@@ -55,6 +55,8 @@ abstract class ezcGraphRenderer
* @param ezcGraphColor $color Color of line
* @param ezcGraphCoordinate $start Starting point
* @param ezcGraphCoordinate $end Ending point
+ * @param int $dataNumber Number of dataset
+ * @param int $dataCount Count of datasets in chart
* @param int $symbol Symbol to draw for line
* @param ezcGraphColor $symbolColor Color of the symbol, defaults to linecolor
* @param ezcGraphColor $fillColor Color to fill line with
@@ -67,6 +69,8 @@ abstract class ezcGraphRenderer
ezcGraphColor $color,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
+ $dataNumber = 1,
+ $dataCount = 1,
$symbol = ezcGraph::NO_SYMBOL,
ezcGraphColor $symbolColor = null,
ezcGraphColor $fillColor = null,
diff --git a/src/renderer/2d.php b/src/renderer/2d.php
index 9880025..8e54de0 100644
--- a/src/renderer/2d.php
+++ b/src/renderer/2d.php
@@ -243,6 +243,8 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
* @param ezcGraphColor $color Color of line
* @param ezcGraphCoordinate $start Starting point
* @param ezcGraphCoordinate $end Ending point
+ * @param int $dataNumber Number of dataset
+ * @param int $dataCount Count of datasets in chart
* @param int $symbol Symbol to draw for line
* @param ezcGraphColor $symbolColor Color of the symbol, defaults to linecolor
* @param ezcGraphColor $fillColor Color to fill line with
@@ -255,11 +257,13 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
ezcGraphColor $color,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
+ $dataNumber = 1,
+ $dataCount = 1,
$symbol = ezcGraph::NO_SYMBOL,
ezcGraphColor $symbolColor = null,
ezcGraphColor $fillColor = null,
$axisPosition = 0.,
- $thickness = 1 )
+ $thickness = 1)
{
// Perhaps fill up line
if ( $fillColor !== null &&
@@ -277,19 +281,19 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
array(
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $start->y
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y
),
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $end->y
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y
),
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
),
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
),
),
$fillColor,
@@ -302,7 +306,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
$startDiff = abs( $axisPosition - $start->y );
$endDiff = abs( $axisPosition - $end->y );
- $cuttingPosition = $startDiff / ( $endDiff / $startDiff );
+ $cuttingPosition = $startDiff / ( $endDiff + $startDiff );
$cuttingPoint = new ezcGraphCoordinate(
$start->x + ( $end->x - $start->x ) * $cuttingPosition,
$axisPosition
@@ -312,15 +316,15 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
array(
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
),
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $start->y
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y
),
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $cuttingPoint->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $cuttingPoint->y
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $cuttingPoint->y
),
),
$fillColor,
@@ -331,15 +335,15 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
array(
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
),
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $end->y
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y
),
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $cuttingPoint->x,
- $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $cuttingPoint->y
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $cuttingPoint->y
),
),
$fillColor,
diff --git a/src/renderer/3d.php b/src/renderer/3d.php
index c23b0ad..9d53af4 100644
--- a/src/renderer/3d.php
+++ b/src/renderer/3d.php
@@ -1,128 +1,1320 @@
<?php
/**
- * File containing the ezcGraphRenderer2D class
+ * File containing the three dimensional renderer
*
* @package Graph
* @version //autogentag//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @copyright Copyright (C) 2005,
+ 2006 eZ systems as. All rights reserved.
* @license http://ez.no/licenses/new_bsd New BSD License
*/
/**
- * Implements the two dimensional renderer for the graph component
+ * Class to transform chart primitives into image primitives
*
* @package Graph
*/
-class ezcGraphRenderer2D extends ezcGraphRenderer {
+class ezcGraphRenderer3d extends ezcGraphRenderer
+{
+
+ protected $pieSegmentLabels = array(
+ 0 => array(),
+ 1 => array(),
+ );
+
+ protected $pieSegmentBoundings = false;
+
+ protected $frontLines = array();
+
+ protected $circleSectors = array();
+
+ protected $options;
+
+ protected $depth = false;
+
+ protected $xDepthFactor = false;
+
+ protected $yDepthFactor = false;
+
+ protected $dataBoundings = false;
+
+ public function __construct( array $options = array() )
+ {
+ $this->options = new ezcGraphRenderer3dOptions( $options );
+ }
+
+ public function __get( $propertyName )
+ {
+ switch ( $propertyName )
+ {
+ case 'options':
+ return $this->options;
+ default:
+ throw new ezcBasePropertyNotFoundException( $propertyName );
+ }
+ }
/**
- * Draw a pie segment
+ * Draw pie segment
+ *
+ * Draws a single pie segment
*
- * @param ezcGraphCoordinate $position
- * @param mixed $radius
- * @param float $startAngle
- * @param float $endAngle
- * @param float $moveOut
- * @access public
+ * @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphColor $color Color of pie segment
+ * @param float $startAngle Start angle
+ * @param float $endAngle End angle
+ * @param string $label Label of pie segment
+ * @param float $moveOut Move out from middle for hilighting
* @return void
*/
- public function drawPieSegment( ezcGraphCoordinate $position, $radius, $startAngle = .0, $endAngle = 360., $moveOut = .0 )
+ public function drawPieSegment(
+ ezcGraphBoundings $boundings,
+ ezcGraphColor $color,
+ $startAngle = .0,
+ $endAngle = 360.,
+ $label = false,
+ $moveOut = false )
{
-
+ // Calculate position and size of pie
+ $center = new ezcGraphCoordinate(
+ $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 - $this->options->pieChartHeight / 2
+ );
+
+ // Limit radius to fourth of width and half of height at maximum
+ $radius = min(
+ ( $boundings->x1 - $boundings->x0 ) / 4,
+ ( $boundings->y1 - $boundings->y0 ) / 2
+ ) * ( 1 - $this->options->moveOut );
+
+ // Move pie segment out of the center
+ if ( $moveOut )
+ {
+ $direction = $startAngle + ( $endAngle - $startAngle ) / 2;
+
+ $center = new ezcGraphCoordinate(
+ $center->x + $this->options->moveOut * $radius * cos( deg2rad( $direction ) ),
+ $center->y + $this->options->moveOut * $radius * sin( deg2rad( $direction ) )
+ );
+ }
+
+ // Add circle sector to queue
+ $this->circleSectors[] = array(
+ 'center' => $center,
+ 'width' => $radius * 2,
+ 'height' => $radius * 2 * $this->options->pieChartRotation - $this->options->pieChartHeight,
+ 'start' => $startAngle,
+ 'end' => $endAngle,
+ 'color' => $color,
+ );
+
+ if ( $label )
+ {
+ // Determine position of label
+ $middle = $startAngle + ( $endAngle - $startAngle ) / 2;
+ $pieSegmentCenter = new ezcGraphCoordinate(
+ cos( deg2rad( $middle ) ) * $radius * 2 / 3 + $center->x,
+ sin( deg2rad( $middle ) ) * $radius * $this->options->pieChartRotation * 2 / 3 + $center->y
+ );
+
+ // Split labels up into left an right size and index them on their
+ // y position
+ $this->pieSegmentLabels[(int) ($pieSegmentCenter->x > $center->x)][$pieSegmentCenter->y] = array(
+ clone $pieSegmentCenter,
+ $label
+ );
+ }
+
+ if ( !$this->pieSegmentBoundings )
+ {
+ $this->pieSegmentBoundings = $boundings;
+ }
+ }
+
+ protected function finishPieSegmentLabels()
+ {
+ if ( $this->pieSegmentBoundings === false )
+ {
+ return true;
+ }
+
+ $boundings = $this->pieSegmentBoundings;
+
+ // Calculate position and size of pie
+ $center = new ezcGraphCoordinate(
+ $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2
+ );
+
+ // Limit radius to fourth of width and half of height at maximum
+ $radius = min(
+ ( $boundings->x1 - $boundings->x0 ) / 4,
+ ( $boundings->y1 - $boundings->y0 ) / 2
+ );
+
+ // Calculate maximum height of labels
+ $labelHeight = (int) round( min(
+ ( count( $this->pieSegmentLabels[0] )
+ ? ( $boundings->y1 - $boundings->y0 ) / count( $this->pieSegmentLabels[0] )
+ : ( $boundings->y1 - $boundings->y0 )
+ ),
+ ( count( $this->pieSegmentLabels[1] )
+ ? ( $boundings->y1 - $boundings->y0 ) / count( $this->pieSegmentLabels[1] )
+ : ( $boundings->y1 - $boundings->y0 )
+ ),
+ ( $boundings->y1 - $boundings->y0 ) * $this->options->maxLabelHeight
+ ) );
+
+ $symbolSize = $this->options->symbolSize;
+
+ foreach ( $this->pieSegmentLabels as $side => $labelPart )
+ {
+ $minHeight = $boundings->y0;
+ $toShare = ( $boundings->y1 - $boundings->y0 ) - count( $labelPart ) * $labelHeight;
+
+ // Sort to draw topmost label first
+ ksort( $labelPart );
+ $sign = ( $side ? -1 : 1 );
+
+ foreach ( $labelPart as $height => $label )
+ {
+ // Determine position of label
+ $minHeight += max( 0, $height - $minHeight - $labelHeight ) / ( $boundings->y1 - $boundings->y0 ) * $toShare;
+ $labelPosition = new ezcGraphCoordinate(
+ $center->x -
+ $sign * (
+ cos ( asin ( ( $center->y - $minHeight - $labelHeight / 2 ) / $radius ) ) * $radius +
+ $symbolSize * (int) $this->options->showSymbol
+ ),
+ $minHeight + $labelHeight / 2
+ );
+
+ if ( $this->options->showSymbol )
+ {
+ // Draw label
+ $this->driver->drawLine(
+ $label[0],
+ $labelPosition,
+ $this->options->font->color,
+ 1
+ );
+
+ $this->driver->drawCircle(
+ $label[0],
+ $symbolSize,
+ $symbolSize,
+ $this->options->font->color,
+ true
+ );
+ $this->driver->drawCircle(
+ $labelPosition,
+ $symbolSize,
+ $symbolSize,
+ $this->options->font->color,
+ true
+ );
+ }
+
+ $this->driver->drawTextBox(
+ $label[1],
+ new ezcGraphCoordinate(
+ ( !$side ? $boundings->x0 : $labelPosition->x + $symbolSize ),
+ $minHeight
+ ),
+ ( !$side ? $labelPosition->x - $boundings->x0 - $symbolSize : $boundings->x1 - $labelPosition->x - $symbolSize ),
+ $labelHeight,
+ ( !$side ? ezcGraph::RIGHT : ezcGraph::LEFT ) | ezcGraph::MIDDLE
+ );
+
+ // Add used space to minHeight
+ $minHeight += $labelHeight;
+ }
+ }
+ }
+
+ protected function finishCirleSectors()
+ {
+ // Draw circular arcs
+ foreach ( $this->circleSectors as $circleSector )
+ {
+ $this->driver->drawCircularArc(
+ $circleSector['center'],
+ $circleSector['width'],
+ $circleSector['height'],
+ $this->options->pieChartHeight,
+ $circleSector['start'],
+ $circleSector['end'],
+ $circleSector['color']
+ );
+ }
+
+ // Draw borders
+ foreach ( $this->circleSectors as $circleSector )
+ {
+ $darkenedColor = $circleSector['color']->darken( $this->options->dataBorder );
+
+ $this->driver->drawPolygon(
+ array(
+ $circleSector['center'],
+ new ezcGraphCoordinate(
+ $circleSector['center']->x,
+ $circleSector['center']->y + $this->options->pieChartHeight
+ ),
+ new ezcGraphCoordinate(
+ $circleSector['center']->x + cos( deg2rad( $circleSector['start'] ) ) * $circleSector['width'] / 2,
+ $circleSector['center']->y + sin( deg2rad( $circleSector['start'] ) ) * $circleSector['height'] / 2 + $this->options->pieChartHeight
+ ),
+ new ezcGraphCoordinate(
+ $circleSector['center']->x + cos( deg2rad( $circleSector['start'] ) ) * $circleSector['width'] / 2,
+ $circleSector['center']->y + sin( deg2rad( $circleSector['start'] ) ) * $circleSector['height'] / 2
+ ),
+ ),
+ $circleSector['color'],
+ true
+ );
+
+ $this->driver->drawPolygon(
+ array(
+ $circleSector['center'],
+ new ezcGraphCoordinate(
+ $circleSector['center']->x,
+ $circleSector['center']->y + $this->options->pieChartHeight
+ ),
+ new ezcGraphCoordinate(
+ $circleSector['center']->x + cos( deg2rad( $circleSector['start'] ) ) * $circleSector['width'] / 2,
+ $circleSector['center']->y + sin( deg2rad( $circleSector['start'] ) ) * $circleSector['height'] / 2 + $this->options->pieChartHeight
+ ),
+ new ezcGraphCoordinate(
+ $circleSector['center']->x + cos( deg2rad( $circleSector['start'] ) ) * $circleSector['width'] / 2,
+ $circleSector['center']->y + sin( deg2rad( $circleSector['start'] ) ) * $circleSector['height'] / 2
+ ),
+ ),
+ $darkenedColor,
+ false
+ );
+
+ $this->driver->drawPolygon(
+ array(
+ $circleSector['center'],
+ new ezcGraphCoordinate(
+ $circleSector['center']->x,
+ $circleSector['center']->y + $this->options->pieChartHeight
+ ),
+ new ezcGraphCoordinate(
+ $circleSector['center']->x + cos( deg2rad( $circleSector['end'] ) ) * $circleSector['width'] / 2,
+ $circleSector['center']->y + sin( deg2rad( $circleSector['end'] ) ) * $circleSector['height'] / 2 + $this->options->pieChartHeight
+ ),
+ new ezcGraphCoordinate(
+ $circleSector['center']->x + cos( deg2rad( $circleSector['end'] ) ) * $circleSector['width'] / 2,
+ $circleSector['center']->y + sin( deg2rad( $circleSector['end'] ) ) * $circleSector['height'] / 2
+ ),
+ ),
+ $circleSector['color'],
+ true
+ );
+
+ $this->driver->drawPolygon(
+ array(
+ $circleSector['center'],
+ new ezcGraphCoordinate(
+ $circleSector['center']->x,
+ $circleSector['center']->y + $this->options->pieChartHeight
+ ),
+ new ezcGraphCoordinate(
+ $circleSector['center']->x + cos( deg2rad( $circleSector['end'] ) ) * $circleSector['width'] / 2,
+ $circleSector['center']->y + sin( deg2rad( $circleSector['end'] ) ) * $circleSector['height'] / 2 + $this->options->pieChartHeight
+ ),
+ new ezcGraphCoordinate(
+ $circleSector['center']->x + cos( deg2rad( $circleSector['end'] ) ) * $circleSector['width'] / 2,
+ $circleSector['center']->y + sin( deg2rad( $circleSector['end'] ) ) * $circleSector['height'] / 2
+ ),
+ ),
+ $darkenedColor,
+ false
+ );
+ }
+
+ // Draw circle sector
+ foreach ( $this->circleSectors as $circleSector )
+ {
+ $this->driver->drawCircleSector(
+ $circleSector['center'],
+ $circleSector['width'],
+ $circleSector['height'],
+ $circleSector['start'],
+ $circleSector['end'],
+ $circleSector['color'],
+ true
+ );
+
+ $darkenedColor = $circleSector['color']->darken( $this->options->dataBorder );
+ $this->driver->drawCircleSector(
+ $circleSector['center'],
+ $circleSector['width'],
+ $circleSector['height'],
+ $circleSector['start'],
+ $circleSector['end'],
+ $darkenedColor,
+ false
+ );
+ }
+ }
+
+ protected function finishFrontLines()
+ {
+ foreach ( $this->frontLines as $line )
+ {
+ $this->driver->drawLine(
+ $line[0],
+ $line[1],
+ $line[2],
+ $line[3]
+ );
+ }
}
/**
- * Draw a line
+ * Draw data line
*
- * Semantically means a line as a chart element, not a single line like
- * the ones used in axes.
+ * Draws a line as a data element in a line chart
*
- * @param ezcGraphCoordinate $position
- * @param ezcGraphCoordinate $end
- * @param mixed $filled
- * @access public
+ * @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphColor $color Color of line
+ * @param ezcGraphCoordinate $start Starting point
+ * @param ezcGraphCoordinate $end Ending point
+ * @param int $dataNumber Number of dataset
+ * @param int $dataCount Count of datasets in chart
+ * @param int $symbol Symbol to draw for line
+ * @param ezcGraphColor $symbolColor Color of the symbol, defaults to linecolor
+ * @param ezcGraphColor $fillColor Color to fill line with
+ * @param float $axisPosition Position of axis for drawing filled lines
+ * @param float $thickness Line thickness
* @return void
*/
- public function drawLine( ezcGraphCoordinate $position, ezcGraphCoordinate $end, $filled = true )
+ public function drawDataLine(
+ ezcGraphBoundings $boundings,
+ ezcGraphColor $color,
+ ezcGraphCoordinate $start,
+ ezcGraphCoordinate $end,
+ $dataNumber = 1,
+ $dataCount = 1,
+ $symbol = ezcGraph::NO_SYMBOL,
+ ezcGraphColor $symbolColor = null,
+ ezcGraphColor $fillColor = null,
+ $axisPosition = 0.,
+ $thickness = 1 )
{
-
+ // Calculate line width based on options
+ if ( $this->options->seperateLines )
+ {
+ $depth = $this->depth / $dataCount;
+ $pointModifier = $depth * $dataNumber;
+ }
+ else
+ {
+ $depth = $this->depth;
+ $pointModifier = 0.;
+ }
+
+ // Apply depth factor to coords
+ $start = clone $start;
+ $start->x *= $this->xDepthFactor;
+ $start->y *= $this->yDepthFactor;
+ $end = clone $end;
+ $end->x *= $this->xDepthFactor;
+ $end->y *= $this->yDepthFactor;
+
+ // Perhaps fill up line
+ if ( $fillColor !== null &&
+ $start->x != $end->x )
+ {
+ $startValue = $axisPosition - $start->y;
+ $endValue = $axisPosition - $end->y;
+
+ if ( ( $startValue == 0 ) ||
+ ( $endValue == 0 ) ||
+ ( $startValue / abs( $startValue ) == $endValue / abs( $endValue ) ) )
+ {
+ // Values have the same sign or are on the axis
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ ),
+ ),
+ $fillColor,
+ true
+ );
+ }
+ else
+ {
+ // values are on differente sides of the axis - split the filled polygon
+ $startDiff = abs( $axisPosition - $start->y );
+ $endDiff = abs( $axisPosition - $end->y );
+
+ $cuttingPosition = $startDiff / ( $endDiff + $startDiff );
+ $cuttingPoint = new ezcGraphCoordinate(
+ $start->x + ( $end->x - $start->x ) * $cuttingPosition,
+ $axisPosition
+ );
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $cuttingPoint->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $cuttingPoint->y
+ ),
+ ),
+ $fillColor,
+ true
+ );
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $cuttingPoint->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $cuttingPoint->y
+ ),
+ ),
+ $fillColor,
+ true
+ );
+ }
+
+ // Draw closing foo
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $depth + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier - $depth + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $depth + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier - $depth + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $axisPosition
+ ),
+ ),
+ $fillColor,
+ true
+ );
+ }
+
+ $linePolygonPoints = array(
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $depth + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $start->x,
+ -$pointModifier - $depth + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $start->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $depth + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier - $depth + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y
+ ),
+ new ezcGraphCoordinate(
+ $pointModifier + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x,
+ -$pointModifier + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y
+ ),
+ );
+
+ // Draw line
+ $this->driver->drawPolygon(
+ $linePolygonPoints,
+ $color,
+ true,
+ $thickness
+ );
+
+ // Draw polygon border
+ if ( $this->options->dataBorder > 0 )
+ {
+ $this->driver->drawPolygon(
+ $linePolygonPoints,
+ $color->darken( $this->options->dataBorder ),
+ false,
+ $thickness
+ );
+ }
+
+ // Draw line symbol
+ if ( $symbol !== ezcGraph::NO_SYMBOL )
+ {
+ if ( $symbolColor === null )
+ {
+ $symbolColor = $color;
+ }
+
+ $this->drawSymbol(
+ new ezcGraphBoundings(
+ $pointModifier + $depth / 2 + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x - $this->options->symbolSize / 2,
+ -$pointModifier - $depth / 2 + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y - $this->options->symbolSize / 2,
+ $pointModifier + $depth / 2 + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $end->x + $this->options->symbolSize / 2,
+ -$pointModifier - $depth / 2 + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y + $this->options->symbolSize / 2
+ ),
+ $symbolColor,
+ $symbol
+ );
+ }
}
/**
- * Draws a text box
+ * Draw legend
+ *
+ * Will draw a legend in the bounding box
*
- * @param ezcGraphCoordinate $position
- * @param mixed $text
- * @param mixed $width
- * @param mixed $height
- * @access public
+ * @param ezcGraphBoundings $boundings Bounding of legend
+ * @param ezcGraphChartElementLegend $labels Legend to draw
+ * @param int $type Type of legend: Protrait or landscape
* @return void
*/
- public function drawTextBox( ezcGraphCoordinate $position, $text, $width = null, $height = null )
+ public function drawLegend(
+ ezcGraphBoundings $boundings,
+ ezcGraphChartElementLegend $legend,
+ $type = ezcGraph::VERTICAL )
{
+ $labels = $legend->labels;
+ // Calculate boundings of each label
+ if ( $type & ezcGraph::VERTICAL )
+ {
+ $labelWidth = $boundings->x1 - $boundings->x0;
+ $labelHeight = min(
+ ( $boundings->y1 - $boundings->y0 ) / count( $labels ) - $legend->spacing,
+ $legend->symbolSize + 2 * $legend->padding
+ );
+ }
+ else
+ {
+ $labelWidth = ( $boundings->x1 - $boundings->x0 ) / count( $labels ) - $legend->spacing;
+ $labelHeight = min(
+ $boundings->x1 - $boundings->x0,
+ $legend->symbolSize + 2 * $legend->padding
+ );
+ }
+
+ $symbolSize = $labelHeight - 2 * $legend->padding;
+
+ // Draw all labels
+ $labelPosition = new ezcGraphCoordinate( $boundings->x0, $boundings->y0 );
+ foreach ( $labels as $label )
+ {
+ $this->drawSymbol(
+ new ezcGraphBoundings(
+ $labelPosition->x + $legend->padding,
+ $labelPosition->y + $legend->padding,
+ $labelPosition->x + $legend->padding + $symbolSize,
+ $labelPosition->y + $legend->padding + $symbolSize
+ ),
+ $label['color'],
+ $label['symbol']
+ );
+
+ $this->driver->drawTextBox(
+ $label['label'],
+ new ezcGraphCoordinate(
+ $labelPosition->x + 2 * $legend->padding + $symbolSize,
+ $labelPosition->y + $legend->padding
+ ),
+ $labelWidth - $symbolSize - 3 * $legend->padding,
+ $labelHeight - 2 * $legend->padding,
+ ezcGraph::LEFT | ezcGraph::MIDDLE
+ );
+
+ $labelPosition->x += ( $type === ezcGraph::VERTICAL ? 0 : $labelWidth + $legend->spacing );
+ $labelPosition->y += ( $type === ezcGraph::VERTICAL ? $labelHeight + $legend->spacing : 0 );
+ }
}
/**
- * Draws a rectangle
+ * Draw box
*
- * @param ezcGraphColor $color
- * @param ezcGraphCoordinate $position
- * @param mixed $width
- * @param mixed $height
- * @param float $borderWidth
- * @access public
- * @return void
+ * Box are wrapping each major chart element and draw border, background
+ * and title to each chart element.
+ *
+ * Optionally a padding and margin for each box can be defined.
+ *
+ * @param ezcGraphBoundings $boundings Boundings of the box
+ * @param ezcGraphColor $background Background color
+ * @param ezcGraphColor $borderColor Border color
+ * @param int $borderWidth Border width
+ * @param int $margin Margin
+ * @param int $padding Padding
+ * @param string $title Title of the box
+ * @param int $titleSize Size of title in the box
+ * @return ezcGraphBoundings Remaining inner boundings
*/
- public function drawRect( ezcGraphColor $color, ezcGraphCoordinate $position = null, $width = null, $height = null, $borderWidth = 1 )
+ public function drawBox(
+ ezcGraphBoundings $boundings,
+ ezcGraphColor $background = null,
+ ezcGraphColor $borderColor = null,
+ $borderWidth = 0,
+ $margin = 0,
+ $padding = 0,
+ $title = false,
+ $titleSize = 16 )
{
+ // Apply margin
+ $boundings->x0 += $margin;
+ $boundings->y0 += $margin;
+ $boundings->x1 -= $margin;
+ $boundings->y1 -= $margin;
+
+ if ( ( $borderColor instanceof ezcGraphColor ) &&
+ ( $borderWidth > 0 ) )
+ {
+ // Draw border
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ),
+ new ezcGraphCoordinate( $boundings->x1, $boundings->y0 ),
+ new ezcGraphCoordinate( $boundings->x1, $boundings->y1 ),
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y1 ),
+ ),
+ $borderColor,
+ false
+ );
+
+ // Reduce local boundings by borderWidth
+ $boundings->x0 += $borderWidth;
+ $boundings->y0 += $borderWidth;
+ $boundings->x1 -= $borderWidth;
+ $boundings->y1 -= $borderWidth;
+ }
+ if ( $background instanceof ezcGraphColor )
+ {
+ // Draw box background
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ),
+ new ezcGraphCoordinate( $boundings->x1, $boundings->y0 ),
+ new ezcGraphCoordinate( $boundings->x1, $boundings->y1 ),
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y1 ),
+ ),
+ $background,
+ true
+ );
+ }
+
+ // Apply padding
+ $boundings->x0 += $padding;
+ $boundings->y0 += $padding;
+ $boundings->x1 -= $padding;
+ $boundings->y1 -= $padding;
+
+ // Add box title
+ if ( $title !== false )
+ {
+ switch ( $this->options->titlePosition )
+ {
+ case ezcGraph::TOP:
+ $this->driver->drawTextBox(
+ $title,
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ),
+ $boundings->x1 - $boundings->x0,
+ $titleSize,
+ $this->options->titleAlignement
+ );
+
+ $boundings->y0 += $titleSize + $padding;
+ $boundings->y1 -= $titleSize + $padding;
+ break;
+ case ezcGraph::BOTTOM:
+ $this->driver->drawTextBox(
+ $title,
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y1 - $titleSize ),
+ $boundings->x1 - $boundings->x0,
+ $titleSize,
+ $this->options->titleAlignement
+ );
+
+ $boundings->y1 -= $titleSize + $padding;
+ break;
+ }
+ }
+
+ return $boundings;
}
/**
- * Draw Background
+ * Draw text
+ *
+ * Draws the provided text in the boundings
+ *
+ * @param ezcGraphBoundings $boundings Boundings of text
+ * @param string $text Text
+ * @param int $align Alignement of text
+ * @return void
+ */
+ public function drawText(
+ ezcGraphBoundings $boundings,
+ $text,
+ $align = ezcGraph::LEFT )
+ {
+ $this->driver->drawTextBox(
+ $text,
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ),
+ $boundings->x1 - $boundings->x0,
+ $boundings->y1 - $boundings->y0,
+ $align
+ );
+ }
+
+ /**
+ * Draw grid line
*
- * Draws a filled rectangle, used for backgrounds
+ * Draw line for the grid in the chart background
*
- * @param ezcGraphColor $color
- * @param ezcGraphCoordinate $position
- * @param mixed $width
- * @param mixed $height
- * @access public
+ *
+ * @param ezcGraphCoordinate $start Start point
+ * @param ezcGraphCoordinate $end End point
+ * @param ezcGraphColor $color Color of the grid line
* @return void
*/
- public function drawBackground( ezcGraphColor $color, ezcGraphCoordinate $position = null, $width = null, $height = null )
+ public function drawGridLine( ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color )
{
+ $xFactor = round( ( $end->x - $start->x ) / ( $this->dataBoundings->x1 - $this->dataBoundings->x0 ) );
+ $yFactor = round( ( $end->y - $start->y ) / ( $this->dataBoundings->y1 - $this->dataBoundings->y0 ) );
+
+ $gridPolygonCoordinates = array(
+ new ezcGraphCoordinate(
+ $start->x,
+ $start->y + ( $this->depth * $yFactor )
+ ),
+ new ezcGraphCoordinate(
+ $end->x - ( $this->depth * $xFactor ),
+ $end->y
+ ),
+ new ezcGraphCoordinate(
+ $end->x + ( $this->depth * $yFactor ),
+ $end->y - ( $this->depth * $yFactor ) - ( $this->depth * $xFactor )
+ ),
+ new ezcGraphCoordinate(
+ $start->x + ( $this->depth * $yFactor ) + ( $this->depth * $xFactor ),
+ $start->y - ( $this->depth * $xFactor )
+ ),
+ );
+
+ // Draw grid polygon
+ if ( ( $this->options->fillGrid > 0 ) &&
+ ( $this->options->fillGrid < 1 ) )
+ {
+ $this->driver->drawPolygon(
+ $gridPolygonCoordinates,
+ $color->transparent( $this->options->fillGrid ),
+ true
+ );
+ }
+ else
+ {
+ $this->driver->drawPolygon(
+ $gridPolygonCoordinates,
+ $color,
+ !(bool) $this->options->fillGrid
+ );
+ }
+ // Draw grid lines - scedule some for later to be drawn in front of
+ // the data
+ $this->frontLines[] = array(
+ $gridPolygonCoordinates[0],
+ $gridPolygonCoordinates[1],
+ $color,
+ 1
+ );
+
+ $this->frontLines[] = array(
+ $gridPolygonCoordinates[1],
+ $gridPolygonCoordinates[2],
+ $color,
+ 1
+ );
+
+ $this->driver->drawLine(
+ $gridPolygonCoordinates[2],
+ $gridPolygonCoordinates[3],
+ $color,
+ 1
+ );
+
+ $this->frontLines[] = array(
+ $gridPolygonCoordinates[3],
+ $gridPolygonCoordinates[0],
+ $color,
+ 1
+ );
+ }
+
+ /**
+ * Draw step line
+ *
+ * Draw a step (marker for label position) on a axis.
+ *
+ * @param ezcGraphCoordinate $start Start point
+ * @param ezcGraphCoordinate $end End point
+ * @param ezcGraphColor $color Color of the grid line
+ * @return void
+ */
+ public function drawStepLine( ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color )
+ {
+ $stepPolygonCoordinates = array(
+ $start,
+ new ezcGraphCoordinate(
+ $start->x + $this->depth,
+ $start->y - $this->depth
+ ),
+ new ezcGraphCoordinate(
+ $end->x + $this->depth,
+ $end->y - $this->depth
+ ),
+ $end,
+ );
+
+ // Draw step polygon
+ if ( ( $this->options->fillAxis > 0 ) &&
+ ( $this->options->fillAxis < 1 ) )
+ {
+ $this->driver->drawPolygon(
+ $stepPolygonCoordinates,
+ $color->transparent( $this->options->fillAxis ),
+ true
+ );
+
+ $this->driver->drawPolygon(
+ $stepPolygonCoordinates,
+ $color,
+ false
+ );
+ }
+ else
+ {
+ $this->driver->drawPolygon(
+ $stepPolygonCoordinates,
+ $color,
+ !(bool) $this->options->fillAxis
+ );
+ }
}
/**
- * Draws BackgrouniImage
+ * Draw axis
+ *
+ * Draws an axis form the provided start point to the end point. A specific
+ * angle of the axis is not required.
+ *
+ * For the labeleing of the axis a sorted array with major steps and an
+ * array with minor steps is expected, which are build like this:
+ * array(
+ * array(
+ * 'position' => (float),
+ * 'label' => (string),
+ * )
+ * )
+ * where the label is optional.
+ *
+ * The label renderer class defines how the labels are rendered. For more
+ * documentation on this topic have a look at the basic label renderer
+ * class.
+ *
+ * Additionally it can be specified if a major and minor grid are rendered
+ * by defining a color for them. Teh axis label is used to add a caption
+ * for the axis.
+ *
+ * @param ezcGraphBoundings $boundings Boundings of axis
+ * @param ezcGraphCoordinate $start Start point of axis
+ * @param ezcGraphCoordinate $end Endpoint of axis
+ * @param ezcGraphChartElementAxis $axis Axis to render
+ * @param ezcGraphLabelRenderer $labelClass Used label renderer
+ * @return void
+ */
+ public function drawAxis(
+ ezcGraphBoundings $boundings,
+ ezcGraphCoordinate $start,
+ ezcGraphCoordinate $end,
+ ezcGraphChartElementAxis $axis,
+ ezcGraphAxisLabelRenderer $labelClass = null )
+ {
+ // Calculate used space for three dimensional effects
+ if ( $this->depth === false )
+ {
+ $this->depth = min(
+ ( $boundings->x1 - $boundings->x0 ) * $this->options->depth,
+ ( $boundings->y1 - $boundings->y0 ) * $this->options->depth
+ );
+
+ $this->xDepthFactor = 1 - $this->depth / ( $boundings->x1 - $boundings->x0 );
+ $this->yDepthFactor = 1 - $this->depth / ( $boundings->y1 - $boundings->y0 );
+
+ $this->dataBoundings = $boundings;
+ }
+
+ // Determine normalized direction
+ $direction = new ezcGraphCoordinate(
+ $start->x - $end->x,
+ $start->y - $end->y
+ );
+ $length = sqrt( pow( $direction->x, 2) + pow( $direction->y, 2 ) );
+ $direction->x /= $length;
+ $direction->y /= $length;
+
+ $start->x *= $this->xDepthFactor;
+ $start->y *= $this->yDepthFactor;
+ $end->x *= $this->xDepthFactor;
+ $end->y *= $this->yDepthFactor;
+
+ $axisPolygonCoordinates = array(
+ new ezcGraphCoordinate(
+ $boundings->x0 + $start->x,
+ $boundings->y0 + $start->y + $this->depth
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x0 + $end->x,
+ $boundings->y0 + $end->y + $this->depth
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x0 + $end->x + $this->depth,
+ $boundings->y0 + $end->y
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x0 + $start->x + $this->depth,
+ $boundings->y0 + $start->y
+ ),
+ );
+
+ // Draw axis
+ if ( ( $this->options->fillAxis > 0 ) &&
+ ( $this->options->fillAxis < 1 ) )
+ {
+ $this->driver->drawPolygon(
+ $axisPolygonCoordinates,
+ $axis->border->transparent( $this->options->fillAxis ),
+ true
+ );
+ }
+ else
+ {
+ $this->driver->drawPolygon(
+ $axisPolygonCoordinates,
+ $axis->border,
+ ! (bool) $this->options->fillAxis
+ );
+ }
+
+ // Draw axis lines - scedule some for later to be drawn in front of
+ // the data
+ $this->frontLines[] = array(
+ $axisPolygonCoordinates[0],
+ $axisPolygonCoordinates[1],
+ $axis->border,
+ 1
+ );
+
+ $this->frontLines[] = array(
+ $axisPolygonCoordinates[1],
+ $axisPolygonCoordinates[2],
+ $axis->border,
+ 1
+ );
+
+ $this->driver->drawLine(
+ $axisPolygonCoordinates[2],
+ $axisPolygonCoordinates[3],
+ $axis->border,
+ 1
+ );
+
+ $this->frontLines[] = array(
+ $axisPolygonCoordinates[3],
+ $axisPolygonCoordinates[0],
+ $axis->border,
+ 1
+ );
+
+ // Draw small arrowhead
+ $size = min(
+ $axis->maxArrowHeadSize,
+ abs( ceil( ( ( $end->x - $start->x ) + ( $end->y - $start->y ) ) * $axis->axisSpace / 4 ) )
+ );
+
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $boundings->x0 + $end->x,
+ $boundings->y0 + $end->y + $this->depth
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x0 + $end->x
+ + $direction->y * $size / 2
+ + $direction->x * $size,
+ $boundings->y0 + $end->y
+ + $direction->x * $size / 2
+ + $direction->y * $size
+ + $this->depth
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x0 + $end->x
+ - $direction->y * $size / 2
+ + $direction->x * $size,
+ $boundings->y0 + $end->y
+ - $direction->x * $size / 2
+ + $direction->y * $size
+ + $this->depth
+ ),
+ ),
+ $axis->border,
+ true
+ );
+
+ $xAxisSpace = ( $end->x - $start->x ) * $axis->axisSpace;
+ $yAxisSpace = ( $end->y - $start->y ) * $axis->axisSpace;
+
+ // Apply axisSpace to start and end
+ $start->x += $xAxisSpace;
+ $start->y += $yAxisSpace;
+ $end->x -= $xAxisSpace;
+ $end->y -= $yAxisSpace;
+
+ if ( $labelClass !== null )
+ {
+ $labelClass->renderLabels(
+ $this,
+ $boundings,
+ new ezcGraphCoordinate(
+ $boundings->x0 + $start->x,
+ $boundings->y0 + $start->y + $this->depth
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x0 + $end->x,
+ $boundings->y0 + $end->y + $this->depth
+ ),
+ $axis
+ );
+ }
+ }
+
+ /**
+ * Draw background image
+ *
+ * Draws a background image at the defined position. If repeat is set the
+ * background image will be repeated like any texture.
*
- * @param mixed $file
- * @param ezcGraphCoordinate $position
- * @param mixed $width
- * @param mixed $height
- * @access public
+ * @param ezcGraphBoundings $boundings Boundings for the background image
+ * @param string $file Filename of background image
+ * @param int $position Position of background image
+ * @param int $repeat Type of repetition
* @return void
*/
- public function drawBackgroundImage( $file, ezcGraphCoordinate $position = null, $width = null, $height = null )
+ public function drawBackgroundImage(
+ ezcGraphBoundings $boundings,
+ $file,
+ $position = 48, // ezcGraph::CENTER | ezcGraph::MIDDLE
+ $repeat = ezcGraph::NO_REPEAT )
{
+ $imageData = getimagesize( $file );
+ $imageWidth = $imageData[0];
+ $imageHeight = $imageData[1];
+
+ $imagePosition = new ezcGraphCoordinate( 0, 0 );
+
+ // Determine x position
+ switch ( true ) {
+ case ( $repeat & ezcGraph::HORIZONTAL ):
+ // If is repeated on this axis fall back to position zero
+ case ( $position & ezcGraph::LEFT ):
+ $imagePosition->x = $boundings->x0;
+ break;
+ case ( $position & ezcGraph::RIGHT ):
+ $imagePosition->x = max(
+ $boundings->x1 - $imageWidth,
+ $boundings->x0
+ );
+ break;
+ default:
+ $imagePosition->x = max(
+ $boundings->x0 + ( $boundings->x1 - $boundings->x0 - $imageWidth ) / 2,
+ $boundings->x0
+ );
+ break;
+ }
+
+ // Determine y position
+ switch ( true ) {
+ case ( $repeat & ezcGraph::VERTICAL ):
+ // If is repeated on this axis fall back to position zero
+ case ( $position & ezcGraph::TOP ):
+ $imagePosition->y = $boundings->y0;
+ break;
+ case ( $position & ezcGraph::BOTTOM ):
+ $imagePosition->y = max(
+ $boundings->y1 - $imageHeight,
+ $boundings->y0
+ );
+ break;
+ default:
+ $imagePosition->y = max(
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 - $imageHeight ) / 2,
+ $boundings->y0
+ );
+ break;
+ }
+
+ $imageWidth = min( $imageWidth, $boundings->x1 - $boundings->x0 );
+ $imageHeight = min( $imageHeight, $boundings->y1 - $boundings->y0 );
+
+ // Texturize backround based on position and repetition
+ $position = new ezcGraphCoordinate(
+ $imagePosition->x,
+ $imagePosition->y
+ );
+ do
+ {
+ $position->y = $imagePosition->y;
+
+ do
+ {
+ $this->driver->drawImage(
+ $file,
+ $position,
+ $imageWidth,
+ $imageHeight
+ );
+
+ $position->y += $imageHeight;
+ }
+ while ( ( $position->y < $boundings->y1 ) &&
+ ( $repeat & ezcGraph::VERTICAL ) );
+
+ $position->x += $imageWidth;
+ }
+ while ( ( $position->x < $boundings->x1 ) &&
+ ( $repeat & ezcGraph::HORIZONTAL ) );
}
/**
- * Draws a lines symbol
+ * Draw Symbol
+ *
+ * Draws a single symbol defined by the symbol constants in ezcGraph. for
+ * NO_SYMBOL a rect will be drawn.
*
- * @param ezcGraphCoordinate $position
- * @param float $width
- * @param float $height
- * @param int $symbol
- * @access public
+ * @param ezcGraphBoundings $boundings Boundings of symbol
+ * @param ezcGraphColor $color Color of symbol
+ * @param int $symbol Type of symbol
* @return void
*/
- public function drawSymbol( ezcGraphCoordinate $position, $width, $height, $symbol = ezcGraph::NO_SYMBOL)
+ public function drawSymbol(
+ ezcGraphBoundings $boundings,
+ ezcGraphColor $color,
+ $symbol = ezcGraph::NO_SYMBOL )
{
-
+ switch ( $symbol )
+ {
+ case ezcGraph::NO_SYMBOL:
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ),
+ new ezcGraphCoordinate( $boundings->x1, $boundings->y0 ),
+ new ezcGraphCoordinate( $boundings->x1, $boundings->y1 ),
+ new ezcGraphCoordinate( $boundings->x0, $boundings->y1 ),
+ ),
+ $color,
+ true
+ );
+ break;
+ case ezcGraph::DIAMOND:
+ $this->driver->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
+ $boundings->y0
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x1,
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
+ $boundings->y1
+ ),
+ new ezcGraphCoordinate(
+ $boundings->x0,
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2
+ ),
+ ),
+ $color,
+ true
+ );
+ break;
+ case ezcGraph::BULLET:
+ $this->driver->drawCircle(
+ new ezcGraphCoordinate(
+ $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2
+ ),
+ $boundings->x1 - $boundings->x0,
+ $boundings->y1 - $boundings->y0,
+ $color,
+ true
+ );
+ break;
+ case ezcGraph::CIRCLE:
+ $this->driver->drawCircle(
+ new ezcGraphCoordinate(
+ $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
+ $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2
+ ),
+ $boundings->x1 - $boundings->x0,
+ $boundings->y1 - $boundings->y0,
+ $color,
+ false
+ );
+ break;
+ }
+ }
+
+ protected function finish()
+ {
+ $this->finishCirleSectors();
+ $this->finishPieSegmentLabels();
+ $this->finishFrontLines();
+
+ return true;
}
}
diff --git a/src/structs/color.php b/src/structs/color.php
index a65dc31..99d9fde 100644
--- a/src/structs/color.php
+++ b/src/structs/color.php
@@ -203,10 +203,26 @@ class ezcGraphColor
}
/**
- * Darkens the color
+ * Returns a copy of the current color made more transparent by the given
+ * factor
+ *
+ * @param mixed $value Percent to make color mor transparent
+ * @return ezcGraphColor New color
+ */
+ public function transparent( $value )
+ {
+ $color = clone $this;
+
+ $color->alpha = 255 - (int) round( ( 255 - $this->alpha ) * ( 1 - $value ) );
+
+ return $color;
+ }
+
+ /**
+ * Returns a copy of the current color darkened by the given factor
*
* @param float $value Percent to darken the color
- * @return void
+ * @return ezcGraphColor New color
*/
public function darken( $value )
{
OpenPOWER on IntegriCloud