File: plotline.tcl

package info (click to toggle)
saods9 8.2%2Brepack-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 28,436 kB
  • sloc: tcl: 247,588; cpp: 69,307; ansic: 3,983; xml: 1,375; sh: 1,312; makefile: 183; perl: 68
file content (430 lines) | stat: -rw-r--r-- 14,220 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#  Copyright (C) 1999-2018
#  Smithsonian Astrophysical Observatory, Cambridge, MA, USA
#  For conditions of distribution and use, see copyright notice in "copyright"

package provide DS9 1.0

# used by backup
proc PlotLineTool {} {
    global iap

    PlotLine $iap(tt) [msgcat::mc {Line Plot Tool}] {} {} {} 2 {} true
}

proc PlotLine {tt wtt title xaxis yaxis dim data theme} {
    global iap

    # make the window name unique
    set ii [lsearch $iap(plots) $tt]
    if {$ii>=0} {
	incr iap(unique)
	append tt $iap(unique)
    }

    # set the window title if none
    if {$wtt == {}} {
	set wtt $tt
    }

    set varname $tt
    upvar #0 $varname var
    global $varname
    
    PlotDialog $varname $wtt $theme
    PlotAddGraph $varname line
    PlotTitle $varname $title $xaxis $yaxis
    PlotAddDataSet $varname $dim $data
    PlotStats $varname
    PlotList $varname
}

proc PlotLineMenus {varname} {
    upvar #0 $varname var
    global $varname

    ThemeMenu $var(mb).dataline
    $var(mb).dataline add checkbutton -label [msgcat::mc {Show}] \
	-variable ${varname}(graph,ds,show) \
	-command [list PlotLineUpdateElement $varname]
    $var(mb).dataline add command -label "[msgcat::mc {Name}]..." \
	-command [list DatasetNameDialog $varname]
    $var(mb).dataline add separator
    $var(mb).dataline add cascade -label [msgcat::mc {Color}] \
	-menu $var(mb).dataline.color
    $var(mb).dataline add cascade -label [msgcat::mc {Width}] \
	-menu $var(mb).dataline.width
    $var(mb).dataline add cascade -label [msgcat::mc {Shadow}] \
	-menu $var(mb).dataline.fill
    $var(mb).dataline add cascade -label [msgcat::mc {Shape}] \
	-menu $var(mb).dataline.shape
    $var(mb).dataline add cascade -label [msgcat::mc {Smooth}] \
	-menu $var(mb).dataline.smooth
    $var(mb).dataline add separator
    $var(mb).dataline add cascade -label [msgcat::mc {Errorbar}] \
	-menu $var(mb).dataline.error

    ColorMenu $var(mb).dataline.color $varname graph,ds,line,color \
	[list PlotLineUpdateElement $varname]

    PlotLineWidthMenu $var(mb).dataline.width $varname \
	[list PlotLineUpdateElement $varname]

    ThemeMenu $var(mb).dataline.fill
    $var(mb).dataline.fill add checkbutton \
	-label [msgcat::mc {Fill}] \
	-variable ${varname}(graph,ds,line,fill) \
	-command [list PlotLineUpdateElement $varname]
    $var(mb).dataline.fill add separator
    $var(mb).dataline.fill add cascade -label [msgcat::mc {Color}] \
	-menu $var(mb).dataline.fill.color

    ColorMenu $var(mb).dataline.fill.color \
	$varname graph,ds,line,fill,color [list PlotLineUpdateElement $varname]

    ThemeMenu $var(mb).dataline.shape
    $var(mb).dataline.shape add checkbutton \
	-label [msgcat::mc {Fill}] \
	-variable ${varname}(graph,ds,line,shape,fill) \
	-command [list PlotLineUpdateElement $varname]
    $var(mb).dataline.shape add separator
    $var(mb).dataline.shape add cascade -label [msgcat::mc {Symbol}] \
	-menu $var(mb).dataline.shape.symbol
    $var(mb).dataline.shape add cascade -label [msgcat::mc {Color}] \
	-menu $var(mb).dataline.shape.color

    PlotLineShapeMenu $var(mb).dataline.shape.symbol $varname \
	[list PlotLineUpdateElement $varname]
    ColorMenu $var(mb).dataline.shape.color \
	$varname graph,ds,line,shape,color \
	[list PlotLineUpdateElement $varname]
    
    PlotLineSmoothMenu $var(mb).dataline.smooth $varname \
	[list PlotLineUpdateElement $varname]
    
    ThemeMenu $var(mb).dataline.error
    $var(mb).dataline.error add checkbutton -label [msgcat::mc {Show}] \
	-variable ${varname}(graph,ds,error) \
	-command [list PlotLineUpdateElement $varname]
    $var(mb).dataline.error add checkbutton -label [msgcat::mc {Cap}] \
	-variable ${varname}(graph,ds,error,cap) \
	-command [list PlotLineUpdateElement $varname]
    $var(mb).dataline.error add separator
    $var(mb).dataline.error add cascade -label [msgcat::mc {Color}] \
	-menu $var(mb).dataline.error.color
    $var(mb).dataline.error add cascade -label [msgcat::mc {Width}] \
	-menu $var(mb).dataline.error.width

    ColorMenu $var(mb).dataline.error.color $varname graph,ds,error,color \
	[list PlotLineUpdateElement $varname]
    WidthDashMenu $var(mb).dataline.error.width $varname \
	graph,ds,error,width {} [list PlotLineUpdateElement $varname] {}
}

proc PlotLineWidthMenu {w varname cmd} {
    ThemeMenu $w
    $w add radiobutton -label {0} \
	-variable ${varname}(graph,ds,line,width) \
	-value 0 -command $cmd
    $w add radiobutton -label {1} \
	-variable ${varname}(graph,ds,line,width) \
	-value 1 -command $cmd
    $w add radiobutton -label {2} \
	-variable ${varname}(graph,ds,line,width) \
	-value 2 -command $cmd
    $w add radiobutton -label {3} \
	-variable ${varname}(graph,ds,line,width) \
	-value 3 -command $cmd
    $w add radiobutton -label {4} \
	-variable ${varname}(graph,ds,line,width) \
	-value 4 -command $cmd
    $w add separator
    $w add checkbutton -label [msgcat::mc {Dash}] \
	-variable ${varname}(graph,ds,line,dash) -command $cmd
}

proc PlotLineShapeMenu {w varname cmd} {
    ThemeMenu $w
    $w add radiobutton -label [msgcat::mc {None}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value none -command $cmd
    $w add radiobutton -label [msgcat::mc {Circle}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value circle -command $cmd
    $w add radiobutton -label [msgcat::mc {Square}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value square -command $cmd
    $w add radiobutton -label [msgcat::mc {Diamond}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value diamond -command $cmd
    $w add radiobutton -label [msgcat::mc {Plus}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value plus -command $cmd
    $w add radiobutton -label [msgcat::mc {Cross}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value cross -command $cmd
    $w add radiobutton -label [msgcat::mc {Simple Plus}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value splus -command $cmd
    $w add radiobutton -label [msgcat::mc {Simple Cross}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value scross -command $cmd
    $w add radiobutton -label [msgcat::mc {Triangle}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value triangle -command $cmd
    $w add radiobutton -label [msgcat::mc {Arrow}] \
	-variable ${varname}(graph,ds,line,shape,symbol) \
	-value arrow -command $cmd
}

proc PlotLineSmoothMenu {w varname cmd} {
    ThemeMenu $w
    $w add radiobutton -label [msgcat::mc {Step}] \
	-variable ${varname}(graph,ds,line,smooth) \
	-value step -command $cmd
    $w add radiobutton -label [msgcat::mc {Linear}] \
	-variable ${varname}(graph,ds,line,smooth) \
	-value linear -command $cmd
    $w add radiobutton -label [msgcat::mc {Cubic}] \
	-variable ${varname}(graph,ds,line,smooth) \
	-value cubic -command $cmd
    $w add radiobutton -label [msgcat::mc {Quadratic}] \
	-variable ${varname}(graph,ds,line,smooth) \
	-value quadratic -command $cmd
    $w add radiobutton -label [msgcat::mc {Catrom}] \
	-variable ${varname}(graph,ds,line,smooth) \
	-value catrom -command $cmd
}

proc PlotLineAddGraph {varname} {
    upvar #0 $varname var
    global $varname

    set var(graph,type) line
    blt::graph $var(graph) \
	-width 600 \
	-height 500 \
	-highlightthickness 0
}

proc PlotLineUpdateElement {varname} {
    upvar #0 $varname var
    global $varname
    
    PlotSaveState $varname

    set cc $var(graph,current)
    if {[llength $var($cc,dss)] == 0} {
 	return
    }
    
    if {$var(canvas,theme)} {
	set color [ThemeBold]
	set shapecolor [ThemeBold]
	set errorcolor [ThemeBold]
    } else {
	set color $var(graph,ds,line,color)
	set shapecolor $var(graph,ds,line,shape,color)
	set errorcolor $var(graph,ds,error,color)
    }

    if {$var(graph,ds,line,fill)} {
	if {$var(canvas,theme)} {
	    set fillColor [ThemeBold]
	} else {
	    set fillColor $var(graph,ds,line,fill,color)
	}
    } else {
	set fillColor {}
    }

    if {$var(graph,ds,line,shape,fill)} {
	if {$var(canvas,theme)} {
	    set shapefillcolor [ThemeBold]
	} else {
	    set shapefillcolor $var(graph,ds,line,shape,color)
	}
    } else {
	set shapefillcolor $var(canvas,background)
    }

    if {$var(graph,ds,line,dash)} {
	set dash {8 3}
    } else {
	set dash { }
    }

    if {$var(graph,ds,error)} {
	set show both
    } else {
	set show none
    }

    if {$var(graph,ds,error,cap)} {
	set cap [expr $var(graph,ds,error,width)+3]
    } else {
	set cap 0
    }

    set nn $var(graph,ds,current)
    $var(graph) element configure ${nn} \
	-label $var(graph,ds,name) \
	-hide [expr !$var(graph,ds,show)] \
	-color $color \
	-areabackground $fillColor \
	-outline $shapecolor \
	-fill $shapefillcolor \
	-symbol $var(graph,ds,line,shape,symbol) \
	-scalesymbols no \
	-pixels 5 \
	-smooth $var(graph,ds,line,smooth) \
	-linewidth $var(graph,ds,line,width) \
	-dashes $dash \
	-showerrorbars $show \
	-errorbarcolor $errorcolor \
	-errorbarwidth $var(graph,ds,error,width) \
	-errorbarcap $cap
}


proc PlotPrefsLine {w} {
    set f [ttk::labelframe $w.line -text [msgcat::mc {Line}]]

    ttk::label $f.tcolor -text [msgcat::mc {Color}]
    ColorMenuButton $f.color pap graph,ds,line,color {}

    ttk::label $f.twidth -text [msgcat::mc {Width}]
    ttk::menubutton $f.width -textvariable pap(graph,ds,line,width) \
	-menu $f.width.menu
    WidthDashMenu $f.width.menu pap graph,ds,line,width graph,ds,line,dash {} {}

    ttk::label $f.tshadow -text [msgcat::mc {Shadow}]
    ColorMenuButton $f.fillcolor pap graph,ds,line,fill,color {}
    ttk::checkbutton $f.fill -text [msgcat::mc {Fill}] \
	-variable pap(graph,ds,line,fill)

    ttk::label $f.tshape -text [msgcat::mc {Shape}]
    ttk::menubutton $f.shape -textvariable pap(graph,ds,line,shape,symbol) \
	-menu $f.shape.menu
    PlotLineShapeMenu $f.shape.menu pap {}
    ttk::label $f.tshapecolor -text [msgcat::mc {Color}]
    ColorMenuButton $f.shapecolor pap graph,ds,line,shape,color {}
    ttk::checkbutton $f.shapefill -text [msgcat::mc {Fill}] \
	-variable pap(graph,ds,line,shape,fill)

    ttk::label $f.tsmooth -text [msgcat::mc {Smooth}]
    ttk::menubutton $f.smooth -textvariable pap(graph,ds,line,smooth) \
	-menu $f.smooth.menu
    PlotLineSmoothMenu $f.smooth.menu pap {}

    grid $f.tcolor $f.color -padx 2 -pady 2 -sticky w
    grid $f.twidth $f.width -padx 2 -pady 2 -sticky w
    grid $f.tshadow $f.fillcolor $f.fill -padx 2 -pady 2 -sticky w
    grid $f.tshape $f.shape $f.tshapecolor $f.shapecolor $f.shapefill \
	-padx 2 -pady 2 -sticky w
    grid $f.tsmooth $f.smooth -padx 2 -pady 2 -sticky w
}

proc PlotGUILine {varname w} {
    upvar #0 $varname var
    global $varname

    # Line
    set f [ttk::labelframe $w.line -text [msgcat::mc {Line Dataset}]]

    ttk::checkbutton $f.show -text [msgcat::mc {Show}] \
	-variable ${varname}(graph,ds,show) \
	-command [list PlotLineUpdateElement $varname]

    ttk::label $f.tname -text [msgcat::mc {Dataset Name}]
    ttk::entry $f.name -textvariable ${varname}(graph,ds,name) -width 20

    grid $f.show -padx 2 -pady 2 -sticky ew
    grid $f.tname $f.name -padx 2 -pady 2 -sticky ew

    # Params
    set f [ttk::labelframe $w.params -text [msgcat::mc {Properties}]]

    # Color
    ttk::label $f.tcolor -text [msgcat::mc {Color}]
    ttk::menubutton $f.color \
	-textvariable ${varname}(graph,ds,line,color) \
	-menu $f.color.menu
    $var(mb).dataline.color clone $f.color.menu

    # Width
    ttk::label $f.twidth -text [msgcat::mc {Width}]
    ttk::menubutton $f.width \
	-textvariable ${varname}(graph,ds,line,width) \
	-menu $f.width.menu
    $var(mb).dataline.width clone $f.width.menu

    # Shadow
    ttk::label $f.tshadow -text [msgcat::mc {Shadow}]
    ttk::menubutton $f.fillcolor \
	-textvariable ${varname}(graph,ds,line,fill,color) \
	-menu $f.fillcolor.menu
    $var(mb).dataline.fill.color clone $f.fillcolor.menu
    ttk::checkbutton $f.fill -text [msgcat::mc {Fill}] \
	-variable ${varname}(graph,ds,line,fill) \
	-command [list PlotLineUpdateElement $varname]

    # Shape
    ttk::label $f.tshape -text [msgcat::mc {Shape}]
    ttk::menubutton $f.shape \
	-textvariable ${varname}(graph,ds,line,shape,symbol) \
	-menu $f.shape.menu
    $var(mb).dataline.shape.symbol clone $f.shape.menu

    ttk::label $f.tshapecolor -text [msgcat::mc {Color}]
    ttk::menubutton $f.shapecolor \
	-textvariable ${varname}(graph,ds,line,shape,color) \
	-menu $f.shapecolor.menu
    $var(mb).dataline.shape.color clone $f.shapecolor.menu

    ttk::checkbutton $f.shapefill -text [msgcat::mc {Fill}] \
	-variable ${varname}(graph,ds,line,shape,fill) \
	-command [list PlotLineUpdateElement $varname]

    # Smooth
    ttk::label $f.tsmooth -text [msgcat::mc {Smooth}]
    ttk::menubutton $f.smooth \
	-textvariable ${varname}(graph,ds,line,smooth) \
	-menu $f.smooth.menu
    $var(mb).dataline.smooth clone $f.smooth.menu

    grid $f.tcolor $f.color -padx 2 -pady 2 -sticky ew
    grid $f.twidth $f.width -padx 2 -pady 2 -sticky ew
    grid $f.tshadow $f.fillcolor $f.fill -padx 2 -pady 2 -sticky ew
    grid $f.tshape $f.shape $f.tshapecolor $f.shapecolor \
	$f.shapefill  -padx 2 -pady 2 -sticky ew
    grid $f.tsmooth $f.smooth -padx 2 -pady 2 -sticky ew

    # Errorbar
    set f [ttk::labelframe $w.error -text [msgcat::mc {Errorbar}]]

    ttk::checkbutton $f.show -text [msgcat::mc {Show}] \
	-variable ${varname}(graph,ds,error) \
	-command [list PlotLineUpdateElement $varname]

    ttk::checkbutton $f.cap -text [msgcat::mc {Cap}] \
	-variable ${varname}(graph,ds,error,cap) \
	-command [list PlotLineUpdateElement $varname]

    ttk::label $f.tcolor -text [msgcat::mc {Color}]
    ttk::menubutton $f.color \
	-textvariable ${varname}(graph,ds,error,color) \
	-menu $f.color.menu
    $var(mb).dataline.error.color clone $f.color.menu

    ttk::label $f.twidth -text [msgcat::mc {Width}]
    ttk::menubutton $f.width \
	-textvariable ${varname}(graph,ds,error,width) \
	-menu $f.width.menu
    $var(mb).dataline.error.width clone $f.width.menu

    grid $f.show $f.cap -padx 2 -pady 2 -sticky ew
    grid $f.tcolor $f.color -padx 2 -pady 2 -sticky ew
    grid $f.twidth $f.width -padx 2 -pady 2 -sticky ew

    pack $w.line $w.params $w.error -side top -fill both -expand true
}