Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// This file is part of Moodle - http://moodle.org/
2
//
3
// Moodle is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
7
//
8
// Moodle is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
 
16
/**
17
 * Chart bar.
18
 *
19
 * @copyright  2016 Frédéric Massart - FMCorz.net
20
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21
 * @module     core/chart_bar
22
 */
23
define(['core/chart_base'], function(Base) {
24
 
25
    /**
26
     * Bar chart.
27
     *
28
     * @extends {module:core/chart_base}
29
     * @class
30
     */
31
    function Bar() {
32
        Base.prototype.constructor.apply(this, arguments);
33
    }
34
    Bar.prototype = Object.create(Base.prototype);
35
 
36
    /**
37
     * Whether the bars should be displayed horizontally or not.
38
     *
39
     * @type {Bool}
40
     * @protected
41
     */
42
    Bar.prototype._horizontal = false;
43
 
44
    /**
45
     * Whether the bars should be stacked or not.
46
     *
47
     * @type {Bool}
48
     * @protected
49
     */
50
    Bar.prototype._stacked = false;
51
 
52
    /** @override */
53
    Bar.prototype.TYPE = 'bar';
54
 
55
    /** @override */
56
    Bar.prototype.create = function(Klass, data) {
57
        var chart = Base.prototype.create.apply(this, arguments);
58
        chart.setHorizontal(data.horizontal);
59
        chart.setStacked(data.stacked);
60
        return chart;
61
    };
62
 
63
    /** @override */
64
    Bar.prototype._setDefaults = function() {
65
        Base.prototype._setDefaults.apply(this, arguments);
66
        var axis = this.getYAxis(0, true);
67
        axis.setMin(0);
68
    };
69
 
70
    /**
71
     * Get whether the bars should be displayed horizontally or not.
72
     *
73
     * @returns {Bool}
74
     */
75
    Bar.prototype.getHorizontal = function() {
76
        return this._horizontal;
77
    };
78
 
79
    /**
80
     * Get whether the bars should be stacked or not.
81
     *
82
     * @returns {Bool}
83
     */
84
    Bar.prototype.getStacked = function() {
85
        return this._stacked;
86
    };
87
 
88
    /**
89
     * Set whether the bars should be displayed horizontally or not.
90
     *
91
     * It sets the X Axis to zero if the min value is null.
92
     *
93
     * @param {Bool} horizontal True if the bars should be displayed horizontally, false otherwise.
94
     */
95
    Bar.prototype.setHorizontal = function(horizontal) {
96
        var axis = this.getXAxis(0, true);
97
        if (axis.getMin() === null) {
98
            axis.setMin(0);
99
        }
100
        this._horizontal = Boolean(horizontal);
101
    };
102
 
103
    /**
104
     * Set whether the bars should be stacked or not.
105
     *
106
     * @method setStacked
107
     * @param {Bool} stacked True if the chart should be stacked or false otherwise.
108
     */
109
    Bar.prototype.setStacked = function(stacked) {
110
        this._stacked = Boolean(stacked);
111
    };
112
 
113
    return Bar;
114
 
115
});