API Docs for: 3.8.0
Show:

File: charts/js/ShapeGroup.js

  1. /**
  2.  * The Charts widget provides an api for displaying data
  3.  * graphically.
  4.  *
  5.  * @module charts
  6.  * @main charts
  7.  */

  8. /**
  9.  * The charts-base submodule contains the core functionality for the charts module.
  10.  *
  11.  * @module charts
  12.  * @submodule charts-base
  13.  */
  14. var CONFIG = Y.config,
  15.     WINDOW = CONFIG.win,
  16.     DOCUMENT = CONFIG.doc,
  17.     Y_Lang = Y.Lang,
  18.     IS_STRING = Y_Lang.isString,
  19.     Y_DOM = Y.DOM,
  20.     LeftAxisLayout,
  21.     RightAxisLayout,
  22.     BottomAxisLayout,
  23.     TopAxisLayout,
  24.     _getClassName = Y.ClassNameManager.getClassName,
  25.     SERIES_MARKER = _getClassName("seriesmarker"),
  26.     ShapeGroup,
  27.     CircleGroup,
  28.     RectGroup,
  29.     EllipseGroup,
  30.     DiamondGroup;

  31. /**
  32.  * Abstract class for creating groups of shapes with the same styles and dimensions.
  33.  *
  34.  * @class ShapeGroup
  35.  * @constructor
  36.  */
  37.  ShapeGroup = function(cfg)
  38.  {
  39.     ShapeGroup.superclass.constructor.apply(this, arguments);
  40.  };

  41.  ShapeGroup.NAME = "shapeGroup";

  42.  Y.extend(ShapeGroup, Y.Path, {
  43.     /**
  44.      * Updates the shape.
  45.      *
  46.      * @method _draw
  47.      * @private
  48.      */
  49.     _draw: function()
  50.     {
  51.         var xvalues = this.get("xvalues"),
  52.             yvalues = this.get("yvalues"),
  53.             x,
  54.             y,
  55.             xRad,
  56.             yRad,
  57.             i = 0,
  58.             len,
  59.             attrs = [],
  60.             dimensions = this.get("dimensions"),
  61.             width = dimensions.width,
  62.             height = dimensions.height,
  63.             radius = dimensions.radius,
  64.             yRadius = dimensions.yRadius,
  65.             id = this.get("id"),
  66.             className = this.node.className,
  67.             widthIsArray = Y_Lang.isArray(width),
  68.             heightIsArray = Y_Lang.isArray(height),
  69.             radiusIsArray = Y_Lang.isArray(radius),
  70.             yRadiusIsArray = Y_Lang.isArray(yRadius);
  71.         if(xvalues && yvalues && xvalues.length > 0)
  72.         {
  73.             this.clear();

  74.             len = xvalues.length;
  75.             for(; i < len; ++i)
  76.             {
  77.                 x = xvalues[i];
  78.                 y = yvalues[i];
  79.                 xRad = radiusIsArray ? radius[i] : radius;
  80.                 yRad = yRadiusIsArray ? yRadius[i] : yRadius;
  81.                 if(!isNaN(x) && !isNaN(y) && !isNaN(xRad))
  82.                 {
  83.                     this.drawShape({
  84.                         x: x,
  85.                         y: y,
  86.                         width: widthIsArray ? width[i] : width,
  87.                         height: heightIsArray ? height[i] : height,
  88.                         radius: xRad,
  89.                         yRadius: yRad
  90.                     });
  91.                     this.closePath();
  92.                     attrs[i] = {
  93.                         id: id + "_" + i,
  94.                         className: className,
  95.                         coords: (x - this._left) + ", " + (y - this._top)  + ", " + radius,
  96.                         shape: "circle"
  97.                     };
  98.                 }
  99.             }
  100.             this._closePath();
  101.         }
  102.     },

  103.     /**
  104.      * Parses and array of lengths into radii
  105.      *
  106.      * @method _getRadiusCollection
  107.      * @param {Array} val Array of lengths
  108.      * @return Array
  109.      * @private
  110.      */
  111.     _getRadiusCollection: function(val)
  112.     {
  113.         var i = 0,
  114.             len = val.length,
  115.             radii = [];
  116.         for(; i < len; ++i)
  117.         {
  118.             radii[i] = val[i] * 0.5;
  119.         }
  120.         return radii;
  121.     }
  122.  });

  123. ShapeGroup.ATTRS = Y.merge(Y.Path.ATTRS, {
  124.     dimensions: {
  125.         getter: function()
  126.         {
  127.             var dimensions = this._dimensions,
  128.                 radius,
  129.                 yRadius,
  130.                 width,
  131.                 height;
  132.             if(dimensions.hasOwnProperty("radius"))
  133.             {
  134.                 return dimensions;
  135.             }
  136.             else
  137.             {
  138.                 width = dimensions.width;
  139.                 height = dimensions.height;
  140.                 radius = Y_Lang.isArray(width) ? this._getRadiusCollection(width) : (width * 0.5);
  141.                 yRadius = Y_Lang.isArray(height) ? this._getRadiusCollection(height) : (height * 0.5);
  142.                 return {
  143.                     width: width,
  144.                     height: height,
  145.                     radius: radius,
  146.                     yRadius: yRadius
  147.                 };
  148.             }
  149.         },

  150.         setter: function(val)
  151.         {
  152.             this._dimensions = val;
  153.             return val;
  154.         }
  155.     },
  156.     xvalues: {
  157.         getter: function()
  158.         {
  159.             return this._xvalues;
  160.         },
  161.         setter: function(val)
  162.         {
  163.             this._xvalues = val;
  164.         }
  165.     },
  166.     yvalues: {
  167.         getter: function()
  168.         {
  169.             return this._yvalues;
  170.         },
  171.         setter: function(val)
  172.         {
  173.             this._yvalues = val;
  174.         }
  175.     }
  176. });
  177. Y.ShapeGroup = ShapeGroup;

  178.