%let name=family_tree;

/* %let rc=%sysfunc(dlgcdir('c:\someplace\public_html')); */
filename odsout '.';

/*
Inspired by:
https://i.redd.it/su6uscf7xjs11.png
*/
options mprint source;


%macro do_graph(rings);

%let maxsize=75;
%let outline=dodgerblue;

%macro increment;
%global generations;
%let generations = %eval(&&rings + 1);
%mend;
%increment;


data anno_tree;
length grand_string $300;
length function $8 style $35 color $12 title $20 
 family_string $100 verb_string $100 html $300;
xsys='3'; ysys='3'; hsys='3'; when='a';
x=50; y=15;
function='pie'; style='pempty'; 
/* draw rings from outer to inner */
do ring=&rings to 1 by -1;
 /* blank out the area for these slices */
 size=(ring/&rings)*&maxsize;
 style='psolid'; color="white"; angle=0; rotate=180; line=0; 
 title=''; html='';
 output;
 if ring=1 then grand_string='';
 if ring>=2 then grand_string='grand';
 if ring>2 then do loop = ring to 3 by -1;
  grand_string='great '||trim(left(grand_string));
  end;
 /* create all the slices for this ring */
 do slice=2**ring to 1 by -1;
  if mod(slice,2)=1 then title='father';
  else title='mother';
  family_string=trim(left(trim(left(grand_string))||trim(left(title))));
  if ring=1 then verb_string='provided 1/';
  else verb_string='On average, provided around 1/';
  html='title='||quote(trim(left(family_string))||'0d'x||
   trim(left(verb_string))||trim(left(put(2**ring,comma20.0)))||' of your DNA');
  style='pempty'; color="&outline";
  rotate=slice*(180/2**ring);
  style='pempty'; angle=0; 
  line=3;
  output;
  end;
 end;

/* create the slice at the bottom */
html='title='||quote('You');
size=.5*(1/&rings)*&maxsize;
style='pempty'; color="&outline";
rotate=-180;
style='pempty'; angle=0; line=2; output;

run;

title1 ls=1.5 "Family Tree Going Back &rings Generations";

ods html anchor="&rings";
proc gslide anno=anno_tree des='' name="&name._&rings";
run;

%mend;


goptions device=png;
goptions xpixels=1000 ypixels=650;
goptions border;
 
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" 
 (title="Family Tree") 
 style=htmlblue;

goptions gunit=pct ftitle='albany amt/bold' ftext='albany amt' htitle=4.2 htext=2.5;
goptions ctext=gray33;

/* use values 3 - 10 */
%do_graph(3);
%do_graph(6);
%do_graph(10);

quit;
ODS HTML CLOSE;
ODS LISTING;
