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