summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-08-15 12:10:39 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-08-15 12:10:39 +0000
commit4c85aee953e34bb0f997af13fc9b35e5ed29699c (patch)
treec0d501e58acbcb00302e2d2ffdfcae0650eae590
parente3f5f4876b49a8274979527fba29fcc004465f85 (diff)
downloadzetacomponents-graph-4c85aee953e34bb0f997af13fc9b35e5ed29699c.zip
zetacomponents-graph-4c85aee953e34bb0f997af13fc9b35e5ed29699c.tar.gz
- Added implementation for bar charts to 3d renderer
-rw-r--r--src/options/renderer_3d.php20
-rw-r--r--src/renderer/3d.php106
-rw-r--r--tests/data/compare/ezcGraphRenderer3dTest_testRenderBarChart.pngbin0 -> 73671 bytes
-rw-r--r--tests/renderer_3d_test.php32
4 files changed, 155 insertions, 3 deletions
diff --git a/src/options/renderer_3d.php b/src/options/renderer_3d.php
index 04994d1..92c0194 100644
--- a/src/options/renderer_3d.php
+++ b/src/options/renderer_3d.php
@@ -133,6 +133,20 @@ class ezcGraphRenderer3dOptions extends ezcGraphChartOptions
protected $barPadding = .05;
/**
+ * Factor to darken the color used for the bars side polygon
+ *
+ * @var float
+ */
+ protected $barDarkenSide = .2;
+
+ /**
+ * Factor to darken the color used for the bars top polygon
+ *
+ * @var float
+ */
+ protected $barDarkenTop = .4;
+
+ /**
* Set an option value
*
* @param string $propertyName
@@ -196,6 +210,12 @@ class ezcGraphRenderer3dOptions extends ezcGraphChartOptions
case 'barPadding':
$this->barPadding = min( 1, max( 0, (float) $propertyValue ) );
break;
+ case 'barDarkenSide':
+ $this->barDarkenSide = min( 1, max( 0, (float) $propertyValue ) );
+ break;
+ case 'barDarkenTop':
+ $this->barDarkenTop = min( 1, max( 0, (float) $propertyValue ) );
+ break;
default:
return parent::__set( $propertyName, $propertyValue );
}
diff --git a/src/renderer/3d.php b/src/renderer/3d.php
index 4537fa7..2af00c3 100644
--- a/src/renderer/3d.php
+++ b/src/renderer/3d.php
@@ -29,6 +29,8 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
protected $circleSectors = array();
+ protected $barPostProcessing = array();
+
protected $options;
protected $depth = false;
@@ -455,9 +457,108 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
$dataCount = 1,
$axisPosition = 0. )
{
- // @TODO: implement
+ // Apply margin
+ $margin = $stepSize * $this->options->barMargin;
+ $padding = $stepSize * $this->options->barPadding;
+ $barWidth = ( $stepSize - $margin ) / $dataCount - $padding;
+ $offset = - $stepSize / 2 + $margin / 2 + ( $dataCount - $dataNumber - 1 ) * ( $padding + $barWidth ) + $padding / 2;
+
+ $startDepth = $this->options->barMargin;
+ $endDepth = 1 - $this->options->barMargin;
+
+ $barPolygonArray = array(
+ new ezcGraphCoordinate(
+ $this->dataBoundings->x0 + $this->xAxisSpace + $position->x * ( $this->dataBoundings->x1 - ( $this->dataBoundings->x0 + 2 * $this->xAxisSpace ) ) + $offset,
+ $this->dataBoundings->y0 + $this->yAxisSpace + $axisPosition * ( $this->dataBoundings->y1 - ( $this->dataBoundings->y0 + 2 * $this->yAxisSpace ) )
+ ),
+ new ezcGraphCoordinate(
+ $this->dataBoundings->x0 + $this->xAxisSpace + $position->x * ( $this->dataBoundings->x1 - ( $this->dataBoundings->x0 + 2 * $this->xAxisSpace ) ) + $offset,
+ $this->dataBoundings->y0 + $this->yAxisSpace + $position->y * ( $this->dataBoundings->y1 - ( $this->dataBoundings->y0 + 2 * $this->yAxisSpace ) )
+ ),
+ new ezcGraphCoordinate(
+ $this->dataBoundings->x0 + $this->xAxisSpace + $position->x * ( $this->dataBoundings->x1 - ( $this->dataBoundings->x0 + 2 * $this->xAxisSpace ) ) + $offset + $barWidth,
+ $this->dataBoundings->y0 + $this->yAxisSpace + $position->y * ( $this->dataBoundings->y1 - ( $this->dataBoundings->y0 + 2 * $this->yAxisSpace ) )
+ ),
+ new ezcGraphCoordinate(
+ $this->dataBoundings->x0 + $this->xAxisSpace + $position->x * ( $this->dataBoundings->x1 - ( $this->dataBoundings->x0 + 2 * $this->xAxisSpace ) ) + $offset + $barWidth,
+ $this->dataBoundings->y0 + $this->yAxisSpace + $axisPosition * ( $this->dataBoundings->y1 - ( $this->dataBoundings->y0 + 2 * $this->yAxisSpace ) )
+ ),
+ );
+
+ // Draw right bar side
+ $this->barPostProcessing[] = array(
+ 'polygone' => array(
+ $this->get3dCoordinate( $barPolygonArray[2], $startDepth ),
+ $this->get3dCoordinate( $barPolygonArray[3], $startDepth ),
+ $this->get3dCoordinate( $barPolygonArray[3], $endDepth ),
+ $this->get3dCoordinate( $barPolygonArray[2], $endDepth ),
+ ),
+ 'color' => $color->darken( $this->options->barDarkenSide ),
+ );
+
+ // Draw bar top
+ $this->barPostProcessing[] = array(
+ 'polygone' => array(
+ $this->get3dCoordinate( $barPolygonArray[1], $startDepth ),
+ $this->get3dCoordinate( $barPolygonArray[2], $startDepth ),
+ $this->get3dCoordinate( $barPolygonArray[2], $endDepth ),
+ $this->get3dCoordinate( $barPolygonArray[1], $endDepth ),
+ ),
+ 'color' => $color->darken( $this->options->barDarkenTop ),
+ );
+
+ // Draw front side
+ $this->barPostProcessing[] = array(
+ 'polygone' => array(
+ $this->get3dCoordinate( $barPolygonArray[0], $startDepth ),
+ $this->get3dCoordinate( $barPolygonArray[1], $startDepth ),
+ $this->get3dCoordinate( $barPolygonArray[2], $startDepth ),
+ $this->get3dCoordinate( $barPolygonArray[3], $startDepth ),
+ ),
+ 'color' => $color,
+ );
}
-
+
+ protected function finishBars()
+ {
+ $zBuffer = array();
+
+ foreach ( $this->barPostProcessing as $bar )
+ {
+ $zIndex = (int) ( $bar['polygone'][0]->x * 10 );
+ if ( !isset( $zBuffer[$zIndex] ) )
+ {
+ $zBuffer[$zIndex] = array();
+ }
+
+ $zBuffer[$zIndex][] = $bar;
+ }
+
+ ksort( $zBuffer );
+
+ foreach ( $zBuffer as $bars )
+ {
+ foreach ( $bars as $bar )
+ {
+ $this->driver->drawPolygon(
+ $bar['polygone'],
+ $bar['color'],
+ true
+ );
+
+ if ( $this->options->dataBorder > 0 )
+ {
+ $borderColor = $bar['color']->darken( $this->options->dataBorder );
+ $this->driver->drawPolygon(
+ $bar['polygone'],
+ $borderColor,
+ false
+ );
+ }
+ }
+ }
+ }
+
/**
* Draw data line
*
@@ -1381,6 +1482,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer
{
$this->finishCirleSectors();
$this->finishPieSegmentLabels();
+ $this->finishBars();
$this->finishLineSymbols();
$this->finishFrontLines();
diff --git a/tests/data/compare/ezcGraphRenderer3dTest_testRenderBarChart.png b/tests/data/compare/ezcGraphRenderer3dTest_testRenderBarChart.png
new file mode 100644
index 0000000..2636c84
--- /dev/null
+++ b/tests/data/compare/ezcGraphRenderer3dTest_testRenderBarChart.png
Binary files differ
diff --git a/tests/renderer_3d_test.php b/tests/renderer_3d_test.php
index 8b0074b..7491169 100644
--- a/tests/renderer_3d_test.php
+++ b/tests/renderer_3d_test.php
@@ -46,7 +46,10 @@ class ezcGraphRenderer3dTest extends ezcImageTestCase
*/
public function tearDown()
{
- $this->removeTempDir();
+ if( !$this->hasFailed() )
+ {
+ $this->removeTempDir();
+ }
}
public function testRenderBackgroundImage()
@@ -559,6 +562,33 @@ class ezcGraphRenderer3dTest extends ezcImageTestCase
);
}
+ public function testRenderBarChart()
+ {
+ $filename = $this->tempDir . __FUNCTION__ . '.png';
+
+ $chart = new ezcGraphLineChart();
+ $chart->palette = new ezcGraphPaletteBlack();
+
+ $chart->data['Line 0'] = new ezcGraphArrayDataSet( array( 'sample 1' => 432, 'sample 2' => 43, 'sample 3' => 65, 'sample 4' => 97, 'sample 5' => 154) );
+ $chart->data['Line 0']->displayType = ezcGraph::BAR;
+ $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) );
+ $chart->data['Line 1']->displayType = ezcGraph::BAR;
+
+ $chart->xAxis->axisLabelRenderer = new ezcGraphAxisBoxedLabelRenderer();
+
+ $chart->driver = new ezcGraphGdDriver();
+ $chart->renderer = new ezcGraphRenderer3d();
+ $chart->options->font = $this->basePath . 'font.ttf';
+ $chart->render( 500, 200, $filename );
+
+ $this->assertImageSimilar(
+ $filename,
+ $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.png',
+ 'Image does not look as expected.',
+ 2000
+ );
+ }
+
public function testRender3dLineChart()
{
$filename = $this->tempDir . __FUNCTION__ . '.png';
OpenPOWER on IntegriCloud