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('series-ohlc', function (Y, NAME) {
11 * Provides functionality for creating a ohlc series.
14 * @submodule series-ohlc
17 * The OHLCSeries class renders lines representing the open, high, low and close
21 * @extends RangeSeries
23 * @param {Object} config (optional) Configuration parameters.
24 * @submodule series-ohlc
28 OHLCSeries.superclass.constructor.apply(this, arguments);
31 OHLCSeries.NAME = "ohlcSeries";
35 * Read-only attribute indicating the type of series.
47 * The graphic in which drawings will be rendered.
55 setter: function(val) {
56 //woraround for Attribute order of operations bug
57 if(!this.get("rendered")) {
58 this.set("rendered", true);
60 this.set("upmarker", val.addShape({
63 this.set("downmarker", val.addShape({
75 * Style properties used for drawing markers. This attribute is inherited from `RangeSeries`. Below are the default values:
77 * <dt>upmarker</dt><dd>Properties for a marker representing a period that closes higher than it opens.
79 * <dt>fill</dt><dd>A hash containing the following values:
81 * <dt>color</dt><dd>Color of the fill. The default value is "#00aa00".</dd>
83 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker fill. The default value is 1.</dd>
86 * <dt>border</dt><dd>A hash containing the following values:
88 * <dt>color</dt><dd>Color of the border. The default value is "#000000".</dd>
89 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker border. The default value is 1.</dd>
90 * <dt>weight</dt><dd>Number indicating the width of the border. The default value is 0.</dd>
95 * <dt>downmarker</dt><dd>Properties for a marker representing a period that opens higher than it closes.
97 * <dt>fill</dt><dd>A hash containing the following values:
99 * <dt>color</dt><dd>Color of the fill. The default value is "#aa0000".</dd>
101 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker fill. The default value is 1.</dd>
104 * <dt>border</dt><dd>A hash containing the following values:
106 * <dt>color</dt><dd>Color of the border. The default value is "#000000".</dd>
107 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker border. The default value is 1.</dd>
108 * <dt>weight</dt><dd>Number indicating the width of the border. The default value is 0.</dd>
120 Y.extend(OHLCSeries, Y.RangeSeries, {
122 * Draws markers for an OHLC series.
125 * @param {Array} xcoords The xcoordinates to be plotted.
126 * @param {Array} opencoords The coordinates representing the open values.
127 * @param {Array} highcoords The coordinates representing the high values.
128 * @param {Array} lowcoords The coordinates representing the low values.
129 * @param {Array} closecoords The coordinates representing the close values.
130 * @param {Number} len The number of x coordinates to plot.
131 * @param {Number} width The width of each ohlc marker.
132 * @param {Number} halfwidth Half the width of each ohlc marker.
133 * @param {Object} styles The styles for the series.
136 _drawMarkers: function(xcoords, opencoords, highcoords, lowcoords, closecoords, len, width, halfwidth, styles)
138 var upmarker = this.get("upmarker"),
139 downmarker = this.get("downmarker"),
146 leftPadding = styles.padding.left,
149 upmarker.set(styles.upmarker);
150 downmarker.set(styles.downmarker);
153 for(i = 0; i < len; i = i + 1)
155 cx = xcoords[i] + leftPadding;
156 left = cx - halfwidth;
157 right = cx + halfwidth;
158 opencoord = opencoords[i];
159 highcoord = highcoords[i];
160 lowcoord = lowcoords[i];
161 closecoord = closecoords[i];
162 up = opencoord > closecoord;
163 height = lowcoord - highcoord;
164 marker = up ? upmarker : downmarker;
165 marker.moveTo(left, opencoord);
166 marker.lineTo(cx, opencoord);
167 marker.moveTo(cx, highcoord);
168 marker.lineTo(cx, lowcoord);
169 marker.moveTo(cx, closecoord);
170 marker.lineTo(right, closecoord);
179 * @method _toggleVisible
180 * @param {Boolean} visible indicates visibilitye
183 _toggleVisible: function(visible)
185 this.get("upmarker").set("visible", visible);
186 this.get("downmarker").set("visible", visible);
190 * Destructor implementation for the CartesianSeries class. Calls destroy on all Graphic instances.
195 destructor: function()
197 var upmarker = this.get("upmarker"),
198 downmarker = this.get("downmarker");
205 downmarker.destroy();
210 * Gets the default value for the `styles` attribute. Overrides
211 * base implementation.
213 * @method _getDefaultStyles
217 _getDefaultStyles: function()
235 return this._mergeStyles(styles, OHLCSeries.superclass._getDefaultStyles());
238 Y.OHLCSeries = OHLCSeries;
241 }, '3.13.0', {"requires": ["series-range"]});