API Docs for: 3.17.2
Show:

File: charts/js/OHLCSeries.js

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