Tk Library Source Code

Check-in [b9e9408532]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2018 Conference, Houston/TX, US, Oct 15-19
Send your abstracts to tclconference@googlegroups.com
or submit via the online form by Aug 20.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: * plothist.test: Moved to examples/plotchart, renamed to plothist.tcl. This is actually not a test suite in the standard form using tcltest, but an example application. * plotcontour.test: Added boilerplate to make it more of a test suite, proper indentation.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b9e9408532bbc8c69e788dbf868e76b4b81d63ff
User & Date: andreas_kupries 2009-02-07 05:13:24
Context
2009-02-07
05:18
* installer.tcl: Updated to use the installer and sak of tcllib * sak.tcl: head. * PACKAGES: Moved to new directory support/releases/ * tklib_version.tcl: Ditto. * README-0.4.txt: Moved to new directory support/releases/history/ * README-0.5.txt: Ditto. * all.tcl: Moved to new directory support/devel * install_action.tcl: Moved to new directory support/installation * installed_modules.tcl: Ditto. * main.tcl: Ditto. * man.macros: Ditto. * support/: New directory, mostly sak from Tcllib, and the renamed forms of the moved files, see above. check-in: cd9be0b9bc user: andreas_kupries tags: trunk
05:13
* plothist.test: Moved to examples/plotchart, renamed to plothist.tcl. This is actually not a test suite in the standard form using tcltest, but an example application. * plotcontour.test: Added boilerplate to make it more of a test suite, proper indentation. check-in: b9e9408532 user: andreas_kupries tags: trunk
05:12
* tkpiechart.tcl: Added explicit provide command to satisfy 'sak validate'. check-in: 0fea70c27b user: andreas_kupries tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added examples/plotchart/plothist.tcl.

















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#! /bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@"}

package require Tcl 8.4
package require Tk
package require Plotchart

# plothist.test --
#     Testing histograms
#
    canvas .c -width 600 -height 400 -bg white
    pack   .c -fill both
    .c delete all

    set s [::Plotchart::createHistogram .c {0.0 100.0 10.0} {0.0 100.0 20.0}]

    $s dataconfig series1 -colour green

    set xd    5.0
    set yd   20.0
    set xold  0.0
    set yold 50.0

    for { set i 0 } { $i < 20 } { incr i } {
	set xnew [expr {$xold+$xd}]
	set ynew [expr {$yold+(rand()-0.5)*$yd}]
	$s plot series1 $xnew $ynew
	set xold $xnew
	set yold $ynew
    }

    $s balloonconfig -background green -rimwidth 3 -arrowsize 10 -font "Times 14"
    $s balloon 50 50 "Here it is!"  south-east

    $s balloonconfig -background red
    $s balloonconfig -margin 10
    $s balloon 50 100 "No, here!"  north-east

    $s title "Aha!"

Changes to modules/plotchart/ChangeLog.










1

2
3
4
5
6
7
8









2008-02-06 Arjen Markus  <arjenmarkus@users.sourceforge.net>

        * plotcontour.tcl:  Commented out one remaining debug puts statement

2009-01-21  Andreas Kupries  <andreas_kupries@users.sourceforge.net>

	*
	* Released and tagged Tklib 0.5 ========================
	*
>
>
>
>
>
>
>
>
>

>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2009-02-06  Andreas Kupries  <andreas_kupries@users.sourceforge.net>

	* plothist.test: Moved to examples/plotchart, renamed to
	  plothist.tcl. This is actually not a test suite in the standard
	  form using tcltest, but an example application.

	* plotcontour.test: Added boilerplate to make it more of a test
	  suite, proper indentation.

2008-02-06 Arjen Markus  <arjenmarkus@users.sourceforge.net>

        * plotcontour.tcl:  Commented out one remaining debug puts statement

2009-01-21  Andreas Kupries  <andreas_kupries@users.sourceforge.net>

	*
	* Released and tagged Tklib 0.5 ========================
	*

Changes to modules/plotchart/plotchart.test.

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    }
}

catch { console show }

source [file join [file dirname [info script]] plotchart.tcl]

puts "Plotchart [package present Plotchart]"

# -------------------------------------------------------------------------

#
# Note:
# The tests are formulated such that the resulting numbers
# are exact. There is no need for a tolerance in the comparison







|







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    }
}

catch { console show }

source [file join [file dirname [info script]] plotchart.tcl]

#puts "Plotchart [package present Plotchart]"

# -------------------------------------------------------------------------

#
# Note:
# The tests are formulated such that the resulting numbers
# are exact. There is no need for a tolerance in the comparison

Changes to modules/plotchart/plotcontour.test.

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
# Informal test for plotcontour
#





























source [file join [file dirname [info script]] plotchart.tcl]
package require Plotchart




test "Plotcontours-1.0" "Informal test for plotcontour" {
########################################################################

proc cowboyhat {x y} {
   set x1 [expr {$x/9.0}]
   set y1 [expr {$y/9.0}]

   expr { 3.0 * (1.0-($x1*$x1+$y1*$y1))*(1.0-($x1*$x1+$y1*$y1)) }
}


#
# Main code
#
set choice 1

if {$choice == 0} {

set x { {0.0 1.0 2.0 3.0}
        {0.0 1.0 2.0 3.0}
        {0.0 1.0 2.0 3.0}
        {0.0 1.0 2.0 3.0} }

set y { {0.0 0.0 0.0 0.0}
        {1.0 1.0 1.0 1.0}
        {2.0 2.0 2.0 2.0}
        {3.0 3.0 3.0 3.0} }


set f { {0.0 0.0 2.0 3.0}
        {0.0 0.0 2.0 3.0}
        {2.0 2.0 3.0 4.0}
        {3.0 3.0 4.0 5.0} }

set contours [list 1.0 2.0 3.0 4.0 5.0 ]

# set contours [list 1.0 1.3 1.6 2.0 2.3 2.6 3.0 3.3 3.6 4.0 4.3 4.6 5.0 5.3 ]

set xlimits {0 3.5 0.5}
set ylimits {0 3.5 0.5}

}


if {$choice == 1} {

set x { {0.0 100.0 200.0}
        {0.0 100.0 200.0}
        {0.0 100.0 200.0}
        {0.0 100.0 200.0}}
set y { {0.0   0.0   0.0}
       {30.0  30.0  30.0}
       {60.0  60.0  60.0}
       {90.0  90.0  90.0}}
set f { {0.0   1.0  10.0}
       { 0.0  30.0  30.0}
       {10.0  60.0  60.0}
       {30.0  90.0  90.0}}

set contours [list \
     0.0             \
     5.2631578947    \
     10.5263157895   \
     15.7894736842   \
     21.0526315789   \
     26.3157894737   \
     31.5789473684   \
     36.8421052632   \
     42.1052631579   \
     47.3684210526   \
     52.6315789474   \
     57.8947368421   \
     63.1578947368   \
     68.4210526316   \
     73.6842105263   \
     78.9473684211   \
     84.2105263158   \
     89.4736842105   \
     94.7368421053   \
     100.0           \
     105.263157895   \
              ]

 set xlimits {0 200 50}
 set ylimits {0 100 20}

}

########################################################################

wm title . "Contour Demo : shade (jet colormap)"

set c [canvas .c  -background white \
          -width 500 -height 500]

pack   $c  -fill both -side top

set chart [::Plotchart::createXYPlot $c $xlimits $ylimits]

::Plotchart::colorMap jet

#$chart contourlines $x $y $f $contours
$chart contourfill $x $y $f $contours
#$chart contourbox $x $y $f $contours
$chart grid $x $y

set t [toplevel .contourlines]
lappend windows $t
wm title $t "Contour Demo : contourlines (default colormap)"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart1 [::Plotchart::createXYPlot $c $xlimits $ylimits]
$chart1 grid $x $y
$chart1 contourlines $x $y $f $contours


set t [toplevel .hot]
lappend windows $t
wm title $t "Contour Demo : contourlines (hot colormap)"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart2 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap hot
$chart2 contourfill $x $y $f $contours
$chart2 grid $x $y


set t [toplevel .gray]
lappend windows $t
wm title $t "Contour Demo : gray contourfill , jet contourlines"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart3 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap gray
$chart3 contourfill $x $y $f $contours

::Plotchart::colorMap jet
$chart3 contourlines $x $y $f $contours
$chart3 grid $x $y


set t [toplevel .cool]
lappend windows $t
wm title $t "Contour Demo : contourlines (cool colormap)"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart4 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap cool
$chart4 contourfill $x $y $f $contours
$chart4 grid $x $y



set t [toplevel .defcont]
lappend windows $t
wm title $t "Contour Demo : default contours (jet colormap)"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set chart5 [::Plotchart::createXYPlot $c $xlimits $ylimits]
::Plotchart::colorMap jet
$chart5 contourfill $x $y $f
$chart5 grid $x $y



set t [toplevel .3dcontour]
lappend windows $t
wm title $t "Contour Demo : contours on a 3DPlot"
set c [canvas $t.c  -background white \
          -width 500 -height 500]
pack   $c  -fill both -side top

set xlimits {-10. 10.  10.  }
set ylimits {-10. 10.  10.  }
set zlimits { -5. 10.   5.  }

set zmin   0.0
set zmax   3.0

set nc    51
set dz    [expr {($zmax - $zmin) / ($nc - 1)}]

set contours {}
for {set cnt 1} {$cnt < $nc} {incr cnt} {
    set zval [expr {$zmin + ($dz * ($cnt - 1))}]
    lappend contours $zval
}

set chart6 [::Plotchart::create3DPlot $c $xlimits $ylimits $zlimits]
::Plotchart::colorMap jet
$chart6 title "3D Plot"
$chart6 plotfuncont cowboyhat $contours

after 10000 {
   foreach t $windows {
      destroy $t
   }
   set vv 1
}
vwait vv
set v 1
} 1


# -------------------------------------------------------------------------
::tcltest::cleanupTests



>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

<

>
>
>
|
|

|
|
|

|
|


|
|
|
|

|

|
|
|
|

|
|
|
|


|
|
|
|

|

|

|
|

|


|

|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|

|

|

|

|
|

|

|

|

|
|
|
|

|
|
|
|
|
|

|
|
|


|
|
|
|
|
|

|
|
|
|


|
|
|
|
|
|

|
|
|

|
|
|


|
|
|
|
|
|

|
|
|
|



|
|
|
|
|
|

|
|
|
|



|
|
|
|
|
|

|
|
|

|
|

|
|

|
|
|
|
|

|
|
|
|

|
|
|
|
|
|
|
|






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
# Informal test for plotcontour
#

if {![package vsatisfies [package provide Tcl] 8.3]} {
    puts "    Aborting tests for plotchart."
    puts "    Requiring Tcl 8.3, have [package present Tcl]"
    return
}

# -------------------------------------------------------------------------
#
# Note:
#    The tests assume tcltest 2.1, in order to compare
#    floating-point results

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest 2.1
    #package require tcltest 2.2
    namespace import ::tcltest::*
} else {
    # Ensure that 2.1 or higher present.

    if {![package vsatisfies [package present tcltest] 2.1]} {
	puts "Aborting tests for Plotchart"
	puts "Requiring tcltest 2.1, have [package present tcltest]"
	return
    }
}

catch { console show }

source [file join [file dirname [info script]] plotchart.tcl]


#puts "Plotchart [package present Plotchart]"


tcltest::test Plotcontours-1.0 {Informal test for plotcontour} {
    ########################################################################

    proc cowboyhat {x y} {
	set x1 [expr {$x/9.0}]
	set y1 [expr {$y/9.0}]

	expr { 3.0 * (1.0-($x1*$x1+$y1*$y1))*(1.0-($x1*$x1+$y1*$y1)) }
    }


    #
    # Main code
    #
    set choice 1

    if {$choice == 0} {

	set x { {0.0 1.0 2.0 3.0}
	    {0.0 1.0 2.0 3.0}
	    {0.0 1.0 2.0 3.0}
	    {0.0 1.0 2.0 3.0} }

	set y { {0.0 0.0 0.0 0.0}
	    {1.0 1.0 1.0 1.0}
	    {2.0 2.0 2.0 2.0}
	    {3.0 3.0 3.0 3.0} }


	set f { {0.0 0.0 2.0 3.0}
	    {0.0 0.0 2.0 3.0}
	    {2.0 2.0 3.0 4.0}
	    {3.0 3.0 4.0 5.0} }

	set contours [list 1.0 2.0 3.0 4.0 5.0 ]

	# set contours [list 1.0 1.3 1.6 2.0 2.3 2.6 3.0 3.3 3.6 4.0 4.3 4.6 5.0 5.3 ]

	set xlimits {0 3.5 0.5}
	set ylimits {0 3.5 0.5}

    }


    if {$choice == 1} {

	set x { {0.0 100.0 200.0}
	    {0.0 100.0 200.0}
	    {0.0 100.0 200.0}
	    {0.0 100.0 200.0}}
	set y { {0.0   0.0   0.0}
	    {30.0  30.0  30.0}
	    {60.0  60.0  60.0}
	    {90.0  90.0  90.0}}
	set f { {0.0   1.0  10.0}
	    { 0.0  30.0  30.0}
	    {10.0  60.0  60.0}
	    {30.0  90.0  90.0}}

	set contours [list \
			  0.0             \
			  5.2631578947    \
			  10.5263157895   \
			  15.7894736842   \
			  21.0526315789   \
			  26.3157894737   \
			  31.5789473684   \
			  36.8421052632   \
			  42.1052631579   \
			  47.3684210526   \
			  52.6315789474   \
			  57.8947368421   \
			  63.1578947368   \
			  68.4210526316   \
			  73.6842105263   \
			  78.9473684211   \
			  84.2105263158   \
			  89.4736842105   \
			  94.7368421053   \
			  100.0           \
			  105.263157895   \
			 ]

	set xlimits {0 200 50}
	set ylimits {0 100 20}

    }

    ########################################################################

    wm title . "Contour Demo : shade (jet colormap)"

    set c [canvas .c  -background white \
	       -width 500 -height 500]

    pack   $c  -fill both -side top

    set chart [::Plotchart::createXYPlot $c $xlimits $ylimits]

    ::Plotchart::colorMap jet

    #$chart contourlines $x $y $f $contours
    $chart contourfill $x $y $f $contours
    #$chart contourbox $x $y $f $contours
    $chart grid $x $y

    set t [toplevel .contourlines]
    lappend windows $t
    wm title $t "Contour Demo : contourlines (default colormap)"
    set c [canvas $t.c  -background white \
	       -width 500 -height 500]
    pack   $c  -fill both -side top

    set chart1 [::Plotchart::createXYPlot $c $xlimits $ylimits]
    $chart1 grid $x $y
    $chart1 contourlines $x $y $f $contours


    set t [toplevel .hot]
    lappend windows $t
    wm title $t "Contour Demo : contourlines (hot colormap)"
    set c [canvas $t.c  -background white \
	       -width 500 -height 500]
    pack   $c  -fill both -side top

    set chart2 [::Plotchart::createXYPlot $c $xlimits $ylimits]
    ::Plotchart::colorMap hot
    $chart2 contourfill $x $y $f $contours
    $chart2 grid $x $y


    set t [toplevel .gray]
    lappend windows $t
    wm title $t "Contour Demo : gray contourfill , jet contourlines"
    set c [canvas $t.c  -background white \
	       -width 500 -height 500]
    pack   $c  -fill both -side top

    set chart3 [::Plotchart::createXYPlot $c $xlimits $ylimits]
    ::Plotchart::colorMap gray
    $chart3 contourfill $x $y $f $contours

    ::Plotchart::colorMap jet
    $chart3 contourlines $x $y $f $contours
    $chart3 grid $x $y


    set t [toplevel .cool]
    lappend windows $t
    wm title $t "Contour Demo : contourlines (cool colormap)"
    set c [canvas $t.c  -background white \
	       -width 500 -height 500]
    pack   $c  -fill both -side top

    set chart4 [::Plotchart::createXYPlot $c $xlimits $ylimits]
    ::Plotchart::colorMap cool
    $chart4 contourfill $x $y $f $contours
    $chart4 grid $x $y



    set t [toplevel .defcont]
    lappend windows $t
    wm title $t "Contour Demo : default contours (jet colormap)"
    set c [canvas $t.c  -background white \
	       -width 500 -height 500]
    pack   $c  -fill both -side top

    set chart5 [::Plotchart::createXYPlot $c $xlimits $ylimits]
    ::Plotchart::colorMap jet
    $chart5 contourfill $x $y $f
    $chart5 grid $x $y



    set t [toplevel .3dcontour]
    lappend windows $t
    wm title $t "Contour Demo : contours on a 3DPlot"
    set c [canvas $t.c  -background white \
	       -width 500 -height 500]
    pack   $c  -fill both -side top

    set xlimits {-10. 10.  10.  }
    set ylimits {-10. 10.  10.  }
    set zlimits { -5. 10.   5.  }

    set zmin   0.0
    set zmax   3.0

    set nc    51
    set dz    [expr {($zmax - $zmin) / ($nc - 1)}]

    set contours {}
    for {set cnt 1} {$cnt < $nc} {incr cnt} {
	set zval [expr {$zmin + ($dz * ($cnt - 1))}]
	lappend contours $zval
    }

    set chart6 [::Plotchart::create3DPlot $c $xlimits $ylimits $zlimits]
    ::Plotchart::colorMap jet
    $chart6 title "3D Plot"
    $chart6 plotfuncont cowboyhat $contours

    after 10000 {
	foreach t $windows {
	    destroy $t
	}
	set vv 1
    }
    vwait vv
    set v 1
} 1


# -------------------------------------------------------------------------
::tcltest::cleanupTests

Deleted modules/plotchart/plothist.test.

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
#! /bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@"}

package require Tcl 8.4
package require Tk
package require Plotchart

# plothist.test --
#     Testing histograms
#
    canvas .c -width 600 -height 400 -bg white
    pack   .c -fill both
    .c delete all

    set s [::Plotchart::createHistogram .c {0.0 100.0 10.0} {0.0 100.0 20.0}]

    $s dataconfig series1 -colour green

    set xd    5.0
    set yd   20.0
    set xold  0.0
    set yold 50.0

    for { set i 0 } { $i < 20 } { incr i } {
	set xnew [expr {$xold+$xd}]
	set ynew [expr {$yold+(rand()-0.5)*$yd}]
	$s plot series1 $xnew $ynew
	set xold $xnew
	set yold $ynew
    }

    $s balloonconfig -background green -rimwidth 3 -arrowsize 10 -font "Times 14"
    $s balloon 50 50 "Here it is!"  south-east

    $s balloonconfig -background red
    $s balloonconfig -margin 10
    $s balloon 50 100 "No, here!"  north-east

    $s title "Aha!"
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<