[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/amd/src/ -> chart_pie.js (source)

   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 pie.
  18   *
  19   * @package    core
  20   * @copyright  2016 Frédéric Massart - FMCorz.net
  21   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   * @module     core/chart_pie
  23   */
  24  define(['core/chart_base'], function(Base) {
  25  
  26      /**
  27       * Pie chart.
  28       *
  29       * @class
  30       * @alias module:core/chart_pie
  31       * @extends {module:core/chart_base}
  32       */
  33      function Pie() {
  34          Base.prototype.constructor.apply(this, arguments);
  35      }
  36      Pie.prototype = Object.create(Base.prototype);
  37  
  38      /** @override */
  39      Pie.prototype.TYPE = 'pie';
  40  
  41      /**
  42       * Overridden to add appropriate colors to the series.
  43       *
  44       * @override
  45       */
  46      Pie.prototype.addSeries = function(series) {
  47          if (series.getColor() === null) {
  48              var colors = [];
  49              for (var i = 0; i < series.getCount(); i++) {
  50                  colors.push(this.COLORSET[i % Base.prototype.COLORSET.length]);
  51              }
  52              series.setColors(colors);
  53          }
  54          return Base.prototype.addSeries.apply(this, arguments);
  55      };
  56  
  57      /**
  58       * Validate a series.
  59       *
  60       * Overrides parent implementation to validate that there is only
  61       * one series per chart instance.
  62       *
  63       * @override
  64       */
  65      Pie.prototype._validateSeries = function() {
  66          if (this._series.length >= 1) {
  67              throw new Error('Pie charts only support one serie.');
  68          }
  69          return Base.prototype._validateSeries.apply(this, arguments);
  70      };
  71  
  72      return Pie;
  73  
  74  });


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1