#  Copyright (c) 1997-2021
#  Ewgenij Gawrilow, Michael Joswig, and the polymake team
#  Technische Universität Berlin, Germany
#  https://polymake.org
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-------------------------------------------------------------------------------


package Visual::CovectorLattice;
use Polymake::Struct (
   [ '@ISA' => 'Container' ],
   [ '$CovectorLattice' => '#%' ],
);

options %decorations = (
   %Visual::Lattice::decorations,

   # String if set to "hidden", the covectors are not displayed.
   Covectors => enum("hidden"),
);

object CovectorLattice {

# @category Visualization
# Visualizes the covector lattice. This works the same as a visualization of a Hasse diagram
# except that by default, covectors are displayed. This can be turned off by the option Covectors=>"hidden"
user_method VISUAL(%Visual::CovectorLattice::decorations, { seed => undef }) {
   my ($this, $decor, $seed)=@_;

   my $show_covectors = delete($decor->{Covectors}) ne "hidden";

   # Add the covector to the node label
   if ($show_covectors) {
      $decor->{LabelAlignment} = "center";
      my @s;
      for my $i (0 .. $this->N_NODES-1) {
         # No label for extreme nodes
         if ($i == $this->BOTTOM_NODE || $i == $this->TOP_NODE) {
            push @s, ""; next;
         }
         my @covector_string = map {$_->size() == 0? "-" : join(" ", @{$_})} @{rows($this->COVECTORS->[$i])};
         push @s, ($this->FACES->[$i])."\\\\( ".join(" , ",@covector_string)." )";
      }
      $decor->{NodeLabels} = \@s;
   }

   $this->SUPER::VISUAL($decor, $seed);
}

}


# Local Variables:
# mode: perl
# cperl-indent-level:3
# indent-tabs-mode:nil
# End:
