graphics-customshape.mustache revision d676c69348c891c2a261a6dbd4f450ddb2e312f3
2N/A#pagetitle {background-image: url(../../assets/bg_hd.gif);}
2N/AThis example shows how to use the `Graphics` to create a custom shape. Currently, the `Graphics` module has four shapes:
2N/AYou can also create your own custom shapes. If you need to have reusable shapes, you can do this by extending the `Shape` class. Once you have created a custom class, you can instantiate it by passing
2N/Aa reference of your class in the `type` attribute of your config to the `addShape` method. In this example, we will create shape called `RoundedRect`.
2N/A<p>Create a custom class. When creating shapes, add a method called `_draw`. This is where you will put your drawing logic for the custom shape. You will also need to mix in any attributes that you need.</p>
RoundedRect.superclass.constructor.apply(this, arguments);
RoundedRect.NAME = "roundedRect";
var w = this.get("width"),
h = this.get("height"),
ew = this.get("ellipseWidth"),
eh = this.get("ellipseHeight");
this.clear();
this.moveTo(0, eh);
this.lineTo(0, h - eh);
this.quadraticCurveTo(0, h, ew, h);
this.lineTo(w - ew, h);
this.quadraticCurveTo(w, h, w, h - eh);
this.lineTo(w, eh);
this.quadraticCurveTo(w, 0, w - ew, 0);
this.lineTo(ew, 0);
this.quadraticCurveTo(0, 0, 0, eh);
this.end();
ATTRS: Y.mix({
}, Y.Shape.ATTRS)
Y.RoundedRect = RoundedRect;
var mygraphic = new Y.Graphic({render: "#mygraphiccontainer"}),
myroundrect = mygraphic.addShape({
type: Y.RoundedRect,