ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
sspmod_statistics_Graph_GoogleCharts Class Reference
+ Collaboration diagram for sspmod_statistics_Graph_GoogleCharts:

Public Member Functions

 __construct ($x=800, $y=350)
 Constructor. More...
 
 show ($axis, $axispos, $datasets, $maxes)
 Generate a Google Charts URL which points to a generated image. More...
 
 showPie ($axis, $datasets)
 

Static Public Member Functions

static extEncode ($values)
 
static roof ($max)
 Takes a input value, and generates a value that suits better as a max value on the Y-axis. More...
 

Private Member Functions

 encodeaxis ($axis)
 
 encodedata ($datasets)
 

Private Attributes

 $x
 
 $y
 

Detailed Description

Definition at line 9 of file GoogleCharts.php.

Constructor & Destructor Documentation

◆ __construct()

sspmod_statistics_Graph_GoogleCharts::__construct (   $x = 800,
  $y = 350 
)

Constructor.

Takes dimension of graph as parameters. X and Y.

Parameters
integer$xX dimension. Default 800.
integer$yY dimension. Default 350.

Definition at line 29 of file GoogleCharts.php.

References $x, and $y.

Member Function Documentation

◆ encodeaxis()

sspmod_statistics_Graph_GoogleCharts::encodeaxis (   $axis)
private

Definition at line 35 of file GoogleCharts.php.

36 {
37 return join('|', $axis);
38 }
$axis
Definition: showstats.php:88

References $axis.

Referenced by show(), and showPie().

+ Here is the caller graph for this function:

◆ encodedata()

sspmod_statistics_Graph_GoogleCharts::encodedata (   $datasets)
private

Definition at line 41 of file GoogleCharts.php.

42 {
43 $setstr = array();
44 foreach ($datasets as $dataset) {
45 $setstr[] = self::extEncode($dataset);
46 }
47 return 'e:' . join(',', $setstr);
48 }
$datasets
Definition: showstats.php:85

References $datasets, and extEncode().

Referenced by show(), and showPie().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ extEncode()

static sspmod_statistics_Graph_GoogleCharts::extEncode (   $values)
static

Definition at line 50 of file GoogleCharts.php.

51 {
52 $extended_table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';
53 $chardata = '';
54 $delta = 4095;
55 $size = (strlen($extended_table));
56
57 foreach ($values as $k => $v) {
58 if ($v >= 0 && $v <= 100) {
59 $first = substr($extended_table, intval(($delta * $v / 100) / $size), 1);
60 $second = substr($extended_table, intval(($delta * $v / 100) % $size), 1);
61 $chardata .= "$first$second";
62 } else {
63 $chardata .= '__'; // Value out of max range;
64 }
65 }
66 return($chardata);
67 }
$size
Definition: RandomTest.php:84
$values

References $size, and $values.

Referenced by encodedata().

+ Here is the caller graph for this function:

◆ roof()

static sspmod_statistics_Graph_GoogleCharts::roof (   $max)
static

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: $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 '

' . $f . ' => ' . sspmod_statistics_Graph_GoogleCharts::roof($f); }

Parameters
$maxInput value.

Definition at line 144 of file GoogleCharts.php.

145 {
146 $mul = 1;
147
148 if ($max < 1) {
149 return 1;
150 }
151
152 $t = intval(ceil($max));
153 while ($t > 100) {
154 $t /= 10;
155 $mul *= 10;
156 }
157
158 $maxGridLines = 10;
159 $candidates = array(1, 2, 5, 10, 20, 25, 50, 100);
160
161 foreach ($candidates as $c) {
162 if ($t / $c < $maxGridLines) {
163 $tick_y = $c * $mul;
164 $target_top = intval(ceil($max / $tick_y) * $tick_y);
165 return $target_top;
166 }
167 }
168 }

References $c, and $t.

Referenced by sspmod_statistics_StatDataset\calculateMax().

+ Here is the caller graph for this function:

◆ show()

sspmod_statistics_Graph_GoogleCharts::show (   $axis,
  $axispos,
  $datasets,
  $maxes 
)

Generate a Google Charts URL which points to a generated image.

More documentation on Google Charts here: http://code.google.com/apis/chart/

Parameters
$axisAxis
$axpisAxis positions
$datasetsDatasets values
$maxMax value. Will be the topmost value on the Y-axis.

Definition at line 79 of file GoogleCharts.php.

80 {
81 $labeld = '&chxt=x,y' . '&chxr=0,0,1|1,0,' . $maxes[0];
82 if (count($datasets) > 1) {
83 if (count($datasets) !== count($maxes)) {
84 throw new Exception('Incorrect number of max calculations for graph plotting.');
85 }
86 $labeld = '&chxt=x,y,r' . '&chxr=0,0,1|1,0,' . $maxes[0] . '|2,0,' . $maxes[1];
87 }
88
89 $url = 'https://chart.apis.google.com/chart?' .
90 // Dimension of graph. Default is 800x350
91 'chs=' . $this->x . 'x' . $this->y .
92
93 // Dateset values
94 '&chd=' . $this->encodedata($datasets) .
95
96 // Fill area...
97 '&chco=ff5c00,cca600' .
98 '&chls=1,1,0|1,6,3' .
99
100 // chart type is linechart
101 '&cht=lc' .
102 $labeld .
103 '&chxl=0:|' . $this->encodeaxis($axis) . # . $'|1:||top' .
104 '&chxp=0,' . join(',', $axispos) .
105 '&chg=' . (2400/(count($datasets[0])-1)) . ',-1,3,3'; // lines
106
107 return $url;
108 }
$url
$maxes
Definition: showstats.php:90

References $axis, $datasets, $maxes, $url, encodeaxis(), and encodedata().

+ Here is the call graph for this function:

◆ showPie()

sspmod_statistics_Graph_GoogleCharts::showPie (   $axis,
  $datasets 
)

Definition at line 110 of file GoogleCharts.php.

111 {
112 $url = 'https://chart.apis.google.com/chart?' .
113
114 // Dimension of graph. Default is 800x350
115 'chs=' . $this->x . 'x' . $this->y .
116
117 // Dateset values.
118 '&chd=' . $this->encodedata(array($datasets)) .
119
120 // chart type is linechart
121 '&cht=p' .
122
123 '&chl=' . $this->encodeaxis($axis);
124
125 return $url;
126 }

References $axis, $datasets, $url, encodeaxis(), and encodedata().

+ Here is the call graph for this function:

Field Documentation

◆ $x

sspmod_statistics_Graph_GoogleCharts::$x
private

Definition at line 14 of file GoogleCharts.php.

Referenced by __construct().

◆ $y

sspmod_statistics_Graph_GoogleCharts::$y
private

Definition at line 19 of file GoogleCharts.php.

Referenced by __construct().


The documentation for this class was generated from the following file: