Skip to content
Snippets Groups Projects
Commit af92ecda authored by Andreas Åkre Solberg's avatar Andreas Åkre Solberg
Browse files

clean up code, and add phpdoc

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1005 44740490-163a-0410-bde0-09ae8108e29a
parent e5ff9eda
No related branches found
No related tags found
No related merge requests found
<?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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment