Commit f554abdd authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1472889: Allowing override of global chart settings"

parents 8df87b1d eb205d6d
......@@ -1089,7 +1089,7 @@ function fetch_graph_data(opts) {
else {
canvascontext = document.getElementById(opts.id).getContext("2d");
}
chartobject = new Chart(canvascontext)[json.data.graph](JSON.parse(json.data.datastr));
chartobject = new Chart(canvascontext)[json.data.graph](JSON.parse(json.data.datastr),JSON.parse(json.data.configstr));
var legendHolder = document.createElement('div');
legendHolder.innerHTML = chartobject.generateLegend();
......
......@@ -38,14 +38,17 @@ if (!defined('CRON')) {
}
else {
$data = ($extradata) ? $graph($type, $extradata) : $graph($type);
if (empty($data)) {
$data['empty'] = true;
json_reply(false, array('data' => $data));
}
$data['configs'] = isset($extradata->configs) ? $extradata->configs : (object) array();
if (!empty($data['jsondata'])) {
$data['datastr'] = $data['jsondata'];
$jsondata = json_decode($data['jsondata']);
$data['datastr'] = json_encode($jsondata[0]);
$data['configstr'] = json_encode($data['configs']);
json_reply(false, array('data' => $data));
}
......@@ -57,17 +60,18 @@ if (!defined('CRON')) {
case 'Pie':
case 'PolarArea':
case 'Doughnut':
$graphdata = get_circular_graph_json($data, $colours);
list($graphdata, $configs) = get_circular_graph_json($data, $colours);
break;
case 'Bar':
$graphdata = get_bar_graph_json($data, $colours);
list($graphdata, $configs) = get_bar_graph_json($data, $colours);
break;
case 'Line':
$graphdata = get_line_graph_json($data, $colours);
list($graphdata, $configs) = get_line_graph_json($data, $colours);
break;
default:
}
$data['datastr'] = json_encode($graphdata);
$data['configstr'] = json_encode($configs);
json_reply(false, array('data' => $data));
}
}
......@@ -33,6 +33,7 @@ function allowed_graph_functions() {
* Includes: 'data': associative array of label -> data points
* 'colours': custom colours from the function to use instead of the defaults
* 'labellang': the lang file to find the label string translation
* 'configs': associative array of config overrides
* @param array $colours Custom colours from js to use instead of the defaults
* @param bool $cron If function is called from cron we don't want to reply via js
*
......@@ -59,7 +60,8 @@ function get_circular_graph_json($data, $colours = null, $cron = false) {
$graphdata[] = $dataobj;
$x = empty($data['colours'][$x+1]) ? 0 : $x + 1;
}
return $graphdata;
$configs = isset($data['configs']) ? $data['configs'] : (object) array();
return array($graphdata, $configs);
}
/**
......@@ -70,6 +72,7 @@ function get_circular_graph_json($data, $colours = null, $cron = false) {
* 'labels': labels for the bars
* 'colours': custom colours from the function to use instead of the defaults
* 'labellang': the lang file to find the label string translation
* 'configs': associative array of config overrides
* @param array $colours Custom colours from js to use instead of the defaults
* @param bool $cron If function is called from cron we don't want to reply via js
*
......@@ -97,7 +100,8 @@ function get_bar_graph_json($data, $colours = null, $cron = false) {
$graphdata['datasets'][] = $dataobj;
$x = empty($data['colours'][$x+1]) ? 0 : $x + 1;
}
return $graphdata;
$configs = isset($data['configs']) ? $data['configs'] : (object) array();
return array($graphdata, $configs);
}
/**
......@@ -108,6 +112,7 @@ function get_bar_graph_json($data, $colours = null, $cron = false) {
* 'labels': labels for the lines
* 'colours': custom colours from the function to use instead of the defaults
* 'labellang': the lang file to find the label string translation
* 'configs': associative array of config overrides
* @param array $colours Custom colours from js to use instead of the defaults
* @param bool $cron If function is called from cron we don't want to reply via js
*
......@@ -137,7 +142,8 @@ function get_line_graph_json($data, $colours = null, $cron = false) {
$graphdata['datasets'][] = $dataobj;
$x = empty($data['colours'][$x+1]) ? 0 : $x + 1;
}
return $graphdata;
$configs = isset($data['configs']) ? $data['configs'] : (object) array();
return array($graphdata, $configs);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment