[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('series-candlestick', function (Y, NAME) { 9 10 /** 11 * Provides functionality for creating a candlestick series. 12 * 13 * @module charts 14 * @submodule series-candlestick 15 */ 16 /** 17 * The CandlestickSeries class renders columns (candles) and lines (wicks) representing the open, high, low and close 18 * values for a chart. 19 * 20 * @class CandlestickSeries 21 * @extends RangeSeries 22 * @constructor 23 * @param {Object} config (optional) Configuration parameters. 24 * @submodule series-candlestick 25 */ 26 function CandlestickSeries() 27 { 28 CandlestickSeries.superclass.constructor.apply(this, arguments); 29 } 30 31 CandlestickSeries.NAME = "candlestickSeries"; 32 33 CandlestickSeries.ATTRS = { 34 /** 35 * Read-only attribute indicating the type of series. 36 * 37 * @attribute type 38 * @type String 39 * @readOnly 40 * @default candlestick 41 */ 42 type: { 43 value: "candlestick" 44 }, 45 46 /** 47 * The graphic in which drawings will be rendered. 48 * 49 * @attribute graphic 50 * @type Graphic 51 */ 52 graphic: { 53 lazyAdd: false, 54 55 setter: function(val) { 56 //woraround for Attribute order of operations bug 57 if(!this.get("rendered")) { 58 this.set("rendered", true); 59 } 60 this.set("upcandle", val.addShape({ 61 type: "path" 62 })); 63 this.set("downcandle", val.addShape({ 64 type: "path" 65 })); 66 this.set("wick", val.addShape({ 67 type: "path" 68 })); 69 return val; 70 } 71 }, 72 73 /** 74 * Reference to the candlestick used when the close value is higher than the open value. 75 * 76 * @attribute upcandle 77 * @type Path 78 */ 79 upcandle: {}, 80 81 /** 82 * Reference to the candlestick used when the open value is higher than the close value. 83 * 84 * @attribute downcandle 85 * @type Path 86 */ 87 downcandle: {}, 88 89 /** 90 * Reference to the line drawn between the high and low values. 91 * 92 * @attribute wick 93 * @type Path 94 */ 95 wick: {} 96 97 /** 98 * Style properties used for drawing candles and wicks. This attribute is inherited from `RangeSeries`. Below are the default values: 99 * <dl> 100 * <dt>upcandle</dt><dd>Properties for a candle representing a period that closes higher than it opens. 101 * <dl> 102 * <dt>fill</dt><dd>A hash containing the following values: 103 * <dl> 104 * <dt>color</dt><dd>Color of the fill. The default value is "#00aa00".</dd> 105 * </dd> 106 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker fill. The default value is 1.</dd> 107 * </dl> 108 * </dd> 109 * <dt>border</dt><dd>A hash containing the following values: 110 * <dl> 111 * <dt>color</dt><dd>Color of the border. The default value is "#000000".</dd> 112 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker border. The default value is 1.</dd> 113 * <dt>weight</dt><dd>Number indicating the width of the border. The default value is 0.</dd> 114 * </dl> 115 * </dd> 116 * </dl> 117 * </dd> 118 * <dt>downcandle</dt><dd>Properties for a candle representing a period that opens higher than it closes. 119 * <dl> 120 * <dt>fill</dt><dd>A hash containing the following values: 121 * <dl> 122 * <dt>color</dt><dd>Color of the fill. The default value is "#aa0000".</dd> 123 * </dd> 124 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker fill. The default value is 1.</dd> 125 * </dl> 126 * </dd> 127 * <dt>border</dt><dd>A hash containing the following values: 128 * <dl> 129 * <dt>color</dt><dd>Color of the border. The default value is "#000000".</dd> 130 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the marker border. The default value is 1.</dd> 131 * <dt>weight</dt><dd>Number indicating the width of the border. The default value is 0.</dd> 132 * </dl> 133 * </dd> 134 * </dl> 135 * </dd> 136 * <dt>wick</dt><dd>Properties for the wick, which is a line drawn from the high point of the period to the low point of the period. 137 * <dl> 138 * <dt>color</dt><dd>The color of the wick. The default value is "#000000".</dd> 139 * <dt>weight</dt><dd>The weight of the wick. The default value is 1.</dd> 140 * <dt>alpha</dt><dd>Number from 0 to 1 indicating the opacity of the wick. The default value is 1.</dd> 141 * </dl> 142 * </dd> 143 * </dl> 144 * 145 * @attribute styles 146 * @type Object 147 */ 148 }; 149 150 Y.extend(CandlestickSeries, Y.RangeSeries, { 151 /** 152 * Draws markers for an Candlestick series. 153 * 154 * @method 155 * @param {Array} xcoords The xcoordinates to be plotted. 156 * @param {Array} opencoords The coordinates representing the open values. 157 * @param {Array} highcoords The coordinates representing the high values. 158 * @param {Array} lowcoords The coordinates representing the low values. 159 * @param {Array} closecoords The coordinates representing the close values. 160 * @param {Number} len The number of x coordinates to plot. 161 * @param {Number} width The width of each candlestick marker. 162 * @param {Number} halfwidth Half the width of each candlestick marker. 163 * @param {Object} styles The styles for the series. 164 * @private 165 */ 166 _drawMarkers: function(xcoords, opencoords, highcoords, lowcoords, closecoords, len, width, halfwidth, styles) 167 { 168 var upcandle = this.get("upcandle"), 169 downcandle = this.get("downcandle"), 170 candle, 171 wick = this.get("wick"), 172 wickStyles = styles.wick, 173 wickWidth = wickStyles.width, 174 cx, 175 opencoord, 176 highcoord, 177 lowcoord, 178 closecoord, 179 left, 180 right, 181 top, 182 bottom, 183 height, 184 leftPadding = styles.padding.left, 185 up, 186 i, 187 isNumber = Y.Lang.isNumber; 188 upcandle.set(styles.upcandle); 189 downcandle.set(styles.downcandle); 190 wick.set({ 191 fill: wickStyles.fill, 192 stroke: wickStyles.stroke, 193 shapeRendering: wickStyles.shapeRendering 194 }); 195 upcandle.clear(); 196 downcandle.clear(); 197 wick.clear(); 198 for(i = 0; i < len; i = i + 1) 199 { 200 cx = Math.round(xcoords[i] + leftPadding); 201 left = cx - halfwidth; 202 right = cx + halfwidth; 203 opencoord = Math.round(opencoords[i]); 204 highcoord = Math.round(highcoords[i]); 205 lowcoord = Math.round(lowcoords[i]); 206 closecoord = Math.round(closecoords[i]); 207 up = opencoord > closecoord; 208 top = up ? closecoord : opencoord; 209 bottom = up ? opencoord : closecoord; 210 height = bottom - top; 211 candle = up ? upcandle : downcandle; 212 if(candle && isNumber(left) && isNumber(top) && isNumber(width) && isNumber(height)) 213 { 214 candle.drawRect(left, top, width, height); 215 } 216 if(isNumber(cx) && isNumber(highcoord) && isNumber(lowcoord)) 217 { 218 wick.drawRect(cx - wickWidth/2, highcoord, wickWidth, lowcoord - highcoord); 219 } 220 } 221 upcandle.end(); 222 downcandle.end(); 223 wick.end(); 224 wick.toBack(); 225 }, 226 227 /** 228 * Toggles visibility 229 * 230 * @method _toggleVisible 231 * @param {Boolean} visible indicates visibilitye 232 * @private 233 */ 234 _toggleVisible: function(visible) 235 { 236 this.get("upcandle").set("visible", visible); 237 this.get("downcandle").set("visible", visible); 238 this.get("wick").set("visible", visible); 239 }, 240 241 /** 242 * Destructor implementation for the CartesianSeries class. Calls destroy on all Graphic instances. 243 * 244 * @method destructor 245 * @protected 246 */ 247 destructor: function() 248 { 249 var upcandle = this.get("upcandle"), 250 downcandle = this.get("downcandle"), 251 wick = this.get("wick"); 252 if(upcandle) 253 { 254 upcandle.destroy(); 255 } 256 if(downcandle) 257 { 258 downcandle.destroy(); 259 } 260 if(wick) 261 { 262 wick.destroy(); 263 } 264 }, 265 266 /** 267 * Gets the default value for the `styles` attribute. Overrides 268 * base implementation. 269 * 270 * @method _getDefaultStyles 271 * @return Object 272 * @private 273 */ 274 _getDefaultStyles: function() 275 { 276 var styles = { 277 upcandle: { 278 shapeRendering: "crispEdges", 279 fill: { 280 color: "#00aa00", 281 alpha: 1 282 }, 283 stroke: { 284 color: "#000000", 285 alpha: 1, 286 weight: 0 287 } 288 }, 289 downcandle: { 290 shapeRendering: "crispEdges", 291 fill: { 292 color: "#aa0000", 293 alpha: 1 294 }, 295 stroke: { 296 color: "#000000", 297 alpha: 1, 298 weight: 0 299 } 300 }, 301 wick: { 302 shapeRendering: "crispEdges", 303 width: 1, 304 fill: { 305 color: "#000000", 306 alpha: 1 307 }, 308 stroke: { 309 color: "#000000", 310 alpha: 1, 311 weight: 0 312 } 313 } 314 }; 315 return this._mergeStyles(styles, CandlestickSeries.superclass._getDefaultStyles()); 316 } 317 }); 318 Y.CandlestickSeries = CandlestickSeries; 319 320 321 }, '3.17.2', {"requires": ["series-range"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |