From 9698ca2d20ac256d9fba86d5e991ca22638c9c1c Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Fri, 29 Jul 2016 12:42:24 +0800 Subject: [PATCH] MDL-55352 core: Label values series should override tooltip --- lib/amd/build/chart_output_chartjs.min.js | 2 +- lib/amd/build/chart_output_htmltable.min.js | 2 +- lib/amd/src/chart_output_chartjs.js | 2 +- lib/amd/src/chart_output_htmltable.js | 2 +- mod/choice/renderer.php | 2 +- mod/feedback/item/multichoice/lib.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/amd/build/chart_output_chartjs.min.js b/lib/amd/build/chart_output_chartjs.min.js index fdc8e84c423..c035888d775 100644 --- a/lib/amd/build/chart_output_chartjs.min.js +++ b/lib/amd/build/chart_output_chartjs.min.js @@ -1 +1 @@ -define(["jquery","core/chartjs","core/chart_axis","core/chart_bar","core/chart_output_base","core/chart_line","core/chart_pie","core/chart_series"],function(a,b,c,d,e,f,g,h){function i(){e.prototype.constructor.apply(this,arguments),this._canvas=this._node,"CANVAS"!=this._canvas.prop("tagName")&&(this._canvas=a(""),this._node.append(this._canvas)),this._build()}var j=function(a,b){return"axis-"+a+"-"+b};return i.prototype=Object.create(e.prototype),i.prototype._config=null,i.prototype._chartjs=null,i.prototype._canvas=null,i.prototype._build=function(){this._config=this._makeConfig(),this._chartjs=new b(this._canvas[0],this._config)},i.prototype._getChartType=function(){var a=this._chart.getType();return this._chart.getType()===d.prototype.TYPE&&this._chart.getHorizontal()===!0&&(a="horizontalBar"),a},i.prototype._makeAxisConfig=function(a,b,d){var e={id:j(b,d)};return a.getPosition()!==c.prototype.POS_DEFAULT&&(e.position=a.getPosition()),null!==a.getLabel()&&(e.scaleLabel={display:!0,labelString:a.getLabel()}),null!==a.getStepSize()&&(e.ticks=e.ticks||{},e.ticks.stepSize=a.getStepSize()),null!==a.getMax()&&(e.ticks=e.ticks||{},e.ticks.max=a.getMax()),null!==a.getMin()&&(e.ticks=e.ticks||{},e.ticks.min=a.getMin()),e},i.prototype._makeConfig=function(){var a={type:this._getChartType(),data:{labels:this._chart.getLabels(),datasets:this._makeDatasetsConfig()},options:{title:{display:null!==this._chart.getTitle(),text:this._chart.getTitle()}}};return this._chart.getXAxes().forEach(function(b,c){var d=b.getLabels();a.options.scales=a.options.scales||{},a.options.scales.xAxes=a.options.scales.xAxes||[],a.options.scales.xAxes[c]=this._makeAxisConfig(b,"x",c),null!==d&&(a.options.scales.xAxes[c].ticks.callback=function(a,b){return d[b]||""})}.bind(this)),this._chart.getYAxes().forEach(function(b,c){var d=b.getLabels();a.options.scales=a.options.scales||{},a.options.scales.yAxes=a.options.scales.yAxes||[],a.options.scales.yAxes[c]=this._makeAxisConfig(b,"y",c),null!==d&&(a.options.scales.yAxes[c].ticks.callback=function(a){return d[parseInt(a,10)]||""})}.bind(this)),a.options.tooltips={callbacks:{label:this._makeTooltip.bind(this)}},a},i.prototype._makeDatasetsConfig=function(){var a=this._chart.getSeries().map(function(a){var b=a.hasColoredValues()?a.getColors():a.getColor(),c={label:a.getLabel(),data:a.getValues(),type:a.getType(),fill:!1,backgroundColor:b,borderColor:this._chart.getType()==g.prototype.TYPE?null:b,lineTension:this._isSmooth(a)?.3:0};return null!==a.getXAxis()&&(c.xAxisID=j("x",a.getXAxis())),null!==a.getYAxis()&&(c.yAxisID=j("y",a.getYAxis())),c}.bind(this));return a},i.prototype._makeTooltip=function(a,b){var c=this._chart.getSeries()[a.datasetIndex],d=c.getLabel(),e=c.getLabels(),f=b.datasets[a.datasetIndex].data,g=f[a.index],h=d+": "+g;return null!==e&&(h+=" "+e[a.index]),h},i.prototype._isSmooth=function(a){var b=!1;return this._chart.getType()===f.prototype.TYPE?(b=a.getSmooth(),null===b&&(b=this._chart.getSmooth())):a.getType()===h.prototype.TYPE_LINE&&(b=a.getSmooth()),b},i.prototype.update=function(){a.extend(!0,this._config,this._makeConfig()),this._chartjs.update()},i}); \ No newline at end of file +define(["jquery","core/chartjs","core/chart_axis","core/chart_bar","core/chart_output_base","core/chart_line","core/chart_pie","core/chart_series"],function(a,b,c,d,e,f,g,h){function i(){e.prototype.constructor.apply(this,arguments),this._canvas=this._node,"CANVAS"!=this._canvas.prop("tagName")&&(this._canvas=a(""),this._node.append(this._canvas)),this._build()}var j=function(a,b){return"axis-"+a+"-"+b};return i.prototype=Object.create(e.prototype),i.prototype._config=null,i.prototype._chartjs=null,i.prototype._canvas=null,i.prototype._build=function(){this._config=this._makeConfig(),this._chartjs=new b(this._canvas[0],this._config)},i.prototype._getChartType=function(){var a=this._chart.getType();return this._chart.getType()===d.prototype.TYPE&&this._chart.getHorizontal()===!0&&(a="horizontalBar"),a},i.prototype._makeAxisConfig=function(a,b,d){var e={id:j(b,d)};return a.getPosition()!==c.prototype.POS_DEFAULT&&(e.position=a.getPosition()),null!==a.getLabel()&&(e.scaleLabel={display:!0,labelString:a.getLabel()}),null!==a.getStepSize()&&(e.ticks=e.ticks||{},e.ticks.stepSize=a.getStepSize()),null!==a.getMax()&&(e.ticks=e.ticks||{},e.ticks.max=a.getMax()),null!==a.getMin()&&(e.ticks=e.ticks||{},e.ticks.min=a.getMin()),e},i.prototype._makeConfig=function(){var a={type:this._getChartType(),data:{labels:this._chart.getLabels(),datasets:this._makeDatasetsConfig()},options:{title:{display:null!==this._chart.getTitle(),text:this._chart.getTitle()}}};return this._chart.getXAxes().forEach(function(b,c){var d=b.getLabels();a.options.scales=a.options.scales||{},a.options.scales.xAxes=a.options.scales.xAxes||[],a.options.scales.xAxes[c]=this._makeAxisConfig(b,"x",c),null!==d&&(a.options.scales.xAxes[c].ticks.callback=function(a,b){return d[b]||""})}.bind(this)),this._chart.getYAxes().forEach(function(b,c){var d=b.getLabels();a.options.scales=a.options.scales||{},a.options.scales.yAxes=a.options.scales.yAxes||[],a.options.scales.yAxes[c]=this._makeAxisConfig(b,"y",c),null!==d&&(a.options.scales.yAxes[c].ticks.callback=function(a){return d[parseInt(a,10)]||""})}.bind(this)),a.options.tooltips={callbacks:{label:this._makeTooltip.bind(this)}},a},i.prototype._makeDatasetsConfig=function(){var a=this._chart.getSeries().map(function(a){var b=a.hasColoredValues()?a.getColors():a.getColor(),c={label:a.getLabel(),data:a.getValues(),type:a.getType(),fill:!1,backgroundColor:b,borderColor:this._chart.getType()==g.prototype.TYPE?null:b,lineTension:this._isSmooth(a)?.3:0};return null!==a.getXAxis()&&(c.xAxisID=j("x",a.getXAxis())),null!==a.getYAxis()&&(c.yAxisID=j("y",a.getYAxis())),c}.bind(this));return a},i.prototype._makeTooltip=function(a,b){var c=this._chart.getSeries()[a.datasetIndex],d=c.getLabel(),e=c.getLabels(),f=b.datasets[a.datasetIndex].data,g=f[a.index],h=d+": "+g;return null!==e&&(h=e[a.index]),h},i.prototype._isSmooth=function(a){var b=!1;return this._chart.getType()===f.prototype.TYPE?(b=a.getSmooth(),null===b&&(b=this._chart.getSmooth())):a.getType()===h.prototype.TYPE_LINE&&(b=a.getSmooth()),b},i.prototype.update=function(){a.extend(!0,this._config,this._makeConfig()),this._chartjs.update()},i}); \ No newline at end of file diff --git a/lib/amd/build/chart_output_htmltable.min.js b/lib/amd/build/chart_output_htmltable.min.js index cea515284e2..a2e9030d295 100644 --- a/lib/amd/build/chart_output_htmltable.min.js +++ b/lib/amd/build/chart_output_htmltable.min.js @@ -1 +1 @@ -define(["jquery","core/chart_output_base"],function(a,b){function c(){b.prototype.constructor.apply(this,arguments),this._build()}return c.prototype=Object.create(b.prototype),c.prototype._build=function(){this._node.empty(),this._node.append(this._makeTable())},c.prototype._makeTable=function(){var b,c,d,e=a(""),f=this._chart,g=f.getLabels(),h=g.length>0,i=f.getSeries(),j=i[0].getCount();e.addClass("chart-output-htmltable"),null!==f.getTitle()&&e.append(a(""),h&&b.append(a("
").text(f.getTitle())),b=a("
")),i.forEach(function(c){b.append(a("").text(c.getLabel()).attr("scope","col"))}),e.append(b);for(var k=0;k"),g.length>0&&b.append(a("").text(g[k]).attr("scope","row"));for(var l=0;l").text(c));e.append(b)}return e},c.prototype.update=function(){this._build()},c}); \ No newline at end of file +define(["jquery","core/chart_output_base"],function(a,b){function c(){b.prototype.constructor.apply(this,arguments),this._build()}return c.prototype=Object.create(b.prototype),c.prototype._build=function(){this._node.empty(),this._node.append(this._makeTable())},c.prototype._makeTable=function(){var b,c,d,e=a(""),f=this._chart,g=f.getLabels(),h=g.length>0,i=f.getSeries(),j=i[0].getCount();e.addClass("chart-output-htmltable"),null!==f.getTitle()&&e.append(a(""),h&&b.append(a("
").text(f.getTitle())),b=a("
")),i.forEach(function(c){b.append(a("").text(c.getLabel()).attr("scope","col"))}),e.append(b);for(var k=0;k"),g.length>0&&b.append(a("").text(g[k]).attr("scope","row"));for(var l=0;l").text(c));e.append(b)}return e},c.prototype.update=function(){this._build()},c}); \ No newline at end of file diff --git a/lib/amd/src/chart_output_chartjs.js b/lib/amd/src/chart_output_chartjs.js index b0075f25969..d73847900e6 100644 --- a/lib/amd/src/chart_output_chartjs.js +++ b/lib/amd/src/chart_output_chartjs.js @@ -274,7 +274,7 @@ define([ // Add serie labels to the tooltip if any. if (serieLabels !== null) { - tooltip += ' ' + serieLabels[tooltipItem.index]; + tooltip = serieLabels[tooltipItem.index]; } return tooltip; diff --git a/lib/amd/src/chart_output_htmltable.js b/lib/amd/src/chart_output_htmltable.js index ab55bbd6468..2ab02a15da5 100644 --- a/lib/amd/src/chart_output_htmltable.js +++ b/lib/amd/src/chart_output_htmltable.js @@ -102,7 +102,7 @@ define([ value = series[serieId].getValues()[rowId]; seriesLabels = series[serieId].getLabels(); if (seriesLabels !== null) { - value += ' ' + series[serieId].getLabels()[rowId]; + value = series[serieId].getLabels()[rowId]; } node.append($('').text(value)); } diff --git a/mod/choice/renderer.php b/mod/choice/renderer.php index 7bd4a9cc73d..f40f331e0d5 100644 --- a/mod/choice/renderer.php +++ b/mod/choice/renderer.php @@ -327,7 +327,7 @@ class mod_choice_renderer extends plugin_renderer_base { } $data['labels'][$count] = $option->text; $data['series'][$count] = $numberofuser; - $data['series_labels'][$count] = '(' . format_float($percentageamount, 1) . '%)'; + $data['series_labels'][$count] = $numberofuser . ' (' . format_float($percentageamount, 1) . '%)'; $count++; $numberofuser = 0; } diff --git a/mod/feedback/item/multichoice/lib.php b/mod/feedback/item/multichoice/lib.php index 63c515b895c..98b9a35478e 100644 --- a/mod/feedback/item/multichoice/lib.php +++ b/mod/feedback/item/multichoice/lib.php @@ -223,14 +223,14 @@ class feedback_item_multichoice extends feedback_item_base { $quotient = format_float($val->quotient * 100, 2); $strquotient = ''; if ($val->quotient > 0) { - $strquotient = '('. $quotient . ' %)'; + $strquotient = ' ('. $quotient . ' %)'; } $answertext = format_text(trim($val->answertext), FORMAT_HTML, array('noclean' => true, 'para' => false)); $data['labels'][$count] = $answertext; $data['series'][$count] = $val->answercount; - $data['series_labels'][$count] = $strquotient; + $data['series_labels'][$count] = $val->answercount . $strquotient; $count++; } $chart = new \core\chart_bar();