2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('axis-time-base', function (Y, NAME) {
11 * Provides functionality for the handling of time axis data for a chart.
14 * @submodule axis-time-base
19 * TimeImpl contains logic for time data. TimeImpl is used by the following classes:
21 * <li>{{#crossLink "TimeAxisBase"}}{{/crossLink}}</li>
22 * <li>{{#crossLink "TimeAxis"}}{{/crossLink}}</li>
27 * @submodule axis-time-base
33 TimeImpl.NAME = "timeImpl";
38 * Method used for formatting a label. This attribute allows for the default label formatting method to overridden.
39 * The method use would need to implement the arguments below and return a `String` or an `HTMLElement`. The default
40 * implementation of the method returns a `String`. The output of this method will be rendered to the DOM using
41 * `appendChild`. If you override the `labelFunction` method and return an html string, you will also need to override
42 * the Axis' `appendLabelFunction` to accept html as a `String`.
44 * <dt>val</dt><dd>Label to be formatted. (`String`)</dd>
45 * <dt>format</dt><dd>STRFTime string used to format the label. (optional)</dd>
48 * @attribute labelFunction
53 * Pattern used by the `labelFunction` to format a label.
55 * @attribute labelFormat
63 TimeImpl.prototype = {
65 * Type of data used in `Data`.
74 * Getter method for maximum attribute.
76 * @method _maximumGetter
80 _maximumGetter: function ()
82 var max = this._getNumber(this._setMaximum);
83 if(!Y_Lang.isNumber(max))
85 max = this._getNumber(this.get("dataMaximum"));
87 return parseFloat(max);
91 * Setter method for maximum attribute.
93 * @method _maximumSetter
94 * @param {Object} value
97 _maximumSetter: function (value)
99 this._setMaximum = this._getNumber(value);
104 * Getter method for minimum attribute.
106 * @method _minimumGetter
110 _minimumGetter: function ()
112 var min = this._getNumber(this._setMinimum);
113 if(!Y_Lang.isNumber(min))
115 min = this._getNumber(this.get("dataMinimum"));
117 return parseFloat(min);
121 * Setter method for minimum attribute.
123 * @method _minimumSetter
124 * @param {Object} value
127 _minimumSetter: function (value)
129 this._setMinimum = this._getNumber(value);
134 * Indicates whether or not the maximum attribute has been explicitly set.
140 _getSetMax: function()
142 var max = this._getNumber(this._setMaximum);
143 return (Y_Lang.isNumber(max));
147 * Indicates whether or not the minimum attribute has been explicitly set.
153 _getSetMin: function()
155 var min = this._getNumber(this._setMinimum);
156 return (Y_Lang.isNumber(min));
160 * Formats a label based on the axis type and optionally specified format.
162 * @method formatLabel
163 * @param {Object} value
164 * @param {Object} format Pattern used to format the value.
167 formatLabel: function(val, format)
169 val = Y.DataType.Date.parse(val);
172 return Y.DataType.Date.format(val, {format:format});
178 * Constant used to generate unique id.
187 * Type of data used in `Axis`.
189 * @property _dataType
196 * Gets an array of values based on a key.
198 * @method _getKeyArray
199 * @param {String} key Value key associated with the data array.
200 * @param {Array} data Array in which the data resides.
204 _getKeyArray: function(key, data)
214 if(Y_Lang.isDate(obj))
221 if(Y_Lang.isDate(val))
225 else if(!Y_Lang.isNumber(obj))
227 if(Y_Lang.isNumber(parseFloat(obj)))
229 val = parseFloat(obj);
233 if(typeof obj !== "string")
237 val = new Date(obj).valueOf();
251 * Calculates the maximum and minimum values for the `Axis`.
253 * @method _updateMinAndMax
256 _updateMinAndMax: function()
258 var data = this.get("data"),
264 if(data && data.length && data.length > 0)
270 for(i = 1; i < len; i++)
277 max = Math.max(num, max);
278 min = Math.min(num, min);
282 this._dataMaximum = max;
283 this._dataMinimum = min;
287 * Returns a coordinate corresponding to a data values.
289 * @method _getCoordFromValue
290 * @param {Number} min The minimum for the axis.
291 * @param {Number} max The maximum for the axis.
292 * @param {length} length The distance that the axis spans.
293 * @param {Number} dataValue A value used to ascertain the coordinate.
294 * @param {Number} offset Value in which to offset the coordinates.
295 * @param {Boolean} reverse Indicates whether the coordinates should start from
296 * the end of an axis. Only used in the numeric implementation.
300 _getCoordFromValue: function(min, max, length, dataValue, offset)
305 isNumber = Y_Lang.isNumber;
306 dataValue = this._getNumber(dataValue);
307 if(isNumber(dataValue))
310 multiplier = length/range;
311 valuecoord = (dataValue - min) * multiplier;
312 valuecoord = offset + valuecoord;
322 * Parses value into a number.
325 * @param val {Object} Value to parse into a number
329 _getNumber: function(val)
331 if(Y_Lang.isDate(val))
335 else if(!Y_Lang.isNumber(val) && val)
337 val = new Date(val).valueOf();
344 Y.TimeImpl = TimeImpl;
347 * TimeAxisBase manages time data for an axis.
349 * @class TimeAxisBase
353 * @param {Object} config (optional) Configuration parameters.
354 * @submodule axis-time-base
356 Y.TimeAxisBase = Y.Base.create("timeAxisBase", Y.AxisBase, [Y.TimeImpl]);
359 }, '3.13.0', {"requires": ["axis-base"]});