Message Boards Message Boards

2
|
5588 Views
|
6 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Use vertex names as VertexShapes, or equivalent?

Posted 3 years ago

I'd like to create an illustration with Mathematica to show the flow of data in a suite of programs. In particular, I'd like to use names instead of points for vertices.

Here's some example metadata, selected from what is automatically generated by the program suite:

columnDefs = {"Program", "Input Files", "Output Files"};
suitedata = {{"Spatial to Spectral", {"Spatial Profiles", 
     "Enhanced Spatial Profiles"}, {"Alleles Frequencies Profiles", 
     "Enhanced Alleles Frequencies Profiles"}},
   {"Profile Enrichment", {"Spatial Profiles"}, {"Enhanced Spatial \
Profiles"}},
   {"Distance Properties", {"Spatial Profiles", 
     "Alleles Frequencies Profiles"}, {"Distances"}},
   {"Distance Properties", {"Spatial Profiles", 
     "Alleles Frequencies Profiles"}, {"Distances"}}};
edges = DeleteDuplicates[Flatten[
    Table[
     {
      Table[suitedata[[p, 2, i]] \[DirectedEdge] suitedata[[p, 1]],
       {i, 1, Length[suitedata[[p, 2]]]}
       ],
      Table[suitedata[[p, 1]] \[DirectedEdge] suitedata[[p, 3, j]],
       {j, 1, Length[suitedata[[p, 3]]]}
       ]
      },
     {p, 1, Length[suitedata]}
     ]
    , 2]];
vertices = Sort[DeleteDuplicates[Flatten[suitedata]]];
vertexLabels = # -> Framed[#] & /@ vertices;

So that's the easy part. I've been failing at rendering them in a Graph.

Graph[edges, EdgeStyle -> Black, VertexLabels -> None, 
 VertexShape -> vertexLabels, VertexSize -> {2, 0.5}, 
 VertexStyle -> Black, GraphLayout -> "SpringEmbedding", 
 ImageSize -> Large]

enter image description here

POSTED BY: Richard Frost
6 Replies
Posted 3 years ago

Alas there seems not to be a way to let mathematica understand the vertex size before calculating the positions. So when creating a nice vertex layout which is "large" the vertexes will overlap. At least except for using a larger image size I've not been able to get mathematica adjust the vertex positions relative to the vertex sizes. Anyone who knows how to do that please post!

POSTED BY: l van Veen

You can try adjusting VertexSize:

Graph[edges, VertexShape -> vertexLabels, VertexSize -> Scaled[.4], 
 VertexStyle -> Black]
POSTED BY: Gianluca Gorni

Thank you Gianluca :)

enter image description here

POSTED BY: Richard Frost
Posted 3 years ago

Hi Richard,

The arrowheads overlap the frame around the labels. To avoid that and have more control over the size you can use a VertexShapeFunction.

vsf[width_, fontSize_][pos_, label_, _] := 
 Inset[Framed[
   Pane[Style[label, fontSize, TextAlignment -> Left], UpTo[width]], 
   Background -> LightYellow, RoundingRadius -> 5], pos]

Graph[edges,
 BaseStyle -> Arrowheads[Medium],
 EdgeStyle -> Black,
 VertexShapeFunction -> vsf[100, 12],
 VertexStyle -> Black,
 GraphLayout -> "SpringEmbedding",
 ImageSize -> Large,
 PerformanceGoal -> "Quality"]

enter image description here

POSTED BY: Rohit Namjoshi

Rohit ... thank you so much, this is great. I embellished by giving dashed borders to the datasets and switching to digraph layout.

programNames = suitedata[[;; , 1]];

vsf[width_, fontSize_][pos_, label_, _] := 
 Inset[Framed[
   Pane[Style[label, fontSize, TextAlignment -> Left], UpTo[width]], 
   Background -> LightYellow, RoundingRadius -> 5, 
   FrameStyle -> 
    If[MemberQ[programNames, label], Dashing[{}], Dashed]], pos]

Graph[edges, BaseStyle -> Arrowheads[Medium], EdgeStyle -> Black, 
 VertexShapeFunction -> vsf[100, 12], VertexStyle -> Black, 
 GraphLayout -> "LayeredDigraphEmbedding", ImageSize -> Large, 
 PerformanceGoal -> "Quality"]

enter image description here

POSTED BY: Richard Frost
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract