MDL-79041 core: Fix typo for MoodleNet resource URL
[moodle.git] / lib / amd / build / chart_base.min.js.map
blob585492df378c8fa1fed56536e8c7f864c4f56357
1 {"version":3,"file":"chart_base.min.js","sources":["../src/chart_base.js"],"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 <http://www.gnu.org/licenses/>.\n\n/**\n * Chart base.\n *\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_base\n */\ndefine(['core/chart_series', 'core/chart_axis'], function(Series, Axis) {\n\n    /**\n     * Chart base.\n     *\n     * The constructor of a chart must never take any argument.\n     *\n     * {@link module:core/chart_base#_setDefault} to set the defaults on instantiation.\n     *\n     * @class\n     */\n    function Base() {\n        this._series = [];\n        this._labels = [];\n        this._xaxes = [];\n        this._yaxes = [];\n\n        this._setDefaults();\n    }\n\n    /**\n     * The series constituting this chart.\n     *\n     * @protected\n     * @type {module:core/chart_series[]}\n     */\n    Base.prototype._series = null;\n\n    /**\n     * The labels of the X axis when categorised.\n     *\n     * @protected\n     * @type {String[]}\n     */\n    Base.prototype._labels = null;\n\n    /**\n     * Options for chart legend display.\n     *\n     * @protected\n     * @type {Object}\n     */\n    Base.prototype._legendOptions = null;\n\n    /**\n     * The title of the chart.\n     *\n     * @protected\n     * @type {String}\n     */\n    Base.prototype._title = null;\n\n    /**\n     * The X axes.\n     *\n     * @protected\n     * @type {module:core/chart_axis[]}\n     */\n    Base.prototype._xaxes = null;\n\n    /**\n     * The Y axes.\n     *\n     * @protected\n     * @type {module:core/chart_axis[]}\n     */\n    Base.prototype._yaxes = null;\n\n    /**\n     * Colours to pick from when automatically assigning them.\n     *\n     * @const\n     * @type {String[]}\n     */\n    Base.prototype.COLORSET = ['#f3c300', '#875692', '#f38400', '#a1caf1', '#be0032', '#c2b280', '#7f180d', '#008856',\n            '#e68fac', '#0067a5'];\n\n    /**\n     * Set of colours defined by setting $CFG->chart_colorset to be picked when automatically assigning them.\n     *\n     * @type {String[]}\n     * @protected\n     */\n    Base.prototype._configColorSet = null;\n\n    /**\n     * The type of chart.\n     *\n     * @abstract\n     * @type {String}\n     * @const\n     */\n    Base.prototype.TYPE = null;\n\n    /**\n     * Add a series to the chart.\n     *\n     * This will automatically assign a color to the series if it does not have one.\n     *\n     * @param {module:core/chart_series} series The series to add.\n     */\n    Base.prototype.addSeries = function(series) {\n        this._validateSeries(series);\n        this._series.push(series);\n\n        // Give a default color from the set.\n        if (series.getColor() === null) {\n            var configColorSet = this.getConfigColorSet() || Base.prototype.COLORSET;\n            series.setColor(configColorSet[this._series.length % configColorSet.length]);\n        }\n    };\n\n    /**\n     * Create a new instance of a chart from serialised data.\n     *\n     * the serialised attributes they offer and support.\n     *\n     * @static\n     * @method create\n     * @param {module:core/chart_base} Klass The class oject representing the type of chart to instantiate.\n     * @param {Object} data The data of the chart.\n     * @return {module:core/chart_base}\n     */\n    Base.prototype.create = function(Klass, data) {\n        // TODO Not convinced about the usage of Klass here but I can't figure out a way\n        // to have a reference to the class in the sub classes, in PHP I'd do new self().\n        var Chart = new Klass();\n        Chart.setConfigColorSet(data.config_colorset);\n        Chart.setLabels(data.labels);\n        Chart.setTitle(data.title);\n        if (data.legend_options) {\n            Chart.setLegendOptions(data.legend_options);\n        }\n        data.series.forEach(function(seriesData) {\n            Chart.addSeries(Series.prototype.create(seriesData));\n        });\n        data.axes.x.forEach(function(axisData, i) {\n            Chart.setXAxis(Axis.prototype.create(axisData), i);\n        });\n        data.axes.y.forEach(function(axisData, i) {\n            Chart.setYAxis(Axis.prototype.create(axisData), i);\n        });\n        return Chart;\n    };\n\n    /**\n     * Get an axis.\n     *\n     * @private\n     * @param {String} xy Accepts the values 'x' or 'y'.\n     * @param {Number} [index=0] The index of the axis of its type.\n     * @param {Bool} [createIfNotExists=false] When true, create an instance if it does not exist.\n     * @return {module:core/chart_axis}\n     */\n    Base.prototype.__getAxis = function(xy, index, createIfNotExists) {\n        var axes = xy === 'x' ? this._xaxes : this._yaxes,\n            setAxis = (xy === 'x' ? this.setXAxis : this.setYAxis).bind(this),\n            axis;\n\n        index = typeof index === 'undefined' ? 0 : index;\n        createIfNotExists = typeof createIfNotExists === 'undefined' ? false : createIfNotExists;\n        axis = axes[index];\n\n        if (typeof axis === 'undefined') {\n            if (!createIfNotExists) {\n                throw new Error('Unknown axis.');\n            }\n            axis = new Axis();\n            setAxis(axis, index);\n        }\n\n        return axis;\n    };\n\n    /**\n     * Get colours defined by setting.\n     *\n     * @return {String[]}\n     */\n    Base.prototype.getConfigColorSet = function() {\n        return this._configColorSet;\n    };\n\n    /**\n     * Get the labels of the X axis.\n     *\n     * @return {String[]}\n     */\n    Base.prototype.getLabels = function() {\n        return this._labels;\n    };\n\n    /**\n     * Get whether to display the chart legend.\n     *\n     * @return {Bool}\n     */\n    Base.prototype.getLegendOptions = function() {\n        return this._legendOptions;\n    };\n\n    /**\n     * Get the series.\n     *\n     * @return {module:core/chart_series[]}\n     */\n    Base.prototype.getSeries = function() {\n        return this._series;\n    };\n\n    /**\n     * Get the title of the chart.\n     *\n     * @return {String}\n     */\n    Base.prototype.getTitle = function() {\n        return this._title;\n    };\n\n    /**\n     * Get the type of chart.\n     *\n     * @see module:core/chart_base#TYPE\n     * @return {String}\n     */\n    Base.prototype.getType = function() {\n        if (!this.TYPE) {\n            throw new Error('The TYPE property has not been set.');\n        }\n        return this.TYPE;\n    };\n\n    /**\n     * Get the X axes.\n     *\n     * @return {module:core/chart_axis[]}\n     */\n    Base.prototype.getXAxes = function() {\n        return this._xaxes;\n    };\n\n    /**\n     * Get an X axis.\n     *\n     * @param {Number} [index=0] The index of the axis.\n     * @param {Bool} [createIfNotExists=false] Create the instance of it does not exist at index.\n     * @return {module:core/chart_axis}\n     */\n    Base.prototype.getXAxis = function(index, createIfNotExists) {\n        return this.__getAxis('x', index, createIfNotExists);\n    };\n\n    /**\n     * Get the Y axes.\n     *\n     * @return {module:core/chart_axis[]}\n     */\n    Base.prototype.getYAxes = function() {\n        return this._yaxes;\n    };\n\n    /**\n     * Get an Y axis.\n     *\n     * @param {Number} [index=0] The index of the axis.\n     * @param {Bool} [createIfNotExists=false] Create the instance of it does not exist at index.\n     * @return {module:core/chart_axis}\n     */\n    Base.prototype.getYAxis = function(index, createIfNotExists) {\n        return this.__getAxis('y', index, createIfNotExists);\n    };\n\n    /**\n     * Set colours defined by setting.\n     *\n     * @param {String[]} colorset An array of css colours.\n     * @protected\n     */\n    Base.prototype.setConfigColorSet = function(colorset) {\n        this._configColorSet = colorset;\n    };\n\n    /**\n     * Set the defaults for this chart type.\n     *\n     * Child classes can extend this to set defaults values on instantiation.\n     *\n     * emphasize and self-document the defaults values set by the chart type.\n     *\n     * @protected\n     */\n    Base.prototype._setDefaults = function() {\n        // For the children to extend.\n    };\n\n    /**\n     * Set the labels of the X axis.\n     *\n     * This requires for each series to contain strictly as many values as there\n     * are labels.\n     *\n     * @param {String[]} labels The labels.\n     */\n    Base.prototype.setLabels = function(labels) {\n        if (labels.length && this._series.length && this._series[0].length != labels.length) {\n            throw new Error('Series must match label values.');\n        }\n        this._labels = labels;\n    };\n\n    /**\n     * Set options for chart legend display.\n     *\n     * @param {Object} legendOptions\n     */\n    Base.prototype.setLegendOptions = function(legendOptions) {\n        if (typeof legendOptions !== 'object') {\n            throw new Error('Setting legend with non-object value:' + legendOptions);\n        }\n        this._legendOptions = legendOptions;\n    };\n\n    /**\n     * Set the title of the chart.\n     *\n     * @param {String} title The title.\n     */\n    Base.prototype.setTitle = function(title) {\n        this._title = title;\n    };\n\n    /**\n     * Set an X axis.\n     *\n     * Note that this will override any predefined axis without warning.\n     *\n     * @param {module:core/chart_axis} axis The axis.\n     * @param {Number} [index=0] The index of the axis.\n     */\n    Base.prototype.setXAxis = function(axis, index) {\n        index = typeof index === 'undefined' ? 0 : index;\n        this._validateAxis('x', axis, index);\n        this._xaxes[index] = axis;\n    };\n\n    /**\n     * Set a Y axis.\n     *\n     * Note that this will override any predefined axis without warning.\n     *\n     * @param {module:core/chart_axis} axis The axis.\n     * @param {Number} [index=0] The index of the axis.\n     */\n    Base.prototype.setYAxis = function(axis, index) {\n        index = typeof index === 'undefined' ? 0 : index;\n        this._validateAxis('y', axis, index);\n        this._yaxes[index] = axis;\n    };\n\n    /**\n     * Validate an axis.\n     *\n     * @protected\n     * @param {String} xy X or Y axis.\n     * @param {module:core/chart_axis} axis The axis to validate.\n     * @param {Number} [index=0] The index of the axis.\n     */\n    Base.prototype._validateAxis = function(xy, axis, index) {\n        index = typeof index === 'undefined' ? 0 : index;\n        if (index > 0) {\n            var axes = xy == 'x' ? this._xaxes : this._yaxes;\n            if (typeof axes[index - 1] === 'undefined') {\n                throw new Error('Missing ' + xy + ' axis at index lower than ' + index);\n            }\n        }\n    };\n\n    /**\n     * Validate a series.\n     *\n     * @protected\n     * @param {module:core/chart_series} series The series to validate.\n     */\n    Base.prototype._validateSeries = function(series) {\n        if (this._series.length && this._series[0].getCount() != series.getCount()) {\n            throw new Error('Series do not have an equal number of values.');\n\n        } else if (this._labels.length && this._labels.length != series.getCount()) {\n            throw new Error('Series must match label values.');\n        }\n    };\n\n    return Base;\n\n});\n"],"names":["define","Series","Axis","Base","_series","_labels","_xaxes","_yaxes","_setDefaults","prototype","_legendOptions","_title","COLORSET","_configColorSet","TYPE","addSeries","series","_validateSeries","push","getColor","configColorSet","this","getConfigColorSet","setColor","length","create","Klass","data","Chart","setConfigColorSet","config_colorset","setLabels","labels","setTitle","title","legend_options","setLegendOptions","forEach","seriesData","axes","x","axisData","i","setXAxis","y","setYAxis","__getAxis","xy","index","createIfNotExists","axis","setAxis","bind","Error","getLabels","getLegendOptions","getSeries","getTitle","getType","getXAxes","getXAxis","getYAxes","getYAxis","colorset","legendOptions","_validateAxis","getCount"],"mappings":";;;;;;;AAsBAA,yBAAO,CAAC,oBAAqB,oBAAoB,SAASC,OAAQC,eAWrDC,YACAC,QAAU,QACVC,QAAU,QACVC,OAAS,QACTC,OAAS,QAETC,sBASTL,KAAKM,UAAUL,QAAU,KAQzBD,KAAKM,UAAUJ,QAAU,KAQzBF,KAAKM,UAAUC,eAAiB,KAQhCP,KAAKM,UAAUE,OAAS,KAQxBR,KAAKM,UAAUH,OAAS,KAQxBH,KAAKM,UAAUF,OAAS,KAQxBJ,KAAKM,UAAUG,SAAW,CAAC,UAAW,UAAW,UAAW,UAAW,UAAW,UAAW,UAAW,UAChG,UAAW,WAQnBT,KAAKM,UAAUI,gBAAkB,KASjCV,KAAKM,UAAUK,KAAO,KAStBX,KAAKM,UAAUM,UAAY,SAASC,gBAC3BC,gBAAgBD,aAChBZ,QAAQc,KAAKF,QAGQ,OAAtBA,OAAOG,WAAqB,KACxBC,eAAiBC,KAAKC,qBAAuBnB,KAAKM,UAAUG,SAChEI,OAAOO,SAASH,eAAeC,KAAKjB,QAAQoB,OAASJ,eAAeI,WAe5ErB,KAAKM,UAAUgB,OAAS,SAASC,MAAOC,UAGhCC,MAAQ,IAAIF,aAChBE,MAAMC,kBAAkBF,KAAKG,iBAC7BF,MAAMG,UAAUJ,KAAKK,QACrBJ,MAAMK,SAASN,KAAKO,OAChBP,KAAKQ,gBACLP,MAAMQ,iBAAiBT,KAAKQ,gBAEhCR,KAAKX,OAAOqB,SAAQ,SAASC,YACzBV,MAAMb,UAAUd,OAAOQ,UAAUgB,OAAOa,gBAE5CX,KAAKY,KAAKC,EAAEH,SAAQ,SAASI,SAAUC,GACnCd,MAAMe,SAASzC,KAAKO,UAAUgB,OAAOgB,UAAWC,MAEpDf,KAAKY,KAAKK,EAAEP,SAAQ,SAASI,SAAUC,G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