[16] | 1 | #!/usr/bin/perl -w |
---|
| 2 | use strict; |
---|
| 3 | use Tk; |
---|
| 4 | use Tk::Xrm; |
---|
| 5 | use Tk qw(exit); |
---|
| 6 | |
---|
| 7 | my $version="Analyzer 20020429"; |
---|
| 8 | |
---|
| 9 | my %bases; |
---|
| 10 | my $first_file=undef; |
---|
| 11 | my $last_file=undef; |
---|
| 12 | my $fileno=0; |
---|
| 13 | |
---|
| 14 | my @panel_labels; |
---|
| 15 | my @panel_ones; |
---|
| 16 | my @panel_twos; |
---|
| 17 | my @panel_onevars; |
---|
| 18 | my @panel_twovars; |
---|
| 19 | my @panel_keys; |
---|
| 20 | my $panel_count; |
---|
| 21 | |
---|
| 22 | # pop the toplevels |
---|
| 23 | |
---|
| 24 | my $toplevel=new MainWindow(-class=>'AnalyzerGraph'); |
---|
| 25 | my $Xname=$toplevel->Class; |
---|
| 26 | $toplevel->optionAdd("$Xname.geometry", "800x600",20); |
---|
| 27 | |
---|
| 28 | my $geometry=$toplevel->optionGet('geometry',''); |
---|
| 29 | $geometry=~/^(\d+)x(\d+)/; |
---|
| 30 | |
---|
| 31 | $toplevel->configure(-width=>$1); |
---|
| 32 | $toplevel->configure(-height=>$2); |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | |
---|
| 38 | $toplevel->optionAdd("$Xname.background", "#4fc627",20); |
---|
| 39 | $toplevel->optionAdd("$Xname*highlightBackground", "#80c0d3",20); |
---|
| 40 | $toplevel->optionAdd("$Xname.Panel.background", "#4fc627",20); |
---|
| 41 | $toplevel->optionAdd("$Xname.Panel.foreground", "#d0d0d0",20); |
---|
| 42 | $toplevel->optionAdd("$Xname.Panel.font", |
---|
| 43 | '-*-helvetica-bold-r-*-*-18-*-*-*-*-*-*-*',20); |
---|
| 44 | $toplevel->optionAdd("$Xname*Statuslabel.font", |
---|
| 45 | '-*-helvetica-bold-r-*-*-18-*-*-*-*-*-*-*',20); |
---|
| 46 | $toplevel->optionAdd("$Xname*Statuslabel.foreground", "#606060"); |
---|
| 47 | $toplevel->optionAdd("$Xname*Status.font", |
---|
| 48 | '-*-helvetica-bold-r-*-*-18-*-*-*-*-*-*-*',20); |
---|
| 49 | |
---|
| 50 | $toplevel->optionAdd("$Xname*AlertDetail.font", |
---|
| 51 | '-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*',20); |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | $toplevel->optionAdd("$Xname*background", "#d0d0d0",20); |
---|
| 55 | $toplevel->optionAdd("$Xname*foreground", '#000000',20); |
---|
| 56 | |
---|
| 57 | $toplevel->optionAdd("$Xname*Button*background", "#f0d0b0",20); |
---|
| 58 | $toplevel->optionAdd("$Xname*Button*foreground", '#000000',20); |
---|
| 59 | $toplevel->optionAdd("$Xname*Button*borderWidth", '2',20); |
---|
| 60 | $toplevel->optionAdd("$Xname*Button*relief", 'groove',20); |
---|
| 61 | $toplevel->optionAdd("$Xname*Button*padY", 1,20); |
---|
| 62 | |
---|
| 63 | #$toplevel->optionAdd("$Xname*Scale*background", "#f0d0b0",20); |
---|
| 64 | $toplevel->optionAdd("$Xname*Scale*foreground", '#000000',20); |
---|
| 65 | $toplevel->optionAdd("$Xname*Scale*borderWidth", '1',20); |
---|
| 66 | #$toplevel->optionAdd("$Xname*Scale*relief", 'groove',20); |
---|
| 67 | $toplevel->optionAdd("$Xname*Scale*padY", 1,20); |
---|
| 68 | |
---|
| 69 | $toplevel->optionAdd("$Xname*Checkbutton*background", "#f0d0b0",20); |
---|
| 70 | $toplevel->optionAdd("$Xname*Checkbutton*foreground", '#000000',20); |
---|
| 71 | $toplevel->optionAdd("$Xname*Checkbutton*borderWidth", '2',20); |
---|
| 72 | $toplevel->optionAdd("$Xname*Checkbutton*relief", 'groove',20); |
---|
| 73 | |
---|
| 74 | $toplevel->optionAdd("$Xname*activeBackground", "#ffffff",20); |
---|
| 75 | $toplevel->optionAdd("$Xname*activeForeground", '#0000a0',20); |
---|
| 76 | $toplevel->optionAdd("$Xname*borderWidth", 0,20); |
---|
| 77 | $toplevel->optionAdd("$Xname*relief", 'flat',20); |
---|
| 78 | $toplevel->optionAdd("$Xname*activeBorderWidth", 1,20); |
---|
| 79 | $toplevel->optionAdd("$Xname*highlightThickness", 0,20); |
---|
| 80 | $toplevel->optionAdd("$Xname*padX", 2,20); |
---|
| 81 | $toplevel->optionAdd("$Xname*padY", 2,20); |
---|
| 82 | $toplevel->optionAdd("$Xname*font", |
---|
| 83 | '-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*',20); |
---|
| 84 | $toplevel->optionAdd("$Xname*Entry.font", |
---|
| 85 | '-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*',20); |
---|
| 86 | $toplevel->optionAdd("$Xname*Exit.font", |
---|
| 87 | '-*-helvetica-bold-r-*-*-10-*-*-*-*-*-*-*',20); |
---|
| 88 | $toplevel->optionAdd("$Xname*Exit.relief", 'groove',20); |
---|
| 89 | $toplevel->optionAdd("$Xname*Exit.padX", 1,20); |
---|
| 90 | $toplevel->optionAdd("$Xname*Exit.padY", 1,20); |
---|
| 91 | $toplevel->optionAdd("$Xname*Exit.borderWidth", 2,20); |
---|
| 92 | $toplevel->optionAdd("$Xname*Exit*background", "#a0a0a0",20); |
---|
| 93 | $toplevel->optionAdd("$Xname*Exit*disabledForeground", "#ffffff",20); |
---|
| 94 | |
---|
| 95 | #$toplevel->optionAdd("$Xname*Canvas.background", "#c0c0c0",20); |
---|
| 96 | |
---|
| 97 | $toplevel->optionAdd("$Xname*Entry.background", "#ffffff",20); |
---|
| 98 | $toplevel->optionAdd("$Xname*Entry.disabledForeground", "#c0c0c0",20); |
---|
| 99 | $toplevel->optionAdd("$Xname*Entry.relief", "sunken",20); |
---|
| 100 | $toplevel->optionAdd("$Xname*Entry.borderWidth", 1,20); |
---|
| 101 | |
---|
| 102 | $toplevel->optionAdd("$Xname*Field.background", "#ffffff",20); |
---|
| 103 | $toplevel->optionAdd("$Xname*Field.disabledForeground", "#c0c0c0",20); |
---|
| 104 | $toplevel->optionAdd("$Xname*Field.relief", "flat",20); |
---|
| 105 | $toplevel->optionAdd("$Xname*Field.borderWidth", 1,20); |
---|
| 106 | |
---|
| 107 | $toplevel->optionAdd("$Xname*Label.disabledForeground", "#c0c0c0",20); |
---|
| 108 | $toplevel->optionAdd("$Xname*Label.borderWidth", 1,20); |
---|
| 109 | |
---|
| 110 | $toplevel->configure(-background=>$toplevel->optionGet("background","")); |
---|
| 111 | |
---|
| 112 | #$toplevel->resizable(FALSE,FALSE); |
---|
| 113 | |
---|
| 114 | my $panel=new MainWindow(-class=>'AnalyzerPanel'); |
---|
| 115 | my $X2name=$panel->Class; |
---|
| 116 | |
---|
| 117 | $panel->optionAdd("$X2name.background", "#353535",20); |
---|
| 118 | $panel->optionAdd("$X2name*highlightBackground", "#80c0d3",20); |
---|
| 119 | $panel->optionAdd("$X2name.Panel.background", "#353535",20); |
---|
| 120 | $panel->optionAdd("$X2name.Panel.foreground", "#4fc627",20); |
---|
| 121 | $panel->optionAdd("$X2name.Panel.font", |
---|
| 122 | '-*-helvetica-bold-o-*-*-18-*-*-*-*-*-*-*',20); |
---|
| 123 | $panel->optionAdd("$X2name*Statuslabel.font", |
---|
| 124 | '-*-helvetica-bold-r-*-*-18-*-*-*-*-*-*-*',20); |
---|
| 125 | $panel->optionAdd("$X2name*Statuslabel.foreground", "#4fc627",20); |
---|
| 126 | $panel->optionAdd("$X2name*Status.font", |
---|
| 127 | '-*-helvetica-bold-r-*-*-18-*-*-*-*-*-*-*',20); |
---|
| 128 | |
---|
| 129 | $panel->optionAdd("$X2name*AlertDetail.font", |
---|
| 130 | '-*-helvetica-medium-r-*-*-10-*-*-*-*-*-*-*',20); |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | $panel->optionAdd("$X2name*background", "#d0d0d0",20); |
---|
| 134 | $panel->optionAdd("$X2name*foreground", '#000000',20); |
---|
| 135 | |
---|
| 136 | $panel->optionAdd("$X2name*Button*background", "#f0d0b0",20); |
---|
| 137 | $panel->optionAdd("$X2name*Button*foreground", '#000000',20); |
---|
| 138 | $panel->optionAdd("$X2name*Button*borderWidth", '2',20); |
---|
| 139 | $panel->optionAdd("$X2name*Button*relief", 'groove',20); |
---|
| 140 | $panel->optionAdd("$X2name*Button*padY", 1,20); |
---|
| 141 | |
---|
| 142 | $panel->optionAdd("$X2name*Checkbutton*background", "#f0d0b0",20); |
---|
| 143 | $panel->optionAdd("$X2name*Checkbutton*foreground", '#000000',20); |
---|
| 144 | $panel->optionAdd("$X2name*Checkbutton*borderWidth", '2',20); |
---|
| 145 | #$panel->optionAdd("$X2name*Checkbutton*padX", '0',20); |
---|
| 146 | #$panel->optionAdd("$X2name*Checkbutton*padY", '0',20); |
---|
| 147 | #$panel->optionAdd("$X2name*Checkbutton*relief", 'groove',20); |
---|
| 148 | |
---|
| 149 | $panel->optionAdd("$X2name*activeBackground", "#ffffff",20); |
---|
| 150 | $panel->optionAdd("$X2name*activeForeground", '#0000a0',20); |
---|
| 151 | $panel->optionAdd("$X2name*borderWidth", 0,20); |
---|
| 152 | $panel->optionAdd("$X2name*relief", 'flat',20); |
---|
| 153 | $panel->optionAdd("$X2name*activeBorderWidth", 1,20); |
---|
| 154 | $panel->optionAdd("$X2name*highlightThickness", 0,20); |
---|
| 155 | $panel->optionAdd("$X2name*padX", 2,20); |
---|
| 156 | $panel->optionAdd("$X2name*padY", 2,20); |
---|
| 157 | $panel->optionAdd("$X2name*font", |
---|
| 158 | '-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*',20); |
---|
| 159 | $panel->optionAdd("$X2name*Entry.font", |
---|
| 160 | '-*-helvetica-medium-r-*-*-12-*-*-*-*-*-*-*',20); |
---|
| 161 | |
---|
| 162 | $panel->optionAdd("$X2name*Exit.font", |
---|
| 163 | '-*-helvetica-bold-r-*-*-10-*-*-*-*-*-*-*',20); |
---|
| 164 | $panel->optionAdd("$X2name*Exit.relief", 'groove',20); |
---|
| 165 | $panel->optionAdd("$X2name*Exit.padX", 1,20); |
---|
| 166 | $panel->optionAdd("$X2name*Exit.padY", 1,20); |
---|
| 167 | $panel->optionAdd("$X2name*Exit.borderWidth", 2,20); |
---|
| 168 | $panel->optionAdd("$X2name*Exit*background", "#a0a0a0",20); |
---|
| 169 | $panel->optionAdd("$X2name*Exit*disabledForeground", "#ffffff",20); |
---|
| 170 | |
---|
| 171 | $panel->optionAdd("$X2name*Entry.background", "#ffffff",20); |
---|
| 172 | $panel->optionAdd("$X2name*Entry.disabledForeground", "#c0c0c0",20); |
---|
| 173 | $panel->optionAdd("$X2name*Entry.relief", "sunken",20); |
---|
| 174 | $panel->optionAdd("$X2name*Entry.borderWidth", 1,20); |
---|
| 175 | |
---|
| 176 | $panel->optionAdd("$X2name*Field.background", "#ffffff",20); |
---|
| 177 | $panel->optionAdd("$X2name*Field.disabledForeground", "#c0c0c0",20); |
---|
| 178 | $panel->optionAdd("$X2name*Field.relief", "flat",20); |
---|
| 179 | $panel->optionAdd("$X2name*Field.borderWidth", 1,20); |
---|
| 180 | |
---|
| 181 | $panel->optionAdd("$X2name*Label.disabledForeground", "#c0c0c0",20); |
---|
| 182 | $panel->optionAdd("$X2name*Label.borderWidth", 1,20); |
---|
| 183 | |
---|
| 184 | $panel->configure(-background=>$panel->optionGet("background","")); |
---|
| 185 | |
---|
| 186 | #$panel->resizable("FALSE","FALSE"); |
---|
| 187 | |
---|
| 188 | my $panel_shell=$panel->Label(Name=>"shell",borderwidth=>1,relief=>'raised')-> |
---|
| 189 | place(-x=>10,-y=>36,-relwidth=>1.0,-relheight=>1.0, |
---|
| 190 | -width=>-20,-height=>-46,-anchor=>'nw'); |
---|
| 191 | |
---|
| 192 | my $panel_quit=$panel_shell->Button(-class=>"Exit",text=>"quit",-command=>[sub{Shutdown()}])-> |
---|
| 193 | place(-x=>-1,-y=>-1,-relx=>1.0,-rely=>1.0,-anchor=>'se'); |
---|
| 194 | |
---|
| 195 | $panel->Label(Name=>"logo text",-class=>"Panel",text=>$version)-> |
---|
| 196 | place(-x=>5,-y=>5,-anchor=>'nw'); |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | my $graph_shell=$toplevel->Label(Name=>"shell",borderwidth=>1,relief=>'raised')-> |
---|
| 200 | place(-x=>10,-y=>36,-relwidth=>1.0,-relheight=>1.0, |
---|
| 201 | -width=>-20,-height=>-46,-anchor=>'nw'); |
---|
| 202 | |
---|
| 203 | my $graph_status=$toplevel->Label(Name=>"logo text",-class=>"Panel",text=>"Starting up")-> |
---|
| 204 | place(-x=>5,-y=>5,-anchor=>'nw'); |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | my $panely=5; |
---|
| 208 | my $panel_rescan=$panel_shell->Button(text=>"rescan",command=>[sub{scan_directory()}])-> |
---|
| 209 | place(-x=>-5,-relx=>1.,-y=>$panely,-anchor=>'ne'); |
---|
| 210 | $panely+=$panel_rescan->reqheight()+6; |
---|
| 211 | |
---|
| 212 | |
---|
| 213 | my$temp=$graph_shell->Button(-text=>"<<", |
---|
| 214 | -command=>[sub{$fileno-=10;$fileno=$first_file if($fileno<$first_file); |
---|
| 215 | load_graph();}])-> |
---|
| 216 | place(-x=>5,-y=>-5,-rely=>1.,-relwidth=>.2,-width=>-5,-anchor=>'sw'); |
---|
| 217 | $graph_shell->Button(-text=>">>", |
---|
| 218 | -command=>[sub{$fileno+=10;$fileno=$last_file if($fileno>$last_file); |
---|
| 219 | load_graph();}])-> |
---|
| 220 | place(-x=>-5,-y=>-5,-relwidth=>.2,-rely=>1.,-width=>-5,-relx=>1.,-anchor=>'se'); |
---|
| 221 | $graph_shell->Button(-text=>"<", |
---|
| 222 | -command=>[sub{$fileno-=1;$fileno=$first_file if($fileno<$first_file); |
---|
| 223 | load_graph();}])-> |
---|
| 224 | place(-x=>5,-y=>-5,-relwidth=>.3,-width=>-7,-rely=>1.,-relx=>.2,-anchor=>'sw'); |
---|
| 225 | $graph_shell->Button(-text=>">", |
---|
| 226 | -command=>[sub{$fileno+=1;$fileno=$last_file if($fileno>$last_file); |
---|
| 227 | load_graph();}])-> |
---|
| 228 | place(-x=>-5,-y=>-5,-relwidth=>.3,-width=>-7,-rely=>1.,-relx=>.8,-anchor=>'se'); |
---|
| 229 | my$graphy=-10-$temp->reqheight(); |
---|
| 230 | my$graph_slider=$temp=$graph_shell->Scale(-bigincrement=>1, |
---|
| 231 | -resolution=>1, |
---|
| 232 | -showvalue=>'TRUE',-variable=>\$fileno,-orient=>'horizontal')-> |
---|
| 233 | place(-x=>5,-y=>$graphy,-relwidth=>1.,-rely=>1.,-width=>-10,-anchor=>'sw'); |
---|
| 234 | $graphy-=$temp->reqheight()+5; |
---|
| 235 | |
---|
| 236 | my$onecrop; |
---|
| 237 | my$twocrop; |
---|
| 238 | |
---|
| 239 | my$oneresize=$temp=$graph_shell->Checkbutton(text=>"rescale",-variable=>\$onecrop, |
---|
| 240 | -command=>[sub{draw_graph();}])-> |
---|
| 241 | place(-x=>5,-y=>5,-anchor=>'nw'); |
---|
| 242 | |
---|
| 243 | my$one=$graph_shell->Canvas()-> |
---|
| 244 | place(-relwidth=>1.,-width=>-10,-relheight=>.5,-height=>($graphy/2)-5-$temp->reqheight(), |
---|
| 245 | -x=>5,-y=>5+$temp->reqheight,-anchor=>'nw'); |
---|
| 246 | |
---|
| 247 | |
---|
| 248 | my$tworesize=$temp=$graph_shell->Checkbutton(text=>"rescale",-variable=>\$twocrop, |
---|
| 249 | -command=>[sub{draw_graph();}])-> |
---|
| 250 | place(-rely=>1.,-y=>5,-anchor=>'nw',-in=>$one); |
---|
| 251 | my$two=$graph_shell->Canvas()-> |
---|
| 252 | place(-relwidth=>1.,-relheight=>1.,-rely=>1.,-y=>5+$temp->reqheight(),-anchor=>'nw',-in=>$one); |
---|
| 253 | |
---|
| 254 | scan_directory(); |
---|
| 255 | |
---|
| 256 | my%onestate; |
---|
| 257 | my%twostate; |
---|
| 258 | my @data; |
---|
| 259 | |
---|
| 260 | $onestate{"canvas"}=$one; |
---|
| 261 | $onestate{"vars"}=\@panel_onevars; |
---|
| 262 | $twostate{"canvas"}=$two; |
---|
| 263 | $twostate{"vars"}=\@panel_twovars; |
---|
| 264 | |
---|
| 265 | $graph_slider->configure(-command=>[sub{load_graph()}]); |
---|
| 266 | load_graph(); |
---|
| 267 | $toplevel->bind('MainWindow','<Configure>',[sub{$toplevel->update(); |
---|
| 268 | draw_graph()}]); |
---|
| 269 | |
---|
| 270 | Tk::MainLoop(); |
---|
| 271 | |
---|
| 272 | sub load_graph{ |
---|
| 273 | |
---|
| 274 | scan_directory()if(!defined($panel_count)); |
---|
| 275 | |
---|
| 276 | @data=undef; |
---|
| 277 | |
---|
| 278 | for(my$i=0;$i<$panel_count;$i++){ |
---|
| 279 | my$filename=$panel_keys[$i]."_$fileno.m"; |
---|
| 280 | if(open F, "$filename"){ |
---|
| 281 | $data[$i]=[(<F>)]; |
---|
| 282 | close F; |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | draw_graph(); |
---|
| 286 | } |
---|
| 287 | |
---|
| 288 | sub graphhelper{ |
---|
| 289 | my($graph)=@_; |
---|
| 290 | my$count=0; |
---|
| 291 | my@colors=("#ff0000","#00df00","#0000ff","#ffff00","#ff00ff","#00ffff","#ffffff", |
---|
| 292 | "#9f0000","#007f00","#00009f","#8f8f00","#8f008f","#008f8f","#000000"); |
---|
| 293 | |
---|
| 294 | my$w=$graph->{"canvas"}; |
---|
| 295 | my$rescale=0; |
---|
| 296 | |
---|
| 297 | Status("Plotting $fileno"); |
---|
| 298 | $w->delete('foo'); |
---|
| 299 | $w->delete('legend'); |
---|
| 300 | $w->delete('lines'); |
---|
| 301 | |
---|
| 302 | # count range |
---|
| 303 | for(my$i=0;$i<$panel_count;$i++){ |
---|
| 304 | if($graph->{"vars"}->[$i]){ |
---|
| 305 | if(defined($data[$i])){ |
---|
| 306 | if(!defined($graph->{"minx"})){ |
---|
| 307 | $data[$i]->[0]=~m/^\s*(-?[0-9\.]*)[ ,]+(-?[0-9\.]*)/; |
---|
| 308 | $graph->{"maxx"}=$1; |
---|
| 309 | $graph->{"minx"}=$1; |
---|
| 310 | $graph->{"maxy"}=$2; |
---|
| 311 | $graph->{"miny"}=$2; |
---|
| 312 | $rescale=1; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | for(my$j=0;$j<=$#{$data[$i]};$j++){ |
---|
| 316 | $data[$i]->[$j]=~m/^\s*(-?[0-9\.]*)[ ,]+(-?[0-9\.]*)/; |
---|
| 317 | $rescale=1 if($1>$graph->{"maxx"}); |
---|
| 318 | $rescale=1 if($1<$graph->{"minx"}); |
---|
| 319 | $rescale=1 if($2>$graph->{"maxy"}); |
---|
| 320 | $rescale=1 if($2<$graph->{"miny"}); |
---|
| 321 | $graph->{"maxx"}=$1 if($1>$graph->{"maxx"}); |
---|
| 322 | $graph->{"minx"}=$1 if($1<$graph->{"minx"}); |
---|
| 323 | $graph->{"maxy"}=$2 if($2>$graph->{"maxy"}); |
---|
| 324 | $graph->{"miny"}=$2 if($2<$graph->{"miny"}); |
---|
| 325 | } |
---|
| 326 | } |
---|
| 327 | $count++; |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | my$width=$w->width(); |
---|
| 332 | my$height=$w->height(); |
---|
| 333 | |
---|
| 334 | $rescale=1 if(!defined($graph->{"width"}) || |
---|
| 335 | $width!=$graph->{"width"} || |
---|
| 336 | $height!=$graph->{"height"}); |
---|
| 337 | |
---|
| 338 | $graph->{"width"}=$width; |
---|
| 339 | $graph->{"height"}=$height; |
---|
| 340 | |
---|
| 341 | if(defined($graph->{"maxx"})){ |
---|
| 342 | # draw axes, labels |
---|
| 343 | # look for appropriate axis scales |
---|
| 344 | |
---|
| 345 | if($rescale){ |
---|
| 346 | |
---|
| 347 | $w->delete('ylabel'); |
---|
| 348 | $w->delete('xlabel'); |
---|
| 349 | $w->delete('axes'); |
---|
| 350 | |
---|
| 351 | my$yscale=1.; |
---|
| 352 | my$xscale=1.; |
---|
| 353 | my$iyscale=1.; |
---|
| 354 | my$ixscale=1.; |
---|
| 355 | while(($graph->{"maxx"}-$graph->{"minx"})*$xscale>15){$xscale*=.1;$ixscale*=10.;} |
---|
| 356 | while(($graph->{"maxy"}-$graph->{"miny"})*$yscale>15){$yscale*=.1;$iyscale*=10.;} |
---|
| 357 | |
---|
| 358 | while(($graph->{"maxx"}-$graph->{"minx"})*$xscale<3){$xscale*=10.;$ixscale*=.1;} |
---|
| 359 | while(($graph->{"maxy"}-$graph->{"miny"})*$yscale<3){$yscale*=10.;$iyscale*=.1;} |
---|
| 360 | |
---|
| 361 | # how tall are the x axis labels? |
---|
| 362 | $w->createText(-1,-1,-anchor=>'se',-tags=>['foo'],-text=>"0123456789."); |
---|
| 363 | my($x1,$y1,$x2,$y2)=$w->bbox('foo'); |
---|
| 364 | $w->delete('foo'); |
---|
| 365 | my$maxlabelheight=$y2-$y1; |
---|
| 366 | my$useabley=$height-$maxlabelheight-3; |
---|
| 367 | my$pixelpery=$useabley/($graph->{"maxy"}-$graph->{"miny"}); |
---|
| 368 | |
---|
| 369 | # place y axis labels at proper spacing/height |
---|
| 370 | my$lasty=-$maxlabelheight/2; |
---|
| 371 | my$topyval=int($graph->{"maxy"}*$yscale+1.)*$iyscale; |
---|
| 372 | |
---|
| 373 | for(my$i=0;;$i++){ |
---|
| 374 | my$yval= $topyval-$i*$iyscale; |
---|
| 375 | my$y= ($graph->{"maxy"}-$yval)*$pixelpery; |
---|
| 376 | last if($y>$useabley); |
---|
| 377 | if($y-$maxlabelheight>=$lasty){ |
---|
| 378 | $w->createText(0,$y,-anchor=>'e',-tags=>['ylabel'],-text=>"$yval"); |
---|
| 379 | $lasty=$y; |
---|
| 380 | } |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | # get the max ylabel width and place them at proper x |
---|
| 384 | ($x1,$y1,$x2,$y2)=$w->bbox('ylabel'); |
---|
| 385 | my$maxylabelwidth=$x2-$x1; |
---|
| 386 | $w->move('ylabel',$maxylabelwidth,0); |
---|
| 387 | |
---|
| 388 | my$beginx=$maxylabelwidth+3; |
---|
| 389 | my$useablex=$width-$beginx; |
---|
| 390 | |
---|
| 391 | # draw basic axes |
---|
| 392 | $w->createLine($beginx,0,$beginx,$useabley,$width,$useabley, |
---|
| 393 | -tags=>['axes'],-width=>2); |
---|
| 394 | # draw y tix |
---|
| 395 | $lasty=-$maxlabelheight/2; |
---|
| 396 | for(my$i=0;;$i++){ |
---|
| 397 | my$yval= $topyval-$i*$iyscale; |
---|
| 398 | my$y= ($graph->{"maxy"}-$yval)*$pixelpery; |
---|
| 399 | last if($y>$useabley); |
---|
| 400 | if($yval==0){ |
---|
| 401 | $w->createLine($beginx,$y,$width,$y, |
---|
| 402 | -tags=>['axes'],-width=>1); |
---|
| 403 | }else{ |
---|
| 404 | if($y-$maxlabelheight>=$lasty){ |
---|
| 405 | $w->createLine($beginx,$y,$width,$y, |
---|
| 406 | -tags=>['axes'],-width=>1, |
---|
| 407 | -stipple=>'gray50'); |
---|
| 408 | |
---|
| 409 | $lasty=$y; |
---|
| 410 | } |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | # place x axis labels at proper spacing |
---|
| 415 | my$topxval=int($graph->{"maxx"}*$xscale+1.)*$ixscale; |
---|
| 416 | my$pixelperx=$useablex/($graph->{"maxx"}-$graph->{"minx"}); |
---|
| 417 | |
---|
| 418 | for(my$i=0;;$i++){ |
---|
| 419 | my$xval= $topxval-$i*$ixscale; |
---|
| 420 | my$x= $width-($graph->{"maxx"}-$xval)*$pixelperx; |
---|
| 421 | |
---|
| 422 | last if($x<$beginx); |
---|
| 423 | # bounding boxen are hard. place temp labels. |
---|
| 424 | $w->createText(-1,-1,-anchor=>'e',-tags=>['foo'],-text=>"$xval"); |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | ($x1,$y1,$x2,$y2)=$w->bbox('foo'); |
---|
| 428 | my$maxxlabelwidth=$x2-$x1; |
---|
| 429 | $w->delete('foo'); |
---|
| 430 | my$lastx=$width; |
---|
| 431 | |
---|
| 432 | for(my$i=0;;$i++){ |
---|
| 433 | my$xval= $topxval-$i*$ixscale; |
---|
| 434 | my$x= $width-($graph->{"maxx"}-$xval)*$pixelperx; |
---|
| 435 | |
---|
| 436 | last if($x-$maxxlabelwidth/2<0 || $x<$beginx); |
---|
| 437 | if($xval==0 && $x<$width){ |
---|
| 438 | $w->createLine($x,0,$x,$useabley,-tags=>['axes'],-width=>1); |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | if($x+$maxxlabelwidth<=$lastx){ |
---|
| 442 | $w->createText($x,$height-1,-anchor=>'s',-tags=>['xlabel'],-text=>"$xval"); |
---|
| 443 | $w->createLine($x,0,$x,$useabley,-tags=>['axes'],-width=>1,-stipple=>"gray50"); |
---|
| 444 | $lastx=$x; |
---|
| 445 | } |
---|
| 446 | } |
---|
| 447 | $graph->{"labelheight"}=$maxlabelheight; |
---|
| 448 | $graph->{"xo"}=$beginx; |
---|
| 449 | $graph->{"ppx"}=$pixelperx; |
---|
| 450 | $graph->{"ppy"}=$pixelpery; |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | # plot the files |
---|
| 454 | $count=0; |
---|
| 455 | my$legendy=$graph->{"labelheight"}/2; |
---|
| 456 | for(my$i=0;$i<$panel_count;$i++){ |
---|
| 457 | if($graph->{"vars"}->[$i]){ |
---|
| 458 | $count++; # count here for legend color selection stability |
---|
| 459 | if(defined($data[$i])){ |
---|
| 460 | # place a legend placard; |
---|
| 461 | my$color=$colors[($count-1)%($#colors+1)]; |
---|
| 462 | $w->createText($width,$legendy,-anchor=>'e',-tags=>['legend'], |
---|
| 463 | -fill=>$color,-text=>$panel_keys[$i]); |
---|
| 464 | $legendy+=$graph->{"labelheight"}; |
---|
| 465 | |
---|
| 466 | # plot the lines |
---|
| 467 | my@pairs=map{if(/^\s*(-?[0-9\.]*)[ ,]+(-?[0-9\.]*)/){ |
---|
| 468 | (($1-$graph->{"minx"})*$graph->{"ppx"}+$graph->{"xo"}, |
---|
| 469 | (-$2+$graph->{"maxy"})*$graph->{"ppy"})}} (@{$data[$i]}); |
---|
| 470 | |
---|
| 471 | $w->createLine((@pairs),-fill=>$color,-tags=>['lines']); |
---|
| 472 | } |
---|
| 473 | } |
---|
| 474 | } |
---|
| 475 | } |
---|
| 476 | } |
---|
| 477 | |
---|
| 478 | sub draw_graph{ |
---|
| 479 | |
---|
| 480 | if($onecrop){ |
---|
| 481 | $onestate{"minx"}=undef; |
---|
| 482 | $onestate{"miny"}=undef; |
---|
| 483 | $onestate{"maxx"}=undef; |
---|
| 484 | $onestate{"maxy"}=undef; |
---|
| 485 | } |
---|
| 486 | if($twocrop){ |
---|
| 487 | $twostate{"minx"}=undef; |
---|
| 488 | $twostate{"miny"}=undef; |
---|
| 489 | $twostate{"maxx"}=undef; |
---|
| 490 | $twostate{"maxy"}=undef; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | for(my$i=0;$i<$panel_count;$i++){ |
---|
| 494 | if($twostate{"vars"}->[$i]){ |
---|
| 495 | |
---|
| 496 | #re-place the canvases |
---|
| 497 | |
---|
| 498 | $oneresize->place(-x=>5,-y=>5,-anchor=>'nw'); |
---|
| 499 | |
---|
| 500 | $one->place(-relwidth=>1.,-width=>-10,-relheight=>.5, |
---|
| 501 | -height=>($graphy/2)-5-$oneresize->reqheight(), |
---|
| 502 | -x=>5,-y=>5+$oneresize->reqheight,-anchor=>'nw'); |
---|
| 503 | |
---|
| 504 | $tworesize->place(-rely=>1.,-y=>5,-anchor=>'nw',-in=>$one); |
---|
| 505 | $two->place(-relwidth=>1.,-relheight=>1.,-rely=>1., |
---|
| 506 | -y=>5+$tworesize->reqheight(),-anchor=>'nw',-in=>$one); |
---|
| 507 | |
---|
| 508 | graphhelper(\%onestate); |
---|
| 509 | graphhelper(\%twostate); |
---|
| 510 | return; |
---|
| 511 | } |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | $oneresize->place(-x=>5,-y=>5,-anchor=>'nw'); |
---|
| 515 | |
---|
| 516 | $one->place(-relwidth=>1.,-width=>-10,-relheight=>1., |
---|
| 517 | -height=>$graphy-5-$oneresize->reqheight(), |
---|
| 518 | -x=>5,-y=>5+$oneresize->reqheight,-anchor=>'nw'); |
---|
| 519 | |
---|
| 520 | $tworesize->placeForget(); |
---|
| 521 | $two->placeForget(); |
---|
| 522 | |
---|
| 523 | graphhelper(\%onestate); |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | sub depopulate_panel{ |
---|
| 527 | my $win; |
---|
| 528 | foreach $win (@panel_labels){ |
---|
| 529 | $win->destroy(); |
---|
| 530 | } |
---|
| 531 | @panel_labels=(); |
---|
| 532 | foreach $win (@panel_ones){ |
---|
| 533 | $win->destroy(); |
---|
| 534 | } |
---|
| 535 | @panel_ones=(); |
---|
| 536 | foreach $win (@panel_twos){ |
---|
| 537 | $win->destroy(); |
---|
| 538 | } |
---|
| 539 | @panel_twos=(); |
---|
| 540 | @panel_keys=(); |
---|
| 541 | } |
---|
| 542 | |
---|
| 543 | sub populate_panel{ |
---|
| 544 | my $localy=$panely; |
---|
| 545 | my $key; |
---|
| 546 | my $i=0; |
---|
| 547 | foreach $key (sort (keys %bases)){ |
---|
| 548 | $panel_keys[$i]=$key; |
---|
| 549 | if(!defined($panel_onevars[$i])){ |
---|
| 550 | $panel_onevars[$i]=0; |
---|
| 551 | $panel_twovars[$i]=0; |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | my $temp=$panel_twos[$i]=$panel_shell-> |
---|
| 555 | Checkbutton(-variable=>\$panel_twovars[$i],-command=>['main::draw_graph'],text=>'2')-> |
---|
| 556 | place(-y=>$localy,-x=>-5,-anchor=>"ne",-relx=>1.); |
---|
| 557 | my $oney=$temp->reqheight(); |
---|
| 558 | my $onex=$temp->reqwidth()+15; |
---|
| 559 | |
---|
| 560 | $temp=$panel_ones[$i]=$panel_shell-> |
---|
| 561 | Checkbutton(-variable=>\$panel_onevars[$i],-command=>['main::draw_graph'],text=>'1')-> |
---|
| 562 | place(-y=>0,-x=>0,-anchor=>"ne",-in=>$temp,-bordermode=>'outside'); |
---|
| 563 | $oney=$temp->reqheight() if ($oney<$temp->reqheight()); |
---|
| 564 | $onex+=$temp->reqwidth(); |
---|
| 565 | |
---|
| 566 | $temp=$panel_labels[$i]=$panel_shell->Label(-text=>$key,-class=>'Field',justify=>'left')-> |
---|
| 567 | place(-y=>$localy,-x=>5,-anchor=>"nw",-relwidth=>1.,-width=>-$onex, |
---|
| 568 | -bordermode=>'outside'); |
---|
| 569 | $oney=$temp->reqheight() if ($oney<$temp->reqheight()); |
---|
| 570 | |
---|
| 571 | $localy+=$oney+2; |
---|
| 572 | $i++; |
---|
| 573 | } |
---|
| 574 | $panel_count=$i; |
---|
| 575 | |
---|
| 576 | $localy+=$panel_quit->reqheight()+50; |
---|
| 577 | my $geometry=$panel->geometry(); |
---|
| 578 | $geometry=~/^(\d+)/; |
---|
| 579 | |
---|
| 580 | $panel->configure(-height=>$localy); |
---|
| 581 | $panel->configure(-width=>$1); |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | sub Shutdown{ |
---|
| 585 | Tk::exit(); |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | sub Status{ |
---|
| 589 | my$text=shift @_; |
---|
| 590 | $graph_status->configure(text=>"$text"); |
---|
| 591 | $toplevel->update(); |
---|
| 592 | } |
---|
| 593 | |
---|
| 594 | sub scan_directory{ |
---|
| 595 | |
---|
| 596 | %bases=(); |
---|
| 597 | my$count=0; |
---|
| 598 | |
---|
| 599 | $first_file=undef; |
---|
| 600 | $last_file=undef; |
---|
| 601 | |
---|
| 602 | if(opendir(D,".")){ |
---|
| 603 | my$file; |
---|
| 604 | while(defined($file=readdir(D))){ |
---|
| 605 | if($file=~m/^(\S*)_(\d+).m/){ |
---|
| 606 | $bases{"$1"}="0"; |
---|
| 607 | $first_file=$2 if(!defined($first_file) || $2<$first_file); |
---|
| 608 | $last_file=$2 if(!defined($last_file) || $2>$last_file); |
---|
| 609 | $count++; |
---|
| 610 | |
---|
| 611 | Status("Reading... $count")if($count%117==0); |
---|
| 612 | } |
---|
| 613 | } |
---|
| 614 | closedir(D); |
---|
| 615 | } |
---|
| 616 | Status("Done Reading: $count files"); |
---|
| 617 | depopulate_panel(); |
---|
| 618 | populate_panel(); |
---|
| 619 | |
---|
| 620 | $fileno=$first_file if($fileno<$first_file); |
---|
| 621 | $fileno=$last_file if($fileno>$last_file); |
---|
| 622 | |
---|
| 623 | $graph_slider->configure(-from=>$first_file,-to=>$last_file); |
---|
| 624 | |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | |
---|
| 628 | |
---|
| 629 | |
---|
| 630 | |
---|