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