From ab0d4099915fc96980144635a6365ca6cd414238 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Thu, 9 Apr 2020 13:14:31 +1200 Subject: [PATCH] MDL-68386 libraries: Enhancement for Area Charts support with chart.js. --- lib/amd/build/chart_output_chartjs.min.js | 2 +- lib/amd/build/chart_output_chartjs.min.js.map | 2 +- lib/amd/build/chart_series.min.js | 2 +- lib/amd/build/chart_series.min.js.map | 2 +- lib/amd/src/chart_output_chartjs.js | 2 +- lib/amd/src/chart_series.js | 27 +++++++++++++++++++ lib/classes/chart_series.php | 18 +++++++++++++ lib/tests/other/chartjstestpage.php | 15 +++++++++++ 8 files changed, 65 insertions(+), 5 deletions(-) diff --git a/lib/amd/build/chart_output_chartjs.min.js b/lib/amd/build/chart_output_chartjs.min.js index 491017c1ce9..b6f1a7196fe 100644 --- a/lib/amd/build/chart_output_chartjs.min.js +++ b/lib/amd/build/chart_output_chartjs.min.js @@ -1,2 +1,2 @@ -define ("core/chart_output_chartjs",["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){var j=function(a,b){return"axis-"+a+"-"+b};function i(){e.prototype.constructor.apply(this,arguments);this._canvas=this._node;if("CANVAS"!=this._canvas.prop("tagName")){this._canvas=a("");this._node.append(this._canvas)}this._build()}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._cleanData=function(b){if(b instanceof Array){return b.map(function(b){return a("").html(b).text()})}else{return a("").html(b).text()}};i.prototype._getChartType=function(){var a=this._chart.getType();if(this._chart.getType()===d.prototype.TYPE&&!0===this._chart.getHorizontal()){a="horizontalBar"}else if(this._chart.getType()===g.prototype.TYPE&&!0===this._chart.getDoughnut()){a="doughnut"}return a};i.prototype._makeAxisConfig=function(a,b,d){var e={id:j(b,d)};if(a.getPosition()!==c.prototype.POS_DEFAULT){e.position=a.getPosition()}if(null!==a.getLabel()){e.scaleLabel={display:!0,labelString:this._cleanData(a.getLabel())}}if(null!==a.getStepSize()){e.ticks=e.ticks||{};e.ticks.stepSize=a.getStepSize()}if(null!==a.getMax()){e.ticks=e.ticks||{};e.ticks.max=a.getMax()}if(null!==a.getMin()){e.ticks=e.ticks||{};e.ticks.min=a.getMin()}return e};i.prototype._makeConfig=function(){var a={type:this._getChartType(),data:{labels:this._cleanData(this._chart.getLabels()),datasets:this._makeDatasetsConfig()},options:{title:{display:null!==this._chart.getTitle(),text:this._cleanData(this._chart.getTitle())}}};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);if(null!==d){a.options.scales.xAxes[c].ticks.callback=function(a,b){return d[b]||""}}a.options.scales.xAxes[c].stacked=this._isStacked()}.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);if(null!==d){a.options.scales.yAxes[c].ticks.callback=function(a){return d[parseInt(a,10)]||""}}a.options.scales.yAxes[c].stacked=this._isStacked()}.bind(this));a.options.tooltips={callbacks:{label:this._makeTooltip.bind(this)}};return a};i.prototype._makeDatasetsConfig=function(){var a=this._chart.getSeries().map(function(a){var b=a.hasColoredValues()?a.getColors():a.getColor(),c={label:this._cleanData(a.getLabel()),data:a.getValues(),type:a.getType(),fill:!1,backgroundColor:b,borderColor:this._chart.getType()==g.prototype.TYPE?"#fff":b,lineTension:this._isSmooth(a)?.3:0};if(null!==a.getXAxis()){c.xAxisID=j("x",a.getXAxis())}if(null!==a.getYAxis()){c.yAxisID=j("y",a.getYAxis())}return 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=[];if(""==a.xLabel&&""==a.yLabel){var i=this._cleanData(this._chart.getLabels());h.push(i[a.index])}if(null!==e){h.push(this._cleanData(e[a.index]))}else{h.push(this._cleanData(d)+": "+g)}return h};i.prototype._isSmooth=function(a){var b=!1;if(this._chart.getType()===f.prototype.TYPE){b=a.getSmooth();if(null===b){b=this._chart.getSmooth()}}else if(a.getType()===h.prototype.TYPE_LINE){b=a.getSmooth()}return b};i.prototype._isStacked=function(){var a=!1;if(this._chart.getType()===d.prototype.TYPE){a=this._chart.getStacked()}return a};i.prototype.update=function(){a.extend(!0,this._config,this._makeConfig());this._chartjs.update()};return i}); +define ("core/chart_output_chartjs",["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){var j=function(a,b){return"axis-"+a+"-"+b};function i(){e.prototype.constructor.apply(this,arguments);this._canvas=this._node;if("CANVAS"!=this._canvas.prop("tagName")){this._canvas=a("");this._node.append(this._canvas)}this._build()}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._cleanData=function(b){if(b instanceof Array){return b.map(function(b){return a("").html(b).text()})}else{return a("").html(b).text()}};i.prototype._getChartType=function(){var a=this._chart.getType();if(this._chart.getType()===d.prototype.TYPE&&!0===this._chart.getHorizontal()){a="horizontalBar"}else if(this._chart.getType()===g.prototype.TYPE&&!0===this._chart.getDoughnut()){a="doughnut"}return a};i.prototype._makeAxisConfig=function(a,b,d){var e={id:j(b,d)};if(a.getPosition()!==c.prototype.POS_DEFAULT){e.position=a.getPosition()}if(null!==a.getLabel()){e.scaleLabel={display:!0,labelString:this._cleanData(a.getLabel())}}if(null!==a.getStepSize()){e.ticks=e.ticks||{};e.ticks.stepSize=a.getStepSize()}if(null!==a.getMax()){e.ticks=e.ticks||{};e.ticks.max=a.getMax()}if(null!==a.getMin()){e.ticks=e.ticks||{};e.ticks.min=a.getMin()}return e};i.prototype._makeConfig=function(){var a={type:this._getChartType(),data:{labels:this._cleanData(this._chart.getLabels()),datasets:this._makeDatasetsConfig()},options:{title:{display:null!==this._chart.getTitle(),text:this._cleanData(this._chart.getTitle())}}};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);if(null!==d){a.options.scales.xAxes[c].ticks.callback=function(a,b){return d[b]||""}}a.options.scales.xAxes[c].stacked=this._isStacked()}.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);if(null!==d){a.options.scales.yAxes[c].ticks.callback=function(a){return d[parseInt(a,10)]||""}}a.options.scales.yAxes[c].stacked=this._isStacked()}.bind(this));a.options.tooltips={callbacks:{label:this._makeTooltip.bind(this)}};return a};i.prototype._makeDatasetsConfig=function(){var a=this._chart.getSeries().map(function(a){var b=a.hasColoredValues()?a.getColors():a.getColor(),c={label:this._cleanData(a.getLabel()),data:a.getValues(),type:a.getType(),fill:a.getFill(),backgroundColor:b,borderColor:this._chart.getType()==g.prototype.TYPE?"#fff":b,lineTension:this._isSmooth(a)?.3:0};if(null!==a.getXAxis()){c.xAxisID=j("x",a.getXAxis())}if(null!==a.getYAxis()){c.yAxisID=j("y",a.getYAxis())}return 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=[];if(""==a.xLabel&&""==a.yLabel){var i=this._cleanData(this._chart.getLabels());h.push(i[a.index])}if(null!==e){h.push(this._cleanData(e[a.index]))}else{h.push(this._cleanData(d)+": "+g)}return h};i.prototype._isSmooth=function(a){var b=!1;if(this._chart.getType()===f.prototype.TYPE){b=a.getSmooth();if(null===b){b=this._chart.getSmooth()}}else if(a.getType()===h.prototype.TYPE_LINE){b=a.getSmooth()}return b};i.prototype._isStacked=function(){var a=!1;if(this._chart.getType()===d.prototype.TYPE){a=this._chart.getStacked()}return a};i.prototype.update=function(){a.extend(!0,this._config,this._makeConfig());this._chartjs.update()};return i}); //# sourceMappingURL=chart_output_chartjs.min.js.map diff --git a/lib/amd/build/chart_output_chartjs.min.js.map b/lib/amd/build/chart_output_chartjs.min.js.map index 39844cb4d1f..1dfb6f5cde7 100644 --- a/lib/amd/build/chart_output_chartjs.min.js.map +++ b/lib/amd/build/chart_output_chartjs.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/chart_output_chartjs.js"],"names":["define","$","Chartjs","Axis","Bar","Base","Line","Pie","Series","makeAxisId","xy","index","Output","prototype","constructor","apply","arguments","_canvas","_node","prop","append","_build","Object","create","_config","_chartjs","_makeConfig","_cleanData","data","Array","map","value","html","text","_getChartType","type","_chart","getType","TYPE","getHorizontal","getDoughnut","_makeAxisConfig","axis","scaleData","id","getPosition","POS_DEFAULT","position","getLabel","scaleLabel","display","labelString","getStepSize","ticks","stepSize","getMax","max","getMin","min","config","labels","getLabels","datasets","_makeDatasetsConfig","options","title","getTitle","getXAxes","forEach","i","axisLabels","scales","xAxes","callback","stacked","_isStacked","bind","getYAxes","yAxes","parseInt","tooltips","callbacks","label","_makeTooltip","sets","getSeries","series","colors","hasColoredValues","getColors","getColor","dataset","getValues","fill","backgroundColor","borderColor","lineTension","_isSmooth","getXAxis","xAxisID","getYAxis","yAxisID","tooltipItem","datasetIndex","serieLabel","serieLabels","chartData","tooltipData","tooltip","xLabel","yLabel","chartLabels","push","smooth","getSmooth","TYPE_LINE","getStacked","update","extend"],"mappings":"AAuBAA,OAAM,6BAAC,CACH,QADG,CAEH,cAFG,CAGH,iBAHG,CAI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CAAYgF,UAAZ,EACb,CAED,MAAO1C,CAAAA,CACV,CATD,CAYA9D,CAAM,CAACC,SAAP,CAAiBwG,MAAjB,CAA0B,UAAW,CACjCpH,CAAC,CAACqH,MAAF,IAAe,KAAK9F,OAApB,CAA6B,KAAKE,WAAL,EAA7B,EACA,KAAKD,QAAL,CAAc4F,MAAd,EACH,CAHD,CAKA,MAAOzG,CAAAA,CAEV,CAhVK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Chart output for chart.js.\n *\n * @package core\n * @copyright 2016 Frédéric Massart - FMCorz.net\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @module core/chart_output_chartjs\n */\ndefine([\n 'jquery',\n 'core/chartjs',\n 'core/chart_axis',\n 'core/chart_bar',\n 'core/chart_output_base',\n 'core/chart_line',\n 'core/chart_pie',\n 'core/chart_series'\n], function($, Chartjs, Axis, Bar, Base, Line, Pie, Series) {\n\n /**\n * Makes an axis ID.\n *\n * @param {String} xy Accepts 'x' and 'y'.\n * @param {Number} index The axis index.\n * @return {String}\n */\n var makeAxisId = function(xy, index) {\n return 'axis-' + xy + '-' + index;\n };\n\n /**\n * Chart output for Chart.js.\n *\n * @class\n * @alias module:core/chart_output_chartjs\n * @extends {module:core/chart_output_base}\n */\n function Output() {\n Base.prototype.constructor.apply(this, arguments);\n\n // Make sure that we've got a canvas tag.\n this._canvas = this._node;\n if (this._canvas.prop('tagName') != 'CANVAS') {\n this._canvas = $('');\n this._node.append(this._canvas);\n }\n\n this._build();\n }\n Output.prototype = Object.create(Base.prototype);\n\n /**\n * Reference to the chart config object.\n *\n * @type {Object}\n * @protected\n */\n Output.prototype._config = null;\n\n /**\n * Reference to the instance of chart.js.\n *\n * @type {Object}\n * @protected\n */\n Output.prototype._chartjs = null;\n\n /**\n * Reference to the canvas node.\n *\n * @type {Jquery}\n * @protected\n */\n Output.prototype._canvas = null;\n\n /**\n * Builds the config and the chart.\n *\n * @protected\n */\n Output.prototype._build = function() {\n this._config = this._makeConfig();\n this._chartjs = new Chartjs(this._canvas[0], this._config);\n };\n\n /**\n * Clean data.\n *\n * @param {(String|String[])} data A single string or an array of strings.\n * @returns {(String|String[])}\n * @protected\n */\n Output.prototype._cleanData = function(data) {\n if (data instanceof Array) {\n return data.map(function(value) {\n return $('').html(value).text();\n });\n } else {\n return $('').html(data).text();\n }\n };\n\n /**\n * Get the chart type and handles the Chart.js specific chart types.\n *\n * By default returns the current chart TYPE value. Also does the handling of specific chart types, for example\n * check if the bar chart should be horizontal and the pie chart should be displayed as a doughnut.\n *\n * @method getChartType\n * @returns {String} the chart type.\n * @protected\n */\n Output.prototype._getChartType = function() {\n var type = this._chart.getType();\n\n // Bars can be displayed vertically and horizontally, defining horizontalBar type.\n if (this._chart.getType() === Bar.prototype.TYPE && this._chart.getHorizontal() === true) {\n type = 'horizontalBar';\n } else if (this._chart.getType() === Pie.prototype.TYPE && this._chart.getDoughnut() === true) {\n // Pie chart can be displayed as doughnut.\n type = 'doughnut';\n }\n\n return type;\n };\n\n /**\n * Make the axis config.\n *\n * @protected\n * @param {module:core/chart_axis} axis The axis.\n * @param {String} xy Accepts 'x' or 'y'.\n * @param {Number} index The axis index.\n * @return {Object} The axis config.\n */\n Output.prototype._makeAxisConfig = function(axis, xy, index) {\n var scaleData = {\n id: makeAxisId(xy, index)\n };\n\n if (axis.getPosition() !== Axis.prototype.POS_DEFAULT) {\n scaleData.position = axis.getPosition();\n }\n\n if (axis.getLabel() !== null) {\n scaleData.scaleLabel = {\n display: true,\n labelString: this._cleanData(axis.getLabel())\n };\n }\n\n if (axis.getStepSize() !== null) {\n scaleData.ticks = scaleData.ticks || {};\n scaleData.ticks.stepSize = axis.getStepSize();\n }\n\n if (axis.getMax() !== null) {\n scaleData.ticks = scaleData.ticks || {};\n scaleData.ticks.max = axis.getMax();\n }\n\n if (axis.getMin() !== null) {\n scaleData.ticks = scaleData.ticks || {};\n scaleData.ticks.min = axis.getMin();\n }\n\n return scaleData;\n };\n\n /**\n * Make the config config.\n *\n * @protected\n * @param {module:core/chart_axis} axis The axis.\n * @return {Object} The axis config.\n */\n Output.prototype._makeConfig = function() {\n var config = {\n type: this._getChartType(),\n data: {\n labels: this._cleanData(this._chart.getLabels()),\n datasets: this._makeDatasetsConfig()\n },\n options: {\n title: {\n display: this._chart.getTitle() !== null,\n text: this._cleanData(this._chart.getTitle())\n }\n }\n };\n\n this._chart.getXAxes().forEach(function(axis, i) {\n var axisLabels = axis.getLabels();\n\n config.options.scales = config.options.scales || {};\n config.options.scales.xAxes = config.options.scales.xAxes || [];\n config.options.scales.xAxes[i] = this._makeAxisConfig(axis, 'x', i);\n\n if (axisLabels !== null) {\n config.options.scales.xAxes[i].ticks.callback = function(value, index) {\n return axisLabels[index] || '';\n };\n }\n config.options.scales.xAxes[i].stacked = this._isStacked();\n }.bind(this));\n\n this._chart.getYAxes().forEach(function(axis, i) {\n var axisLabels = axis.getLabels();\n\n config.options.scales = config.options.scales || {};\n config.options.scales.yAxes = config.options.scales.yAxes || [];\n config.options.scales.yAxes[i] = this._makeAxisConfig(axis, 'y', i);\n\n if (axisLabels !== null) {\n config.options.scales.yAxes[i].ticks.callback = function(value) {\n return axisLabels[parseInt(value, 10)] || '';\n };\n }\n config.options.scales.yAxes[i].stacked = this._isStacked();\n }.bind(this));\n\n config.options.tooltips = {\n callbacks: {\n label: this._makeTooltip.bind(this)\n }\n };\n\n return config;\n };\n\n /**\n * Get the datasets configurations.\n *\n * @protected\n * @return {Object[]}\n */\n Output.prototype._makeDatasetsConfig = function() {\n var sets = this._chart.getSeries().map(function(series) {\n var colors = series.hasColoredValues() ? series.getColors() : series.getColor();\n var dataset = {\n label: this._cleanData(series.getLabel()),\n data: series.getValues(),\n type: series.getType(),\n fill: false,\n backgroundColor: colors,\n // Pie charts look better without borders.\n borderColor: this._chart.getType() == Pie.prototype.TYPE ? '#fff' : colors,\n lineTension: this._isSmooth(series) ? 0.3 : 0\n };\n\n if (series.getXAxis() !== null) {\n dataset.xAxisID = makeAxisId('x', series.getXAxis());\n }\n if (series.getYAxis() !== null) {\n dataset.yAxisID = makeAxisId('y', series.getYAxis());\n }\n\n return dataset;\n }.bind(this));\n return sets;\n };\n\n /**\n * Get the chart data, add labels and rebuild the tooltip.\n *\n * @param {Object[]} tooltipItem The tooltip item data.\n * @param {Object[]} data The chart data.\n * @returns {String}\n * @protected\n */\n Output.prototype._makeTooltip = function(tooltipItem, data) {\n\n // Get series and chart data to rebuild the tooltip and add labels.\n var series = this._chart.getSeries()[tooltipItem.datasetIndex];\n var serieLabel = series.getLabel();\n var serieLabels = series.getLabels();\n var chartData = data.datasets[tooltipItem.datasetIndex].data;\n var tooltipData = chartData[tooltipItem.index];\n\n // Build default tooltip.\n var tooltip = [];\n\n // Pie and doughnut charts does not have axis.\n if (tooltipItem.xLabel == '' && tooltipItem.yLabel == '') {\n var chartLabels = this._cleanData(this._chart.getLabels());\n tooltip.push(chartLabels[tooltipItem.index]);\n }\n\n // Add series labels to the tooltip if any.\n if (serieLabels !== null) {\n tooltip.push(this._cleanData(serieLabels[tooltipItem.index]));\n } else {\n tooltip.push(this._cleanData(serieLabel) + ': ' + tooltipData);\n }\n\n return tooltip;\n };\n\n /**\n * Verify if the chart line is smooth or not.\n *\n * @protected\n * @param {module:core/chart_series} series The series.\n * @returns {Bool}\n */\n Output.prototype._isSmooth = function(series) {\n var smooth = false;\n if (this._chart.getType() === Line.prototype.TYPE) {\n smooth = series.getSmooth();\n if (smooth === null) {\n smooth = this._chart.getSmooth();\n }\n } else if (series.getType() === Series.prototype.TYPE_LINE) {\n smooth = series.getSmooth();\n }\n\n return smooth;\n };\n\n /**\n * Verify if the bar chart is stacked or not.\n *\n * @protected\n * @returns {Bool}\n */\n Output.prototype._isStacked = function() {\n var stacked = false;\n\n // Stacking is (currently) only supported for bar charts.\n if (this._chart.getType() === Bar.prototype.TYPE) {\n stacked = this._chart.getStacked();\n }\n\n return stacked;\n };\n\n /** @override */\n Output.prototype.update = function() {\n $.extend(true, this._config, this._makeConfig());\n this._chartjs.update();\n };\n\n return Output;\n\n});\n"],"file":"chart_output_chartjs.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/chart_output_chartjs.js"],"names":["define","$","Chartjs","Axis","Bar","Base","Line","Pie","Series","makeAxisId","xy","index","Output","prototype","constructor","apply","arguments","_canvas","_node","prop","append","_build","Object","create","_config","_chartjs","_makeConfig","_cleanData","data","Array","map","value","html","text","_getChartType","type","_chart","getType","TYPE","getHorizontal","getDoughnut","_makeAxisConfig","axis","scaleData","id","getPosition","POS_DEFAULT","position","getLabel","scaleLabel","display","labelString","getStepSize","ticks","stepSize","getMax","max","getMin","min","config","labels","getLabels","datasets","_makeDatasetsConfig","options","title","getTitle","getXAxes","forEach","i","axisLabels","scales","xAxes","callback","stacked","_isStacked","bind","getYAxes","yAxes","parseInt","tooltips","callbacks","label","_makeTooltip","sets","getSeries","series","colors","hasColoredValues","getColors","getColor","dataset","getValues","fill","getFill","backgroundColor","borderColor","lineTension","_isSmooth","getXAxis","xAxisID","getYAxis","yAxisID","tooltipItem","datasetIndex","serieLabel","serieLabels","chartData","tooltipData","tooltip","xLabel","yLabel","chartLabels","push","smooth","getSmooth","TYPE_LINE","getStacked","update","extend"],"mappings":"AAuBAA,OAAM,6BAAC,CACH,QADG,CAEH,cAFG,CAGH,iBAHG,CAIH,gBAJG,CAKH,wBALG,CAMH,iBANG,CAOH,gBAPG,CAQH,mBARG,CAAD,CASH,SAASC,CAAT,CAAYC,CAAZ,CAAqBC,CAArB,CAA2BC,CAA3B,CA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W,CACjCrH,CAAC,CAACsH,MAAF,IAAe,KAAK/F,OAApB,CAA6B,KAAKE,WAAL,EAA7B,EACA,KAAKD,QAAL,CAAc6F,MAAd,EACH,CAHD,CAKA,MAAO1G,CAAAA,CAEV,CAhVK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Chart output for chart.js.\n *\n * @package core\n * @copyright 2016 Frédéric Massart - FMCorz.net\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @module core/chart_output_chartjs\n */\ndefine([\n 'jquery',\n 'core/chartjs',\n 'core/chart_axis',\n 'core/chart_bar',\n 'core/chart_output_base',\n 'core/chart_line',\n 'core/chart_pie',\n 'core/chart_series'\n], function($, Chartjs, Axis, Bar, Base, Line, Pie, Series) {\n\n /**\n * Makes an axis ID.\n *\n * @param {String} xy Accepts 'x' and 'y'.\n * @param {Number} index The axis index.\n * @return {String}\n */\n var makeAxisId = function(xy, index) {\n return 'axis-' + xy + '-' + index;\n };\n\n /**\n * Chart output for Chart.js.\n *\n * @class\n * @alias module:core/chart_output_chartjs\n * @extends {module:core/chart_output_base}\n */\n function Output() {\n Base.prototype.constructor.apply(this, arguments);\n\n // Make sure that we've got a canvas tag.\n this._canvas = this._node;\n if (this._canvas.prop('tagName') != 'CANVAS') {\n this._canvas = $('');\n this._node.append(this._canvas);\n }\n\n this._build();\n }\n Output.prototype = Object.create(Base.prototype);\n\n /**\n * Reference to the chart config object.\n *\n * @type {Object}\n * @protected\n */\n Output.prototype._config = null;\n\n /**\n * Reference to the instance of chart.js.\n *\n * @type {Object}\n * @protected\n */\n Output.prototype._chartjs = null;\n\n /**\n * Reference to the canvas node.\n *\n * @type {Jquery}\n * @protected\n */\n Output.prototype._canvas = null;\n\n /**\n * Builds the config and the chart.\n *\n * @protected\n */\n Output.prototype._build = function() {\n this._config = this._makeConfig();\n this._chartjs = new Chartjs(this._canvas[0], this._config);\n };\n\n /**\n * Clean data.\n *\n * @param {(String|String[])} data A single string or an array of strings.\n * @returns {(String|String[])}\n * @protected\n */\n Output.prototype._cleanData = function(data) {\n if (data instanceof Array) {\n return data.map(function(value) {\n return $('').html(value).text();\n });\n } else {\n return $('').html(data).text();\n }\n };\n\n /**\n * Get the chart type and handles the Chart.js specific chart types.\n *\n * By default returns the current chart TYPE value. Also does the handling of specific chart types, for example\n * check if the bar chart should be horizontal and the pie chart should be displayed as a doughnut.\n *\n * @method getChartType\n * @returns {String} the chart type.\n * @protected\n */\n Output.prototype._getChartType = function() {\n var type = this._chart.getType();\n\n // Bars can be displayed vertically and horizontally, defining horizontalBar type.\n if (this._chart.getType() === Bar.prototype.TYPE && this._chart.getHorizontal() === true) {\n type = 'horizontalBar';\n } else if (this._chart.getType() === Pie.prototype.TYPE && this._chart.getDoughnut() === true) {\n // Pie chart can be displayed as doughnut.\n type = 'doughnut';\n }\n\n return type;\n };\n\n /**\n * Make the axis config.\n *\n * @protected\n * @param {module:core/chart_axis} axis The axis.\n * @param {String} xy Accepts 'x' or 'y'.\n * @param {Number} index The axis index.\n * @return {Object} The axis config.\n */\n Output.prototype._makeAxisConfig = function(axis, xy, index) {\n var scaleData = {\n id: makeAxisId(xy, index)\n };\n\n if (axis.getPosition() !== Axis.prototype.POS_DEFAULT) {\n scaleData.position = axis.getPosition();\n }\n\n if (axis.getLabel() !== null) {\n scaleData.scaleLabel = {\n display: true,\n labelString: this._cleanData(axis.getLabel())\n };\n }\n\n if (axis.getStepSize() !== null) {\n scaleData.ticks = scaleData.ticks || {};\n scaleData.ticks.stepSize = axis.getStepSize();\n }\n\n if (axis.getMax() !== null) {\n scaleData.ticks = scaleData.ticks || {};\n scaleData.ticks.max = axis.getMax();\n }\n\n if (axis.getMin() !== null) {\n scaleData.ticks = scaleData.ticks || {};\n scaleData.ticks.min = axis.getMin();\n }\n\n return scaleData;\n };\n\n /**\n * Make the config config.\n *\n * @protected\n * @param {module:core/chart_axis} axis The axis.\n * @return {Object} The axis config.\n */\n Output.prototype._makeConfig = function() {\n var config = {\n type: this._getChartType(),\n data: {\n labels: this._cleanData(this._chart.getLabels()),\n datasets: this._makeDatasetsConfig()\n },\n options: {\n title: {\n display: this._chart.getTitle() !== null,\n text: this._cleanData(this._chart.getTitle())\n }\n }\n };\n\n this._chart.getXAxes().forEach(function(axis, i) {\n var axisLabels = axis.getLabels();\n\n config.options.scales = config.options.scales || {};\n config.options.scales.xAxes = config.options.scales.xAxes || [];\n config.options.scales.xAxes[i] = this._makeAxisConfig(axis, 'x', i);\n\n if (axisLabels !== null) {\n config.options.scales.xAxes[i].ticks.callback = function(value, index) {\n return axisLabels[index] || '';\n };\n }\n config.options.scales.xAxes[i].stacked = this._isStacked();\n }.bind(this));\n\n this._chart.getYAxes().forEach(function(axis, i) {\n var axisLabels = axis.getLabels();\n\n config.options.scales = config.options.scales || {};\n config.options.scales.yAxes = config.options.scales.yAxes || [];\n config.options.scales.yAxes[i] = this._makeAxisConfig(axis, 'y', i);\n\n if (axisLabels !== null) {\n config.options.scales.yAxes[i].ticks.callback = function(value) {\n return axisLabels[parseInt(value, 10)] || '';\n };\n }\n config.options.scales.yAxes[i].stacked = this._isStacked();\n }.bind(this));\n\n config.options.tooltips = {\n callbacks: {\n label: this._makeTooltip.bind(this)\n }\n };\n\n return config;\n };\n\n /**\n * Get the datasets configurations.\n *\n * @protected\n * @return {Object[]}\n */\n Output.prototype._makeDatasetsConfig = function() {\n var sets = this._chart.getSeries().map(function(series) {\n var colors = series.hasColoredValues() ? series.getColors() : series.getColor();\n var dataset = {\n label: this._cleanData(series.getLabel()),\n data: series.getValues(),\n type: series.getType(),\n fill: series.getFill(),\n backgroundColor: colors,\n // Pie charts look better without borders.\n borderColor: this._chart.getType() == Pie.prototype.TYPE ? '#fff' : colors,\n lineTension: this._isSmooth(series) ? 0.3 : 0\n };\n\n if (series.getXAxis() !== null) {\n dataset.xAxisID = makeAxisId('x', series.getXAxis());\n }\n if (series.getYAxis() !== null) {\n dataset.yAxisID = makeAxisId('y', series.getYAxis());\n }\n\n return dataset;\n }.bind(this));\n return sets;\n };\n\n /**\n * Get the chart data, add labels and rebuild the tooltip.\n *\n * @param {Object[]} tooltipItem The tooltip item data.\n * @param {Object[]} data The chart data.\n * @returns {String}\n * @protected\n */\n Output.prototype._makeTooltip = function(tooltipItem, data) {\n\n // Get series and chart data to rebuild the tooltip and add labels.\n var series = this._chart.getSeries()[tooltipItem.datasetIndex];\n var serieLabel = series.getLabel();\n var serieLabels = series.getLabels();\n var chartData = data.datasets[tooltipItem.datasetIndex].data;\n var tooltipData = chartData[tooltipItem.index];\n\n // Build default tooltip.\n var tooltip = [];\n\n // Pie and doughnut charts does not have axis.\n if (tooltipItem.xLabel == '' && tooltipItem.yLabel == '') {\n var chartLabels = this._cleanData(this._chart.getLabels());\n tooltip.push(chartLabels[tooltipItem.index]);\n }\n\n // Add series labels to the tooltip if any.\n if (serieLabels !== null) {\n tooltip.push(this._cleanData(serieLabels[tooltipItem.index]));\n } else {\n tooltip.push(this._cleanData(serieLabel) + ': ' + tooltipData);\n }\n\n return tooltip;\n };\n\n /**\n * Verify if the chart line is smooth or not.\n *\n * @protected\n * @param {module:core/chart_series} series The series.\n * @returns {Bool}\n */\n Output.prototype._isSmooth = function(series) {\n var smooth = false;\n if (this._chart.getType() === Line.prototype.TYPE) {\n smooth = series.getSmooth();\n if (smooth === null) {\n smooth = this._chart.getSmooth();\n }\n } else if (series.getType() === Series.prototype.TYPE_LINE) {\n smooth = series.getSmooth();\n }\n\n return smooth;\n };\n\n /**\n * Verify if the bar chart is stacked or not.\n *\n * @protected\n * @returns {Bool}\n */\n Output.prototype._isStacked = function() {\n var stacked = false;\n\n // Stacking is (currently) only supported for bar charts.\n if (this._chart.getType() === Bar.prototype.TYPE) {\n stacked = this._chart.getStacked();\n }\n\n return stacked;\n };\n\n /** @override */\n Output.prototype.update = function() {\n $.extend(true, this._config, this._makeConfig());\n this._chartjs.update();\n };\n\n return Output;\n\n});\n"],"file":"chart_output_chartjs.min.js"} \ No newline at end of file diff --git a/lib/amd/build/chart_series.min.js b/lib/amd/build/chart_series.min.js index 20e78fdd7cb..6153da1be7b 100644 --- a/lib/amd/build/chart_series.min.js +++ b/lib/amd/build/chart_series.min.js @@ -1,2 +1,2 @@ -function _typeof(a){if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("core/chart_series",[],function(){function a(a,b){if("string"!=typeof a){throw new Error("Invalid label for series.")}else if("object"!==_typeof(b)){throw new Error("Values for a series must be an array.")}else if(1>b.length){throw new Error("Invalid values received for series.")}this._colors=[];this._label=a;this._values=b}a.prototype.TYPE_DEFAULT=null;a.prototype.TYPE_LINE="line";a.prototype._colors=null;a.prototype._label=null;a.prototype._labels=null;a.prototype._smooth=!1;a.prototype._type=a.prototype.TYPE_DEFAULT;a.prototype._values=null;a.prototype._xaxis=null;a.prototype._yaxis=null;a.prototype.create=function(b){var c=new a(b.label,b.values);c.setType(b.type);c.setXAxis(b.axes.x);c.setYAxis(b.axes.y);c.setLabels(b.labels);if(b.colors&&1b.length){throw new Error("Invalid values received for series.")}this._colors=[];this._label=a;this._values=b}a.prototype.TYPE_DEFAULT=null;a.prototype.TYPE_LINE="line";a.prototype._colors=null;a.prototype._fill=!1;a.prototype._label=null;a.prototype._labels=null;a.prototype._smooth=!1;a.prototype._type=a.prototype.TYPE_DEFAULT;a.prototype._values=null;a.prototype._xaxis=null;a.prototype._yaxis=null;a.prototype.create=function(b){var c=new a(b.label,b.values);c.setType(b.type);c.setXAxis(b.axes.x);c.setYAxis(b.axes.y);c.setLabels(b.labels);if(b.colors&&1.\n\n/**\n * Chart series.\n *\n * @package core\n * @copyright 2016 Frédéric Massart - FMCorz.net\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @module core/chart_series\n */\ndefine([], function() {\n\n /**\n * Chart data series.\n *\n * @class\n * @alias module:core/chart_series\n * @param {String} label The series label.\n * @param {Number[]} values The values.\n */\n function Series(label, values) {\n if (typeof label !== 'string') {\n throw new Error('Invalid label for series.');\n\n } else if (typeof values !== 'object') {\n throw new Error('Values for a series must be an array.');\n\n } else if (values.length < 1) {\n throw new Error('Invalid values received for series.');\n }\n\n this._colors = [];\n this._label = label;\n this._values = values;\n }\n\n /**\n * The default type of series.\n *\n * @type {Null}\n * @const\n */\n Series.prototype.TYPE_DEFAULT = null;\n\n /**\n * Type of series 'line'.\n *\n * @type {String}\n * @const\n */\n Series.prototype.TYPE_LINE = 'line';\n\n /**\n * The colors of the series.\n *\n * @type {String[]}\n * @protected\n */\n Series.prototype._colors = null;\n\n /**\n * The label of the series.\n *\n * @type {String}\n * @protected\n */\n Series.prototype._label = null;\n\n /**\n * The labels for the values of the series.\n *\n * @type {String[]}\n * @protected\n */\n Series.prototype._labels = null;\n\n /**\n * Whether the line of the serie should be smooth or not.\n *\n * @type {Bool}\n * @protected\n */\n Series.prototype._smooth = false;\n\n /**\n * The type of the series.\n *\n * @type {String}\n * @protected\n */\n Series.prototype._type = Series.prototype.TYPE_DEFAULT;\n\n /**\n * The values in the series.\n *\n * @type {Number[]}\n * @protected\n */\n Series.prototype._values = null;\n\n /**\n * The index of the X axis.\n *\n * @type {Number[]}\n * @protected\n */\n Series.prototype._xaxis = null;\n\n /**\n * The index of the Y axis.\n *\n * @type {Number[]}\n * @protected\n */\n Series.prototype._yaxis = null;\n\n /**\n * Create a new instance of a series from serialised data.\n *\n * @static\n * @method create\n * @param {Object} obj The data of the series.\n * @return {module:core/chart_series}\n */\n Series.prototype.create = function(obj) {\n var s = new Series(obj.label, obj.values);\n s.setType(obj.type);\n s.setXAxis(obj.axes.x);\n s.setYAxis(obj.axes.y);\n s.setLabels(obj.labels);\n\n // Colors are exported as an array with 1, or n values.\n if (obj.colors && obj.colors.length > 1) {\n s.setColors(obj.colors);\n } else {\n s.setColor(obj.colors[0]);\n }\n\n s.setSmooth(obj.smooth);\n return s;\n };\n\n /**\n * Get the color.\n *\n * @return {String}\n */\n Series.prototype.getColor = function() {\n return this._colors[0] || null;\n };\n\n /**\n * Get the colors for each value in the series.\n *\n * @return {String[]}\n */\n Series.prototype.getColors = function() {\n return this._colors;\n };\n\n /**\n * Get the number of values in the series.\n *\n * @return {Number}\n */\n Series.prototype.getCount = function() {\n return this._values.length;\n };\n\n /**\n * Get the series label.\n *\n * @return {String}\n */\n Series.prototype.getLabel = function() {\n return this._label;\n };\n\n /**\n * Get labels for the values of the series.\n *\n * @return {String[]}\n */\n Series.prototype.getLabels = function() {\n return this._labels;\n };\n\n /**\n * Get whether the line of the serie should be smooth or not.\n *\n * @returns {Bool}\n */\n Series.prototype.getSmooth = function() {\n return this._smooth;\n };\n\n /**\n * Get the series type.\n *\n * @return {String}\n */\n Series.prototype.getType = function() {\n return this._type;\n };\n\n /**\n * Get the series values.\n *\n * @return {Number[]}\n */\n Series.prototype.getValues = function() {\n return this._values;\n };\n\n /**\n * Get the index of the X axis.\n *\n * @return {Number}\n */\n Series.prototype.getXAxis = function() {\n return this._xaxis;\n };\n\n /**\n * Get the index of the Y axis.\n *\n * @return {Number}\n */\n Series.prototype.getYAxis = function() {\n return this._yaxis;\n };\n\n /**\n * Whether there is a color per value.\n *\n * @return {Bool}\n */\n Series.prototype.hasColoredValues = function() {\n return this._colors.length == this.getCount();\n };\n\n /**\n * Set the series color.\n *\n * @param {String} color A CSS-compatible color.\n */\n Series.prototype.setColor = function(color) {\n this._colors = [color];\n };\n\n /**\n * Set a color for each value in the series.\n *\n * @param {String[]} colors CSS-compatible colors.\n */\n Series.prototype.setColors = function(colors) {\n if (colors && colors.length != this.getCount()) {\n throw new Error('When setting multiple colors there must be one per value.');\n }\n this._colors = colors || [];\n };\n\n /**\n * Set the labels for the values of the series.\n *\n * @param {String[]} labels the labels of the series values.\n */\n Series.prototype.setLabels = function(labels) {\n this._validateLabels(labels);\n labels = typeof labels === 'undefined' ? null : labels;\n this._labels = labels;\n };\n\n /**\n * Set Whether the line of the serie should be smooth or not.\n *\n * Only applicable for line chart or a line series, if null it assumes the chart default (not smooth).\n *\n * @param {Bool} smooth True if the lines should be smooth, false for tensioned lines.\n */\n Series.prototype.setSmooth = function(smooth) {\n smooth = typeof smooth === 'undefined' ? null : smooth;\n this._smooth = smooth;\n };\n\n /**\n * Set the type of the series.\n *\n * @param {String} type A type constant value.\n */\n Series.prototype.setType = function(type) {\n if (type != this.TYPE_DEFAULT && type != this.TYPE_LINE) {\n throw new Error('Invalid serie type.');\n }\n this._type = type || null;\n };\n\n /**\n * Set the index of the X axis.\n *\n * @param {Number} index The index.\n */\n Series.prototype.setXAxis = function(index) {\n this._xaxis = index || null;\n };\n\n\n /**\n * Set the index of the Y axis.\n *\n * @param {Number} index The index.\n */\n Series.prototype.setYAxis = function(index) {\n this._yaxis = index || null;\n };\n\n /**\n * Validate series labels.\n *\n * @protected\n * @param {String[]} labels The labels of the serie.\n */\n Series.prototype._validateLabels = function(labels) {\n if (labels && labels.length > 0 && labels.length != this.getCount()) {\n throw new Error('Series labels must match series values.');\n }\n };\n\n return Series;\n\n});\n"],"file":"chart_series.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/chart_series.js"],"names":["define","Series","label","values","Error","length","_colors","_label","_values","prototype","TYPE_DEFAULT","TYPE_LINE","_fill","_labels","_smooth","_type","_xaxis","_yaxis","create","obj","s","setType","type","setXAxis","axes","x","setYAxis","y","setLabels","labels","colors","setColors","setColor","setFill","fill","setSmooth","smooth","getColor","getColors","getCount","getFill","getLabel","getLabels","getS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istribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Chart series.\n *\n * @package core\n * @copyright 2016 Frédéric Massart - FMCorz.net\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n * @module core/chart_series\n */\ndefine([], function() {\n\n /**\n * Chart data series.\n *\n * @class\n * @alias module:core/chart_series\n * @param {String} label The series label.\n * @param {Number[]} values The values.\n */\n function Series(label, values) {\n if (typeof label !== 'string') {\n throw new Error('Invalid label for series.');\n\n } else if (typeof values !== 'object') {\n throw new Error('Values for a series must be an array.');\n\n } else if (values.length < 1) {\n throw new Error('Invalid values received for series.');\n }\n\n this._colors = [];\n this._label = label;\n this._values = values;\n }\n\n /**\n * The default type of series.\n *\n * @type {Null}\n * @const\n */\n Series.prototype.TYPE_DEFAULT = null;\n\n /**\n * Type of series 'line'.\n *\n * @type {String}\n * @const\n */\n Series.prototype.TYPE_LINE = 'line';\n\n /**\n * The colors of the series.\n *\n * @type {String[]}\n * @protected\n */\n Series.prototype._colors = null;\n\n /**\n * The fill mode of the series.\n *\n * @type {Object}\n * @protected\n */\n Series.prototype._fill = false;\n\n /**\n * The label of the series.\n *\n * @type {String}\n * @protected\n */\n Series.prototype._label = null;\n\n /**\n * The labels for the values of the series.\n *\n * @type {String[]}\n * @protected\n */\n Series.prototype._labels = null;\n\n /**\n * Whether the line of the serie should be smooth or not.\n *\n * @type {Bool}\n * @protected\n */\n Series.prototype._smooth = false;\n\n /**\n * The type of the series.\n *\n * @type {String}\n * @protected\n */\n Series.prototype._type = Series.prototype.TYPE_DEFAULT;\n\n /**\n * The values in the series.\n *\n * @type {Number[]}\n * @protected\n */\n Series.prototype._values = null;\n\n /**\n * The index of the X axis.\n *\n * @type {Number[]}\n * @protected\n */\n Series.prototype._xaxis = null;\n\n /**\n * The index of the Y axis.\n *\n * @type {Number[]}\n * @protected\n */\n Series.prototype._yaxis = null;\n\n /**\n * Create a new instance of a series from serialised data.\n *\n * @static\n * @method create\n * @param {Object} obj The data of the series.\n * @return {module:core/chart_series}\n */\n Series.prototype.create = function(obj) {\n var s = new Series(obj.label, obj.values);\n s.setType(obj.type);\n s.setXAxis(obj.axes.x);\n s.setYAxis(obj.axes.y);\n s.setLabels(obj.labels);\n\n // Colors are exported as an array with 1, or n values.\n if (obj.colors && obj.colors.length > 1) {\n s.setColors(obj.colors);\n } else {\n s.setColor(obj.colors[0]);\n }\n\n s.setFill(obj.fill);\n s.setSmooth(obj.smooth);\n return s;\n };\n\n /**\n * Get the color.\n *\n * @return {String}\n */\n Series.prototype.getColor = function() {\n return this._colors[0] || null;\n };\n\n /**\n * Get the colors for each value in the series.\n *\n * @return {String[]}\n */\n Series.prototype.getColors = function() {\n return this._colors;\n };\n\n /**\n * Get the number of values in the series.\n *\n * @return {Number}\n */\n Series.prototype.getCount = function() {\n return this._values.length;\n };\n\n /**\n * Get the fill mode of the series.\n *\n * @return {Object}\n */\n Series.prototype.getFill = function() {\n return this._fill;\n };\n\n /**\n * Get the series label.\n *\n * @return {String}\n */\n Series.prototype.getLabel = function() {\n return this._label;\n };\n\n /**\n * Get labels for the values of the series.\n *\n * @return {String[]}\n */\n Series.prototype.getLabels = function() {\n return this._labels;\n };\n\n /**\n * Get whether the line of the serie should be smooth or not.\n *\n * @returns {Bool}\n */\n Series.prototype.getSmooth = function() {\n return this._smooth;\n };\n\n /**\n * Get the series type.\n *\n * @return {String}\n */\n Series.prototype.getType = function() {\n return this._type;\n };\n\n /**\n * Get the series values.\n *\n * @return {Number[]}\n */\n Series.prototype.getValues = function() {\n return this._values;\n };\n\n /**\n * Get the index of the X axis.\n *\n * @return {Number}\n */\n Series.prototype.getXAxis = function() {\n return this._xaxis;\n };\n\n /**\n * Get the index of the Y axis.\n *\n * @return {Number}\n */\n Series.prototype.getYAxis = function() {\n return this._yaxis;\n };\n\n /**\n * Whether there is a color per value.\n *\n * @return {Bool}\n */\n Series.prototype.hasColoredValues = function() {\n return this._colors.length == this.getCount();\n };\n\n /**\n * Set the series color.\n *\n * @param {String} color A CSS-compatible color.\n */\n Series.prototype.setColor = function(color) {\n this._colors = [color];\n };\n\n /**\n * Set a color for each value in the series.\n *\n * @param {String[]} colors CSS-compatible colors.\n */\n Series.prototype.setColors = function(colors) {\n if (colors && colors.length != this.getCount()) {\n throw new Error('When setting multiple colors there must be one per value.');\n }\n this._colors = colors || [];\n };\n\n /**\n * Set the fill mode for the series.\n *\n * @param {Object} fill\n */\n Series.prototype.setFill = function(fill) {\n this._fill = typeof fill === 'undefined' ? null : fill;\n };\n\n /**\n * Set the labels for the values of the series.\n *\n * @param {String[]} labels the labels of the series values.\n */\n Series.prototype.setLabels = function(labels) {\n this._validateLabels(labels);\n labels = typeof labels === 'undefined' ? null : labels;\n this._labels = labels;\n };\n\n /**\n * Set Whether the line of the serie should be smooth or not.\n *\n * Only applicable for line chart or a line series, if null it assumes the chart default (not smooth).\n *\n * @param {Bool} smooth True if the lines should be smooth, false for tensioned lines.\n */\n Series.prototype.setSmooth = function(smooth) {\n smooth = typeof smooth === 'undefined' ? null : smooth;\n this._smooth = smooth;\n };\n\n /**\n * Set the type of the series.\n *\n * @param {String} type A type constant value.\n */\n Series.prototype.setType = function(type) {\n if (type != this.TYPE_DEFAULT && type != this.TYPE_LINE) {\n throw new Error('Invalid serie type.');\n }\n this._type = type || null;\n };\n\n /**\n * Set the index of the X axis.\n *\n * @param {Number} index The index.\n */\n Series.prototype.setXAxis = function(index) {\n this._xaxis = index || null;\n };\n\n\n /**\n * Set the index of the Y axis.\n *\n * @param {Number} index The index.\n */\n Series.prototype.setYAxis = function(index) {\n this._yaxis = index || null;\n };\n\n /**\n * Validate series labels.\n *\n * @protected\n * @param {String[]} labels The labels of the serie.\n */\n Series.prototype._validateLabels = function(labels) {\n if (labels && labels.length > 0 && labels.length != this.getCount()) {\n throw new Error('Series labels must match series values.');\n }\n };\n\n return Series;\n\n});\n"],"file":"chart_series.min.js"} \ 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 4f0a0b05ba3..3d6180eb516 100644 --- a/lib/amd/src/chart_output_chartjs.js +++ b/lib/amd/src/chart_output_chartjs.js @@ -256,7 +256,7 @@ define([ label: this._cleanData(series.getLabel()), data: series.getValues(), type: series.getType(), - fill: false, + fill: series.getFill(), backgroundColor: colors, // Pie charts look better without borders. borderColor: this._chart.getType() == Pie.prototype.TYPE ? '#fff' : colors, diff --git a/lib/amd/src/chart_series.js b/lib/amd/src/chart_series.js index 90cb2813952..34e521162ad 100644 --- a/lib/amd/src/chart_series.js +++ b/lib/amd/src/chart_series.js @@ -71,6 +71,14 @@ define([], function() { */ Series.prototype._colors = null; + /** + * The fill mode of the series. + * + * @type {Object} + * @protected + */ + Series.prototype._fill = false; + /** * The label of the series. * @@ -149,6 +157,7 @@ define([], function() { s.setColor(obj.colors[0]); } + s.setFill(obj.fill); s.setSmooth(obj.smooth); return s; }; @@ -180,6 +189,15 @@ define([], function() { return this._values.length; }; + /** + * Get the fill mode of the series. + * + * @return {Object} + */ + Series.prototype.getFill = function() { + return this._fill; + }; + /** * Get the series label. * @@ -273,6 +291,15 @@ define([], function() { this._colors = colors || []; }; + /** + * Set the fill mode for the series. + * + * @param {Object} fill + */ + Series.prototype.setFill = function(fill) { + this._fill = typeof fill === 'undefined' ? null : fill; + }; + /** * Set the labels for the values of the series. * diff --git a/lib/classes/chart_series.php b/lib/classes/chart_series.php index b3e79d8c1da..5db4ede4aed 100644 --- a/lib/classes/chart_series.php +++ b/lib/classes/chart_series.php @@ -44,6 +44,8 @@ class chart_series implements JsonSerializable { /** @var string[] Colors of the series. */ protected $colors = []; + /** @var string Fill mode for area charts. See https://www.chartjs.org/docs/latest/charts/area.html */ + protected $fill = null; /** @var string Label for this series. */ protected $label; /** @var string[] Labels for the values of the series. */ @@ -97,6 +99,13 @@ class chart_series implements JsonSerializable { return count($this->values); } + /** + * Get area fill mode for series. + */ + public function get_fill() { + return $this->fill; + } + /** * Get the label of the series. * @@ -181,6 +190,7 @@ class chart_series implements JsonSerializable { 'type' => $this->type, 'values' => $this->values, 'colors' => $this->colors, + 'fill' => $this->fill, 'axes' => [ 'x' => $this->xaxis, 'y' => $this->yaxis, @@ -208,6 +218,14 @@ class chart_series implements JsonSerializable { $this->colors = $colors; } + /** + * Set fill mode for the series. + * @param string $fill + */ + public function set_fill($fill) { + $this->fill = $fill; + } + /** * Set labels for the values of the series. * diff --git a/lib/tests/other/chartjstestpage.php b/lib/tests/other/chartjstestpage.php index f1081d951b7..441c7e62a71 100644 --- a/lib/tests/other/chartjstestpage.php +++ b/lib/tests/other/chartjstestpage.php @@ -90,6 +90,20 @@ $chart8->add_series($expensesline); $chart8->add_series($sales); $chart8->set_labels($labels); +$hills = new \core\chart_series('Hills', [700, 870, 660, 950]); +$mountain = new \core\chart_series('Mountain', [400, 460, 1350, 540]); +$sky = new \core\chart_series('Sky', [1400, 1500, 1550, 1500]); +$chart9 = new \core\chart_line(); +$chart9->set_title('AREA FILL CHART'); +$chart9->add_series($hills); +$chart9->add_series($mountain); +$chart9->add_series($sky); +$chart9->set_labels($labels); +$hills->set_smooth(true); +$hills->set_fill('origin'); +$mountain->set_fill('-1'); +$sky->set_fill('end'); + echo $OUTPUT->render($chart); echo $OUTPUT->render($chart2); echo $OUTPUT->render($chart3); @@ -98,4 +112,5 @@ echo $OUTPUT->render($chart5); echo $OUTPUT->render($chart6); echo $OUTPUT->render($chart7); echo $OUTPUT->render($chart8); +echo $OUTPUT->render($chart9); echo $OUTPUT->footer();