frameview.pl 20 KB

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