diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2006-08-15 12:10:39 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2006-08-15 12:10:39 +0000 |
commit | 4c85aee953e34bb0f997af13fc9b35e5ed29699c (patch) | |
tree | c0d501e58acbcb00302e2d2ffdfcae0650eae590 /src | |
parent | e3f5f4876b49a8274979527fba29fcc004465f85 (diff) | |
download | zetacomponents-graph-4c85aee953e34bb0f997af13fc9b35e5ed29699c.zip zetacomponents-graph-4c85aee953e34bb0f997af13fc9b35e5ed29699c.tar.gz |
- Added implementation for bar charts to 3d renderer
Diffstat (limited to 'src')
-rw-r--r-- | src/options/renderer_3d.php | 20 | ||||
-rw-r--r-- | src/renderer/3d.php | 106 |
2 files changed, 124 insertions, 2 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(); |