# EdgeRenderingFunction and Graph input output structure

I am trying to create an EdgeRenderingFunction but the more information does not help me at all as far as explaining what the mathematical structure of the input is and at what level , the number of @s, mathematica makes the function act and the mathematical structure of the output.

I would like to be able to create a pure function that does:

• If the initial vertex is "j" then color should be "color[j]"
• If the end vertex is "k" then the thickness should be "Thickness[k]"
• If the relation is "->" then the label should be whatever" and position "somewhere", if the relation is "-" then the label should be "whateverelse" and position "somewhere else".

EdgeRenderingFunction->g specifies that each edge should be rendered with the graphics primitives given by g[{ri..},{vi..},lbij], where ri , rj are the beginning and ending points of the edge,vi ,vj are the beginning and ending vertices, lbij the is any label specified for the edge. 

Typically, in math, if "g" is a function then g[something] signifies that the "something"is the input and "g[something]" is the output. But if "ri" are coordinates, "vi" are vertices and "lb" are labels then the "something"is intended to be the output of g[input]. So I'm a bit confused by the "more information" and would appreciate some help here.

My other questions are:

1. What is the mathematical structure of the input graph {1->2}?

Someone showed me yesterday in chat but I have forgotten how to replicate it, that:

{1->2} is collection of lists where the first list carries the vertices in order

and the second list carries the direction in order.

{1->2} is stored as {{1,2},{Rule[1,2]}}

1. what does this Rule look like? How can I write functions on this rule?

Confusingly

(#2[[1]] &) @@ {{1, 2}, {"a"}}
a


But

 (#2[[1]] &) @@ {1 -> 2}
2
but with an error message


On the other hand

 (#[[2]] &) @@ {1 -> 2}
2
No errors.


So if a Graph is stored as a list of lists that I am atting @@ at a second level then shouldn't I have found the Rule between 1 and 2?

1. How many @@@ levels is mathematica gonna make my edgerenderingfunction act on to the input?
• I think you're asking several unrelated questions here, and an explanation is too long for a comment. Drop by chat to get some guidance, you're complicating things a bit. – Dr. belisarius Oct 19 '12 at 11:32
• @belisarius thanks. I'm happy to hear that I am complicating things. I'll try to find you in chat sometime. – Amatya Oct 23 '12 at 1:17

The EdgeRenderingFunction part is not that difficult. The function g that you specify in the option EdgeRenderingFunction->g gets handed three parameters:

1. A list with begin and end points, so that's a list with two 2D vectors/lists
2. A list with the numbers of the begin and end vertices
3. An edge label (if provided)

You can see what is thrown to EdgeRenderingFunction by setting the option in a small GraphPlot to:

EdgeRenderingFunction->(Print[{##}]&)


So, g should be a user-defined function of three parameters (or a pure function that uses 0-3 parameters) and that should return graphics instructions. Most often you'll need only the first one (#1), to draw some kind of non-standard line.

There are many examples of this given in the documentation, either on the EdgeRenderingFunction doc page or the Graphplotpage. Similar examples can be found for the Graph/EdgeShapeFunction combo . An application can be found in the custom arrow question.

• Thanks for your answer. I'm a bit swamped this month so I'll respond properly a bit later. Thanks. – Amatya Nov 4 '12 at 20:51