[1572] | 1 | |
---|
| 2 | # ---------------------------------------------------------------------- |
---|
| 3 | # COMPONENT: xyprint - Print X-Y plot. |
---|
| 4 | # |
---|
| 5 | # ====================================================================== |
---|
| 6 | # AUTHOR: Michael McLennan, Purdue University |
---|
| 7 | # Copyright (c) 2004-2005 Purdue Research Foundation |
---|
| 8 | # |
---|
| 9 | # See the file "license.terms" for information on usage and |
---|
| 10 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 11 | # ====================================================================== |
---|
[1588] | 12 | package require Itk |
---|
[1572] | 13 | package require BLT |
---|
| 14 | |
---|
[1593] | 15 | #option add *XyPrint.width 3i widgetDefault |
---|
| 16 | #option add *XyPrint.height 3i widgetDefault |
---|
| 17 | option add *XyPrint.gridColor #d9d9d9 widgetDefault |
---|
[1588] | 18 | option add *XyPrint.activeColor blue widgetDefault |
---|
| 19 | option add *XyPrint.dimColor gray widgetDefault |
---|
| 20 | option add *XyPrint.controlBackground gray widgetDefault |
---|
[1785] | 21 | option add *XyPrint*Font "Arial 9" widgetDefault |
---|
[1588] | 22 | option add *XyPrint*Entry*width "6" widgetDefault |
---|
| 23 | option add *XyPrint*Entry*background "white" widgetDefault |
---|
| 24 | |
---|
| 25 | itcl::class Rappture::XyPrint { |
---|
| 26 | inherit itk::Widget |
---|
| 27 | |
---|
[1589] | 28 | constructor {args} {} |
---|
[1572] | 29 | destructor {} |
---|
[1589] | 30 | |
---|
| 31 | private variable _graph ""; # Original graph. |
---|
[1588] | 32 | private variable _clone ""; # Cloned graph. |
---|
| 33 | private variable _preview ""; # Preview image. |
---|
[1598] | 34 | private variable _savedSettings; # Array of settings. |
---|
[1607] | 35 | |
---|
[1636] | 36 | private common _oldSettingsFile "~/.rpsettings" |
---|
| 37 | private common _settingsFile "~/.rp_settings" |
---|
[1607] | 38 | |
---|
[1598] | 39 | public method print { graph toolName plotName } |
---|
[1603] | 40 | public method reset {} |
---|
[1572] | 41 | |
---|
[1785] | 42 | private method CopyOptions { cmd orig clone {exclude {}}} |
---|
[1572] | 43 | private method CloneGraph { orig } |
---|
[1588] | 44 | |
---|
[1593] | 45 | private method BuildGeneralTab {} |
---|
[1588] | 46 | private method BuildLayoutTab {} |
---|
| 47 | private method BuildLegendTab {} |
---|
| 48 | private method BuildAxisTab {} |
---|
| 49 | private method SetOption { opt } |
---|
| 50 | private method SetComponentOption { comp opt } |
---|
| 51 | private method SetNamedComponentOption { comp name opt } |
---|
| 52 | private method GetAxis {} |
---|
| 53 | private method GetElement { args } |
---|
| 54 | private method RegeneratePreview {} |
---|
| 55 | private method InitClone {} |
---|
| 56 | private method Pixels2Inches { pixels } |
---|
[1636] | 57 | private method Inches2Pixels { inches {defValue ""}} |
---|
[1606] | 58 | private method Color2RGB { color } |
---|
[1589] | 59 | |
---|
| 60 | private method ApplyGeneralSettings {} |
---|
| 61 | private method ApplyLegendSettings {} |
---|
| 62 | private method ApplyAxisSettings {} |
---|
| 63 | private method ApplyElementSettings {} |
---|
| 64 | private method ApplyLayoutSettings {} |
---|
| 65 | private method InitializeSettings {} |
---|
[1598] | 66 | private method CreateSettings { toolName plotName } |
---|
| 67 | private method RestoreSettings { toolName plotName } |
---|
| 68 | private method SaveSettings { toolName plotName } |
---|
[1603] | 69 | private method DestroySettings {} |
---|
[1593] | 70 | private method ResetSettings { } |
---|
| 71 | private method GetOutput {} |
---|
[1785] | 72 | private method SetWaitVariable { state } |
---|
[1636] | 73 | private method SetLayoutOption { option } |
---|
| 74 | private method GetAxisType { axis } |
---|
[1598] | 75 | private method restore { toolName plotName data } |
---|
[1588] | 76 | private common _settings |
---|
[1601] | 77 | private common _fonts |
---|
[1589] | 78 | private common _wait |
---|
[1572] | 79 | } |
---|
| 80 | |
---|
| 81 | # ---------------------------------------------------------------------- |
---|
| 82 | # CONSTRUCTOR |
---|
| 83 | # ---------------------------------------------------------------------- |
---|
[1589] | 84 | itcl::body Rappture::XyPrint::constructor { args } { |
---|
[1588] | 85 | Rappture::dispatcher _dispatcher |
---|
| 86 | $_dispatcher register !rebuild |
---|
| 87 | $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" |
---|
| 88 | |
---|
| 89 | set w [winfo pixels . 2.5i] |
---|
| 90 | set h [winfo pixels . 2i] |
---|
| 91 | set _preview [image create photo -width $w -height $h] |
---|
| 92 | itk_component add tabs { |
---|
| 93 | blt::tabset $itk_interior.tabs \ |
---|
| 94 | -highlightthickness 0 -tearoff 0 -side top \ |
---|
| 95 | -bd 0 -gap 0 -tabborderwidth 1 \ |
---|
| 96 | -outerpad 1 -background grey |
---|
| 97 | } { |
---|
| 98 | keep -cursor |
---|
| 99 | ignore -highlightthickness -borderwidth -background |
---|
| 100 | } |
---|
| 101 | itk_component add preview { |
---|
| 102 | label $itk_interior.preview \ |
---|
| 103 | -highlightthickness 0 -bd 0 -image $_preview -width 2.5i \ |
---|
[1929] | 104 | -height 2.25i -background grey -padx 10 -pady 10 |
---|
[1588] | 105 | } { |
---|
[1929] | 106 | ignore -background |
---|
[1588] | 107 | } |
---|
| 108 | itk_component add ok { |
---|
[1601] | 109 | button $itk_interior.ok -text "Save" \ |
---|
[1785] | 110 | -highlightthickness 0 -pady 2 -padx 0 \ |
---|
[1929] | 111 | -command [itcl::code $this SetWaitVariable 1] \ |
---|
| 112 | -compound left \ |
---|
| 113 | -image [Rappture::icon download] |
---|
[1588] | 114 | } |
---|
| 115 | itk_component add cancel { |
---|
| 116 | button $itk_interior.cancel -text "Cancel" \ |
---|
[1785] | 117 | -highlightthickness 0 -pady 2 -padx 0 \ |
---|
[1929] | 118 | -command [itcl::code $this SetWaitVariable 0] \ |
---|
| 119 | -compound left \ |
---|
| 120 | -image [Rappture::icon cancel] |
---|
[1588] | 121 | } |
---|
| 122 | blt::table $itk_interior \ |
---|
[1929] | 123 | 0,0 $itk_component(preview) -cspan 2 -fill both \ |
---|
| 124 | 1,0 $itk_component(tabs) -fill both -cspan 2 \ |
---|
[1595] | 125 | 2,1 $itk_component(cancel) -padx 2 -pady 2 -width .9i -fill y \ |
---|
[1929] | 126 | 2,0 $itk_component(ok) -padx 2 -pady 2 -width .9i -fill y |
---|
[1588] | 127 | blt::table configure $itk_interior r1 -resize none |
---|
| 128 | blt::table configure $itk_interior r1 -resize both |
---|
| 129 | |
---|
[1593] | 130 | BuildGeneralTab |
---|
[1588] | 131 | BuildAxisTab |
---|
| 132 | BuildLegendTab |
---|
| 133 | BuildLayoutTab |
---|
| 134 | eval itk_initialize $args |
---|
[1572] | 135 | } |
---|
| 136 | |
---|
[1588] | 137 | # ---------------------------------------------------------------------- |
---|
| 138 | # DESTRUCTOR |
---|
| 139 | # ---------------------------------------------------------------------- |
---|
[1593] | 140 | itcl::body Rappture::XyPrint::destructor {} { |
---|
[1588] | 141 | destroy $_clone |
---|
| 142 | image delete $_preview |
---|
| 143 | array unset _settings $this-* |
---|
| 144 | } |
---|
| 145 | |
---|
[1593] | 146 | itcl::body Rappture::XyPrint::DestroySettings {} { |
---|
[1590] | 147 | destroy $_clone |
---|
| 148 | set _clone "" |
---|
| 149 | set _graph "" |
---|
[1605] | 150 | foreach font [array names _fonts] { |
---|
[1929] | 151 | font delete $font |
---|
[1605] | 152 | } |
---|
| 153 | array unset _fonts |
---|
[1590] | 154 | } |
---|
| 155 | |
---|
[1603] | 156 | itcl::body Rappture::XyPrint::reset {} { |
---|
[1785] | 157 | SetWaitVariable 0 |
---|
[1603] | 158 | } |
---|
| 159 | |
---|
[1785] | 160 | itcl::body Rappture::XyPrint::SetWaitVariable { state } { |
---|
[1589] | 161 | set _wait($this) $state |
---|
| 162 | } |
---|
[1588] | 163 | |
---|
[1598] | 164 | itcl::body Rappture::XyPrint::print { graph toolName plotName } { |
---|
[1590] | 165 | set _graph $graph |
---|
[1785] | 166 | CloneGraph $graph |
---|
[1589] | 167 | InitClone |
---|
[1604] | 168 | RestoreSettings $toolName $plotName |
---|
[1589] | 169 | InitializeSettings |
---|
[1785] | 170 | SetWaitVariable 0 |
---|
[1589] | 171 | tkwait variable [itcl::scope _wait($this)] |
---|
[1785] | 172 | SaveSettings $toolName $plotName |
---|
[1593] | 173 | set output "" |
---|
| 174 | if { $_wait($this) } { |
---|
[1929] | 175 | set output [GetOutput] |
---|
[1589] | 176 | } |
---|
[1598] | 177 | DestroySettings |
---|
[1593] | 178 | return $output |
---|
[1589] | 179 | } |
---|
| 180 | |
---|
| 181 | itcl::body Rappture::XyPrint::GetOutput {} { |
---|
[1588] | 182 | # Get the selected format of the download. |
---|
| 183 | set page $itk_component(graph_page) |
---|
| 184 | set format [$page.format current] |
---|
| 185 | |
---|
| 186 | if { $format == "jpg" } { |
---|
[1929] | 187 | set img [image create photo] |
---|
| 188 | $_clone snap $img |
---|
| 189 | set bytes [$img data -format "jpeg -quality 100"] |
---|
| 190 | set bytes [Rappture::encoding::decode -as b64 $bytes] |
---|
| 191 | image delete $img |
---|
| 192 | return [list .jpg $bytes] |
---|
[1588] | 193 | } elseif { $format == "png" } { |
---|
[1929] | 194 | set img [image create photo] |
---|
| 195 | $_clone snap $img |
---|
| 196 | set bytes [$img data -format "png"] |
---|
| 197 | set bytes [Rappture::encoding::decode -as b64 $bytes] |
---|
| 198 | image delete $img |
---|
| 199 | return [list .png $bytes] |
---|
[1588] | 200 | } |
---|
| 201 | |
---|
| 202 | # Handle encapsulated postscript or portable document format. |
---|
| 203 | |
---|
| 204 | # Append an "i" for the graph postscript component. |
---|
| 205 | set w $_settings($this-layout-width)i |
---|
| 206 | set h $_settings($this-layout-height)i |
---|
| 207 | |
---|
| 208 | $_clone postscript configure \ |
---|
[1929] | 209 | -maxpect false \ |
---|
| 210 | -decoration yes \ |
---|
| 211 | -center yes \ |
---|
| 212 | -width $w -height $h |
---|
[1572] | 213 | |
---|
[1588] | 214 | set psdata [$_clone postscript output] |
---|
[1572] | 215 | |
---|
[1717] | 216 | if 0 { |
---|
[1929] | 217 | set f [open "junk.raw" "w"] |
---|
| 218 | puts -nonewline $f $psdata |
---|
| 219 | close $f |
---|
[1717] | 220 | } |
---|
[1616] | 221 | if { $format == "eps" } { |
---|
[1929] | 222 | return [list .$format $psdata] |
---|
[1572] | 223 | } |
---|
[1598] | 224 | |
---|
| 225 | set cmd "" |
---|
| 226 | # | eps2eps << $psdata |
---|
| 227 | lappend cmd "|" "/usr/bin/gs" \ |
---|
[1929] | 228 | "-q" "-sDEVICE=epswrite" "-sstdout=%stderr" \ |
---|
| 229 | "-sOutputFile=-" "-dNOPAUSE" "-dBATCH" "-dSAFER" \ |
---|
| 230 | "-dDEVICEWIDTH=250000" "-dDEVICEHEIGHT=250000" "-" "<<" "$psdata" |
---|
[1598] | 231 | if { $format == "pdf" } { |
---|
[1929] | 232 | # | eps2eps << $psdata | ps2pdf |
---|
| 233 | lappend cmd "|" "/usr/bin/gs" \ |
---|
| 234 | "-q" "-sDEVICE=pdfwrite" "-sstdout=%stderr" \ |
---|
| 235 | "-sOutputFile=-" "-dNOPAUSE" "-dBATCH" "-dSAFER" \ |
---|
| 236 | "-dCompatibilityLevel=1.4" "-c" ".setpdfwrite" "-f" "-" |
---|
[1598] | 237 | } |
---|
[1588] | 238 | if { [catch { |
---|
[1929] | 239 | set f [open $cmd "r"] |
---|
| 240 | fconfigure $f -translation binary -encoding binary |
---|
| 241 | set output [read $f] |
---|
| 242 | close $f |
---|
[1588] | 243 | } err ] != 0 } { |
---|
[1929] | 244 | global errorInfo |
---|
| 245 | puts stderr "failed to generate file: $err\n$errorInfo" |
---|
| 246 | return "" |
---|
[1572] | 247 | } |
---|
[1593] | 248 | if 0 { |
---|
[1929] | 249 | set f [open "junk.$format" "w"] |
---|
| 250 | fconfigure $f -translation binary -encoding binary |
---|
| 251 | puts -nonewline $f $output |
---|
| 252 | close $f |
---|
[1593] | 253 | } |
---|
[1588] | 254 | return [list .$format $output] |
---|
[1572] | 255 | } |
---|
| 256 | |
---|
[1785] | 257 | itcl::body Rappture::XyPrint::CopyOptions { cmd orig clone {exclude {}} } { |
---|
[1572] | 258 | set all [eval $orig $cmd] |
---|
| 259 | set configLine $clone |
---|
[1785] | 260 | foreach name $exclude { |
---|
[1929] | 261 | set ignore($name) 1 |
---|
[1785] | 262 | } |
---|
[1572] | 263 | foreach arg $cmd { |
---|
[1929] | 264 | lappend configLine $arg |
---|
[1572] | 265 | } |
---|
| 266 | foreach option $all { |
---|
[1929] | 267 | if { [llength $option] != 5 } { |
---|
| 268 | continue |
---|
| 269 | } |
---|
| 270 | set switch [lindex $option 0] |
---|
| 271 | set initial [lindex $option 3] |
---|
| 272 | set current [lindex $option 4] |
---|
| 273 | if { [info exists ignore($switch)] } { |
---|
| 274 | continue |
---|
| 275 | } |
---|
| 276 | if { [string compare $initial $current] == 0 } { |
---|
| 277 | continue |
---|
| 278 | } |
---|
| 279 | lappend configLine $switch $current |
---|
[1572] | 280 | } |
---|
| 281 | eval $configLine |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | itcl::body Rappture::XyPrint::CloneGraph { orig } { |
---|
[1588] | 285 | set top $itk_interior |
---|
[1636] | 286 | if { [winfo exists $top.graph] } { |
---|
[1929] | 287 | destroy $top.graph |
---|
[1636] | 288 | } |
---|
[1785] | 289 | set _clone [blt::graph $top.graph] |
---|
| 290 | CopyOptions "configure" $orig $_clone |
---|
[1572] | 291 | # Axis component |
---|
| 292 | foreach axis [$orig axis names] { |
---|
[1929] | 293 | if { [$orig axis cget $axis -hide] } { |
---|
| 294 | continue |
---|
| 295 | } |
---|
| 296 | if { [$_clone axis name $axis] == "" } { |
---|
| 297 | $_clone axis create $axis |
---|
| 298 | } |
---|
| 299 | CopyOptions [list axis configure $axis] $orig $_clone |
---|
[1572] | 300 | } |
---|
| 301 | foreach axis { x y x2 y2 } { |
---|
[1929] | 302 | $_clone ${axis}axis use [$orig ${axis}axis use] |
---|
[1572] | 303 | } |
---|
| 304 | # Pen component |
---|
| 305 | foreach pen [$orig pen names] { |
---|
[1929] | 306 | if { [$_clone pen name $pen] == "" } { |
---|
| 307 | $_clone pen create $pen |
---|
| 308 | } |
---|
| 309 | CopyOptions [list pen configure $pen] $orig $_clone |
---|
[1572] | 310 | } |
---|
| 311 | # Marker component |
---|
| 312 | foreach marker [$orig marker names] { |
---|
[1929] | 313 | $_clone marker create [$orig marker type $marker] -name $marker |
---|
| 314 | CopyOptions [list marker configure $marker] $orig $_clone -name |
---|
[1572] | 315 | } |
---|
| 316 | # Element component |
---|
| 317 | foreach elem [$orig element names] { |
---|
[1930] | 318 | set oper [$orig element type $elem] |
---|
| 319 | $_clone $oper create $elem |
---|
| 320 | CopyOptions [list $oper configure $elem] $orig $_clone -data |
---|
| 321 | if { [$_clone $oper cget $elem -hide] } { |
---|
| 322 | $_clone $oper configure $elem -label "" |
---|
| 323 | puts stderr [$_clone $oper configure] |
---|
[1929] | 324 | } |
---|
[1572] | 325 | } |
---|
| 326 | # Fix element display list |
---|
[1785] | 327 | $_clone element show [$orig element show] |
---|
[1572] | 328 | # Legend component |
---|
[1785] | 329 | CopyOptions {legend configure} $orig $_clone |
---|
[1572] | 330 | # Postscript component |
---|
[1785] | 331 | CopyOptions {postscript configure} $orig $_clone |
---|
| 332 | # Crosshairs component |
---|
| 333 | CopyOptions {crosshairs configure} $orig $_clone |
---|
[1572] | 334 | # Grid component |
---|
[1785] | 335 | CopyOptions {grid configure} $orig $_clone |
---|
| 336 | |
---|
| 337 | # Create markers representing lines at zero for the x and y axis. |
---|
| 338 | $_clone marker create line -name x-zero \ |
---|
[1929] | 339 | -coords "0 -Inf 0 Inf" -dashes 1 -hide yes |
---|
[1785] | 340 | $_clone marker create line -name y-zero \ |
---|
[1929] | 341 | -coords "-Inf 0 Inf 0" -dashes 1 -hide yes |
---|
[1572] | 342 | } |
---|
[1588] | 343 | |
---|
| 344 | itcl::body Rappture::XyPrint::InitClone {} { |
---|
[1572] | 345 | |
---|
[1588] | 346 | $_clone configure -width 3.4i -height 3.4i -background white \ |
---|
[1929] | 347 | -borderwidth 0 \ |
---|
| 348 | -leftmargin 0 \ |
---|
| 349 | -rightmargin 0 \ |
---|
| 350 | -topmargin 0 \ |
---|
| 351 | -bottommargin 0 |
---|
[1588] | 352 | |
---|
| 353 | # Kill the title and create a border around the plot |
---|
| 354 | $_clone configure \ |
---|
[1929] | 355 | -title "" \ |
---|
| 356 | -plotborderwidth 1 -plotrelief solid \ |
---|
| 357 | -plotbackground white -plotpadx 0 -plotpady 0 |
---|
[1930] | 358 | |
---|
[1604] | 359 | set _settings($this-layout-width) [Pixels2Inches [$_clone cget -width]] |
---|
| 360 | set _settings($this-layout-height) [Pixels2Inches [$_clone cget -height]] |
---|
| 361 | set _fonts(legend) [font create legend \ |
---|
[1929] | 362 | -family helvetica -size 10 -weight normal] |
---|
[1598] | 363 | update |
---|
[1588] | 364 | $_clone legend configure \ |
---|
[1929] | 365 | -position right \ |
---|
| 366 | -font $_fonts(legend) \ |
---|
| 367 | -hide yes -borderwidth 0 -background white -relief solid \ |
---|
| 368 | -anchor nw -activeborderwidth 0 |
---|
[1588] | 369 | # |
---|
| 370 | foreach axis [$_clone axis names] { |
---|
[1929] | 371 | if { [$_clone axis cget $axis -hide] } { |
---|
| 372 | continue |
---|
| 373 | } |
---|
| 374 | set _fonts($axis-ticks) [font create $axis-ticks \ |
---|
| 375 | -family helvetica -size 10 \ |
---|
| 376 | -weight normal -slant roman] |
---|
| 377 | set _fonts($axis-title) [font create $axis-title \ |
---|
| 378 | -family helvetica -size 10 \ |
---|
| 379 | -weight normal -slant roman] |
---|
| 380 | update |
---|
| 381 | $_clone axis configure $axis -ticklength 5 \ |
---|
| 382 | -majorticks {} -minorticks {} |
---|
| 383 | $_clone axis configure $axis \ |
---|
| 384 | -tickfont $_fonts($axis-ticks) \ |
---|
| 385 | -titlefont $_fonts($axis-title) |
---|
[1588] | 386 | } |
---|
| 387 | foreach elem [$_clone element names] { |
---|
[1930] | 388 | if { [$_clone element type $elem] == "bar" } { |
---|
| 389 | continue |
---|
| 390 | } |
---|
[1929] | 391 | if { [$_clone element cget $elem -linewidth] > 1 } { |
---|
| 392 | $_clone element configure $elem -linewidth 1 -pixels 3 |
---|
| 393 | } |
---|
[1588] | 394 | } |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | itcl::body Rappture::XyPrint::SetOption { opt } { |
---|
[1785] | 398 | set new $_settings($this-graph$opt) |
---|
| 399 | set old [$_clone cget $opt] |
---|
| 400 | set code [catch [list $_clone configure $opt $new] err] |
---|
[1588] | 401 | if { $code != 0 } { |
---|
[1929] | 402 | bell |
---|
| 403 | global errorInfo |
---|
| 404 | puts stderr "$err: $errorInfo" |
---|
| 405 | set _settings($this-graph$opt) $old |
---|
| 406 | $_clone configure $opt $old |
---|
[1588] | 407 | } |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | itcl::body Rappture::XyPrint::SetComponentOption { comp opt } { |
---|
[1785] | 411 | set new $_settings($this-$comp$opt) |
---|
| 412 | set old [$_clone $comp cget $opt] |
---|
| 413 | set code [catch [list $_clone $comp configure $opt $new] err] |
---|
[1588] | 414 | if { $code != 0 } { |
---|
[1929] | 415 | bell |
---|
| 416 | global errorInfo |
---|
| 417 | puts stderr "$err: $errorInfo" |
---|
| 418 | set _settings($this-$comp$opt) $old |
---|
| 419 | $_clone $comp configure $opt $old |
---|
[1588] | 420 | } |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | itcl::body Rappture::XyPrint::SetNamedComponentOption { comp name opt } { |
---|
[1785] | 424 | set new $_settings($this-$comp$opt) |
---|
| 425 | set old [$_clone $comp cget $name $opt] |
---|
| 426 | set code [catch [list $_clone $comp configure $name $opt $new] err] |
---|
[1588] | 427 | if { $code != 0 } { |
---|
[1929] | 428 | bell |
---|
| 429 | global errorInfo |
---|
| 430 | puts stderr "$err: $errorInfo" |
---|
| 431 | set _settings($this-$comp$opt) $old |
---|
| 432 | $_clone $comp configure $name $opt $old |
---|
[1588] | 433 | } |
---|
| 434 | } |
---|
| 435 | |
---|
[1589] | 436 | itcl::body Rappture::XyPrint::RegeneratePreview {} { |
---|
| 437 | update |
---|
| 438 | set img [image create photo] |
---|
[1636] | 439 | set w [Inches2Pixels $_settings($this-layout-width) 3.4] |
---|
| 440 | set h [Inches2Pixels $_settings($this-layout-height) 3.4] |
---|
[1589] | 441 | set pixelsPerInch [winfo pixels . 1i] |
---|
| 442 | set sx [expr 2.5*$pixelsPerInch/$w] |
---|
| 443 | set sy [expr 2.0*$pixelsPerInch/$h] |
---|
| 444 | set s [expr min($sx,$sy)] |
---|
| 445 | $_clone snap $img -width $w -height $h |
---|
| 446 | |
---|
| 447 | if 0 { |
---|
| 448 | if { ![winfo exists .labeltest] } { |
---|
[1929] | 449 | toplevel .labeltest -bg red |
---|
| 450 | label .labeltest.label -image $img |
---|
| 451 | pack .labeltest.label -fill both |
---|
[1589] | 452 | } |
---|
| 453 | } |
---|
| 454 | set pw [expr int(round($s * $w))] |
---|
| 455 | set ph [expr int(round($s * $h))] |
---|
| 456 | $_preview configure -width $pw -height $ph |
---|
| 457 | #.labeltest.label configure -image $img |
---|
| 458 | blt::winop resample $img $_preview box |
---|
| 459 | image delete $img |
---|
[1588] | 460 | } |
---|
| 461 | |
---|
[1589] | 462 | itcl::body Rappture::XyPrint::Pixels2Inches { pixels } { |
---|
| 463 | if { [llength $pixels] == 2 } { |
---|
[1929] | 464 | set pixels [lindex $pixels 0] |
---|
[1589] | 465 | } |
---|
| 466 | set pixelsPerInch [winfo pixels . 1i] |
---|
| 467 | set inches [expr { double($pixels) / $pixelsPerInch }] |
---|
| 468 | return [format %.3g ${inches}] |
---|
| 469 | } |
---|
| 470 | |
---|
[1636] | 471 | itcl::body Rappture::XyPrint::Inches2Pixels { inches {defValue ""}} { |
---|
| 472 | set n [scan $inches %g dummy] |
---|
[1653] | 473 | if { $n != 1 && $defValue != "" } { |
---|
[1929] | 474 | set inches $defValue |
---|
[1636] | 475 | } |
---|
[1589] | 476 | return [winfo pixels . ${inches}i] |
---|
| 477 | } |
---|
| 478 | |
---|
[1606] | 479 | itcl::body Rappture::XyPrint::Color2RGB { color } { |
---|
| 480 | foreach { r g b } [winfo rgb $_clone $color] { |
---|
[1929] | 481 | set r [expr round($r / 257.0)] |
---|
| 482 | set g [expr round($g / 257.0)] |
---|
| 483 | set b [expr round($b / 257.0)] |
---|
[1606] | 484 | } |
---|
| 485 | return [format "\#%02x%02x%02x" $r $g $b] |
---|
| 486 | } |
---|
[1589] | 487 | |
---|
[1636] | 488 | itcl::body Rappture::XyPrint::GetAxisType { axis } { |
---|
| 489 | foreach type { x y x2 y2 } { |
---|
[1929] | 490 | set axes [$_clone ${type}axis use] |
---|
| 491 | if { [lsearch $axes $axis] >= 0 } { |
---|
| 492 | return [string range $type 0 0] |
---|
| 493 | } |
---|
[1636] | 494 | } |
---|
| 495 | return "" |
---|
| 496 | } |
---|
[1606] | 497 | |
---|
[1589] | 498 | itcl::body Rappture::XyPrint::GetAxis {} { |
---|
| 499 | set axis [$itk_component(axis_combo) current] |
---|
[1785] | 500 | foreach option { -min -max -loose -title -stepsize -subdivisions } { |
---|
[1929] | 501 | set _settings($this-axis$option) [$_clone axis cget $axis $option] |
---|
[1589] | 502 | } |
---|
[1636] | 503 | set type [GetAxisType $axis] |
---|
[1589] | 504 | if { [$_clone grid cget -map${type}] == $axis } { |
---|
[1929] | 505 | set _settings($this-axis-grid) 1 |
---|
[1589] | 506 | } else { |
---|
[1929] | 507 | set _settings($this-axis-grid) 0 |
---|
[1589] | 508 | } |
---|
[1599] | 509 | set _settings($this-axis-plotpad${type}) \ |
---|
[1929] | 510 | [Pixels2Inches [$_clone cget -plotpad${type}]] |
---|
[1589] | 511 | set _settings($this-axis-zero) [$_clone marker cget ${type}-zero -hide] |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | itcl::body Rappture::XyPrint::GetElement { args } { |
---|
| 515 | set index 1 |
---|
[1636] | 516 | array unset _settings $this-element-* |
---|
[1589] | 517 | foreach elem [$_clone element show] { |
---|
[1929] | 518 | set _settings($this-element-$index) $elem |
---|
| 519 | incr index |
---|
[1589] | 520 | } |
---|
| 521 | set index [$itk_component(element_slider) get] |
---|
| 522 | set elem $_settings($this-element-$index) |
---|
[1930] | 523 | set _settings($this-element-label) [$_clone element cget $elem -label] |
---|
[1589] | 524 | set _settings($this-element-color) [$_clone element cget $elem -color] |
---|
[1930] | 525 | if { [$_clone element type $elem] != "bar" } { |
---|
| 526 | set _settings($this-element-symbol) [$_clone element cget $elem -symbol] |
---|
| 527 | set _settings($this-element-dashes) [$_clone element cget $elem -dashes] |
---|
| 528 | } |
---|
[1589] | 529 | set page $itk_component(legend_page) |
---|
[1606] | 530 | set color [$page.color label $_settings($this-element-color)] |
---|
| 531 | if { $color == "" } { |
---|
[1929] | 532 | set color [Color2RGB $_settings($this-element-color)] |
---|
| 533 | $page.color choices insert end $color $color |
---|
| 534 | $page.color value $color |
---|
[1606] | 535 | } else { |
---|
[1929] | 536 | $page.color value [$page.color label $_settings($this-element-color)] |
---|
[1606] | 537 | } |
---|
[1930] | 538 | if { [$_clone element type $elem] != "bar" } { |
---|
| 539 | $page.symbol value [$page.symbol label $_settings($this-element-symbol)] |
---|
| 540 | $page.dashes value [$page.dashes label $_settings($this-element-dashes)] |
---|
| 541 | } |
---|
[1589] | 542 | #FixElement |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | itcl::body Rappture::XyPrint::BuildLayoutTab {} { |
---|
| 546 | itk_component add layout_page { |
---|
[1929] | 547 | frame $itk_component(tabs).layout_page |
---|
[1589] | 548 | } |
---|
| 549 | set page $itk_component(layout_page) |
---|
| 550 | $itk_component(tabs) insert end "layout" \ |
---|
| 551 | -text "Layout" -padx 2 -pady 2 -window $page -fill both |
---|
| 552 | |
---|
| 553 | label $page.width_l -text "width" |
---|
| 554 | entry $page.width -width 6 \ |
---|
[1929] | 555 | -textvariable [itcl::scope _settings($this-layout-width)] |
---|
[1589] | 556 | bind $page.width <KeyPress-Return> [itcl::code $this ApplyLayoutSettings] |
---|
[1609] | 557 | Rappture::Tooltip::for $page.width \ |
---|
| 558 | "Set the width (inches) of the output image. Must be a positive number." |
---|
[1589] | 559 | |
---|
| 560 | label $page.height_l -text "height" |
---|
| 561 | entry $page.height -width 6 \ |
---|
[1929] | 562 | -textvariable [itcl::scope _settings($this-layout-height)] |
---|
[1589] | 563 | bind $page.height <KeyPress-Return> [itcl::code $this ApplyLayoutSettings] |
---|
[1609] | 564 | Rappture::Tooltip::for $page.height \ |
---|
| 565 | "Set the height (inches) of the output image. Must be a positive number" |
---|
[1589] | 566 | |
---|
| 567 | label $page.margin_l -text "Margins" |
---|
| 568 | |
---|
| 569 | label $page.left_l -text "left" |
---|
| 570 | entry $page.left -width 6 \ |
---|
[1929] | 571 | -textvariable [itcl::scope _settings($this-layout-leftmargin)] |
---|
[1589] | 572 | bind $page.left <KeyPress-Return> [itcl::code $this ApplyLayoutSettings] |
---|
[1609] | 573 | Rappture::Tooltip::for $page.left \ |
---|
| 574 | "Set the size (inches) of the left margin. If zero, the size is automatically determined." |
---|
[1589] | 575 | |
---|
| 576 | label $page.right_l -text "right" |
---|
| 577 | entry $page.right -width 6 \ |
---|
[1929] | 578 | -textvariable [itcl::scope _settings($this-layout-rightmargin)] |
---|
[1589] | 579 | bind $page.right <KeyPress-Return> [itcl::code $this ApplyLayoutSettings] |
---|
[1609] | 580 | Rappture::Tooltip::for $page.right \ |
---|
| 581 | "Set the size (inches) of the right margin. If zero, the size is automatically determined." |
---|
[1589] | 582 | |
---|
[1609] | 583 | |
---|
[1589] | 584 | label $page.top_l -text "top" |
---|
| 585 | entry $page.top -width 6 \ |
---|
[1929] | 586 | -textvariable [itcl::scope _settings($this-layout-topmargin)] |
---|
[1589] | 587 | bind $page.top <KeyPress-Return> [itcl::code $this ApplyLayoutSettings] |
---|
[1609] | 588 | Rappture::Tooltip::for $page.top \ |
---|
| 589 | "Set the size (inches) of the top margin. If zero, the size is automatically determined." |
---|
[1589] | 590 | |
---|
| 591 | label $page.bottom_l -text "bottom" |
---|
| 592 | entry $page.bottom -width 6 \ |
---|
[1929] | 593 | -textvariable [itcl::scope _settings($this-layout-bottommargin)] |
---|
[1589] | 594 | bind $page.bottom <KeyPress-Return> [itcl::code $this ApplyLayoutSettings] |
---|
[1609] | 595 | Rappture::Tooltip::for $page.bottom \ |
---|
| 596 | "Set the size (inches) of the bottom margin. If zero, the size is automatically determined." |
---|
[1589] | 597 | |
---|
[1621] | 598 | |
---|
| 599 | label $page.map -image [Rappture::icon graphmargins] |
---|
[1589] | 600 | blt::table $page \ |
---|
[1929] | 601 | 0,0 $page.width_l -anchor e \ |
---|
| 602 | 0,1 $page.width -fill x \ |
---|
| 603 | 1,0 $page.height_l -anchor e \ |
---|
| 604 | 1,1 $page.height -fill x \ |
---|
| 605 | 3,0 $page.left_l -anchor e \ |
---|
| 606 | 3,1 $page.left -fill x \ |
---|
| 607 | 4,0 $page.right_l -anchor e \ |
---|
| 608 | 4,1 $page.right -fill x \ |
---|
| 609 | 5,0 $page.top_l -anchor e \ |
---|
| 610 | 5,1 $page.top -fill x \ |
---|
| 611 | 6,0 $page.bottom_l -anchor e \ |
---|
| 612 | 6,1 $page.bottom -fill x \ |
---|
| 613 | 0,2 $page.map -fill both -rspan 7 -padx 2 |
---|
[1589] | 614 | |
---|
[1621] | 615 | blt::table configure $page c0 r* -resize none |
---|
| 616 | blt::table configure $page c1 r2 -resize both |
---|
[1589] | 617 | } |
---|
| 618 | |
---|
| 619 | |
---|
| 620 | itcl::body Rappture::XyPrint::BuildGeneralTab {} { |
---|
[1588] | 621 | itk_component add graph_page { |
---|
[1929] | 622 | frame $itk_component(tabs).graph_page |
---|
[1588] | 623 | } |
---|
| 624 | set page $itk_component(graph_page) |
---|
| 625 | $itk_component(tabs) insert end "graph" \ |
---|
| 626 | -text "General" -padx 2 -pady 2 -window $page -fill both |
---|
| 627 | |
---|
| 628 | label $page.format_l -text "format" |
---|
| 629 | Rappture::Combobox $page.format -width 30 -editable no |
---|
| 630 | $page.format choices insert end \ |
---|
[1929] | 631 | "pdf" "PDF Portable Document Format" \ |
---|
| 632 | "ps" "PS PostScript Format" \ |
---|
| 633 | "eps" "EPS Encapsulated PostScript" \ |
---|
| 634 | "jpg" "JPEG Joint Photographic Experts Group Format" \ |
---|
| 635 | "png" "PNG Portable Network Graphics Format" |
---|
[1588] | 636 | |
---|
[1589] | 637 | bind $page.format <<Value>> [itcl::code $this ApplyGeneralSettings] |
---|
[1609] | 638 | Rappture::Tooltip::for $page.format \ |
---|
| 639 | "Set the format of the image." |
---|
[1588] | 640 | |
---|
| 641 | label $page.style_l -text "style" |
---|
| 642 | Rappture::Combobox $page.style -width 20 -editable no |
---|
| 643 | $page.style choices insert end \ |
---|
[1929] | 644 | "ieee" "IEEE Journal" \ |
---|
| 645 | "gekco" "G Klimeck" |
---|
[1589] | 646 | bind $page.style <<Value>> [itcl::code $this ApplyGeneralSettings] |
---|
[1609] | 647 | Rappture::Tooltip::for $page.format \ |
---|
| 648 | "Set the style template." |
---|
[1588] | 649 | |
---|
| 650 | checkbutton $page.remember -text "remember settings" \ |
---|
[1929] | 651 | -variable [itcl::scope _settings($this-general-remember)] |
---|
[1609] | 652 | Rappture::Tooltip::for $page.remember \ |
---|
| 653 | "Remember the settings. They will be override the default settings." |
---|
[1588] | 654 | |
---|
[1785] | 655 | button $page.revert -text "revert" -image [Rappture::icon revert] \ |
---|
[1929] | 656 | -compound left -padx 3 -pady 1 -overrelief raised -relief flat \ |
---|
| 657 | -command [itcl::code $this ResetSettings] |
---|
[1785] | 658 | Rappture::Tooltip::for $page.revert \ |
---|
| 659 | "Revert to the default settings." |
---|
| 660 | |
---|
[1588] | 661 | blt::table $page \ |
---|
[1929] | 662 | 2,0 $page.format_l -anchor e \ |
---|
| 663 | 2,1 $page.format -fill x -cspan 2 \ |
---|
| 664 | 3,0 $page.style_l -anchor e \ |
---|
| 665 | 3,1 $page.style -fill x -cspan 2 \ |
---|
| 666 | 5,0 $page.remember -cspan 2 -anchor w \ |
---|
| 667 | 5,2 $page.revert -anchor e |
---|
[1601] | 668 | blt::table configure $page r* -resize none -pady { 0 2 } |
---|
[1588] | 669 | blt::table configure $page r4 -resize both |
---|
| 670 | |
---|
| 671 | } |
---|
| 672 | |
---|
[1589] | 673 | itcl::body Rappture::XyPrint::ApplyLegendSettings {} { |
---|
[1588] | 674 | set page $itk_component(legend_page) |
---|
| 675 | set _settings($this-legend-anchor) [$page.anchor current] |
---|
[1930] | 676 | if { $_clone != "" } { |
---|
| 677 | font configure $_fonts(legend) \ |
---|
| 678 | -family $_settings($this-legend-font-family) \ |
---|
| 679 | -size $_settings($this-legend-font-size) \ |
---|
| 680 | -weight $_settings($this-legend-font-weight) \ |
---|
| 681 | -slant $_settings($this-legend-font-slant) |
---|
| 682 | foreach option { -hide -position -anchor -borderwidth } { |
---|
| 683 | SetComponentOption legend $option |
---|
| 684 | } |
---|
| 685 | $_clone legend configure -font fixed -font $_fonts(legend) |
---|
[1588] | 686 | } |
---|
[1589] | 687 | ApplyElementSettings |
---|
[1588] | 688 | } |
---|
| 689 | |
---|
| 690 | itcl::body Rappture::XyPrint::BuildLegendTab {} { |
---|
| 691 | itk_component add legend_page { |
---|
[1929] | 692 | frame $itk_component(tabs).legend_page |
---|
[1588] | 693 | } |
---|
| 694 | set page $itk_component(legend_page) |
---|
| 695 | $itk_component(tabs) insert end "legend" \ |
---|
| 696 | -text "Legend" -padx 2 -pady 2 -window $page -fill both |
---|
| 697 | |
---|
| 698 | checkbutton $page.show -text "show legend" \ |
---|
[1929] | 699 | -offvalue 1 -onvalue 0 \ |
---|
| 700 | -variable [itcl::scope _settings($this-legend-hide)] \ |
---|
| 701 | -command [itcl::code $this ApplyLegendSettings] |
---|
[1609] | 702 | Rappture::Tooltip::for $page.show \ |
---|
| 703 | "Display the legend." |
---|
[1588] | 704 | |
---|
| 705 | label $page.position_l -text "position" |
---|
| 706 | Rappture::Combobox $page.position -width 15 -editable no |
---|
| 707 | $page.position choices insert end \ |
---|
[1929] | 708 | "leftmargin" "left margin" \ |
---|
| 709 | "rightmargin" "right margin" \ |
---|
| 710 | "bottommargin" "bottom margin" \ |
---|
| 711 | "topmargin" "top margin" \ |
---|
| 712 | "plotarea" "inside plot" |
---|
[1589] | 713 | bind $page.position <<Value>> [itcl::code $this ApplyLegendSettings] |
---|
[1609] | 714 | Rappture::Tooltip::for $page.position \ |
---|
| 715 | "Set the position of the legend. This option and the anchor determine the legend's location." |
---|
[1588] | 716 | |
---|
| 717 | Rappture::Combobox $page.anchor -width 10 -editable no |
---|
| 718 | $page.anchor choices insert end \ |
---|
[1929] | 719 | "nw" "northwest" \ |
---|
| 720 | "n" "north" \ |
---|
| 721 | "ne" "northeast" \ |
---|
| 722 | "sw" "southwest" \ |
---|
| 723 | "s" "south" \ |
---|
| 724 | "se" "southeast" \ |
---|
| 725 | "c" "center" \ |
---|
| 726 | "e" "east" \ |
---|
| 727 | "w" "west" |
---|
[1589] | 728 | bind $page.anchor <<Value>> [itcl::code $this ApplyLegendSettings] |
---|
[1609] | 729 | Rappture::Tooltip::for $page.anchor \ |
---|
| 730 | "Set the anchor of the legend. This option and the anchor determine the legend's location." |
---|
[1588] | 731 | |
---|
| 732 | checkbutton $page.border -text "border" \ |
---|
[1929] | 733 | -variable [itcl::scope _settings($this-legend-borderwidth)] \ |
---|
| 734 | -onvalue 1 -offvalue 0 \ |
---|
| 735 | -command [itcl::code $this ApplyLegendSettings] |
---|
[1609] | 736 | Rappture::Tooltip::for $page.border \ |
---|
| 737 | "Display a solid border around the legend." |
---|
[1588] | 738 | |
---|
[1785] | 739 | label $page.slider_l -text "legend\nentry" -justify right |
---|
[1588] | 740 | itk_component add element_slider { |
---|
[1929] | 741 | ::scale $page.slider -from 1 -to 1 \ |
---|
| 742 | -orient horizontal -width 12 \ |
---|
| 743 | -command [itcl::code $this GetElement] |
---|
[1588] | 744 | } |
---|
[1609] | 745 | Rappture::Tooltip::for $page.slider \ |
---|
| 746 | "Select the current entry." |
---|
[1588] | 747 | |
---|
[1785] | 748 | label $page.label_l -text "label" |
---|
[1588] | 749 | entry $page.label \ |
---|
[1929] | 750 | -background white \ |
---|
| 751 | -textvariable [itcl::scope _settings($this-element-label)] |
---|
[1589] | 752 | bind $page.label <KeyPress-Return> [itcl::code $this ApplyElementSettings] |
---|
[1609] | 753 | Rappture::Tooltip::for $page.label \ |
---|
| 754 | "Set the label of the current entry in the legend." |
---|
[1588] | 755 | |
---|
[1785] | 756 | label $page.color_l -text "color " |
---|
[1588] | 757 | Rappture::Combobox $page.color -width 15 -editable no |
---|
| 758 | $page.color choices insert end \ |
---|
[1929] | 759 | "#000000" "black" \ |
---|
| 760 | "#ffffff" "white" \ |
---|
| 761 | "#0000cd" "blue" \ |
---|
| 762 | "#cd0000" "red" \ |
---|
| 763 | "#00cd00" "green" \ |
---|
| 764 | "#3a5fcd" "royal blue" \ |
---|
[1588] | 765 | "#cdcd00" "yellow" \ |
---|
| 766 | "#cd1076" "deep pink" \ |
---|
| 767 | "#009acd" "deep sky blue" \ |
---|
[1929] | 768 | "#00c5cd" "torquise" \ |
---|
[1588] | 769 | "#a2b5cd" "light steel blue" \ |
---|
[1929] | 770 | "#7ac5cd" "cadet blue" \ |
---|
| 771 | "#66cdaa" "aquamarine" \ |
---|
| 772 | "#a2cd5a" "dark olive green" \ |
---|
[1607] | 773 | "#cd9b9b" "rosy brown" \ |
---|
[1929] | 774 | "#0000ff" "blue1" \ |
---|
| 775 | "#ff0000" "red1" \ |
---|
| 776 | "#00ff00" "green1" |
---|
[1589] | 777 | bind $page.color <<Value>> [itcl::code $this ApplyElementSettings] |
---|
[1609] | 778 | Rappture::Tooltip::for $page.color \ |
---|
| 779 | "Set the color of the current entry." |
---|
[1588] | 780 | |
---|
[1785] | 781 | label $page.dashes_l -text "line style" |
---|
[1588] | 782 | Rappture::Combobox $page.dashes -width 15 -editable no |
---|
| 783 | $page.dashes choices insert end \ |
---|
[1929] | 784 | "" "solid" \ |
---|
[1588] | 785 | "1" "dot" \ |
---|
| 786 | "5 2" "dash" \ |
---|
| 787 | "2 4 2" "dashdot" \ |
---|
| 788 | "2 4 2 2" "dashdotdot" |
---|
[1589] | 789 | bind $page.dashes <<Value>> [itcl::code $this ApplyElementSettings] |
---|
[1609] | 790 | Rappture::Tooltip::for $page.dashes \ |
---|
| 791 | "Set the line style of the current entry." |
---|
[1588] | 792 | |
---|
[1785] | 793 | label $page.symbol_l -text "symbol" |
---|
[1588] | 794 | Rappture::Combobox $page.symbol -editable no |
---|
| 795 | $page.symbol choices insert end \ |
---|
[1929] | 796 | "none" "none" \ |
---|
| 797 | "square" "square" \ |
---|
| 798 | "circle" "circle" \ |
---|
| 799 | "diamond" "diamond" \ |
---|
| 800 | "plus" "plus" \ |
---|
| 801 | "cross" "cross" \ |
---|
| 802 | "splus" "skinny plus" \ |
---|
| 803 | "scross" "skinny cross" \ |
---|
| 804 | "triangle" "triangle" |
---|
[1589] | 805 | bind $page.symbol <<Value>> [itcl::code $this ApplyElementSettings] |
---|
[1609] | 806 | Rappture::Tooltip::for $page.symbol \ |
---|
| 807 | "Set the symbol of the current entry. \"none\" display no symbols." |
---|
[1588] | 808 | |
---|
[1599] | 809 | label $page.font_l -text "font" |
---|
| 810 | Rappture::Combobox $page.fontfamily -width 10 -editable no |
---|
| 811 | $page.fontfamily choices insert end \ |
---|
[1929] | 812 | "courier" "courier" \ |
---|
| 813 | "helvetica" "helvetica" \ |
---|
| 814 | "new*century*schoolbook" "new century schoolbook" \ |
---|
| 815 | "symbol" "symbol" \ |
---|
| 816 | "times" "times" |
---|
[1601] | 817 | bind $page.fontfamily <<Value>> [itcl::code $this ApplyLegendSettings] |
---|
[1609] | 818 | Rappture::Tooltip::for $page.fontfamily \ |
---|
| 819 | "Set the font of entries in the legend." |
---|
[1599] | 820 | |
---|
| 821 | Rappture::Combobox $page.fontsize -width 4 -editable no |
---|
| 822 | $page.fontsize choices insert end \ |
---|
[1929] | 823 | "8" "8" \ |
---|
| 824 | "9" "9" \ |
---|
| 825 | "10" "10" \ |
---|
| 826 | "11" "11" \ |
---|
| 827 | "12" "12" \ |
---|
| 828 | "14" "14" \ |
---|
| 829 | "17" "17" \ |
---|
| 830 | "18" "18" \ |
---|
| 831 | "20" "20" |
---|
[1601] | 832 | bind $page.fontsize <<Value>> [itcl::code $this ApplyLegendSettings] |
---|
[1609] | 833 | Rappture::Tooltip::for $page.fontsize \ |
---|
| 834 | "Set the size (points) of the font." |
---|
[1599] | 835 | |
---|
[1604] | 836 | Rappture::PushButton $page.fontweight \ |
---|
[1929] | 837 | -width 18 -height 18 \ |
---|
| 838 | -onimage [Rappture::icon font-bold] \ |
---|
| 839 | -offimage [Rappture::icon font-bold] \ |
---|
| 840 | -onvalue "bold" -offvalue "normal" \ |
---|
| 841 | -command [itcl::code $this ApplyLegendSettings] \ |
---|
| 842 | -variable [itcl::scope _settings($this-legend-font-weight)] |
---|
[1609] | 843 | Rappture::Tooltip::for $page.fontweight \ |
---|
| 844 | "Use the bold version of the font." |
---|
[1599] | 845 | |
---|
[1604] | 846 | Rappture::PushButton $page.fontslant \ |
---|
[1929] | 847 | -width 18 -height 18 \ |
---|
| 848 | -onimage [Rappture::icon font-italic] \ |
---|
| 849 | -offimage [Rappture::icon font-italic] \ |
---|
| 850 | -onvalue "italic" -offvalue "roman" \ |
---|
| 851 | -command [itcl::code $this ApplyLegendSettings] \ |
---|
| 852 | -variable [itcl::scope _settings($this-legend-font-slant)] |
---|
[1609] | 853 | Rappture::Tooltip::for $page.fontslant \ |
---|
| 854 | "Use the italic version of the font." |
---|
[1599] | 855 | |
---|
[1588] | 856 | blt::table $page \ |
---|
[1929] | 857 | 1,0 $page.show -cspan 2 -anchor w \ |
---|
| 858 | 1,2 $page.border -cspan 2 -anchor w \ |
---|
| 859 | 2,0 $page.position_l -anchor e \ |
---|
| 860 | 2,1 $page.position -fill x \ |
---|
| 861 | 2,2 $page.anchor -fill x -cspan 3 \ |
---|
| 862 | 3,0 $page.font_l -anchor e \ |
---|
| 863 | 3,1 $page.fontfamily -fill x \ |
---|
| 864 | 3,2 $page.fontsize -fill x \ |
---|
| 865 | 3,3 $page.fontweight -anchor e \ |
---|
| 866 | 3,4 $page.fontslant -anchor e \ |
---|
| 867 | 4,0 $page.slider_l -anchor e \ |
---|
| 868 | 4,1 $page.slider -fill x -cspan 5 \ |
---|
| 869 | 5,0 $page.label_l -anchor e \ |
---|
| 870 | 5,1 $page.label -fill x -cspan 5 \ |
---|
| 871 | 6,0 $page.color_l -anchor e \ |
---|
| 872 | 6,1 $page.color -fill x \ |
---|
| 873 | 6,2 $page.symbol_l -anchor e \ |
---|
| 874 | 6,3 $page.symbol -fill both -cspan 3 \ |
---|
| 875 | 7,0 $page.dashes_l -anchor e \ |
---|
| 876 | 7,1 $page.dashes -fill x \ |
---|
[1588] | 877 | |
---|
[1601] | 878 | blt::table configure $page r* -resize none -pady { 0 2 } |
---|
[1588] | 879 | blt::table configure $page r8 -resize both |
---|
| 880 | |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | itcl::body Rappture::XyPrint::BuildAxisTab {} { |
---|
| 884 | itk_component add axis_page { |
---|
[1929] | 885 | frame $itk_component(tabs).axis_page |
---|
[1588] | 886 | } |
---|
| 887 | set page $itk_component(axis_page) |
---|
| 888 | $itk_component(tabs) insert end "axis" \ |
---|
| 889 | -text "Axis" -padx 2 -pady 2 -window $page -fill both |
---|
| 890 | |
---|
[1785] | 891 | label $page.axis_l -text "axis" |
---|
[1588] | 892 | itk_component add axis_combo { |
---|
[1929] | 893 | Rappture::Combobox $page.axis -width 20 -editable no |
---|
[1588] | 894 | } |
---|
| 895 | bind $itk_component(axis_combo) <<Value>> [itcl::code $this GetAxis] |
---|
[1609] | 896 | Rappture::Tooltip::for $page.axis \ |
---|
| 897 | "Select the current axis." |
---|
[1588] | 898 | |
---|
[1785] | 899 | label $page.title_l -text "title" |
---|
[1588] | 900 | entry $page.title \ |
---|
[1929] | 901 | -textvariable [itcl::scope _settings($this-axis-title)] |
---|
[1589] | 902 | bind $page.title <KeyPress-Return> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 903 | Rappture::Tooltip::for $page.title \ |
---|
| 904 | "Set the title of the current axis." |
---|
[1588] | 905 | |
---|
[1785] | 906 | label $page.min_l -text "min" |
---|
[1588] | 907 | entry $page.min -width 10 \ |
---|
[1929] | 908 | -textvariable [itcl::scope _settings($this-axis-min)] |
---|
[1589] | 909 | bind $page.min <KeyPress-Return> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 910 | Rappture::Tooltip::for $page.min \ |
---|
| 911 | "Set the minimum limit for the current axis. If empty, the minimum is automatically determined." |
---|
[1588] | 912 | |
---|
[1785] | 913 | label $page.max_l -text "max" |
---|
[1588] | 914 | entry $page.max -width 10 \ |
---|
[1929] | 915 | -textvariable [itcl::scope _settings($this-axis-max)] |
---|
[1589] | 916 | bind $page.max <KeyPress-Return> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 917 | Rappture::Tooltip::for $page.max \ |
---|
| 918 | "Set the maximum limit for the current axis. If empty, the maximum is automatically determined." |
---|
[1588] | 919 | |
---|
[1785] | 920 | label $page.subdivisions_l -text "subdivisions" |
---|
[1588] | 921 | entry $page.subdivisions \ |
---|
[1929] | 922 | -textvariable [itcl::scope _settings($this-axis-subdivisions)] |
---|
[1589] | 923 | bind $page.subdivisions <KeyPress-Return> \ |
---|
[1929] | 924 | [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 925 | Rappture::Tooltip::for $page.subdivisions \ |
---|
| 926 | "Set the number of subdivisions (minor ticks) for the current axis." |
---|
[1588] | 927 | |
---|
[1785] | 928 | label $page.stepsize_l -text "step size" |
---|
[1588] | 929 | entry $page.stepsize \ |
---|
[1929] | 930 | -textvariable [itcl::scope _settings($this-axis-stepsize)] |
---|
[1589] | 931 | bind $page.stepsize <KeyPress-Return> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 932 | Rappture::Tooltip::for $page.stepsize \ |
---|
| 933 | "Set the interval between major ticks for the current axis. If zero, the interval is automatically determined." |
---|
[1588] | 934 | |
---|
| 935 | checkbutton $page.loose -text "loose limits" \ |
---|
[1929] | 936 | -onvalue "always" -offvalue "0" \ |
---|
| 937 | -variable [itcl::scope _settings($this-axis-loose)] \ |
---|
| 938 | -command [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 939 | Rappture::Tooltip::for $page.loose \ |
---|
| 940 | "Set major ticks outside of the limits for the current axis." |
---|
[1588] | 941 | |
---|
[1599] | 942 | label $page.plotpad_l -text "pad" |
---|
| 943 | entry $page.plotpad -width 6 \ |
---|
[1929] | 944 | -textvariable [itcl::scope _settings($this-axis-plotpad)] |
---|
[1599] | 945 | bind $page.plotpad <KeyPress-Return> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 946 | Rappture::Tooltip::for $page.plotpad \ |
---|
| 947 | "Set padding (points) between the current axis and the plot." |
---|
[1588] | 948 | |
---|
| 949 | checkbutton $page.grid -text "show grid lines" \ |
---|
[1929] | 950 | -variable [itcl::scope _settings($this-axis-grid)] \ |
---|
| 951 | -command [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 952 | Rappture::Tooltip::for $page.grid \ |
---|
| 953 | "Display grid lines for the current axis." |
---|
[1588] | 954 | |
---|
| 955 | checkbutton $page.zero -text "mark zero" \ |
---|
[1929] | 956 | -offvalue 1 -onvalue 0 \ |
---|
| 957 | -variable [itcl::scope _settings($this-axis-zero)] \ |
---|
| 958 | -command [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 959 | Rappture::Tooltip::for $page.zero \ |
---|
| 960 | "Display a line at zero for the current axis." |
---|
[1588] | 961 | |
---|
[1598] | 962 | label $page.tickfont_l -text "tick font" |
---|
| 963 | Rappture::Combobox $page.tickfontfamily -width 10 -editable no |
---|
| 964 | $page.tickfontfamily choices insert end \ |
---|
[1929] | 965 | "courier" "courier" \ |
---|
| 966 | "helvetica" "helvetica" \ |
---|
| 967 | "new*century*schoolbook" "new century schoolbook" \ |
---|
| 968 | "symbol" "symbol" \ |
---|
| 969 | "times" "times" |
---|
[1601] | 970 | bind $page.tickfontfamily <<Value>> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 971 | Rappture::Tooltip::for $page.tickfontfamily \ |
---|
| 972 | "Set the font of the ticks for the current axis." |
---|
[1598] | 973 | |
---|
| 974 | Rappture::Combobox $page.tickfontsize -width 4 -editable no |
---|
| 975 | $page.tickfontsize choices insert end \ |
---|
[1929] | 976 | "8" "8" \ |
---|
| 977 | "9" "9" \ |
---|
| 978 | "10" "10" \ |
---|
| 979 | "11" "11" \ |
---|
| 980 | "12" "12" \ |
---|
| 981 | "14" "14" \ |
---|
| 982 | "17" "17" \ |
---|
| 983 | "18" "18" \ |
---|
| 984 | "20" "20" |
---|
[1601] | 985 | bind $page.tickfontsize <<Value>> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 986 | Rappture::Tooltip::for $page.tickfontsize \ |
---|
| 987 | "Set the size (points) of the tick font." |
---|
[1598] | 988 | |
---|
[1604] | 989 | Rappture::PushButton $page.tickfontweight \ |
---|
[1929] | 990 | -width 18 -height 18 \ |
---|
| 991 | -onimage [Rappture::icon font-bold] \ |
---|
| 992 | -offimage [Rappture::icon font-bold] \ |
---|
| 993 | -onvalue "bold" -offvalue "normal" \ |
---|
| 994 | -command [itcl::code $this ApplyAxisSettings] \ |
---|
| 995 | -variable [itcl::scope _settings($this-axis-tickfont-weight)] |
---|
[1609] | 996 | Rappture::Tooltip::for $page.tickfontweight \ |
---|
| 997 | "Use the bold version of the tick font." |
---|
[1598] | 998 | |
---|
[1604] | 999 | Rappture::PushButton $page.tickfontslant \ |
---|
[1929] | 1000 | -width 18 -height 18 \ |
---|
| 1001 | -onimage [Rappture::icon font-italic] \ |
---|
| 1002 | -offimage [Rappture::icon font-italic] \ |
---|
| 1003 | -onvalue "italic" -offvalue "roman" \ |
---|
| 1004 | -command [itcl::code $this ApplyAxisSettings] \ |
---|
| 1005 | -variable [itcl::scope _settings($this-axis-tickfont-slant)] |
---|
[1609] | 1006 | Rappture::Tooltip::for $page.tickfontslant \ |
---|
| 1007 | "Use the italic version of the tick font." |
---|
[1598] | 1008 | |
---|
[1599] | 1009 | label $page.titlefont_l -text "title font" |
---|
| 1010 | Rappture::Combobox $page.titlefontfamily -width 10 -editable no |
---|
| 1011 | $page.titlefontfamily choices insert end \ |
---|
[1929] | 1012 | "courier" "courier" \ |
---|
| 1013 | "helvetica" "helvetica" \ |
---|
| 1014 | "new*century*schoolbook" "new century schoolbook" \ |
---|
| 1015 | "symbol" "symbol" \ |
---|
| 1016 | "times" "times" |
---|
[1601] | 1017 | bind $page.titlefontfamily <<Value>> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 1018 | Rappture::Tooltip::for $page.titlefontfamily \ |
---|
| 1019 | "Set the font of the title for the current axis." |
---|
[1599] | 1020 | |
---|
| 1021 | Rappture::Combobox $page.titlefontsize -width 4 -editable no |
---|
| 1022 | $page.titlefontsize choices insert end \ |
---|
[1929] | 1023 | "8" "8" \ |
---|
| 1024 | "9" "9" \ |
---|
| 1025 | "10" "10" \ |
---|
| 1026 | "11" "11" \ |
---|
| 1027 | "12" "12" \ |
---|
| 1028 | "14" "14" \ |
---|
| 1029 | "17" "17" \ |
---|
| 1030 | "18" "18" \ |
---|
| 1031 | "20" "20" |
---|
[1647] | 1032 | bind $page.titlefontsize <<Value>> [itcl::code $this ApplyAxisSettings] |
---|
[1609] | 1033 | Rappture::Tooltip::for $page.titlefontsize \ |
---|
| 1034 | "Set the size (point) of the title font." |
---|
[1599] | 1035 | |
---|
[1604] | 1036 | Rappture::PushButton $page.titlefontweight \ |
---|
[1929] | 1037 | -width 18 -height 18 \ |
---|
| 1038 | -onimage [Rappture::icon font-bold] \ |
---|
| 1039 | -offimage [Rappture::icon font-bold] \ |
---|
| 1040 | -onvalue "bold" -offvalue "normal" \ |
---|
| 1041 | -command [itcl::code $this ApplyAxisSettings] \ |
---|
| 1042 | -variable [itcl::scope _settings($this-axis-titlefont-weight)] |
---|
[1609] | 1043 | Rappture::Tooltip::for $page.titlefontweight \ |
---|
| 1044 | "Use the bold version of the title font." |
---|
[1599] | 1045 | |
---|
[1604] | 1046 | Rappture::PushButton $page.titlefontslant \ |
---|
[1929] | 1047 | -width 18 -height 18 \ |
---|
| 1048 | -onimage [Rappture::icon font-italic] \ |
---|
| 1049 | -offimage [Rappture::icon font-italic] \ |
---|
| 1050 | -onvalue "italic" -offvalue "roman" \ |
---|
| 1051 | -command [itcl::code $this ApplyAxisSettings] \ |
---|
| 1052 | -variable [itcl::scope _settings($this-axis-titlefont-slant)] |
---|
[1609] | 1053 | Rappture::Tooltip::for $page.titlefontslant \ |
---|
| 1054 | "Use the italic version of the title font." |
---|
[1599] | 1055 | |
---|
[1588] | 1056 | blt::table $page \ |
---|
[1929] | 1057 | 1,1 $page.axis_l -anchor e -pady 6 \ |
---|
| 1058 | 1,2 $page.axis -fill x -cspan 6 \ |
---|
| 1059 | 2,1 $page.title_l -anchor e \ |
---|
| 1060 | 2,2 $page.title -fill x -cspan 5 \ |
---|
| 1061 | 3,1 $page.min_l -anchor e \ |
---|
| 1062 | 3,2 $page.min -fill x \ |
---|
| 1063 | 3,3 $page.stepsize_l -anchor e \ |
---|
| 1064 | 3,4 $page.stepsize -fill both -cspan 3 \ |
---|
| 1065 | 4,1 $page.max_l -anchor e \ |
---|
| 1066 | 4,2 $page.max -fill both \ |
---|
| 1067 | 4,3 $page.subdivisions_l -anchor e \ |
---|
| 1068 | 4,4 $page.subdivisions -fill both -cspan 3 \ |
---|
| 1069 | 5,1 $page.titlefont_l -anchor e \ |
---|
| 1070 | 5,2 $page.titlefontfamily -fill x -cspan 2 \ |
---|
| 1071 | 5,4 $page.titlefontsize -fill x \ |
---|
| 1072 | 5,5 $page.titlefontweight -anchor e \ |
---|
| 1073 | 5,6 $page.titlefontslant -anchor e \ |
---|
| 1074 | 6,1 $page.tickfont_l -anchor e \ |
---|
| 1075 | 6,2 $page.tickfontfamily -fill x -cspan 2 \ |
---|
| 1076 | 6,4 $page.tickfontsize -fill x \ |
---|
| 1077 | 6,5 $page.tickfontweight -anchor e \ |
---|
| 1078 | 6,6 $page.tickfontslant -anchor e \ |
---|
| 1079 | 7,1 $page.loose -cspan 2 -anchor w \ |
---|
| 1080 | 7,3 $page.grid -anchor w -cspan 2 \ |
---|
| 1081 | 8,1 $page.zero -cspan 2 -anchor w \ |
---|
| 1082 | 8,3 $page.plotpad_l -anchor e \ |
---|
| 1083 | 8,4 $page.plotpad -fill both -cspan 3 |
---|
[1785] | 1084 | |
---|
| 1085 | blt::table configure $page c0 c7 c8 -resize none |
---|
[1588] | 1086 | } |
---|
| 1087 | |
---|
[1589] | 1088 | itcl::body Rappture::XyPrint::ApplyGeneralSettings {} { |
---|
| 1089 | RegeneratePreview |
---|
| 1090 | } |
---|
| 1091 | |
---|
| 1092 | itcl::body Rappture::XyPrint::ApplyLegendSettings {} { |
---|
| 1093 | set page $itk_component(legend_page) |
---|
| 1094 | set _settings($this-legend-position) [$page.position current] |
---|
| 1095 | set _settings($this-legend-anchor) [$page.anchor current] |
---|
| 1096 | |
---|
[1788] | 1097 | foreach option { -hide -position -anchor -borderwidth } { |
---|
[1929] | 1098 | SetComponentOption legend $option |
---|
[1588] | 1099 | } |
---|
[1601] | 1100 | font configure $_fonts(legend) \ |
---|
[1929] | 1101 | -family [$page.fontfamily current] \ |
---|
| 1102 | -size [$page.fontsize current] \ |
---|
| 1103 | -weight $_settings($this-legend-font-weight) \ |
---|
| 1104 | -slant $_settings($this-legend-font-slant) |
---|
[1717] | 1105 | $_clone legend configure -font fixed -font $_fonts(legend) |
---|
[1589] | 1106 | ApplyElementSettings |
---|
[1588] | 1107 | } |
---|
| 1108 | |
---|
[1589] | 1109 | itcl::body Rappture::XyPrint::ApplyAxisSettings {} { |
---|
| 1110 | set axis [$itk_component(axis_combo) current] |
---|
[1636] | 1111 | set type [GetAxisType $axis] |
---|
[1601] | 1112 | set page $itk_component(axis_page) |
---|
[1589] | 1113 | if { $_settings($this-axis-grid) } { |
---|
[1929] | 1114 | $_clone grid configure -hide no -map${type} ${axis} |
---|
[1589] | 1115 | } else { |
---|
[1929] | 1116 | $_clone grid configure -hide no -map${type} "" |
---|
[1589] | 1117 | } |
---|
[1599] | 1118 | $_clone configure -plotpad${type} $_settings($this-axis-plotpad) |
---|
[1785] | 1119 | foreach option { -min -max -loose -title -stepsize -subdivisions } { |
---|
[1929] | 1120 | SetNamedComponentOption axis $axis $option |
---|
[1589] | 1121 | } |
---|
| 1122 | $_clone marker configure ${type}-zero -hide $_settings($this-axis-zero) |
---|
[1604] | 1123 | font configure $axis-title \ |
---|
[1929] | 1124 | -family [$page.titlefontfamily current] \ |
---|
| 1125 | -size [$page.titlefontsize current] \ |
---|
| 1126 | -weight $_settings($this-axis-titlefont-weight) \ |
---|
| 1127 | -slant $_settings($this-axis-titlefont-slant) |
---|
[1604] | 1128 | font configure $axis-ticks \ |
---|
[1929] | 1129 | -family [$page.tickfontfamily current] \ |
---|
| 1130 | -size [$page.tickfontsize current] \ |
---|
| 1131 | -weight $_settings($this-axis-tickfont-weight) \ |
---|
| 1132 | -slant $_settings($this-axis-tickfont-slant) |
---|
[1604] | 1133 | $_clone axis configure $axis -tickfont $axis-ticks -titlefont $axis-title |
---|
[1589] | 1134 | GetAxis |
---|
| 1135 | RegeneratePreview |
---|
| 1136 | } |
---|
| 1137 | |
---|
| 1138 | itcl::body Rappture::XyPrint::ApplyElementSettings {} { |
---|
[1588] | 1139 | set index [$itk_component(element_slider) get] |
---|
| 1140 | set page $itk_component(legend_page) |
---|
| 1141 | set _settings($this-element-color) [$page.color current] |
---|
[1930] | 1142 | if { $_clone != "" } { |
---|
| 1143 | set elem $_settings($this-element-$index) |
---|
| 1144 | if { [$_clone element type $elem] != "bar" } { |
---|
| 1145 | set _settings($this-element-symbol) [$page.symbol current] |
---|
| 1146 | set _settings($this-element-dashes) [$page.dashes current] |
---|
| 1147 | foreach option { -symbol -dashes } { |
---|
| 1148 | SetNamedComponentOption element $elem $option |
---|
| 1149 | } |
---|
| 1150 | } |
---|
| 1151 | foreach option { -color -label } { |
---|
| 1152 | SetNamedComponentOption element $elem $option |
---|
| 1153 | } |
---|
| 1154 | RegeneratePreview |
---|
[1588] | 1155 | } |
---|
| 1156 | } |
---|
| 1157 | |
---|
[1636] | 1158 | itcl::body Rappture::XyPrint::SetLayoutOption { opt } { |
---|
[1785] | 1159 | set new [Inches2Pixels $_settings($this-layout$opt)] |
---|
| 1160 | $_clone configure $opt $new |
---|
[1636] | 1161 | } |
---|
| 1162 | |
---|
[1589] | 1163 | itcl::body Rappture::XyPrint::ApplyLayoutSettings {} { |
---|
[1785] | 1164 | foreach opt { -width -height -leftmargin -rightmargin -topmargin |
---|
[1929] | 1165 | -bottommargin } { |
---|
| 1166 | set old [$_clone cget $opt] |
---|
| 1167 | set code [catch { SetLayoutOption $opt } err] |
---|
| 1168 | if { $code != 0 } { |
---|
| 1169 | bell |
---|
| 1170 | global errorInfo |
---|
| 1171 | puts stderr "$err: $errorInfo" |
---|
| 1172 | set _settings($this-layout$opt) [Pixels2Inches $old] |
---|
| 1173 | $_clone configure $opt [Pixels2Inches $old] |
---|
| 1174 | } |
---|
[1588] | 1175 | } |
---|
| 1176 | RegeneratePreview |
---|
| 1177 | } |
---|
| 1178 | |
---|
| 1179 | |
---|
[1589] | 1180 | itcl::body Rappture::XyPrint::InitializeSettings {} { |
---|
| 1181 | # General settings |
---|
[1588] | 1182 | |
---|
[1616] | 1183 | # Always set to "ps" "ieee" |
---|
| 1184 | set _settings($this-general-format) ps |
---|
[1589] | 1185 | set _settings($this-general-style) ieee |
---|
[1636] | 1186 | set _settings($this-general-remember) 0 |
---|
[1589] | 1187 | set page $itk_component(graph_page) |
---|
[1588] | 1188 | |
---|
[1589] | 1189 | # Layout settings |
---|
[1588] | 1190 | set _settings($this-layout-width) [Pixels2Inches [$_clone cget -width]] |
---|
| 1191 | set _settings($this-layout-height) [Pixels2Inches [$_clone cget -height]] |
---|
| 1192 | set _settings($this-layout-leftmargin) \ |
---|
[1929] | 1193 | [Pixels2Inches [$_clone cget -leftmargin]] |
---|
[1588] | 1194 | set _settings($this-layout-rightmargin) \ |
---|
[1929] | 1195 | [Pixels2Inches [$_clone cget -rightmargin]] |
---|
[1588] | 1196 | set _settings($this-layout-topmargin) \ |
---|
[1929] | 1197 | [Pixels2Inches [$_clone cget -topmargin]] |
---|
[1588] | 1198 | set _settings($this-layout-bottommargin) \ |
---|
[1929] | 1199 | [Pixels2Inches [$_clone cget -bottommargin]] |
---|
[1589] | 1200 | |
---|
| 1201 | # Legend settings |
---|
| 1202 | set page $itk_component(legend_page) |
---|
| 1203 | |
---|
| 1204 | set names [$_clone element show] |
---|
| 1205 | $itk_component(element_slider) configure -from 1 -to [llength $names] |
---|
[1593] | 1206 | set state [expr { ([llength $names] < 2) ? "disabled" : "normal" } ] |
---|
| 1207 | $page.slider configure -state $state |
---|
| 1208 | $page.slider_l configure -state $state |
---|
[1589] | 1209 | # Always initialize the slider to the first entry in the element list. |
---|
| 1210 | $itk_component(element_slider) set 1 |
---|
| 1211 | # Always set the borderwidth to be not displayed |
---|
| 1212 | set _settings($this-legend-borderwidth) 0 |
---|
| 1213 | |
---|
[1604] | 1214 | array unset info |
---|
| 1215 | array set info [font configure legend] |
---|
| 1216 | $page.fontfamily value $info(-family) |
---|
| 1217 | $page.fontsize value $info(-size) |
---|
| 1218 | set _settings($this-legend-font-weight) $info(-weight) |
---|
| 1219 | set _settings($this-legend-font-slant) $info(-slant) |
---|
| 1220 | if { $info(-weight) == "bold" } { |
---|
[1929] | 1221 | set _settings($this-legend-font-bold) 1 |
---|
[1604] | 1222 | } |
---|
[1589] | 1223 | set _settings($this-legend-hide) [$_clone legend cget -hide] |
---|
| 1224 | set _settings($this-legend-position) [$_clone legend cget -position] |
---|
| 1225 | set _settings($this-legend-anchor) [$_clone legend cget -anchor] |
---|
| 1226 | $page.position value \ |
---|
[1929] | 1227 | [$page.position label $_settings($this-legend-position)] |
---|
[1589] | 1228 | $page.anchor value [$page.anchor label $_settings($this-legend-anchor)] |
---|
| 1229 | GetElement |
---|
| 1230 | |
---|
| 1231 | # Axis settings |
---|
[1601] | 1232 | set page $itk_component(axis_page) |
---|
[1589] | 1233 | set names [lsort [$_clone axis names]] |
---|
| 1234 | $itk_component(axis_combo) choices delete 0 end |
---|
| 1235 | foreach axis $names { |
---|
[1929] | 1236 | if { ![$_clone axis cget $axis -hide] } { |
---|
| 1237 | $itk_component(axis_combo) choices insert end $axis $axis |
---|
| 1238 | } |
---|
| 1239 | lappend axisnames $axis |
---|
[1589] | 1240 | } |
---|
[1604] | 1241 | set axis [lindex $names 0] |
---|
| 1242 | |
---|
| 1243 | array set info [font configure $axis-title] |
---|
| 1244 | $page.titlefontfamily value $info(-family) |
---|
| 1245 | $page.titlefontsize value $info(-size) |
---|
| 1246 | set _settings($this-axis-titlefont-weight) $info(-weight) |
---|
| 1247 | set _settings($this-axis-titlefont-slant) $info(-slant) |
---|
| 1248 | |
---|
| 1249 | array set info [font configure $axis-ticks] |
---|
| 1250 | $page.tickfontfamily value $info(-family) |
---|
| 1251 | $page.tickfontsize value $info(-size) |
---|
| 1252 | set _settings($this-axis-tickfont-weight) $info(-weight) |
---|
| 1253 | set _settings($this-axis-tickfont-slant) $info(-slant) |
---|
| 1254 | |
---|
[1589] | 1255 | # Always hide the zero line. |
---|
| 1256 | set _settings($this-axis-zero) 1 |
---|
[1601] | 1257 | set _settings($this-axis-plotpad) [Pixels2Inches [$_clone cget -plotpadx]] |
---|
[1589] | 1258 | # Pick the first axis to initially display |
---|
| 1259 | set axis [lindex $axisnames 0] |
---|
| 1260 | $itk_component(axis_combo) value $axis |
---|
| 1261 | GetAxis |
---|
[1588] | 1262 | } |
---|
| 1263 | |
---|
[1589] | 1264 | |
---|
[1598] | 1265 | itcl::body Rappture::XyPrint::restore { toolName plotName data } { |
---|
| 1266 | set key [list $toolName $plotName] |
---|
| 1267 | set _savedSettings($key) $data |
---|
| 1268 | } |
---|
[1590] | 1269 | |
---|
[1598] | 1270 | itcl::body Rappture::XyPrint::RestoreSettings { toolName plotName } { |
---|
[1607] | 1271 | if { ![file readable $_settingsFile] } { |
---|
[1929] | 1272 | return; # No file or not readable |
---|
[1636] | 1273 | } |
---|
| 1274 | if { [file exists $_oldSettingsFile] } { |
---|
[1929] | 1275 | file delete $_oldSettingsFile |
---|
[1598] | 1276 | } |
---|
| 1277 | # Read the file by sourcing it into a safe interpreter The only commands |
---|
| 1278 | # executed will be "xyprint" which will simply add the data into an array |
---|
| 1279 | # _savedSettings. |
---|
| 1280 | set parser [interp create -safe] |
---|
| 1281 | $parser alias xyprint [itcl::code $this restore] |
---|
[1604] | 1282 | $parser alias font font |
---|
[1607] | 1283 | set f [open $_settingsFile "r"] |
---|
[1598] | 1284 | set code [read $f] |
---|
| 1285 | close $f |
---|
| 1286 | $parser eval $code |
---|
| 1287 | |
---|
| 1288 | # Now see if there's an entry for this tool/plot combination. The data |
---|
| 1289 | # associated with the variable is itself code to update the graph (clone). |
---|
| 1290 | set key [list $toolName $plotName] |
---|
| 1291 | if { [info exists _savedSettings($key)] } { |
---|
[1929] | 1292 | $parser alias "preview" $_clone |
---|
| 1293 | $parser eval $_savedSettings($key) |
---|
[1598] | 1294 | } |
---|
| 1295 | foreach {name value} [$parser eval "array get general"] { |
---|
[1929] | 1296 | set _settings($this-graph-$name) $value |
---|
[1598] | 1297 | } |
---|
| 1298 | interp delete $parser |
---|
| 1299 | } |
---|
| 1300 | |
---|
[1593] | 1301 | itcl::body Rappture::XyPrint::ResetSettings {} { |
---|
[1785] | 1302 | set graph $_graph |
---|
| 1303 | DestroySettings |
---|
| 1304 | set _graph $graph |
---|
| 1305 | CloneGraph $graph |
---|
[1590] | 1306 | InitClone |
---|
| 1307 | InitializeSettings |
---|
[1589] | 1308 | } |
---|
| 1309 | |
---|
[1598] | 1310 | itcl::body Rappture::XyPrint::SaveSettings { toolName plotName } { |
---|
[1604] | 1311 | if { !$_settings($this-general-remember) } { |
---|
[1929] | 1312 | return |
---|
[1598] | 1313 | } |
---|
[1607] | 1314 | if { [catch { open $_settingsFile "w" 0600 } f ] != 0 } { |
---|
[1929] | 1315 | puts stderr "$_settingsFile isn't writable: $f" |
---|
| 1316 | bell |
---|
| 1317 | return |
---|
[1604] | 1318 | } |
---|
| 1319 | set key [list $toolName $plotName] |
---|
| 1320 | set _savedSettings($key) [CreateSettings $toolName $plotName] |
---|
[1598] | 1321 | # Write the settings out |
---|
| 1322 | foreach key [lsort [array names _savedSettings]] { |
---|
[1929] | 1323 | set tool [lindex $key 0] |
---|
| 1324 | set plot [lindex $key 1] |
---|
| 1325 | puts $f "xyprint \"$tool\" \"$plot\" \{" |
---|
| 1326 | set settings [string trim $_savedSettings($key) \n] |
---|
| 1327 | puts $f "$settings" |
---|
| 1328 | puts $f "\}\n" |
---|
[1598] | 1329 | } |
---|
| 1330 | close $f |
---|
| 1331 | } |
---|
| 1332 | |
---|
| 1333 | itcl::body Rappture::XyPrint::CreateSettings { toolName plotName } { |
---|
[1589] | 1334 | # Create stanza associated with tool and plot title. |
---|
| 1335 | # General settings |
---|
[1607] | 1336 | append out " set general(format) $_settings($this-general-format)\n" |
---|
| 1337 | append out " set general(style) $_settings($this-general-style)\n" |
---|
[1589] | 1338 | |
---|
[1604] | 1339 | foreach font [array names _fonts] { |
---|
[1929] | 1340 | append out " font configure $font" |
---|
| 1341 | array unset info |
---|
| 1342 | array set info [font configure $font] |
---|
| 1343 | foreach opt { -family -size -weight -slant } { |
---|
| 1344 | set value [list $info($opt)] |
---|
| 1345 | append out " $opt $value" |
---|
| 1346 | } |
---|
| 1347 | append out "\n" |
---|
[1604] | 1348 | } |
---|
[1607] | 1349 | append out "\n" |
---|
[1604] | 1350 | |
---|
[1589] | 1351 | # Layout settings |
---|
[1607] | 1352 | append out " preview configure" |
---|
[1606] | 1353 | foreach opt { -width -height -leftmargin -rightmargin -topmargin |
---|
[1929] | 1354 | -bottommargin -plotpadx -plotpady } { |
---|
| 1355 | set value [list [$_clone cget $opt]] |
---|
| 1356 | append out " $opt $value" |
---|
[1606] | 1357 | } |
---|
| 1358 | append out "\n" |
---|
[1595] | 1359 | |
---|
[1589] | 1360 | # Legend settings |
---|
[1607] | 1361 | append out " preview legend configure" |
---|
[1606] | 1362 | foreach opt { -position -anchor -borderwidth -hide } { |
---|
[1929] | 1363 | set value [list [$_clone legend cget $opt]] |
---|
| 1364 | append out " $opt $value" |
---|
[1606] | 1365 | } |
---|
| 1366 | append out " -font legend\n" |
---|
| 1367 | |
---|
[1589] | 1368 | # Element settings |
---|
| 1369 | foreach elem [$_clone element show] { |
---|
[1929] | 1370 | set label [$_clone element cget $elem -label] |
---|
| 1371 | if { $label == "" } { |
---|
| 1372 | continue |
---|
| 1373 | } |
---|
| 1374 | append out " if \{ \[preview element exists \"$label\"\] \} \{\n" |
---|
| 1375 | append out " preview element configure \"$label\"" |
---|
[1930] | 1376 | if { [$_clone element type $elem] != "bar" } { |
---|
| 1377 | set options { -symbol -color -dashes -label } |
---|
| 1378 | } else { |
---|
| 1379 | set options { -color -label } |
---|
| 1380 | } |
---|
| 1381 | foreach opt $options { |
---|
[1929] | 1382 | set value [list [$_clone element cget $elem $opt]] |
---|
| 1383 | append out " $opt $value" |
---|
| 1384 | } |
---|
| 1385 | append out " \}\n" |
---|
[1589] | 1386 | } |
---|
| 1387 | |
---|
| 1388 | # Axis settings |
---|
| 1389 | foreach axis [$_clone axis names] { |
---|
[1929] | 1390 | if { [$_clone axis cget $axis -hide] } { |
---|
| 1391 | continue |
---|
| 1392 | } |
---|
| 1393 | append out " if \{ \[preview axis names \"$axis\"\] == \"$axis\" \} \{\n" |
---|
| 1394 | append out " preview axis configure \"$axis\"" |
---|
| 1395 | foreach opt { -hide -min -max -loose -title -stepsize -subdivisions } { |
---|
| 1396 | set value [list [$_clone axis cget $axis $opt]] |
---|
| 1397 | append out " $opt $value" |
---|
| 1398 | } |
---|
| 1399 | append out " -tickfont \"$axis-ticks\"" |
---|
| 1400 | append out " -titlefont \"$axis-title\"\n" |
---|
| 1401 | set hide [$_clone marker cget ${axis}-zero -hide] |
---|
| 1402 | append out " preview marker configure \"${axis}-zero\" -hide $hide\n" |
---|
| 1403 | append out " \}\n" |
---|
[1589] | 1404 | } |
---|
[1604] | 1405 | |
---|
[1607] | 1406 | append out " preview grid configure" |
---|
[1606] | 1407 | append out " -hide \"[$_clone grid cget -hide]\"" |
---|
| 1408 | append out " -mapx \"[$_clone grid cget -mapx]\"" |
---|
| 1409 | append out " -mapy \"[$_clone grid cget -mapy]\"" |
---|
[1598] | 1410 | return $out |
---|
[1589] | 1411 | } |
---|