diff --git a/modules/statistics/lib/Graph/GoogleCharts.php b/modules/statistics/lib/Graph/GoogleCharts.php index 3525e626cd09d66101e6d9b428d92e852b6abcee..73143687eb247ed3732535bf52ebdf97025c1a7c 100644 --- a/modules/statistics/lib/Graph/GoogleCharts.php +++ b/modules/statistics/lib/Graph/GoogleCharts.php @@ -31,12 +31,32 @@ class sspmod_statistics_Graph_GoogleCharts { private function encodedata($datasets) { $setstr = array(); 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... @@ -65,8 +85,18 @@ class sspmod_statistics_Graph_GoogleCharts { * @param $datasets Datasets values * @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?' . // Dimension of graph. Default is 800x350 @@ -76,15 +106,16 @@ class sspmod_statistics_Graph_GoogleCharts { '&chd=' . $this->encodedata($datasets) . // Fill area... - $this->getFillArea($datasets) . +# $this->getFillArea($datasets) . + '&chco=ff5c00,cca600' . + '&chls=1,1,0|1,6,3' . // chart type is linechart '&cht=lc' . - '&chxt=x,y' . + $labeld . '&chxl=0:|' . $this->encodeaxis($axis) . # . $'|1:||top' . '&chxp=0,' . join(',', $axispos) . # '&chxp=0,0.3,0.4' . - '&chxr=0,0,1|1,0,' . $max . # '&chm=R,CCCCCC,0,0.25,0.5' . '&chg=' . (2400/(count($datasets[0])-1)) . ',20,3,3'; // lines return $url; diff --git a/modules/statistics/templates/statistics-tpl.php b/modules/statistics/templates/statistics-tpl.php index e6d342eb14262dc599a6c4ba6fc0e0d34d2fd157..58ad34733fb84f5b39cda9765d68f5c42043a7b8 100644 --- a/modules/statistics/templates/statistics-tpl.php +++ b/modules/statistics/templates/statistics-tpl.php @@ -18,6 +18,7 @@ $this->includeAtTemplateBase('includes/header.php'); function getBaseURL($t, $type = 'get', $key = NULL, $value = NULL) { $vars = array( 'rule' => $t->data['selected.rule'], + 'rule2' => $t->data['selected.rule2'], 'time' => $t->data['selected.time'], 'res' => $t->data['selected.timeres'], ); @@ -224,6 +225,22 @@ echo ' 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. diff --git a/modules/statistics/www/showstats.php b/modules/statistics/www/showstats.php index a46882b04f72813480c5c98d24c273254238901c..d9356349119dfd086b340227dbea5257e59ae309 100644 --- a/modules/statistics/www/showstats.php +++ b/modules/statistics/www/showstats.php @@ -57,14 +57,17 @@ if ($protected) { * Check input parameters */ $preferRule = NULL; +$preferRule2 = NULL; $preferTime = NULL; $preferTimeRes = NULL; $delimiter = NULL; -if(array_key_exists('rule', $_GET)) $preferRule = $_GET['rule']; -if(array_key_exists('time', $_GET)) $preferTime = $_GET['time']; -if(array_key_exists('res', $_GET)) $preferTimeRes = $_GET['res']; -if(array_key_exists('d', $_GET)) $delimiter = $_GET['d']; +if(array_key_exists('rule', $_REQUEST)) $preferRule = $_REQUEST['rule']; +if(array_key_exists('rule2', $_REQUEST)) $preferRule2 = $_REQUEST['rule2']; +if(array_key_exists('time', $_REQUEST)) $preferTime = $_REQUEST['time']; +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. @@ -96,7 +99,28 @@ $datasets = array(); $datasets[] = $dataset->getPercentValues(); $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); @@ -110,7 +134,7 @@ SimpleSAML_Module::callHooks('htmlinject', $hookinfo); $t = new SimpleSAML_XHTML_Template($config, 'statistics:statistics-tpl.php'); $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)) { $t->data['pieimgurl'] = $grapher->showPie( $dataset->getDelimiterPresentationPie(), $piedata); } @@ -124,6 +148,7 @@ $t->data['htmlContentPost'] = $htmlContentPost; $t->data['htmlContentHead'] = $htmlContentHead; $t->data['jquery'] = $jquery; $t->data['selected.rule']= $rule; +$t->data['selected.rule2']= $preferRule2; $t->data['selected.time'] = $fileslot; $t->data['selected.timeres'] = $timeres; $t->data['selected.delimiter'] = $delimiter;