Tk Library Source Code

Check-in [8630a2204b]
Login

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

Overview
Comment:Made some changes to the 3D plots - added support for formats and x-labels. Also added a remark about the tags for bars in a barchart (this information was missing). Bumped the version to 2.3.4.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:8630a2204b8497d1d020ca0c406ff66758826f0b
User & Date: markus 2015-04-11 13:43:14
Context
2015-04-13
06:43
Remove [console show], a left over from a debugging session check-in: 5a8cd11629 user: markus tags: trunk
2015-04-11
13:43
Made some changes to the 3D plots - added support for formats and x-labels. Also added a remark about the tags for bars in a barchart (this information was missing). Bumped the version to 2.3.4. check-in: 8630a2204b user: markus tags: trunk
13:07
Remove explicit path from test script - should not be there check-in: 23384a8af0 user: markus tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to examples/plotchart/plotdemos1.tcl.

1
2
3

4
5
6
7
8
9
10
...
151
152
153
154
155
156
157


158
159
160
161
162
163
164
165
#!/usr/bin/env tclsh
## -*- tcl -*-


package require Tcl 8.5
package require Tk
package require Plotchart

# plotdemos1.tcl --
#    Test program 1 for the Plotchart package
#
................................................................................
canvas .h3.c3 -bg white -width 400 -height 250
pack .h3.c .h3.c2 .h3.c3

set s [::Plotchart::create3DPlot .h3.c {0 10 3} {-10 10 10} {0 10 2.5}]
$s title "3D Plot"
$s plotfunc cowboyhat



set s [::Plotchart::create3DPlot .h3.c2 {0 10 3} {-10 10 10} {0 10 2.5}]
$s title "3D Plot - data "
$s colour "green" "black"
$s plotdata { {1.0 2.0 1.0 0.0} {1.1 3.0 1.1 -0.5} {3.0 1.0 4.0 5.0} }

set s [::Plotchart::create3DPlot .h3.c3 {0 10 3} {-10 10 10} {0 10 2.5}]
$s title "3D Plot - data "
$s colour "green" "black"



>







 







>
>
|







1
2
3
4
5
6
7
8
9
10
11
...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env tclsh
## -*- tcl -*-

source ../../modules/plotchart/plotchart.tcl
package require Tcl 8.5
package require Tk
package require Plotchart

# plotdemos1.tcl --
#    Test program 1 for the Plotchart package
#
................................................................................
canvas .h3.c3 -bg white -width 400 -height 250
pack .h3.c .h3.c2 .h3.c3

set s [::Plotchart::create3DPlot .h3.c {0 10 3} {-10 10 10} {0 10 2.5}]
$s title "3D Plot"
$s plotfunc cowboyhat

::Plotchart::plotconfig 3dplot xaxis format "%4.2f"

set s [::Plotchart::create3DPlot .h3.c2 {0 10 3} {-10 10 10} {0 10 2.5} -xlabels {A B C}]
$s title "3D Plot - data "
$s colour "green" "black"
$s plotdata { {1.0 2.0 1.0 0.0} {1.1 3.0 1.1 -0.5} {3.0 1.0 4.0 5.0} }

set s [::Plotchart::create3DPlot .h3.c3 {0 10 3} {-10 10 10} {0 10 2.5}]
$s title "3D Plot - data "
$s colour "green" "black"

Changes to modules/plotchart/ChangeLog.

1
2

3
4




5
6
7
8
9
10
11
2015-04-11  Arjen Markus  <arjenmarkus@users,sourceforge.net>
	* plotchart.tcl: Properly place the table wrt a title and subtitle, take care of fonts (patch by Frank Gover)

	* plottable.tcl: Correct drawing of the row in a table, take care of fonts (patch by Frank Gover)
	* plotconfig.tcl: Extend calculation of font metrics, optional font and linespacing (patch by Frank Gover)





2014-12-14  Arjen Markus  <arjenmarkus@users,sourceforge.net>
	* plotchart.tcl: Introduce an option -xlabelangle for barcharts (request by Frank Gover)
	* plotaxis.tcl: Implement the option -xlabelangle for the labels of barcharts, also add a call
	                to worldCoordinates to reset the scaling (cause of xconfig -scale not working
	                correctly)
	* plotpriv.tcl: Correct the margins if subtext is used (required for the masking rectangles)


>


>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2015-04-11  Arjen Markus  <arjenmarkus@users,sourceforge.net>
	* plotchart.tcl: Properly place the table wrt a title and subtitle, take care of fonts (patch by Frank Gover)
	                 Support setting axis labels at 3D plot (patch by Frank Gover)
	* plottable.tcl: Correct drawing of the row in a table, take care of fonts (patch by Frank Gover)
	* plotconfig.tcl: Extend calculation of font metrics, optional font and linespacing (patch by Frank Gover)
	* plot3d.tcl:    Support formatting of the numerical axis labels for 3D plots (requested by Frank Gover)
	* plotchart.man: Bumped version to 2.3.4, added documentation of the tags for bars in a barchart.
	* pkgIndex.tcl:  Bumped version to 2.3.4
	* plotdemos1.tcl: Small changes to the 3D plot demo - axis labels and formatting

2014-12-14  Arjen Markus  <arjenmarkus@users,sourceforge.net>
	* plotchart.tcl: Introduce an option -xlabelangle for barcharts (request by Frank Gover)
	* plotaxis.tcl: Implement the option -xlabelangle for the labels of barcharts, also add a call
	                to worldCoordinates to reset the scaling (cause of xconfig -scale not working
	                correctly)
	* plotpriv.tcl: Correct the margins if subtext is used (required for the masking rectangles)

Changes to modules/plotchart/plot3d.tcl.

33
34
35
36
37
38
39

40
41
42
43
44
45
46
..
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
...
104
105
106
107
108
109
110

111
112
113
114
115
116





117
118
119
120
121
122
123
124
125
# Side effects:
#    Axes drawn in canvas
#
proc ::Plotchart::Draw3DAxes { w xmin  ymin  zmin
                                 xmax  ymax  zmax
                                 xstep ystep zstep
                                 {names {}}        } {

   variable scaling

   $w delete axis3d

   #
   # Create the support lines first
   #
................................................................................
   }
   $w create line $pxxmin $pyxmin $pxymx2 $pyymx2 -fill black -tag axis3d
   $w create line $pxxmin $pyxmin $pxzmx2 $pyzmx2 -fill black -tag axis3d

   #
   # Numbers to the z-axis
   #

   set z $zmin
   while { $z < $zmax+0.5*$zstep } {
      foreach {xcrd ycrd} [coords3DToPixel $w $xmin $ymin $z] {break}
      set xcrd2 [expr {$xcrd-3}]
      set xcrd3 [expr {$xcrd-5}]






      $w create line $xcrd2 $ycrd $xcrd $ycrd -tag axis3d
      $w create text $xcrd3 $ycrd -text $z -tag axis3d -anchor e
      set z [expr {$z+$zstep}]
   }

   #
   # Numbers or labels to the x-axis (shown on the right!)
   #

   if { $xstep > 0 } {
       if { $names eq "" } {
           set x $xmin
           while { $x < $xmax+0.5*$xstep } {
               foreach {xcrd ycrd} [coords3DToPixel $w $x $ymax $zmin] {break}
               set xcrd2 [expr {$xcrd+4}]
               set xcrd3 [expr {$xcrd+6}]

               $w create line $xcrd2 $ycrd $xcrd $ycrd -tag axis3d





               $w create text $xcrd3 $ycrd -text $x -tag axis3d -anchor w
               set x [expr {$x+$xstep}]
           }
       } else {
           set x [expr {$xmin+0.5*$xstep}]
           foreach label $names {
               foreach {xcrd ycrd} [coords3DToPixel $w $x $ymax $zmin] {break}
               set xcrd2 [expr {$xcrd+6}]
................................................................................
           }
       }
   }

   #
   # Numbers to the y-axis (shown in front!)
   #

   set y $ymin
   while { $y < $ymax+0.5*$ystep } {
      foreach {xcrd ycrd} [coords3DToPixel $w $xmin $y $zmin] {break}
      set ycrd2 [expr {$ycrd+3}]
      set ycrd3 [expr {$ycrd+5}]






      $w create line $xcrd $ycrd2 $xcrd $ycrd -tag axis3d
      $w create text $xcrd $ycrd3 -text $y -tag axis3d -anchor n
      set y [expr {$y+$ystep}]
   }

   set scaling($w,xstep) $xstep
   set scaling($w,ystep) $ystep
   set scaling($w,zstep) $zstep








>







 







>






>
>
>
>
>

|






>









>
>
>
>
>
|







 







>






>
>
>
>
>

|







33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
..
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
...
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
# Side effects:
#    Axes drawn in canvas
#
proc ::Plotchart::Draw3DAxes { w xmin  ymin  zmin
                                 xmax  ymax  zmax
                                 xstep ystep zstep
                                 {names {}}        } {
   variable config
   variable scaling

   $w delete axis3d

   #
   # Create the support lines first
   #
................................................................................
   }
   $w create line $pxxmin $pyxmin $pxymx2 $pyymx2 -fill black -tag axis3d
   $w create line $pxxmin $pyxmin $pxzmx2 $pyzmx2 -fill black -tag axis3d

   #
   # Numbers to the z-axis
   #
   set format $config($w,zaxis,format)
   set z $zmin
   while { $z < $zmax+0.5*$zstep } {
      foreach {xcrd ycrd} [coords3DToPixel $w $xmin $ymin $z] {break}
      set xcrd2 [expr {$xcrd-3}]
      set xcrd3 [expr {$xcrd-5}]

      set zt [format "%.12g" $z]
      if { $format != "" } {
          set zt [FormatNumber $format $z]
      }

      $w create line $xcrd2 $ycrd $xcrd $ycrd -tag axis3d
      $w create text $xcrd3 $ycrd -text $zt -tag axis3d -anchor e
      set z [expr {$z+$zstep}]
   }

   #
   # Numbers or labels to the x-axis (shown on the right!)
   #
   set format $config($w,xaxis,format)
   if { $xstep > 0 } {
       if { $names eq "" } {
           set x $xmin
           while { $x < $xmax+0.5*$xstep } {
               foreach {xcrd ycrd} [coords3DToPixel $w $x $ymax $zmin] {break}
               set xcrd2 [expr {$xcrd+4}]
               set xcrd3 [expr {$xcrd+6}]

               $w create line $xcrd2 $ycrd $xcrd $ycrd -tag axis3d

               set xt [format "%.12g" $x]
               if { $format != "" } {
                   set xt [FormatNumber $format $x]
               }
               $w create text $xcrd3 $ycrd -text $xt -tag axis3d -anchor w
               set x [expr {$x+$xstep}]
           }
       } else {
           set x [expr {$xmin+0.5*$xstep}]
           foreach label $names {
               foreach {xcrd ycrd} [coords3DToPixel $w $x $ymax $zmin] {break}
               set xcrd2 [expr {$xcrd+6}]
................................................................................
           }
       }
   }

   #
   # Numbers to the y-axis (shown in front!)
   #
   set format $config($w,yaxis,format)
   set y $ymin
   while { $y < $ymax+0.5*$ystep } {
      foreach {xcrd ycrd} [coords3DToPixel $w $xmin $y $zmin] {break}
      set ycrd2 [expr {$ycrd+3}]
      set ycrd3 [expr {$ycrd+5}]

      set yt [format "%.12g" $y]
      if { $format != "" } {
          set yt [FormatNumber $format $y]
      }

      $w create line $xcrd $ycrd2 $xcrd $ycrd -tag axis3d
      $w create text $xcrd $ycrd3 -text $yt -tag axis3d -anchor n
      set y [expr {$y+$ystep}]
   }

   set scaling($w,xstep) $xstep
   set scaling($w,ystep) $ystep
   set scaling($w,zstep) $zstep

Changes to modules/plotchart/plotchart.man.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
...
394
395
396
397
398
399
400




401
402
403
404
405
406
407
....
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
....
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin Plotchart n 2.3.2]
[copyright {2013 Arjen Markus <arjenmarkus@users.sourceforge.net>}]
[moddesc   Plotchart]
[titledesc {Simple plotting and charting package}]
[require Tcl [opt 8.5]]
[require Tk [opt 8.5]]
[require Plotchart [opt 2.3.2]]

[description]
[para]

Plotchart is a Tcl-only package that focuses on the easy creation of
xy-plots, barcharts and other common types of graphical presentations.
The emphasis is on ease of use, rather than flexibility. The procedures
................................................................................
[arg_def list args in]
Zero or more options - see the XY-plot for more information.

[list_end]
[para]


[call [cmd ::Plotchart::create3DPlot] [arg w] [arg xaxis] [arg yaxis] [arg zaxis]]

Create a new 3D plot.

[list_begin arguments]
[arg_def widget w in]
Name of the [emph existing] canvas widget to hold the plot.

................................................................................
A 3-element list containing minimum, maximum and stepsize for the x-axis, in this order.

[arg_def list yaxis in]
A 3-element list containing minimum, maximum and stepsize for the y-axis, in this order.

[arg_def list zaxis in]
A 3-element list containing minimum, maximum and stepsize for the z-axis, in this order.





[list_end]
[para]


[call [cmd ::Plotchart::create3DRibbonPlot] [arg w] [arg yaxis] [arg zaxis]]

................................................................................
[para]

For [emph {vertical barcharts}]:

[list_begin definitions]
[call [cmd \$barchart] plot [arg series] [arg ydata] [arg colour] [opt dir] [opt brightness]]

Add a data series to a barchart.

[list_begin arguments]
[arg_def string series in]
Name of the series the values belong to.

[arg_def list ydata in]
A list of values, one for each x-axis label.
................................................................................
[para]

For [emph {horizontal barcharts}]:

[list_begin definitions]
[call [cmd \$barchart] plot [arg series] [arg xdata] [arg colour] [opt dir] [opt brightness]]

Add a data series to a barchart.

[list_begin arguments]
[arg_def string series in]
Name of the series the values belong to.

[arg_def list xdata in]
A list of values, one for each y-axis label.

|





|







 







|







 







>
>
>
>







 







|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
...
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
....
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
....
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin Plotchart n 2.3.4]
[copyright {2013 Arjen Markus <arjenmarkus@users.sourceforge.net>}]
[moddesc   Plotchart]
[titledesc {Simple plotting and charting package}]
[require Tcl [opt 8.5]]
[require Tk [opt 8.5]]
[require Plotchart [opt 2.3.4]]

[description]
[para]

Plotchart is a Tcl-only package that focuses on the easy creation of
xy-plots, barcharts and other common types of graphical presentations.
The emphasis is on ease of use, rather than flexibility. The procedures
................................................................................
[arg_def list args in]
Zero or more options - see the XY-plot for more information.

[list_end]
[para]


[call [cmd ::Plotchart::create3DPlot] [arg w] [arg xaxis] [arg yaxis] [arg zaxis] [arg args]]

Create a new 3D plot.

[list_begin arguments]
[arg_def widget w in]
Name of the [emph existing] canvas widget to hold the plot.

................................................................................
A 3-element list containing minimum, maximum and stepsize for the x-axis, in this order.

[arg_def list yaxis in]
A 3-element list containing minimum, maximum and stepsize for the y-axis, in this order.

[arg_def list zaxis in]
A 3-element list containing minimum, maximum and stepsize for the z-axis, in this order.

[arg_def list args in]
Optional list of options (keyword-value pairs). Currently supported: -xlabels to set the
labels for the x-axis.

[list_end]
[para]


[call [cmd ::Plotchart::create3DRibbonPlot] [arg w] [arg yaxis] [arg zaxis]]

................................................................................
[para]

For [emph {vertical barcharts}]:

[list_begin definitions]
[call [cmd \$barchart] plot [arg series] [arg ydata] [arg colour] [opt dir] [opt brightness]]

Add a data series to a barchart. The bars are tagged with a tag "data_\$series" to identify them.

[list_begin arguments]
[arg_def string series in]
Name of the series the values belong to.

[arg_def list ydata in]
A list of values, one for each x-axis label.
................................................................................
[para]

For [emph {horizontal barcharts}]:

[list_begin definitions]
[call [cmd \$barchart] plot [arg series] [arg xdata] [arg colour] [opt dir] [opt brightness]]

Add a data series to a barchart. The bars are tagged with a tag "data_\$series" to identify them.

[list_begin arguments]
[arg_def string series in]
Name of the series the values belong to.

[arg_def list xdata in]
A list of values, one for each y-axis label.

Changes to modules/plotchart/plotchart.tcl.

2253
2254
2255
2256
2257
2258
2259








2260
2261
2262
2263
2264
2265
2266
2267
2268
   foreach {xmin xmax xstep} $xscale {break}
   foreach {ymin ymax ystep} $yscale {break}
   foreach {zmin zmax zstep} $zscale {break}

   viewPort           $w $pxmin $pymin $pxmax $pymax
   world3DCoordinates $w $xmin  $ymin  $zmin  $xmax  $ymax $zmax









   Draw3DAxes         $w $xmin  $ymin  $zmin  $xmax  $ymax $zmax \
                         $xstep $ystep $zstep
   DefaultLegend      $w
   DefaultBalloon     $w

   SetColours $w grey black

   #
   # TODO: Take care of the compatibility for coordsToPixel and friends







>
>
>
>
>
>
>
>

|







2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
   foreach {xmin xmax xstep} $xscale {break}
   foreach {ymin ymax ystep} $yscale {break}
   foreach {zmin zmax zstep} $zscale {break}

   viewPort           $w $pxmin $pymin $pxmax $pymax
   world3DCoordinates $w $xmin  $ymin  $zmin  $xmax  $ymax $zmax

   set names {}
   foreach {keyword value} $args {
       switch -- $keyword {
           "-xlabels" {
                set names $value
           }
       }
   }
   Draw3DAxes         $w $xmin  $ymin  $zmin  $xmax  $ymax $zmax \
                         $xstep $ystep $zstep $names
   DefaultLegend      $w
   DefaultBalloon     $w

   SetColours $w grey black

   #
   # TODO: Take care of the compatibility for coordsToPixel and friends