|
1 YUI.add('axis-stacked-base', function (Y, NAME) { |
|
2 |
|
3 /** |
|
4 * Provides core functionality for the handling of stacked numeric axis data for a chart. |
|
5 * |
|
6 * @module charts |
|
7 * @submodule axis-stacked-base |
|
8 */ |
|
9 |
|
10 /** |
|
11 * StackedImpl contains logic for managing stacked numeric data. StackedImpl is used by the following classes: |
|
12 * <ul> |
|
13 * <li>{{#crossLink "StackedAxisBase"}}{{/crossLink}}</li> |
|
14 * <li>{{#crossLink "StackedAxis"}}{{/crossLink}}</li> |
|
15 * </ul> |
|
16 * |
|
17 * @submodule axis-stacked-base |
|
18 * @class StackedImpl |
|
19 * @constructor |
|
20 */ |
|
21 function StackedImpl() |
|
22 { |
|
23 } |
|
24 |
|
25 StackedImpl.NAME = "stackedImpl"; |
|
26 |
|
27 StackedImpl.prototype = { |
|
28 /** |
|
29 * Type of data used in `Data`. |
|
30 * |
|
31 * @property _type |
|
32 * @readOnly |
|
33 * @private |
|
34 */ |
|
35 _type: "stacked", |
|
36 |
|
37 /** |
|
38 * Calculates the maximum and minimum values for the `Data`. |
|
39 * |
|
40 * @method _updateMinAndMax |
|
41 * @private |
|
42 */ |
|
43 _updateMinAndMax: function() |
|
44 { |
|
45 var max = 0, |
|
46 min = 0, |
|
47 pos = 0, |
|
48 neg = 0, |
|
49 len = 0, |
|
50 i = 0, |
|
51 key, |
|
52 num, |
|
53 keys = this.get("keys"), |
|
54 setMin = this.get("setMin"), |
|
55 setMax = this.get("setMax"); |
|
56 |
|
57 for(key in keys) |
|
58 { |
|
59 if(keys.hasOwnProperty(key)) |
|
60 { |
|
61 len = Math.max(len, keys[key].length); |
|
62 } |
|
63 } |
|
64 for(; i < len; ++i) |
|
65 { |
|
66 pos = 0; |
|
67 neg = 0; |
|
68 for(key in keys) |
|
69 { |
|
70 if(keys.hasOwnProperty(key)) |
|
71 { |
|
72 num = keys[key][i]; |
|
73 if(isNaN(num)) |
|
74 { |
|
75 continue; |
|
76 } |
|
77 if(num >= 0) |
|
78 { |
|
79 pos += num; |
|
80 } |
|
81 else |
|
82 { |
|
83 neg += num; |
|
84 } |
|
85 } |
|
86 } |
|
87 if(pos > 0) |
|
88 { |
|
89 max = Math.max(max, pos); |
|
90 } |
|
91 else |
|
92 { |
|
93 max = Math.max(max, neg); |
|
94 } |
|
95 if(neg < 0) |
|
96 { |
|
97 min = Math.min(min, neg); |
|
98 } |
|
99 else |
|
100 { |
|
101 min = Math.min(min, pos); |
|
102 } |
|
103 } |
|
104 this._actualMaximum = max; |
|
105 this._actualMinimum = min; |
|
106 if(setMax) |
|
107 { |
|
108 max = this._setMaximum; |
|
109 } |
|
110 if(setMin) |
|
111 { |
|
112 min = this._setMinimum; |
|
113 } |
|
114 this._roundMinAndMax(min, max, setMin, setMax); |
|
115 } |
|
116 }; |
|
117 |
|
118 Y.StackedImpl = StackedImpl; |
|
119 |
|
120 /** |
|
121 * StackedAxisBase manages stacked numeric data for an axis. |
|
122 * |
|
123 * @class StackedAxisBase |
|
124 * @constructor |
|
125 * @extends AxisBase |
|
126 * @uses StackedImpl |
|
127 * @param {Object} config (optional) Configuration parameters. |
|
128 * @submodule axis-stacked-base |
|
129 */ |
|
130 Y.StackedAxisBase = Y.Base.create("stackedAxisBase", Y.NumericAxisBase, [Y.StackedImpl]); |
|
131 |
|
132 |
|
133 }, '@VERSION@', {"requires": ["axis-numeric-base"]}); |