c93f22e29ce34fa597140835aafff5a770513ad2Jeff Conniff<div class="intro" style="min-height: 184px;">
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <p>
8a9c8f46081091689310524284394f06d22fcbfeJeff Conniff <img src="{{componentAssets}}/img/ship.png" alt="Screencapture of ship drawn with Graphics" style="border: 1px solid #bfbfbf; float:right; height:150px; margin: 0 0 8px 8px; width:275px;">
0fdefaa9ca017edfb76b736c825b34186f33045aTripp The Graphics module provides a JavaScript API for creating shapes in a variety of formats across a <a href="http://developer.yahoo.com/yui/articles/gbs">browser test baseline</a>. Based on device and browser capabilities, Graphics leverages SVG, HTML Canvas and VML to render its graphical elements.
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp 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.
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp</div>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp{{>getting-started}}
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h2 id="using">Using the Graphics module</h2>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>The `Graphic` class acts a factory and container for shapes. You need at least one `Graphic` instance to create shapes for your application.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h3 id="instantiating">Instantiating A Graphic instance</h3>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>All you need to instantiate a Graphic instance is an HTML element in which to render. Alternatively, you can attach your instance to the body of your page.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4>CSS</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp#mygraphiccontainer {
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp width: 600px;
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp height: 400px;
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp}
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4>HTML</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<div id="mygraphiccontainer"></div>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4>JavaScript</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp// Instantiate a graphic instance
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Trippvar mygraphic = new Y.Graphic({
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp render: "#mygraphiccontainer"
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp});
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <p>By default, `Graphic` will size to its parent container. The API also provides the option of explicitly setting its `width` and `height` attributes. Additionally, the Graphic class provides an `autoSize` attribute. When set to true, the Graphic instance will expand to fit its contents.
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h3>Creating shapes</h3>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp<p>Shapes are created using the `addShape` method. The `addShape` method takes a config parameter that defines the shape and its properties. When creating a shape, the shape is determined by the `type`
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Trippattribute. The `Graphics` module includes four pre-defined shapes. They can be created by passing a `String` reference.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>key</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>shape</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>circle</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Y.Circle</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>ellipse</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Y.Ellipse</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>.
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>rect</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Y.Rect</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>path</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Y.Path</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp</table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>Alternatively, you can create your own custom class and pass it directly through the `type` attribute.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>The below code would create a 300x200 rectangle with a blue fill and a red border.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Trippvar mygraphic = new Y.Graphic({render:"#mygraphiccontainer"}),
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp myrect = mygraphic.addShape({
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp type: "rect",
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp width: 300,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp height: 200,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp fill: {
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp color: "#0000ff"
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp },
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp stroke: {
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp weight: 2,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp color: "#ff0000"
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp },
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp x: 50,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp y: 100
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp });
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>This code would create an instance of a custom shape that you have created.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Trippvar mygraphic = new Y.Graphic({render:"#mygraphiccontainer"}),
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp myrect = mygraphic.addShape({
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp type: Y.MyCustomShape,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp width: 300,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp height: 200,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp fill: {
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp color: "#0000ff"
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp },
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp stroke: {
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp weight: 2,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp color: "#ff0000"
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp },
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp x: 50,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp y: 100
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp });
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
bd8602ea6a0a0749b673d9ee28d1ae8d5808175bJeff Conniff<h3>Path Drawing Tool</h3>
bd8602ea6a0a0749b673d9ee28d1ae8d5808175bJeff Conniff{{>graphics-path-tool-promotion}}
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h3 id="aboutgraphic">Working with the Graphic Class</h3>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>The `Graphics` module uses different technologies based on browser capabilities. The `Graphics` module normalizes these different technologies with a consistent API. Ideally, you should not
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripphave to interact directly with the underlying technologies or their corresponding HTML elements. Both the `Graphic` and `Shape` classes provide APIs for sizing, positioning and customization.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4 id="graphicattributes">Graphic Attributes</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>The `Graphic` class exposes the following attributes.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Attribute</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Type</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Description</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`id`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`String`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Unique identifier for the `Graphic` instance. If not explicity set, one will be generated.</td></tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`shapes`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Object`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Key value pairs containing all shape instances contained in the `Graphic` instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`contentBounds`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Object`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Object containing size and coordinate data for the content of a Graphic in relation to the coordinate space of the `Graphic` instance. The following values are included: `top`, `right`, `bottom`, `left`, `width` and `height`.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`node`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`HTMLElement`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Outermost HTMLElement of the `Graphic` instance. (read-only)</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`width`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Number`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>The width of the `Graphic` instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`height`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Number`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>The height of the `Graphic` instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`autoSize`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`boolean`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Determines how the size of instance is calculated. If true, the width and height are determined by the size of the contents. If false, the width and height values are either explicitly set or determined by the size of the parent node's dimensions. The default value is false.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`resizeDown`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`boolean`</td>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <td>The `contentBounds` will resize to greater values but not to smaller values. (for performance) When resizing the `contentBounds` down is desirable, set the resizeDown value to true. The default value is false.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`x`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Number`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Indicates the x-coordinate for the instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`y`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Number`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Indicates the y-coordinate for the instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`autoDraw`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`boolean`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Indicates whether or not the instance will automatically redraw after a change is made to a shape. When performing multiple operations, such adding many shapes, `autoDraw` can be set to false. Calling `_redraw` will force a redraw when `autoDraw` is `false`.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`visible`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`boolean`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Toggles visibility for a `Graphic` instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4 id="graphicmethods">Graphic Methods</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>The `Graphic` class also has the following public methods.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>`Method`</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Description</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>getXY</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Returns an array containing the current position of the graphic instance in page coordinates.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>addShape</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Generates and returns a shape instance by type.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>removeShape</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Removes a shape instance from from the graphic instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>removeAllShapes</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Removes all shape instances</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>destroy</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Destroys the graphic instance and all its children.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>getShapeById</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Returns a shape instance based on an id.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>batch</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Allows for creating multiple shapes in order to batch appending and redraw operations.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h3 id="aboutshapes">Working with Shapes</h3>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4 id="shapeattributes">Shape Attributes</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>Each shape shares a common set of attributes. Attributes shared across all shapes are listed below:</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Attribute</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Type</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Description</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`id`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`String`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Unique identifier for the `Shape` instance. If not explicity set, one will be generated.</td></tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`node`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`HTMLElement`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>HTMLElement of the `Shape` instance. (read-only)</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`x`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Number`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>The x-coordinate of the shape.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`y`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Number`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>The y-coordinate of the shape.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`width`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Number`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>The width of the `Shape` instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`height`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Number`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>The height of the `Shape` instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`visible`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`boolean`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Toggles visibility for a `Shape` instance.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`fill`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Object`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp Contains information about the fill of the shape.
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>stroke</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Object`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp Contains information about the stroke of the shape.
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`transformOrigin`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`Array`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>The x and y values for the transformOrigin of a transform.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <tr>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <td>`transform`</td>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <td>`String`</td>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <td>A string containing, in order, transform operations applied to the shape instance. The `transform` string can contain the following values:
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dl>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dt>rotate</dt><dd>Rotates the shape clockwise around it transformOrigin.</dd>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dt>translate</dt><dd>Specifies a 2d translation.</dd>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dt>skew</dt><dd>Skews the shape around the x-axis and y-axis.</dd>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dt>scale</dt><dd>Specifies a 2d scaling operation.</dd>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dt>translateX</dt><dd>Translates the shape along the x-axis.</dd>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dt>translateY</dt><dd>Translates the shape along the y-axis.</dd>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dt>skewX</dt><dd>Skews the shape around the x-axis.</dd>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp <dt>skewY</dt><dd>Skews the shape around the y-axis.</dd>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp </dl>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp 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
6a3585e2672045e8e28e6a45f279f80aef446959Tripp 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.
6a3585e2672045e8e28e6a45f279f80aef446959Tripp ```
6a3585e2672045e8e28e6a45f279f80aef446959Tripp var myRect = new Y.Rect({
6a3585e2672045e8e28e6a45f279f80aef446959Tripp type:"rect",
6a3585e2672045e8e28e6a45f279f80aef446959Tripp width: 50,
6a3585e2672045e8e28e6a45f279f80aef446959Tripp height: 40,
6a3585e2672045e8e28e6a45f279f80aef446959Tripp transform: "rotate(45)"
6a3585e2672045e8e28e6a45f279f80aef446959Tripp };
6a3585e2672045e8e28e6a45f279f80aef446959Tripp ```
6a3585e2672045e8e28e6a45f279f80aef446959Tripp The code below would apply `translate` and `rotate` to an existing shape.</p>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp ```
6a3585e2672045e8e28e6a45f279f80aef446959Tripp myRect.set("transform", "translate(40, 50) rotate(45)");
6a3585e2672045e8e28e6a45f279f80aef446959Tripp ```
6a3585e2672045e8e28e6a45f279f80aef446959Tripp </td>
6a3585e2672045e8e28e6a45f279f80aef446959Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4 id="shapemethods">Shape Methods</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>Shapes can also be manipulated by the following methods:</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Method</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <th>Description</th>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`addClass`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Adds a class to the underlying HTMLElement.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`removeClass`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Removes a class to the underlying HTMLElement.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`getXY`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Gets the current position of the shape in page coordinates. Returns an array, `[x, y,]`, with the coordinates.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`setXY`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Sets the current position of the shape in page coordinates. Accepts an array, `[x, y]`, with the coordinates.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`get`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Returns the value of a given attribute.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>`set`</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <td>Sets the value of an attribute.</td>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>`rotate`</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>Rotates the shape clockwise around it `transformOrigin`.</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp </tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>`translate`</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>Specifies a 2d translation.</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp </tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>`translateX`</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>Translates the shape along the x-axis.</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp </tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>`translateY`</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>Translates the shape along the y-axis.</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp </tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>`skew`</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>Skews the shape around the x-axis and y-axis.</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp </tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>`skewX`</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>Skews the shape around the x-axis.</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp </tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>`skewY`</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>Skews the shape around the y-axis.</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp </tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <tr>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>`scale`</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <td>Specifies a 2d scaling operation.</td>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp </tr>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp</table>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4 id="drawingmethods">Drawing Methods</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>Unlike the other included shapes, the `Path` class is not pre-defined. Setting the size, fill and/or stroke of a pre-defined shape will render the shape. This is not true with the `Path`. To render
909133170c0bdbed7a7a4a885f39dd32fe961a7cTrippa `Path` instance, its drawing methods need to be leveraged. These drawing methods can also be leveraged when creating custom shapes. Available drawing methods include:
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>moveTo</dt><dd>Moves to a coordinate point without drawing a line.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>lineTo</dt><dd>Draws a line segment from the current point to the specified point.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>curveTo</dt><dd>Draws a curve based on a start point, end point and two control points.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>quadraticCurveTo</dt><dd>Draws a quadratic curve based on a start point, end point and two control points.</dd>
909133170c0bdbed7a7a4a885f39dd32fe961a7cTripp <dt>end</dt><dd>Ends a drawing operation. The path or custom shape will draw after end is called.</dd>
909133170c0bdbed7a7a4a885f39dd32fe961a7cTripp <dt>clear</dt><dd>Clears all contents of a path or custom shape.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp</dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h4 id="strokesandfills">Strokes and Fills</h4>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>All `Shape` instances contain `stroke` and `fill` attributes. They are used to define the colors for a `Shape`.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h5 id="definingstrokes">Defining a Stroke</h5>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp<p>The `stroke` attribute has six properties.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>color</dt><dd>The color of the stroke.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>weight</dt><dd>Number that indicates the width of the stroke.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the stroke. The default value is 1.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <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
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp length of the dash. The second index indicates the length of gap.
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>linecap</dt><dd>Specifies the linecap for the stroke. The following values can be specified:
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dl>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>butt (default)</dt><dd>Specifies a butt linecap.</dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>square</dt><dd>Specifies a sqare linecap.</dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>round</dt><dd>Specifies a round linecap.</dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp </dl>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp </dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>linejoin</dt><dd>Specifies a linejoin for the stroke. The following values can be specified:
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dl>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>round (default)</dt><dd>Specifies that the linejoin will be round.</dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>bevel</dt><dd>Specifies a bevel for the linejoin.</dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <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
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp separate miter and miter limit values.</dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp </dl>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp </dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>The code below would set a 2 pixel solid red stroke on `myshape`.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp myshape.set("stroke", {
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp color: "#ff0000",
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp weight: 2
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp });
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>The `dashstyle` property can be used to create a dashed stroke on a shape.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp myshape.set("stroke", {
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp color: "#ff0000",
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp weight: 2,
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp dashstyle: [3, 2]
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp });
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp```
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h5 id="definingfills">Defining a Fill</h5>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>The `fill` attribute has the following properties.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>color</dt><dd>The color of the fill.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>opacity</dt><dd>Number between 0 and 1 that indicates the opacity of the fill. The default value is 1.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>type</dt><dd>Type of fill.
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>solid</dt><dd>Solid single color fill. (default)</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>linear</dt><dd>Linear gradient fill.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>radial</dt><dd>Radial gradient fill.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<p>If a `linear` or `radial` is specified as the fill type. The following additional property is used:
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>stops</dt><dd>An array of objects containing the following properties:
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>color</dt><dd>The color of the stop.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <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 <= 8</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>offset</dt><dd>Number between 0 and 1 indicating where the color stop is positioned.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </dl>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <p>Linear gradients also have the following property:</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <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>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <p>Radial gradients have the following additional properties:</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>r</dt><dd>Radius of the gradient circle.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>fx</dt><dd>Focal point x-coordinate of the gradient.</dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <dt>fy</dt><dd>Focal point y-coordinate of the gradient.</dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>cx</dt><dd>The x-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <p><strong>Note: </strong>This property currently has no effect on Android or IE 6 - 8.</p>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp </dd>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <dt>cy</dt><dd>The y-coordinate of the center of the gradient circle. Determines where the color stop begins. The default value 0.5.
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <p><strong>Note: </strong>This property currently has no effect on Android or IE 6 - 8.</p>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp </dd>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </dl>
3b28a6cd6294fa40166327b097529ae5da1698ceJeff Conniff<h3>Radial Gradient Tool</h3>
3b28a6cd6294fa40166327b097529ae5da1698ceJeff Conniff{{>graphics-radial-tool-promotion}}
3b28a6cd6294fa40166327b097529ae5da1698ceJeff Conniff
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<h2 id="issues">Known Issues</h2>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp<ul class="spaced">
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <li>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <p>Gradients need more need more normalization across technologies. Certain gradient types have limitations on different browsers.
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp </p>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <ul>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <li>Radial gradients contain the properties `cx` and `cy`. These properties currently have no impact on Android or IE 6 - 8.</li>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp <li>After being initially set, gradients cannot be updated in IE 6 - 8.</li>
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp </ul>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </li>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp <li>
d1a404610f53bdff63cde29a00ea9cf48739d91eTripp <p>Path element currently lacks the ability to have interactivity in Android.</p>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp </li>
5e878519d1a8afcc3b0c5d9aa68d4751ed294c86Tripp</ul>