]> git.donarmstrong.com Git - biopieces.git/blob - www/cgi-bin/index.cgi
more KISS
[biopieces.git] / www / cgi-bin / index.cgi
1 #!/usr/bin/env perl
2
3 # Copyright (C) 2006-2009 Martin A. Hansen.
4
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.
9
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.
14
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.
18
19 # http://www.gnu.org/copyleft/gpl.html
20
21 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
22
23 use strict;
24 use warnings;
25
26 use lib "/Users/maasha/biopieces/code_perl/";
27
28 use CGI;
29 use Data::Dumper;
30 use Time::HiRes;
31 use Maasha::Common;
32 use Maasha::Filesys;
33 use Maasha::Calc;
34 use Maasha::XHTML;
35 use Maasha::KISS::IO;
36 use Maasha::KISS::Track;
37 use Maasha::KISS::Draw;
38
39 my ( $cgi, $cookie, @html );
40
41 $cgi    = new CGI;
42 $cookie = cookie_default( $cgi );;
43
44 push @html, Maasha::XHTML::html_header(
45     cgi_header  => 1,
46     title       => "KISS Genome Browser",
47     css_file    => "kiss.css",
48     author      => "Martin A. Hansen, mail\@maasha.dk",
49     description => "Biopieces bacterial genome browser - KISS",
50     keywords    => [ qw( KISS Biopieces biopiece genome browser viewer bacterium bacteria prokaryote prokaryotes ) ],
51     no_cache    => 1,
52 );
53
54 push @html, Maasha::XHTML::h1( txt => "KISS Genome Browser", class => 'center' );
55 push @html, Maasha::XHTML::form_beg( action => $cookie->{ 'SCRIPT' }, method => "get", enctype => "multipart/form-data" );
56
57 push @html, page( $cookie );
58
59 push @html, Maasha::XHTML::form_end;
60 push @html, Maasha::XHTML::body_end;
61 push @html, Maasha::XHTML::html_end;
62
63 # push @html, Maasha::KISS::Draw::hdump( $cgi->param );
64 # push @html, Maasha::KISS::Draw::hdump( $cookie );
65
66 print "$_\n" foreach @html;
67
68
69 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
70
71
72 sub cookie_default
73 {
74     my ( $cgi,   # CGI object
75        ) = @_;
76
77     # Returns a hash
78
79     my ( $cookie, $path );
80
81     $cookie = {};
82
83     $cookie->{ 'SCRIPT' }      = Maasha::Common::get_scriptname();
84     $cookie->{ 'DATA_DIR' }    = "Data";
85     $cookie->{ 'LIST_PAGES' }  = [ qw( user clade genome assembly contig browse ) ];
86     $cookie->{ 'PAGE' }        = $cgi->param( 'page' )     || 'user';
87     $cookie->{ 'USER' }        = $cgi->param( 'user' )     || '';
88     $cookie->{ 'CLADE' }       = $cgi->param( 'clade' )    || '';
89     $cookie->{ 'GENOME' }      = $cgi->param( 'genome' )   || '';
90     $cookie->{ 'ASSEMBLY' }    = $cgi->param( 'assembly' ) || '';
91     $cookie->{ 'CONTIG' }      = $cgi->param( 'contig' )   || '';
92     $cookie->{ 'NAV_START' }   = $cgi->param( 'nav_start' );
93     $cookie->{ 'NAV_END' }     = $cgi->param( 'nav_end' );
94     $cookie->{ 'ZOOM_IN1' }    = $cgi->param( 'zoom_in1' );
95     $cookie->{ 'ZOOM_IN2' }    = $cgi->param( 'zoom_in2' );
96     $cookie->{ 'ZOOM_IN3' }    = $cgi->param( 'zoom_in3' );
97     $cookie->{ 'ZOOM_OUT1' }   = $cgi->param( 'zoom_out1' );
98     $cookie->{ 'ZOOM_OUT2' }   = $cgi->param( 'zoom_out2' );
99     $cookie->{ 'ZOOM_OUT3' }   = $cgi->param( 'zoom_out3' );
100     $cookie->{ 'MOVE_LEFT1' }  = $cgi->param( 'move_left1' );
101     $cookie->{ 'MOVE_LEFT2' }  = $cgi->param( 'move_left2' );
102     $cookie->{ 'MOVE_LEFT3' }  = $cgi->param( 'move_left3' );
103     $cookie->{ 'MOVE_RIGHT1' } = $cgi->param( 'move_right1' );
104     $cookie->{ 'MOVE_RIGHT2' } = $cgi->param( 'move_right2' );
105     $cookie->{ 'MOVE_RIGHT3' } = $cgi->param( 'move_right3' );
106
107     $path = "$cookie->{ 'DATA_DIR' }/Users";
108
109     $cookie->{ 'LIST_USER' }     = ls_dir_base( $path ) if -d $path;
110
111     $path .= "/$cookie->{ 'USER' }";
112
113     $cookie->{ 'LIST_CLADE' }    = ls_dir_base( $path ) if -d $path;
114
115     $path .= "/$cookie->{ 'CLADE' }";
116
117     $cookie->{ 'LIST_GENOME' }   = ls_dir_base( $path ) if -d $path;
118
119     $path .= "/$cookie->{ 'GENOME' }";
120
121     $cookie->{ 'LIST_ASSEMBLY' } = ls_dir_base( $path ) if -d $path;
122
123     $path .= "/$cookie->{ 'ASSEMBLY' }";
124
125     $cookie->{ 'LIST_CONTIG' }   = ls_dir_base( $path ) if -d $path;
126
127     if ( $cookie->{ 'CONTIG' } )
128     {
129         cookie_start( $cookie );
130         cookie_end( $cookie );
131         cookie_zoom( $cookie );
132         cookie_move( $cookie );
133     }
134
135     return wantarray ? %{ $cookie } : $cookie;
136 }
137
138
139 sub ls_dir_base
140 {
141     my ( $path,
142        ) = @_;
143
144     # Returns a list.
145     
146     my ( @dirs, $dir, @list );
147
148     @dirs = Maasha::Filesys::ls_dirs( $path );
149
150     foreach $dir ( @dirs )
151     {
152         next if $dir =~ /\/\.\.?$/;
153
154         push @list, ( split "/", $dir )[ -1 ];
155     }
156
157     return wantarray ? @list : \@list;
158 }
159
160
161 sub cookie_clade
162 {
163     my ( $cookie,
164        ) = @_;
165
166     # Returns nothing.
167     
168     my ( $user, @dirs, $dir );
169
170     $user = $cookie->{ 'USER' };
171
172     @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user" );
173
174     foreach $dir ( @dirs )
175     {
176         next if $dir =~ /\/\.\.?$/;
177
178         push @{ $cookie->{ 'LIST_CLADE' } }, ( split "/", $dir )[ -1 ];
179     }
180 }
181
182
183 sub cookie_genome
184 {
185     my ( $cookie,
186        ) = @_;
187
188     # Returns nothing.
189     
190     my ( $user, $clade, @dirs, $dir );
191
192     $user  = $cookie->{ 'USER' };
193     $clade = $cookie->{ 'CLADE' };
194
195     @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade" );
196
197     foreach $dir ( @dirs )
198     {
199         next if $dir =~ /\/\.\.?$/;
200
201         push @{ $cookie->{ 'LIST_GENOME' } }, ( split "/", $dir )[ -1 ];
202     }
203 }
204
205
206 sub cookie_assembly
207 {
208     my ( $cookie,
209        ) = @_;
210
211     # Returns nothing.
212     
213     my ( $user, $clade, $genome, @dirs, $dir );
214
215     $user   = $cookie->{ 'USER' };
216     $clade  = $cookie->{ 'CLADE' };
217     $genome = $cookie->{ 'GENOME' };
218
219     @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade/$genome" );
220
221     foreach $dir ( @dirs )
222     {
223         next if $dir =~ /\/\.\.?$/;
224
225         push @{ $cookie->{ 'LIST_ASSEMBLY' } }, ( split "/", $dir )[ -1 ];
226     }
227 }
228
229
230 sub cookie_contig
231 {
232     my ( $cookie,
233        ) = @_;
234
235     # Returns nothing.
236     
237     my ( $user, $clade, $genome, $assembly, @dirs, $dir );
238
239     $user     = $cookie->{ 'USER' };
240     $clade    = $cookie->{ 'CLADE' };
241     $genome   = $cookie->{ 'GENOME' };
242     $assembly = $cookie->{ 'ASSEMBLY' };
243
244     @dirs = Maasha::Filesys::ls_dirs( "$cookie->{ 'DATA_DIR' }/Users/$user/$clade/$genome/$assembly" );
245
246     foreach $dir ( @dirs )
247     {
248         next if $dir =~ /\/\.\.?$/;
249
250         push @{ $cookie->{ 'LIST_CONTIG' } }, ( split "/", $dir )[ -1 ];
251     }
252 }
253
254
255 sub cookie_start
256 {
257     my ( $cookie,
258        ) = @_;
259
260     # Returns nothing.
261
262     if ( defined $cookie->{ 'NAV_START' } )
263     {
264         $cookie->{ 'NAV_START' } =~ tr/,//d;
265         $cookie->{ 'NAV_START' } = 1 if $cookie->{ 'NAV_START' } <= 0;
266     }
267     else
268     {
269         $cookie->{ 'NAV_START' } = 1;
270     }
271 }
272
273
274 sub cookie_end
275 {
276     my ( $cookie,
277        ) = @_;
278
279     # Returns nothing.
280
281     my ( $max );
282     
283     $max = Maasha::Filesys::file_size( Maasha::KISS::Track::path_seq( $cookie ) );
284
285     if ( defined $cookie->{ 'NAV_END' } )
286     {
287         $cookie->{ 'NAV_END' } =~ tr/,//d;
288         $cookie->{ 'NAV_END' } = $max if $cookie->{ 'NAV_END' } > $max;
289     }
290     else
291     {
292         $cookie->{ 'NAV_END' } = $max;
293     }
294 }
295
296
297 sub cookie_zoom
298 {
299     my ( $cookie,
300        ) = @_;
301
302     # Returns nothing.
303
304     my ( $max, $dist, $new_dist, $dist_diff );
305
306     $max = Maasha::Filesys::file_size( Maasha::KISS::Track::path_seq( $cookie ) );
307
308     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
309
310     if ( defined $cookie->{ 'ZOOM_IN1' } ) {
311         $new_dist = $dist / 1.5;
312     } elsif ( defined $cookie->{ 'ZOOM_IN2' } ) {
313         $new_dist = $dist / 3;
314     } elsif ( defined $cookie->{ 'ZOOM_IN3' } ) {
315         $new_dist = $dist / 10;
316     } elsif ( defined $cookie->{ 'ZOOM_OUT1' } ) {
317         $new_dist = $dist * 1.5;
318     } elsif ( defined $cookie->{ 'ZOOM_OUT2' } ) {
319         $new_dist = $dist * 3;
320     } elsif ( defined $cookie->{ 'ZOOM_OUT3' } ) {
321         $new_dist = $dist * 10;
322     }
323
324     if ( $new_dist )
325     {
326         $dist_diff = $dist - $new_dist;
327
328         $cookie->{ 'NAV_START' } = int( $cookie->{ 'NAV_START' } + ( $dist_diff / 2 ) );
329         $cookie->{ 'NAV_END' }   = int( $cookie->{ 'NAV_END' }   - ( $dist_diff / 2 ) );
330
331         $cookie->{ 'NAV_START' } = 1     if $cookie->{ 'NAV_START' } <= 0;
332         $cookie->{ 'NAV_END' }   = $max if $cookie->{ 'NAV_END' } > $max;
333     }
334 }
335
336
337 sub cookie_move
338 {
339     my ( $cookie,
340        ) = @_;
341
342     my ( $max, $dist, $shift, $new_start, $new_end );
343
344     $max = Maasha::Filesys::file_size( Maasha::KISS::Track::path_seq( $cookie ) );
345
346     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
347
348     if ( defined $cookie->{ 'MOVE_LEFT1' } ) {
349         $shift = -1 * $dist * 0.10;
350     } elsif ( defined $cookie->{ 'MOVE_LEFT2' } ) {
351         $shift = -1 * $dist * 0.475;
352     } elsif ( defined $cookie->{ 'MOVE_LEFT3' } ) {
353         $shift = -1 * $dist * 0.95;
354     } elsif ( defined $cookie->{ 'MOVE_RIGHT1' } ) {
355         $shift = $dist * 0.10;
356     } elsif ( defined $cookie->{ 'MOVE_RIGHT2' } ) {
357         $shift = $dist * 0.475;
358     } elsif ( defined $cookie->{ 'MOVE_RIGHT3' } ) {
359         $shift = $dist * 0.95;
360     }
361
362     if ( $shift )
363     {
364         $new_start = int( $cookie->{ 'NAV_START' } + $shift );
365         $new_end   = int( $cookie->{ 'NAV_END' }   + $shift );
366
367         if ( $new_start > 0 and $new_end < $max )
368         {
369             $cookie->{ 'NAV_START' } = $new_start;
370             $cookie->{ 'NAV_END' }   = $new_end;
371         }
372     }
373 }
374
375
376 sub page
377 {
378     my ( $cookie,
379        ) = @_;
380
381     # Returns a list.
382
383     my ( @html, $list, $item, $href );
384
385     push @html, breadcrumb( $cookie );
386
387     $list = "LIST_" . uc $cookie->{ 'PAGE' };
388
389     if ( $cookie->{ 'PAGE' } eq 'export' )
390     {
391         push @html, Maasha::XHTML::h2( txt => "Export", class => 'center' );
392     }
393     elsif ( $cookie->{ 'PAGE' } ne 'browse' )
394     {
395         push @html, Maasha::XHTML::h2( txt => "Select $cookie->{ 'PAGE' }", class => 'center' );
396
397         push @html, Maasha::XHTML::table_beg( summary => "Select table", align => 'center', cellpadding => '5px' );
398
399         foreach $item ( @{ $cookie->{ $list } } )
400         {
401             $cookie->{ uc $cookie->{ 'PAGE' } } = $item;
402
403             $href = page_href( $cookie, page_next( $cookie ) );
404
405             push @html, Maasha::XHTML::table_row_simple( tr => [ Maasha::XHTML::ln( txt => $item, href => $href ) ] );
406         }
407
408         push @html, Maasha::XHTML::table_end;
409     }
410     else
411     {
412         push @html, sec_navigate( $cookie );
413         push @html, sec_browse( $cookie );
414     }
415
416     return wantarray ? @html : \@html;
417 }
418
419
420 sub page_next
421 {
422     my ( $cookie,
423        ) = @_;
424
425     my ( $i );
426
427     for ( $i = 0; $i < @{ $cookie->{ 'LIST_PAGES' } }; $i++ ) {
428         last if $cookie->{ 'PAGE' } eq $cookie->{ 'LIST_PAGES' }->[ $i ];
429     }
430
431     return $cookie->{ 'LIST_PAGES' }->[ $i + 1 ];
432 }
433
434
435 sub breadcrumb
436 {
437     my ( $cookie,
438        ) = @_;
439
440     # Returns a list.
441
442     my ( @pages, $page, @row1, @row2, @html, $href, $txt );
443     
444     @pages = @{ $cookie->{ 'LIST_PAGES' } };
445
446     pop @pages;   # remove 'browse'
447
448     foreach $page ( @pages )
449     {
450         $href = page_href( $cookie, $page );
451
452         $txt = $cookie->{ uc $page } || "";
453
454         push @row1, Maasha::XHTML::ln( txt => $page, href => $href, class => 'inline' );
455         push @row2, Maasha::XHTML::p( txt => $txt, class => 'inline' );
456
457         last if $page eq $cookie->{ 'PAGE' };
458     }
459
460     push @html, Maasha::XHTML::table_beg( summary => "Taxonomy table", align => 'center', cellpadding => '5px' );
461     push @html, Maasha::XHTML::table_row_simple( tr => \@row1, align => 'center' );
462     push @html, Maasha::XHTML::table_row_simple( tr => \@row2, align => 'center' );
463     push @html, Maasha::XHTML::table_end;
464
465     return wantarray ? @html : \@html;
466 }
467
468
469 sub page_href
470 {
471     my ( $cookie,
472          $page,
473        ) = @_;
474
475     # Returns a string.
476
477     my ( @href );
478
479     while ( 1 )
480     {
481         push @href, "$cookie->{ 'SCRIPT' }?page=$page";
482         push @href, "user=$cookie->{ 'USER' }"         if $cookie->{ 'USER' };
483         last if $page eq 'user';
484         push @href, "clade=$cookie->{ 'CLADE' }"       if $cookie->{ 'CLADE' };
485         last if $page eq 'clade';
486         push @href, "genome=$cookie->{ 'GENOME' }"     if $cookie->{ 'GENOME' };
487         last if $page eq 'genome';
488         push @href, "assembly=$cookie->{ 'ASSEMBLY' }" if $cookie->{ 'ASSEMBLY' };
489         last if $page eq 'assembly';
490         push @href, "contig=$cookie->{ 'CONTIG' }"     if $cookie->{ 'CONTIG' };
491         last if $page eq 'contig';
492         last;
493     }
494
495     return join "&", @href;
496 }
497
498
499 sub sec_navigate
500 {
501     my ( $cookie,
502        ) = @_;
503
504     # Returns a list.
505
506     my ( @html );
507
508     push @html, Maasha::XHTML::table_beg( summary => "Navigation table", align => 'center' );
509     push @html, Maasha::XHTML::table_row_simple( tr => [ qw( Start End ) ], align => 'center' );
510     push @html, Maasha::XHTML::table_row_simple( tr => [
511         Maasha::XHTML::text( name => "nav_start", value => Maasha::Calc::commify( $cookie->{ 'NAV_START' } ), size => 20 ),
512         Maasha::XHTML::text( name => "nav_end",   value => Maasha::Calc::commify( $cookie->{ 'NAV_END' } ),   size => 20 ), 
513         Maasha::XHTML::submit( name => "nav_submit", value => "Submit" ),
514     ] );
515     push @html, Maasha::XHTML::table_end;
516
517     push @html, Maasha::XHTML::table_beg( summary => "Zoom table", align => 'center' );
518     push @html, Maasha::XHTML::table_row_simple( tr => [
519         Maasha::XHTML::p( txt => 'Move:' ),
520         Maasha::XHTML::submit( name => "move_left3",  value => "<<<", title => "move 95% to the left" ),
521         Maasha::XHTML::submit( name => "move_left2",  value => "<<",  title => "move 47.5% to the left" ),
522         Maasha::XHTML::submit( name => "move_left1",  value => "<",   title => "move 10% to the left" ),
523         Maasha::XHTML::submit( name => "move_right1", value => ">",   title => "move 10% to the rigth" ),
524         Maasha::XHTML::submit( name => "move_right2", value => ">>",  title => "move 47.5% to the rigth" ),
525         Maasha::XHTML::submit( name => "move_right3", value => ">>>", title => "move 95% to the right" ),
526         Maasha::XHTML::p( txt => 'Zoom in:' ),
527         Maasha::XHTML::submit( name => "zoom_in1", value => "1.5x" ),
528         Maasha::XHTML::submit( name => "zoom_in2", value => "3x" ),
529         Maasha::XHTML::submit( name => "zoom_in3", value => "10x" ),
530         Maasha::XHTML::p( txt => 'Zoom out:' ),
531         Maasha::XHTML::submit( name => "zoom_out1", value => "1.5x" ),
532         Maasha::XHTML::submit( name => "zoom_out2", value => "3x" ),
533         Maasha::XHTML::submit( name => "zoom_out3", value => "10x" ),
534     ] );
535     push @html, Maasha::XHTML::table_end;
536
537     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "page",     value => "browse" ) );
538     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "user",     value => "$cookie->{ 'USER' }" ) );
539     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "clade",    value => "$cookie->{ 'CLADE' }" ) );
540     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "genome",   value => "$cookie->{ 'GENOME' }" ) );
541     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "assembly", value => "$cookie->{ 'ASSEMBLY' }" ) );
542     push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "contig",   value => "$cookie->{ 'CONTIG' }" ) );
543
544     return wantarray ? @html : \@html;
545 }
546
547
548 sub sec_browse
549 {
550     my ( $cookie,
551        ) = @_;
552
553     # Returns a list.
554
555     my ( $draw_metrics, @tracks, $i, @features, $feat, $elem, $file, $surface, $cr, @html, @img );
556
557     $draw_metrics = {
558         IMG_WIDTH       => 1200,
559         IMG_HEIGHT      => 800,
560         TRACK_OFFSET    => 20,
561         TRACK_SPACE     => 20,
562         RULER_FONT_SIZE => 10,
563         RULER_COLOR     => [ 0, 0, 0 ],
564         SEQ_FONT_SIZE   => 10,
565         SEQ_COLOR       => [ 0, 0, 0, ],
566         FEAT_WIDTH      => 5,
567         FEAT_COLOR      => [ 0, 1, 0 ],
568     };
569     
570     push @features, [ Maasha::KISS::Track::track_ruler( $draw_metrics, $cookie ) ];
571     push @features, [ Maasha::KISS::Track::track_seq( $draw_metrics, $cookie ) ];
572
573     @tracks = Maasha::KISS::Track::path_tracks( $cookie );
574
575     for ( $i = 0; $i < @tracks; $i++ )
576     {
577         $draw_metrics->{ 'FEAT_COLOR' } = palette( $i );
578
579         push @features, [ Maasha::KISS::Track::track_feature( $tracks[ $i ], $draw_metrics, $cookie ) ];
580     }
581
582     $file = "fisk.png";
583
584     $surface = Cairo::ImageSurface->create( 'argb32', $draw_metrics->{ 'IMG_WIDTH' }, $draw_metrics->{ 'TRACK_OFFSET' } );
585     $cr      = Cairo::Context->create( $surface );
586
587     foreach $feat ( @features ) {
588         Maasha::KISS::Draw::draw_feature( $cr, $feat ) if $feat;
589     }
590
591     Maasha::KISS::Draw::file_png( $surface, $file );
592
593     push @img, Maasha::XHTML::img(
594         src    => $file,
595         alt    => "Browser Tracks",
596         height => $draw_metrics->{ 'TRACK_OFFSET' },
597         width  => $draw_metrics->{ 'IMG_WIDTH' },
598         id     => "browser_map",
599         usemap => "#browser_map"
600     );
601
602     push @img, Maasha::XHTML::map_beg( name => "browser_map", id => "browser_map" );
603
604     foreach $feat ( @features )
605     {
606         foreach $elem ( @{ $feat } )
607         {
608             next if $elem->{ 'type' } eq 'text';
609
610             push @img, Maasha::XHTML::area(
611                 href   => page_href( $cookie, "export" ) . "&Q_ID=$elem->{ 'id' }",
612                 shape  => "rect",
613                 coords => "$elem->{ x1 }, $elem->{ y1 }, $elem->{ x2 }, $elem->{ y2 }", title => "$elem->{ 'title' }",
614             );
615         }
616     }
617
618     push @img, Maasha::XHTML::map_end();
619
620     push @html, Maasha::XHTML::p( txt => join( "\n", @img ) );
621
622     @html = Maasha::XHTML::div( txt => join( "\n", @html ), class => 'browse' );
623
624     return wantarray ? @html : \@html;
625 }
626
627
628 sub palette
629 {
630     my ( $i,
631        ) = @_;
632
633     my ( $palette, $color );
634
635     $palette = [
636         [ 30, 130, 130 ],
637         [ 30, 50, 150 ],
638         [ 130, 130, 50 ],
639         [ 130, 90, 130 ],
640         [ 130, 70, 70 ],
641         [ 70, 170, 130 ],
642         [ 130, 170, 50 ],
643     ];
644
645     $color = $palette->[ $i ];
646
647     map { $_ /= 255 } @{ $color };
648
649     return $color;
650 }
651
652 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
653
654
655 __END__
656
657     # push @html, Maasha::KISS::Draw::hdump( $features );
658
659     $t0 = Time::HiRes::gettimeofday();
660     $t1 = Time::HiRes::gettimeofday();