The `Graphics` module provides a JavaScript API for creating shapes in a variety of formats across * a browser test baseline. * Based on device and browser capabilities, `Graphics` leverages SVG, * Canvas and VML * to render its graphical elements.
The `Graphics` module features a `Graphic` class that allows you to easily create and manage shapes. * Currently, a `Graphic` instance can be used to create predifined shapes and free-form polygons with fill * and stroke properties.
The `Graphics` module normalizes an API through the use of alias and implementation classes that share * interfaces. Each alias class points to an appropriate implementation class dependent on the browser's * capabilities. There should rarely, if ever, be a need to interact directly with an implementation class.
Below is a list of available classes. *
Base class for creating shapes.
`Shape` is an abstract class and is not meant to be used directly. The following classes extend * `Shape`. * *
A string containing, in order, transform operations applied to the shape instance. The `transform` string can contain the following values: * *
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 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.
The code below would apply `translate` and `rotate` to an existing shape.
If a `linear` or `radial` is specified as the fill type. The following additional property is used: *
Linear gradients also have the following property:
Radial gradients have the following additional properties:
The x-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.
Note: Currently, this property is not implemented for corresponding `CanvasShape` and * `VMLShape` classes which are used on Android or IE 6 - 8.
The y-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.
Note: Currently, this property is not implemented for corresponding `CanvasShape` and `VMLShape` * classes which are used on Android or IE 6 - 8.
Creates circle shape with editable attributes.
`Circle` instances can be created using the `addShape` method of the * `Graphic` class. The method's `cfg` argument contains a `type` attribute. Assigning "circle" * or `Y.Circle` to this attribute will create a `Circle` instance. Required attributes for instantiating a `Circle` are * `type` and `radius`. Optional attributes include: *
`Circle` has the following implementations based on browser capability. *
Creates an ellipse shape with editable attributes.
`Ellipse` instances can be created using the `addShape` method of the * `Graphic` class. The method's `cfg` argument contains a `type` attribute. Assigning "ellipse" * or `Y.Ellipse` to this attribute will create a `Ellipse` instance. Required attributes for instantiating a `Ellipse` are * `type`, `width` and `height`. Optional attributes include: *
`Ellipse` has the following implementations based on browser capability. *
Creates an rectangle shape with editable attributes.
`Rect` instances can be created using the `addShape` method of the * `Graphic` class. The method's `cfg` argument contains a `type` attribute. Assigning "rect" * or `Y.Rect` to this attribute will create a `Rect` instance. Required attributes for instantiating a `Rect` are `type`, * `width` and `height`. Optional attributes include: *
`Rect` has the following implementations based on browser capability. *
The `Path` class creates a shape through the use of drawing methods. The `Path` class has the following drawing methods available:
Like other shapes, `Path` elements are created using the `addShape` * method of the `Graphic` class. The method's `cfg` argument contains a `type` attribute. * Assigning "path" or `Y.Path` to this attribute will create a `Path` instance. 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` attribute as "path":
`Path` has the following implementations based on browser capability. *
The code block below creates a `Graphic` instance and appends it to an HTMLElement with the id 'mygraphiccontainer'.
Alternatively, you can add a `Graphic` instance to the DOM using the `render` method.
width
height
preserveAspectRatio
autoSize
sizeContentToGraphic
Generates a shape instance by type. The method accepts an object that contain's the shape's * type and attributes to be customized. For example, the code below would create a rectangle:
The `Graphics` module includes a few basic shapes. More information on their creation * can be found in each shape's documentation: * *