How to draw a tree in which each vertex contains some circles inside?

I would like to recreate the following picture in Mathematica. I know how to draw a tree with GraphLayout. But I don't know how to create the shape of nodes as below. A bit hints about where to start will be appreciated!

• I know how to draw a tree with GraphLayout -- include that code as a starting point, and the data you want to represent in numerical form. help us help you! Jun 5, 2020 at 15:19

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]];

• Beautiful, and lightning fast! :-) Jun 5, 2020 at 15:21
• @MarcoB thanks :D Jun 5, 2020 at 15:22
• Your internal nodes with degree > 1 have inner circles. Shouldn't these be empty? Jun 5, 2020 at 15:58
• @flinty OP says he knows how to create the graph, he's just asking about how to create the vertex shapes, as far as I understand. Jun 5, 2020 at 16:01
• @flinty added an example of how to create the shape list too now though. Jun 5, 2020 at 16:35
(* 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]