How to draw a tree in which each vertex contains some circles inside?
vertexShape[n_] := Graphics[{
EdgeForm[Black],
FaceForm[Lighter@Gray],
Disk[{0, 0}],
White,
Disk[0.5 #, 0.2] & /@ CirclePoints[n]
}]
shapes = Thread[Range[0, 11] -> Table[
vertexShape@RandomInteger[4],
12]];
SeedRandom[110]
g = TreeGraph[
RandomInteger[#] \[UndirectedEdge] # + 1 & /@ Range[0, 10],
EdgeStyle -> Black,
VertexSize -> 0.5,
VertexShape -> shapes
]
Here's an example of how you can set internal nodes to blank and set the other ones according to some other rules:
shapes = Cases[
Thread[Range[0, Length@VertexList[g] - 1] -> VertexOutDegree[g]],
(x_ -> 1) :> (x -> vertexShape@RandomInteger[{1, 4}])
];
shapes = Prepend[shapes, _ -> vertexShape[0]];
(* generate a random tree *)
edges = Table[i <-> RandomInteger[{0, i - 1}], {i, 1, 20}];
(* random circles appear on edges with degree 1 only *)
circles = If[# == 1, RandomInteger[{1, 4}], 0] & /@ VertexDegree[Graph[edges]];
gencircles[{x_, y_}, name_] :=
If[circles[[name + 1]] > 0,
Disk[{x, y} + 0.1*#, .05] & /@ CirclePoints[circles[[name + 1]]]
, Nothing]
vsf[{x_, y_}, name_, {w_, h_}] := {Gray, Disk[{x, y}, .2], White, gencircles[{x, y}, name]}
Graph[edges, VertexShapeFunction -> vsf]