ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 
 getFillArea ($datasets)
 Return colors between multiple graphs... More...
 

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
$xX dimension. Default 800.
$yY dimension. Default 350.

Definition at line 21 of file GoogleCharts.php.

References $x, and $y.

Member Function Documentation

◆ encodeaxis()

sspmod_statistics_Graph_GoogleCharts::encodeaxis (   $axis)
private

Definition at line 27 of file GoogleCharts.php.

28 {
29 return join('|', $axis);
30 }
$axis
Definition: showstats.php:64

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 33 of file GoogleCharts.php.

34 {
35 $setstr = array();
36 foreach ($datasets as $dataset) {
37 $setstr[] = self::extEncode($dataset);
38 }
39 return 'e:' . join(',', $setstr);
40 }
$datasets
Definition: showstats.php:61
$dataset
Definition: showstats.php:45

References $dataset, $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 42 of file GoogleCharts.php.

43 {
44 $extended_table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';
45 $chardata = '';
46 $delta = 4095;
47 $size = (strlen($extended_table));
48
49 foreach ($values as $k => $v) {
50 if ($v >= 0 && $v <= 100) {
51 $first = substr($extended_table, intval(($delta * $v / 100) / $size), 1);
52 $second = substr($extended_table, intval(($delta * $v / 100) % $size), 1);
53 $chardata .= "$first$second";
54 } else {
55 $chardata .= '__'; // Value out of max range;
56 }
57 }
58 return($chardata);
59 }
$size
Definition: RandomTest.php:84

References $size.

Referenced by encodedata().

+ Here is the caller graph for this function:

◆ getFillArea()

sspmod_statistics_Graph_GoogleCharts::getFillArea (   $datasets)
private

Return colors between multiple graphs...

Definition at line 64 of file GoogleCharts.php.

65 {
66 if (count($datasets) < 2) {
67 return '';
68 }
69
70 $colors = array('eeeeee', 'cccccc', 'aaaaaa', '99eecc');
71 $num = count($datasets) ;
72 $colstr = array();
73 for ($i = 0; $i < $num; $i++) {
74 $colstr[] = 'b' . ',' . $colors[$i] . ',' . ($i) . ',' . ($i+1) . ',0';
75 }
76 return '&chm=' . join('|', $colstr);
77 }
$i
Definition: disco.tpl.php:19

References $datasets, and $i.

◆ 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 154 of file GoogleCharts.php.

155 {
156 $mul = 1;
157
158 if ($max < 1) {
159 return 1;
160 }
161
162 $t = intval(ceil($max));
163 while ($t > 100) {
164 $t /= 10;
165 $mul *= 10;
166 }
167
168 $maxGridLines = 10;
169 $candidates = array(1, 2, 5, 10, 20, 25, 50, 100);
170
171 foreach ($candidates as $c) {
172 if ($t / $c < $maxGridLines) {
173 $tick_y = $c * $mul;
174 $target_top = intval(ceil($max / $tick_y) * $tick_y);
175 return $target_top;
176 }
177 }
178 }

References $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 89 of file GoogleCharts.php.

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

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 120 of file GoogleCharts.php.

121 {
122 $url = 'https://chart.apis.google.com/chart?' .
123
124 // Dimension of graph. Default is 800x350
125 'chs=' . $this->x . 'x' . $this->y .
126
127 // Dateset values.
128 '&chd=' . $this->encodedata(array($datasets)) .
129
130 // chart type is linechart
131 '&cht=p' .
132
133 '&chl=' . $this->encodeaxis($axis);
134
135 return $url;
136 }

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 11 of file GoogleCharts.php.

Referenced by __construct().

◆ $y

sspmod_statistics_Graph_GoogleCharts::$y
private

Definition at line 11 of file GoogleCharts.php.

Referenced by __construct().


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