3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('graphics', function(Y) {
11
* <p>The `Graphics` module provides a JavaScript API for creating shapes in a variety of formats across
12
* a <a href="http://developer.yahoo.com/yui/articles/gbs">browser test baseline</a>.
13
* Based on device and browser capabilities, `Graphics` leverages <a href="http://www.w3.org/TR/SVG/">SVG</a>,
14
* <a href="http://www.w3.org/TR/html5/the-canvas-element.html">Canvas</a> and <a href="http://www.w3.org/TR/NOTE-VML">VML</a>
15
* to render its graphical elements.</p>
17
* <p>The `Graphics` module features a <a href="../classes/Graphic.html">`Graphic`</a> class that allows you to easily create and manage shapes.
18
* Currently, a <a href="../classes/Graphic.html">`Graphic`</a> instance can be used to create predifined shapes and free-form polygons with fill
19
* and stroke properties.</p>
21
* <p>The `Graphics` module normalizes an API through the use of alias and implementation classes that share
22
* interfaces. Each alias class points to an appropriate implementation class dependent on the browser's
23
* capabilities. There should rarely, if ever, be a need to interact directly with an implementation class.</p>
25
* <p>Below is a list of available classes.
27
* <li><a href="../classes/Graphic.html">`Graphic`</a>
28
* <li><a href="../classes/Shape.html">`Shape`</a>
29
* <li><a href="../classes/Circle.html">`Circle`</a>
30
* <li><a href="../classes/Ellipse.html">`Ellipse`</a>
31
* <li><a href="../classes/Rect.html">`Rect`</a>
32
* <li><a href="../classes/Path.html">`Path`</a>
34
* You can also extend the `Shape` class to create your own custom shape classes.</p>
38
var SETTER = "setter",
39
PluginHost = Y.Plugin.Host,
42
READONLY = "readOnly",
45
WRITE_ONCE = "writeOnce",
50
* AttributeLite provides Attribute-like getters and setters for shape classes in the Graphics module. It provides a get/set API without the event infastructure.
51
* This class is temporary and a work in progress.
53
* @class AttributeLite
56
AttributeLite = function()
58
var host = this; // help compression
60
// Perf tweak - avoid creating event literals if not required.
61
host._ATTR_E_FACADE = {};
63
Y.EventTarget.call(this, {emitFacade:true});
65
host.prototype = Y.mix(AttributeLite.prototype, host.prototype);
68
AttributeLite.prototype = {
70
* Initializes the attributes for a shape. If an attribute config is passed into the constructor of the host,
71
* the initial values will be overwritten.
74
* @param {Object} cfg Optional object containing attributes key value pairs to be set.
76
addAttrs: function(cfg)
79
attrConfig = this.constructor.ATTRS,
86
if(attrConfig.hasOwnProperty(i))
89
if(attr.hasOwnProperty(VALUE))
91
state[i] = attr.value;
93
else if(attr.hasOwnProperty(VALUEFN))
96
if(Y_LANG.isString(fn))
98
state[i] = host[fn].apply(host);
102
state[i] = fn.apply(host);
110
if(attrConfig.hasOwnProperty(i))
112
attr = attrConfig[i];
113
if(attr.hasOwnProperty(READONLY) && attr.readOnly)
118
if(attr.hasOwnProperty(WRITE_ONCE) && attr.writeOnce)
120
attr.readOnly = true;
123
if(cfg && cfg.hasOwnProperty(i))
125
if(attr.hasOwnProperty(SETTER))
127
host._state[i] = attr.setter.apply(host, [cfg[i]]);
131
host._state[i] = cfg[i];
139
* For a given item, returns the value of the property requested, or undefined if not found.
142
* @param name {String} The name of the item
143
* @return {Any} The value of the supplied property.
149
attrConfig = host.constructor.ATTRS;
150
if(attrConfig && attrConfig[attr])
152
getter = attrConfig[attr].getter;
155
if(typeof getter == STR)
157
return host[getter].apply(host);
159
return attrConfig[attr].getter.apply(host);
162
return host._state[attr];
168
* Sets the value of an attribute.
171
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
172
* be passed in to set multiple attributes at once.
173
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
176
set: function(attr, val)
179
if(Y_LANG.isObject(attr))
183
if(attr.hasOwnProperty(i))
185
this._set(i, attr[i]);
191
this._set.apply(this, arguments);
196
* Provides setter logic. Used by `set`.
199
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
200
* be passed in to set multiple attributes at once.
201
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
205
_set: function(attr, val)
210
attrConfig = host.constructor.ATTRS;
211
if(attrConfig && attrConfig.hasOwnProperty(attr))
213
setter = attrConfig[attr].setter;
217
if(typeof setter == STR)
219
val = host[setter].apply(host, args);
223
val = attrConfig[attr].setter.apply(host, args);
226
host._state[attr] = val;
230
Y.mix(AttributeLite, Y.EventTarget, false, null, 1);
231
Y.AttributeLite = AttributeLite;
234
* GraphicBase serves as the base class for the graphic layer. It serves the same purpose as
235
* Base but uses a lightweight getter/setter class instead of Attribute.
236
* This class is temporary and a work in progress.
240
* @param {Object} cfg Key value pairs for attributes
242
GraphicBase = function(cfg)
245
PluginHost = Y.Plugin && Y.Plugin.Host;
246
if (host._initPlugins && PluginHost) {
247
PluginHost.call(host);
250
host.name = host.constructor.NAME;
251
host._eventPrefix = host.constructor.EVENT_PREFIX || host.constructor.NAME;
252
AttributeLite.call(host);
254
host.init.apply(this, arguments);
255
if (host._initPlugins) {
256
// Need to initPlugins manually, to handle constructor parsing, static Plug parsing
257
host._initPlugins(cfg);
259
host.initialized = true;
262
GraphicBase.NAME = "baseGraphic";
264
GraphicBase.prototype = {
266
* Init method, invoked during construction.
267
* Fires an init event after calling `initializer` on implementers.
274
this.publish("init", {
277
this.initializer.apply(this, arguments);
278
this.fire("init", {cfg: arguments[0]});
281
//Straightup augment, no wrapper functions
282
Y.mix(GraphicBase, Y.AttributeLite, false, null, 1);
283
Y.mix(GraphicBase, PluginHost, false, null, 1);
284
GraphicBase.prototype.constructor = GraphicBase;
285
GraphicBase.plug = PluginHost.plug;
286
GraphicBase.unplug = PluginHost.unplug;
287
Y.GraphicBase = GraphicBase;
291
* `Drawing` provides a set of drawing methods used by `Path` and custom shape classes.
292
* `Drawing` has the following implementations based on browser capability.
294
* <li><a href="SVGDrawing.html">`SVGDrawing`</a></li>
295
* <li><a href="VMLDrawing.html">`VMLDrawing`</a></li>
296
* <li><a href="CanvasDrawing.html">`CanvasDrawing`</a></li>
303
* Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
306
* @param {Number} point1 x-coordinate for the end point.
307
* @param {Number} point2 y-coordinate for the end point.
310
* Moves the current drawing position to specified x and y coordinates.
313
* @param {Number} x x-coordinate for the end point.
314
* @param {Number} y y-coordinate for the end point.
317
* Draws a bezier curve.
320
* @param {Number} cp1x x-coordinate for the first control point.
321
* @param {Number} cp1y y-coordinate for the first control point.
322
* @param {Number} cp2x x-coordinate for the second control point.
323
* @param {Number} cp2y y-coordinate for the second control point.
324
* @param {Number} x x-coordinate for the end point.
325
* @param {Number} y y-coordinate for the end point.
328
* Draws a quadratic bezier curve.
330
* @method quadraticCurveTo
331
* @param {Number} cpx x-coordinate for the control point.
332
* @param {Number} cpy y-coordinate for the control point.
333
* @param {Number} x x-coordinate for the end point.
334
* @param {Number} y y-coordinate for the end point.
340
* @param {Number} x x-coordinate
341
* @param {Number} y y-coordinate
342
* @param {Number} w width
343
* @param {Number} h height
346
* Draws a rectangle with rounded corners.
348
* @method drawRoundRect
349
* @param {Number} x x-coordinate
350
* @param {Number} y y-coordinate
351
* @param {Number} w width
352
* @param {Number} h height
353
* @param {Number} ew width of the ellipse used to draw the rounded corners
354
* @param {Number} eh height of the ellipse used to draw the rounded corners
357
* Completes a drawing operation.
367
* <p>Base class for creating shapes.</p>
368
* <p>`Shape` is an abstract class and is not meant to be used directly. The following classes extend
372
* <li><a href="Circle.html">`Circle`</a></li>
373
* <li><a href="Ellipse.html">`Ellipse`</a></li>
374
* <li><a href="Rect.html">`Rect`</a></li>
375
* <li><a href="Path.html">`Path`</a></li>
378
* `Shape` can also be extended to create custom shape classes.</p>
380
* `Shape` has the following implementations based on browser capability.
382
* <li><a href="SVGShape.html">`SVGShape`</a></li>
383
* <li><a href="VMLShape.html">`VMLShape`</a></li>
384
* <li><a href="CanvasShape.html">`CanvasShape`</a></li>
387
* It is not necessary to interact with these classes directly. `Shape` will point to the appropriate implemention.</p>
391
* @param {Object} cfg (optional) Attribute configs
394
* Init method, invoked during construction.
395
* Calls `initializer` method.
401
* Initializes the shape
404
* @method initializer
407
* Add a class name to each node.
410
* @param {String} className the class name to add to the node's class attribute
413
* Removes a class name from each node.
415
* @method removeClass
416
* @param {String} className the class name to remove from the node's class attribute
419
* Gets the current position of the node in page coordinates.
422
* @return Array The XY position of the shape.
425
* Set the position of the shape in page coordinates, regardless of how the node is positioned.
428
* @param {Array} Contains x & y values for new position (coordinates are page-based)
431
* Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
434
* @param {Shape | HTMLElement} needle The possible node or descendent
435
* @return Boolean Whether or not this shape is the needle or its ancestor.
438
* Compares nodes to determine if they match.
439
* Node instances can be compared to each other and/or HTMLElements.
441
* @param {HTMLElement | Node} refNode The reference node to compare to the node.
442
* @return {Boolean} True if the nodes match, false if they do not.
445
* Test if the supplied node matches the supplied selector.
448
* @param {String} selector The CSS selector to test against.
449
* @return Boolean Wheter or not the shape matches the selector.
452
* Sets the value of an attribute.
455
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
456
* be passed in to set multiple attributes at once.
457
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
461
* Specifies a 2d translation.
464
* @param {Number} x The value to transate on the x-axis.
465
* @param {Number} y The value to translate on the y-axis.
468
* Translates the shape along the x-axis. When translating x and y coordinates,
469
* use the `translate` method.
472
* @param {Number} x The value to translate.
475
* Translates the shape along the y-axis. When translating x and y coordinates,
476
* use the `translate` method.
479
* @param {Number} y The value to translate.
482
* Skews the shape around the x-axis and y-axis.
485
* @param {Number} x The value to skew on the x-axis.
486
* @param {Number} y The value to skew on the y-axis.
489
* Skews the shape around the x-axis.
492
* @param {Number} x x-coordinate
495
* Skews the shape around the y-axis.
498
* @param {Number} y y-coordinate
501
* Rotates the shape clockwise around it transformOrigin.
504
* @param {Number} deg The degree of the rotation.
507
* Specifies a 2d scaling operation.
510
* @param {Number} val
513
* Returns the bounds for a shape.
515
* Calculates the a new bounding box from the original corner coordinates (base on size and position) and the transform matrix.
516
* The calculated bounding box is used by the graphic instance to calculate its viewBox.
522
* Destroys the instance.
527
* An array of x, y values which indicates the transformOrigin in which to rotate the shape. Valid values range between 0 and 1 representing a
528
* fraction of the shape's corresponding bounding box dimension. The default value is [0.5, 0.5].
530
* @config transformOrigin
534
* <p>A string containing, in order, transform operations applied to the shape instance. The `transform` string can contain the following values:
537
* <dt>rotate</dt><dd>Rotates the shape clockwise around it transformOrigin.</dd>
538
* <dt>translate</dt><dd>Specifies a 2d translation.</dd>
539
* <dt>skew</dt><dd>Skews the shape around the x-axis and y-axis.</dd>
540
* <dt>scale</dt><dd>Specifies a 2d scaling operation.</dd>
541
* <dt>translateX</dt><dd>Translates the shape along the x-axis.</dd>
542
* <dt>translateY</dt><dd>Translates the shape along the y-axis.</dd>
543
* <dt>skewX</dt><dd>Skews the shape around the x-axis.</dd>
544
* <dt>skewY</dt><dd>Skews the shape around the y-axis.</dd>
547
* <p>Applying transforms through the transform attribute will reset the transform matrix and apply a new transform. The shape class also contains corresponding methods for each transform
548
* that will apply the transform to the current matrix. The below code illustrates how you might use the `transform` attribute to instantiate a recangle with a rotation of 45 degrees.</p>
549
var myRect = new Y.Rect({
553
transform: "rotate(45)"
555
* <p>The code below would apply `translate` and `rotate` to an existing shape.</p>
557
myRect.set("transform", "translate(40, 50) rotate(45)");
562
* Unique id for class instance.
568
* Indicates the x position of shape.
574
* Indicates the y position of shape.
580
* Indicates the width of the shape
586
* Indicates the height of the shape
592
* Indicates whether the shape is visible.
598
* Contains information about the fill of the shape.
600
* <dt>color</dt><dd>The color of the fill.</dd>
601
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the fill. The default value is 1.</dd>
602
* <dt>type</dt><dd>Type of fill.
604
* <dt>solid</dt><dd>Solid single color fill. (default)</dd>
605
* <dt>linear</dt><dd>Linear gradient fill.</dd>
606
* <dt>radial</dt><dd>Radial gradient fill.</dd>
610
* <p>If a `linear` or `radial` is specified as the fill type. The following additional property is used:
612
* <dt>stops</dt><dd>An array of objects containing the following properties:
614
* <dt>color</dt><dd>The color of the stop.</dd>
615
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the stop. The default value is 1. Note: No effect for IE 6 - 8</dd>
616
* <dt>offset</dt><dd>Number between 0 and 1 indicating where the color stop is positioned.</dd>
619
* <p>Linear gradients also have the following property:</p>
620
* <dt>rotation</dt><dd>Linear gradients flow left to right by default. The rotation property allows you to change the flow by rotation. (e.g. A rotation of 180 would make the gradient pain from right to left.)</dd>
621
* <p>Radial gradients have the following additional properties:</p>
622
* <dt>r</dt><dd>Radius of the gradient circle.</dd>
623
* <dt>fx</dt><dd>Focal point x-coordinate of the gradient.</dd>
624
* <dt>fy</dt><dd>Focal point y-coordinate of the gradient.</dd>
626
* <p>The x-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
627
* <p><strong>Note: </strong>Currently, this property is not implemented for corresponding `CanvasShape` and `VMLShape` classes which are used on Android or IE 6 - 8.</p>
630
* <p>The y-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
631
* <p><strong>Note: </strong>Currently, this property is not implemented for corresponding `CanvasShape` and `VMLShape` classes which are used on Android or IE 6 - 8.</p>
639
* Contains information about the stroke of the shape.
641
* <dt>color</dt><dd>The color of the stroke.</dd>
642
* <dt>weight</dt><dd>Number that indicates the width of the stroke.</dd>
643
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the stroke. The default value is 1.</dd>
644
* <dt>dashstyle</dt>Indicates whether to draw a dashed stroke. When set to "none", a solid stroke is drawn. When set to an array, the first index indicates the
645
* length of the dash. The second index indicates the length of gap.
646
* <dt>linecap</dt><dd>Specifies the linecap for the stroke. The following values can be specified:
648
* <dt>butt (default)</dt><dd>Specifies a butt linecap.</dd>
649
* <dt>square</dt><dd>Specifies a sqare linecap.</dd>
650
* <dt>round</dt><dd>Specifies a round linecap.</dd>
653
* <dt>linejoin</dt><dd>Specifies a linejoin for the stroke. The following values can be specified:
655
* <dt>round (default)</dt><dd>Specifies that the linejoin will be round.</dd>
656
* <dt>bevel</dt><dd>Specifies a bevel for the linejoin.</dd>
657
* <dt>miter limit</dt><dd>An integer specifying the miter limit of a miter linejoin. If you want to specify a linejoin of miter, you simply specify the limit as opposed to having
658
* separate miter and miter limit values.</dd>
667
* Dom node for the shape.
674
* Reference to the parent graphic instance
682
* <p>Creates circle shape with editable attributes.</p>
683
* <p>`Circle` instances can be created using the <a href="Graphic.html#method_addShape">`addShape`</a> method of the <a href="Graphic.html">`Graphic`</a> class.
684
* The method's `cfg` argument contains a `type` attribute. Assigning "circle" or `Y.Circle` to this attribute will create a `Circle` instance. Required attributes
685
* for instantiating a `Circle` are `type` and `radius`. Optional attributes include:
687
* <li><a href="#attr_fill">fill</a></li>
688
* <li><a href="#attr_id">id</a></li>
689
* <li><a href="#attr_stroke">stroke</a></li>
690
* <li><a href="#attr_transform">transform</a></li>
691
* <li><a href="#attr_transformOrigin">transformOrigin</a></li>
692
* <li><a href="#attr_visible">visible</a></li>
693
* <li><a href="#attr_x">x</a></li>
694
* <li><a href="#attr_y">y</a></li>
697
* The below code creates a circle by defining the `type` attribute as "circle":</p>
699
var myCircle = myGraphic.addShape({
711
* Below, this same circle is created by defining the `type` attribute with a class reference:
713
var myCircle = myGraphic.addShape({
725
* <p>`Circle` has the following implementations based on browser capability.
727
* <li><a href="SVGCircle.html">`SVGCircle`</a></li>
728
* <li><a href="VMLCircle.html">`VMLCircle`</a></li>
729
* <li><a href="CanvasCircle.html">`CanvasCircle`</a></li>
732
* It is not necessary to interact with these classes directly. `Circle` will point to the appropriate implemention.</p>
739
* Radius of the circle
745
* <p>Creates an ellipse shape with editable attributes.</p>
746
* <p>`Ellipse` instances can be created using the <a href="Graphic.html#method_addShape">`addShape`</a> method of the <a href="Graphic.html">`Graphic`</a> class.
747
* The method's `cfg` argument contains a `type` attribute. Assigning "ellipse" or `Y.Ellipse` to this attribute will create a `Ellipse` instance. Required attributes
748
* for instantiating a `Ellipse` are `type`, `width` and `height`. Optional attributes include:
750
* <li><a href="#attr_fill">fill</a></li>
751
* <li><a href="#attr_id">id</a></li>
752
* <li><a href="#attr_stroke">stroke</a></li>
753
* <li><a href="#attr_transform">transform</a></li>
754
* <li><a href="#attr_transformOrigin">transformOrigin</a></li>
755
* <li><a href="#attr_visible">visible</a></li>
756
* <li><a href="#attr_x">x</a></li>
757
* <li><a href="#attr_y">y</a></li>
760
* The below code creates an ellipse by defining the `type` attribute as "ellipse":</p>
762
var myEllipse = myGraphic.addShape({
775
* Below, the same ellipse is created by defining the `type` attribute with a class reference:
777
var myEllipse = myGraphic.addShape({
790
* <p>`Ellipse` has the following implementations based on browser capability.
792
* <li><a href="SVGEllipse.html">`SVGEllipse`</a></li>
793
* <li><a href="VMLEllipse.html">`VMLEllipse`</a></li>
794
* <li><a href="CanvasEllipse.html">`CanvasEllipse`</a></li>
797
* It is not necessary to interact with these classes directly. `Ellipse` will point to the appropriate implemention.</p>
804
* <p>Creates an rectangle shape with editable attributes.</p>
805
* <p>`Rect` instances can be created using the <a href="Graphic.html#method_addShape">`addShape`</a> method of the <a href="Graphic.html">`Graphic`</a>
806
* class. The method's `cfg` argument contains a `type` attribute. Assigning "rect" or `Y.Rect` to this attribute will create a `Rect` instance.
807
* Required attributes for instantiating a `Rect` are `type`, `width` and `height`. Optional attributes include:
809
* <li><a href="#attr_fill">fill</a></li>
810
* <li><a href="#attr_id">id</a></li>
811
* <li><a href="#attr_stroke">stroke</a></li>
812
* <li><a href="#attr_transform">transform</a></li>
813
* <li><a href="#attr_transformOrigin">transformOrigin</a></li>
814
* <li><a href="#attr_visible">visible</a></li>
815
* <li><a href="#attr_x">x</a></li>
816
* <li><a href="#attr_y">y</a></li>
819
* The below code creates a rectangle by defining the `type` attribute as "rect":</p>
821
var myRect = myGraphic.addShape({
834
* Below, the same rectangle is created by defining the `type` attribute with a class reference:
836
var myRect = myGraphic.addShape({
849
* <p>`Rect` has the following implementations based on browser capability.
851
* <li><a href="SVGRect.html">`SVGRect`</a></li>
852
* <li><a href="VMLRect.html">`VMLRect`</a></li>
853
* <li><a href="CanvasRect.html">`CanvasRect`</a></li>
856
* It is not necessary to interact with these classes directly. `Rect` will point to the appropriate implemention.</p>
863
* <p>The `Path` class creates a shape through the use of drawing methods. The `Path` class has the following drawing methods available:</p>
865
* <li><a href="#method_clear">`clear`</a></li>
866
* <li><a href="#method_curveTo">`curveTo`</a></li>
867
* <li><a href="#method_drawRect">`drawRect`</a></li>
868
* <li><a href="#method_drawRoundRect">`drawRoundRect`</a></li>
869
* <li><a href="#method_end">`end`</a></li>
870
* <li><a href="#method_lineTo">`lineTo`</a></li>
871
* <li><a href="#method_moveTo">`moveTo`</a></li>
872
* <li><a href="#method_quadraticCurveTo">`quadraticCurveTo`</a></li>
875
* <p>Like other shapes, `Path` elements are created using the <a href="Graphic.html#method_addShape">`addShape`</a> method of the <a href="Graphic.html">`Graphic`</a>
876
* class. The method's `cfg` argument contains a `type` attribute. Assigning "path" or `Y.Path` to this attribute will create a `Path` instance.
877
* After instantiation, a series of drawing operations must be performed in order to render a shape. The below code instantiates a path element by defining the `type`
878
* attribute as "path":</p>
880
var myPath = myGraphic.addShape({
891
* Below a `Path` element with the same properties is instantiated by defining the `type` attribute with a class reference:
893
var myPath = myGraphic.addShape({
904
* After instantiation, a shape or segment needs to be drawn for an element to render. After all draw operations are performed, the <a href="#method_end">`end`</a>
905
* method will render the shape. The code below will draw a triangle:
907
myPath.moveTo(35, 5);
908
myPath.lineTo(65, 65);
909
myPath.lineTo(5, 65);
910
myPath.lineTo(35, 5);
913
* <p>`Path` has the following implementations based on browser capability.
915
* <li><a href="SVGPath.html">`SVGPath`</a></li>
916
* <li><a href="VMLPath.html">`VMLPath`</a></li>
917
* <li><a href="CanvasPath.html">`CanvasPath`</a></li>
919
* It is not necessary to interact with these classes directly. `Path` will point to the appropriate implemention.</p>
927
* Indicates the path used for the node.
934
* `Graphic` acts a factory and container for shapes. You need at least one `Graphic` instance to create shapes for your application.
935
* <p>The code block below creates a `Graphic` instance and appends it to an HTMLElement with the id 'mygraphiccontainer'.</p>
937
var myGraphic = new Y.Graphic({render:"#mygraphiccontainer"});
939
* <p>Alternatively, you can add a `Graphic` instance to the DOM using the <a href="#method_render">`render`</a> method.</p>
940
var myGraphic = new Y.Graphic();
941
myGraphic.render("#mygraphiccontainer");
943
* `Graphic` has the following implementations based on browser capability.
945
* <li><a href="SVGGraphic.html">`SVGGraphic`</a></li>
946
* <li><a href="VMLGraphic.html">`VMLGraphic`</a></li>
947
* <li><a href="CanvasGraphic.html">`CanvasGraphic`</a></li>
950
* It is not necessary to interact with these classes directly. `Graphic` will point to the appropriate implemention.</p>
956
* Whether or not to render the `Graphic` automatically after to a specified parent node after init. This can be a Node instance or a CSS selector string.
959
* @type Node | String
962
* Unique id for class instance.
968
* Key value pairs in which a shape instance is associated with its id.
975
* Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
977
* @config contentBounds
982
* The html element that represents to coordinate system of the Graphic instance.
989
* Indicates the width of the `Graphic`.
995
* Indicates the height of the `Graphic`.
1001
* Determines how the size of instance is calculated. If true, the width and height are determined by the size of the contents.
1002
* If false, the width and height values are either explicitly set or determined by the size of the parent node's dimensions.
1009
* The contentBounds will resize to greater values but not to smaller values. (for performance)
1010
* When resizing the contentBounds down is desirable, set the resizeDown value to true.
1012
* @config resizeDown
1016
* Indicates the x-coordinate for the instance.
1022
* Indicates the y-coordinate for the instance.
1028
* Indicates whether or not the instance will automatically redraw after a change is made to a shape.
1029
* This property will get set to false when batching operations.
1037
* Indicates whether the `Graphic` and its children are visible.
1043
* Gets the current position of the graphic instance in page coordinates.
1046
* @return Array The XY position of the shape.
1049
* Adds the graphics node to the dom.
1052
* @param {Node|String} parentNode node in which to render the graphics node into.
1055
* Removes all nodes.
1060
* <p>Generates a shape instance by type. The method accepts an object that contain's the shape's
1061
* type and attributes to be customized. For example, the code below would create a rectangle:</p>
1063
var myRect = myGraphic.addShape({
1076
* <p>The `Graphics` module includes a few basic shapes. More information on their creation
1077
* can be found in each shape's documentation:
1080
* <li><a href="Circle.html">`Circle`</a></li>
1081
* <li><a href="Ellipse.html">`Ellipse`</a></li>
1082
* <li><a href="Rect.html">`Rect`</a></li>
1083
* <li><a href="Path.html">`Path`</a></li>
1086
* The `Graphics` module also allows for the creation of custom shapes. If a custom shape
1087
* has been created, it can be instantiated with the `addShape` method as well. The attributes,
1088
* required and optional, would need to be defined in the custom shape.
1090
var myCustomShape = myGraphic.addShape({
1091
type: Y.MyCustomShape,
1104
* @param {Object} cfg Object containing the shape's type and attributes.
1108
* Removes a shape instance from from the graphic instance.
1110
* @method removeShape
1111
* @param {Shape|String} shape The instance or id of the shape to be removed.
1114
* Removes all shape instances from the dom.
1116
* @method removeAllShapes
1119
* Returns a shape based on the id of its dom node.
1121
* @method getShapeById
1122
* @param {String} id Dom id of the shape's node attribute.
1126
* Allows for creating multiple shapes in order to batch appending and redraw operations.
1129
* @param {Function} method Method to execute.
1133
}, '3.5.0' ,{requires:['event-custom', 'node', 'pluginhost']});