[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/series-histogram-base/ -> series-histogram-base-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-histogram-base', function (Y, NAME) {
   9  
  10  /**
  11   * Provides core functionality for creating a bar or column series.
  12   *
  13   * @module charts
  14   * @submodule series-histogram
  15   */
  16  var Y_Lang = Y.Lang;
  17  
  18  /**
  19   * Histogram is the base class for Column and Bar series.
  20   *
  21   * @class Histogram
  22   * @constructor
  23   * @param {Object} config (optional) Configuration parameters.
  24   * @submodule series-histogram
  25   */
  26  function Histogram(){}
  27  
  28  Histogram.prototype = {
  29      /**
  30       * Draws the series.
  31       *
  32       * @method drawSeries
  33       * @protected
  34       */
  35      drawSeries: function()
  36      {
  37          if(this.get("xcoords").length < 1)
  38          {
  39              return;
  40          }
  41          var style = this._copyObject(this.get("styles").marker),
  42              graphic = this.get("graphic"),
  43              setSize,
  44              calculatedSize,
  45              xcoords = this.get("xcoords"),
  46              ycoords = this.get("ycoords"),
  47              i = 0,
  48              len = xcoords.length,
  49              top = ycoords[0],
  50              seriesTypeCollection = this.get("seriesTypeCollection"),
  51              seriesLen = seriesTypeCollection ? seriesTypeCollection.length : 0,
  52              seriesSize = 0,
  53              totalSize = 0,
  54              offset = 0,
  55              ratio,
  56              renderer,
  57              order = this.get("order"),
  58              graphOrder = this.get("graphOrder"),
  59              left,
  60              marker,
  61              setSizeKey,
  62              calculatedSizeKey,
  63              config,
  64              fillColors = null,
  65              borderColors = null,
  66              xMarkerPlane = [],
  67              yMarkerPlane = [],
  68              xMarkerPlaneLeft,
  69              xMarkerPlaneRight,
  70              yMarkerPlaneTop,
  71              yMarkerPlaneBottom,
  72              dimensions = {
  73                  width: [],
  74                  height: []
  75              },
  76              xvalues = [],
  77              yvalues = [],
  78              groupMarkers = this.get("groupMarkers");
  79          if(Y_Lang.isArray(style.fill.color))
  80          {
  81              fillColors = style.fill.color.concat();
  82          }
  83          if(Y_Lang.isArray(style.border.color))
  84          {
  85              borderColors = style.border.color.concat();
  86          }
  87          if(this.get("direction") === "vertical")
  88          {
  89              setSizeKey = "height";
  90              calculatedSizeKey = "width";
  91          }
  92          else
  93          {
  94              setSizeKey = "width";
  95              calculatedSizeKey = "height";
  96          }
  97          setSize = style[setSizeKey];
  98          calculatedSize = style[calculatedSizeKey];
  99          this._createMarkerCache();
 100          this._maxSize = graphic.get(setSizeKey);
 101          if(seriesTypeCollection && seriesLen > 1)
 102          {
 103              for(; i < seriesLen; ++i)
 104              {
 105                  renderer = seriesTypeCollection[i];
 106                  seriesSize += renderer.get("styles").marker[setSizeKey];
 107                  if(order > i)
 108                  {
 109                      offset = seriesSize;
 110                  }
 111              }
 112              totalSize = len * seriesSize;
 113              if(totalSize > this._maxSize)
 114              {
 115                  ratio = graphic.get(setSizeKey)/totalSize;
 116                  seriesSize *= ratio;
 117                  offset *= ratio;
 118                  setSize *= ratio;
 119                  setSize = Math.max(setSize, 1);
 120                  this._maxSize = setSize;
 121              }
 122          }
 123          else
 124          {
 125              seriesSize = style[setSizeKey];
 126              totalSize = len * seriesSize;
 127              if(totalSize > this._maxSize)
 128              {
 129                  seriesSize = this._maxSize/len;
 130                  this._maxSize = seriesSize;
 131              }
 132          }
 133          offset -= seriesSize/2;
 134          for(i = 0; i < len; ++i)
 135          {
 136              xMarkerPlaneLeft = xcoords[i] - seriesSize/2;
 137              xMarkerPlaneRight = xMarkerPlaneLeft + seriesSize;
 138              yMarkerPlaneTop = ycoords[i] - seriesSize/2;
 139              yMarkerPlaneBottom = yMarkerPlaneTop + seriesSize;
 140              xMarkerPlane.push({start: xMarkerPlaneLeft, end: xMarkerPlaneRight});
 141              yMarkerPlane.push({start: yMarkerPlaneTop, end: yMarkerPlaneBottom});
 142              if(!groupMarkers && (isNaN(xcoords[i]) || isNaN(ycoords[i])))
 143              {
 144                  this._markers.push(null);
 145                  continue;
 146              }
 147              config = this._getMarkerDimensions(xcoords[i], ycoords[i], calculatedSize, offset);
 148              if(!isNaN(config.calculatedSize) && config.calculatedSize > 0)
 149              {
 150                  top = config.top;
 151                  left = config.left;
 152  
 153                  if(groupMarkers)
 154                  {
 155                      dimensions[setSizeKey][i] = setSize;
 156                      dimensions[calculatedSizeKey][i] = config.calculatedSize;
 157                      xvalues.push(left);
 158                      yvalues.push(top);
 159                  }
 160                  else
 161                  {
 162                      style[setSizeKey] = setSize;
 163                      style[calculatedSizeKey] = config.calculatedSize;
 164                      style.x = left;
 165                      style.y = top;
 166                      if(fillColors)
 167                      {
 168                          style.fill.color = fillColors[i % fillColors.length];
 169                      }
 170                      if(borderColors)
 171                      {
 172                          style.border.color = borderColors[i % borderColors.length];
 173                      }
 174                      marker = this.getMarker(style, graphOrder, i);
 175                  }
 176  
 177              }
 178              else if(!groupMarkers)
 179              {
 180                  this._markers.push(null);
 181              }
 182          }
 183          this.set("xMarkerPlane", xMarkerPlane);
 184          this.set("yMarkerPlane", yMarkerPlane);
 185          if(groupMarkers)
 186          {
 187              this._createGroupMarker({
 188                  fill: style.fill,
 189                  border: style.border,
 190                  dimensions: dimensions,
 191                  xvalues: xvalues,
 192                  yvalues: yvalues,
 193                  shape: style.shape
 194              });
 195          }
 196          else
 197          {
 198              this._clearMarkerCache();
 199          }
 200      },
 201  
 202      /**
 203       * Collection of default colors used for marker fills in a series when not specified by user.
 204       *
 205       * @property _defaultFillColors
 206       * @type Array
 207       * @protected
 208       */
 209      _defaultFillColors: ["#66007f", "#a86f41", "#295454", "#996ab2", "#e8cdb7", "#90bdbd","#000000","#c3b8ca", "#968373", "#678585"],
 210  
 211      /**
 212       * Gets the default style values for the markers.
 213       *
 214       * @method _getPlotDefaults
 215       * @return Object
 216       * @private
 217       */
 218      _getPlotDefaults: function()
 219      {
 220          var defs = {
 221              fill:{
 222                  type: "solid",
 223                  alpha: 1,
 224                  colors:null,
 225                  alphas: null,
 226                  ratios: null
 227              },
 228              border:{
 229                  weight: 0,
 230                  alpha: 1
 231              },
 232              width: 12,
 233              height: 12,
 234              shape: "rect",
 235  
 236              padding:{
 237                  top: 0,
 238                  left: 0,
 239                  right: 0,
 240                  bottom: 0
 241              }
 242          };
 243          defs.fill.color = this._getDefaultColor(this.get("graphOrder"), "fill");
 244          defs.border.color = this._getDefaultColor(this.get("graphOrder"), "border");
 245          return defs;
 246      }
 247  };
 248  
 249  Y.Histogram = Histogram;
 250  
 251  
 252  }, '3.17.2', {"requires": ["series-cartesian", "series-plot-util"]});


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