summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/charts/pie.php12
-rw-r--r--src/datasets/array.php6
-rw-r--r--src/exceptions/invalid_data.php25
-rw-r--r--src/graph_autoload.php1
4 files changed, 43 insertions, 1 deletions
diff --git a/src/charts/pie.php b/src/charts/pie.php
index 782ad32..4d616c8 100644
--- a/src/charts/pie.php
+++ b/src/charts/pie.php
@@ -86,8 +86,13 @@ class ezcGraphPieChart extends ezcGraphChart
// Calculate sum of all values to be able to calculate percentage
$sum = 0;
- foreach ( $dataset as $value )
+ foreach ( $dataset as $name => $value )
{
+ if ( $value <= 0 )
+ {
+ throw new ezcGraphInvalidDataException( "Values > 0 required, '$name' => '$value'." );
+ }
+
$sum += $value;
}
if ( $this->options->sum !== false )
@@ -95,6 +100,11 @@ class ezcGraphPieChart extends ezcGraphChart
$sum = max( $sum, $this->options->sum );
}
+ if ( $sum <= 0 )
+ {
+ throw new ezcGraphInvalidDataException( "Pie charts require a value sum > 0, your value: '$sum'." );
+ }
+
$angle = 0;
foreach ( $dataset as $label => $value )
{
diff --git a/src/datasets/array.php b/src/datasets/array.php
index 3340cd0..ee7f0df 100644
--- a/src/datasets/array.php
+++ b/src/datasets/array.php
@@ -44,10 +44,16 @@ class ezcGraphArrayDataSet extends ezcGraphDataSet
throw new ezcGraphInvalidArrayDataSourceException( $data );
}
+ $this->data = array();
foreach ( $data as $key => $value )
{
$this->data[$key] = $value;
}
+
+ if ( !count( $this->data ) )
+ {
+ throw new ezcGraphInvalidDataException( 'Data sets should contain some values.' );
+ }
}
/**
diff --git a/src/exceptions/invalid_data.php b/src/exceptions/invalid_data.php
new file mode 100644
index 0000000..4c8f3f2
--- /dev/null
+++ b/src/exceptions/invalid_data.php
@@ -0,0 +1,25 @@
+<?php
+/**
+ * File containing the ezcGraphInvalidDataException class
+ *
+ * @package Graph
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * Exception thrown when invalid data is provided, which cannot be rendered
+ * for some reason.
+ *
+ * @package Graph
+ * @version //autogen//
+ */
+class ezcGraphInvalidDataException extends ezcGraphException
+{
+ public function __construct( $message )
+ {
+ parent::__construct( "You provided unusable data: '$message'." );
+ }
+}
+
+?>
diff --git a/src/graph_autoload.php b/src/graph_autoload.php
index 12aea2b..5bc8507 100644
--- a/src/graph_autoload.php
+++ b/src/graph_autoload.php
@@ -36,6 +36,7 @@ return array(
'ezcGraphUnknownColorDefinitionException' => 'Graph/exceptions/unknown_color_definition.php',
'ezcGraphUnknownFontTypeException' => 'Graph/exceptions/font_type.php',
'ezcGraphUnregularStepsException' => 'Graph/exceptions/unregular_steps.php',
+ 'ezcGraphInvalidDataException' => 'Graph/exceptions/invalid_data.php',
'ezcGraphChart' => 'Graph/interfaces/chart.php',
'ezcGraphChartElement' => 'Graph/interfaces/element.php',
'ezcGraphChartOptions' => 'Graph/options/chart.php',
OpenPOWER on IntegriCloud