4
$\begingroup$

I have constructed a small tool to produce documentation for my code. It constructs dataflow diagrams (my own version) using an association-based data structure and Graph.

The DFDs look pretty good except that some of the labeling gets buried behind some of the vertices, and I haven't been able to figure out how to make them layer as I wish. Take a look at the vertex "buildPartnerGraphLF" which is on top of the edge label.

As background, the association data structure gets translated into the lists below which are then fed to Graph. I include the raw lists. Any help would be appreciated.

 vL = {Property["buildLimitedPGraphLF", VertexShapeFunction -> "Circle"], 
  Property["buildPartnerGraphLF", {VertexShapeFunction -> "Circle", 
   VertexStyle -> RGBColor[0.87, 0.94, 1], VertexSize -> {0.3, 0.3}}],
  Property["dealDataDS", VertexShapeFunction -> "Square"], 
  Property["fullPartL", VertexShapeFunction -> "RoundedRectangle"], 
  Property["leadsAndCoLeadsDS", VertexShapeFunction -> "Square"], 
  Property["seedPartnerL", VertexShapeFunction -> "RoundedRectangle"], 
  Property["shortSeedPL", VertexShapeFunction -> "RoundedRectangle"]}

eL = {"buildLimitedPGraphLF" \[DirectedEdge] "buildPartnerGraphLF", 
 "buildLimitedPGraphLF" \[DirectedEdge] "fullPartL", 
 "buildPartnerGraphLF" \[DirectedEdge] "getPartnerF", 
 "buildPartnerGraphLF" \[DirectedEdge] "leadsAndCoLeadsDS", 
 "buildPartnerGraphLF" \[DirectedEdge] "seedPartnerL", 
 "dealDataDS" \[DirectedEdge] "getPartnerF", 
 "frequentPartF" \[DirectedEdge] "shortSeedPL", 
 "getPartnerF" \[DirectedEdge] "buildPartnerGraphLF", 
 "getPartnerF" \[DirectedEdge] "dealDataDS", 
 "leadsAndCoLeadsDS" \[DirectedEdge] "buildPartnerGraphLF", 
 "medF" \[DirectedEdge] "frequentPartF", 
 "medF" \[DirectedEdge] "getPartTimesF", 
 "seedPartnerL" \[DirectedEdge] "frequentPartF", 
 "shortSeedPL" \[DirectedEdge] "buildLimitedPGraphLF"}

eLabL={"buildLimitedPGraphLF" \[DirectedEdge] "buildPartnerGraphLF" -> 
  "brokerS medI", 
 "buildLimitedPGraphLF" \[DirectedEdge] "fullPartL" -> 
  "broker+partnerL", 
 "buildPartnerGraphLF" \[DirectedEdge] "getPartnerF" -> 
  "Each/leadOrCoL", 
 "buildPartnerGraphLF" \[DirectedEdge] "leadsAndCoLeadsDS" -> 
  "brokerS", "dealDataDS" \[DirectedEdge] "getPartnerF" -> "partnerL",
  "getPartnerF" \[DirectedEdge] "buildPartnerGraphLF" -> "partnerL", 
 "getPartnerF" \[DirectedEdge] "dealDataDS" -> "dealS", 
 "leadsAndCoLeadsDS" \[DirectedEdge] "buildPartnerGraphLF" -> 
  "leadOrCoL", "medF" \[DirectedEdge] "frequentPartF" -> "medI", 
 "medF" \[DirectedEdge] "getPartTimesF" -> "brokerS", 
 "shortSeedPL" \[DirectedEdge] "buildLimitedPGraphLF" -> 
  "Each/partnerS"}

g1 = Graph[vL, eL, EdgeLabels -> eLabL, 
  VertexLabels -> Placed["Name", Center], VertexSize -> {0.25, .25}, 
  ImageSize -> Full]

enter image description here

$\endgroup$
  • $\begingroup$ Use as option a color with opacity VertexStyle -> RGBColor[0.77, 0.76, 0.21, .3] would be a quick way to see all labeling. $\endgroup$ – Rolf Mertig Dec 22 '16 at 21:11
5
$\begingroup$

You can move all of the text to the top with

Show[Show@g1 /. {{_Text -> {}}, {_Disk | _Rectangle | _Arrow | _FilledCurve -> {}}}]

Mathematica graphics

This uses Show to convert the graph to a normal graphics object, and then uses Show again to layer a copy with only the text over a copy with all of the text removed.

$\endgroup$
  • $\begingroup$ I had to read that replacement three times to see what you are doing. That's clever! $\endgroup$ – Mr.Wizard Dec 23 '16 at 2:34
  • 2
    $\begingroup$ @Mr.Wizard Thanks! I think that's the first time I've made good use of the "list-of-lists" syntax for ReplaceAll. $\endgroup$ – Simon Rochester Dec 23 '16 at 3:14
  • $\begingroup$ Awesome is the word that suggests itself to me! $\endgroup$ – mdc18550 Dec 23 '16 at 17:23
  • $\begingroup$ For those reading this, @Simon Rochester has (in one line) converted the graph to a graphic, then created two versions of the graphic, using replacement rules to turn "off" all of the text in the first and all of the other graphics in the second. Then Show essentially overlays the text-y one on top of the graphic-y one. Thanks! $\endgroup$ – mdc18550 Dec 23 '16 at 17:53
  • $\begingroup$ @mdc18550 You're welcome. I just found a way to shorten it some more -- you can use Show instead of FullGraphics to convert the graph object to graphics; that removes the need to specify ImageSize again. $\endgroup$ – Simon Rochester Dec 23 '16 at 23:42
1
$\begingroup$

An approach to get a Graph object as the final output:

  1. Make the labels in g1 invisible.
  2. Extract the Insets and InsetBoxes that contain the vertex and edge labels.
  3. Use the extracted labels as Epilog using SetProperty.

Example:

g2 = SetProperty[g1, Thread[{EdgeLabelStyle, VertexLabelStyle} -> Opacity[0]]];
labels = Cases[Show@g1 , i : (Inset | InsetBox)[__] :> i, {0,  ∞}];
g3 = SetProperty[g2, Epilog -> labels]

enter image description here

Head @ g3

Graph

Alternatively, do all in a single step:

SetProperty[SetProperty[g1, Thread[{EdgeLabelStyle, VertexLabelStyle} -> Opacity[0]]], 
 Epilog -> Cases[Show@g1 , i : (Inset | InsetBox)[__] :> i, {0, ∞}]]

same picture

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.