JAVASCRIPT   76

axis-time

Guest on 7th May 2022 02:22:22 AM

  1. /*
  2. YUI 3.17.2 (build 9c3c78e)
  3. Copyright Yahoo! Inc. All rights reserved.
  4. Licensed under the BSD License.
  5. http://yuilibrary.com/license/
  6. */
  7.  
  8. YUI.add('axis-time', function (Y, NAME) {
  9.  
  10. /**
  11.  * Provides functionality for drawing a time axis for use with a chart.
  12.  *
  13.  * @module charts
  14.  * @submodule axis-time
  15.  */
  16. /**
  17.  * TimeAxis draws a time-based axis for a chart.
  18.  *
  19.  * @class TimeAxis
  20.  * @constructor
  21.  * @extends Axis
  22.  * @uses TimeImpl
  23.  * @param {Object} config (optional) Configuration parameters.
  24.  * @submodule axis-time
  25.  */
  26. Y.TimeAxis = Y.Base.create("timeAxis", Y.Axis, [Y.TimeImpl], {
  27.     /**
  28.      * Calculates and returns a value based on the number of labels and the index of
  29.      * the current label.
  30.      *
  31.      * @method _getLabelByIndex
  32.      * @param {Number} i Index of the label.
  33.      * @param {Number} l Total number of labels.
  34.      * @return String
  35.      * @private
  36.      */
  37.     _getLabelByIndex: function(i, l)
  38.     {
  39.         var min = this.get("minimum"),
  40.             max = this.get("maximum"),
  41.             increm,
  42.             label;
  43.             l -= 1;
  44.         increm = ((max - min)/l) * i;
  45.         label = min + increm;
  46.         return label;
  47.     },
  48.  
  49.     /**
  50.      * Returns an object literal containing and array of label values and an array of points.
  51.      *
  52.      * @method _getLabelData
  53.      * @param {Object} startPoint An object containing x and y values.
  54.      * @param {Number} edgeOffset Distance to offset coordinates.
  55.      * @param {Number} layoutLength Distance that the axis spans.
  56.      * @param {Number} count Number of labels.
  57.      * @param {String} direction Indicates whether the axis is horizontal or vertical.
  58.      * @param {Array} Array containing values for axis labels.
  59.      * @return Array
  60.      * @private
  61.      */
  62.     _getLabelData: function(constantVal, staticCoord, dynamicCoord, min, max, edgeOffset, layoutLength, count, dataValues)
  63.     {
  64.         var dataValue,
  65.             i,
  66.             points = [],
  67.             values = [],
  68.             point,
  69.             offset = edgeOffset;
  70.         dataValues = dataValues || this._getDataValuesByCount(count, min, max);
  71.         for(i = 0; i < count; i = i + 1)
  72.         {
  73.             dataValue = this._getNumber(dataValues[i]);
  74.             if(dataValue <= max && dataValue >= min)
  75.             {
  76.                 point = {};
  77.                 point[staticCoord] = constantVal;
  78.                 point[dynamicCoord] = this._getCoordFromValue(
  79.                     min,
  80.                     max,
  81.                     layoutLength,
  82.                     dataValue,
  83.                     offset
  84.                 );
  85.                 points.push(point);
  86.                 values.push(dataValue);
  87.             }
  88.         }
  89.         return {
  90.             points: points,
  91.             values: values
  92.         };
  93.     }
  94. });
  95.  
  96.  
  97.  
  98. }, '3.17.2', {"requires": ["axis", "axis-time-base"]});

Raw Paste


Login or Register to edit or fork this paste. It's free.