Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>VertexRenderingFunction</code> and <code>EdgeRenderingFunction</code> allow you to take explicit control over the way that vertices and edges are drawn in the graph. Both functions are expected to return a symbolic graphics directive (or list of such directives) that is valid for the <a href="http://reference.wolfram.com/mathematica/ref/Graphics.html" rel="nofollow noreferrer">Graphics</a> command.</p> <p>Let's start with <code>VertexRenderingFunction</code>. We shall define a new function called <code>drawVertex</code>. A <code>VertexRenderingFunction</code> is called with two arguments: the position of the vertex (as an X/Y co-ordinate pair) and the name of the vertex.</p> <pre><code>drawVertex[position_, vertex:(4 | 5 | 6)] := Inset[Framed[vertex, Background -&gt; LightMagenta], position] drawVertex[position_, _] := {PointSize[Medium], Blue, Point[position]} </code></pre> <p>Two definitions are provided for <code>drawVertex</code>. The first is only applicable to the vertices <code>4</code> or <code>5</code> or <code>6</code>. It draws those vertices as framed labels. The second definition is applicable to all other vertices and draws simple blue points.</p> <p>Now for an <code>EdgeRenderingFunction</code> named <code>drawEdge</code>. The function will be passed three arguments: the endpoints of the edge, a list of the source and target vertices of the edge, and the label for the edge (if any). In our case, all edges will be drawn as arrows but the colour and thickness will vary depending upon the edge. The helper function <code>edgeStyle</code> is introduced to capture those differences:</p> <pre><code>drawEdge[ends_, fromTo_, label_] := Join[edgeStyle[fromTo], {Arrowheads[{{Automatic, 0.5}}], Arrow[ends]}] edgeStyle[{3, 6} | {2, 4} | {1, 3}] := {Blue, Thick} edgeStyle[_] := {Red, Thin} </code></pre> <p>With these definitions in place, we can now use them in conjunction with <code>LayeredGraphPlot</code> to produce a customized diagram:</p> <pre><code>LayeredGraphPlot[{1 -&gt; 2, 1 -&gt; 3, 2 -&gt; 4, 3 -&gt; 5, 3 -&gt; 6}, VertexRenderingFunction -&gt; drawVertex, EdgeRenderingFunction -&gt; drawEdge ] </code></pre> <p><img src="https://i.stack.imgur.com/SOzui.png" alt="layered graph"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload