[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/axis-numeric/ -> axis-numeric.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-numeric', function (Y, NAME) {
   9  
  10  /**
  11   * Provides functionality for drawing a numeric axis for use with a chart.
  12   *
  13   * @module charts
  14   * @submodule axis-numeric
  15   */
  16  var Y_Lang = Y.Lang;
  17  /**
  18   * NumericAxis draws a numeric axis.
  19   *
  20   * @class NumericAxis
  21   * @constructor
  22   * @extends Axis
  23   * @uses NumericImpl
  24   * @param {Object} config (optional) Configuration parameters.
  25   * @submodule axis-numeric
  26   */
  27  Y.NumericAxis = Y.Base.create("numericAxis", Y.Axis, [Y.NumericImpl], {
  28      /**
  29       * Calculates and returns a value based on the number of labels and the index of
  30       * the current label.
  31       *
  32       * @method getLabelByIndex
  33       * @param {Number} i Index of the label.
  34       * @param {Number} l Total number of labels.
  35       * @return String
  36       * @private
  37       */
  38      _getLabelByIndex: function(i, l)
  39      {
  40          var min = this.get("minimum"),
  41              max = this.get("maximum"),
  42              increm = (max - min)/(l-1),
  43              label,
  44              roundingMethod = this.get("roundingMethod");
  45              l -= 1;
  46          //respect the min and max. calculate all other labels.
  47          if(i === 0)
  48          {
  49              label = min;
  50          }
  51          else if(i === l)
  52          {
  53              label = max;
  54          }
  55          else
  56          {
  57              label = (i * increm);
  58              if(roundingMethod === "niceNumber")
  59              {
  60                  label = this._roundToNearest(label, increm);
  61              }
  62              label += min;
  63          }
  64          return parseFloat(label);
  65      },
  66  
  67      /**
  68       * Returns an object literal containing and array of label values and an array of points.
  69       *
  70       * @method _getLabelData
  71       * @param {Object} startPoint An object containing x and y values.
  72       * @param {Number} edgeOffset Distance to offset coordinates.
  73       * @param {Number} layoutLength Distance that the axis spans.
  74       * @param {Number} count Number of labels.
  75       * @param {String} direction Indicates whether the axis is horizontal or vertical.
  76       * @param {Array} Array containing values for axis labels.
  77       * @return Array
  78       * @private
  79       */
  80      _getLabelData: function(constantVal, staticCoord, dynamicCoord, min, max, edgeOffset, layoutLength, count, dataValues)
  81      {
  82          var dataValue,
  83              i,
  84              points = [],
  85              values = [],
  86              point,
  87              isVertical = staticCoord === "x",
  88              offset = isVertical ? layoutLength + edgeOffset : edgeOffset;
  89          dataValues = dataValues || this._getDataValuesByCount(count, min, max);
  90          for(i = 0; i < count; i = i + 1)
  91          {
  92              dataValue = parseFloat(dataValues[i]);
  93              if(dataValue <= max && dataValue >= min)
  94              {
  95                  point = {};
  96                  point[staticCoord] = constantVal;
  97                  point[dynamicCoord] = this._getCoordFromValue(
  98                      min,
  99                      max,
 100                      layoutLength,
 101                      dataValue,
 102                      offset,
 103                      isVertical
 104                  );
 105                  points.push(point);
 106                  values.push(dataValue);
 107              }
 108          }
 109          return {
 110              points: points,
 111              values: values
 112          };
 113      },
 114  
 115      /**
 116       * Checks to see if data extends beyond the range of the axis. If so,
 117       * that data will need to be hidden. This method is internal, temporary and subject
 118       * to removal in the future.
 119       *
 120       * @method _hasDataOverflow
 121       * @protected
 122       * @return Boolean
 123       */
 124      _hasDataOverflow: function()
 125      {
 126          var roundingMethod,
 127              min,
 128              max;
 129          if(this.get("setMin") || this.get("setMax"))
 130          {
 131              return true;
 132          }
 133          roundingMethod = this.get("roundingMethod");
 134          min = this._actualMinimum;
 135          max = this._actualMaximum;
 136          if(Y_Lang.isNumber(roundingMethod) &&
 137              ((Y_Lang.isNumber(max) && max > this._dataMaximum) || (Y_Lang.isNumber(min) && min < this._dataMinimum)))
 138          {
 139              return true;
 140          }
 141          return false;
 142      }
 143  });
 144  
 145  
 146  
 147  }, '3.17.2', {"requires": ["axis", "axis-numeric-base"]});


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