8
$\begingroup$

Historically, MMA has never handled label collisions well, but recently they added some improvements here via things like Callout. I want to fix ImageSize but still see as much as possible (by tooltipping a minimal set of vertices).

Here's two examples of the problem:

enter image description here

enter image description here

Unfortunately, Callout doesn't work in Graphics but it does on ListPlot type functions... any ideas?

Here's a starting point (some problems: callouts don't look like nice tree vertices labeled in-place, changing imagesize does not update callouts, below 200 imagesize doesn't look good...)

t=Tree["[email protected]", {Tree["[email protected]", {Tree["[email protected]", None], Tree["[email protected]", None], 
    Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", 
     {Tree["[email protected]", None], Tree["[email protected]", {Tree["[email protected]", None], Tree["[email protected]", None], 
        Tree["[email protected]", None], Tree["[email protected]", None]}], Tree["[email protected]", 
       {Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], 
        Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], 
        Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None]}], 
      Tree["[email protected]", {Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], 
        Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None]}], 
      Tree["[email protected]", {Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], 
        Tree["[email protected]", {Tree["[email protected]", None]}], Tree["[email protected]", None], Tree["[email protected]", None]}]}], 
    Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], 
    Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None], Tree["[email protected]", None]}]}];

g = Graph@t;
vc = Association[(#[[2]] -> AnnotationValue[{g, #}, VertexCoordinates]) & /@ 
    VertexList[g]];
vl = Association[#2 -> #1 & @@@ VertexList[g]];
ve = #1[[2]] -> #2[[2]] & @@@ EdgeList[g];
data = Values@Merge[{vc, vl}, Identity]; is = 300;
annotated = data /. {{a_, b_}, n_} :> Callout[{a, b}, n];
Slider[Dynamic[is], {100, 800}]
ListPlot[annotated, Axes -> None, 
 Prolog -> {LightGray, Line[List @@@ (ve /. vc)]}, ImageSize -> Dynamic[is]]

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ This is already a huge improvement! $\endgroup$
    – user5601
    Commented Jun 11, 2021 at 22:08
  • 1
    $\begingroup$ Thanks, yes the tooltips are nice, but I would disagree... 1) the callouts are covering the edges 2) it doesn't have the styling of a Tree object 3) doesn't respond to ImageSize updates $\endgroup$
    – M.R.
    Commented Jun 16, 2021 at 0:16
  • 1
    $\begingroup$ I guess this is too hard for now... $\endgroup$
    – M.R.
    Commented Jul 5, 2021 at 4:54
  • $\begingroup$ I don't have Tree[..] on my system but for Tree styling and size updates: t = RandomInteger[#] -> # + 1 & /@ Range[0, 30]; Slider[Dynamic[is], {100, 1500}], Dynamic[is]} {Slider[Dynamic[ar], {0.05, 0.5}], Dynamic[ar]} Dynamic[g = TreeGraph[t, VertexSize -> is/1800, AspectRatio -> ar, EdgeStyle -> {Arrowheads[{is/130000}]}, VertexLabels -> Placed[Automatic, Center, Tooltip], ImageSize -> is]] $\endgroup$
    – Syed
    Commented Sep 4, 2021 at 8:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.