diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/interfaces/renderer.php | 166 | ||||
-rw-r--r-- | src/options/renderer.php | 19 | ||||
-rw-r--r-- | src/options/renderer_3d.php | 6 | ||||
-rw-r--r-- | src/renderer/2d.php | 81 | ||||
-rw-r--r-- | src/renderer/3d.php | 173 |
5 files changed, 280 insertions, 165 deletions
diff --git a/src/interfaces/renderer.php b/src/interfaces/renderer.php index 9d6b850..b273745 100644 --- a/src/interfaces/renderer.php +++ b/src/interfaces/renderer.php @@ -235,11 +235,171 @@ abstract class ezcGraphRenderer * @param int $symbol Type of symbol * @return void */ - abstract public function drawSymbol( + public function drawSymbol( ezcGraphBoundings $boundings, ezcGraphColor $color, - $symbol = ezcGraph::NO_SYMBOL - ); + $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 + ); + + // Draw optional gleam + if ( $this->options->legendSymbolGleam !== false ) + { + $this->driver->drawPolygon( + array( + $topLeft = new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize + ), + new ezcGraphCoordinate( + $boundings->x1 - ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize + ), + $bottomRight = new ezcGraphCoordinate( + $boundings->x1 - ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, + $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize + ), + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, + $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize + ), + ), + new ezcGraphLinearGradient( + $bottomRight, + $topLeft, + $color->darken( -$this->options->legendSymbolGleam ), + $color->darken( $this->options->legendSymbolGleam ) + ), + 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 + ); + + // Draw optional gleam + if ( $this->options->legendSymbolGleam !== false ) + { + $this->driver->drawPolygon( + array( + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize + ), + new ezcGraphCoordinate( + $boundings->x1 - ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 + ), + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, + $boundings->y1 - ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize + ), + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 + ), + ), + new ezcGraphLinearGradient( + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * 0.353553391, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * 0.353553391 + ), + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * ( 1 - 0.353553391 ), + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * ( 1 - 0.353553391 ) + ), + $color->darken( -$this->options->legendSymbolGleam ), + $color->darken( $this->options->legendSymbolGleam ) + ), + 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 + ); + + // Draw optional gleam + if ( $this->options->legendSymbolGleam !== false ) + { + $this->driver->drawCircle( + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) / 2, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) / 2 + ), + ( $boundings->x1 - $boundings->x0 ) * $this->options->legendSymbolGleamSize, + ( $boundings->y1 - $boundings->y0 ) * $this->options->legendSymbolGleamSize, + new ezcGraphLinearGradient( + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * 0.292893219, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * 0.292893219 + ), + new ezcGraphCoordinate( + $boundings->x0 + ( $boundings->x1 - $boundings->x0 ) * 0.707106781, + $boundings->y0 + ( $boundings->y1 - $boundings->y0 ) * 0.707106781 + ), + $color->darken( -$this->options->legendSymbolGleam ), + $color->darken( $this->options->legendSymbolGleam ) + ), + 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; + } + } /** * Finish rendering diff --git a/src/options/renderer.php b/src/options/renderer.php index 533f887..4e3a34f 100644 --- a/src/options/renderer.php +++ b/src/options/renderer.php @@ -33,6 +33,10 @@ * Procentual distance between bars. * @property float $pieChartOffset * Offset for starting with first pie chart segment in degrees. + * @property float $legendSymbolGleam + * Opacity of gleam in legend symbols + * @property float $legendSymbolGleamSize + * Size of gleam in legend symbols * * @package Graph */ @@ -57,6 +61,8 @@ class ezcGraphRendererOptions extends ezcGraphChartOptions $this->properties['barMargin'] = .1; $this->properties['barPadding'] = .05; $this->properties['pieChartOffset'] = 0; + $this->properties['legendSymbolGleam'] = false; + $this->properties['legendSymbolGleamSize'] = .9; parent::__construct( $options ); } @@ -106,6 +112,19 @@ class ezcGraphRendererOptions extends ezcGraphChartOptions case 'pieChartOffset': $this->properties['pieChartOffset'] = $propertyValue % 360; break; + case 'legendSymbolGleam': + $this->properties['legendSymbolGleam'] = min( 1, max( 0, (float) $propertyValue ) ); + break; + case 'legendSymbolGleamSize': + $this->properties['legendSymbolGleamSize'] = min( 1, max( 0, (float) $propertyValue ) ); + break; + case 'legendSymbolGleamColor': + if ( !$propertyValue instanceof ezcGraphColor ) + { + throw new ezcBaseValueException( $propertyName, $propertyValue, 'ezcGraphColor' ); + } + $this->properties['legendSymbolGleamColor'] = $propertyValue; + break; default: return parent::__set( $propertyName, $propertyValue ); } diff --git a/src/options/renderer_3d.php b/src/options/renderer_3d.php index 9de4b03..459b5fd 100644 --- a/src/options/renderer_3d.php +++ b/src/options/renderer_3d.php @@ -38,6 +38,8 @@ * Factor to darken the color used for the bars side polygon. * @property float $barDarkenTop * Factor to darken the color used for the bars top polygon. + * @property float $barChartGleam + * Transparancy for gleam on bar charts * * @package Graph */ @@ -65,6 +67,7 @@ class ezcGraphRenderer3dOptions extends ezcGraphRendererOptions $this->properties['pieChartGleamColor'] = ezcGraphColor::fromHex( '#FFFFFF' ); $this->properties['barDarkenSide'] = .2; $this->properties['barDarkenTop'] = .4; + $this->properties['barChartGleam'] = false; parent::__construct( $options ); } @@ -126,6 +129,9 @@ class ezcGraphRenderer3dOptions extends ezcGraphRendererOptions case 'barDarkenTop': $this->properties['barDarkenTop'] = min( 1, max( 0, (float) $propertyValue ) ); break; + case 'barChartGleam': + $this->properties['barChartGleam'] = min( 1, max( 0, (float) $propertyValue ) ); + break; default: return parent::__set( $propertyName, $propertyValue ); } diff --git a/src/renderer/2d.php b/src/renderer/2d.php index ddc389f..5233013 100644 --- a/src/renderer/2d.php +++ b/src/renderer/2d.php @@ -942,87 +942,6 @@ class ezcGraphRenderer2d extends ezcGraphRenderer while ( ( $position->x < $boundings->x1 ) && ( $repeat & ezcGraph::HORIZONTAL ) ); } - - /** - * Draw Symbol - * - * Draws a single symbol defined by the symbol constants in ezcGraph. for - * NO_SYMBOL a rect will be drawn. - * - * @param ezcGraphBoundings $boundings Boundings of symbol - * @param ezcGraphColor $color Color of symbol - * @param int $symbol Type of symbol - * @return void - */ - 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() { diff --git a/src/renderer/3d.php b/src/renderer/3d.php index c1fefd2..3c1edc0 100644 --- a/src/renderer/3d.php +++ b/src/renderer/3d.php @@ -624,6 +624,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer ), ); + // Draw top side $this->barPostProcessing[] = array( 'index' => $barPolygonArray[1]->x, 'method' => 'drawPolygon', @@ -647,6 +648,45 @@ class ezcGraphRenderer3d extends ezcGraphRenderer ), ); + // Draw top side gleam + if ( $this->options->barChartGleam !== false ) + { + $this->barPostProcessing[] = array( + 'index' => $barPolygonArray[1]->x + 1, + 'method' => 'drawPolygon', + 'parameters' => array( + ( $barPolygonArray[1]->y < $barPolygonArray[3]->y + ? array( + $this->get3dCoordinate( $barPolygonArray[1], $startDepth ), + $this->get3dCoordinate( $barPolygonArray[2], $startDepth ), + $this->get3dCoordinate( $barPolygonArray[2], $endDepth ), + $this->get3dCoordinate( $barPolygonArray[1], $endDepth ), + ) + : array( + $this->get3dCoordinate( $barPolygonArray[0], $startDepth ), + $this->get3dCoordinate( $barPolygonArray[3], $startDepth ), + $this->get3dCoordinate( $barPolygonArray[3], $endDepth ), + $this->get3dCoordinate( $barPolygonArray[0], $endDepth ), + ) + ), + new ezcGraphLinearGradient( + ( $barPolygonArray[1]->y < $barPolygonArray[3]->y + ? $this->get3dCoordinate( $barPolygonArray[2], $endDepth ) + : $this->get3dCoordinate( $barPolygonArray[3], $endDepth ) + ), + ( $barPolygonArray[1]->y < $barPolygonArray[3]->y + ? $this->get3dCoordinate( $barPolygonArray[1], $startDepth ) + : $this->get3dCoordinate( $barPolygonArray[0], $startDepth ) + ), + ezcGraphColor::fromHex( '#FFFFFFFF' ), + ezcGraphColor::fromHex( '#FFFFFF' )->transparent( 1 - $this->options->barChartGleam ) + ), + true + ), + ); + } + + // Draw front side $this->barPostProcessing[] = array( 'index' => $barPolygonArray[1]->x, 'method' => 'drawPolygon', @@ -661,6 +701,31 @@ class ezcGraphRenderer3d extends ezcGraphRenderer true ), ); + + // Draw front side gleam + if ( $this->options->barChartGleam !== false ) + { + $this->barPostProcessing[] = array( + 'index' => $barPolygonArray[1]->x + 1, + 'method' => 'drawPolygon', + 'parameters' => array( + array( + $this->get3dCoordinate( $barPolygonArray[0], $startDepth ), + $this->get3dCoordinate( $barPolygonArray[1], $startDepth ), + $this->get3dCoordinate( $barPolygonArray[2], $startDepth ), + $this->get3dCoordinate( $barPolygonArray[3], $startDepth ), + ), + new ezcGraphLinearGradient( + $this->get3dCoordinate( $barPolygonArray[3], $startDepth ), + $this->get3dCoordinate( $barPolygonArray[1], $startDepth ), + ezcGraphColor::fromHex( '#FFFFFFFF' ), + ezcGraphColor::fromHex( '#FFFFFF' )->transparent( 1 - $this->options->barChartGleam ) + ), + true + ), + ); + } + break; case ezcGraph::DIAMOND: $barCoordinateArray = array( @@ -678,6 +743,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer ), ); + // Left side $this->barPostProcessing[] = array( 'index' => $barCoordinateArray['x'][0], 'method' => 'drawPolygon', @@ -693,6 +759,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer ), ); + // Right side $this->barPostProcessing[] = array( 'index' => $barCoordinateArray['x'][1], 'method' => 'drawPolygon', @@ -713,6 +780,7 @@ class ezcGraphRenderer3d extends ezcGraphRenderer $barCoordinateArray['y'][1] ); + // Top side $this->barPostProcessing[] = array( 'index' => $barCoordinateArray['x'][0], 'method' => 'drawPolygon', @@ -727,6 +795,30 @@ class ezcGraphRenderer3d extends ezcGraphRenderer true ), ); + + // Top side gleam + if ( $this->options->barChartGleam !== false ) + { + $this->barPostProcessing[] = array( + 'index' => $barCoordinateArray['x'][0] + 1, + 'method' => 'drawPolygon', + 'parameters' => array( + array( + $this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][1], $topLocation ), $startDepth ), + $this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][2], $topLocation ), $midDepth ), + $this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][3], $topLocation ), $endDepth ), + $this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][0], $topLocation ), $midDepth ), + ), + new ezcGraphLinearGradient( + $this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][2], $topLocation ), $midDepth ), + $this->get3dCoordinate( new ezcGraphCoordinate( $barCoordinateArray['x'][0], $topLocation ), $midDepth ), + ezcGraphColor::fromHex( '#FFFFFFFF' ), + ezcGraphColor::fromHex( '#FFFFFF' )->transparent( 1 - $this->options->barChartGleam ) + ), + true + ), + ); + } break; case ezcGraph::BULLET: case ezcGraph::CIRCLE: @@ -1655,87 +1747,6 @@ class ezcGraphRenderer3d extends ezcGraphRenderer while ( ( $position->x < $boundings->x1 ) && ( $repeat & ezcGraph::HORIZONTAL ) ); } - - /** - * Draw Symbol - * - * Draws a single symbol defined by the symbol constants in ezcGraph. for - * NO_SYMBOL a rect will be drawn. - * - * @param ezcGraphBoundings $boundings Boundings of symbol - * @param ezcGraphColor $color Color of symbol - * @param int $symbol Type of symbol - * @return void - */ - 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() { |