|
1 YUI.add('series-ohlc', function (Y, NAME) { |
|
2 |
|
3 /** |
|
4 * Provides functionality for creating a ohlc series. |
|
5 * |
|
6 * @module charts |
|
7 * @submodule series-ohlc |
|
8 */ |
|
9 /** |
|
10 * The OHLCSeries class renders lines representing the open, high, low and close |
|
11 * values for a chart. |
|
12 * |
|
13 * @class OHLCSeries |
|
14 * @extends RangeSeries |
|
15 * @constructor |
|
16 * @param {Object} config (optional) Configuration parameters. |
|
17 * @submodule series-ohlc |
|
18 */ |
|
19 function OHLCSeries() |
|
20 { |
|
21 OHLCSeries.superclass.constructor.apply(this, arguments); |
|
22 } |
|
23 |
|
24 OHLCSeries.NAME = "ohlcSeries"; |
|
25 |
|
26 OHLCSeries.ATTRS = { |
|
27 /** |
|
28 * Read-only attribute indicating the type of series. |
|
29 * |
|
30 * @attribute type |
|
31 * @type String |
|
32 * @readOnly |
|
33 * @default ohlc |
|
34 */ |
|
35 type: { |
|
36 value: "ohlc" |
|
37 }, |
|
38 |
|
39 /** |
|
40 * The graphic in which drawings will be rendered. |
|
41 * |
|
42 * @attribute graphic |
|
43 * @type Graphic |
|
44 */ |
|
45 graphic: { |
|
46 lazyAdd: false, |
|
47 |
|
48 setter: function(val) { |
|
49 //woraround for Attribute order of operations bug |
|
50 if(!this.get("rendered")) { |
|
51 this.set("rendered", true); |
|
52 } |
|
53 this.set("upmarker", val.addShape({ |
|
54 type: "path" |
|
55 })); |
|
56 this.set("downmarker", val.addShape({ |
|
57 type: "path" |
|
58 })); |
|
59 return val; |
|
60 } |
|
61 }, |
|
62 |
|
63 upmarker: {}, |
|
64 |
|
65 downmarker: {} |
|
66 |
|
67 /** |
|
68 * Style properties used for drawing markers. This attribute is inherited from `RangeSeries`. Below are the default values: |
|
69 * <dl> |
|
70 * <dt>upmarker</dt><dd>Properties for a marker representing a period that closes higher than it opens. |
|
71 * <dl> |
|
72 * <dt>fill</dt><dd>A hash containing the following values: |
|
73 * <dl> |
|
74 * <dt>color</dt><dd>Color of the fill. The default value is "#00aa00".</dd> |
|
75 * </dd> |
|
76 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker fill. The default value is 1.</dd> |
|
77 * </dl> |
|
78 * </dd> |
|
79 * <dt>border</dt><dd>A hash containing the following values: |
|
80 * <dl> |
|
81 * <dt>color</dt><dd>Color of the border. The default value is "#000000".</dd> |
|
82 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker border. The default value is 1.</dd> |
|
83 * <dt>weight</dt><dd>Number indicating the width of the border. The default value is 0.</dd> |
|
84 * </dl> |
|
85 * </dd> |
|
86 * </dl> |
|
87 * </dd> |
|
88 * <dt>downmarker</dt><dd>Properties for a marker representing a period that opens higher than it closes. |
|
89 * <dl> |
|
90 * <dt>fill</dt><dd>A hash containing the following values: |
|
91 * <dl> |
|
92 * <dt>color</dt><dd>Color of the fill. The default value is "#aa0000".</dd> |
|
93 * </dd> |
|
94 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker fill. The default value is 1.</dd> |
|
95 * </dl> |
|
96 * </dd> |
|
97 * <dt>border</dt><dd>A hash containing the following values: |
|
98 * <dl> |
|
99 * <dt>color</dt><dd>Color of the border. The default value is "#000000".</dd> |
|
100 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker border. The default value is 1.</dd> |
|
101 * <dt>weight</dt><dd>Number indicating the width of the border. The default value is 0.</dd> |
|
102 * </dl> |
|
103 * </dd> |
|
104 * </dl> |
|
105 * </dd> |
|
106 * </dl> |
|
107 * |
|
108 * @attribute styles |
|
109 * @type Object |
|
110 */ |
|
111 }; |
|
112 |
|
113 Y.extend(OHLCSeries, Y.RangeSeries, { |
|
114 /** |
|
115 * Draws markers for an OHLC series. |
|
116 * |
|
117 * @method |
|
118 * @param {Array} xcoords The xcoordinates to be plotted. |
|
119 * @param {Array} opencoords The coordinates representing the open values. |
|
120 * @param {Array} highcoords The coordinates representing the high values. |
|
121 * @param {Array} lowcoords The coordinates representing the low values. |
|
122 * @param {Array} closecoords The coordinates representing the close values. |
|
123 * @param {Number} len The number of x coordinates to plot. |
|
124 * @param {Number} width The width of each ohlc marker. |
|
125 * @param {Number} halfwidth Half the width of each ohlc marker. |
|
126 * @param {Object} styles The styles for the series. |
|
127 * @private |
|
128 */ |
|
129 _drawMarkers: function(xcoords, opencoords, highcoords, lowcoords, closecoords, len, width, halfwidth, styles) |
|
130 { |
|
131 var upmarker = this.get("upmarker"), |
|
132 downmarker = this.get("downmarker"), |
|
133 opencoord, |
|
134 highcoord, |
|
135 lowcoord, |
|
136 closecoord, |
|
137 left, |
|
138 right, |
|
139 leftPadding = styles.padding.left, |
|
140 marker, |
|
141 up, |
|
142 cx, |
|
143 i, |
|
144 height; |
|
145 upmarker.set(styles.upmarker); |
|
146 downmarker.set(styles.downmarker); |
|
147 upmarker.clear(); |
|
148 downmarker.clear(); |
|
149 for(i = 0; i < len; i = i + 1) |
|
150 { |
|
151 cx = xcoords[i] + leftPadding; |
|
152 left = cx - halfwidth; |
|
153 right = cx + halfwidth; |
|
154 opencoord = opencoords[i]; |
|
155 highcoord = highcoords[i]; |
|
156 lowcoord = lowcoords[i]; |
|
157 closecoord = closecoords[i]; |
|
158 up = opencoord > closecoord; |
|
159 height = lowcoord - highcoord; |
|
160 marker = up ? upmarker : downmarker; |
|
161 marker.moveTo(left, opencoord); |
|
162 marker.lineTo(cx, opencoord); |
|
163 marker.moveTo(cx, highcoord); |
|
164 marker.lineTo(cx, lowcoord); |
|
165 marker.moveTo(cx, closecoord); |
|
166 marker.lineTo(right, closecoord); |
|
167 } |
|
168 upmarker.end(); |
|
169 downmarker.end(); |
|
170 }, |
|
171 |
|
172 /** |
|
173 * Toggles visibility |
|
174 * |
|
175 * @method _toggleVisible |
|
176 * @param {Boolean} visible indicates visibilitye |
|
177 * @private |
|
178 */ |
|
179 _toggleVisible: function(visible) |
|
180 { |
|
181 this.get("upmarker").set("visible", visible); |
|
182 this.get("downmarker").set("visible", visible); |
|
183 }, |
|
184 |
|
185 /** |
|
186 * Destructor implementation for the CartesianSeries class. Calls destroy on all Graphic instances. |
|
187 * |
|
188 * @method destructor |
|
189 * @protected |
|
190 */ |
|
191 destructor: function() |
|
192 { |
|
193 var upmarker = this.get("upmarker"), |
|
194 downmarker = this.get("downmarker"); |
|
195 if(upmarker) |
|
196 { |
|
197 upmarker.destroy(); |
|
198 } |
|
199 if(downmarker) |
|
200 { |
|
201 downmarker.destroy(); |
|
202 } |
|
203 }, |
|
204 |
|
205 /** |
|
206 * Gets the default value for the `styles` attribute. Overrides |
|
207 * base implementation. |
|
208 * |
|
209 * @method _getDefaultStyles |
|
210 * @return Object |
|
211 * @private |
|
212 */ |
|
213 _getDefaultStyles: function() |
|
214 { |
|
215 var styles = { |
|
216 upmarker: { |
|
217 stroke: { |
|
218 color: "#00aa00", |
|
219 alpha: 1, |
|
220 weight: 1 |
|
221 } |
|
222 }, |
|
223 downmarker: { |
|
224 stroke: { |
|
225 color: "#aa0000", |
|
226 alpha: 1, |
|
227 weight: 1 |
|
228 } |
|
229 } |
|
230 }; |
|
231 return this._mergeStyles(styles, OHLCSeries.superclass._getDefaultStyles()); |
|
232 } |
|
233 }); |
|
234 Y.OHLCSeries = OHLCSeries; |
|
235 |
|
236 |
|
237 }, '@VERSION@', {"requires": ["series-range"]}); |