[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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('graphics-group', function (Y, NAME) { 9 10 /** 11 * The graphics-group submodule allows from drawing a shape multiple times within a single instance. 12 * 13 * @module graphics 14 * @submodule graphics-group 15 */ 16 var ShapeGroup, 17 CircleGroup, 18 RectGroup, 19 EllipseGroup, 20 DiamondGroup, 21 Y_Lang = Y.Lang; 22 23 /** 24 * Abstract class for creating groups of shapes with the same styles and dimensions. 25 * 26 * @class ShapeGroup 27 * @constructor 28 * @submodule graphics-group 29 */ 30 31 ShapeGroup = function() 32 { 33 ShapeGroup.superclass.constructor.apply(this, arguments); 34 }; 35 36 ShapeGroup.NAME = "shapeGroup"; 37 38 Y.extend(ShapeGroup, Y.Path, { 39 /** 40 * Updates the shape. 41 * 42 * @method _draw 43 * @private 44 */ 45 _draw: function() 46 { 47 var xvalues = this.get("xvalues"), 48 yvalues = this.get("yvalues"), 49 x, 50 y, 51 xRad, 52 yRad, 53 i = 0, 54 len, 55 dimensions = this.get("dimensions"), 56 width = dimensions.width, 57 height = dimensions.height, 58 radius = dimensions.radius, 59 yRadius = dimensions.yRadius, 60 widthIsArray = Y_Lang.isArray(width), 61 heightIsArray = Y_Lang.isArray(height), 62 radiusIsArray = Y_Lang.isArray(radius), 63 yRadiusIsArray = Y_Lang.isArray(yRadius); 64 if(xvalues && yvalues && xvalues.length > 0) 65 { 66 this.clear(); 67 68 len = xvalues.length; 69 for(; i < len; ++i) 70 { 71 x = xvalues[i]; 72 y = yvalues[i]; 73 xRad = radiusIsArray ? radius[i] : radius; 74 yRad = yRadiusIsArray ? yRadius[i] : yRadius; 75 if(!isNaN(x) && !isNaN(y) && !isNaN(xRad)) 76 { 77 this.drawShape({ 78 x: x, 79 y: y, 80 width: widthIsArray ? width[i] : width, 81 height: heightIsArray ? height[i] : height, 82 radius: xRad, 83 yRadius: yRad 84 }); 85 this.closePath(); 86 } 87 } 88 this._closePath(); 89 } 90 }, 91 92 /** 93 * Parses and array of lengths into radii 94 * 95 * @method _getRadiusCollection 96 * @param {Array} val Array of lengths 97 * @return Array 98 * @private 99 */ 100 _getRadiusCollection: function(val) 101 { 102 var i = 0, 103 len = val.length, 104 radii = []; 105 for(; i < len; ++i) 106 { 107 radii[i] = val[i] * 0.5; 108 } 109 return radii; 110 } 111 }); 112 113 ShapeGroup.ATTRS = Y.merge(Y.Path.ATTRS, { 114 dimensions: { 115 getter: function() 116 { 117 var dimensions = this._dimensions, 118 radius, 119 yRadius, 120 width, 121 height; 122 if(dimensions.hasOwnProperty("radius")) 123 { 124 return dimensions; 125 } 126 else 127 { 128 width = dimensions.width; 129 height = dimensions.height; 130 radius = Y_Lang.isArray(width) ? this._getRadiusCollection(width) : (width * 0.5); 131 yRadius = Y_Lang.isArray(height) ? this._getRadiusCollection(height) : (height * 0.5); 132 return { 133 width: width, 134 height: height, 135 radius: radius, 136 yRadius: yRadius 137 }; 138 } 139 }, 140 141 setter: function(val) 142 { 143 this._dimensions = val; 144 return val; 145 } 146 }, 147 xvalues: { 148 getter: function() 149 { 150 return this._xvalues; 151 }, 152 setter: function(val) 153 { 154 this._xvalues = val; 155 } 156 }, 157 yvalues: { 158 getter: function() 159 { 160 return this._yvalues; 161 }, 162 setter: function(val) 163 { 164 this._yvalues = val; 165 } 166 } 167 }); 168 Y.ShapeGroup = ShapeGroup; 169 /** 170 * Abstract class for creating groups of circles with the same styles and dimensions. 171 * 172 * @class CircleGroup 173 * @constructor 174 * @submodule graphics-group 175 */ 176 CircleGroup = function() 177 { 178 CircleGroup.superclass.constructor.apply(this, arguments); 179 }; 180 181 CircleGroup.NAME = "circleGroup"; 182 183 Y.extend(CircleGroup, Y.ShapeGroup, { 184 /** 185 * Algorithm for drawing shape. 186 * 187 * @method drawShape 188 * @param {Object} cfg Parameters used to draw the shape. 189 */ 190 drawShape: function(cfg) 191 { 192 this.drawCircle(cfg.x, cfg.y, cfg.radius); 193 } 194 }); 195 196 CircleGroup.ATTRS = Y.merge(Y.ShapeGroup.ATTRS, { 197 dimensions: { 198 getter: function() 199 { 200 var dimensions = this._dimensions, 201 radius, 202 yRadius, 203 width, 204 height; 205 if(dimensions.hasOwnProperty("radius")) 206 { 207 return dimensions; 208 } 209 else 210 { 211 width = dimensions.width; 212 height = dimensions.height; 213 radius = Y_Lang.isArray(width) ? this._getRadiusCollection(width) : (width * 0.5); 214 yRadius = radius; 215 return { 216 width: width, 217 height: height, 218 radius: radius, 219 yRadius: yRadius 220 }; 221 } 222 } 223 } 224 }); 225 226 CircleGroup.ATTRS = Y.ShapeGroup.ATTRS; 227 Y.CircleGroup = CircleGroup; 228 /** 229 * Abstract class for creating groups of rects with the same styles and dimensions. 230 * 231 * @class GroupRect 232 * @constructor 233 * @submodule graphics-group 234 */ 235 RectGroup = function() 236 { 237 RectGroup.superclass.constructor.apply(this, arguments); 238 }; 239 240 RectGroup.NAME = "rectGroup"; 241 242 Y.extend(RectGroup, Y.ShapeGroup, { 243 /** 244 * Updates the rect. 245 * 246 * @method _draw 247 * @private 248 */ 249 drawShape: function(cfg) 250 { 251 this.drawRect(cfg.x, cfg.y, cfg.width, cfg.height); 252 } 253 }); 254 255 RectGroup.ATTRS = Y.ShapeGroup.ATTRS; 256 Y.RectGroup = RectGroup; 257 /** 258 * Abstract class for creating groups of diamonds with the same styles and dimensions. 259 * 260 * @class GroupDiamond 261 * @constructor 262 * @submodule graphics-group 263 */ 264 DiamondGroup = function() 265 { 266 DiamondGroup.superclass.constructor.apply(this, arguments); 267 }; 268 269 DiamondGroup.NAME = "diamondGroup"; 270 271 Y.extend(DiamondGroup, Y.ShapeGroup, { 272 /** 273 * Updates the diamond. 274 * 275 * @method _draw 276 * @private 277 */ 278 drawShape: function(cfg) 279 { 280 this.drawDiamond(cfg.x, cfg.y, cfg.width, cfg.height); 281 } 282 }); 283 284 DiamondGroup.ATTRS = Y.ShapeGroup.ATTRS; 285 Y.DiamondGroup = DiamondGroup; 286 /** 287 * Abstract class for creating groups of ellipses with the same styles and dimensions. 288 * 289 * @class EllipseGroup 290 * @constructor 291 * @submodule graphics-group 292 */ 293 EllipseGroup = function() 294 { 295 EllipseGroup.superclass.constructor.apply(this, arguments); 296 }; 297 298 EllipseGroup.NAME = "ellipseGroup"; 299 300 Y.extend(EllipseGroup, Y.ShapeGroup, { 301 /** 302 * Updates the ellipse. 303 * 304 * @method _draw 305 * @private 306 */ 307 drawShape: function(cfg) 308 { 309 this.drawEllipse(cfg.x, cfg.y, cfg.width, cfg.height); 310 } 311 }); 312 313 EllipseGroup.ATTRS = Y.ShapeGroup.ATTRS; 314 Y.EllipseGroup = EllipseGroup; 315 316 317 }, '3.17.2', {"requires": ["graphics"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |