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