[Bio] / FigKernelPackages / HTML.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/HTML.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.61, Mon Oct 3 20:05:34 2005 UTC revision 1.62, Mon Oct 3 23:22:48 2005 UTC
# Line 480  Line 480 
480  }  }
481    
482    
483    =head2 merge_table_rows()
484    
485    Merge table rows together. This will merge a table so that adjacent cells with the same content will only be shown once.
486    
487    Something like this:
488    
489        -----------------------
490        |    1     |    a     |
491        -----------------------
492        |    1     |    b     |
493        -----------------------
494        |    2     |    c     |
495        -----------------------
496        |    3     |    d     |
497        -----------------------
498        |    4     |    d     |
499        -----------------------
500        |    5     |    d     |
501        -----------------------
502    
503    Will become:
504    
505        -----------------------
506        |          |    a     |
507        |    1     |-----------
508        |          |    b     |
509        -----------------------
510        |    2     |    c     |
511        -----------------------
512        |    3     |          |
513        ------------          |
514        |    4     |    5     |
515        ------------          |
516        |    5     |          |
517        -----------------------
518    
519    
520    The method takes two arguments. The reference to the array that is the table ($tab). This is the standard table that is created for HTML.pm to draw, and a reference to a hash of columns that you don't want to merge together. The reference to the hash is optional, and if not included, everything will be merged.
521    
522     $tab=&HTML::merge_table_rows($tab);
523    
524     or
525    
526     $skip=(1=>1, 3=>1, 5=>1);
527     $tab=&HTML::merge_table_rows($tab, $skip);  # will merge all columns except 1, 3 and 5. Note the first column in the table is #0
528    
529    
530    =cut
531    
532    
533    
534    
535  sub merge_table_rows {  sub merge_table_rows {
536   # RAE:   # RAE:
537   # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer   # Experimental piece of code. We often want to have rows or columns were cells are merged. It just looks so much nicer
# Line 489  Line 541 
541   # before you do a make_table call   # before you do a make_table call
542    
543   my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);   my $self=shift if UNIVERSAL::isa($_[0],__PACKAGE__);
544   my ($tab)=@_;   my ($tab, $skip)=@_;
545    
546   my $newtable;   my $newtable;
547   my $lastrow;   my $lastrow;
# Line 499  Line 551 
551   for (my $y=0; $y <= $#$tab; $y++) {   for (my $y=0; $y <= $#$tab; $y++) {
552   #$y is the row in the table;   #$y is the row in the table;
553    for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {    for (my $x=0; $x <= $#{$tab->[$y]}; $x++) {
554       # this is the user definable columns not to merge
555       if ($skip->{$x})
556       {
557        $newtable->[$y]->[$x] = $tab->[$y]->[$x];
558        next;
559       }
560    
561     #$x is the column in the table     #$x is the column in the table
562     # if the column in the row we are looking at is the same as the column in the previous row, we don't add     # if the column in the row we are looking at is the same as the column in the previous row, we don't add
563     # this cell to $newtable. Instead we increment the rowspan of the previous row by one     # this cell to $newtable. Instead we increment the rowspan of the previous row by one

Legend:
Removed from v.1.61  
changed lines
  Added in v.1.62

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3