Graphics-HotMap

 view release on metacpan or  search on metacpan

lib/Graphics/HotMap.pm  view on Meta::CPAN

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Create a new HotMap
my $hotMap = Graphics::HotMap->new(
      minValue => 1,
      maxValue => 50,
      ); 
 
# Define scale
$hotMap->scale(20);
 
# Show legend
$hotMap->legend(1);
 
# Show CrossMarks and values
$hotMap->crossMark(1,1);
 
# Define a new size
$hotMap->mapSize({ sizeX => 15, sizeY => 15 });
 
# Add time
$hotMap->addHorodatage(time, 15, 30);

lib/Graphics/HotMap.pm  view on Meta::CPAN

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
=for ref
 
Construct and return a new HotMap Object;
 
=for usage
 
   Graphics::HotMap->new(
      outfileGif        => <File path>, # file to write GIF
      outfilePng        => <File path>, # file to write PNG
      legend            => [0|1],       # activate lengend
      legendNbGrad      => <number>,    # Number a graduation
      cross             => <bool>,      # activate crossing of known values
      crossValues       => <bool>,      # activate values printing whith cross
      minValue          => <number>,    # minimum value
      maxValue          => <number>,    # maximum value
      font              => <path to font file>,
      fontSize          => <number>,    # font size
      scale             => <number>,    # scale values and coordonates
      sizeX             => <number>,    # X size
      sizeY             => <number>,    # Y size
   );

lib/Graphics/HotMap.pm  view on Meta::CPAN

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
   );
 
 
=cut
 
sub new {
   my ($class, %params) = (@_);
   my $self={};
   $self->{_outfileGif}   = $params{outfileGif}   || undef;
   $self->{_outfilePng}   = $params{outfilePng}   || undef;
   $self->{_legend}       = $params{legend}       || 0;
   $self->{_legendNbGrad} = $params{legendNbGrad} || 7;
   $self->{_crossMark}    = $params{cross}        || 0;
   $self->{_crossMarkTemp}= $params{crossTemp}    || 0;
   #$self->{_minValue}     = $params{minValue}     || 0;
   #$self->{_maxValue}     = $params{maxValue}     || 70;
   $self->{_font}         = $params{font}         || '/usr/share/fonts/truetype/freefont/FreeSans.ttf';
   $self->{_fontSize}     = $params{fontSize}     || 15;
   $self->{_text}         = ();
   $self->{_horodatage}   = $params{horodatage}   || [0, 0, 0];
   $self->{_scale}        = $params{echelle}      || 1;
   $self->{_verbose}      = $params{verbose}      || 0;

lib/Graphics/HotMap.pm  view on Meta::CPAN

775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
   my $tmpPiddle = $self->{_mapPoints};
   #$tmpPiddle->where($tmpPiddle > PALETTE_SLICE) -= PALETTE_SLICE;
 
   if (defined $function) {
      return scalar (floor($tmpPiddle)) if ($function eq 'floor');
      die "toString: Unknown Function. => '$function'",$/;
   }
   return scalar ($tmpPiddle);
}
 
=item legend()
 
=for ref
 
Set or Return legend status. When enabled, the legend gradient will be drawn on the image.
 
=cut
 
sub legend {
   my $self = shift;
   my ($value) = @_;
 
   if (defined $value) {
      $self->{_legend} = 1;
   } else {
      return $self->{_legend};
   }
}
 
=item crossMark()
 
=for ref
 
Set or Return cross marks status. When enabled, a cross will be drawn on the image where points have been defined.
 
=cut

lib/Graphics/HotMap.pm  view on Meta::CPAN

955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
         fill=>$color,
         text=>$text,
         align=>$align,
         x=>$x,
         y=>$y,
         rotate=>$rotate,
         );
}
 
=for comment
Internal function for generating legend bar on the image
 
=cut
 
sub _drawLegendBar {
   my $self = shift;
   my ($gradientName, $i, $im) = @_;
   my $repere = 10;
 
   my $legendBar = Graphics::HotMap->new(
      wall     => 1,
   );
   $legendBar->{_gradient} = $self->{_gradient};
   $legendBar->mapSize({
      sizeX => 10,
      sizeY => 500,
      });
    
   $legendBar->addLayer({ layerName => '_Legend'.$gradientName, visibility => 1, gradientName => $gradientName });
 
   my $nbGrad = $self->{_gradient}{$gradientName}{nbColors}; #$self->{_legendNbGrad}-1;
   my $min    = $self->{_gradient}{$gradientName}{minValue};
   my $max    = $self->{_gradient}{$gradientName}{maxValue};
 
   for (0..$nbGrad) {
      my $x = $legendBar->{_mapSize}{x}-1;
      my $y = $_/$nbGrad*($legendBar->{_mapSize}{y}-1);
      my $valeur = $max-(int(($nbGrad-$_)/$nbGrad*($max-$min)));
      my $unit   = $legendBar->{_gradient}{$gradientName}{unit};
      $legendBar->addPoint({
            layerName => '_Legend'.$gradientName,
            #x => $_/$nbGrad*($legendBar->{_mapSize}{x}-1),
            #y => $legendBar->{_mapSize}{y}-1-$repere*$i,
            x => $x,
            y => $y,
            value => $valeur,
            noScale => 1,
            unit => $unit,
            });
      $legendBar->addText ( {
              x => $x+15,
              y => $y+10,
              text => int($valeur).$unit,
              size => 10,
              align => 'center'
              } ) if ($nbGrad < 11 || $_%5 == 0);
   }
 
   $legendBar->addZone({
         layerName =>'_Legend'.$gradientName,
         zoneName => '_Legend'.$gradientName,
         coordonates => [
         1,
         1,
         $legendBar->{_mapSize}{x}-1,
         $legendBar->{_mapSize}{y}-1,
         ],
         noScale => 1 });
   $legendBar->_genDegradZone('_Legend'.$gradientName, $legendBar->{_zones}{'_Legend'.$gradientName}{'_Legend'.$gradientName}, 1);
 
   my $imag =  byte $legendBar->{_mapPoints};
   my $tmpName = new File::Temp( TEMPLATE => 'generated-XXXXX',
                                 DIR => '/tmp/',
                                 SUFFIX => '.png',
                                 OPEN => 0);
   #my $tmpName = tmpnam().'.png';
   my $cptLoop = 0;
   do {
      eval {$imag->wpic($tmpName, { LUT => $legendBar->{_gradient}{colors} }); };
   #        $imag->wpic($tmpName, { LUT => $legendBar->{_gradient}{colors} });
      ++$cptLoop;
   } while ($@ && $cptLoop < 10);
 
   if ($cptLoop > 2) {
        print "ARgh ! Function: _saveImage ; nbErr for wpic:$cptLoop\n";
        exit;
   }
 
# read the temporary File in PerlMagick
   my $status = $im->ReadImage($tmpName);
   warn $status if $status;
   #unlink $tmpName;
 
# Flip the image
   $im->[$i+1]->Flip;
   $im->[$i+1]->Border(fill=>'black', width=>-1, height=>-1);
   $im->[$i+1]->Extent(
           background => 'white',
           geometry   => ($legendBar->{_mapSize}{x}+35).'x'.($legendBar->{_mapSize}{y}+15),
           gravity    => 'West',
           );
   $legendBar->_genText($im->[$i+1]);
   $im->[$i+1]->Extent(
           background => 'white',
           geometry   => ($legendBar->{_mapSize}{x}+35).'x'.$self->{_mapSize}{y},
           gravity    => 'Center',
           );
 
   $im->[$i+1]->Extent(
           background => 'white',
           geometry   => ($legendBar->{_mapSize}{x}+35+20).'x'.$self->{_mapSize}{y},
           gravity    => 'East',
           );
   $im->[$i+1]->Annotate(
         font=>$self->{_font},
         pointsize=>10,
         fill=>'black',
         text=>$gradientName,
         align=>'right',
         x=>10,
         y=>35,
         rotate=>270,
         );
   $self->{_im} = $im->Append(stack=>'false');
}
 
=for comment
Internal function for generating legend on the image
 
=cut
 
sub _genLegende {
   my $self = shift;
   my ($im) = @_;
 
   my $i=0;
   #print "Printing Gradient Bars",$/;
   foreach my $gradientName (sort keys %{$self->{_gradient}}) {

lib/Graphics/HotMap.pm  view on Meta::CPAN

1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
   #my $im = $image->[0];
   $im->Flip;
 
# Gen CrossMarks
   $self->_genCrossMark($im) if $self->{_crossMark};
# Draw time on image
   $self->_drawTime($im) if $self->{_horodatage}[0];
# Draw texts
   $self->_genText($im);
 
# Gen legend in piddle
   $self->_genLegende($im) if $self->{_legend};
}
 
=for comment
Really compute the interpolation from known points.
 
=cut
 
sub _pdlDegrad {
   my $self = shift;
   my ($input, $output, $sliceColors, $gradientName) = @_;



( run in 0.513 second using v1.01-cache-2.11-cpan-d9388b9e2af )