Shape
is an abstract class and is not meant to be used directly. The following classes extend Shape
.
Shape
can also be extended to create custom shape classes. The Path class creates a shape through the use of drawing methods. The Path class has the following drawing methods available: clear, curveTo, drawRect¸ drawRoundRect, end, lineTo, moveTo, quadraticCurveTo
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":
var myPath = myGraphic.addShape({ type: "path", fill: { color: "#9aa" }, stroke: { weight: 1, color: "#000" } });
Below a Path element with the same properties is instantiated by defining the type attribute with a class reference:
var myPath = myGraphic.addShape({ type: Y.Path, fill: { color: "#9aa" }, stroke: { weight: 1, color: "#000" } });
After instantiation, a shape or segment needs to be drawn for an element to render. After all draw operations are performed, the end method will render the shape. The code below will draw a triangle:
myPath.moveTo(35, 5); myPath.lineTo(65, 65); myPath.lineTo(5, 65); myPath.lineTo(35, 5); myPath.end();@author sg
|
|