%( $Id: deslist_afm.txt mickroue(a)yahoo.fr 20140129 templ=templm %)
  
%( %import;anclist_deslist_stat_age %)

%( begin $Id: anclist_deslist_stat_age.txt mickroue(a)yahoo.fr 20131203 templ=templm %)

%define;stat_age1()
  <div class="col">
    110<br%/>100<br%/>90<br%/>80<br%/>
    70<br%/>60<br%/>50<br%/>40<br%/>
    30<br%/>20<br%/>10<br%/>0
  </div>
  <div class="body">
    %reset_count;
    %foreach;sorted_list_item;
      %if;(item.1 = 0)
        %incr_count;
        %if;(next_item.2 != item.2)
          %let;l_width0;%expr(count * l_size)%in;
          %let;l_width;%if;(l_width0 > max_width)%max_width;%else;%l_width0;%end;%in;
          <span class="a%item.1;%item.2;" style="border-left:solid %l_width;px #4682B4;">%count;</span>
          %reset_count;
        %end;
      %end;
      %if;(item.1 = 1)
        %incr_count;
        %if;(next_item.2 != item.2)
          %let;l_width0;%expr(count * l_size)%in;
          %let;l_width;%if;(l_width0 > max_width)%max_width;%else;%l_width0;%end;%in;
          <span class="a%item.1;%item.2;" style="border-left:solid %l_width;px #FF69B4;">%count;</span>
          %reset_count;
        %end;
      %end;
    %end;
  </div>
%end;

%define;stat_age2()
  %let;l_height;%expr(40 + (count *2))%in;
  <div class="body bcbg1" style="height:%l_height;px;">
    %reset_count;
    %foreach;sorted_list_item;
      %incr_count;
      %let;l_top;%expr(20 + (count * 2))%in;
      %let;l_left0;%expr(20 + item.2 * 8)%in;
      %let;l_left;%if;(l_left0 > 840)840%else;%l_left0;%end;%in;
      %if;(count = 1)
        <span class="date">%item.1;</span>
        <span class="lev">%level;</span>
      %end;
      %if;(next_item.1 = "")<span class="date" style="top:%l_top;px;">%item.1;</span>%end;
      <a href="%prefix;i=%item.4;" class="link"
         style="color:#%if;(item.3 = 0)4682B4;%else;FF69B4%end;;left:%l_left;px;top:%l_top;px;">%item.2;</a>
    %end;
  </div>
%end;
%( end $Id: anclist_deslist_stat_age.txt mickroue(a)yahoo.fr 20131203 templ=templm %)

%define;desc_afm(curlev, maxlev)
  %let;l_aby;%if;(birth_date.year = "" or birth_date.prec = ".." or birth_date.prec = "|")0%else;%birth_date.year;%end;%in;
  %let;l_fby;%if;(has_parents)%if;(father.birth_date.year = "" or father.birth_date.prec = ".." or father.birth_date.prec = "|")9999%else;%father.birth_date.year;%end;%else;9999%end;%in;
  %let;l_mby;%if;(has_parents)%if;(mother.birth_date.year = "" or mother.birth_date.prec = ".." or mother.birth_date.prec = "|")9999%else;%mother.birth_date.year;%end;%else;9999%end;%in;
  %if;(l_aby >= l_fby)
    %incr_count;
    %let;l_age;%expr((l_aby - l_fby)/10)%in;
    %apply;add_in_sorted_list(0,l_age,father.index,count)
  %end;
  %if;(l_aby >= l_mby)
    %incr_count;
    %let;l_age;%expr((l_aby - l_mby)/10)%in;
    %apply;add_in_sorted_list(1,l_age,mother.index,count)
  %end;
  %foreach;family;
    %if;(curlev < maxlev and family.desc_level = curlev and has_children)
      %family.set_infinite_desc_level;
      %foreach;child;
        %apply;desc_afm(curlev+1, maxlev)
      %end;
    %end;
  %end;
%end;

%define;desc_afm1(curlev, maxlev)
  %let;l_aby;%if;(birth_date.year = "" or birth_date.prec = ".." or birth_date.prec = "|")0%else;%birth_date.year;%end;%in;
  %let;l_fby;%if;(has_parents)%if;(father.birth_date.year = "" or father.birth_date.prec = ".." or father.birth_date.prec = "|")9999%else;%father.birth_date.year;%end;%else;9999%end;%in;
  %let;l_mby;%if;(has_parents)%if;(mother.birth_date.year = "" or mother.birth_date.prec = ".." or mother.birth_date.prec = "|")9999%else;%mother.birth_date.year;%end;%else;9999%end;%in;
  %if;(l_aby >= l_fby)
    %incr_count;
    %let;l_age;%expr(l_aby - l_fby)%in;
    %apply;add_in_sorted_list(l_aby,l_age,0,index,count)
  %end;
  %if;(l_aby >= l_mby)
    %incr_count;
    %let;l_age;%expr(l_aby - l_mby)%in;
    %apply;add_in_sorted_list(l_aby,l_age,1,index,count)
  %end;
  %foreach;family;
    %if;(curlev < maxlev and family.desc_level = curlev and has_children)
      %family.set_infinite_desc_level;
      %foreach;child;
        %apply;desc_afm1(curlev+1, maxlev)
      %end;
    %end;
  %end;
%end;

%( age father mother by generation tl1 = afm %)
<p>%apply;togen(l_v)</p>
%reset_count;
%reset_desc_level;
%empty_sorted_list;
%apply;desc_afm(0,l_v)
%let;max_width;360%in;
%let;l_size;%expr(36 / ((40 + count) / 4 / 10))%in;
<div class="stat_age1 bcbg1">
  <table class="title" width="100%%"><tr>
    <td>[*age]</td>
    <td align="center">[*age]
      (<span style="color:#4682B4;"/>[father/mother]0</span>,
       <span style="color:#FF69B4;"/>[father/mother]1</span>)</td>
    <td align="right"><em>%count; [date/dates]1</em></td>
  </tr></table>
  %apply;stat_age1()
</div>
<div class="stat_age2 bcbg1">
  <table class="title" width="100%%"><tr>
    <td align="center">[*age]
        (<span style="color:#4682B4;"/>[father/mother]0</span>,
         <span style="color:#FF69B4;"/>[father/mother]1</span>)</td>
    <td align="right">[*date of birth]</td>
  </tr></table>
  %reset_desc_level;
  %reset_count;
  %empty_sorted_list;
  %apply;desc_afm1(0,l_v)
  %apply;stat_age2()
</div>
