[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/series-ohlc/ -> series-ohlc-debug.js (source)

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


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1