src/cm/media/js/lib/yui/yui_3.10.3/build/axis-time/axis-time-debug.js
changeset 525 89ef5ed3c48b
equal deleted inserted replaced
524:322d0feea350 525:89ef5ed3c48b
       
     1 /*
       
     2 YUI 3.10.3 (build 2fb5187)
       
     3 Copyright 2013 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      * Calculates the position of ticks and labels based on an array of specified label values. Returns
       
    51      * an object containing an array of values to be used for labels and an array of objects containing
       
    52      * x and y coordinates for each label.
       
    53      *
       
    54      * @method _getDataFromLabelValues
       
    55      * @param {Object} startPoint An object containing the x and y coordinates for the start of the axis.
       
    56      * @param {Array} labelValues An array containing values to be used for determining the number and
       
    57      * position of labels and ticks on the axis.
       
    58      * @param {Number} edgeOffset The distance, in pixels, on either edge of the axis.
       
    59      * @param {Number} layoutLength The length, in pixels, of the axis. If the axis is vertical, the length
       
    60      * is equal to the height. If the axis is horizontal, the length is equal to the width.
       
    61      * @return Object
       
    62      * @private
       
    63      */
       
    64     _getDataFromLabelValues: function(startPoint, labelValues, edgeOffset, layoutLength, direction)
       
    65     {
       
    66         var points = [],
       
    67             labelValue,
       
    68             i,
       
    69             len = labelValues.length,
       
    70             staticCoord,
       
    71             dynamicCoord,
       
    72             constantVal,
       
    73             newPoint,
       
    74             max = this.get("maximum"),
       
    75             min = this.get("minimum"),
       
    76             values = [],
       
    77             scaleFactor = (layoutLength - (edgeOffset * 2)) / (max - min);
       
    78         if(direction === "vertical")
       
    79         {
       
    80             staticCoord = "x";
       
    81             dynamicCoord = "y";
       
    82         }
       
    83         else
       
    84         {
       
    85             staticCoord = "y";
       
    86             dynamicCoord = "x";
       
    87         }
       
    88         constantVal = startPoint[staticCoord];
       
    89         for(i = 0; i < len; i = i + 1)
       
    90         {
       
    91             labelValue = this._getNumber(labelValues[i]);
       
    92             if(Y.Lang.isNumber(labelValue) && labelValue >= min && labelValue <= max)
       
    93             {
       
    94                 newPoint = {};
       
    95                 newPoint[staticCoord] = constantVal;
       
    96                 newPoint[dynamicCoord] = edgeOffset + ((labelValue - min) * scaleFactor);
       
    97                 points.push(newPoint);
       
    98                 values.push(labelValue);
       
    99             }
       
   100         }
       
   101         return {
       
   102             points: points,
       
   103             values: values
       
   104         };
       
   105     }
       
   106 });
       
   107 
       
   108 
       
   109 
       
   110 }, '3.10.3', {"requires": ["axis", "axis-time-base"]});