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

Statistics Extended Google chart encoding... Add option of alternative compare plot in graph...

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1540 44740490-163a-0410-bde0-09ae8108e29a
parent cfc345b9
No related branches found
No related tags found
No related merge requests found
...@@ -31,12 +31,32 @@ class sspmod_statistics_Graph_GoogleCharts { ...@@ -31,12 +31,32 @@ class sspmod_statistics_Graph_GoogleCharts {
private function encodedata($datasets) { private function encodedata($datasets) {
$setstr = array(); $setstr = array();
foreach ($datasets AS $dataset) { foreach ($datasets AS $dataset) {
$setstr[] = join(',', $dataset); $setstr[] = self::extEncode($dataset);
} }
return 't:' . join('|', $setstr); return 'e:' . join(',', $setstr);
} }
public static function extEncode($values) { #}, $max = 4095, $min = 0){
$extended_table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.';
$chardata = '';
$delta = 4095;
$size = (strlen($extended_table));
foreach($values as $k => $v){
if($v >= 0 && $v <= 100){
$first = substr($extended_table, round( ($delta*$v/100) / $size),1);
$second = substr($extended_table, round( ($delta*$v/100) % $size), 1);
$chardata .= "$first$second";
#echo '<p>encoding ' . $v . ' to ' . $first . ' ' . $second . '';
} else {
$chardata .= '__'; // Value out of max range;
}
}
#echo ' encoding ' . join(' ', $values) . ' to ' . $chardata; exit;
return($chardata);
}
/** /**
* Return colors between multiple graphs... * Return colors between multiple graphs...
...@@ -65,8 +85,18 @@ class sspmod_statistics_Graph_GoogleCharts { ...@@ -65,8 +85,18 @@ class sspmod_statistics_Graph_GoogleCharts {
* @param $datasets Datasets values * @param $datasets Datasets values
* @param $max Max value. Will be the topmost value on the Y-axis. * @param $max Max value. Will be the topmost value on the Y-axis.
*/ */
public function show($axis, $axispos, $datasets, $max) { public function show($axis, $axispos, $datasets, $maxes) {
$labeld = '&chxt=x,y' . '&chxr=0,0,1|1,0,' . $maxes[0];
if (count($datasets) > 1) {
if (count($datasets) !== count($maxes)) {
throw new Exception('Incorrect number of max calculations for graph plotting.');
}
$labeld = '&chxt=x,y,r' .
'&chxr=0,0,1|1,0,' . $maxes[0] . '|2,0,' . $maxes[1];
}
$url = 'http://chart.apis.google.com/chart?' . $url = 'http://chart.apis.google.com/chart?' .
// Dimension of graph. Default is 800x350 // Dimension of graph. Default is 800x350
...@@ -76,15 +106,16 @@ class sspmod_statistics_Graph_GoogleCharts { ...@@ -76,15 +106,16 @@ class sspmod_statistics_Graph_GoogleCharts {
'&chd=' . $this->encodedata($datasets) . '&chd=' . $this->encodedata($datasets) .
// Fill area... // Fill area...
$this->getFillArea($datasets) . # $this->getFillArea($datasets) .
'&chco=ff5c00,cca600' .
'&chls=1,1,0|1,6,3' .
// chart type is linechart // chart type is linechart
'&cht=lc' . '&cht=lc' .
'&chxt=x,y' . $labeld .
'&chxl=0:|' . $this->encodeaxis($axis) . # . $'|1:||top' . '&chxl=0:|' . $this->encodeaxis($axis) . # . $'|1:||top' .
'&chxp=0,' . join(',', $axispos) . '&chxp=0,' . join(',', $axispos) .
# '&chxp=0,0.3,0.4' . # '&chxp=0,0.3,0.4' .
'&chxr=0,0,1|1,0,' . $max .
# '&chm=R,CCCCCC,0,0.25,0.5' . # '&chm=R,CCCCCC,0,0.25,0.5' .
'&chg=' . (2400/(count($datasets[0])-1)) . ',20,3,3'; // lines '&chg=' . (2400/(count($datasets[0])-1)) . ',20,3,3'; // lines
return $url; return $url;
......
...@@ -18,6 +18,7 @@ $this->includeAtTemplateBase('includes/header.php'); ...@@ -18,6 +18,7 @@ $this->includeAtTemplateBase('includes/header.php');
function getBaseURL($t, $type = 'get', $key = NULL, $value = NULL) { function getBaseURL($t, $type = 'get', $key = NULL, $value = NULL) {
$vars = array( $vars = array(
'rule' => $t->data['selected.rule'], 'rule' => $t->data['selected.rule'],
'rule2' => $t->data['selected.rule2'],
'time' => $t->data['selected.time'], 'time' => $t->data['selected.time'],
'res' => $t->data['selected.timeres'], 'res' => $t->data['selected.timeres'],
); );
...@@ -224,6 +225,22 @@ echo ' ...@@ -224,6 +225,22 @@ echo '
echo '<img src="' . htmlspecialchars($this->data['imgurl']) . '" />'; echo '<img src="' . htmlspecialchars($this->data['imgurl']) . '" />';
echo '<form style="display: inline">';
echo('<p style="text-align: right">Compare with total from this dataset ');
echo getBaseURL($this, 'post', 'rule2');
echo '<select onChange="submit();" name="rule2">';
echo ' <option value="_">None</option>';
foreach ($this->data['available.rules'] AS $key => $rule) {
if ($key === $this->data['selected.rule2']) {
echo '<option selected="selected" value="' . $key . '">' . $rule['name'] . '</option>';
} else {
echo '<option value="' . $key . '">' . $rule['name'] . '</option>';
}
}
echo '</select></form>';
echo '</div>'; # end graph content. echo '</div>'; # end graph content.
......
...@@ -57,14 +57,17 @@ if ($protected) { ...@@ -57,14 +57,17 @@ if ($protected) {
* Check input parameters * Check input parameters
*/ */
$preferRule = NULL; $preferRule = NULL;
$preferRule2 = NULL;
$preferTime = NULL; $preferTime = NULL;
$preferTimeRes = NULL; $preferTimeRes = NULL;
$delimiter = NULL; $delimiter = NULL;
if(array_key_exists('rule', $_GET)) $preferRule = $_GET['rule']; if(array_key_exists('rule', $_REQUEST)) $preferRule = $_REQUEST['rule'];
if(array_key_exists('time', $_GET)) $preferTime = $_GET['time']; if(array_key_exists('rule2', $_REQUEST)) $preferRule2 = $_REQUEST['rule2'];
if(array_key_exists('res', $_GET)) $preferTimeRes = $_GET['res']; if(array_key_exists('time', $_REQUEST)) $preferTime = $_REQUEST['time'];
if(array_key_exists('d', $_GET)) $delimiter = $_GET['d']; if(array_key_exists('res', $_REQUEST)) $preferTimeRes = $_REQUEST['res'];
if(array_key_exists('d', $_REQUEST)) $delimiter = $_REQUEST['d'];
if ($preferRule2 === '_') $preferRule2 = NULL;
/* /*
* Create statistics data. * Create statistics data.
...@@ -96,7 +99,28 @@ $datasets = array(); ...@@ -96,7 +99,28 @@ $datasets = array();
$datasets[] = $dataset->getPercentValues(); $datasets[] = $dataset->getPercentValues();
$axis = $dataset->getAxis(); $axis = $dataset->getAxis();
$max = $dataset->getMax();
$maxes = array();
$maxes[] = $dataset->getMax();
if (isset($preferRule2)) {
$statrule = $ruleset->getRule($preferRule2);
# $rule2 = $statrule->getRuleID();
$dataset2 = $statrule->getDataset($preferTimeRes, $preferTime);
$dataset2->aggregateSummary();
$dataset2->calculateMax();
$datasets[] = $dataset2->getPercentValues();
$maxes[] = $dataset2->getMax();
}
$dimx = $statconfig->getValue('dimension.x', 800); $dimx = $statconfig->getValue('dimension.x', 800);
...@@ -110,7 +134,7 @@ SimpleSAML_Module::callHooks('htmlinject', $hookinfo); ...@@ -110,7 +134,7 @@ SimpleSAML_Module::callHooks('htmlinject', $hookinfo);
$t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics-tpl.php'); $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics-tpl.php');
$t->data['header'] = 'stat'; $t->data['header'] = 'stat';
$t->data['imgurl'] = $grapher->show($axis['axis'], $axis['axispos'], $datasets, $max); $t->data['imgurl'] = $grapher->show($axis['axis'], $axis['axispos'], $datasets, $maxes);
if (isset($piedata)) { if (isset($piedata)) {
$t->data['pieimgurl'] = $grapher->showPie( $dataset->getDelimiterPresentationPie(), $piedata); $t->data['pieimgurl'] = $grapher->showPie( $dataset->getDelimiterPresentationPie(), $piedata);
} }
...@@ -124,6 +148,7 @@ $t->data['htmlContentPost'] = $htmlContentPost; ...@@ -124,6 +148,7 @@ $t->data['htmlContentPost'] = $htmlContentPost;
$t->data['htmlContentHead'] = $htmlContentHead; $t->data['htmlContentHead'] = $htmlContentHead;
$t->data['jquery'] = $jquery; $t->data['jquery'] = $jquery;
$t->data['selected.rule']= $rule; $t->data['selected.rule']= $rule;
$t->data['selected.rule2']= $preferRule2;
$t->data['selected.time'] = $fileslot; $t->data['selected.time'] = $fileslot;
$t->data['selected.timeres'] = $timeres; $t->data['selected.timeres'] = $timeres;
$t->data['selected.delimiter'] = $delimiter; $t->data['selected.delimiter'] = $delimiter;
......
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