src/cm/media/js/lib/yui/yui3-3.15.0/build/series-base/series-base-debug.js
changeset 602 e16a97fb364a
equal deleted inserted replaced
601:d334a616c023 602:e16a97fb364a
       
     1 YUI.add('series-base', function (Y, NAME) {
       
     2 
       
     3 /**
       
     4  * Provides functionality for creating a chart series.
       
     5  *
       
     6  * @module charts
       
     7  * @submodule series-base
       
     8  */
       
     9 
       
    10 /**
       
    11  * An abstract class for creating series instances.
       
    12  * SeriesBase is used by the following classes:
       
    13  * <ul>
       
    14  *      <li>{{#crossLink "CartesianSeries"}}{{/crossLink}}</li>
       
    15  *      <li>{{#crossLink "PieSeries"}}{{/crossLink}}</li>
       
    16  *  </ul>
       
    17  *
       
    18  * @class SeriesBase
       
    19  * @extends Base
       
    20  * @uses Renderer
       
    21  * @constructor
       
    22  * @param {Object} config (optional) Configuration parameters.
       
    23  * @submodule series-base
       
    24  */
       
    25 Y.SeriesBase = Y.Base.create("seriesBase", Y.Base, [Y.Renderer], {
       
    26     /**
       
    27      * @method render
       
    28      * @private
       
    29      */
       
    30     render: function()
       
    31     {
       
    32         this._setCanvas();
       
    33         this.addListeners();
       
    34         this.validate();
       
    35     },
       
    36 
       
    37     /**
       
    38      * Creates a `Graphic` instance.
       
    39      *
       
    40      * @method _setCanvas
       
    41      * @protected
       
    42      */
       
    43     _setCanvas: function()
       
    44     {
       
    45         var graph = this.get("graph"),
       
    46             graphic = graph.get("graphic");
       
    47         this.set("graphic", graphic);
       
    48     },
       
    49 
       
    50     /**
       
    51      * Returns a reference to the parent container to which all chart elements are contained.
       
    52      * When the series is bound to a `Chart` instance, the `Chart` instance is the reference.
       
    53      * If nothing is set as the `chart` attribute, the `_getChart` method will return a reference
       
    54      * to the `graphic` attribute.
       
    55      *
       
    56      * @method _getChart
       
    57      * @return {Object}
       
    58      * @private
       
    59      */
       
    60     _getChart:function() {
       
    61         var chart,
       
    62             graph = this.get("graph");
       
    63         if(graph)
       
    64         {
       
    65             chart = graph.get("chart");
       
    66         }
       
    67         if(!chart)
       
    68         {
       
    69             chart = this.get("graphic");
       
    70         }
       
    71         return chart;
       
    72     },
       
    73 
       
    74     /**
       
    75      * Returns the sum of all values for the series.
       
    76      *
       
    77      * @method getTotalValues
       
    78      * @return Number
       
    79      */
       
    80     getTotalValues: function()
       
    81     {
       
    82         var valueCoord = this.get("direction") === "vertical" ? "x" : "y",
       
    83             total = this.get(valueCoord + "Axis").getTotalByKey(this.get(valueCoord + "Key"));
       
    84         return total;
       
    85     },
       
    86 
       
    87     /**
       
    88      * Gets the default value for the `styles` attribute. Overrides
       
    89      * base implementation.
       
    90      *
       
    91      * @method _getDefaultStyles
       
    92      * @return Object
       
    93      * @protected
       
    94      */
       
    95     _getDefaultStyles: function()
       
    96     {
       
    97         return {padding:{
       
    98                 top: 0,
       
    99                 left: 0,
       
   100                 right: 0,
       
   101                 bottom: 0
       
   102             }};
       
   103     },
       
   104 
       
   105     /**
       
   106      * Shows/hides contents of the series.
       
   107      *
       
   108      * @method _handleVisibleChange
       
   109      * @param {Object} e Event object.
       
   110      * @protected
       
   111      */
       
   112     _handleVisibleChange: function()
       
   113     {
       
   114         this._toggleVisible(this.get("visible"));
       
   115     },
       
   116 
       
   117     /**
       
   118      * Destructor implementation for the CartesianSeries class. Calls destroy on all Graphic instances.
       
   119      *
       
   120      * @method destructor
       
   121      * @protected
       
   122      */
       
   123     destructor: function()
       
   124     {
       
   125         var marker,
       
   126             markers = this.get("markers");
       
   127         if(this.get("rendered"))
       
   128         {
       
   129             if(this._stylesChangeHandle)
       
   130             {
       
   131                 this._stylesChangeHandle.detach();
       
   132             }
       
   133             if(this._widthChangeHandle)
       
   134             {
       
   135                 this._widthChangeHandle.detach();
       
   136             }
       
   137             if(this._heightChangeHandle)
       
   138             {
       
   139                 this._heightChangeHandle.detach();
       
   140             }
       
   141             if(this._visibleChangeHandle)
       
   142             {
       
   143                 this._visibleChangeHandle.detach();
       
   144             }
       
   145         }
       
   146         while(markers && markers.length > 0)
       
   147         {
       
   148             marker = markers.shift();
       
   149             if(marker && marker instanceof Y.Shape)
       
   150             {
       
   151                 marker.destroy();
       
   152             }
       
   153         }
       
   154         if(this._path)
       
   155         {
       
   156             this._path.destroy();
       
   157             this._path = null;
       
   158         }
       
   159         if(this._lineGraphic)
       
   160         {
       
   161             this._lineGraphic.destroy();
       
   162             this._lineGraphic = null;
       
   163         }
       
   164         if(this._groupMarker)
       
   165         {
       
   166             this._groupMarker.destroy();
       
   167             this._groupMarker = null;
       
   168         }
       
   169     },
       
   170 
       
   171     /**
       
   172      * Collection of default colors used for lines in a series when not specified by user.
       
   173      *
       
   174      * @property _defaultLineColors
       
   175      * @type Array
       
   176      * @protected
       
   177      */
       
   178     _defaultLineColors:[
       
   179         "#426ab3",
       
   180         "#d09b2c",
       
   181         "#000000",
       
   182         "#b82837",
       
   183         "#b384b5",
       
   184         "#ff7200",
       
   185         "#779de3",
       
   186         "#cbc8ba",
       
   187         "#7ed7a6",
       
   188         "#007a6c"
       
   189     ],
       
   190 
       
   191     /**
       
   192      * Collection of default colors used for marker fills in a series when not specified by user.
       
   193      *
       
   194      * @property _defaultFillColors
       
   195      * @type Array
       
   196      * @protected
       
   197      */
       
   198     _defaultFillColors:[
       
   199         "#6084d0",
       
   200         "#eeb647",
       
   201         "#6c6b5f",
       
   202         "#d6484f",
       
   203         "#ce9ed1",
       
   204         "#ff9f3b",
       
   205         "#93b7ff",
       
   206         "#e0ddd0",
       
   207         "#94ecba",
       
   208         "#309687"
       
   209     ],
       
   210 
       
   211     /**
       
   212      * Collection of default colors used for marker borders in a series when not specified by user.
       
   213      *
       
   214      * @property _defaultBorderColors
       
   215      * @type Array
       
   216      * @protected
       
   217      */
       
   218     _defaultBorderColors:[
       
   219         "#205096",
       
   220         "#b38206",
       
   221         "#000000",
       
   222         "#94001e",
       
   223         "#9d6fa0",
       
   224         "#e55b00",
       
   225         "#5e85c9",
       
   226         "#adab9e",
       
   227         "#6ac291",
       
   228         "#006457"
       
   229     ],
       
   230 
       
   231     /**
       
   232      * Collection of default colors used for area fills, histogram fills and pie fills in a series when not specified by user.
       
   233      *
       
   234      * @property _defaultSliceColors
       
   235      * @type Array
       
   236      * @protected
       
   237      */
       
   238     _defaultSliceColors: [
       
   239         "#66007f",
       
   240         "#a86f41",
       
   241         "#295454",
       
   242         "#996ab2",
       
   243         "#e8cdb7",
       
   244         "#90bdbd",
       
   245         "#000000",
       
   246         "#c3b8ca",
       
   247         "#968373",
       
   248         "#678585"
       
   249     ],
       
   250 
       
   251     /**
       
   252      * Parses a color based on a series order and type.
       
   253      *
       
   254      * @method _getDefaultColor
       
   255      * @param {Number} index Index indicating the series order.
       
   256      * @param {String} type Indicates which type of object needs the color.
       
   257      * @return String
       
   258      * @protected
       
   259      */
       
   260     _getDefaultColor: function(index, type)
       
   261     {
       
   262         var colors = {
       
   263                 line: this._defaultLineColors,
       
   264                 fill: this._defaultFillColors,
       
   265                 border: this._defaultBorderColors,
       
   266                 slice: this._defaultSliceColors
       
   267             },
       
   268             col = colors[type] || colors.fill,
       
   269             l = col.length;
       
   270         index = index || 0;
       
   271         if(index >= l)
       
   272         {
       
   273             index = index % l;
       
   274         }
       
   275         type = type || "fill";
       
   276         return colors[type][index];
       
   277     }
       
   278 }, {
       
   279     ATTRS: {
       
   280         /*
       
   281          * Returns the width of the parent graph
       
   282          *
       
   283          * @attribute width
       
   284          * @type Number
       
   285          */
       
   286         width: {
       
   287             readOnly: true,
       
   288 
       
   289             getter: function()
       
   290             {
       
   291                 return this.get("graphic").get("width");
       
   292             }
       
   293         },
       
   294 
       
   295         /**
       
   296          * Returns the height of the parent graph
       
   297          *
       
   298          * @attribute height
       
   299          * @type Number
       
   300          */
       
   301         height: {
       
   302             readOnly: true,
       
   303 
       
   304             getter: function()
       
   305             {
       
   306                 return this.get("graphic").get("height");
       
   307             }
       
   308         },
       
   309 
       
   310         /**
       
   311          * The graphic in which drawings will be rendered.
       
   312          *
       
   313          * @attribute graphic
       
   314          * @type Graphic
       
   315          */
       
   316         graphic: {
       
   317             lazyAdd: false,
       
   318 
       
   319             setter: function(val) {
       
   320                 //woraround for Attribute order of operations bug
       
   321                 if(!this.get("rendered")) {
       
   322                     this.set("rendered", true);
       
   323                 }
       
   324                 return val;
       
   325             }
       
   326         },
       
   327 
       
   328         /**
       
   329          * Reference to the `Chart` application. If no `Chart` application is present,
       
   330          * a reference to the `Graphic` instance that the series is drawn into will be returned.
       
   331          *
       
   332          * @attribute chart
       
   333          * @type ChartBase
       
   334          */
       
   335         chart: {
       
   336             getter: function()
       
   337             {
       
   338                 var chart,
       
   339                     graph = this.get("graph");
       
   340                 if(graph)
       
   341                 {
       
   342                     chart = graph.get("chart");
       
   343                 }
       
   344                 return chart;
       
   345             }
       
   346         },
       
   347 
       
   348         /**
       
   349          * Reference to the `Graph` in which the series is drawn into.
       
   350          *
       
   351          * @attribute graph
       
   352          * @type Graph
       
   353          */
       
   354         graph: {},
       
   355 
       
   356         /**
       
   357          * Indicates whether the Series has been through its initial set up.
       
   358          *
       
   359          * @attribute rendered
       
   360          * @type Boolean
       
   361          */
       
   362         rendered: {
       
   363             value: false
       
   364         },
       
   365 
       
   366         /**
       
   367          * Indicates whether to show the series
       
   368          *
       
   369          * @attribute visible
       
   370          * @type Boolean
       
   371          * @default true
       
   372          */
       
   373         visible: {
       
   374             value: true
       
   375         },
       
   376 
       
   377         /**
       
   378          * Indicates whether or not markers for a series will be grouped and rendered in a single complex shape instance.
       
   379          *
       
   380          * @attribute groupMarkers
       
   381          * @type Boolean
       
   382          */
       
   383         groupMarkers: {
       
   384             getter: function()
       
   385             {
       
   386                 var graph,
       
   387                     groupMarkers = this._groupMarkers;
       
   388                 if(!groupMarkers) {
       
   389                     graph = this.get("graph");
       
   390                     if(graph)
       
   391                     {
       
   392                         groupMarkers = graph.get("groupMarkers");
       
   393                     }
       
   394                 }
       
   395                 return groupMarkers;
       
   396             },
       
   397 
       
   398             setter: function(val)
       
   399             {
       
   400                 this._groupMarkers = val;
       
   401                 return val;
       
   402             }
       
   403         }
       
   404     }
       
   405 });
       
   406 
       
   407 
       
   408 }, '@VERSION@', {"requires": ["graphics", "axis-base"]});