Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"chart_series.min.js","sources":["../src/chart_series.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 series.\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_series\n */\ndefine([], function() {\n\n    /**\n     * Chart data series.\n     *\n     * @class\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"],"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","this","getColors","getCount","getFill","getLabel","getLabels","getSmooth","getType","getValues","getXAxis","getYAxis","hasColoredValues","color","_validateLabels","index"],"mappings":";;;;;;;AAsBAA,2BAAO,IAAI,oBASEC,OAAOC,MAAOC,WACE,iBAAVD,YACD,IAAIE,MAAM,6BAEb,GAAsB,iBAAXD,aACR,IAAIC,MAAM,yCAEb,GAAID,OAAOE,OAAS,QACjB,IAAID,MAAM,4CAGfE,QAAU,QACVC,OAASL,WACTM,QAAUL,cASnBF,OAAOQ,UAAUC,aAAe,KAQhCT,OAAOQ,UAAUE,UAAY,OAQ7BV,OAAOQ,UAAUH,QAAU,KAQ3BL,OAAOQ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