File: test_legend.tcl

package info (click to toggle)
tklib 0.6%2B20190108-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,008 kB
  • sloc: tcl: 75,757; sh: 5,789; ansic: 792; pascal: 359; makefile: 70; sed: 53; exp: 21
file content (126 lines) | stat: -rw-r--r-- 4,071 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env tclsh
## -*- tcl -*-

package require Tcl 8.5
package require Tk

package require Plotchart

# test_legend.tcl --
#     Show how to deal with resizing the window holding the plot
#     and one way of dealing with varying legends.
#     Basically: recreate the plots. There is a small issue to
#     be aware of for right axes - hence the use of $p instead
#     of the canvas widget.

set calc_height 600
set c_id [canvas .c2 -borderwidth 1 \
        -height $calc_height \
        -width  [expr ($calc_height * 7) / 5]]

wm geometry . 300x300+50+50

pack $c_id -side top -fill both -expand 1

catch { console show }

set max 10
set min -10
set step 2
set f 0
for {set i 0} {$i < 2} {incr i} {
    if {!$f} {
	$c_id delete "all"
update
	set p [::Plotchart::createXYPlot .c2 "$min $max $step" "$min $max $step"]

	$p title "Main Title"
	$p xtext "X title"
	$p vtext "V title"
        $p legendconfig -position top-left

	#
	# Use the plot returned by createXYPlot, rather than the widget to
	# create the right axis - this will guarantee the right geometry!
	#
	set rp [::Plotchart::createRightAxis $p "$min $max 2"]
	$rp dataconfig error -colour red
	$rp vtext "% Error"

	array set colors {1 blue 2 green 3 yellow 4 orange 5 red}
	set pct_number 5
	for {set elines 1} {$elines <= 5} {incr elines} {
	    set pct [expr $pct_number * $elines]
	
	    $p dataconfig ${pct}_pct -colour $colors($elines)
			
	    if {$min < 0} {$p plot ${pct}_pct $min [expr $min * (1.0 - ($pct /100.0))]      } else {$p plot ${pct}_pct $min [expr $min * (1.0 + ($pct /100.0))]     }
	    if {$max > 0} {$p plot ${pct}_pct      [expr $max * (1.0 - ($pct /100.0))] $max } else {$p plot ${pct}_pct      [expr $max * (1.0 + ($pct /100.0))] $max}

	    #--- plotting the negative percentage of errpr line
	    $p dataconfig n_${pct}_pct -colour $colors($elines)
			
	    if {$min < 0} {$p plot  n_${pct}_pct      [expr $min * (1.0 - ($pct /100.0))] $min } else {$p plot  n_${pct}_pct      [expr $min * (1.0 + ($pct /100.0))] $min}
	    if {$max > 0} {$p plot  n_${pct}_pct $max [expr $max * (1.0 - ($pct /100.0))]      } else {$p plot  n_${pct}_pct $max [expr $max * (1.0 + ($pct /100.0))]     }
			
	    $p legend ${pct}_pct  "+/- ${pct} percent"
	}
	#--- This controls the display of the ticklines
	$p xticklines blue dots1
	$p yticklines blue dots1


update
	set f 1
	after 2000

    } else {
wm geometry . 600x300+50+50

	$c_id delete "all"
update

	set p [::Plotchart::createXYPlot .c2 "$min $max $step" "$min $max $step"]

	$p title "Main Title"
	$p xtext "X title"
	$p vtext "V title"
        $p legendconfig -position top-left

	#
	# Use the plot returned by createXYPlot, rather than the widget to
	# create the right axis - this will guarantee the right geometry!
	#
	set rp [::Plotchart::createRightAxis $p "$min $max 2"]
	$rp dataconfig error -colour red
	$rp vtext "% Error"


	array set colors {1 blue 2 green 3 yellow 4 orange 5 red}
	set pct_number 5
	for {set elines 1} {$elines <= 2} {incr elines} {
	    set pct [expr $pct_number * $elines]
	
	    $p dataconfig ${pct}_pct -colour $colors($elines)
			
	    if {$min < 0} {$p plot ${pct}_pct $min [expr $min * (1.0 - ($pct /100.0))]      } else {$p plot ${pct}_pct $min [expr $min * (1.0 + ($pct /100.0))]     }
	    if {$max > 0} {$p plot ${pct}_pct      [expr $max * (1.0 - ($pct /100.0))] $max } else {$p plot ${pct}_pct      [expr $max * (1.0 + ($pct /100.0))] $max}

	    #--- plotting the negative percentage of errpr line
	    $p dataconfig n_${pct}_pct -colour $colors($elines)
			
	    if {$min < 0} {$p plot  n_${pct}_pct      [expr $min * (1.0 - ($pct /100.0))] $min } else {$p plot  n_${pct}_pct      [expr $min * (1.0 + ($pct /100.0))] $min}
	    if {$max > 0} {$p plot  n_${pct}_pct $max [expr $max * (1.0 - ($pct /100.0))]      } else {$p plot  n_${pct}_pct $max [expr $max * (1.0 + ($pct /100.0))]     }
			
	    $p legend ${pct}_pct  "+/- ${pct} percent"
	}
	#--- This controls the display of the ticklines
	$p xticklines blue dots1
	$p yticklines blue dots1


update
	set f 0
	after 2000
    }
}