NumericAxis.js revision 2a322140e93579c14e2037ff2eb3e62eaa86c9df
/**
* NumericAxis manages numeric data on an axis.
*
* @module charts
* @class NumericAxis
* @constructor
* @param {Object} config (optional) Configuration parameters for the Chart.
* @extends AxisType
*/
function NumericAxis(config)
{
}
NumericAxis.ATTRS = {
/**
* Indicates whether 0 should always be displayed.
*
* @attribute alwaysShowZero
* @type Boolean
*/
value: true
},
/**
* Method used for formatting a label. This attribute allows for the default label formatting method to overridden. The method use would need
* to implement the arguments below and return a `String`.
* <dl>
* <dt>val</dt><dd>Label to be formatted. (`String`)</dd>
* <dt>format</dt><dd>Object containing properties used to format the label. (optional)</dd>
* </dl>
*
* @attribute labelFunction
* @type Function
*/
{
if(format)
{
}
return val;
}
},
/**
* Object containing properties used by the `labelFunction` to format a
* label.
*
* @attribute labelFormat
* @type Object
*/
labelFormat: {
value: {
prefix: "",
thousandsSeparator: "",
decimalSeparator: "",
decimalPlaces: "0",
suffix: ""
}
}
};
{
/**
* Type of data used in `Axis`.
*
* @property _type
* @readOnly
* @private
*/
_type: "numeric",
/**
* Returns a value based of a key value and an index.
*
* @method getKeyValueAt
* @param {String} key value used to look up the correct array
* @param {Number} index within the array
* @return Object
*/
{
{
}
return value;
},
/**
* Helper method for getting a `roundingUnit` when calculating the minimum and maximum values.
*
* @method _getMinimumUnit
* @param {Number} max Maximum number
* @param {Number} min Minimum number
* @param {Number} units Number of units on the axis
* @return Number
* @private
*/
{
},
/**
* Calculates a nice rounding unit based on the range.
*
* @method _getNiceNumber
* @param {Number} roundingUnit The calculated rounding unit.
* @return Number
* @private
*/
_getNiceNumber: function(roundingUnit)
{
var tempMajorUnit = roundingUnit,
{
}
else
{
}
if(!isNaN(tempMajorUnit))
{
return tempMajorUnit;
}
return roundingUnit;
},
/**
* Calculates the maximum and minimum values for the `Axis`.
*
* @method _updateMinAndMax
* @private
*/
_updateMinAndMax: function()
{
max = 0,
min = 0,
len,
num,
i,
key,
setMax = this._setMaximum,
setMin = this._setMinimum;
{
{
if(len > 1)
{
for(i = 1; i < len; i++)
{
{
{
//hloc values
{
{
}
}
}
continue;
}
}
}
}
}
},
/**
* Rounds the mimimum and maximum values based on the `roundingUnit` attribute.
*
* @method _roundMinAndMax
* @param {Number} min Minimum value
* @param {Number} max Maximum value
* @private
*/
{
var roundingUnit,
if(roundingMethod)
{
if(roundingMethod == "niceNumber")
{
{
{
min = 0;
}
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
}
else
{
{
max = 0;
}
else
{
}
}
}
else if(roundingMethod == "auto")
{
{
{
min = 0;
}
if(useIntegers)
{
}
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
if(alwaysShowZero)
{
if(useIntegers)
{
}
else
{
}
}
else
{
if(useIntegers)
{
}
}
}
else
{
if(useIntegers)
{
}
{
max = 0;
if(useIntegers)
{
Math.ceil(roundingUnit);
}
}
else
{
}
}
}
{
{
{
min = 0;
}
else
{
}
if(!dataRangeGreater)
{
}
else
{
}
}
else if(maxGreaterThanZero && !minGreaterThanZero)
{
if(!dataRangeGreater)
{
}
else
{
}
}
else
{
{
max = 0;
}
else
{
}
if(!dataRangeGreater)
{
}
else
{
}
}
}
}
this._dataMaximum = max;
this._dataMinimum = min;
},
/**
* Calculates and returns a value based on the number of labels and the index of
* the current label.
*
* @method getLabelByIndex
* @param {Number} i Index of the label.
* @param {Number} l Total number of labels.
* @return String
*/
getLabelByIndex: function(i, l)
{
l -= 1;
//respect the min and max. calculate all other labels.
if(i === 0)
{
}
else if(i === l)
{
}
else
{
}
return label;
},
/**
* Rounds a Number to the nearest multiple of an input. For example, by rounding
* 16 to the nearest 10, you will receive 20. Similar to the built-in function Math.round().
*
* @method _roundToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
{
if(nearest === 0)
{
return number;
}
},
/**
* Rounds a Number up to the nearest multiple of an input. For example, by rounding
* 16 up to the nearest 10, you will receive 20. Similar to the built-in function Math.ceil().
*
* @method _roundUpToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
{
if(nearest === 0)
{
return number;
}
},
/**
* Rounds a Number down to the nearest multiple of an input. For example, by rounding
* 16 down to the nearest 10, you will receive 10. Similar to the built-in function Math.floor().
*
* @method _roundDownToNearest
* @param {Number} number Number to round
* @param {Number} nearest Multiple to round towards.
* @return Number
* @private
*/
{
if(nearest === 0)
{
return number;
}
},
/**
* Rounds a number to a certain level of precision. Useful for limiting the number of
* decimal places on a fractional number.
*
* @method _roundToPrecision
* @param {Number} number Number to round
* @param {Number} precision Multiple to round towards.
* @return Number
* @private
*/
{
}
});
Y.NumericAxis = NumericAxis;