Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"chart_axis.min.js","sources":["../src/chart_axis.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 axis.\n *\n * @module core/chart_axis\n * @copyright  2016 Frédéric Massart - FMCorz.net\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine([], function() {\n\n    /**\n     * Chart axis class.\n     *\n     * This is used to represent an axis, whether X or Y.\n     *\n     * @class core/chart_axis\n     */\n    function Axis() {\n        // Please eslint no-empty-function.\n    }\n\n    /**\n     * Default axis position.\n     * @const {Null}\n     */\n    Axis.prototype.POS_DEFAULT = null;\n\n    /**\n     * Bottom axis position.\n     * @const {String}\n     */\n    Axis.prototype.POS_BOTTOM = 'bottom';\n\n    /**\n     * Left axis position.\n     * @const {String}\n     */\n    Axis.prototype.POS_LEFT = 'left';\n\n    /**\n     * Right axis position.\n     * @const {String}\n     */\n    Axis.prototype.POS_RIGHT = 'right';\n\n    /**\n     * Top axis position.\n     * @const {String}\n     */\n    Axis.prototype.POS_TOP = 'top';\n\n    /**\n     * Label of the axis.\n     * @type {String}\n     * @protected\n     */\n    Axis.prototype._label = null;\n\n    /**\n     * Labels of the ticks.\n     * @type {String[]}\n     * @protected\n     */\n    Axis.prototype._labels = null;\n\n    /**\n     * Maximum value of the axis.\n     * @type {Number}\n     * @protected\n     */\n    Axis.prototype._max = null;\n\n    /**\n     * Minimum value of the axis.\n     * @type {Number}\n     * @protected\n     */\n    Axis.prototype._min = null;\n\n    /**\n     * Position of the axis.\n     * @type {String}\n     * @protected\n     */\n    Axis.prototype._position = null;\n\n    /**\n     * Steps on the axis.\n     * @type {Number}\n     * @protected\n     */\n    Axis.prototype._stepSize = null;\n\n    /**\n     * Create a new instance of an axis from serialised data.\n     *\n     * @static\n     * @method create\n     * @param {Object} obj The data of the axis.\n     * @return {module:core/chart_axis}\n     */\n    Axis.prototype.create = function(obj) {\n        var s = new Axis();\n        s.setPosition(obj.position);\n        s.setLabel(obj.label);\n        s.setStepSize(obj.stepSize);\n        s.setMax(obj.max);\n        s.setMin(obj.min);\n        s.setLabels(obj.labels);\n        return s;\n    };\n\n    /**\n     * Get the label of the axis.\n     *\n     * @method getLabel\n     * @return {String}\n     */\n    Axis.prototype.getLabel = function() {\n        return this._label;\n    };\n\n    /**\n     * Get the labels of the ticks of the axis.\n     *\n     * @method getLabels\n     * @return {String[]}\n     */\n    Axis.prototype.getLabels = function() {\n        return this._labels;\n    };\n\n    /**\n     * Get the maximum value of the axis.\n     *\n     * @method getMax\n     * @return {Number}\n     */\n    Axis.prototype.getMax = function() {\n        return this._max;\n    };\n\n    /**\n     * Get the minimum value of the axis.\n     *\n     * @method getMin\n     * @return {Number}\n     */\n    Axis.prototype.getMin = function() {\n        return this._min;\n    };\n\n    /**\n     * Get the position of the axis.\n     *\n     * @method getPosition\n     * @return {String}\n     */\n    Axis.prototype.getPosition = function() {\n        return this._position;\n    };\n\n    /**\n     * Get the step size of the axis.\n     *\n     * @method getStepSize\n     * @return {Number}\n     */\n    Axis.prototype.getStepSize = function() {\n        return this._stepSize;\n    };\n\n    /**\n     * Set the label of the axis.\n     *\n     * @method setLabel\n     * @param {String} label The label.\n     */\n    Axis.prototype.setLabel = function(label) {\n        this._label = label || null;\n    };\n\n    /**\n     * Set the labels of the values on the axis.\n     *\n     * This automatically sets the [_stepSize]{@link module:core/chart_axis#_stepSize},\n     * [_min]{@link module:core/chart_axis#_min} and [_max]{@link module:core/chart_axis#_max}\n     * to define a scale from 0 to the number of labels when none of the previously\n     * mentioned values have been modified.\n     *\n     * You can use other values so long that your values in a series are mapped\n     * to the values represented by your _min, _max and _stepSize.\n     *\n     * @method setLabels\n     * @param {String[]} labels The labels.\n     */\n    Axis.prototype.setLabels = function(labels) {\n        this._labels = labels || null;\n\n        // By default we set the grid according to the labels.\n        if (this._labels !== null\n                && this._stepSize === null\n                && (this._min === null || this._min === 0)\n                && this._max === null) {\n            this.setStepSize(1);\n            this.setMin(0);\n            this.setMax(labels.length - 1);\n        }\n    };\n\n    /**\n     * Set the maximum value on the axis.\n     *\n     * When this is not set (or set to null) it is left for the output\n     * library to best guess what should be used.\n     *\n     * @method setMax\n     * @param {Number} max The value.\n     */\n    Axis.prototype.setMax = function(max) {\n        this._max = typeof max !== 'undefined' ? max : null;\n    };\n\n    /**\n     * Set the minimum value on the axis.\n     *\n     * When this is not set (or set to null) it is left for the output\n     * library to best guess what should be used.\n     *\n     * @method setMin\n     * @param {Number} min The value.\n     */\n    Axis.prototype.setMin = function(min) {\n        this._min = typeof min !== 'undefined' ? min : null;\n    };\n\n    /**\n     * Set the position of the axis.\n     *\n     * This does not validate whether or not the constant used is valid\n     * as the axis itself is not aware whether it represents the X or Y axis.\n     *\n     * The output library has to have a fallback in case the values are incorrect.\n     * When this is not set to {@link module:core/chart_axis#POS_DEFAULT} it is up\n     * to the output library to choose what position fits best.\n     *\n     * @method setPosition\n     * @param {String} position The value.\n     */\n    Axis.prototype.setPosition = function(position) {\n        if (position != this.POS_DEFAULT\n                && position != this.POS_BOTTOM\n                && position != this.POS_LEFT\n                && position != this.POS_RIGHT\n                && position != this.POS_TOP) {\n            throw new Error('Invalid axis position.');\n        }\n        this._position = position;\n    };\n\n    /**\n     * Set the stepSize on the axis.\n     *\n     * This is used to determine where ticks are displayed on the axis between min and max.\n     *\n     * @method setStepSize\n     * @param {Number} stepSize The value.\n     */\n    Axis.prototype.setStepSize = function(stepSize) {\n        if (typeof stepSize === 'undefined' || stepSize === null) {\n            stepSize = null;\n        } else if (isNaN(Number(stepSize))) {\n            throw new Error('Value for stepSize is not a number.');\n        } else {\n            stepSize = Number(stepSize);\n        }\n\n        this._stepSize = stepSize;\n    };\n\n    return Axis;\n\n});\n"],"names":["define","Axis","prototype","POS_DEFAULT","POS_BOTTOM","POS_LEFT","POS_RIGHT","POS_TOP","_label","_labels","_max","_min","_position","_stepSize","create","obj","s","setPosition","position","setLabel","label","setStepSize","stepSize","setMax","max","setMin","min","setLabels","labels","getLabel","this","getLabels","getMax","getMin","getPosition","getStepSize","length","Error","isNaN","Number"],"mappings":";;;;;;;AAsBAA,yBAAO,IAAI,oBASEC,eAQTA,KAAKC,UAAUC,YAAc,KAM7BF,KAAKC,UAAUE,WAAa,SAM5BH,KAAKC,UAAUG,SAAW,OAM1BJ,KAAKC,UAAUI,UAAY,QAM3BL,KAAKC,UAAUK,QAAU,MAOzBN,KAAKC,UAAUM,OAAS,KAOxBP,KAAKC,UAAUO,QAAU,KAOzBR,KAAKC,UAAUQ,KAAO,KAOtBT,KAAKC,UAAUS,KAAO,KAOtBV,KAAKC,UAAUU,UAAY,KAO3BX,KAAKC,UAAUW,UAAY,KAU3BZ,KAAKC,UAAUY,OAAS,SAASC,SACzBC,EAAI,IAAIf,YACZe,EAAEC,YAAYF,IAAIG,UAClBF,EAAEG,SAASJ,IAAIK,OACfJ,EAAEK,YAAYN,IAAIO,UAClBN,EAAEO,OAAOR,IAAIS,KACbR,EAAES,OAAOV,IAAIW,KACbV,EAAEW,UAAUZ,IAAIa,QACTZ,GASXf,KAAKC,UAAU2B,SAAW,kBACfC,KAAKtB,QAShBP,KAAKC,UAAU6B,UAAY,kBAChBD,KAAKrB,SAShBR,KAAKC,UAAU8B,OAAS,kBACbF,KAAKpB,MAShBT,KAAKC,UAAU+B,OAAS,kBACbH,KAAKnB,MAShBV,KAAKC,UAAUgC,YAAc,kBAClBJ,KAAKlB,WAShBX,KAAKC,UAAUiC,YAAc,kBAClBL,KAAK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