summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-09-12 11:20:27 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-09-12 11:20:27 +0000
commit22649b2b81c18461fd85793690de5d04b45806fa (patch)
treea227e9ebef702838ddc1d84b1348464663b80f16 /src
parentb269dab61f162292ba4ad1f3cb400e182be23cee (diff)
downloadzetacomponents-graph-22649b2b81c18461fd85793690de5d04b45806fa.zip
zetacomponents-graph-22649b2b81c18461fd85793690de5d04b45806fa.tar.gz
- Added image map support
# This changes all generated SVGs because each genereted element has an ID now
Diffstat (limited to 'src')
-rw-r--r--src/charts/line.php4
-rw-r--r--src/charts/pie.php2
-rw-r--r--src/driver/gd.php87
-rw-r--r--src/driver/svg.php52
-rw-r--r--src/graph_autoload.php1
-rw-r--r--src/interfaces/driver.php2
-rw-r--r--src/interfaces/renderer.php35
-rw-r--r--src/options/gd_driver.php7
-rw-r--r--src/renderer/2d.php76
-rw-r--r--src/renderer/3d.php82
-rw-r--r--src/structs/context.php35
11 files changed, 304 insertions, 79 deletions
diff --git a/src/charts/line.php b/src/charts/line.php
index ebf86f9..6d6f381 100644
--- a/src/charts/line.php
+++ b/src/charts/line.php
@@ -108,7 +108,7 @@ class ezcGraphLineChart extends ezcGraphChart
}
// Display data
- foreach ( $this->data as $data )
+ foreach ( $this->data as $datasetName => $data )
{
--$nr[$data->displayType->default];
switch ( $data->displayType->default )
@@ -140,6 +140,7 @@ class ezcGraphLineChart extends ezcGraphChart
$renderer->drawDataLine(
$boundings,
+ new ezcGraphContext( $datasetName, $key ),
$data->color->default,
( $lastPoint === false ? $point : $lastPoint ),
$point,
@@ -173,6 +174,7 @@ class ezcGraphLineChart extends ezcGraphChart
$renderer->drawBar(
$boundings,
+ new ezcGraphContext( $datasetName, $key ),
$data->color->default,
$this->elements['xAxis']->axisLabelRenderer->modifyChartDataPosition(
$this->elements['yAxis']->axisLabelRenderer->modifyChartDataPosition(
diff --git a/src/charts/pie.php b/src/charts/pie.php
index 5f4258a..b21401e 100644
--- a/src/charts/pie.php
+++ b/src/charts/pie.php
@@ -35,6 +35,7 @@ class ezcGraphPieChart extends ezcGraphChart
{
// Only draw the first (and only) dataset
$dataset = $this->data->rewind();
+ $datasetName = $this->data->key();
$this->driver->options->font = $this->options->font;
@@ -53,6 +54,7 @@ class ezcGraphPieChart extends ezcGraphChart
case ezcGraph::PIE:
$renderer->drawPieSegment(
$boundings,
+ new ezcGraphContext( $datasetName, $label ),
$dataset->color[$label],
$angle,
$angle += $value / $sum * 360,
diff --git a/src/driver/gd.php b/src/driver/gd.php
index bf9249b..1e30e81 100644
--- a/src/driver/gd.php
+++ b/src/driver/gd.php
@@ -170,6 +170,8 @@ class ezcGraphGdDriver extends ezcGraphDriver
{
imagepolygon( $image, $pointArray, $pointCount, $drawColor );
}
+
+ return $points;
}
/**
@@ -204,6 +206,8 @@ class ezcGraphGdDriver extends ezcGraphDriver
$this->image,
$this->options->supersampling
);
+
+ return array();
}
/**
@@ -415,6 +419,13 @@ class ezcGraphGdDriver extends ezcGraphDriver
{
throw new ezcGraphFontRenderingException( $string, $this->options->font->minFontSize, $width, $height );
}
+
+ return array(
+ clone $position,
+ new ezcGraphCoordinate( $position->x + $width, $position->y ),
+ new ezcGraphCoordinate( $position->x + $width, $position->y + $height ),
+ new ezcGraphCoordinate( $position->x, $position->y + $height ),
+ );
}
protected function drawAllTexts()
@@ -546,6 +557,26 @@ class ezcGraphGdDriver extends ezcGraphDriver
IMG_ARC_PIE | IMG_ARC_NOFILL | IMG_ARC_EDGED
);
}
+
+ // Create polygon array to return
+ $polygonArray = array( $center );
+ for ( $angle = $startAngle; $angle < $endAngle; $angle += $this->options->imageMapResolution )
+ {
+ $polygonArray[] = new ezcGraphCoordinate(
+ $center->x +
+ ( ( cos( deg2rad( $angle ) ) * $width ) / 2 ),
+ $center->y +
+ ( ( sin( deg2rad( $angle ) ) * $height ) / 2 )
+ );
+ }
+ $polygonArray[] = new ezcGraphCoordinate(
+ $center->x +
+ ( ( cos( deg2rad( $endAngle ) ) * $width ) / 2 ),
+ $center->y +
+ ( ( sin( deg2rad( $endAngle ) ) * $height ) / 2 )
+ );
+
+ return $polygonArray;
}
/**
@@ -680,6 +711,42 @@ class ezcGraphGdDriver extends ezcGraphDriver
IMG_ARC_PIE | IMG_ARC_NOFILL
);
}
+
+ // Create polygon array to return
+ $polygonArray = array();
+ for ( $angle = $startAngle; $angle < $endAngle; $angle += $this->options->imageMapResolution )
+ {
+ $polygonArray[] = new ezcGraphCoordinate(
+ $center->x +
+ ( ( cos( deg2rad( $angle ) ) * $width ) / 2 ),
+ $center->y +
+ ( ( sin( deg2rad( $angle ) ) * $height ) / 2 )
+ );
+ }
+ $polygonArray[] = new ezcGraphCoordinate(
+ $center->x +
+ ( ( cos( deg2rad( $endAngle ) ) * $width ) / 2 ),
+ $center->y +
+ ( ( sin( deg2rad( $endAngle ) ) * $height ) / 2 )
+ );
+
+ for ( $angle = $endAngle; $angle > $startAngle; $angle -= $this->options->imageMapResolution )
+ {
+ $polygonArray[] = new ezcGraphCoordinate(
+ $center->x +
+ ( ( cos( deg2rad( $angle ) ) * $width ) / 2 ) + $size,
+ $center->y +
+ ( ( sin( deg2rad( $angle ) ) * $height ) / 2 )
+ );
+ }
+ $polygonArray[] = new ezcGraphCoordinate(
+ $center->x +
+ ( ( cos( deg2rad( $startAngle ) ) * $width ) / 2 ) + $size,
+ $center->y +
+ ( ( sin( deg2rad( $startAngle ) ) * $height ) / 2 )
+ );
+
+ return $polygonArray;
}
/**
@@ -721,6 +788,19 @@ class ezcGraphGdDriver extends ezcGraphDriver
$drawColor
);
}
+
+ $polygonArray = array();
+ for ( $angle = 0; $angle < 360; $angle += $this->options->imageMapResolution )
+ {
+ $polygonArray[] = new ezcGraphCoordinate(
+ $center->x +
+ ( ( cos( deg2rad( $angle ) ) * $width ) / 2 ),
+ $center->y +
+ ( ( sin( deg2rad( $angle ) ) * $height ) / 2 )
+ );
+ }
+
+ return $polygonArray;
}
/**
@@ -740,6 +820,13 @@ class ezcGraphGdDriver extends ezcGraphDriver
'width' => $width,
'height' => $height,
);
+
+ return array(
+ $position,
+ new ezcGraphCoordinate( $position->x + $width, $position->y ),
+ new ezcGraphCoordinate( $position->x + $width, $position->y + $height ),
+ new ezcGraphCoordinate( $position->x, $position->y + $height ),
+ );
}
/**
diff --git a/src/driver/svg.php b/src/driver/svg.php
index 0a6bd28..b7de230 100644
--- a/src/driver/svg.php
+++ b/src/driver/svg.php
@@ -55,6 +55,13 @@ class ezcGraphSvgDriver extends ezcGraphDriver
*/
protected $drawnGradients = array();
+ /**
+ * Numeric unique element id
+ *
+ * @var int
+ */
+ protected $elementID = 0;
+
public function __construct( array $options = array() )
{
$this->options = new ezcGraphSvgDriverOptions( $options );
@@ -297,8 +304,10 @@ class ezcGraphSvgDriver extends ezcGraphDriver
'style',
$this->getStyle( $color, $filled, $thickness )
);
-
+ $path->setAttribute( 'id', $id = ( 'ezcGraphPolygon_' . ++$this->elementID ) );
$this->elements->appendChild( $path );
+
+ return $id;
}
/**
@@ -327,7 +336,10 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$this->getStyle( $color, false, $thickness )
);
+ $path->setAttribute( 'id', $id = ( 'ezcGraphLine_' . ++$this->elementID ) );
$this->elements->appendChild( $path );
+
+ return $id;
}
protected function testFitStringInTextBox( $string, ezcGraphCoordinate $position, $width, $height, $size )
@@ -408,19 +420,18 @@ class ezcGraphSvgDriver extends ezcGraphDriver
}
}
- if ( is_array( $result ) )
- {
- $this->options->font->minimalUsedFont = $size;
-
- $this->strings[] = array(
- 'text' => $result,
- 'position' => $position,
- 'width' => $width,
- 'height' => $height,
- 'align' => $align,
- 'options' => $this->options->font,
- );
- }
+ $this->options->font->minimalUsedFont = $size;
+ $this->strings[] = array(
+ 'text' => $result,
+ 'id' => $id = ( 'ezcGraphTextBox_' . ++$this->elementID ),
+ 'position' => $position,
+ 'width' => $width,
+ 'height' => $height,
+ 'align' => $align,
+ 'options' => $this->options->font,
+ );
+
+ return $id;
}
protected function drawAllTexts()
@@ -476,6 +487,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
}
$textNode = $this->dom->createElement( 'text', $string );
+ $textNode->setAttribute( 'id', $text['id'] );
$textNode->setAttribute( 'x', $position->x + $this->options->graphOffset->x );
$textNode->setAttribute( 'text-length', ( $size * strlen( $string ) * $this->options->assumedCharacterWidth ) . 'px' );
$textNode->setAttribute( 'y', $position->y + $this->options->graphOffset->y );
@@ -551,7 +563,10 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$this->getStyle( $color, $filled, 1 )
);
+ $arc->setAttribute( 'id', $id = ( 'ezcGraphCircleSector_' . ++$this->elementID ) );
$this->elements->appendChild( $arc );
+
+ return $id;
}
/**
@@ -646,6 +661,7 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$this->getStyle( $color, $filled )
);
+ $arc->setAttribute( 'id', $id = ( 'ezcGraphCircularArc_' . ++$this->elementID ) );
$this->elements->appendChild( $arc );
if ( ( $this->options->shadeCircularArc !== false ) &&
@@ -692,6 +708,8 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$this->elements->appendChild( $arc );
}
+
+ return $id;
}
/**
@@ -720,7 +738,10 @@ class ezcGraphSvgDriver extends ezcGraphDriver
$this->getStyle( $color, $filled, 1 )
);
+ $ellipse->setAttribute( 'id', $id = ( 'ezcGraphCircle_' . ++$this->elementID ) );
$this->elements->appendChild( $ellipse );
+
+ return $id;
}
/**
@@ -753,6 +774,9 @@ class ezcGraphSvgDriver extends ezcGraphDriver
);
$this->elements->appendChild( $image );
+ $image->setAttribute( 'id', $id = ( 'ezcGraphImage_' . ++$this->elementID ) );
+
+ return $id;
}
/**
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index f415aa6..448a3d9 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -96,6 +96,7 @@ return array(
'ezcGraphBoundings' => 'Graph/math/boundings.php',
'ezcGraphCoordinate' => 'Graph/structs/coordinate.php',
+ 'ezcGraphContext' => 'Graph/structs/context.php',
);
?>
diff --git a/src/interfaces/driver.php b/src/interfaces/driver.php
index b7045f0..a763f91 100644
--- a/src/interfaces/driver.php
+++ b/src/interfaces/driver.php
@@ -69,7 +69,7 @@ abstract class ezcGraphDriver
case 'options':
return $this->options;
default:
- return parent::__get( $propertyName );
+ throw new ezcBasePropertyNotFoundException( $propertyName );
}
}
diff --git a/src/interfaces/renderer.php b/src/interfaces/renderer.php
index 80fdc5d..84907e0 100644
--- a/src/interfaces/renderer.php
+++ b/src/interfaces/renderer.php
@@ -23,11 +23,23 @@ abstract class ezcGraphRenderer
protected $yAxisSpace = false;
+ protected $elements = array();
+
public function setDriver( ezcGraphDriver $driver )
{
$this->driver = $driver;
}
+ protected function addElementReference( ezcGraphContext $context, $reference )
+ {
+ $this->elements['data'][$context->dataset][$context->datapoint][] = $reference;
+ }
+
+ public function getElementReferences()
+ {
+ return $this->elements;
+ }
+
/**
* __get
*
@@ -44,6 +56,8 @@ abstract class ezcGraphRenderer
case 'xAxisSpace':
case 'yAxisSpace':
return $this->$propertyName;
+ case 'elements':
+ return $this->elements;
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
}
@@ -55,6 +69,7 @@ abstract class ezcGraphRenderer
* Draws a single pie segment
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of pie segment
* @param float $startAngle Start angle
* @param float $endAngle End angle
@@ -64,6 +79,7 @@ abstract class ezcGraphRenderer
*/
abstract public function drawPieSegment(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
$startAngle = .0,
$endAngle = 360.,
@@ -77,6 +93,7 @@ abstract class ezcGraphRenderer
* Draws a bar as a data element in a line chart
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of line
* @param ezcGraphCoordinate $position Position of data point
* @param float $stepSize Space which can be used for bars
@@ -88,6 +105,7 @@ abstract class ezcGraphRenderer
*/
abstract public function drawBar(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
ezcGraphCoordinate $position,
$stepSize,
@@ -103,6 +121,7 @@ abstract class ezcGraphRenderer
* Draws a line as a data element in a line chart
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of line
* @param ezcGraphCoordinate $start Starting point
* @param ezcGraphCoordinate $end Ending point
@@ -117,6 +136,7 @@ abstract class ezcGraphRenderer
*/
abstract public function drawDataLine(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
@@ -268,7 +288,7 @@ abstract class ezcGraphRenderer
switch ( $symbol )
{
case ezcGraph::NO_SYMBOL:
- $this->driver->drawPolygon(
+ $return = $this->driver->drawPolygon(
array(
new ezcGraphCoordinate( $boundings->x0, $boundings->y0 ),
new ezcGraphCoordinate( $boundings->x1, $boundings->y0 ),
@@ -310,9 +330,9 @@ abstract class ezcGraphRenderer
true
);
}
- break;
+ return $return;
case ezcGraph::DIAMOND:
- $this->driver->drawPolygon(
+ $return = $this->driver->drawPolygon(
array(
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
@@ -372,9 +392,9 @@ abstract class ezcGraphRenderer
true
);
}
- break;
+ return $return;
case ezcGraph::BULLET:
- $this->driver->drawCircle(
+ $return = $this->driver->drawCircle(
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
$boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2
@@ -410,9 +430,9 @@ abstract class ezcGraphRenderer
true
);
}
- break;
+ return $return;
case ezcGraph::CIRCLE:
- $this->driver->drawCircle(
+ return $this->driver->drawCircle(
new ezcGraphCoordinate(
$boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2,
$boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2
@@ -422,7 +442,6 @@ abstract class ezcGraphRenderer
$color,
false
);
- break;
}
}
diff --git a/src/options/gd_driver.php b/src/options/gd_driver.php
index 2faddd7..0037892 100644
--- a/src/options/gd_driver.php
+++ b/src/options/gd_driver.php
@@ -23,6 +23,9 @@
* Function used to resample / resize images
* @property bool $forceNativeTTF
* Force use of native ttf functions instead of free type 2
+ * @property float $imageMapResolution
+ * Degree step used to interpolate round image primitives by
+ * polygons for image maps
*
* @package Graph
*/
@@ -44,6 +47,7 @@ class ezcGraphGdDriverOptions extends ezcGraphDriverOptions
$this->properties['background'] = false;
$this->properties['resampleFunction'] = 'imagecopyresampled';
$this->properties['forceNativeTTF'] = false;
+ $this->properties['imageMapResolution'] = 10;
parent::__construct( $options );
}
@@ -101,6 +105,9 @@ class ezcGraphGdDriverOptions extends ezcGraphDriverOptions
case 'forceNativeTTF':
$this->properties['forceNativeTTF'] = (bool) $propertyValue;
break;
+ case 'imageMapResolution':
+ $this->properties['imageMapResolution'] = max( 1, (int) $propertyValue );
+ break;
default:
parent::__set( $propertyName, $propertyValue );
break;
diff --git a/src/renderer/2d.php b/src/renderer/2d.php
index 677e2ac..5099e61 100644
--- a/src/renderer/2d.php
+++ b/src/renderer/2d.php
@@ -51,6 +51,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
* Draws a single pie segment
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of pie segment
* @param float $startAngle Start angle
* @param float $endAngle End angle
@@ -60,6 +61,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
*/
public function drawPieSegment(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
$startAngle = .0,
$endAngle = 360.,
@@ -90,14 +92,17 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
}
// Draw circle sector
- $this->driver->drawCircleSector(
- $center,
- $radius * 2,
- $radius * 2,
- $startAngle + $this->options->pieChartOffset,
- $endAngle + $this->options->pieChartOffset,
- $color,
- true
+ $this->addElementReference(
+ $context,
+ $this->driver->drawCircleSector(
+ $center,
+ $radius * 2,
+ $radius * 2,
+ $startAngle + $this->options->pieChartOffset,
+ $endAngle + $this->options->pieChartOffset,
+ $color,
+ true
+ )
);
$darkenedColor = $color->darken( .5 );
@@ -127,7 +132,8 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
cos( deg2rad( $middle ) ) * $radius * 2 / 3 + $center->x,
sin( deg2rad( $middle ) ) * $radius * 2 / 3 + $center->y
),
- $label
+ $label,
+ $context
);
}
@@ -236,15 +242,18 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
);
}
- $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
+ $this->addElementReference(
+ $label[2],
+ $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
@@ -257,10 +266,13 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
{
foreach ( $this->linePostSymbols as $symbol )
{
- $this->drawSymbol(
- $symbol['boundings'],
- $symbol['color'],
- $symbol['symbol']
+ $this->addElementReference(
+ $symbol['context'],
+ $this->drawSymbol(
+ $symbol['boundings'],
+ $symbol['color'],
+ $symbol['symbol']
+ )
);
}
}
@@ -271,6 +283,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
* Draws a bar as a data element in a line chart
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of line
* @param ezcGraphCoordinate $position Position of data point
* @param float $stepSize Space which can be used for bars
@@ -282,6 +295,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
*/
public function drawBar(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
ezcGraphCoordinate $position,
$stepSize,
@@ -315,10 +329,13 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
),
);
- $this->driver->drawPolygon(
- $barPointArray,
- $color,
- true
+ $this->addElementReference(
+ $context,
+ $this->driver->drawPolygon(
+ $barPointArray,
+ $color,
+ true
+ )
);
if ( $this->options->dataBorder > 0 )
@@ -339,6 +356,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
* Draws a line as a data element in a line chart
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of line
* @param ezcGraphCoordinate $start Starting point
* @param ezcGraphCoordinate $end Ending point
@@ -353,6 +371,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
*/
public function drawDataLine(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
@@ -481,6 +500,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
$boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $end->y + $this->options->symbolSize / 2
),
'color' => $symbolColor,
+ 'context' => $context,
'symbol' => $symbol,
);
}
@@ -527,7 +547,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
$labelPosition = new ezcGraphCoordinate( $boundings->x0, $boundings->y0 );
foreach ( $labels as $label )
{
- $this->drawSymbol(
+ $this->elements['legend'][$label['label']]['symbol'] = $this->drawSymbol(
new ezcGraphBoundings(
$labelPosition->x + $legend->padding,
$labelPosition->y + $legend->padding,
@@ -538,7 +558,7 @@ class ezcGraphRenderer2d extends ezcGraphRenderer
$label['symbol']
);
- $this->driver->drawTextBox(
+ $this->elements['legend'][$label['label']]['text'] = $this->driver->drawTextBox(
$label['label'],
new ezcGraphCoordinate(
$labelPosition->x + 2 * $legend->padding + $symbolSize,
diff --git a/src/renderer/3d.php b/src/renderer/3d.php
index 610d34e..b1ccbe5 100644
--- a/src/renderer/3d.php
+++ b/src/renderer/3d.php
@@ -73,6 +73,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
* Draws a single pie segment
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of pie segment
* @param float $startAngle Start angle
* @param float $endAngle End angle
@@ -82,6 +83,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
*/
public function drawPieSegment(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
$startAngle = .0,
$endAngle = 360.,
@@ -119,6 +121,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
// Add circle sector to queue
$this->circleSectors[] = array(
'center' => $center,
+ 'context' => $context,
'width' => $radius * 2,
'height' => $radius * 2 * $this->options->pieChartRotation - $this->options->pieChartHeight,
'start' => $startAngle,
@@ -139,7 +142,8 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
// y position
$this->pieSegmentLabels[(int) ($pieSegmentCenter->x > $center->x)][$pieSegmentCenter->y] = array(
clone $pieSegmentCenter,
- $label
+ $label,
+ $context,
);
}
@@ -248,15 +252,17 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
);
}
- $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
+ $this->addElementReference( $label[2],
+ $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
@@ -453,14 +459,16 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
// Draw circle sector for front
foreach ( $this->circleSectors as $circleSector )
{
- $this->driver->drawCircleSector(
- $circleSector['center'],
- $circleSector['width'],
- $circleSector['height'],
- $circleSector['start'],
- $circleSector['end'],
- $circleSector['color'],
- true
+ $this->addElementReference( $circleSector['context'],
+ $this->driver->drawCircleSector(
+ $circleSector['center'],
+ $circleSector['width'],
+ $circleSector['height'],
+ $circleSector['start'],
+ $circleSector['end'],
+ $circleSector['color'],
+ true
+ )
);
if ( $this->options->pieChartGleam !== false )
@@ -541,10 +549,12 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
{
foreach ( $this->linePostSymbols as $symbol )
{
- $this->drawSymbol(
- $symbol['boundings'],
- $symbol['color'],
- $symbol['symbol']
+ $this->addElementReference( $symbol['context'],
+ $this->drawSymbol(
+ $symbol['boundings'],
+ $symbol['color'],
+ $symbol['symbol']
+ )
);
}
}
@@ -555,6 +565,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
* Draws a bar as a data element in a line chart
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of line
* @param ezcGraphCoordinate $position Position of data point
* @param float $stepSize Space which can be used for bars
@@ -566,6 +577,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
*/
public function drawBar(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
ezcGraphCoordinate $position,
$stepSize,
@@ -610,6 +622,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barPolygonArray[2]->x,
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
array(
$this->get3dCoordinate( $barPolygonArray[2], $startDepth ),
@@ -626,6 +639,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barPolygonArray[1]->x,
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
( $barPolygonArray[1]->y < $barPolygonArray[3]->y
? array(
@@ -652,6 +666,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barPolygonArray[1]->x + 1,
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
( $barPolygonArray[1]->y < $barPolygonArray[3]->y
? array(
@@ -688,6 +703,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barPolygonArray[1]->x,
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
array(
$this->get3dCoordinate( $barPolygonArray[0], $startDepth ),
@@ -706,6 +722,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barPolygonArray[1]->x + 1,
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
array(
$this->get3dCoordinate( $barPolygonArray[0], $startDepth ),
@@ -745,6 +762,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barCoordinateArray['x'][0],
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
array(
$this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][0], $barCoordinateArray['y'][0] ), $midDepth ),
@@ -761,6 +779,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barCoordinateArray['x'][1],
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
array(
$this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][2], $barCoordinateArray['y'][0] ), $midDepth ),
@@ -782,6 +801,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barCoordinateArray['x'][0],
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
array(
$this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][1], $topLocation ), $startDepth ),
@@ -800,6 +820,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barCoordinateArray['x'][0] + 1,
'method' => 'drawPolygon',
+ 'context' => $context,
'parameters' => array(
array(
$this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][1], $topLocation ), $startDepth ),
@@ -840,6 +861,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barCenterBottom->x,
'method' => 'drawCircularArc',
+ 'context' => $context,
'parameters' => array(
$this->get3dCoordinate( $barCenterTop, $midDepth ),
$barWidth,
@@ -854,6 +876,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$this->barPostProcessing[] = array(
'index' => $barCenterBottom->x + 1,
'method' => 'drawCircle',
+ 'context' => $context,
'parameters' => array(
$top = $this->get3dCoordinate( $barCenterTop, $midDepth ),
$barWidth,
@@ -901,9 +924,11 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
foreach ( $this->barPostProcessing as $bar )
{
- call_user_func_array(
- array( $this->driver, $bar['method'] ),
- $bar['parameters']
+ $this->addElementReference( $bar['context'],
+ call_user_func_array(
+ array( $this->driver, $bar['method'] ),
+ $bar['parameters']
+ )
);
}
}
@@ -914,6 +939,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
* Draws a line as a data element in a line chart
*
* @param ezcGraphBoundings $boundings Chart boundings
+ * @param ezcGraphContext $context Context of call
* @param ezcGraphColor $color Color of line
* @param ezcGraphCoordinate $start Starting point
* @param ezcGraphCoordinate $end Ending point
@@ -928,6 +954,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
*/
public function drawDataLine(
ezcGraphBoundings $boundings,
+ ezcGraphContext $context,
ezcGraphColor $color,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
@@ -1092,6 +1119,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$linePolygonPoints[2]->y + $this->options->symbolSize / 2
),
'color' => $symbolColor,
+ 'context' => $context,
'symbol' => $symbol,
);
}
@@ -1138,7 +1166,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$labelPosition = new ezcGraphCoordinate( $boundings->x0, $boundings->y0 );
foreach ( $labels as $label )
{
- $this->drawSymbol(
+ $this->elements['legend'][$label['label']]['symbol'] = $this->drawSymbol(
new ezcGraphBoundings(
$labelPosition->x + $legend->padding,
$labelPosition->y + $legend->padding,
@@ -1149,7 +1177,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$label['symbol']
);
- $this->driver->drawTextBox(
+ $this->elements['legend'][$label['label']]['text'] = $this->driver->drawTextBox(
$label['label'],
new ezcGraphCoordinate(
$labelPosition->x + 2 * $legend->padding + $symbolSize,
diff --git a/src/structs/context.php b/src/structs/context.php
new file mode 100644
index 0000000..351031f
--- /dev/null
+++ b/src/structs/context.php
@@ -0,0 +1,35 @@
+<?php
+
+class ezcGraphContext
+{
+ public $dataset = false;
+
+ public $datapoint = false;
+
+ /**
+ * Empty constructor
+ */
+ public function __construct( $dataset = false, $datapoint = false )
+ {
+ $this->dataset = $dataset;
+ $this->datapoint = $datapoint;
+ }
+
+ /**
+ * Throws a BasePropertyNotFound exception.
+ */
+ public function __set( $name, $value )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+
+ /**
+ * Throws a BasePropertyNotFound exception.
+ */
+ public function __get( $name )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+}
+
+?>
OpenPOWER on IntegriCloud