Skip to content

Commit

Permalink
MDL-48794 report_log: make sure y-axis gridlines in graphs are integers
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy committed Jan 12, 2015
1 parent edbcfbd commit 698aa47
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions report/log/graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@
$graph->y_data['logs'] = $logs;
$graph->y_order = array('logs');

// Make sure the Y-axis gridlines correspond to the integer values.
if (count($logs) && ($ymax = max($logs)) && ($graph->parameter['y_axis_gridlines'] > 1)) {
if ($ymax < $graph->parameter['y_axis_gridlines'] - 1) {
$graph->parameter['y_axis_gridlines'] = $ymax + 1;
} else if ($ymax % ($graph->parameter['y_axis_gridlines'] - 1)) {
$graph->parameter['y_max_left'] = $graph->parameter['y_max_right'] =
ceil($ymax/($graph->parameter['y_axis_gridlines'] - 1)) * ($graph->parameter['y_axis_gridlines'] - 1);
}
}

if (!empty($CFG->preferlinegraphs)) {
$graph->y_format['logs'] = array('colour' => 'blue', 'line' => 'line');
} else {
Expand Down Expand Up @@ -206,6 +216,16 @@
$graph->y_data['logs'] = $logs;
$graph->y_order = array('logs');

// Make sure the Y-axis gridlines correspond to the integer values.
if (count($logs) && ($ymax = max($logs)) && ($graph->parameter['y_axis_gridlines'] > 1)) {
if ($ymax < $graph->parameter['y_axis_gridlines'] - 1) {
$graph->parameter['y_axis_gridlines'] = $ymax + 1;
} else if ($ymax % ($graph->parameter['y_axis_gridlines'] - 1)) {
$graph->parameter['y_max_left'] = $graph->parameter['y_max_right'] =
ceil($ymax/($graph->parameter['y_axis_gridlines'] - 1)) * ($graph->parameter['y_axis_gridlines'] - 1);
}
}

if (!empty($CFG->preferlinegraphs)) {
$graph->y_format['logs'] = array('colour' => 'blue', 'line' => 'line');
} else {
Expand Down

0 comments on commit 698aa47

Please sign in to comment.