Version 3.18.1
Show:

File: graphics/js/ShapeGroup.js

  1. /**
  2. * The graphics-group submodule allows from drawing a shape multiple times within a single instance.
  3. *
  4. * @module graphics
  5. * @submodule graphics-group
  6. */
  7. var ShapeGroup,
  8. CircleGroup,
  9. RectGroup,
  10. EllipseGroup,
  11. DiamondGroup,
  12. Y_Lang = Y.Lang;
  13. /**
  14. * Abstract class for creating groups of shapes with the same styles and dimensions.
  15. *
  16. * @class ShapeGroup
  17. * @constructor
  18. * @submodule graphics-group
  19. */
  20. ShapeGroup = function()
  21. {
  22. ShapeGroup.superclass.constructor.apply(this, arguments);
  23. };
  24. ShapeGroup.NAME = "shapeGroup";
  25. Y.extend(ShapeGroup, Y.Path, {
  26. /**
  27. * Updates the shape.
  28. *
  29. * @method _draw
  30. * @private
  31. */
  32. _draw: function()
  33. {
  34. var xvalues = this.get("xvalues"),
  35. yvalues = this.get("yvalues"),
  36. x,
  37. y,
  38. xRad,
  39. yRad,
  40. i = 0,
  41. len,
  42. dimensions = this.get("dimensions"),
  43. width = dimensions.width,
  44. height = dimensions.height,
  45. radius = dimensions.radius,
  46. yRadius = dimensions.yRadius,
  47. widthIsArray = Y_Lang.isArray(width),
  48. heightIsArray = Y_Lang.isArray(height),
  49. radiusIsArray = Y_Lang.isArray(radius),
  50. yRadiusIsArray = Y_Lang.isArray(yRadius);
  51. if(xvalues && yvalues && xvalues.length > 0)
  52. {
  53. this.clear();
  54. len = xvalues.length;
  55. for(; i < len; ++i)
  56. {
  57. x = xvalues[i];
  58. y = yvalues[i];
  59. xRad = radiusIsArray ? radius[i] : radius;
  60. yRad = yRadiusIsArray ? yRadius[i] : yRadius;
  61. if(!isNaN(x) && !isNaN(y) && !isNaN(xRad))
  62. {
  63. this.drawShape({
  64. x: x,
  65. y: y,
  66. width: widthIsArray ? width[i] : width,
  67. height: heightIsArray ? height[i] : height,
  68. radius: xRad,
  69. yRadius: yRad
  70. });
  71. this.closePath();
  72. }
  73. }
  74. this._closePath();
  75. }
  76. },
  77. /**
  78. * Parses and array of lengths into radii
  79. *
  80. * @method _getRadiusCollection
  81. * @param {Array} val Array of lengths
  82. * @return Array
  83. * @private
  84. */
  85. _getRadiusCollection: function(val)
  86. {
  87. var i = 0,
  88. len = val.length,
  89. radii = [];
  90. for(; i < len; ++i)
  91. {
  92. radii[i] = val[i] * 0.5;
  93. }
  94. return radii;
  95. }
  96. });
  97. ShapeGroup.ATTRS = Y.merge(Y.Path.ATTRS, {
  98. dimensions: {
  99. getter: function()
  100. {
  101. var dimensions = this._dimensions,
  102. radius,
  103. yRadius,
  104. width,
  105. height;
  106. if(dimensions.hasOwnProperty("radius"))
  107. {
  108. return dimensions;
  109. }
  110. else
  111. {
  112. width = dimensions.width;
  113. height = dimensions.height;
  114. radius = Y_Lang.isArray(width) ? this._getRadiusCollection(width) : (width * 0.5);
  115. yRadius = Y_Lang.isArray(height) ? this._getRadiusCollection(height) : (height * 0.5);
  116. return {
  117. width: width,
  118. height: height,
  119. radius: radius,
  120. yRadius: yRadius
  121. };
  122. }
  123. },
  124. setter: function(val)
  125. {
  126. this._dimensions = val;
  127. return val;
  128. }
  129. },
  130. xvalues: {
  131. getter: function()
  132. {
  133. return this._xvalues;
  134. },
  135. setter: function(val)
  136. {
  137. this._xvalues = val;
  138. }
  139. },
  140. yvalues: {
  141. getter: function()
  142. {
  143. return this._yvalues;
  144. },
  145. setter: function(val)
  146. {
  147. this._yvalues = val;
  148. }
  149. }
  150. });
  151. Y.ShapeGroup = ShapeGroup;