Graphics-HotMap
view release on metacpan or search on metacpan
lib/Graphics/HotMap.pm view on Meta::CPAN
303132333435363738394041424344454647484950# 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
194195196197198199200201202203204205206207208209210211212213214215=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
224225226227228229230231232233234235236237238239240241242243244245
);
=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
775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
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
955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
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) {
"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
1239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
#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 )