Skip to content

Commit

Permalink
Fixed issue #16620: simple statistics looks odd
Browse files Browse the repository at this point in the history
Made the view responsive and have 1, 2 columns or 3 depending on the screen width.
Made the legends to be below the chart, and not on its right side.
  • Loading branch information
gabrieljenik authored and eddylackmann committed Oct 10, 2020
1 parent 7ec9248 commit 108ddbf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
25 changes: 10 additions & 15 deletions application/helpers/admin/statistics_helper.php
Expand Up @@ -2127,6 +2127,7 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
if ($outputType == 'html') {
// show this block only when we show graphs and are not in the public statics controller
if ($usegraph == 1 && $bShowGraph && get_class(Yii::app()->getController()) !== 'Statistics_userController') {
$fullLabels = $labels;
// We clean the labels
$iMaxLabelLength = 0;
foreach ($labels as $key => $label) {
Expand All @@ -2141,6 +2142,7 @@ protected function displaySimpleResults($outputs, $results, $rt, $outputType, $s
$aData['rt'] = $rt;
$aData['qqid'] = $qqid;
$aData['labels'] = $labels;
$aData['fullLabels'] = $fullLabels;
$aData['charttype'] = $charttype;
$aData['sChartname'] = '';
$aData['grawdata'] = $grawdata;
Expand Down Expand Up @@ -3547,7 +3549,7 @@ public function generate_simple_statistics($surveyid, $allfields, $q2show = 'all
$aData['surveyid'] = $surveyid;
$aData['sql'] = $sql;

$sOutputHTML = '';
$sOutputHTML = '<div class="row">';

//let's run through the survey
$runthrough = $summary;
Expand All @@ -3556,29 +3558,26 @@ public function generate_simple_statistics($surveyid, $allfields, $q2show = 'all

//loop through all selected questions
$count = 0;
$rowOpened = 0;
foreach ($runthrough as $rt) {
////Step 1: Get information about this response field (SGQA) for the summary
$outputs = $this->buildOutputList($rt, $language, $surveyid, $outputType, $sql, $sLanguageCode);
//$sOutputHTML .= $outputs['statisticsoutput']; // Nothing interesting for us in this output
//2. Collect and Display results #######################################################################

if (isset($outputs['alist']) && $outputs['alist']) {
//Make sure there really is an answerlist, and if so:
$count = $count + 1;
if ($count == 1) {
$sOutputHTML .= '<div class="row">';
$rowOpened = 1;
}

$display = $this->displaySimpleResults($outputs, $results, $rt, $outputType, $surveyid, $sql, $usegraph, $browse, $sLanguageCode);
$sOutputHTML .= $display['statisticsoutput'];
$aStatisticsData = array_merge($aStatisticsData, $display['astatdata']);

if ($count == 3) {
$sOutputHTML .= '</div>';
$rowOpened = 0;
$count = 0;
// Add row break after every second column for md size
if ($count % 2 == 0) {
$sOutputHTML .= '<div class="clearfix visible-md-block"></div>';
}
// Add row break after every third column for lg size
if ($count % 3 == 0) {
$sOutputHTML .= '<div class="clearfix visible-lg-block"></div>';
}

} //end if -> collect and display results
Expand All @@ -3592,10 +3591,6 @@ public function generate_simple_statistics($surveyid, $allfields, $q2show = 'all

}

if ($rowOpened) {
$sOutputHTML .= '</div>';
}

$sOutputHTML .= '</div>';

$sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey"));
Expand Down
Expand Up @@ -16,8 +16,8 @@
<!-- _statisticsoutput_graphs -->
<?php if(count($labels) < 70): ?>
<!-- Charts -->
<div class="row">
<div class="col-sm-9 vcenter chartjs-container" id="chartjs-container-<?php echo $qqid; ?>"
<div class="row custom custom-padding bottom-20">
<div class="col-sm-12 vcenter chartjs-container" id="chartjs-container-<?php echo $qqid; ?>"
data-chartname="<?php echo $sChartname; // The name of the jschart object ?>"
data-qid="<?php echo $qqid; // the question id ?>"
data-type="<?php echo $charttype; // the chart start type (bar, donut, etc.) ?>"
Expand All @@ -30,11 +30,12 @@
<canvas class="canvas-chart " id="chartjs-<?php echo $qqid; ?>" width="400" height="300<?php // echo $iCanvaHeight;?>"
data-color="<?php echo $color; // the background color for bar, etc. ?>"></canvas>
</div>
</div>

<div class="row">
<!-- legends -->
<?php if($charttype=='Pie' || $charttype=='Doughnut'): ?>
<div class="legend col-sm-2 vcenter">
<?php foreach($labels as $i=>$label): ?>
<div class="legend col-sm-12 vcenter">
<?php foreach($fullLabels as $i=>$label): ?>
<?php $colorindex = $color+$i; ?>
<div class="row" style="margin-bottom: 10px;">
<div class="col-sm-1">
Expand All @@ -47,7 +48,6 @@
</div>
<?php endforeach;?>
</div>
<?php endif; ?>
</div>

<!-- Buttons to change graph type -->
Expand Down
Expand Up @@ -9,6 +9,6 @@
?>

<!-- _statisticsoutput_header -->
<div class="col-sm-4 printable" style="margin-top: 2em;margin-bottom: 2em;">
<div class="col-sm-12 col-md-6 col-lg-4 printable" style="margin-top: 2em;margin-bottom: 2em;">
<h4><?php echo $outputs['qquestion'];?></h4>
<!-- end of _statisticsoutput_header -->

0 comments on commit 108ddbf

Please sign in to comment.