summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-11-30 09:29:35 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-11-30 09:29:35 +0000
commit5ced6d5c25202717ef3ec1a811cffba6b44bcb79 (patch)
tree9e809048dd794a6d7d95497fe60f11bbcd77cc88
parenta624a3e637586a8efc327cd5e8e6021bf3546c00 (diff)
downloadzetacomponents-graph-5ced6d5c25202717ef3ec1a811cffba6b44bcb79.zip
zetacomponents-graph-5ced6d5c25202717ef3ec1a811cffba6b44bcb79.tar.gz
- Fixed bug #9568: (Devision by zero warning)
-rw-r--r--ChangeLog1
-rw-r--r--src/charts/line.php5
-rw-r--r--src/charts/pie.php5
-rw-r--r--src/exceptions/no_data.php24
-rw-r--r--src/graph_autoload.php1
-rw-r--r--tests/chart_test.php26
6 files changed, 62 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a7e5c0..c4ff7b6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
- Renamed pie chart options percentTreshHold to percentThreshold and
absoluteTreshHold to absoluteThreshold
+- Fixed issue #9568: Devision by zero warning
- Fixed issue #9655: pieChartOffset and highlight do not work together in 2d
renderer
- Fixed issue #9586: No data rendered with string keys on date axis.
diff --git a/src/charts/line.php b/src/charts/line.php
index 2024ef0..3cdd444 100644
--- a/src/charts/line.php
+++ b/src/charts/line.php
@@ -290,6 +290,11 @@ class ezcGraphLineChart extends ezcGraphChart
*/
public function render( $width, $height, $file = null )
{
+ if ( !count( $this->data ) )
+ {
+ throw new ezcGraphNoDataException();
+ }
+
// Set image properties in driver
$this->driver->options->width = $width;
$this->driver->options->height = $height;
diff --git a/src/charts/pie.php b/src/charts/pie.php
index 58c4ec7..2201ac7 100644
--- a/src/charts/pie.php
+++ b/src/charts/pie.php
@@ -182,6 +182,11 @@ class ezcGraphPieChart extends ezcGraphChart
*/
public function render( $width, $height, $file = null )
{
+ if ( !count( $this->data ) )
+ {
+ throw new ezcGraphNoDataException();
+ }
+
// Set image properties in driver
$this->driver->options->width = $width;
$this->driver->options->height = $height;
diff --git a/src/exceptions/no_data.php b/src/exceptions/no_data.php
new file mode 100644
index 0000000..68069c8
--- /dev/null
+++ b/src/exceptions/no_data.php
@@ -0,0 +1,24 @@
+<?php
+/**
+ * File containing the ezcGraphNoDataException class
+ *
+ * @package Graph
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Exception shown, when trying to render a chart without assigning any data.
+ *
+ * @package Graph
+ * @version //autogen//
+ */
+class ezcGraphNoDataException extends ezcGraphException
+{
+ public function __construct()
+ {
+ parent::__construct( "No data sets assigned to chart." );
+ }
+}
+
+?>
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index 5ba3f02..1b99888 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -70,6 +70,7 @@ return array(
'ezcGraphChartElement' => 'Graph/interfaces/element.php',
'ezcGraphNoSuchElementException' => 'Graph/exceptions/no_such_element.php',
+ 'ezcGraphNoDataException' => 'Graph/exceptions/no_data.php',
'ezcGraphFontOptions' => 'Graph/options/font.php',
'ezcGraphChartElementText' => 'Graph/element/text.php',
'ezcGraphChartElementLegend' => 'Graph/element/legend.php',
diff --git a/tests/chart_test.php b/tests/chart_test.php
index 803eb13..796498d 100644
--- a/tests/chart_test.php
+++ b/tests/chart_test.php
@@ -182,5 +182,31 @@ class ezcGraphChartTest extends ezcTestCase
$this->fail( 'Expected ezcGraphInvalidDriverException' );
}
+
+ public function testPieChartWithoutData()
+ {
+ try
+ {
+ $pieChart = new ezcGraphPieChart();
+ $pieChart->render( 400, 200 );
+ }
+ catch ( ezcGraphNoDataException $e )
+ {
+ return true;
+ }
+ }
+
+ public function testBarChartWithoutData()
+ {
+ try
+ {
+ $pieChart = new ezcGraphPieChart();
+ $pieChart->render( 400, 200 );
+ }
+ catch ( ezcGraphNoDataException $e )
+ {
+ return true;
+ }
+ }
}
?>
OpenPOWER on IntegriCloud