[ 6 posts ]

Stuart Grimshaw

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

Best way to provide default values for a standard shape?

Post Posted: Tue Jun 12, 2012 1:39 pm
+1-
If I want to create a new graphic with a set of parameters to be used every time, what's the best way to do that?

I'm trying this atm:

Code:
    Y.extend(ConeIcon, Y.Shape,
    {},
    {
        ATTRS: Y.mix({
            type: 'circle',
            radius: 5,
            stroke: {
                weight: 2,
                color: '#fff'
            }
        }, Y.Shape.ATTRS)
    });


I just want to create a circle each time, and creating the above like this:

Code:
        newThing = FC.pitch.addShape({
            type: FC.ConeIcon,
            x: e.pageX,
            y: e.pageY
        });


I get several errors in the browser

Code:
Error: Invalid value for <svg:svg> attribute width="NaN" /drill/:1
Error: Invalid value for <svg:svg> attribute height="NaN" /drill/:1
Warning: Problem parsing viewBox="NaN NaN NaN NaN"


Is this the best way to do it? I have several shapes & the same event will draw the right shape depending on other and just want to be able to create a new instance where the pointer is.

Stuart Grimshaw

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

Re: Best way to provide default values for a standard shape?

Post Posted: Tue Jun 19, 2012 9:50 am
+0-
Can anyone help?

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: Best way to provide default values for a standard shape?

Post Posted: Tue Jun 19, 2012 8:08 pm
+1-
You want to extend Circle so you can get all of its default behavior.

Code:
Y.extend(ConeIcon, Y.Circle, {
}, {
    ATTRS : Y.mix({
        stroke: {
            valueFn: function() {
                return {
                    weight: 2,
                    dashstyle: "none",
                    color: "#fff",
                    opacity: 1.0
                };
            }
        },
        radius: {
            value: 5
        }
    }, Y.Circle.ATTRS, false, false, null, 0, true)
});


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: Best way to provide default values for a standard shape?

Post Posted: Tue Jun 19, 2012 11:21 pm
+0-
What's the difference between the way you've set radius & stroke Tripp? Why does one use valueFN() & the other just return an object?

Alberto Santini

YUI Contributor

  • Offline
  • Profile

Re: Best way to provide default values for a standard shape?

Post Posted: Wed Jun 20, 2012 3:39 am
+1-
Hello Stuart.

Maybe you may give a look at Attributes guide (Attribute Configuration Properties section - see valueFn):

http://yuilibrary.com/yui/docs/attribute/

Recap for valueFn: A function, the return value of which is the value for the attribute. This property can be used instead of the value property for static configurations, if you need to set default values which require access to instance state ("this.something").

Hope that helps,
IceBox

Stuart Grimshaw

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

Re: Best way to provide default values for a standard shape?

Post Posted: Wed Jun 20, 2012 10:50 am
+0-
Thanks for your help Alberto & Tripp.
  [ 6 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