3
Copyright 2011 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",
51
* Matrix is a class that allows for the manipulation of a transform matrix.
52
* This class is a work in progress.
57
Matrix = function(config) {
63
* Used as value for the _rounding method.
81
multiply: function(a, b, c, d, dx, dy) {
83
matrix_a = matrix.a * a + matrix.c * b,
84
matrix_b = matrix.b * a + matrix.d * b,
85
matrix_c = matrix.a * c + matrix.c * d,
86
matrix_d = matrix.b * c + matrix.d * d,
87
matrix_dx = matrix.a * dx + matrix.c * dy + matrix.dx,
88
matrix_dy = matrix.b * dx + matrix.d * dy + matrix.dy;
94
matrix.dx = matrix_dx;
95
matrix.dy = matrix_dy;
100
* Parses a string and updates the matrix.
102
* @method applyCSSText
103
* @param {String} val A css transform string
105
applyCSSText: function(val) {
106
var re = /\s*([a-z]*)\(([\w,\s]*)\)/gi,
110
while ((m = re.exec(val))) {
111
if (typeof this[m[1]] === 'function') {
112
args = m[2].split(',');
114
this[m[1]].apply(this, args);
120
* Parses a string and returns an array of transform arrays.
122
* @method applyCSSText
123
* @param {String} val A css transform string
126
getTransformArray: function(val) {
127
var re = /\s*([a-z]*)\(([\w,\s]*)\)/gi,
132
while ((m = re.exec(val))) {
133
if (typeof this[m[1]] === 'function') {
134
args = m[2].split(',');
136
transforms.push(args);
143
* Default values for the matrix
145
* @property _defaults
163
_round: function(val) {
164
val = Math.round(val * this._rounder) / this._rounder;
169
* Initializes a matrix.
172
* @param {Object} config Specified key value pairs for matrix properties. If a property is not explicitly defined in the config argument,
173
* the default value will be used.
175
init: function(config) {
176
var defaults = this._defaults,
179
config = config || {};
181
for (prop in defaults) {
182
if(defaults.hasOwnProperty(prop))
184
this[prop] = (prop in config) ? config[prop] : defaults[prop];
188
this._config = config;
192
* Applies a scale transform
195
* @param {Number} val
197
scale: function(x, y) {
198
this.multiply(x, 0, 0, y, 0, 0);
203
* Applies a skew transformation.
206
* @param {Number} x The value to skew on the x-axis.
207
* @param {Number} y The value to skew on the y-axis.
209
skew: function(x, y) {
213
if (x !== undefined) { // null or undef
214
x = this._round(Math.tan(this.angle2rad(x)));
218
if (y !== undefined) { // null or undef
219
y = this._round(Math.tan(this.angle2rad(y)));
222
this.multiply(1, y, x, 1, 0, 0);
227
* Applies a skew to the x-coordinate
230
* @param {Number} x x-coordinate
238
* Applies a skew to the y-coordinate
241
* @param {Number} y y-coordinate
249
* Returns a string of text that can be used to populate a the css transform property of an element.
254
toCSSText: function() {
261
if (Y.UA.gecko) { // requires unit
270
text += matrix.a + ',' +
283
* Returns a string that can be used to populate the css filter property of an element.
285
* @method toFilterText
288
toFilterText: function() {
290
text = 'progid:DXImageTransform.Microsoft.Matrix(';
291
text += 'M11=' + matrix.a + ',' +
292
'M21=' + matrix.b + ',' +
293
'M12=' + matrix.c + ',' +
294
'M22=' + matrix.d + ',' +
295
'sizingMethod="auto expand")';
303
* Converts a radian value to a degree.
306
* @param {Number} rad Radian value to be converted.
309
rad2deg: function(rad) {
310
var deg = rad * (180 / Math.PI);
315
* Converts a degree value to a radian.
318
* @param {Number} deg Degree value to be converted to radian.
321
deg2rad: function(deg) {
322
var rad = deg * (Math.PI / 180);
326
angle2rad: function(val) {
327
if (typeof val === 'string' && val.indexOf('rad') > -1) {
328
val = parseFloat(val);
329
} else { // default to deg
330
val = this.deg2rad(parseFloat(val));
337
* Applies a rotate transform.
340
* @param {Number} deg The degree of the rotation.
342
rotate: function(deg, x, y) {
344
rad = this.angle2rad(deg),
345
sin = this._round(Math.sin(rad)),
346
cos = this._round(Math.cos(rad));
347
this.multiply(cos, sin, 0 - sin, cos, 0, 0);
352
* Applies translate transformation.
355
* @param {Number} x The value to transate on the x-axis.
356
* @param {Number} y The value to translate on the y-axis.
358
translate: function(x, y) {
359
this.multiply(1, 0, 0, 1, parseFloat(x), parseFloat(y));
366
* AttributeLite provides Attribute-like getters and setters for shape classes in the Graphics module. It provides a get/set API without the event infastructure.
367
* This class is temporary and a work in progress.
369
* @class AttributeLite
372
AttributeLite = function()
374
var host = this; // help compression
376
// Perf tweak - avoid creating event literals if not required.
377
host._ATTR_E_FACADE = {};
379
Y.EventTarget.call(this, {emitFacade:true});
381
host.prototype = Y.mix(AttributeLite.prototype, host.prototype);
384
AttributeLite.prototype = {
386
* Initializes the attributes for a shape. If an attribute config is passed into the constructor of the host,
387
* the initial values will be overwritten.
390
* @param {Object} cfg Optional object containing attributes key value pairs to be set.
392
addAttrs: function(cfg)
395
attrConfig = this.constructor.ATTRS,
402
if(attrConfig.hasOwnProperty(i))
404
attr = attrConfig[i];
405
if(attr.hasOwnProperty(VALUE))
407
state[i] = attr.value;
409
else if(attr.hasOwnProperty(VALUEFN))
412
if(Y_LANG.isString(fn))
414
state[i] = host[fn].apply(host);
418
state[i] = fn.apply(host);
426
if(attrConfig.hasOwnProperty(i))
428
attr = attrConfig[i];
429
if(attr.hasOwnProperty(READONLY) && attr.readOnly)
434
if(attr.hasOwnProperty(WRITE_ONCE) && attr.writeOnce)
436
attr.readOnly = true;
439
if(cfg && cfg.hasOwnProperty(i))
441
if(attr.hasOwnProperty(SETTER))
443
host._state[i] = attr.setter.apply(host, [cfg[i]]);
447
host._state[i] = cfg[i];
455
* For a given item, returns the value of the property requested, or undefined if not found.
458
* @param name {String} The name of the item
459
* @return {Any} The value of the supplied property.
465
attrConfig = host.constructor.ATTRS;
466
if(attrConfig && attrConfig[attr])
468
getter = attrConfig[attr].getter;
471
if(typeof getter == STR)
473
return host[getter].apply(host);
475
return attrConfig[attr].getter.apply(host);
478
return host._state[attr];
484
* Sets the value of an attribute.
487
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
488
* be passed in to set multiple attributes at once.
489
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
492
set: function(attr, val)
495
if(Y_LANG.isObject(attr))
499
if(attr.hasOwnProperty(i))
501
this._set(i, attr[i]);
507
this._set.apply(this, arguments);
512
* Provides setter logic. Used by `set`.
515
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
516
* be passed in to set multiple attributes at once.
517
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
521
_set: function(attr, val)
526
attrConfig = host.constructor.ATTRS;
527
if(attrConfig && attrConfig.hasOwnProperty(attr))
529
setter = attrConfig[attr].setter;
533
if(typeof setter == STR)
535
val = host[setter].apply(host, args);
539
val = attrConfig[attr].setter.apply(host, args);
542
host._state[attr] = val;
546
Y.mix(AttributeLite, Y.EventTarget, false, null, 1);
547
Y.AttributeLite = AttributeLite;
550
* BaseGraphic serves as the base class for the graphic layer. It serves the same purpose as
551
* Base but uses a lightweight getter/setter class instead of Attribute.
552
* This class is temporary and a work in progress.
556
* @param {Object} cfg Key value pairs for attributes
558
BaseGraphic = function(cfg)
561
PluginHost = Y.Plugin && Y.Plugin.Host;
562
if (host._initPlugins && PluginHost) {
563
PluginHost.call(host);
566
host.name = host.constructor.NAME;
567
host._eventPrefix = host.constructor.EVENT_PREFIX || host.constructor.NAME;
568
AttributeLite.call(host);
570
host.init.apply(this, arguments);
571
if (host._initPlugins) {
572
// Need to initPlugins manually, to handle constructor parsing, static Plug parsing
573
host._initPlugins(cfg);
575
host.initialized = true;
578
BaseGraphic.NAME = "baseGraphic";
580
BaseGraphic.prototype = {
582
* Init method, invoked during construction.
583
* Fires an init event after calling `initializer` on implementers.
590
this.publish("init", {
593
this.initializer.apply(this, arguments);
594
this.fire("init", {cfg: arguments[0]});
597
//Straightup augment, no wrapper functions
598
Y.mix(BaseGraphic, Y.AttributeLite, false, null, 1);
599
Y.mix(BaseGraphic, PluginHost, false, null, 1);
600
BaseGraphic.prototype.constructor = BaseGraphic;
601
BaseGraphic.plug = PluginHost.plug;
602
BaseGraphic.unplug = PluginHost.unplug;
603
Y.BaseGraphic = BaseGraphic;
607
* `Drawing` provides a set of drawing methods used by `Path` and custom shape classes.
608
* `Drawing` has the following implementations based on browser capability.
610
* <li><a href="SVGDrawing.html">`SVGDrawing`</a></li>
611
* <li><a href="VMLDrawing.html">`VMLDrawing`</a></li>
612
* <li><a href="CanvasDrawing.html">`CanvasDrawing`</a></li>
619
* Draws a line segment using the current line style from the current drawing position to the specified x and y coordinates.
622
* @param {Number} point1 x-coordinate for the end point.
623
* @param {Number} point2 y-coordinate for the end point.
626
* Moves the current drawing position to specified x and y coordinates.
629
* @param {Number} x x-coordinate for the end point.
630
* @param {Number} y y-coordinate for the end point.
633
* Draws a bezier curve.
636
* @param {Number} cp1x x-coordinate for the first control point.
637
* @param {Number} cp1y y-coordinate for the first control point.
638
* @param {Number} cp2x x-coordinate for the second control point.
639
* @param {Number} cp2y y-coordinate for the second control point.
640
* @param {Number} x x-coordinate for the end point.
641
* @param {Number} y y-coordinate for the end point.
644
* Draws a quadratic bezier curve.
646
* @method quadraticCurveTo
647
* @param {Number} cpx x-coordinate for the control point.
648
* @param {Number} cpy y-coordinate for the control point.
649
* @param {Number} x x-coordinate for the end point.
650
* @param {Number} y y-coordinate for the end point.
656
* @param {Number} x x-coordinate
657
* @param {Number} y y-coordinate
658
* @param {Number} w width
659
* @param {Number} h height
662
* Draws a rectangle with rounded corners.
664
* @method drawRoundRect
665
* @param {Number} x x-coordinate
666
* @param {Number} y y-coordinate
667
* @param {Number} w width
668
* @param {Number} h height
669
* @param {Number} ew width of the ellipse used to draw the rounded corners
670
* @param {Number} eh height of the ellipse used to draw the rounded corners
673
* Completes a drawing operation.
683
* <p>Base class for creating shapes.</p>
684
* <p>`Shape` is an abstract class and is not meant to be used directly. The following classes extend
688
* <li><a href="Circle.html">`Circle`</a></li>
689
* <li><a href="Ellipse.html">`Ellipse`</a></li>
690
* <li><a href="Rect.html">`Rect`</a></li>
691
* <li><a href="Path.html">`Path`</a></li>
694
* `Shape` can also be extended to create custom shape classes.</p>
696
* `Shape` has the following implementations based on browser capability.
698
* <li><a href="SVGShape.html">`SVGShape`</a></li>
699
* <li><a href="VMLShape.html">`VMLShape`</a></li>
700
* <li><a href="CanvasShape.html">`CanvasShape`</a></li>
703
* It is not necessary to interact with these classes directly. `Shape` will point to the appropriate implemention.</p>
707
* @param {Object} cfg (optional) Attribute configs
710
* Init method, invoked during construction.
711
* Calls `initializer` method.
717
* Initializes the shape
720
* @method initializer
723
* Add a class name to each node.
726
* @param {String} className the class name to add to the node's class attribute
729
* Removes a class name from each node.
731
* @method removeClass
732
* @param {String} className the class name to remove from the node's class attribute
735
* Gets the current position of the node in page coordinates.
738
* @return Array The XY position of the shape.
741
* Set the position of the shape in page coordinates, regardless of how the node is positioned.
744
* @param {Array} Contains x & y values for new position (coordinates are page-based)
747
* Determines whether the node is an ancestor of another HTML element in the DOM hierarchy.
750
* @param {Shape | HTMLElement} needle The possible node or descendent
751
* @return Boolean Whether or not this shape is the needle or its ancestor.
754
* Compares nodes to determine if they match.
755
* Node instances can be compared to each other and/or HTMLElements.
757
* @param {HTMLElement | Node} refNode The reference node to compare to the node.
758
* @return {Boolean} True if the nodes match, false if they do not.
761
* Test if the supplied node matches the supplied selector.
764
* @param {String} selector The CSS selector to test against.
765
* @return Boolean Wheter or not the shape matches the selector.
768
* Sets the value of an attribute.
771
* @param {String|Object} name The name of the attribute. Alternatively, an object of key value pairs can
772
* be passed in to set multiple attributes at once.
773
* @param {Any} value The value to set the attribute to. This value is ignored if an object is received as
777
* Specifies a 2d translation.
780
* @param {Number} x The value to transate on the x-axis.
781
* @param {Number} y The value to translate on the y-axis.
784
* Translates the shape along the x-axis. When translating x and y coordinates,
785
* use the `translate` method.
788
* @param {Number} x The value to translate.
791
* Translates the shape along the y-axis. When translating x and y coordinates,
792
* use the `translate` method.
795
* @param {Number} y The value to translate.
798
* Skews the shape around the x-axis and y-axis.
801
* @param {Number} x The value to skew on the x-axis.
802
* @param {Number} y The value to skew on the y-axis.
805
* Skews the shape around the x-axis.
808
* @param {Number} x x-coordinate
811
* Skews the shape around the y-axis.
814
* @param {Number} y y-coordinate
817
* Rotates the shape clockwise around it transformOrigin.
820
* @param {Number} deg The degree of the rotation.
823
* Specifies a 2d scaling operation.
826
* @param {Number} val
829
* Returns the bounds for a shape.
831
* Calculates the a new bounding box from the original corner coordinates (base on size and position) and the transform matrix.
832
* The calculated bounding box is used by the graphic instance to calculate its viewBox.
838
* Destroys the instance.
843
* 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
844
* fraction of the shape's corresponding bounding box dimension. The default value is [0.5, 0.5].
846
* @config transformOrigin
850
* <p>A string containing, in order, transform operations applied to the shape instance. The `transform` string can contain the following values:
853
* <dt>rotate</dt><dd>Rotates the shape clockwise around it transformOrigin.</dd>
854
* <dt>translate</dt><dd>Specifies a 2d translation.</dd>
855
* <dt>skew</dt><dd>Skews the shape around the x-axis and y-axis.</dd>
856
* <dt>scale</dt><dd>Specifies a 2d scaling operation.</dd>
857
* <dt>translateX</dt><dd>Translates the shape along the x-axis.</dd>
858
* <dt>translateY</dt><dd>Translates the shape along the y-axis.</dd>
859
* <dt>skewX</dt><dd>Skews the shape around the x-axis.</dd>
860
* <dt>skewY</dt><dd>Skews the shape around the y-axis.</dd>
863
* <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
864
* 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>
865
var myRect = new Y.Rect({
869
transform: "rotate(45)"
871
* <p>The code below would apply `translate` and `rotate` to an existing shape.</p>
873
myRect.set("transform", "translate(40, 50) rotate(45)");
878
* Unique id for class instance.
884
* Indicates the x position of shape.
890
* Indicates the y position of shape.
896
* Indicates the width of the shape
902
* Indicates the height of the shape
908
* Indicates whether the shape is visible.
914
* Contains information about the fill of the shape.
916
* <dt>color</dt><dd>The color of the fill.</dd>
917
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the fill. The default value is 1.</dd>
918
* <dt>type</dt><dd>Type of fill.
920
* <dt>solid</dt><dd>Solid single color fill. (default)</dd>
921
* <dt>linear</dt><dd>Linear gradient fill.</dd>
922
* <dt>radial</dt><dd>Radial gradient fill.</dd>
926
* <p>If a `linear` or `radial` is specified as the fill type. The following additional property is used:
928
* <dt>stops</dt><dd>An array of objects containing the following properties:
930
* <dt>color</dt><dd>The color of the stop.</dd>
931
* <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>
932
* <dt>offset</dt><dd>Number between 0 and 1 indicating where the color stop is positioned.</dd>
935
* <p>Linear gradients also have the following property:</p>
936
* <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>
937
* <p>Radial gradients have the following additional properties:</p>
938
* <dt>r</dt><dd>Radius of the gradient circle.</dd>
939
* <dt>fx</dt><dd>Focal point x-coordinate of the gradient.</dd>
940
* <dt>fy</dt><dd>Focal point y-coordinate of the gradient.</dd>
942
* <p>The x-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
943
* <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>
946
* <p>The y-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.</p>
947
* <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>
955
* Contains information about the stroke of the shape.
957
* <dt>color</dt><dd>The color of the stroke.</dd>
958
* <dt>weight</dt><dd>Number that indicates the width of the stroke.</dd>
959
* <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the stroke. The default value is 1.</dd>
960
* <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
961
* length of the dash. The second index indicates the length of gap.
962
* <dt>linecap</dt><dd>Specifies the linecap for the stroke. The following values can be specified:
964
* <dt>butt (default)</dt><dd>Specifies a butt linecap.</dd>
965
* <dt>square</dt><dd>Specifies a sqare linecap.</dd>
966
* <dt>round</dt><dd>Specifies a round linecap.</dd>
969
* <dt>linejoin</dt><dd>Specifies a linejoin for the stroke. The following values can be specified:
971
* <dt>round (default)</dt><dd>Specifies that the linejoin will be round.</dd>
972
* <dt>bevel</dt><dd>Specifies a bevel for the linejoin.</dd>
973
* <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
974
* separate miter and miter limit values.</dd>
983
* Dom node for the shape.
990
* Reference to the parent graphic instance
998
* <p>Creates circle shape with editable attributes.</p>
999
* <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.
1000
* The method's `cfg` argument contains a `type` attribute. Assigning "circle" or `Y.Circle` to this attribute will create a `Circle` instance. Required attributes
1001
* for instantiating a `Circle` are `type` and `radius`. Optional attributes include:
1003
* <li><a href="#attr_fill">fill</a></li>
1004
* <li><a href="#attr_id">id</a></li>
1005
* <li><a href="#attr_stroke">stroke</a></li>
1006
* <li><a href="#attr_transform">transform</a></li>
1007
* <li><a href="#attr_transformOrigin">transformOrigin</a></li>
1008
* <li><a href="#attr_visible">visible</a></li>
1009
* <li><a href="#attr_x">x</a></li>
1010
* <li><a href="#attr_y">y</a></li>
1013
* The below code creates a circle by defining the `type` attribute as "circle":</p>
1015
var myCircle = myGraphic.addShape({
1027
* Below, this same circle is created by defining the `type` attribute with a class reference:
1029
var myCircle = myGraphic.addShape({
1041
* <p>`Circle` has the following implementations based on browser capability.
1043
* <li><a href="SVGCircle.html">`SVGCircle`</a></li>
1044
* <li><a href="VMLCircle.html">`VMLCircle`</a></li>
1045
* <li><a href="CanvasCircle.html">`CanvasCircle`</a></li>
1048
* It is not necessary to interact with these classes directly. `Circle` will point to the appropriate implemention.</p>
1055
* Radius of the circle
1061
* <p>Creates an ellipse shape with editable attributes.</p>
1062
* <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.
1063
* The method's `cfg` argument contains a `type` attribute. Assigning "ellipse" or `Y.Ellipse` to this attribute will create a `Ellipse` instance. Required attributes
1064
* for instantiating a `Ellipse` are `type`, `width` and `height`. Optional attributes include:
1066
* <li><a href="#attr_fill">fill</a></li>
1067
* <li><a href="#attr_id">id</a></li>
1068
* <li><a href="#attr_stroke">stroke</a></li>
1069
* <li><a href="#attr_transform">transform</a></li>
1070
* <li><a href="#attr_transformOrigin">transformOrigin</a></li>
1071
* <li><a href="#attr_visible">visible</a></li>
1072
* <li><a href="#attr_x">x</a></li>
1073
* <li><a href="#attr_y">y</a></li>
1076
* The below code creates an ellipse by defining the `type` attribute as "ellipse":</p>
1078
var myEllipse = myGraphic.addShape({
1091
* Below, the same ellipse is created by defining the `type` attribute with a class reference:
1093
var myEllipse = myGraphic.addShape({
1106
* <p>`Ellipse` has the following implementations based on browser capability.
1108
* <li><a href="SVGEllipse.html">`SVGEllipse`</a></li>
1109
* <li><a href="VMLEllipse.html">`VMLEllipse`</a></li>
1110
* <li><a href="CanvasEllipse.html">`CanvasEllipse`</a></li>
1113
* It is not necessary to interact with these classes directly. `Ellipse` will point to the appropriate implemention.</p>
1120
* <p>Creates an rectangle shape with editable attributes.</p>
1121
* <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>
1122
* class. The method's `cfg` argument contains a `type` attribute. Assigning "rect" or `Y.Rect` to this attribute will create a `Rect` instance.
1123
* Required attributes for instantiating a `Rect` are `type`, `width` and `height`. Optional attributes include:
1125
* <li><a href="#attr_fill">fill</a></li>
1126
* <li><a href="#attr_id">id</a></li>
1127
* <li><a href="#attr_stroke">stroke</a></li>
1128
* <li><a href="#attr_transform">transform</a></li>
1129
* <li><a href="#attr_transformOrigin">transformOrigin</a></li>
1130
* <li><a href="#attr_visible">visible</a></li>
1131
* <li><a href="#attr_x">x</a></li>
1132
* <li><a href="#attr_y">y</a></li>
1135
* The below code creates a rectangle by defining the `type` attribute as "rect":</p>
1137
var myRect = myGraphic.addShape({
1150
* Below, the same rectangle is created by defining the `type` attribute with a class reference:
1152
var myRect = myGraphic.addShape({
1165
* <p>`Rect` has the following implementations based on browser capability.
1167
* <li><a href="SVGRect.html">`SVGRect`</a></li>
1168
* <li><a href="VMLRect.html">`VMLRect`</a></li>
1169
* <li><a href="CanvasRect.html">`CanvasRect`</a></li>
1172
* It is not necessary to interact with these classes directly. `Rect` will point to the appropriate implemention.</p>
1179
* <p>The `Path` class creates a shape through the use of drawing methods. The `Path` class has the following drawing methods available:</p>
1181
* <li><a href="#method_clear">`clear`</a></li>
1182
* <li><a href="#method_curveTo">`curveTo`</a></li>
1183
* <li><a href="#method_drawRect">`drawRect`</a></li>
1184
* <li><a href="#method_drawRoundRect">`drawRoundRect`</a></li>
1185
* <li><a href="#method_end">`end`</a></li>
1186
* <li><a href="#method_lineTo">`lineTo`</a></li>
1187
* <li><a href="#method_moveTo">`moveTo`</a></li>
1188
* <li><a href="#method_quadraticCurveTo">`quadraticCurveTo`</a></li>
1191
* <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>
1192
* class. The method's `cfg` argument contains a `type` attribute. Assigning "path" or `Y.Path` to this attribute will create a `Path` instance.
1193
* 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`
1194
* attribute as "path":</p>
1196
var myPath = myGraphic.addShape({
1207
* Below a `Path` element with the same properties is instantiated by defining the `type` attribute with a class reference:
1209
var myPath = myGraphic.addShape({
1220
* 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>
1221
* method will render the shape. The code below will draw a triangle:
1223
myPath.moveTo(35, 5);
1224
myPath.lineTo(65, 65);
1225
myPath.lineTo(5, 65);
1226
myPath.lineTo(35, 5);
1229
* <p>`Path` has the following implementations based on browser capability.
1231
* <li><a href="SVGPath.html">`SVGPath`</a></li>
1232
* <li><a href="VMLPath.html">`VMLPath`</a></li>
1233
* <li><a href="CanvasPath.html">`CanvasPath`</a></li>
1235
* It is not necessary to interact with these classes directly. `Path` will point to the appropriate implemention.</p>
1243
* Indicates the path used for the node.
1250
* `Graphic` acts a factory and container for shapes. You need at least one `Graphic` instance to create shapes for your application.
1251
* <p>The code block below creates a `Graphic` instance and appends it to an HTMLElement with the id 'mygraphiccontainer'.</p>
1253
var myGraphic = new Y.Graphic({render:"#mygraphiccontainer"});
1255
* <p>Alternatively, you can add a `Graphic` instance to the DOM using the <a href="#method_render">`render`</a> method.</p>
1256
var myGraphic = new Y.Graphic();
1257
myGraphic.render("#mygraphiccontainer");
1259
* `Graphic` has the following implementations based on browser capability.
1261
* <li><a href="SVGGraphic.html">`SVGGraphic`</a></li>
1262
* <li><a href="VMLGraphic.html">`VMLGraphic`</a></li>
1263
* <li><a href="CanvasGraphic.html">`CanvasGraphic`</a></li>
1266
* It is not necessary to interact with these classes directly. `Graphic` will point to the appropriate implemention.</p>
1272
* 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.
1275
* @type Node | String
1278
* Unique id for class instance.
1284
* Key value pairs in which a shape instance is associated with its id.
1291
* Object containing size and coordinate data for the content of a Graphic in relation to the coordSpace node.
1293
* @config contentBounds
1298
* The html element that represents to coordinate system of the Graphic instance.
1305
* Indicates the width of the `Graphic`.
1311
* Indicates the height of the `Graphic`.
1317
* Determines how the size of instance is calculated. If true, the width and height are determined by the size of the contents.
1318
* If false, the width and height values are either explicitly set or determined by the size of the parent node's dimensions.
1325
* The contentBounds will resize to greater values but not to smaller values. (for performance)
1326
* When resizing the contentBounds down is desirable, set the resizeDown value to true.
1328
* @config resizeDown
1332
* Indicates the x-coordinate for the instance.
1338
* Indicates the y-coordinate for the instance.
1344
* Indicates whether or not the instance will automatically redraw after a change is made to a shape.
1345
* This property will get set to false when batching operations.
1353
* Indicates whether the `Graphic` and its children are visible.
1359
* Gets the current position of the graphic instance in page coordinates.
1362
* @return Array The XY position of the shape.
1365
* Adds the graphics node to the dom.
1368
* @param {Node|String} parentNode node in which to render the graphics node into.
1371
* Removes all nodes.
1376
* <p>Generates a shape instance by type. The method accepts an object that contain's the shape's
1377
* type and attributes to be customized. For example, the code below would create a rectangle:</p>
1379
var myRect = myGraphic.addShape({
1392
* <p>The `Graphics` module includes a few basic shapes. More information on their creation
1393
* can be found in each shape's documentation:
1396
* <li><a href="Circle.html">`Circle`</a></li>
1397
* <li><a href="Ellipse.html">`Ellipse`</a></li>
1398
* <li><a href="Rect.html">`Rect`</a></li>
1399
* <li><a href="Path.html">`Path`</a></li>
1402
* The `Graphics` module also allows for the creation of custom shapes. If a custom shape
1403
* has been created, it can be instantiated with the `addShape` method as well. The attributes,
1404
* required and optional, would need to be defined in the custom shape.
1406
var myCustomShape = myGraphic.addShape({
1407
type: Y.MyCustomShape,
1420
* @param {Object} cfg Object containing the shape's type and attributes.
1424
* Removes a shape instance from from the graphic instance.
1426
* @method removeShape
1427
* @param {Shape|String} shape The instance or id of the shape to be removed.
1430
* Removes all shape instances from the dom.
1432
* @method removeAllShapes
1435
* Returns a shape based on the id of its dom node.
1437
* @method getShapeById
1438
* @param {String} id Dom id of the shape's node attribute.
1442
* Allows for creating multiple shapes in order to batch appending and redraw operations.
1445
* @param {Function} method Method to execute.
1449
}, '3.4.1' ,{requires:['event-custom', 'node', 'pluginhost']});