1 package Maasha::KISS::Draw;
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 graphics.
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
36 use vars qw( @ISA @EXPORT );
38 @ISA = qw( Exporter );
41 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
46 # Martin A. Hansen, October 2005.
48 # inititalizes SVG object, which is returned.
50 my ( $height, # Height in pixels
51 $width, # Width in pixels
68 # Martin A. Hansen, October 2009.
70 # Adds a top level layer frame of given
71 # height and width to an SVG object.
73 my ( $height, # Height in pixels
74 $width, # Width in pixels
105 # Martin A. Hansen, October 2009.
107 # Given a DNA sequence as a list add a string
108 # of chars to a SVG object.
119 $dna = 'GAACGACGAGCATCAGCGGACACTACATCATATACTACATC';
121 $track = $svg->group(
124 # 'stroke-width' => 5,
125 # stroke => 'black', # TODO can this be removed?
126 'font-family' => 'Courier New',
127 'font-size' => '15px',
128 'letter-spacing' => '15',
141 sub svg_track_feature
143 # Martin A. Hansen, October 2009.
145 # Given a list of features add these to
148 my ( $height, # Height in pixels
149 $width, # Width in pixels
151 $features, # List of features
152 $track_id, # Unique track id
153 $color, # Color of features
158 my ( $track, $i, $id, $x, $y, $w, $h );
160 $track = $svg->group(
168 for ( $i = 0; $i < @{ $features }; $i++ )
171 $x = $features->[ $i ]->{ 'x' };
172 $y = $features->[ $i ]->{ 'y' };
173 $h = $features->[ $i ]->{ 'height' };
174 $w = $features->[ $i ]->{ 'width' };
176 # $track->rectangle( id => $id, x => $x, y => $y, width => $w, height => $h );
178 $track->line( id => $id, x1 => $x, y1 => $y, x2 => $x + $w, y2 => $y );
183 sub svg_track_histogram
185 # Given a list of features add these to
188 my ( $svg, # SVG object
189 $features, # List of features
190 $track_id, # Unique track id
191 $color, # Color of features
198 $track = $svg->group(
206 for ( $i = 0; $i < @{ $features }; $i++ )
210 x1 => $features->[ $i ]->{ 'x1' },
211 y1 => $features->[ $i ]->{ 'y1' },
212 x2 => $features->[ $i ]->{ 'x2' },
213 y2 => $features->[ $i ]->{ 'y2' },
221 # Martin A. Hansen, October 2009.
223 # Prints XML output from a SVG object.
225 my ( $svg, # SVG object
226 $fh, # file handle - OPTIONAL
233 print $fh $svg->xmlify;
243 @html = "Content-Type: text/html; charset=ISO-8859-1\n\n";
245 push @html, "<pre>\n";
246 push @html, Dumper( $foo );
247 push @html, "</pre>\n";
249 return wantarray ? @html : \@html;
253 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<