|
602
|
1 |
YUI.add('axis-numeric', function (Y, NAME) { |
|
|
2 |
|
|
|
3 |
/** |
|
|
4 |
* Provides functionality for drawing a numeric axis for use with a chart. |
|
|
5 |
* |
|
|
6 |
* @module charts |
|
|
7 |
* @submodule axis-numeric |
|
|
8 |
*/ |
|
|
9 |
var Y_Lang = Y.Lang; |
|
|
10 |
/** |
|
|
11 |
* NumericAxis draws a numeric axis. |
|
|
12 |
* |
|
|
13 |
* @class NumericAxis |
|
|
14 |
* @constructor |
|
|
15 |
* @extends Axis |
|
|
16 |
* @uses NumericImpl |
|
|
17 |
* @param {Object} config (optional) Configuration parameters. |
|
|
18 |
* @submodule axis-numeric |
|
|
19 |
*/ |
|
|
20 |
Y.NumericAxis = Y.Base.create("numericAxis", Y.Axis, [Y.NumericImpl], { |
|
|
21 |
/** |
|
|
22 |
* Calculates and returns a value based on the number of labels and the index of |
|
|
23 |
* the current label. |
|
|
24 |
* |
|
|
25 |
* @method getLabelByIndex |
|
|
26 |
* @param {Number} i Index of the label. |
|
|
27 |
* @param {Number} l Total number of labels. |
|
|
28 |
* @return String |
|
|
29 |
* @private |
|
|
30 |
*/ |
|
|
31 |
_getLabelByIndex: function(i, l) |
|
|
32 |
{ |
|
|
33 |
var min = this.get("minimum"), |
|
|
34 |
max = this.get("maximum"), |
|
|
35 |
increm = (max - min)/(l-1), |
|
|
36 |
label, |
|
|
37 |
roundingMethod = this.get("roundingMethod"); |
|
|
38 |
l -= 1; |
|
|
39 |
//respect the min and max. calculate all other labels. |
|
|
40 |
if(i === 0) |
|
|
41 |
{ |
|
|
42 |
label = min; |
|
|
43 |
} |
|
|
44 |
else if(i === l) |
|
|
45 |
{ |
|
|
46 |
label = max; |
|
|
47 |
} |
|
|
48 |
else |
|
|
49 |
{ |
|
|
50 |
label = (i * increm); |
|
|
51 |
if(roundingMethod === "niceNumber") |
|
|
52 |
{ |
|
|
53 |
label = this._roundToNearest(label, increm); |
|
|
54 |
} |
|
|
55 |
label += min; |
|
|
56 |
} |
|
|
57 |
return parseFloat(label); |
|
|
58 |
}, |
|
|
59 |
|
|
|
60 |
/** |
|
|
61 |
* Returns an object literal containing and array of label values and an array of points. |
|
|
62 |
* |
|
|
63 |
* @method _getLabelData |
|
|
64 |
* @param {Object} startPoint An object containing x and y values. |
|
|
65 |
* @param {Number} edgeOffset Distance to offset coordinates. |
|
|
66 |
* @param {Number} layoutLength Distance that the axis spans. |
|
|
67 |
* @param {Number} count Number of labels. |
|
|
68 |
* @param {String} direction Indicates whether the axis is horizontal or vertical. |
|
|
69 |
* @param {Array} Array containing values for axis labels. |
|
|
70 |
* @return Array |
|
|
71 |
* @private |
|
|
72 |
*/ |
|
|
73 |
_getLabelData: function(constantVal, staticCoord, dynamicCoord, min, max, edgeOffset, layoutLength, count, dataValues) |
|
|
74 |
{ |
|
|
75 |
var dataValue, |
|
|
76 |
i, |
|
|
77 |
points = [], |
|
|
78 |
values = [], |
|
|
79 |
point, |
|
|
80 |
isVertical = staticCoord === "x", |
|
|
81 |
offset = isVertical ? layoutLength + edgeOffset : edgeOffset; |
|
|
82 |
dataValues = dataValues || this._getDataValuesByCount(count, min, max); |
|
|
83 |
for(i = 0; i < count; i = i + 1) |
|
|
84 |
{ |
|
|
85 |
dataValue = parseFloat(dataValues[i]); |
|
|
86 |
if(dataValue <= max && dataValue >= min) |
|
|
87 |
{ |
|
|
88 |
point = {}; |
|
|
89 |
point[staticCoord] = constantVal; |
|
|
90 |
point[dynamicCoord] = this._getCoordFromValue( |
|
|
91 |
min, |
|
|
92 |
max, |
|
|
93 |
layoutLength, |
|
|
94 |
dataValue, |
|
|
95 |
offset, |
|
|
96 |
isVertical |
|
|
97 |
); |
|
|
98 |
points.push(point); |
|
|
99 |
values.push(dataValue); |
|
|
100 |
} |
|
|
101 |
} |
|
|
102 |
return { |
|
|
103 |
points: points, |
|
|
104 |
values: values |
|
|
105 |
}; |
|
|
106 |
}, |
|
|
107 |
|
|
|
108 |
/** |
|
|
109 |
* Checks to see if data extends beyond the range of the axis. If so, |
|
|
110 |
* that data will need to be hidden. This method is internal, temporary and subject |
|
|
111 |
* to removal in the future. |
|
|
112 |
* |
|
|
113 |
* @method _hasDataOverflow |
|
|
114 |
* @protected |
|
|
115 |
* @return Boolean |
|
|
116 |
*/ |
|
|
117 |
_hasDataOverflow: function() |
|
|
118 |
{ |
|
|
119 |
var roundingMethod, |
|
|
120 |
min, |
|
|
121 |
max; |
|
|
122 |
if(this.get("setMin") || this.get("setMax")) |
|
|
123 |
{ |
|
|
124 |
return true; |
|
|
125 |
} |
|
|
126 |
roundingMethod = this.get("roundingMethod"); |
|
|
127 |
min = this._actualMinimum; |
|
|
128 |
max = this._actualMaximum; |
|
|
129 |
if(Y_Lang.isNumber(roundingMethod) && |
|
|
130 |
((Y_Lang.isNumber(max) && max > this._dataMaximum) || (Y_Lang.isNumber(min) && min < this._dataMinimum))) |
|
|
131 |
{ |
|
|
132 |
return true; |
|
|
133 |
} |
|
|
134 |
return false; |
|
|
135 |
} |
|
|
136 |
}); |
|
|
137 |
|
|
|
138 |
|
|
|
139 |
|
|
|
140 |
}, '@VERSION@', {"requires": ["axis", "axis-numeric-base"]}); |