summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-05-30 10:24:32 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-05-30 10:24:32 +0000
commite474041293c79a80ca818338a5dde07e6d1fc898 (patch)
tree7743c13ce58d7cecf9b7e3c153d2de1be7c8ff2e /src
parenta2be390c78a5b98655b08fc5c3da6c688011922d (diff)
downloadzetacomponents-graph-e474041293c79a80ca818338a5dde07e6d1fc898.zip
zetacomponents-graph-e474041293c79a80ca818338a5dde07e6d1fc898.tar.gz
- Implemented circular arcs for gd driver
Diffstat (limited to 'src')
-rw-r--r--src/driver/gd.php123
-rw-r--r--src/driver/svg.php21
-rw-r--r--src/interfaces/driver.php20
-rw-r--r--src/options/driver.php43
-rw-r--r--src/options/gd_driver.php16
-rw-r--r--src/structs/color.php18
6 files changed, 214 insertions, 27 deletions
diff --git a/src/driver/gd.php b/src/driver/gd.php
index 5172334..59a7a4e 100644
--- a/src/driver/gd.php
+++ b/src/driver/gd.php
@@ -170,23 +170,130 @@ class ezcGraphGdDriver extends ezcGraphDriver
*/
public function drawCircleSector( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, ezcGraphColor $color )
{
-
+ $image = $this->getImage();
+ $drawColor = $this->allocate( $color );
+
+ // Normalize angles
+ if ( $startAngle > $endAngle )
+ {
+ $tmp = $startAngle;
+ $startAngle = $endAngle;
+ $endAngle = $tmp;
+ }
+
+ imagefilledarc( $image, $center->x, $center->y, $width, $height, $startAngle, $endAngle, $drawColor, IMG_ARC_PIE );
}
/**
* Draws a circular arc
*
- * @param ezcGraphCoordinate $center
- * @param mixed $width
- * @param mixed $height
- * @param mixed $startAngle
- * @param mixed $endAngle
- * @param ezcGraphColor $color
+ * @param ezcGraphCoordinate $center Center of ellipse
+ * @param integer $width Width of ellipse
+ * @param integer $height Height of ellipse
+ * @param integer $size Height of border
+ * @param float $startAngle Starting angle of circle sector
+ * @param float $endAngle Ending angle of circle sector
+ * @param ezcGraphColor $color Color of Border
* @return void
*/
- public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, ezcGraphColor $color )
+ public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color )
{
+ $image = $this->getImage();
+ $drawColor = $this->allocate( $color );
+
+ // Normalize angles
+ if ( $startAngle > $endAngle )
+ {
+ $tmp = $startAngle;
+ $startAngle = $endAngle;
+ $endAngle = $tmp;
+ }
+ $startIteration = ceil( $startAngle / $this->options->detail ) * $this->options->detail;
+ $endIteration = floor( $endAngle / $this->options->detail ) * $this->options->detail;
+
+
+ if ( $startAngle < $startIteration )
+ {
+ // Draw initial step
+ $this->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $startAngle ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $startAngle ) ) * $height ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $startAngle ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $startAngle ) ) * $height + $size ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $startIteration ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $startIteration ) ) * $height + $size ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $startIteration ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $startIteration ) ) * $height ) / 2 )
+ ),
+ ),
+ $color->darken( $this->options->shadeCircularArc * abs ( cos ( deg2rad( $startIteration ) ) ) ),
+ true
+ );
+ }
+
+ // Draw all steps
+ for ( ; $startIteration < $endIteration; $startIteration += $this->options->detail )
+ {
+ $end = $startIteration + $this->options->detail;
+ $this->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $startIteration ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $startIteration ) ) * $height ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $startIteration ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $startIteration ) ) * $height + $size ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $end ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $end ) ) * $height + $size ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $end ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $end ) ) * $height ) / 2 )
+ ),
+ ),
+ $color->darken( $this->options->shadeCircularArc * abs ( cos ( deg2rad( $startIteration ) ) ) ),
+ true
+ );
+ }
+
+ if ( $endIteration < $endAngle )
+ {
+ // Draw closing step
+ $this->drawPolygon(
+ array(
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $endIteration ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $endIteration ) ) * $height ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $endIteration ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $endIteration ) ) * $height + $size ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $endAngle ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $endAngle ) ) * $height + $size ) / 2 )
+ ),
+ new ezcGraphCoordinate(
+ $center->x + ( ( cos( deg2rad( $endAngle ) ) * $width ) / 2 ),
+ $center->y + ( ( sin( deg2rad( $endAngle ) ) * $height ) / 2 )
+ ),
+ ),
+ $color->darken( $this->options->shadeCircularArc * abs ( cos ( deg2rad( $endIteration ) ) ) ),
+ true
+ );
+ }
}
/**
diff --git a/src/driver/svg.php b/src/driver/svg.php
index 54e9689..55c0ad5 100644
--- a/src/driver/svg.php
+++ b/src/driver/svg.php
@@ -15,6 +15,12 @@
class ezcGraphSVGDriver extends ezcGraphDriver
{
+
+ public function __construct( array $options = array() )
+ {
+
+ }
+
/**
* Draws a single polygon
*
@@ -75,15 +81,16 @@ class ezcGraphSVGDriver extends ezcGraphDriver
/**
* Draws a circular arc
*
- * @param ezcGraphCoordinate $center
- * @param mixed $width
- * @param mixed $height
- * @param mixed $startAngle
- * @param mixed $endAngle
- * @param ezcGraphColor $color
+ * @param ezcGraphCoordinate $center Center of ellipse
+ * @param integer $width Width of ellipse
+ * @param integer $height Height of ellipse
+ * @param integer $size Height of border
+ * @param float $startAngle Starting angle of circle sector
+ * @param float $endAngle Ending angle of circle sector
+ * @param ezcGraphColor $color Color of Border
* @return void
*/
- public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, ezcGraphColor $color )
+ public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color )
{
}
diff --git a/src/interfaces/driver.php b/src/interfaces/driver.php
index 2060edd..d6956f2 100644
--- a/src/interfaces/driver.php
+++ b/src/interfaces/driver.php
@@ -35,10 +35,7 @@ abstract class ezcGraphDriver
*/
protected $height;
- public function __construct( array $options = array() )
- {
- $this->options = new ezcGraphDriverOptions( $options );
- }
+ abstract public function __construct( array $options = array() );
/**
* Options write access
@@ -135,15 +132,16 @@ abstract class ezcGraphDriver
/**
* Draws a circular arc
*
- * @param ezcGraphCoordinate $center
- * @param mixed $width
- * @param mixed $height
- * @param mixed $startAngle
- * @param mixed $endAngle
- * @param ezcGraphColor $color
+ * @param ezcGraphCoordinate $center Center of ellipse
+ * @param integer $width Width of ellipse
+ * @param integer $height Height of ellipse
+ * @param integer $size Height of border
+ * @param float $startAngle Starting angle of circle sector
+ * @param float $endAngle Ending angle of circle sector
+ * @param ezcGraphColor $color Color of Border
* @return void
*/
- abstract public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $startAngle, $endAngle, ezcGraphColor $color );
+ abstract public function drawCircularArc( ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color );
/**
* Draws a circle
diff --git a/src/options/driver.php b/src/options/driver.php
index 8ea338e..f01d846 100644
--- a/src/options/driver.php
+++ b/src/options/driver.php
@@ -12,7 +12,7 @@
*
* @package Graph
*/
-class ezcGraphDriverOptions extends ezcBaseOptions
+abstract class ezcGraphDriverOptions extends ezcBaseOptions
{
/**
* Width of the chart
@@ -30,6 +30,34 @@ class ezcGraphDriverOptions extends ezcBaseOptions
protected $height;
/**
+ * Font face
+ *
+ * @var mixed
+ */
+ protected $font;
+
+ /**
+ * Minimum font size for displayed texts
+ *
+ * @var float
+ */
+ protected $minFontSize = 6;
+
+ /**
+ * Maximum font size for displayed texts
+ *
+ * @var float
+ */
+ protected $maxFontSize = 24;
+
+ /**
+ * Color of text
+ *
+ * @var ezcGraphColor
+ */
+ protected $fontColor;
+
+ /**
* Set an option value
*
* @param string $propertyName
@@ -48,11 +76,24 @@ class ezcGraphDriverOptions extends ezcBaseOptions
case 'height':
$this->height = max( 1, (int) $propertyValue );
break;
+ case 'minFontSize':
+ $this->minFontSize = max(1, (float) $propertyValue);
+ break;
+ case 'maxFontSize':
+ $this->maxFontSize = max(1, (float) $propertyValue);
+ break;
+ case 'font':
+ // Heavily depends on driver - check should be implemented in
+ // derived classes
+ $this->checkFont( $propertyValue );
+ break;
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
break;
}
}
+
+ abstract protected function checkFont( $font );
}
?>
diff --git a/src/options/gd_driver.php b/src/options/gd_driver.php
index 87de839..d7d52eb 100644
--- a/src/options/gd_driver.php
+++ b/src/options/gd_driver.php
@@ -25,6 +25,10 @@ class ezcGraphGdDriverOptions extends ezcGraphDriverOptions
*/
protected $imageFormat;
+ protected $detail = 1;
+
+ protected $shadeCircularArc = .5;
+
/**
* Set an option value
*
@@ -53,6 +57,18 @@ class ezcGraphGdDriverOptions extends ezcGraphDriverOptions
break;
}
}
+
+ protected function checkFont( $font )
+ {
+ // We expect a valid font file here.
+ if ( !is_file( $font ) || !is_readable( $font ) )
+ {
+ throw new ezcBaseFileNotFoundException( $font );
+ }
+
+ // @TODO: Check if font file is a valid TTF file.
+ $this->font = realpath( $font );
+ }
}
?>
diff --git a/src/structs/color.php b/src/structs/color.php
index c9b1617..c95ce6c 100644
--- a/src/structs/color.php
+++ b/src/structs/color.php
@@ -197,6 +197,24 @@ class ezcGraphColor
throw new ezcGraphUnknownColorDefinitionException( $color );
}
}
+
+ /**
+ * Darkens the color
+ *
+ * @param float $value Percent to darken the color
+ * @return void
+ */
+ public function darken( $value )
+ {
+ $color = clone $this;
+
+ $value = 1 - $value;
+ $color->red *= $value;
+ $color->green *= $value;
+ $color->blue *= $value;
+
+ return $color;
+ }
}
?>
OpenPOWER on IntegriCloud