[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/axis-category-base/ -> axis-category-base.js (source)

   1  /*
   2  YUI 3.17.2 (build 9c3c78e)
   3  Copyright 2014 Yahoo! Inc. All rights reserved.
   4  Licensed under the BSD License.
   5  http://yuilibrary.com/license/
   6  */
   7  
   8  YUI.add('axis-category-base', function (Y, NAME) {
   9  
  10  /**
  11   * Provides functionality for the handling of category axis data for a chart.
  12   *
  13   * @module charts
  14   * @submodule axis-category-base
  15   */
  16  var Y_Lang = Y.Lang;
  17  
  18  /**
  19   * CategoryImpl contains logic for managing category data. CategoryImpl is used by the following classes:
  20   * <ul>
  21   *      <li>{{#crossLink "CategoryAxisBase"}}{{/crossLink}}</li>
  22   *      <li>{{#crossLink "CategoryAxis"}}{{/crossLink}}</li>
  23   *  </ul>
  24   *
  25   * @class CategoryImpl
  26   * @constructor
  27   * @submodule axis-category-base
  28   */
  29  function CategoryImpl()
  30  {
  31  }
  32  
  33  CategoryImpl.NAME = "categoryImpl";
  34  
  35  CategoryImpl.ATTRS = {
  36      /**
  37       * Pattern used by the `labelFunction` to format a label. The default `labelFunction` values for
  38       * `CategoryAxis` and `CategoryAxisBase` do not accept a format object. This value can be used by
  39       * a custom method.
  40       *
  41       * @attribute labelFormat
  42       * @type Object
  43       */
  44      labelFormat: {
  45          value: null
  46      },
  47  
  48      /**
  49       * Determines whether and offset is automatically calculated for the edges of the axis.
  50       *
  51       * @attribute calculateEdgeOffset
  52       * @type Boolean
  53       */
  54      calculateEdgeOffset: {
  55          value: true
  56      }
  57  
  58      /**
  59       * Method used for formatting a label. This attribute allows for the default label formatting method to overridden.
  60       * The method use would need to implement the arguments below and return a `String` or `HTMLElement`.
  61       * <dl>
  62       *      <dt>val</dt><dd>Label to be formatted. (`String`)</dd>
  63       *      <dt>format</dt><dd>Template for formatting label. (optional)</dd>
  64       * </dl>
  65       *
  66       * @attribute labelFunction
  67       * @type Function
  68       */
  69  };
  70  
  71  CategoryImpl.prototype = {
  72      /**
  73       * Formats a label based on the axis type and optionally specified format.
  74       *
  75       * @method formatLabel
  76       * @param {Object} value
  77       * @return String
  78       */
  79      formatLabel: function(val)
  80      {
  81          return val;
  82      },
  83  
  84      /**
  85       * Object storing key data.
  86       *
  87       * @property _indices
  88       * @private
  89       */
  90      _indices: null,
  91  
  92      /**
  93       * Constant used to generate unique id.
  94       *
  95       * @property GUID
  96       * @type String
  97       * @private
  98       */
  99      GUID: "yuicategoryaxis",
 100  
 101      /**
 102       * Type of data used in `Data`.
 103       *
 104       * @property _dataType
 105       * @readOnly
 106       * @private
 107       */
 108      _type: "category",
 109  
 110      /**
 111       * Calculates the maximum and minimum values for the `Data`.
 112       *
 113       * @method _updateMinAndMax
 114       * @private
 115       */
 116      _updateMinAndMax: function()
 117      {
 118          this._dataMaximum = Math.max(this.get("data").length - 1, 0);
 119          this._dataMinimum = 0;
 120      },
 121  
 122      /**
 123       * Gets an array of values based on a key.
 124       *
 125       * @method _getKeyArray
 126       * @param {String} key Value key associated with the data array.
 127       * @param {Array} data Array in which the data resides.
 128       * @return Array
 129       * @private
 130       */
 131      _getKeyArray: function(key, data)
 132      {
 133          var i = 0,
 134              obj,
 135              keyArr = [],
 136              labels = [],
 137              len = data.length;
 138          if(!this._indices)
 139          {
 140              this._indices = {};
 141          }
 142          for(; i < len; ++i)
 143          {
 144              obj = data[i];
 145              keyArr[i] = i;
 146              labels[i] = obj[key];
 147          }
 148          this._indices[key] = keyArr;
 149          return labels;
 150      },
 151  
 152      /**
 153       * Returns an array of values based on an identifier key.
 154       *
 155       * @method getDataByKey
 156       * @param {String} value value used to identify the array
 157       * @return Array
 158       */
 159      getDataByKey: function (value)
 160      {
 161          if(!this._indices)
 162          {
 163              this.get("keys");
 164          }
 165          var keys = this._indices;
 166          if(keys && keys[value])
 167          {
 168              return keys[value];
 169          }
 170          return null;
 171      },
 172  
 173      /**
 174       * Returns the total number of majorUnits that will appear on an axis.
 175       *
 176       * @method getTotalMajorUnits
 177       * @param {Object} majorUnit Object containing properties related to the majorUnit.
 178       * @param {Number} len Length of the axis.
 179       * @return Number
 180       */
 181      getTotalMajorUnits: function()
 182      {
 183          return this.get("data").length;
 184      },
 185  
 186      /**
 187       * Returns a coordinate corresponding to a data values.
 188       *
 189       * @method _getCoordFromValue
 190       * @param {Number} min The minimum for the axis.
 191       * @param {Number} max The maximum for the axis.
 192       * @param {Number} length The distance that the axis spans.
 193       * @param {Number} dataValue A value used to ascertain the coordinate.
 194       * @param {Number} offset Value in which to offset the coordinates.
 195       * @param {Boolean} reverse Indicates whether the coordinates should start from
 196       * the end of an axis. Only used in the numeric implementation.
 197       * @return Number
 198       * @private
 199       */
 200      _getCoordFromValue: function(min, max, length, dataValue, offset)
 201      {
 202          var range,
 203              multiplier,
 204              valuecoord;
 205          if(Y_Lang.isNumber(dataValue))
 206          {
 207              range = max - min;
 208              multiplier = length/range;
 209              valuecoord = (dataValue - min) * multiplier;
 210              valuecoord = offset + valuecoord;
 211          }
 212          else
 213          {
 214              valuecoord = NaN;
 215          }
 216          return valuecoord;
 217      },
 218  
 219      /**
 220       * Returns a value based of a key value and an index.
 221       *
 222       * @method getKeyValueAt
 223       * @param {String} key value used to look up the correct array
 224       * @param {Number} index within the array
 225       * @return String
 226       */
 227      getKeyValueAt: function(key, index)
 228      {
 229          var value = NaN,
 230              keys = this.get("keys");
 231          if(keys[key] && keys[key][index])
 232          {
 233              value = keys[key][index];
 234          }
 235          return value;
 236      }
 237  };
 238  
 239  Y.CategoryImpl = CategoryImpl;
 240  
 241  /**
 242   * CategoryAxisBase manages category data for an axis.
 243   *
 244   * @class CategoryAxisBase
 245   * @constructor
 246   * @extends AxisBase
 247   * @uses CategoryImpl
 248   * @param {Object} config (optional) Configuration parameters.
 249   * @submodule axis-category-base
 250   */
 251  Y.CategoryAxisBase = Y.Base.create("categoryAxisBase", Y.AxisBase, [Y.CategoryImpl]);
 252  
 253  
 254  }, '3.17.2', {"requires": ["axis-base"]});


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