From af92ecda6970c7ac6269d0c02cc8785d68271a86 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Sat, 15 Nov 2008 12:03:08 +0000
Subject: [PATCH] clean up code, and add phpdoc

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1005 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/statistics/lib/Graph/GoogleCharts.php | 49 ++++++++++++++++---
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/modules/statistics/lib/Graph/GoogleCharts.php b/modules/statistics/lib/Graph/GoogleCharts.php
index 07321adc7..f11231597 100644
--- a/modules/statistics/lib/Graph/GoogleCharts.php
+++ b/modules/statistics/lib/Graph/GoogleCharts.php
@@ -1,5 +1,8 @@
 <?php
 /*
+ * sspmod_statistics_Graph_GoogleCharts will help you to create a Google Chart
+ * using the Google Charts API. 
+ *
  * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>
  * @package simpleSAMLphp
  * @version $Id$
@@ -9,9 +12,14 @@ class sspmod_statistics_Graph_GoogleCharts {
 	private $x, $y;
 
 	/**
-	 * Constructor
+	 * Constructor.
+	 *
+	 * Takes dimension of graph as parameters. X and Y.
+	 *
+	 * @param $x 	X dimension. Default 800.
+	 * @param $y 	Y dimension. Default 350.
 	 */
-	public function __construct($x, $y) {
+	public function __construct($x = 800, $y = 350) {
 		$this->x = $x; $this->y = $y;
 	}
 
@@ -24,11 +32,25 @@ class sspmod_statistics_Graph_GoogleCharts {
 		return 't:' . join(',', $data);
 	}
 	
+	/**
+	 * Generate a Google Charts URL which points to a generated image.
+	 * More documentation on Google Charts here: 
+	 *   http://code.google.com/apis/chart/
+	 *
+	 * @param $axis		Axis
+	 * @param $axpis	Axis positions
+	 * @param $values	Dataset values
+	 * @param $max		Max value. Will be the topmost value on the Y-axis.
+	 */
 	public function show($axis, $axispos, $values, $max) {
 	
 		$nv = count($values);
 		$url = 'http://chart.apis.google.com/chart?' .
-			'chs=800x350' .
+			
+			// Dimension of graph. Default is 800x350
+			'chs=' . $this->x . 'x' . $this->y . 
+			
+			// Dateset values.
 			'&chd=' . $this->encodedata($values) .
 			'&cht=lc' .
 			'&chxt=x,y' .
@@ -41,17 +63,28 @@ class sspmod_statistics_Graph_GoogleCharts {
 		return $url;
 	}
 	
+	/**
+	 * Takes a input value, and generates a value that suits better as a max
+	 * value on the Y-axis. In example 37.6 will not make a good max value, instead
+	 * it will return 40. It will always return an equal or larger number than it gets
+	 * as input.
+	 *
+	 * Here is some test code:
+	 * <code>
+	 * 		$foo = array(0, 2, 2.3, 2.6, 6, 10, 15, 98, 198, 256, 487, 563, 763, 801, 899, 999, 987, 198234.485, 283746);
+	 *		foreach ($foo AS $f) {
+	 *			echo '<p>' . $f . ' => ' . sspmod_statistics_Graph_GoogleCharts::roof($f);
+	 *		}
+	 * </code>
+	 * 
+	 * @param $in 	Input value.
+	 */
 	public static function roof($in) {
 		if ($in < 1) return 1;
 		$base = log10($in);
 		$r =  ceil(5*$in / pow(10, ceil($base)));
 		return ($r/5)*pow(10, ceil($base));
 	}
-	// $foo = array(0, 2, 2.3, 2.6, 6, 10, 15, 98, 198, 256, 487, 563, 763, 801, 899, 999, 987, 198234.485, 283746);
-	// foreach ($foo AS $f) {
-	// 	echo '<p>' . $f . ' => ' . roof($f);
-	// }
-	// exit;
 
 }
 
-- 
GitLab