[ 3 posts ]

Stuart Grimshaw

  • Username: Stubbs
  • Joined: Sun Jun 10, 2012 6:36 am
  • Posts: 11
  • GitHub: Stubbs
  • Gists: Stubbs
  • IRC: Stubbs
  • Offline
  • Profile

How to instantiate custom shape by name?

Post Posted: Sat Jun 23, 2012 11:57 am
+0-
When creating a new graphic object, a circle for example, I can create a new one by giving the name of the object as a string in the "type" attribute, like this example from the documentation.

Code:
var mygraphic = new Y.Graphic({render:"#mygraphiccontainer"}),
    myrect = mygraphic.addShape({
        type: "rect",
        width: 300,
        height: 200,
        fill: {
            color: "#0000ff"
        },
        stroke: {
            weight: 2,
            color: "#ff0000"
        },
        x: 50,
        y: 100
    });


My question is, how do I set that same thing up for my own custom shapes rather than having to specify the class name?

Tripp Bridges

YUI Developer

  • Username: tripp
  • Joined: Wed Jan 07, 2009 1:54 pm
  • Posts: 435
  • GitHub: tripp
  • Gists: tripp
  • YUI Developer
  • Offline
  • Profile

Re: How to instantiate custom shape by name?

Post Posted: Sun Jun 24, 2012 12:28 pm
+1-
Currently, there is not an automated way to do this. You could probably accomplish what you want by adding a key value pair to you Graphic instance's _shapeClass property.

Code:
mygraphic._shapeClass.mycustomshape = Y.MyCustomShape;
mygraphic.addShape({
    type: "mycustomshape",
    ...
});


Thanks,
Tripp

Stuart Grimshaw

  • Username: Stubbs
  • Joined: Sun Jun 10, 2012 6:36 am
  • Posts: 11
  • GitHub: Stubbs
  • Gists: Stubbs
  • IRC: Stubbs
  • Offline
  • Profile

Re: How to instantiate custom shape by name?

Post Posted: Sat Jun 30, 2012 7:30 am
+0-
Thanks Tripp.

I was trying to instantiate a new shape based on the name of the class of the dom element the user clicked on.

In the end I created a method that takes the name as a param and returns the right shape for that element.
  [ 3 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum