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-category-base', function (Y, NAME) {
11 * Provides functionality for the handling of category axis data for a chart.
14 * @submodule axis-category-base
19 * CategoryImpl contains logic for managing category data. CategoryImpl is used by the following classes:
21 * <li>{{#crossLink "CategoryAxisBase"}}{{/crossLink}}</li>
22 * <li>{{#crossLink "CategoryAxis"}}{{/crossLink}}</li>
27 * @submodule axis-category-base
29 function CategoryImpl()
33 CategoryImpl.NAME = "categoryImpl";
35 CategoryImpl.ATTRS = {
37 * Determines whether and offset is automatically calculated for the edges of the axis.
39 * @attribute calculateEdgeOffset
42 calculateEdgeOffset: {
47 * Method used for formatting a label. This attribute allows for the default label formatting method to overridden.
48 * The method use would need to implement the arguments below and return a `String` or `HTMLElement`.
50 * <dt>val</dt><dd>Label to be formatted. (`String`)</dd>
51 * <dt>format</dt><dd>Template for formatting label. (optional)</dd>
54 * @attribute labelFunction
59 CategoryImpl.prototype = {
61 * Formats a label based on the axis type and optionally specified format.
64 * @param {Object} value
67 formatLabel: function(val)
73 * Object storing key data.
81 * Constant used to generate unique id.
87 GUID: "yuicategoryaxis",
90 * Type of data used in `Data`.
99 * Calculates the maximum and minimum values for the `Data`.
101 * @method _updateMinAndMax
104 _updateMinAndMax: function()
106 this._dataMaximum = Math.max(this.get("data").length - 1, 0);
107 this._dataMinimum = 0;
111 * Gets an array of values based on a key.
113 * @method _getKeyArray
114 * @param {String} key Value key associated with the data array.
115 * @param {Array} data Array in which the data resides.
119 _getKeyArray: function(key, data)
134 labels[i] = obj[key];
136 this._indices[key] = keyArr;
141 * Returns an array of values based on an identifier key.
143 * @method getDataByKey
144 * @param {String} value value used to identify the array
147 getDataByKey: function (value)
153 var keys = this._indices;
154 if(keys && keys[value])
162 * Returns the total number of majorUnits that will appear on an axis.
164 * @method getTotalMajorUnits
165 * @param {Object} majorUnit Object containing properties related to the majorUnit.
166 * @param {Number} len Length of the axis.
169 getTotalMajorUnits: function()
171 return this.get("data").length;
175 * Returns a coordinate corresponding to a data values.
177 * @method _getCoordFromValue
178 * @param {Number} min The minimum for the axis.
179 * @param {Number} max The maximum for the axis.
180 * @param {length} length The distance that the axis spans.
181 * @param {Number} dataValue A value used to ascertain the coordinate.
182 * @param {Number} offset Value in which to offset the coordinates.
183 * @param {Boolean} reverse Indicates whether the coordinates should start from
184 * the end of an axis. Only used in the numeric implementation.
188 _getCoordFromValue: function(min, max, length, dataValue, offset)
193 if(Y_Lang.isNumber(dataValue))
196 multiplier = length/range;
197 valuecoord = (dataValue - min) * multiplier;
198 valuecoord = offset + valuecoord;
208 * Returns a value based of a key value and an index.
210 * @method getKeyValueAt
211 * @param {String} key value used to look up the correct array
212 * @param {Number} index within the array
215 getKeyValueAt: function(key, index)
218 keys = this.get("keys");
219 if(keys[key] && keys[key][index])
221 value = keys[key][index];
227 Y.CategoryImpl = CategoryImpl;
230 * CategoryAxisBase manages category data for an axis.
232 * @class CategoryAxisBase
236 * @param {Object} config (optional) Configuration parameters.
237 * @submodule axis-category-base
239 Y.CategoryAxisBase = Y.Base.create("categoryAxisBase", Y.AxisBase, [Y.CategoryImpl]);
242 }, '3.13.0', {"requires": ["axis-base"]});