1 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
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
23 define(['core/chart_base'], function(Base) {
28 * @extends {module:core/chart_base}
32 Base.prototype.constructor.apply(this, arguments);
34 Bar.prototype = Object.create(Base.prototype);
37 * Whether the bars should be displayed horizontally or not.
42 Bar.prototype._horizontal = false;
45 * Whether the bars should be stacked or not.
50 Bar.prototype._stacked = false;
53 Bar.prototype.TYPE = 'bar';
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);
64 Bar.prototype._setDefaults = function() {
65 Base.prototype._setDefaults.apply(this, arguments);
66 var axis = this.getYAxis(0, true);
71 * Get whether the bars should be displayed horizontally or not.
75 Bar.prototype.getHorizontal = function() {
76 return this._horizontal;
80 * Get whether the bars should be stacked or not.
84 Bar.prototype.getStacked = function() {
89 * Set whether the bars should be displayed horizontally or not.
91 * It sets the X Axis to zero if the min value is null.
93 * @param {Bool} horizontal True if the bars should be displayed horizontally, false otherwise.
95 Bar.prototype.setHorizontal = function(horizontal) {
96 var axis = this.getXAxis(0, true);
97 if (axis.getMin() === null) {
100 this._horizontal = Boolean(horizontal);
104 * Set whether the bars should be stacked or not.
107 * @param {Bool} stacked True if the chart should be stacked or false otherwise.
109 Bar.prototype.setStacked = function(stacked) {
110 this._stacked = Boolean(stacked);