#!/usr/bin/perl -w #Copyright (c) 2008 Matteo Ramazzotti, matteo.ramazzotti@unifi.it #This code is free for academic and non commercial use. #THIS CODE IS PROVIDED ''AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED #WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF #MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND #CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. use Tk; use Tk::Canvas; use Tk::Font; use Tk::Button; use Tk::Label; use Tk::Entry; use Tk::Balloon; use Tk::BrowseEntry; #use TK::Bitmap; #needed for linux PAR if ($^O =~ /linux/i || $^O =~ /darwin/i) { $xclip = system('which xclip 2>&1 > /dev/null'); $pasteOK = 'off' if ($xclip != 0); print "ERROR: xclip not found.\n" if ($xclip != 0); $conf_file = $ENV{'HOME'}."\/XYLab.conf"; $log_file = $ENV{'HOME'}."\/XYLab.log"; } if ($^O =~ /win32/i){ require Win32::Clipboard or ($pasteOK = 'off'); $clip = Win32::Clipboard->new; require Win32; $OS = Win32::GetOSName(); print "\n",$OS,"\n\n"; $conf_file = 'c:\\'.$ENV{'HOMEPATH'}."\\XYLab.conf" if ($OS =~ /xp/i); $conf_file = "c:\\XYLab.conf" if ($OS !~ /xp/i); $log_file = 'c:\\'.$ENV{'HOMEPATH'}."\\XYLab.log" if ($OS =~ /xp/i); $log_file = "c:\\XYLab.log" if ($OS !~ /xp/i); } $xstateold = ''; $ystateold = ''; $xcolold = ''; $ycolold = ''; $debugmode = 0; &load_conf if (-e $conf_file); &factory_defaults if (!-e $conf_file); &update_conf if (!-e $conf_file); sub factory_defaults { $plot_x_size = 800; # initial plot area width (in pixel units) $plot_y_size = 500; # initial plot area height (in pixel units) $area_movements = 10; # amount of movement associated with arrows (in pixel units) $x_axis_dist = 10; # initial x-axis spacing (% of plot area width) $y_axis_dist = 10; # initial y-axis spacing (% of plot area height) $axes_redimension = 1; # redimension factor associated with arrows (in % units) $copywin_height = 5; # initial height (in character units) of the copy-paste region $xlabel_size = 8; # initial size of the X axis text $ylabel_size = 8; # initial size of the Y axis text $ballabel_size = 5; # initial size of the Label text $x_dim = $plot_x_size; #used for fullscreen $y_dim = $plot_y_size; #used for fullscreen $x_ax_placement = int($plot_x_size*$x_axis_dist/100); #axis distance configuration $y_ax_placement = int($plot_y_size*$y_axis_dist/100); #axis distance configuration $label_delay = 100; } sub load_conf { print "Loading init values from XYLab.conf..."; open (IN, $conf_file); foreach () { chomp $_; next if ($_ =~ /^#/ || $_ !~ /\w/); $_ =~ s/ //g; @tmp = split (/=/,$_); $plot_x_size = $tmp[1] if ($tmp[0] =~ /plot_width/i); $plot_y_size = $tmp[1] if ($tmp[0] =~ /plot_height/i); $area_movements = $tmp[1] if ($tmp[0] =~ /area_mov/i); $x_axis_dist = $tmp[1] if ($tmp[0] =~ /x_ax_dist/i); $y_axis_dist = $tmp[1] if ($tmp[0] =~ /y_ax_dist/i); $axes_redimension = $tmp[1] if ($tmp[0] =~ /axes_mov/i); $copywin_height = $tmp[1] if ($tmp[0] =~ /copywin_height/i); $xlabel_size = $tmp[1] if ($tmp[0] =~ /x_label_size/i); $ylabel_size = $tmp[1] if ($tmp[0] =~ /y_label_size/i); $ballabel_size = $tmp[1] if ($tmp[0] =~ /ballon_label_size/i); $label_delay = $tmp[1] if ($tmp[0] =~ /label_delay/i); } close IN; $x_dim = $plot_x_size; #used for fullscreen $y_dim = $plot_y_size; #used for fullscreen $x_ax_placement = int($plot_x_size*$x_axis_dist/100); #axis distance configuration $y_ax_placement = int($plot_y_size*$y_axis_dist/100); #axis distance configuration print "done.\n"; } sub update_conf { print "Writing new configuration to XYLab.conf..."; open (OUT, ">$conf_file") or warn "WARNING: Cannot modify XYLab.conf !!!"; print OUT "### XYLab configuration file ###\n\n"; print OUT "plot_width=$plot_x_size\n"; print OUT "plot_height=$plot_y_size\n"; print OUT "area_mov=$area_movements\n"; print OUT "x_ax_dist=$x_axis_dist\n"; print OUT "y_ax_dist=$y_axis_dist\n"; print OUT "axes_mov=$axes_redimension\n"; print OUT "copywin_height=$copywin_height\n"; print OUT "x_label_size=$xlabel_size\n"; print OUT "y_label_size=$ylabel_size\n"; print OUT "ballon_label_size=$ballabel_size\n"; print OUT "label_delay=$label_delay\n"; close OUT; print "done.\n"; } #CONFIGURATION OPTIONS @restrict = qw/on off/; @labelperm = qw/on off/; @fix_status = qw/fix unfix/; @high_w_copy = qw/on off/; @types = qw/Square Circle/; @fills = qw/empty filled/; @colors = qw/red blue green black/; @ftypes = qw/Square Circle/; @ffills = qw/empty filled/; @fcolors = qw/blue green black red/; @xalt = qw/off on/; @yalt = qw/off on/; $point_type = 'Circle'; $point_size = 1; $point_fill = 'filled'; $point_color = 'black'; $found_type = 'Circle'; $found_size = 2; $found_fill = 'filled'; $found_color = 'red'; #CONFIGURATION DEFAULTS $session = 0; $separator = '\t'; $mousectrl = 'zoom'; $restrict = 'off'; $high_w_copy = 'off'; $labview = 'off'; #$found_status = 'on'; $xlabstat = 'on'; $ylabstat = 'on'; $xlabform = 'norm'; $ylabform = 'norm'; $xscalestate = 'wt'; $yscalestate = 'wt'; $zoomstate = 0; $sortstate = 'null'; $labelstate = 'single'; $copystate = 'single'; $search_string = ''; $search_string_ = ''; $fix = 'unfix'; $find_n_save = 0; $touse = ''; #MAIN SUBROUTINE LAUNCH AT STARTUP &init_interface; &create_interface; &make_menu; #&updateplot; if ($ARGV[0] && -e $ARGV[0]) {$in = $ARGV[0]; &load_data;&init_data;&bind_data_to_interface;&plotpoint;} MainLoop; sub open_file { $types = [['Tab separated values','.txt'],['Comma separated values','.csv'],['GenePix file','.gpr']]; # $types = [['Tab or comma separated values','.'],['Tab or comma separated values','.']]; $in = $main->getOpenFile(-filetypes=>$types); return 'false' if (!$in); $separator = ',' if ($in =~ /\.csv/); $separator = '\t' if ($in =~ /\.txt/ || $in =~ /\.gpr/); $skip = 28 if ($in =~ /\.gpr/); load_values($separator); &init_data; &bind_data_to_interface; &plotpoint; } sub clipread { if ($^O =~ /win/i) { $dat = $clip->GetText(); # print $dat; # @in = split (/[\n*\r*]+/,$dat); } if ($^O =~ /linux/i) { print "Using linux clipboard\n"; #catch xclipboard in $url variable $/ = undef; open (IN, "xclip -o |"); $dat = ; close IN; $/ ="\n"; } @in = split (/(?:\015{1,2}\012|\015|\012)/, $dat); load_values($separator,\@in); &init_data; &bind_data_to_interface; &plotpoint; } sub init_interface { $main = MainWindow->new(-title=>'XYLab - by matteo.ramazzotti@unifi.it 2008'); $main->geometry('+0+0'); $main->fontCreate('matram',-family=>'Courier', -size=>10); # $main->fontCreate('matrams',-family=>'Courier', -size=>8); # $main->fontCreate('matramx',-family=>'Courier', -size=>$xlabel_size); #plot labels font $main->fontCreate('matramy',-family=>'Courier', -size=>$ylabel_size); #plot labels font $main->fontCreate('matraml',-family=>'Courier', -size=>$ballabel_size); #plot labels font $main->resizable(0,0); $b = $main->Balloon(-background=>'white', -initwait=>$label_delay); $f0 = $main->Frame(-relief=>'ridge', -width=>820)->pack(-anchor=>'w'); $f1 = $main->Frame(-relief=>'ridge', -width=>820)->pack(-anchor=>'w'); $f2 = $main->Frame(-relief=>'ridge', -width=>820)->pack(-anchor=>'w'); $f3 = $main->Frame(-relief=>'ridge', -width=>820)->pack(-anchor=>'w'); $f4 = $main->Frame(-relief=>'ridge', -width=>820)->pack(-anchor=>'w'); $main->OnDestroy(sub {close OLDOUT;close OLDERR}); } sub update_label_size { $main->fontConfigure('matramx', -size=>$xlabel_size); #plot x labels font $main->fontConfigure('matramy', -size=>$ylabel_size); #plot y labels font $main->fontConfigure('matraml', -size=>$ballabel_size); #plot y labels font } sub create_interface { print "Creating interface..."; #FRAME0 $c = $f0->Canvas(-width=>$plot_x_size, -height=>$plot_y_size, -background=>'white', -cursor=>'crosshair', -relief=>'solid')->pack(); #grid(-columnspan=>14); $t = $f0->Scrolled('Text',-height=>$copywin_height, -scrollbars=>'se', -font=>'matram', -wrap=>'none')->pack(-fill=>'both'); #grid(-columnspan=>14); #FRAME1 $f1->Label(-text=>'X col', -font=>'matram', -width=>6)->pack(-side=>'left'); $browseX = $f1->BrowseEntry(-width=>20, -variable=>\$xcoltoplot, -background=>'white', -browsecmd=>\&plotpoint)->pack(-side=>'left'); $f1->Label(-text=>'min', -font=>'matram')->pack(-side=>'left'); $f1->Entry(-width=>7, -textvariable=>\$xmin)->pack(-side=>'left'); $f1->Label(-text=>'max', -font=>'matram')->pack(-side=>'left'); $f1->Entry(-width=>7, -textvariable=>\$xmax)->pack(-side=>'left'); $f1->Checkbutton(-text=>'Log', -font=>'matram', -variable=>\$xscalestate, -onvalue=>'log', -offvalue=>'wt', -command=>\&plotpoint)->pack(-side=>'left'); $f1->Checkbutton(-text=>'Norm', -font=>'matram', -variable=>\$xscalestate, -onvalue=>'norm',-offvalue=>'wt', -command=>\&plotpoint)->pack(-side=>'left'); $f1->Checkbutton(-text=>'Std', -font=>'matram', -variable=>\$xscalestate, -onvalue=>'std',-offvalue=>'wt', -command=>\&plotpoint)->pack(-side=>'left'); $f1->Checkbutton(-text=>'Cent', -font=>'matram', -variable=>\$xscalestate, -onvalue=>'cent',-offvalue=>'wt', -command=>\&plotpoint)->pack(-side=>'left'); $f1->Label(-text=>"| Value", -font=>'matrams')->pack(-side=>'left'); $f1->Label(-textvariable=>\$xpos, -font=>'matrams')->pack(-side=>'left'); #FRAME2 $f2->Label(-text=>'Y col', -font=>'matram', -width=>6)->pack(-side=>'left'); $browseY = $f2->BrowseEntry(-width=>20, -variable=>\$ycoltoplot, -background=>'white', -browsecmd=>\&plotpoint)->pack(-side=>'left'); $f2->Label(-text=>'min', -font=>'matram')->pack(-side=>'left'); $f2->Entry(-width=>7, -textvariable=>\$ymin)->pack(-side=>'left'); $f2->Label(-text=>'max', -font=>'matram')->pack(-side=>'left'); $f2->Entry(-width=>7, -textvariable=>\$ymax)->pack(-side=>'left'); $f2->Checkbutton(-text=>'Log', -font=>'matram', -variable=>\$yscalestate, -onvalue=>'log', -offvalue=>'wt', -command=>\&plotpoint)->pack(-side=>'left'); $f2->Checkbutton(-text=>'Norm', -font=>'matram', -variable=>\$yscalestate, -onvalue=>'norm',-offvalue=>'wt', -command=>\&plotpoint)->pack(-side=>'left'); $f2->Checkbutton(-text=>'Std', -font=>'matram', -variable=>\$yscalestate, -onvalue=>'std',-offvalue=>'wt', -command=>\&plotpoint)->pack(-side=>'left'); $f2->Checkbutton(-text=>'Cent', -font=>'matram', -variable=>\$yscalestate, -onvalue=>'cent',-offvalue=>'wt', -command=>\&plotpoint)->pack(-side=>'left'); $f2->Label(-text=>"| Value", -font=>'matrams')->pack(-side=>'left'); $f2->Label(-textvariable=>\$ypos, -font=>'matrams')->pack(-side=>'left'); #FRAME3 $f3->Label(-text=>'Labels', -font=>'matram', -width=>6)->pack(-side=>'left'); $browseBall = $f3->BrowseEntry(-width=>20, -variable=>\$balloon_col, -background=>'white', -browsecmd=>\&plotpoint)->pack(-side=>'left'); $f3->Label(-text=>"Find string", -font=>'matram')->pack(-side=>'left'); $f3->Entry(-width=>20, -textvariable=>\$search_string, -background=>'white')->pack(-side=>'left'); $f3->Label(-text=>" ", -font=>'matram')->pack(-side=>'left'); $lock_but = $f3->Button(-text=>"Unlock", -font=>'matrams', -command=>\&lock_mode, -activebackground=>'green', -background=>'green', -width=>8)->pack(-side=>'left'); $f3->Label(-text=>" ", -font=>'matram')->pack(-side=>'left'); $restrict_but = $f3->Button(-text=>"Full", -font=>'matrams', -command=>\&restrict_mode, -activebackground=>'green', -background=>'green', -width=>8)->pack(-side=>'left'); $f3->Label(-text=>" ", -font=>'matram')->pack(-side=>'left'); $f3->Radiobutton (-text=>'Zoom', -variable=>\$mousectrl, -value=>'zoom', -font=>'matram')->pack(-side=>'left'); $f3->Radiobutton (-text=>'Copy', -variable=>\$mousectrl, -value=>'copy', -font=>'matram')->pack(-side=>'left'); $f4->Label(-textvariable=>\$statusbar, -font=>'matram')->pack(-side=>'left', -fill=>'both'); print "done.\n"; } sub lock_mode { $fix = shift @fix_status; push (@fix_status,$fix); $lock_but->configure(-text=>'Lock', -background=>'red', -activebackground=>'red') if ($fix eq 'fix'); $lock_but->configure(-text=>'Unlock', -background=>'green', -activebackground=>'green') if ($fix eq 'unfix'); } sub restrict_mode { return 'false' if ($restrict eq 'off' && $search_string eq '' || $found_cnt == 0); $restrict = shift @restrict; push (@restrict, $restrict); $restrict_but->configure(-text=>'Free', -background=>'green', -activebackground=>'green') if ($restrict eq 'off'); $restrict_but->configure(-text=>'Restrict', -background=>'red', -activebackground=>'red') if ($restrict eq 'on'); &plotpoint; } sub make_menu { print "Building up menu..."; $menubar = $main->Menu; $main->configure(-menu=>$menubar); $data_ = $menubar->cascade(-label=>'Data', -tearoff=>0); $data_->command (-label=>'Load', -command => \&open_file); $data_->command (-label=>'Paste', -command => \&clipread); $data_->separator; $data_->command (-label=>'Save current data', -command => \&save_current); $data_->command (-label=>'Save visible data', -command => \&save_visible); $data_->separator; $data_->command (-label=>'Save plot', -command => \&saveto); $copy_ = $menubar->cascade(-label=>'Copy', -tearoff=>0); $copy_->checkbutton (-label=>'Single', -variable=>\$copystate, -onvalue=>'single', -command => sub {$copystate = 'single'}); $copy_->checkbutton (-label=>'Full', -variable=>\$copystate, -onvalue=>'full', -command => sub {$copystate = 'full'}); $copy_->separator; $copy_->command(-label=>'Highlight copied', -command => sub {$high_copy = 1;&plotpoint;$high_copy = 0;}); $copy_->command(-label=>'Highlight while copying on/off', -command => sub {$high_w_copy = shift @high_w_copy; push (@high_w_copy,$high_w_copy)}); $copy_->command(-label=>'Remove highlights', -command => sub {$high_copy = 0; &plotpoint}); $copy_->separator; $copy_->command (-label=>'Clear copy buffer', -command => sub{$res = ''; $touse = ''; $session = 0; $t->Contents($res);}); $copy_->command (-label=>'Save copy buffer', -command => \&save_copied); $xaxis_ = $menubar->cascade(-label=>'X axis', -tearoff=>0); $xaxis_format_ = $xaxis_ ->cascade(-label=>'Format', -tearoff=>0); $xaxis_format_->checkbutton (-label=>'normal', -variable=>\$xlabform, -onvalue=>'norm', -command => sub {$xlabform = 'norm';&updateplot}); $xaxis_format_->checkbutton (-label=>'full', -variable=>\$xlabform, -onvalue=>'full', -command => sub {$xlabform = 'full';&updateplot}); $xaxis_format_->checkbutton (-label=>'int', -variable=>\$xlabform, -onvalue=>'int', -command => sub {$xlabform = 'int';&updateplot}); $xaxis_format_->checkbutton (-label=>'sci', -variable=>\$xlabform, -onvalue=>'sci', -command => sub {$xlabform = 'sci';&updateplot}); $xaxis_->command (-label=>'labels on/off', -command => sub {$xlabstat = shift @xalt; push (@xalt, $xlabstat);&updateplot}); $xaxis_->command(-label=>'Increase font', -command => sub {$xlabel_size++ if ($xlabel_size < 9); print "Label size set to $xlabel_size\n"; &plotpoint;}); $xaxis_->command(-label=>'Decrease font', -command => sub {$xlabel_size--; $xlabel_size = 2 if ($xlabel_size < 2); print "Label size set to $xlabel_size\n";&plotpoint}); $yaxis_ = $menubar->cascade(-label=>'Y axis', -tearoff=>0); $yaxis_format_ = $yaxis_ ->cascade(-label=>'Format', -tearoff=>0); $yaxis_format_->checkbutton (-label=>'normal', -variable=>\$ylabform, -onvalue=>'norm', -command => sub {$ylabform = 'norm';&updateplot}); $yaxis_format_->checkbutton (-label=>'full', -variable=>\$ylabform, -onvalue=>'full', -command => sub {$ylabform = 'full';&updateplot}); $yaxis_format_->checkbutton (-label=>'int', -variable=>\$ylabform, -onvalue=>'int', -command => sub {$ylabform = 'int';&updateplot}); $yaxis_format_->checkbutton (-label=>'sci', -variable=>\$ylabform, -onvalue=>'sci', -command => sub {$ylabform = 'sci';&updateplot}); $yaxis_->command (-label=>'labels on/off', -command => sub {$ylabstat = shift @yalt; push (@yalt, $ylabstat);&updateplot}); $yaxis_->command(-label=>'Increase font', -command => sub {$ylabel_size++ if ($ylabel_size < 9); print "Label size set to $ylabel_size\n"; &plotpoint;}); $yaxis_->command(-label=>'Decrease font', -command => sub {$ylabel_size--; $ylabel_size = 2 if ($ylabel_size < 2); print "Label size set to $ylabel_size\n";&plotpoint}); $labels_ = $menubar->cascade(-label=>'Labels', -tearoff=>0); $labels_->checkbutton (-label=>'Single', -variable=>\$labelstate, -onvalue=>'single', -command => sub {$labelstate = 'single';&plotpoint}); $labels_->checkbutton (-label=>'Full', -variable=>\$labelstate, -onvalue=>'full', -command => sub {$labelstate = 'full';&plotpoint}); $labels_->command (-label=>'Permanent on/off', -command => sub {$labview = shift @labelperm; push (@labelperm,$labview);&plotpoint}); $labels_->command(-label=>'Increase font', -command => sub {$ballabel_size++ if ($ballabel_size < 9);&plotpoint;}); $labels_->command(-label=>'Decrease font', -command => sub {$ballabel_size--; $ballabel_size = 2 if ($ballabel_size < 2);&plotpoint}); $found_ = $menubar->cascade(-label=>'Find', -tearoff=>0); $found_->command(-label=>'Save', -command => sub {$find_n_save = 1; &plotpoint;&save_copied;$find_n_save = 0;$find2save = '';}); $found_->separator(); $found_->command(-label=>'Increase size', -command => sub {$found_size++ if ($found_size < 9); print "Point size set to $point_size\n"; &plotpoint;}); $found_->command(-label=>'Decrease size', -command => sub {$found_size--; $found_size = 2 if ($found_size < 2); print "Point size set to $point_size\n";&plotpoint}); $found_->command(-label=>'Toggle empty/filled', -command => sub {$found_fill = shift @ffills; push (@ffills, $found_fill); print "Fill found set to $found_fill\n";&plotstyle}); $found_->command(-label=>'Toggle circle/square', -command => sub {$found_type = shift @ftypes; push (@ftypes, $found_type); print "Found type set to $found_type\n";&plotpoint}); $found_->command(-label=>'Toggle black/red/blue/green', -command => sub {$found_color = shift @fcolors; push (@fcolors, $found_color); print "Color point set to $found_color ->", join (" ",@fcolors),"\n";&plotstyle}); $points_ = $menubar->cascade(-label=>'Points', -tearoff=>0); $points_->command(-label=>'X sort on', -command => sub {$sortstate = 'xsort'; &plotpoint}); $points_->command(-label=>'Y sort on', -command => sub {$sortstate = 'ysort'; &plotpoint}); $points_->command(-label=>'Sort off', -command => sub {$sortstate = 'null'; &plotpoint}); $points_->separator(); $points_->command(-label=>'Increase size', -command => sub {$point_size++ if ($point_size < 8); print "Point size set to $point_size\n"; &plotpoint}); $points_->command(-label=>'Decrease size', -command => sub {$point_size--; $point_size = 1 if ($point_size < 1); print "Point size set to $point_size\n";&plotpoint}); $points_->command(-label=>'Toggle empty/filled', -command => sub {$point_fill = shift @fills; push (@fills, $point_fill); print "Fill point set to $point_fill\n";&plotstyle}); $points_->command(-label=>'Toggle circle/square', -command => sub {$point_type = shift @types; push (@types, $point_type); print "Point type set to $point_type\n";&plotpoint}); $points_->command(-label=>'Rotate black/red/blue/green', -command => sub {$point_color = shift @colors; push (@colors, $point_color); print "Color point set to $point_color ->", join (" ",@colors),"\n";&plotstyle}); $conf_ = $menubar->cascade(-label=>'Config', -tearoff=>0); $conf_->command (-label=>'Reload factory defaults', -command => sub { &factory_defaults; &update_conf; $c->configure(-width=>$plot_x_size); $c->configure(-height=>$plot_y_size); &plotpoint; print "Factory default values restored and written to XYLab.conf\n"; }); $conf_->command (-label=>'Show current conf', -command => sub {open (IN,$conf_file);$t->Contents(join("",)); close IN;}); $conf_->command (-label=>'Save current conf', -command => sub { $newconf = $t->get('1.0','end'); return 'false'if ($newconf !~ /XYLab configuration file/); open (OUT,">$conf_file"); print OUT $newconf; close OUT; &load_conf; $c->configure(-width=>$plot_x_size); $c->configure(-height=>$plot_y_size); &plotpoint; print "Current configuration loaded and written to XYLab.conf\n"; }); print "done.\n"; } sub reset_all { undef ($dat) if ($dat); undef (@data) if (@data); undef (@unlogarithmable) if (@unlogarithmable); undef (@unplottable) if (@unplottable); undef (@minval) if (@minval); undef (@maxval) if (@maxval); undef (@labels) if (@labels); undef ($dataend) if ($dataend); undef ($xcoltoplot) if ($xcoltoplot); undef ($ycoltoplot) if ($ycoltoplot); undef (@logarithmable) if (@logarithmable); undef (@plottable) if (@plottable); undef (%ball) if (%ball); } sub save_copied { #i.e. everythig that is in the paste area. $outfile = $main->getSaveFile; return 'false' if (!$outfile); $outfile .= ".txt" if ($outfile !~ /\./); open (OUT,">$outfile"); print OUT $res if ($find_n_save != 1); print OUT $find2save if ($find_n_save == 1); close OUT; } sub save_current { #i.e. save the X Y and Labels that are at that moment displayed on the plot area $outfile = $main->getSaveFile; return 'false' if (!$outfile); $outfile .= ".txt" if ($outfile !~ /\./); open (OUT,">$outfile"); print OUT $labels[$index{$xcoltoplot}],"\t",$labels[$index{$ycoltoplot}],"\t",$labels[$index{$balloon_col}],"\n"; foreach $lin (0..$#xtrue) { print OUT $xtrue[$lin],"\t",$ytrue[$lin],"\t",$balltrue[$lin],"\n" if ($xtrue[$lin] >= $xmin && $xtrue[$lin] <= $xmax && $ytrue[$lin] >= $ymin && $ytrue[$lin] <= $ymax); } close OUT; } sub save_visible { # i.e. save the full row corresponding to the point that are at that moment on the plot area return 'false' if ($sortstate eq 'xsort' || $sortstate eq 'ysort'); # in fact, until unique identifiers are added to the program, the 0..$#xtrue counter cannto be used since the data order is changed. $outfile = $main->getSaveFile; return 'false' if (!$outfile); $outfile .= ".txt" if ($outfile !~ /\./); open (OUT,">$outfile"); print OUT join ("\t",@labels),"\n"; foreach $lin (0..$#xtrue) { next if ($xtrue[$lin] < $xmin || $xtrue[$lin] > $xmax || $ytrue[$lin] < $ymin || $ytrue[$lin] > $ymax); foreach $col (0..$dataend) { print OUT $data[$col][$lin],"\t"; } print OUT "\n"; } close OUT; } sub init_data { print "Initializing data..."; foreach $num (0..$dataend) { $xcoltoplot = $labels[$num] if ($toplot[$num]); last if ($xcoltoplot); } foreach $num (0..$dataend) { $ycoltoplot = $labels[$num] if ($toplot[$num]); last if ($ycoltoplot && $ycoltoplot ne $xcoltoplot); } foreach $num (0..$dataend) { push(@plottable, $labels[$num]) if ($toplot[$num]); } foreach $num (0..$dataend) { push(@unplottable, $labels[$num]) if (!$toplot[$num]); } $balloon_col = $unplottable[0] if ($unplottable[0]); $balloon_col = $xcoltoplot if (!$unplottable[0]); $xcoltoplot_old = $xcoltoplot; $ycoltoplot_old = $ycoltoplot; $browseX->configure(-choices=>\@plottable); $browseY->configure(-choices=>\@plottable); $browseBall->configure(-choices=>\@labels); print "done.\n"; } sub load_values { $total = 0; my $sep = shift; my $inf = shift; if (!$inf) { open (IN, "$in"); @in = ; close IN; print "Loading data..."; } else { print "Loading data from clipboard..."; @in = @$inf; } if ($skip) { foreach (0..$skip) { shift @in; } } $labelrow = shift @in; chomp $labelrow; @labels = split (/$sep/, $labelrow); foreach (0..$#labels) { $index{$labels[$_]} = $_; } #read first line, containing column labels $row = 0; $line = -1; foreach (@in) { chomp $_; next if ($_ !~ /\w/); $line++; @vals = split (/\t/, $_); $dataend = $#vals; # $dataend-- if ($vals[$#vals] !~ /\w/); #in case of autogenerated files, the last tab does not contain data... $row++; foreach $num (0..$dataend) { $total++; $vals[$num] = 'n.a.' if (!exists $vals[$num] || $vals[$num] !~ /\w/); $data[$num][$line] = $vals[$num]; #bidimensional array with data if ($vals[$num] =~ /\d{1,}[e\.]{0,1}\d*/i && $vals[$num] !~ /[ abcdfghijklmnopqrstuvwxyz;,]/i) { #i.e. numbers and not letters $toplot[$num] = 1; } } } print "done. $total data loaded: $row entities, each with ", scalar(@vals), " features.\n"; $statusbar = "$total data loaded: $row entities, each with ". scalar(@vals). " features."; } sub bind_data_to_interface { print "Binding data..."; $main->bind(''=> \&plotpoint); $main->bind(''=> \&fullscreen); $main->bind(''=> sub {$debugmode++; &set_debug}); $main->bind('' => sub{resize('x+')}); $main->bind('' => sub{resize('x-')}); $main->bind('' => sub{resize('y+')}); $main->bind('' => sub{resize('y-')}); $main->bind('' => sub{resize('xs+')}); $main->bind('' => sub{resize('xs-')}); $main->bind('' => sub{resize('ys+')}); $main->bind('' => sub{resize('ys-')}); $c->CanvasBind("", [\&pos_conversion, Ev('x'), Ev('y')]); $c->CanvasBind("" , [\&zoom1, Ev('x'), Ev('y')]); $c->CanvasBind("" , [\&zoom2, Ev('x'), Ev('y')]); $c->CanvasBind("" => \&unzoom); $c->CanvasBind("" => \&unzoom); $main->bind("" => sub {$label_delay += 50;&lab_delay}); $main->bind("" => sub {$label_delay -= 50;&lab_delay}); $c->update; print "done\n"; } sub set_debug { if ($debugmode%2 > 0) { print "Debug mode: ON.\n"; # take copies of the file descriptors open(OLDOUT, ">&STDOUT"); open(OLDERR, ">&STDERR"); # redirect stdout and stderr open(STDOUT, ">> $log_file") or die "Can't redirect stdout: $!"; open(STDERR, ">&STDOUT") or die "Can't dup stdout: $!"; } if ($debugmode%2 == 0) { print "Debug mode: OFF.\n"; # close the redirected filehandles close(STDOUT) or die "Can't close STDOUT: $!"; close(STDERR) or die "Can't close STDERR: $!"; # restore stdout and stderr open(STDERR, ">&OLDERR") or die "Can't restore stderr: $!"; open(STDOUT, ">&OLDOUT") or die "Can't restore stdout: $!"; } } sub lab_delay { $label_delay = 50 if ($label_delay < 50); $b->configure(-initwait=>$label_delay); # $c->update; $main->update; &plotpoint; &update_conf; } sub fullscreen { $full++; @dim = $main->maxsize; if ($full%2 != 0) { $plot_x_size = $dim[0]; $plot_y_size = $dim[1]; $main->geometry('+0+0'); print "Going fullscreen ($dim[0] x $dim[1])..."; } if ($full%2 == 0) { $plot_x_size = $x_dim; $plot_y_size = $y_dim; print "Going normal ($x_dim x $y_dim)..."; } $c->configure(-width=>$plot_x_size); $c->configure(-height=>$plot_y_size); &plotpoint; print "done.\n"; } sub resize { my $what = shift; if ($what eq 'x+') { print "Interface x size increased of $area_movements px\n"; $plot_x_size += $area_movements; $x_dim = $plot_x_size; $c->configure(-width=>$plot_x_size); } if ($what eq 'x-') { print "Interface x size decreased of $area_movements px\n"; $plot_x_size -= $area_movements; $x_dim = $plot_x_size; $c->configure(-width=>$plot_x_size); } if ($what eq 'y+') { print "Interface y size increased of $area_movements px\n"; $plot_y_size += $area_movements; $y_dim = $plot_y_size; $c->configure(-height=>$plot_y_size); } if ($what eq 'y-') { print "Interface y size decreased of $area_movements px\n"; $plot_y_size -= $area_movements; $y_dim = $plot_y_size; $c->configure(-height=>$plot_y_size); } if ($what eq 'xs+') { return 'false' if ($x_axis_dist == 30); print "x axis spacing increased of $axes_redimension %\n"; $x_axis_dist += $axes_redimension; $x_ax_placement = int($plot_x_size*$x_axis_dist/100); } if ($what eq 'xs-') { return 'false' if ($x_axis_dist == 1); print "x axis spacing decreased of $axes_redimension %\n"; $x_axis_dist -= $axes_redimension; $x_ax_placement = int($plot_x_size*$x_axis_dist/100); } if ($what eq 'ys+') { return 'false' if ($y_axis_dist == 30); print "y axis spacing increased of $axes_redimension %\n"; $y_axis_dist += $axes_redimension; $y_ax_placement = int($plot_y_size*$y_axis_dist/100); } if ($what eq 'ys-') { return 'false' if ($y_axis_dist == 1); print "y axis spacing decreased of $axes_redimension %\n"; $y_axis_dist -= $axes_redimension; $y_ax_placement = int($plot_y_size*$y_axis_dist/100); } $c->update; $main->update; &plotpoint; &update_conf; } sub find_points { $search_string = shift; $search_string_ = $search_string; &plotpoint; } sub scale { my ($val,$a) = @_; $new = (($val/($xmax-$xmin))*($plot_x_size-2*$x_ax_placement)) - (($xmin/($xmax-$xmin))*($plot_x_size-2*$x_ax_placement)) + $x_ax_placement if ($a eq 'x'); $new = -(($val/($ymax-$ymin))*($plot_y_size-2*$y_ax_placement)) + (($ymin/($ymax-$ymin))*($plot_y_size-2*$y_ax_placement)) + $plot_y_size-$y_ax_placement if ($a eq 'y'); return $new; } sub pos_conversion { my ($canv, $x, $y) = @_; my $xposa = ($canv->canvasx($x) + (($xmin/($xmax-$xmin))*($plot_x_size-2*$x_ax_placement)) - $x_ax_placement) * (($xmax-$xmin)/($plot_x_size-2*$x_ax_placement)); my $yposa = ((($ymin/($ymax-$ymin))*($plot_y_size-2*$y_ax_placement)) + $plot_y_size-$y_ax_placement - $canv->canvasy($y)) * (($ymax-$ymin)/($plot_y_size-2*$y_ax_placement)); $xposa = 0 if ($xposa < $xmin || $yposa < $ymin); $yposa = 0 if ($yposa < $ymin || $xposa < $xmin); $xpos = sprintf($xfix,$xposa) if ($xlabform eq 'norm'); $xpos = $xposa if ($xlabform eq 'full'); $xpos = int($xposa) if ($xlabform eq 'int'); $xpos = sprintf('%.0e',$xposa) if ($xlabform eq 'sci'); $ypos = sprintf($yfix,$yposa) if ($ylabform eq 'norm'); $ypos = $yposa if ($ylabform eq 'full'); $ypos = int($yposa) if ($ylabform eq 'int'); $ypos = sprintf('%.0e',$yposa) if ($ylabform eq 'sci'); } sub zoom1 { my ($canv, $x, $y) = @_; $x1z = $canv->canvasx($x); $y1z = $canv->canvasy($y); $c->CanvasBind("" =>, [\&rectangle, Ev('x'), Ev('y')]); } sub rectangle { my ($canv, $x, $y) = @_; $c->delete('Rectangle'); $c->createRectangle($x1z,$y1z,$canv->canvasx($x),$canv->canvasx($y), -tags=>'Rectangle'); } sub zoom2 { my ($canv, $x, $y) = @_; $c->delete('Rectangle'); $c->CanvasBind("", [\&pos_conversion, Ev('x'), Ev('y')]); $x2z = $canv->canvasx($x); $y2z = $canv->canvasy($y); return 'false' if (!$x1z && !$x2z && !$y1z && !$y2z || ($mousectrl eq 'zoom' && abs($x1z-$x2z) <= 5 || abs($y1z-$y2z) <= 5)); #to avoid erroneous zooming (e.g. small single clicks) &zooming if ($mousectrl eq 'zoom'); ©data if ($mousectrl eq 'copy'); } sub copydata { $session++; my $x1 = ($x1z + (($xmin/($xmax-$xmin))*($plot_x_size-2*$x_ax_placement)) - $x_ax_placement) * (($xmax-$xmin)/($plot_x_size-2*$x_ax_placement)); my $y1 = ((($ymin/($ymax-$ymin))*($plot_y_size-2*$y_ax_placement)) + $plot_y_size-$y_ax_placement - $y1z) * (($ymax-$ymin)/($plot_y_size-2*$y_ax_placement)); my $x2 = ($x2z + (($xmin/($xmax-$xmin))*($plot_x_size-2*$x_ax_placement)) - $x_ax_placement) * (($xmax-$xmin)/($plot_x_size-2*$x_ax_placement)); my $y2 = ((($ymin/($ymax-$ymin))*($plot_y_size-2*$y_ax_placement)) + $plot_y_size-$y_ax_placement - $y2z) * (($ymax-$ymin)/($plot_y_size-2*$y_ax_placement)); my @xlimits = sort {$a<=>$b} ($x1,$x2); my @ylimits = sort {$a<=>$b} ($y1,$y2); $xlimits[0] = $xmin if ($xlimits[0] < $xmin); $ylimits[0] = $ymin if ($ylimits[0] < $ymin); my $xmin = $xlimits[0]; my $xmax = $xlimits[1]; my $ymin = $ylimits[0]; my $ymax = $ylimits[1]; $res = $t->get('1.0','end'); chomp $res; $ind = 0; $res .= "---- Session $session ----\n"; if ($copystate eq 'full') { foreach my $labs (0..$dataend) { $res.= "\t".$labels[$labs]; } $res .= "\n"; } foreach $lin (0..$#xtrue) { next if ($restrict eq 'on' && $search_col[$lin] !~ /$search_string_go/i && $search_string !~ /^\!/); #NOTE: search_col is different to balltrue since it is affected by the fix/unfix !!! next if ($restrict eq 'on' && $search_col[$lin] =~ /$search_string_go/i && $search_string =~ /^\!/); #NOTE: search_col is different to balltrue since it is affected by the fix/unfix !!! if ($copystate eq 'full' && $xtrue[$lin] >= $xmin && $xtrue[$lin] <= $xmax && $ytrue[$lin] >= $ymin && $ytrue[$lin] <= $ymax) { $res .= ++$ind."-\t"; foreach my $labs (0..$dataend) { $res .= $data[$labs][$lin]."\t"; } $res .= "\n"; $touse .= "$lin "; #this is for copy->find } if ($copystate eq 'single' && $xtrue[$lin] >= $xmin && $xtrue[$lin] <= $xmax && $ytrue[$lin] >= $ymin && $ytrue[$lin] <= $ymax) { $res .= ++$ind."- X(".$labels[$index{$xcoltoplot}]."):\t$xtrue[$lin]\tY(".$labels[$index{$ycoltoplot}]."):\t$ytrue[$lin]\tLAB(".$labels[$index{$balloon_col}]."):\t$balltrue[$lin]\n"; $touse .= "$lin "; #this is for copy->find } } $t->Contents($res); ($lines) = $res=~ s/\n/\n/g; $t->yview($lines-$ind-1) if ($copystate eq 'single'); $t->yview($lines-$ind-2) if ($copystate eq 'full'); if ($high_w_copy eq 'on') { $high_copy = 1; &plotpoint; } $statusbar = "$ind entities pasted."; print "$ind entities pasted.\n"; } sub zooming { my $x1 = ($x1z + (($xmin/($xmax-$xmin))*($plot_x_size-2*$x_ax_placement)) - $x_ax_placement) * (($xmax-$xmin)/($plot_x_size-2*$x_ax_placement)); my $y1 = ((($ymin/($ymax-$ymin))*($plot_y_size-2*$y_ax_placement)) + $plot_y_size-$y_ax_placement - $y1z) * (($ymax-$ymin)/($plot_y_size-2*$y_ax_placement)); my $x2 = ($x2z + (($xmin/($xmax-$xmin))*($plot_x_size-2*$x_ax_placement)) - $x_ax_placement) * (($xmax-$xmin)/($plot_x_size-2*$x_ax_placement)); my $y2 = ((($ymin/($ymax-$ymin))*($plot_y_size-2*$y_ax_placement)) + $plot_y_size-$y_ax_placement - $y2z) * (($ymax-$ymin)/($plot_y_size-2*$y_ax_placement)); my @xlimits = sort {$a<=>$b} ($x1,$x2); my @ylimits = sort {$a<=>$b} ($y1,$y2); $xlimits[0] = $xmin if ($xlimits[0] < $xmin); $ylimits[0] = $ymin if ($ylimits[0] < $ymin); push (@x1old, $xmin); #fill old values array for unzoom funcion push (@y1old, $ymin); #fill old values array for unzoom funcion push (@x2old, $xmax); #fill old values array for unzoom funcion push (@y2old, $ymax); #fill old values array for unzoom funcion push (@xstepold, $xstep); #fill old values array for unzoom funcion push (@ystepold, $ystep); #fill old values array for unzoom funcion $xmin = $xlimits[0]; $xmax = $xlimits[1]; $ymin = $ylimits[0]; $ymax = $ylimits[1]; $xstep = ($xmax-$xmin)/10; $ystep = ($ymax-$ymin)/10; $zoomstate++; &plotpoint; &plot_curve if ($ploton && $ploton == 1); } sub unzoom { return 'false' if (!@x1old); $xmin = pop @x1old; $xmax = pop @x2old; $ymin = pop @y1old; $ymax = pop @y2old; $xstep = pop @xstepold; $ystep = pop @ystepold; $zoomstate--; &plotpoint; &plot_curve if ($ploton && $ploton == 1); } sub clearzoom { undef (@x1old) if (@x1old); undef (@x2old) if (@x2old); undef (@y1old) if (@y1old); undef (@y2old) if (@y2old); undef (@xstepold) if (@xstepold); undef (@xstepold) if (@xstepold); } sub saveto { $saveto = $main->getSaveFile; $saveto =~ s/\....//; $saveto = $saveto.'.ps'; $c->update; $c->postscript(-pagewidth=>'770p', -file=>$saveto); } sub updateplot { return 'false' if ($xstep == 0 || $ystep == 0); print "Reconfiguring plot area..."; $c->delete('xgrid'); $c->delete('ygrid'); $c->delete('xlabel'); $c->delete('ylabel'); $c->delete('xaxlabel'); $c->delete('yaxlabel'); # $c->createLine(50, 575, 810, 575, -arrow=>'last', -fill=>'black', -tags=>'xgrid'); #x-axis $c->createLine($x_ax_placement-5, $plot_y_size-$y_ax_placement, $plot_x_size-$x_ax_placement+5, $plot_y_size-$y_ax_placement, -arrow=>'last', -fill=>'black', -tags=>'xgrid'); #x-axis # $c->createLine(55, 15, 55, 580, -arrow=>'first', -fill=>'black', -tags=>'ygrid'); #y-axis $c->createLine($x_ax_placement, $y_ax_placement-5, $x_ax_placement, $plot_y_size-$y_ax_placement+5, -arrow=>'first', -fill=>'black', -tags=>'ygrid'); #y-axis &clearzoom if (($xcoltoplot ne $xcoltoplot_old) || ($ycoltoplot ne $ycoltoplot_old)); &update_label_size; $xlimit = $xmax+$xstep if ($xscalestate eq 'wt'); $xlimit = $xmax if ($xscalestate ne 'wt'); my $xcnt = 0; for (my $i=$xmin;$i<=$xlimit;$i+=$xstep) { $xcnt++; last if ($xcnt >11); my $xpos = scale($i,'x'); $xlab = sprintf($xfix,$i) if ($xlabform eq 'norm'); $xlab = $i if ($xlabform eq 'full'); $xlab = int($i) if ($xlabform eq 'int'); $xlab = sprintf('%.0e',$i) if ($xlabform eq 'sci'); $c->createLine($xpos, $plot_y_size-$y_ax_placement+5, $xpos, $plot_y_size-$y_ax_placement, -fill => 'black', -tags=>'xgrid'); $c->createText($xpos, $plot_y_size-$y_ax_placement+15, -fill => 'black', -text => $xlab, -tags=>'xlabel', -font=>'matramx') if ($xlabstat ne 'off'); } $ylimit = $ymax+$ystep if ($yscalestate eq 'wt'); $ylimit = $ymax if ($yscalestate ne 'wt'); my $ycnt = 0; for (my $j=$ymin;$j<=$ymax+$ystep;$j+=$ystep) { $ycnt++; last if ($ycnt >11); my $ypos = scale($j,'y'); $ylab = sprintf($yfix, $j) if ($ylabform eq 'norm'); $ylab = $j if ($ylabform eq 'full'); $ylab = int($j) if ($ylabform eq 'int'); $ylab = sprintf('%.0e',$j) if ($ylabform eq 'sci'); $c->createLine($x_ax_placement-5, $ypos, $x_ax_placement, $ypos, -fill => 'black', -tags=>'ygrid'); $c->createText($x_ax_placement-10, $ypos, -fill => 'black', -text => $ylab, -tags=>'ylabel', -font=>'matramy', -anchor=>'e') if ($ylabstat ne 'off'); } print "done.\n"; $c->createText($plot_x_size/2, $plot_y_size-$y_ax_placement+30, -fill => 'black', -text => $xcoltoplot, -tags=>'xlabel', -font=>'matramx'); $c->createText($y_ax_placement, $y_ax_placement-15, -fill => 'black', -text => $ycoltoplot, -tags=>'ylabel', -font=>'matramy'); # print "MINXTMP = $xmintmp\nMINYTMP = $ymintmp\n"; $xcoltoplot_old = $xcoltoplot; $ycoltoplot_old = $ycoltoplot; } sub ave { my @arr = @_; # shift @arr; my $ave = 0; my $cnt = 0; foreach (@arr) { next if ($_ eq 'n.a.'); $cnt++; $ave += $_; } return ($ave/$cnt); } sub avef { my @arr = @_; my $ave = 0; my $cnt = 0; foreach (@arr) { next if ($_ eq 'n.a.'); $ave += $_; } return ($ave/$cnt); } sub devst { my @arr = @_; # shift @arr; my $std = 0; my $cnt = 0; my $ave = ave(@arr); foreach (@arr) { next if ($_ eq 'n.a.'); $cnt++; $std += ($_-$ave)**2; } return ($ave,(sqrt($std/($cnt-1)))); } sub var { my @arr = @_; my ($ave,$std) = devst(@arr); return ($std**2); } sub stdz { my @arr = @_; # shift @arr; my ($ave,$std) = devst(@arr); my @out; foreach (0..$#arr) { $out[$_]= ($arr[$_]-$ave)/$std if ($arr[$_] ne 'n.a.'); $out[$_] = 'n.a.' if ($arr[$_] eq 'n.a.'); } return (@out); } sub min_max { my @inp = @_; my %in = (); my @in = (); foreach (@inp) { next if ($_ eq 'n.a.'); $in{$_}= 1; } @in = sort {$a <=> $b} keys %in; return ($in[0],$in[$#in]); } sub norm { my @arr = @_; # shift @arr; my @sort = sort {$a <=> $b} @arr; my @out; foreach (0..$#arr) { $out[$_] = ($arr[$_]-$sort[0])/($sort[$#sort]-$sort[0]) if ($arr[$_] ne 'n.a.'); # val-min/max-min $out[$_] = 'n.a.' if ($arr[$_] eq 'n.a.'); } return (@out); } sub loga { my @arr = @_; # shift @arr; foreach (0..$#arr) { $out[$_] = log($arr[$_]) if ($arr[$_] ne 'n.a.' && $arr[$_] > 0); $out[$_] = 'n.a.' if ($arr[$_] eq 'n.a.' && $arr[$_] <= 0); } return (@out); } sub center { my @arr = @_; # shift @arr; my $av = ave(@arr); foreach (0..$#arr) { $out[$_] = $arr[$_]-$av; } return (@out); } sub xsorter { my @id; my $xin = shift; my $yin = shift; my $ballin = shift; my @xin = @$xin; my @yin = @$yin; my @ballin = @$ballin; my @yout= @yin[@id = sort {$xin[$a]<=>$xin[$b]} 0..$#xin]; my @ballout = @ballin[@id = sort {$xin[$a]<=>$xin[$b]} 0..$#xin]; my @xout = @xin[@id]; shift @xout; shift @yout; shift @ballout; print "$xout[0] -> $yout[0] -> $ballout[0]\n"; return (\@xout,\@yout,\@ballout); } sub ysorter { my @id; my $xin = shift; my $yin = shift; my $ballin = shift; my @ballin = @$ballin; my @xin = @$xin; my @yin = @$yin; my @xout= @xin[@id = sort {$yin[$a]<=>$yin[$b]} 0..$#yin]; my @ballout= @ballin[@id = sort {$xin[$a]<=>$xin[$b]} 0..$#xin]; my @yout = @yin[@id]; return (\@xout,\@yout,\@ballout); } sub add_to_find_n_save { my $lin = shift; if ($copystate eq 'full') { foreach my $labs (0..$dataend) { $find2save .= $data[$labs][$lin]."\t"; } } if ($copystate eq 'single') { $find2save .= ++$ind."- X(".$labels[$index{$xcoltoplot}]."):\t$xtrue[$lin]\tY(".$labels[$index{$ycoltoplot}]."):\t$ytrue[$lin]\tLAB(".$labels[$index{$balloon_col}]."):\t$balltrue[$lin]"; } $find2save .= "\n"; } sub plotpoint { $found_cnt = 0; $point_cnt = 0; @xtrue = @{$data[$index{$xcoltoplot}]}; @ytrue = @{$data[$index{$ycoltoplot}]}; ($xmintmp,undef) = min_max(@xtrue); ($ymintmp,undef) = min_max(@ytrue); @xtrue = norm(@{$data[$index{$xcoltoplot}]}) if ($xscalestate eq 'norm'); @ytrue = norm(@{$data[$index{$ycoltoplot}]}) if ($yscalestate eq 'norm'); @xtrue = stdz(@{$data[$index{$xcoltoplot}]}) if ($xscalestate eq 'std'); @ytrue = stdz(@{$data[$index{$ycoltoplot}]}) if ($yscalestate eq 'std'); @xtrue = loga(@{$data[$index{$xcoltoplot}]}) if ($xscalestate eq 'log' && $xmintmp >0); @ytrue = loga(@{$data[$index{$ycoltoplot}]}) if ($yscalestate eq 'log' && $ymintmp >0); @xtrue = center(@{$data[$index{$xcoltoplot}]}) if ($xscalestate eq 'cent'); @ytrue = center(@{$data[$index{$ycoltoplot}]}) if ($yscalestate eq 'cent'); $xscalestate = 'wt' if ($xscalestate eq 'log' && $xmintmp <= 0); $yscalestate = 'wt' if ($yscalestate eq 'log' && $ymintmp <= 0); @balltrue = @{$data[$index{$balloon_col}]}; ($xtrue,$ytrue,$balltrue) = xsorter (\@xtrue,\@ytrue,\@balltrue) if ($sortstate eq 'xsort'); ($xtrue,$ytrue,$balltrue) = ysorter (\@xtrue,\@ytrue,\@balltrue) if ($sortstate eq 'ysort'); @xtrue = @$xtrue if ($sortstate eq 'xsort' || $sortstate eq 'ysort'); @ytrue = @$ytrue if ($sortstate eq 'xsort' || $sortstate eq 'ysort'); @balltrue = @$balltrue if ($sortstate eq 'xsort' || $sortstate eq 'ysort'); # print "FIRST DATAPOINT: $xtrue[0] -> $ytrue[0] -> $balltrue[0]\n"; # return ('false') if (!@xtrue || !@ytrue); # || (@xtrue && $xtrue[0] eq 'false') || (@ytrue && $ytrue[0] eq 'false')); if ($xcolold ne $xcoltoplot || $xstateold ne $xscalestate) { ($xmin,$xmax) = min_max(@xtrue) if ($zoomstate == 0); #associata ad una textvariable di una entry } if ($ycolold ne $ycoltoplot || $ystateold ne $yscalestate) { ($ymin,$ymax) = min_max(@ytrue) if ($zoomstate == 0); #associata ad una textvariable di una entry } $xstep = ($xmax-$xmin)/10; #associata ad una textvariable di una entry $ystep = ($ymax-$ymin)/10; #associata ad una textvariable di una entry @search_col = @balltrue if ($fix eq 'unfix'); @tmp = split (/\./,$xmintmp); $xfix = '%.'.length($tmp[1]).'f'; #a tentative to detect decimals, used in real time value display @tmp = split (/\./,$ymintmp); $yfix = '%.'.length($tmp[1]).'f'; #a tentative to detect decimals, used in real time value display print "Replotting..."; # &update_label_size; $c->delete('found'); $c->delete('point'); $c->delete('ballabel'); foreach $lin (0..$#xtrue) { ######### <-------------- next if ($xtrue[$lin] eq 'n.a.' || $ytrue[$lin] eq 'n.a.'); $found = 0; $ball = ''; $ball{$balltrue[$lin]} = $balltrue[$lin] if ($labelstate eq 'single'); $ball = $balltrue[$lin] if ($labelstate eq 'single'); if ($labelstate eq 'full') { foreach my $labs (0..$dataend) { $ball .= $labels[$labs].":".$data[$labs][$lin]."\n"; } $ball{$ball} = $ball; } $desc = $balltrue[$lin]; $search_string_go = $search_string; $search_string_go = substr($search_string,1) if ($search_string =~ /^[\!|<|>]/); if ($search_string) { if ($search_string =~ /^[><]/ ) { if ($desc !~ /[a-z]/i) { $found = 1 if ($search_string =~ /^>/ && $search_string_go <= $desc); #numerical match $found = 1 if ($search_string =~ /^= $desc); #numerical match } } else { $found = 1 if ($search_string !~ /^\!/ && $desc =~ /$search_string_go/i); #text match $found = 1 if ($search_string =~ /^\!/ && $desc !~ /$search_string_go/i); #text match } $found_cnt++ if ($found == 1); } $x = scale($xtrue[$lin],'x'); $y = scale($ytrue[$lin],'y'); if ($xtrue[$lin] >= $xmin && $xtrue[$lin] <= $xmax && $ytrue[$lin] >= $ymin && $ytrue[$lin] <= $ymax) { $point_cnt++; if ($point_type eq 'Circle' && !$found && $restrict eq 'off') { $c->createOval($x-$point_size, $y-$point_size, $x+$point_size, $y+$point_size, -tags=>['point',$ball,'notfound'], ) ; $c->createText($x+$point_size, $y+$point_size+2, -fill => 'black', -text => $ball, -tags=>'ballabel', -font=>'matraml') if ($labview eq 'on'); } if ($point_type eq 'Circle' && ($found || ($touse =~ / $lin / && $high_copy))) { $c->createOval($x-$found_size, $y-$found_size, $x+$found_size, $y+$found_size, -tags=>['point',$ball,'found'], ); add_to_find_n_save($lin) if ($find_n_save == 1); $c->createText($x+$point_size, $y+$point_size+2, -fill => 'black', -text => $ball, -tags=>'ballabel', -font=>'matraml') if ($labview eq 'on'); } if ($point_type eq 'Square' && !$found && $restrict eq 'off') { $c->createRectangle($x-$point_size, $y-$point_size, $x+$point_size, $y+$point_size, -tags=>['point',$ball,'notfound'], ); $c->createText($x+$point_size, $y+$point_size+2, -fill => 'black', -text => $ball, -tags=>'ballabel', -font=>'matraml') if ($labview eq 'on'); } if ($point_type eq 'Square' && ($found || ($touse =~ / $lin / && $high_copy))) { $c->createRectangle($x-$found_size, $y-$found_size, $x+$found_size, $y+$found_size, -tags=>['point',$ball,'found'], ); add_to_find_n_save($lin) if ($find_n_save == 1); $c->createText($x+$point_size, $y+$point_size+2, -fill => 'black', -text => $ball, -tags=>'ballabel', -font=>'matraml') if ($labview eq 'on'); } } } $b->attach($c, -balloonposition => 'mouse',-msg => \%ball); print "done.\n"; &plotstyle; $xstateold = $xscalestate; $ystateold = $yscalestate; $xcolold = $xcoltoplot; $ycolold = $ycoltoplot; &updateplot; $perc_presence = int($point_cnt/$row*100); print "$point_cnt over $row entities are now plotted ($perc_presence %).\n" if ($point_cnt > 0); print "No elements are now present in plot.\n" if ($point_cnt == 0); print "$found_cnt elements found matching \"$search_string_go\"\n" if ($search_string ne '' && $found_cnt > 0 && $search_string !~ /^[\!|>|<]/); print "$found_cnt elements found not matching \"$search_string_go\"\n" if ($search_string ne '' && $found_cnt > 0 && $search_string =~ /^\!/); print "$found_cnt elements found >= $search_string_go\n" if ($search_string ne '' && $found_cnt > 0 && $search_string =~ /^>/); print "$found_cnt elements found <= $search_string_go\n" if ($search_string ne '' && $found_cnt > 0 && $search_string =~ /^|<]/); print "No element found not matching \"$search_string_go\"\n" if ($search_string ne '' && $found_cnt == 0 && $search_string =~ /^\!/); print "No elements found >= $search_string_go\n" if ($search_string ne '' && $found_cnt == 0 && $search_string =~ /^>/); print "No elements found <= $search_string_go\n" if ($search_string ne '' && $found_cnt == 0 && $search_string =~ /^|<]/); print "All elements do not match \"$search_string_go\"\n" if ($search_string ne '' && $found_cnt == $point_cnt && $search_string =~ /^\!/); print "All elements are >= $search_string_go\n" if ($search_string ne '' && $found_cnt == $point_cnt && $search_string =~ /^\>/); print "All elements are <= $search_string_go\n" if ($search_string ne '' && $found_cnt == $point_cnt && $search_string =~ /^\ 0 && $search_string !~ /^[\!|>|<]/); $statusbar = "$found_cnt elements found not matching \"$search_string_go\"" if ($search_string ne '' && $found_cnt > 0 && $search_string =~ /^\!/); $statusbar = "$found_cnt elements found >= $search_string_go" if ($search_string ne '' && $found_cnt > 0 && $search_string =~ /^>/); $statusbar = "$found_cnt elements found <= $search_string_go" if ($search_string ne '' && $found_cnt > 0 && $search_string =~ /^|<]/); $statusbar = "No element found not matching \"$search_string_go\"" if ($search_string ne '' && $found_cnt == 0 && $search_string =~ /^\!/); $statusbar = "No elements found >= $search_string_go" if ($search_string ne '' && $found_cnt == 0 && $search_string =~ /^>/); $statusbar = "No elements found <= $search_string_go" if ($search_string ne '' && $found_cnt == 0 && $search_string =~ /^|<]/); $statusbar = "All elements do not match \"$search_string_go\"" if ($search_string ne '' && $found_cnt == $point_cnt && $search_string =~ /^\!/); $statusbar = "All elements are >= $search_string_go" if ($search_string ne '' && $found_cnt == $point_cnt && $search_string =~ /^\>/); $statusbar = "All elements are <= $search_string_go" if ($search_string ne '' && $found_cnt == $point_cnt && $search_string =~ /^\itemconfigure('point', -outline=>$point_color); if ($point_fill eq 'filled') { $c->itemconfigure('point', -fill=>$point_color); } if ($point_fill eq 'empty') { $c->itemconfigure('point', -fill=>'white'); } $c->itemconfigure('found', -outline=>$found_color); if ($found_fill eq 'filled') { $c->itemconfigure('found', -fill=>$found_color); } if ($found_fill eq 'empty') { $c->itemconfigure('found', -fill=>'white'); } }