MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: EdgeRenderingFunction to produce edge labels in GraphPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87658] Re: [mg87549] EdgeRenderingFunction to produce edge labels in GraphPlot
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Tue, 15 Apr 2008 05:50:38 -0400 (EDT)

But...

(1) The first method you suggest -- to use SetEdgeLabels to build the
labels into the Graph object -- does not seem to allow the option
Method->None in GraphPlot:

   g=Cycle[3];
   g=SetEdgeLabels[g,{"a","b","c"}];
   GraphPLot[g,Method->None]

This produces a GraphPlot::mthd error saying that None is not a
permissible method.  Why not?  I do NOT want GraphPlot to relocate the
vertices in the plane drawing, but to maintain their location; that's
the purpose of Method->None, after all.  Method->Automatic moves
vertices and creates an unpleasnt skewing of the eges away from their
original positions.  (This becomes more evident with more complicated
graphs, e.g., those having horizontal or vertical egdes.)

(2) My graphs are UNdirected.  I don't readily see how to adapt the
second method -- using an EdgeRenderingFunction building upon an
edgeLabelFunction -- to undirected graphs.  

Am I missing something "obvious" here with method (2)?


> Murray Eisenberg wrote:
> 
> >I'm having trouble fathoming from the documentation how 
> >EdgeRenderingFunction works.  In a display produced by GraphPlot, 
> >applied to a graph that's a Graph object created with Combinatorica,  I 
> >want to be able to put distinct labels on the edges.
> >
> >For example, take something very simple:
> >
> >   g = Cycle[3];
> >
> >I'd like to put labels "a", "b", "c" on the three {1,2}, {2,3}, {3,1}, 
> >respectively.
> >
> >Here's what I tried finally:
> >
> >   labels = Characters["abc"];
> >   edgeLabelFunction[{u_, v_}] :=
> >     labels[[First@Flatten@Position[Edges[Cycle[3]], {u, v}]]]
> >
> >   offset={0.05,0.05}; (* to move labels away from edges *)
> >
> >   GraphPlot[g, Method -> None,
> >     EdgeRenderingFunction -> ({
> >          Line[#1],
> >          Inset[edgeLabelFunction[#2], Mean[#1] + offset]
> >        ]} &)
> >   ]
> >
> >This does not work.  How, exactly, do I index into the list of edges...
> >
> >     Edges[g]
> >   {{1,2},{2,3},{1,3}}
> >
> >.. so as to select the labels.  From the reference page on 
> >EdgeRenderingFunction, it seems to me that argument #2 is supposed to be 
> >the length 2 list {u,v} of vertices with which the edge is incident.
> >
> >  
> >
> It seems that GraphPlot conversions of Combinatorica graphs with edge 
> labels isn't working. Otherwise you could use the Combinatorica function 
> SetEdgeLabels on the graph and then display using EdgeLabeling->True.
> 
> One possibility is to manipulate the Graph object produced by 
> Combinatorica into a form suitable for GraphPlot. Here is an example:
> 
> g = SetEdgeLabels[Cycle[3], {a, b, c}];
> g = Replace[First@g, {{a_, b_}, opts___} :> (If[MatchQ[#, EdgeLabel], a 
> -> b, {a -> b, #}] &[EdgeLabel /. {opts}]), {1}];
> 
> GraphPlot[g, EdgeLabeling -> True]
> 
> The alternative as you tried to do, is to add the edge labels using 
> EdgeRenderingFunction
> 
> First, here's a close facsimile to the default EdgeRenderingFunction:
> 
> EdgeRenderingFunction -> ({
>     RGBColor[0.5, 0, 0],
>     Arrowheads[{{0.5, 0.5, Graphics[{Black, Inset[Style[#3], {0, 0}, 
> ImageScaled[{0.5, 0.5}], Automatic, None, Background -> White]}]}, 
> {0.03, 0.8}}],
>     Arrow[#1]
> }&)
> 
> Now, it's best if the Combinatorica graph is directed (otherwise 
> GraphPlot will try to label it in both directions). So,
> 
> g = Cycle[3, Type -> Directed];
> 
> labels = Characters["abc"];
> edgeLabelFunction[{u_, v_}] := 
> labels[[First@Flatten@Position[Edges[Cycle[3, Type -> Directed]], {u, v}]]]
> 
> GraphPlot[g, EdgeRenderingFunction -> ({RGBColor[0.5, 0, 0],
>      Arrowheads[{{0.5, 0.5,
>         Graphics[{Black, Inset[Style[edgeLabelFunction[#2]], {0, 0}, 
> ImageScaled[{0.5, 0.5}], Automatic, None,
>            Background -> White]}]}, {0.03, 0.8}}], Arrow[#1]} &)]
> 
> Carl Woll
> Wolfram Research
> 


-- 
  Murray Eisenberg                       Internet:  murray at math.umass.edu
  Mathematics & Statistics Dept.            Voice:  413-545-2859 (W)
  University of Massachusetts                       413-549-1020 (H)
  Amherst, MA 01003                           Fax:  413-545-1801


  • Prev by Date: Re: Re: List concatenation speed
  • Next by Date: Re: Labelling contours on contour plots
  • Previous by thread: Re: EdgeRenderingFunction to produce edge labels in GraphPlot
  • Next by thread: Re: EdgeRenderingFunction to produce edge labels in GraphPlot