Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

YadaJudgeBar.tcl

00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## YadaJudgeBar - draw a chart of categories. 00013 ## This widget is used in the YadaDifference document to visualize the categories 00014 ## between performance and accuracy. 00015 ## 00016 ## \author Michael Daum 00017 ## 00018 ## $Id: YadaJudgeBar.tcl,v 1.10 2004/02/25 14:42:09 micha Exp $ 00019 ## ---------------------------------------------------------------------------- 00020 class YadaJudgeBar { 00021 inherit itk::Widget 00022 00023 00024 # variables ---------------------------------------------------------------- 00025 public variable betterAndFasterBackground "green1" 00026 public variable betterAndFasterForeground "black" 00027 public variable betterBackground "green2" 00028 public variable betterButSlowerBackground "green3" 00029 public variable betterButSlowerForeground "black" 00030 public variable betterForeground "black" 00031 public variable fasterBackground "lightblue" 00032 public variable fasterForeground "black" 00033 public variable harderBackground "deepskyblue3" 00034 public variable harderForeground "black" 00035 public variable sameBackground "gray" 00036 public variable sameForeground "black" 00037 public variable slowerBackground "yellow" 00038 public variable slowerForeground "black" 00039 public variable softerBackground "deepskyblue1" 00040 public variable softerForeground "black" 00041 public variable weirdBackground "pink" 00042 public variable weirdForeground "black" 00043 public variable worseAndSlowerBackground "red3" 00044 public variable worseAndSlowerForeground "white" 00045 public variable worseBackground "red1" 00046 public variable worseButFasterBackground "orange" 00047 public variable worseButFasterForeground "black" 00048 public variable worseForeground "white" 00049 00050 constructor {args} {}; ## \type TclList 00051 00052 private variable _totalWordgraphs 0 00053 private variable _fasterWordgraphs 0 00054 private variable _betterWordgraphs 0 00055 private variable _betterAndFasterWordgraphs 0 00056 private variable _betterButSlowerWordgraphs 0 00057 private variable _softerWordgraphs 0 00058 private variable _harderWordgraphs 0 00059 private variable _sameWordgraphs 0 00060 private variable _worseButFasterWordgraphs 0 00061 private variable _worseAndSlowerWordgraphs 0 00062 private variable _worseWordgraphs 0 00063 private variable _slowerWordgraphs 0 00064 private variable _weirdWordgraphs 0 00065 00066 # methods ------------------------------------------------------------------ 00067 public method draw {args}; ## \type TclList 00068 private method _judgeEnter {x y}; ## \type TclNumber, TclNumber 00069 private method _judgeLeave {} 00070 00071 }; 00072 00073 ## ---------------------------------------------------------------------------- 00074 ## constructor 00075 ## ---------------------------------------------------------------------------- 00076 body YadaJudgeBar::constructor {args} { 00077 00078 itk_component add canvas { 00079 canvas $itk_interior.canvas \ 00080 -height 15 \ 00081 -borderwidth 2 \ 00082 -relief sunk 00083 } { 00084 usual 00085 keep -height -width -relief -borderwidth 00086 } 00087 00088 eval itk_initialize $args 00089 00090 set cv $itk_component(canvas) 00091 $cv create rectangle -100 -100 -100 -100 -tag betterRec -fill $betterBackground 00092 $cv create rectangle -100 -100 -100 -100 -tag betterAndFasterRec -fill $betterAndFasterBackground 00093 $cv create rectangle -100 -100 -100 -100 -tag betterButSlowerRec -fill $betterButSlowerBackground 00094 $cv create rectangle -100 -100 -100 -100 -tag fasterRec -fill $fasterBackground 00095 $cv create rectangle -100 -100 -100 -100 -tag softerRec -fill $softerBackground 00096 $cv create rectangle -100 -100 -100 -100 -tag sameRec -fill $sameBackground 00097 $cv create rectangle -100 -100 -100 -100 -tag harderRec -fill $harderBackground 00098 $cv create rectangle -100 -100 -100 -100 -tag slowerRec -fill $slowerBackground 00099 $cv create rectangle -100 -100 -100 -100 -tag worseButFasterRec -fill $worseButFasterBackground 00100 $cv create rectangle -100 -100 -100 -100 -tag worseAndSlowerRec -fill $worseAndSlowerBackground 00101 $cv create rectangle -100 -100 -100 -100 -tag worseRec -fill $worseBackground 00102 $cv create rectangle -100 -100 -100 -100 -tag weirdRec -fill $weirdBackground 00103 $cv create text -100 -100 -tag betterText -fill $betterForeground -text "" -anchor c \ 00104 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00105 $cv create text -100 -100 -tag betterAndFasterText -fill $betterAndFasterForeground -text "" -anchor c \ 00106 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00107 $cv create text -100 -100 -tag betterButSlowerText -fill $betterButSlowerForeground -text "" -anchor c \ 00108 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00109 $cv create text -100 -100 -tag fasterText -fill $fasterForeground -text "" -anchor c \ 00110 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00111 $cv create text -100 -100 -tag softerText -fill $softerForeground -text "" -anchor c \ 00112 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00113 $cv create text -100 -100 -tag sameText -fill $sameForeground -text "" -anchor c \ 00114 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00115 $cv create text -100 -100 -tag harderText -fill $harderForeground -text "" -anchor c \ 00116 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00117 $cv create text -100 -100 -tag slowerText -fill $slowerForeground -text "" -anchor c \ 00118 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00119 $cv create text -100 -100 -tag worseButFasterText -fill $worseButFasterForeground \ 00120 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} -text "" -anchor c 00121 $cv create text -100 -100 -tag worseAndSlowerText -fill $worseAndSlowerForeground \ 00122 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} -text "" -anchor c 00123 $cv create text -100 -100 -tag worseText -fill $worseForeground -text "" -anchor c \ 00124 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00125 $cv create text -100 -100 -tag weirdText -fill $weirdForeground -text "" -anchor c \ 00126 -font {-adobe-helvetica-medium-r-normal--10-*-*-*-*-*-*-*} 00127 00128 # canvas bindings 00129 $cv bind all <Any-Enter> [code $this _judgeEnter %X %Y] 00130 $cv bind all <Any-Leave> [code $this _judgeLeave] 00131 00132 # bindings 00133 bind $cv <Configure> [code $this draw] 00134 00135 # packing 00136 pack $itk_component(canvas) -fill both -expand 1 00137 } 00138 00139 ## ---------------------------------------------------------------------------- 00140 ## draw 00141 ## ---------------------------------------------------------------------------- 00142 body YadaJudgeBar::draw {args} { 00143 00144 set noArgs [llength $args] 00145 00146 if {$noArgs == 12} { 00147 set pos 0 00148 set _totalWordgraphs 0 00149 foreach argument { 00150 _fasterWordgraphs _betterWordgraphs 00151 _betterAndFasterWordgraphs _betterButSlowerWordgraphs _softerWordgraphs 00152 _harderWordgraphs _sameWordgraphs _worseButFasterWordgraphs 00153 _worseAndSlowerWordgraphs _worseWordgraphs _slowerWordgraphs 00154 _weirdWordgraphs 00155 } { 00156 set $argument [lindex $args $pos] 00157 incr pos 00158 incr _totalWordgraphs [subst \$$argument] 00159 } 00160 } elseif {$noArgs != 0} { 00161 error "ERROR: illegal number of parameters to YadaJudgeBar::draw" 00162 } 00163 00164 set cv $itk_component(canvas) 00165 set cvHeight [winfo height $cv] 00166 set cvWidth [winfo width $cv] 00167 00168 set lastX 0 00169 foreach category {betterAndFaster better betterButSlower \ 00170 faster softer same weird harder slower \ 00171 worseButFaster worse worseAndSlower} { 00172 00173 set wordgraphs [subst \$_${category}Wordgraphs] 00174 if {$wordgraphs > 0} { 00175 if {$_totalWordgraphs > 0} { 00176 set percentage [expr $wordgraphs / ($_totalWordgraphs + 0.0) ] 00177 } else { 00178 set percentage 0.0 00179 } 00180 set newX [expr $lastX + $percentage * $cvWidth] 00181 $cv coords ${category}Rec $lastX 0 $newX $cvHeight 00182 00183 if {$percentage >= 0.02} { 00184 $cv coords ${category}Text [expr $lastX + ($newX - $lastX) / 2.0] [expr $cvHeight / 2.0] 00185 $cv itemconfigure ${category}Text -text [format "%.f%%" [expr $percentage * 100]] 00186 } else { 00187 $cv coords ${category}Text -100 -100 00188 } 00189 00190 set lastX $newX 00191 } else { 00192 $cv coords ${category}Rec -100 -100 -100 -100 00193 $cv coords ${category}Text -100 -100 00194 } 00195 } 00196 00197 } 00198 00199 ## ---------------------------------------------------------------------------- 00200 ## _judgeEnter 00201 ## ---------------------------------------------------------------------------- 00202 body YadaJudgeBar::_judgeEnter {x y} { 00203 set cv $itk_component(canvas) 00204 set id [$cv find withtag current] 00205 set tag [lindex [$cv itemcget $id -tags] 0] 00206 00207 regexp "\(.*\)\(Rec\|Text\)" $tag dummy category 00208 00209 00210 set noWordgraphs [subst \$_${category}Wordgraphs] 00211 set percentage [expr $noWordgraphs / ($_totalWordgraphs + 0.0) * 100] 00212 00213 .balloon on $x $y [format "%s - %d (%.2f%%)" $category $noWordgraphs $percentage] 00214 } 00215 00216 ## ---------------------------------------------------------------------------- 00217 ## _judgeLeave 00218 ## ---------------------------------------------------------------------------- 00219 body YadaJudgeBar::_judgeLeave {} { 00220 .balloon off 00221 }

YADA 2.0-alpha (20 Oct 2004)