From: Ghuloum, Anwar on

Is it possible to put conditional clauses (i.e. If[.]) in the
VertexRenderingFunction option for TreeForm (or any primitive that this
option applies to)? I wanted to selectively label vertices based on label
content, but Mathematica was complaining that "If" is not a graphics
primitive or directive.



(Basically, I'm trying to draw a tree where only the leaves have labels:

TreeForm[{{a, b}, {c, {d}}}, VertexRenderingFunction -> (If[#2 == List, {},
Text[#2, #1]] &)]

)



In general, I was having a hard time finding information at the
documentation center on the limitations on how I can generate graphics
primitives.but perhaps I'm not looking in the right place.


Thanks in advance!

--

Anwar Ghuloum

Microprocessor Technology Lab, Intel



From: Jean-Marc Gulliet on
Ghuloum, Anwar wrote:
> Is it possible to put conditional clauses (i.e. If[.]) in the
> VertexRenderingFunction option for TreeForm (or any primitive that this
> option applies to)? I wanted to selectively label vertices based on label
> content, but Mathematica was complaining that "If" is not a graphics
> primitive or directive.
>
>
>
> (Basically, I'm trying to draw a tree where only the leaves have labels:
>
> TreeForm[{{a, b}, {c, {d}}}, VertexRenderingFunction -> (If[#2 == List, {},
> Text[#2, #1]] &)]
>
> )
>
>
>
> In general, I was having a hard time finding information at the
> documentation center on the limitations on how I can generate graphics
> primitives.but perhaps I'm not looking in the right place.
>
>
> Thanks in advance!
>
> --
>
> Anwar Ghuloum
>
> Microprocessor Technology Lab, Intel
>
>
>

Below we define a function with some conditions on it. In doing so,
Mathematica sees only graphic primitive whenever it evaluates the
VertexRenderingFunction option. (Arguably, the following example is
written in a more Mathematica fashion.) If the second argument is a
list, then the first definition (the less general definition indeed) is
evaluated and the empty list is returned. Otherwise, the more general
definition (the second in our case) is called and the graphic primitive
Text is returned.

myRender[r_, k_] := {} /; k == List
myRender[r_, k_] := Text[k, r]
TreeForm[{{a, b}, {c, {d}}}, VertexRenderingFunction ->
(myRender[#1, #2] & )]

Regards,
Jean-Marc

From: Carl Woll on
Ghuloum, Anwar wrote:

>Is it possible to put conditional clauses (i.e. If[.]) in the
>VertexRenderingFunction option for TreeForm (or any primitive that this
>option applies to)? I wanted to selectively label vertices based on label
>content, but Mathematica was complaining that "If" is not a graphics
>primitive or directive.
>
>
>
>(Basically, I'm trying to draw a tree where only the leaves have labels:
>
>TreeForm[{{a, b}, {c, {d}}}, VertexRenderingFunction -> (If[#2 == List, {},
>Text[#2, #1]] &)]
>
>)
>
>
Try using === instead of ==:

TreeForm[{{a, b}, {c, {d}}}, VertexRenderingFunction -> (If[#2 === List, {},
Text[#2, #1]] &)]

Alternatively, use the 4 argument form of If. Your problem was that If
couldn't determine whether a==List was True or False. Hence it was left
unevaluated, and the result wasn't a graphics directive.

Carl Woll
Wolfram Research

>
>
>In general, I was having a hard time finding information at the
>documentation center on the limitations on how I can generate graphics
>primitives.but perhaps I'm not looking in the right place.
>
>
>Thanks in advance!
>
>--
>
>Anwar Ghuloum
>
>Microprocessor Technology Lab, Intel
>
>
>
>


From: Ghuloum, Anwar on

Thanks to Jean-Marc and all who responded!


-----Original Message-----
From: Jean-Marc Gulliet [mailto:jeanmarc.gulliet(a)gmail.com]
Sent: Thursday, June 14, 2007 2:24 AM
Subject: Re: Question re: graphics primitives

Ghuloum, Anwar wrote:
> Is it possible to put conditional clauses (i.e. If[.]) in the
> VertexRenderingFunction option for TreeForm (or any primitive that this
> option applies to)? I wanted to selectively label vertices based on label
> content, but Mathematica was complaining that "If" is not a graphics
> primitive or directive.
>
>
>
> (Basically, I'm trying to draw a tree where only the leaves have labels:
>
> TreeForm[{{a, b}, {c, {d}}}, VertexRenderingFunction -> (If[#2 == List,
{},
> Text[#2, #1]] &)]
>
> )
>
>
>
> In general, I was having a hard time finding information at the
> documentation center on the limitations on how I can generate graphics
> primitives.but perhaps I'm not looking in the right place.
>
>
> Thanks in advance!
>
> --
>
> Anwar Ghuloum
>
> Microprocessor Technology Lab, Intel
>
>
>

Below we define a function with some conditions on it. In doing so,
Mathematica sees only graphic primitive whenever it evaluates the
VertexRenderingFunction option. (Arguably, the following example is
written in a more Mathematica fashion.) If the second argument is a
list, then the first definition (the less general definition indeed) is
evaluated and the empty list is returned. Otherwise, the more general
definition (the second in our case) is called and the graphic primitive
Text is returned.

myRender[r_, k_] := {} /; k == List
myRender[r_, k_] := Text[k, r]
TreeForm[{{a, b}, {c, {d}}}, VertexRenderingFunction ->
(myRender[#1, #2] & )]

Regards,
Jean-Marc


 | 
Pages: 1
Prev: JLink error on startup
Next: NautyTools`NautyTools