summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--tests/driver_gd_test.php28
7 files changed, 230 insertions, 39 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;
+ }
}
?>
diff --git a/tests/driver_gd_test.php b/tests/driver_gd_test.php
index c988010..7c657c4 100644
--- a/tests/driver_gd_test.php
+++ b/tests/driver_gd_test.php
@@ -48,6 +48,7 @@ class ezcGraphGdDriverTest extends ezcTestCase
$this->driver->options->width = 200;
$this->driver->options->height = 100;
$this->driver->options->imageFormat = IMG_PNG;
+ $this->driver->options->font = $this->basePath . 'font.ttf';
}
/**
@@ -192,7 +193,7 @@ class ezcGraphGdDriverTest extends ezcTestCase
);
$this->assertEquals(
- '$hash',
+ '1dac226effaec9d8da712769cc7b8b9d',
md5_file( $filename ),
'Incorrect image rendered.'
);
@@ -219,7 +220,7 @@ class ezcGraphGdDriverTest extends ezcTestCase
);
$this->assertEquals(
- '$hash',
+ '1dac226effaec9d8da712769cc7b8b9d',
md5_file( $filename ),
'Incorrect image rendered.'
);
@@ -246,7 +247,7 @@ class ezcGraphGdDriverTest extends ezcTestCase
);
$this->assertEquals(
- '$hash',
+ 'ea1219631829e61485ee8dfefeca7ddd',
md5_file( $filename ),
'Incorrect image rendered.'
);
@@ -258,10 +259,11 @@ class ezcGraphGdDriverTest extends ezcTestCase
$this->driver->drawCircularArc(
new ezcGraphCoordinate( 100, 50 ),
+ 150,
80,
- 40,
+ 10,
12.5,
- 25,
+ 55,
ezcGraphColor::fromHex( '#3465A4' )
);
@@ -273,7 +275,7 @@ class ezcGraphGdDriverTest extends ezcTestCase
);
$this->assertEquals(
- '$hash',
+ '24b25c19ca1d03fbd9dcbd6b19b1dd13',
md5_file( $filename ),
'Incorrect image rendered.'
);
@@ -285,9 +287,10 @@ class ezcGraphGdDriverTest extends ezcTestCase
$this->driver->drawCircularArc(
new ezcGraphCoordinate( 100, 50 ),
+ 150,
80,
- 40,
- 25,
+ 10,
+ 55,
12.5,
ezcGraphColor::fromHex( '#3465A4' )
);
@@ -300,7 +303,7 @@ class ezcGraphGdDriverTest extends ezcTestCase
);
$this->assertEquals(
- '$hash',
+ '24b25c19ca1d03fbd9dcbd6b19b1dd13',
md5_file( $filename ),
'Incorrect image rendered.'
);
@@ -312,10 +315,11 @@ class ezcGraphGdDriverTest extends ezcTestCase
$this->driver->drawCircularArc(
new ezcGraphCoordinate( 100, 50 ),
+ 150,
80,
- 40,
+ 10,
25,
- 273,
+ 300,
ezcGraphColor::fromHex( '#3465A4' )
);
@@ -327,7 +331,7 @@ class ezcGraphGdDriverTest extends ezcTestCase
);
$this->assertEquals(
- '$hash',
+ '87218c59d376f08156acb844e9ebb6e4',
md5_file( $filename ),
'Incorrect image rendered.'
);
OpenPOWER on IntegriCloud