1 package Maasha::KISS::Track;
3 # Copyright (C) 2009 Martin A. Hansen.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Routines for creating KISS tracks.
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
35 use vars qw( @ISA @EXPORT );
37 @ISA = qw( Exporter );
40 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
45 my ( $entries, # list of KISS entries
50 @{ $entries } = sort { $a->{ 'S_BEG' } <=> $b->{ 'S_BEG' } or
51 $a->{ 'S_END' } <=> $b->{ 'S_END' } } @{ $entries };
57 my ( $width, # draw window width
58 $y_offset, # y axis draw offset
59 $beg, # base window beg
60 $end, # base window end
61 $entries, # list of sorted KISS entries
66 my ( $factor, $entry, $y_step, @ladder, $i, $x, $y, $w, @features );
68 $factor = $width / ( $end - $beg );
71 foreach $entry ( @{ $entries } )
73 $w = sprintf( "%.0f", ( $entry->{ 'S_END' } - $entry->{ 'S_BEG' } + 1 ) * $factor );
77 $x = sprintf( "%.0f", ( $entry->{ 'S_BEG' } - $beg ) * $factor );
79 for ( $y_step = 0; $y_step < @ladder; $y_step++ )
81 last if $x >= $ladder[ $y_step ] + 1;
84 $y = $y_offset + ( 5 * $y_step );
87 # id => $entry->{ 'Q_ID' },
94 $ladder[ $y_step ] = $x + $w;
98 return wantarray ? @features : \@features;
104 my ( $width, # draw window width
105 $y_offset, # y axis draw offset
106 $min, # minimum base position
107 $max, # maximum base position
108 $entries, # list of sorted KISS entries
113 my ( $hist_height, $bucket_width, $factor_heigth, $factor_width, $entry, $max_height, $bucket_beg, $bucket_end, $i, @buckets, $bucket, @hist, $x, $h );
115 return if $max == $min;
117 $hist_height = 100; # pixels
118 $bucket_width = 5; # pixels
120 $factor_width = ( $width / $bucket_width ) / ( $max - $min );
124 foreach $entry ( @{ $entries } )
126 $bucket_beg = int( $entry->{ 'S_BEG' } * $factor_width );
127 $bucket_end = int( $entry->{ 'S_END' } * $factor_width );
129 # print "$bucket_beg $bucket_end\n";
131 for ( $i = $bucket_beg; $i <= $bucket_end; $i++ )
135 $max_height = Maasha::Calc::max( $max_height, $buckets[ $i ] );
139 # print Maasha::KISS::Draw::hdump( \@buckets );
140 #print Dumper( $max_height );
142 if ( $max_height > 0 )
144 $factor_heigth = $hist_height / $max_height;
148 for ( $i = int( $entries->[ 0 ]->{ 'S_BEG' } * $factor_width ); $i < @buckets; $i++ )
150 if ( defined $buckets[ $i ] )
152 $h = sprintf( "%.0f", $buckets[ $i ] * $factor_heigth );
158 y1 => $y_offset + $hist_height,
160 y2 => $y_offset + $hist_height - $h,
169 return wantarray ? @hist : \@hist;
181 $div = $num / $bucket_size;
184 if ( $div - $int >= 0.5 ) {
185 return $bucket_size * ( $int + 1 );
187 return $bucket_size * $int;
192 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<