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 Side-by-Side Diffs Ignore Whitespace Patch

Changes to examples/plotchart/plotdemos1.tcl.

     1      1   #!/usr/bin/env tclsh
     2      2   ## -*- tcl -*-
     3      3   
            4  +source ../../modules/plotchart/plotchart.tcl
     4      5   package require Tcl 8.5
     5      6   package require Tk
     6      7   package require Plotchart
     7      8   
     8      9   # plotdemos1.tcl --
     9     10   #    Test program 1 for the Plotchart package
    10     11   #
................................................................................
   151    152   canvas .h3.c3 -bg white -width 400 -height 250
   152    153   pack .h3.c .h3.c2 .h3.c3
   153    154   
   154    155   set s [::Plotchart::create3DPlot .h3.c {0 10 3} {-10 10 10} {0 10 2.5}]
   155    156   $s title "3D Plot"
   156    157   $s plotfunc cowboyhat
   157    158   
   158         -set s [::Plotchart::create3DPlot .h3.c2 {0 10 3} {-10 10 10} {0 10 2.5}]
          159  +::Plotchart::plotconfig 3dplot xaxis format "%4.2f"
          160  +
          161  +set s [::Plotchart::create3DPlot .h3.c2 {0 10 3} {-10 10 10} {0 10 2.5} -xlabels {A B C}]
   159    162   $s title "3D Plot - data "
   160    163   $s colour "green" "black"
   161    164   $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} }
   162    165   
   163    166   set s [::Plotchart::create3DPlot .h3.c3 {0 10 3} {-10 10 10} {0 10 2.5}]
   164    167   $s title "3D Plot - data "
   165    168   $s colour "green" "black"

Changes to modules/plotchart/ChangeLog.

     1      1   2015-04-11  Arjen Markus  <arjenmarkus@users,sourceforge.net>
     2      2   	* plotchart.tcl: Properly place the table wrt a title and subtitle, take care of fonts (patch by Frank Gover)
            3  +	                 Support setting axis labels at 3D plot (patch by Frank Gover)
     3      4   	* plottable.tcl: Correct drawing of the row in a table, take care of fonts (patch by Frank Gover)
     4      5   	* plotconfig.tcl: Extend calculation of font metrics, optional font and linespacing (patch by Frank Gover)
            6  +	* plot3d.tcl:    Support formatting of the numerical axis labels for 3D plots (requested by Frank Gover)
            7  +	* plotchart.man: Bumped version to 2.3.4, added documentation of the tags for bars in a barchart.
            8  +	* pkgIndex.tcl:  Bumped version to 2.3.4
            9  +	* plotdemos1.tcl: Small changes to the 3D plot demo - axis labels and formatting
     5     10   
     6     11   2014-12-14  Arjen Markus  <arjenmarkus@users,sourceforge.net>
     7     12   	* plotchart.tcl: Introduce an option -xlabelangle for barcharts (request by Frank Gover)
     8     13   	* plotaxis.tcl: Implement the option -xlabelangle for the labels of barcharts, also add a call
     9     14   	                to worldCoordinates to reset the scaling (cause of xconfig -scale not working
    10     15   	                correctly)
    11     16   	* plotpriv.tcl: Correct the margins if subtext is used (required for the masking rectangles)

Changes to modules/plotchart/plot3d.tcl.

    33     33   # Side effects:
    34     34   #    Axes drawn in canvas
    35     35   #
    36     36   proc ::Plotchart::Draw3DAxes { w xmin  ymin  zmin
    37     37                                    xmax  ymax  zmax
    38     38                                    xstep ystep zstep
    39     39                                    {names {}}        } {
           40  +   variable config
    40     41      variable scaling
    41     42   
    42     43      $w delete axis3d
    43     44   
    44     45      #
    45     46      # Create the support lines first
    46     47      #
................................................................................
    63     64      }
    64     65      $w create line $pxxmin $pyxmin $pxymx2 $pyymx2 -fill black -tag axis3d
    65     66      $w create line $pxxmin $pyxmin $pxzmx2 $pyzmx2 -fill black -tag axis3d
    66     67   
    67     68      #
    68     69      # Numbers to the z-axis
    69     70      #
           71  +   set format $config($w,zaxis,format)
    70     72      set z $zmin
    71     73      while { $z < $zmax+0.5*$zstep } {
    72     74         foreach {xcrd ycrd} [coords3DToPixel $w $xmin $ymin $z] {break}
    73     75         set xcrd2 [expr {$xcrd-3}]
    74     76         set xcrd3 [expr {$xcrd-5}]
           77  +
           78  +      set zt [format "%.12g" $z]
           79  +      if { $format != "" } {
           80  +          set zt [FormatNumber $format $z]
           81  +      }
    75     82   
    76     83         $w create line $xcrd2 $ycrd $xcrd $ycrd -tag axis3d
    77         -      $w create text $xcrd3 $ycrd -text $z -tag axis3d -anchor e
           84  +      $w create text $xcrd3 $ycrd -text $zt -tag axis3d -anchor e
    78     85         set z [expr {$z+$zstep}]
    79     86      }
    80     87   
    81     88      #
    82     89      # Numbers or labels to the x-axis (shown on the right!)
    83     90      #
           91  +   set format $config($w,xaxis,format)
    84     92      if { $xstep > 0 } {
    85     93          if { $names eq "" } {
    86     94              set x $xmin
    87     95              while { $x < $xmax+0.5*$xstep } {
    88     96                  foreach {xcrd ycrd} [coords3DToPixel $w $x $ymax $zmin] {break}
    89     97                  set xcrd2 [expr {$xcrd+4}]
    90     98                  set xcrd3 [expr {$xcrd+6}]
    91     99   
    92    100                  $w create line $xcrd2 $ycrd $xcrd $ycrd -tag axis3d
    93         -               $w create text $xcrd3 $ycrd -text $x -tag axis3d -anchor w
          101  +
          102  +               set xt [format "%.12g" $x]
          103  +               if { $format != "" } {
          104  +                   set xt [FormatNumber $format $x]
          105  +               }
          106  +               $w create text $xcrd3 $ycrd -text $xt -tag axis3d -anchor w
    94    107                  set x [expr {$x+$xstep}]
    95    108              }
    96    109          } else {
    97    110              set x [expr {$xmin+0.5*$xstep}]
    98    111              foreach label $names {
    99    112                  foreach {xcrd ycrd} [coords3DToPixel $w $x $ymax $zmin] {break}
   100    113                  set xcrd2 [expr {$xcrd+6}]
................................................................................
   104    117              }
   105    118          }
   106    119      }
   107    120   
   108    121      #
   109    122      # Numbers to the y-axis (shown in front!)
   110    123      #
          124  +   set format $config($w,yaxis,format)
   111    125      set y $ymin
   112    126      while { $y < $ymax+0.5*$ystep } {
   113    127         foreach {xcrd ycrd} [coords3DToPixel $w $xmin $y $zmin] {break}
   114    128         set ycrd2 [expr {$ycrd+3}]
   115    129         set ycrd3 [expr {$ycrd+5}]
          130  +
          131  +      set yt [format "%.12g" $y]
          132  +      if { $format != "" } {
          133  +          set yt [FormatNumber $format $y]
          134  +      }
   116    135   
   117    136         $w create line $xcrd $ycrd2 $xcrd $ycrd -tag axis3d
   118         -      $w create text $xcrd $ycrd3 -text $y -tag axis3d -anchor n
          137  +      $w create text $xcrd $ycrd3 -text $yt -tag axis3d -anchor n
   119    138         set y [expr {$y+$ystep}]
   120    139      }
   121    140   
   122    141      set scaling($w,xstep) $xstep
   123    142      set scaling($w,ystep) $ystep
   124    143      set scaling($w,zstep) $zstep
   125    144   

Changes to modules/plotchart/plotchart.man.

     1      1   [comment {-*- tcl -*- doctools manpage}]
     2         -[manpage_begin Plotchart n 2.3.2]
            2  +[manpage_begin Plotchart n 2.3.4]
     3      3   [copyright {2013 Arjen Markus <arjenmarkus@users.sourceforge.net>}]
     4      4   [moddesc   Plotchart]
     5      5   [titledesc {Simple plotting and charting package}]
     6      6   [require Tcl [opt 8.5]]
     7      7   [require Tk [opt 8.5]]
     8         -[require Plotchart [opt 2.3.2]]
            8  +[require Plotchart [opt 2.3.4]]
     9      9   
    10     10   [description]
    11     11   [para]
    12     12   
    13     13   Plotchart is a Tcl-only package that focuses on the easy creation of
    14     14   xy-plots, barcharts and other common types of graphical presentations.
    15     15   The emphasis is on ease of use, rather than flexibility. The procedures
................................................................................
   378    378   [arg_def list args in]
   379    379   Zero or more options - see the XY-plot for more information.
   380    380   
   381    381   [list_end]
   382    382   [para]
   383    383   
   384    384   
   385         -[call [cmd ::Plotchart::create3DPlot] [arg w] [arg xaxis] [arg yaxis] [arg zaxis]]
          385  +[call [cmd ::Plotchart::create3DPlot] [arg w] [arg xaxis] [arg yaxis] [arg zaxis] [arg args]]
   386    386   
   387    387   Create a new 3D plot.
   388    388   
   389    389   [list_begin arguments]
   390    390   [arg_def widget w in]
   391    391   Name of the [emph existing] canvas widget to hold the plot.
   392    392   
................................................................................
   394    394   A 3-element list containing minimum, maximum and stepsize for the x-axis, in this order.
   395    395   
   396    396   [arg_def list yaxis in]
   397    397   A 3-element list containing minimum, maximum and stepsize for the y-axis, in this order.
   398    398   
   399    399   [arg_def list zaxis in]
   400    400   A 3-element list containing minimum, maximum and stepsize for the z-axis, in this order.
          401  +
          402  +[arg_def list args in]
          403  +Optional list of options (keyword-value pairs). Currently supported: -xlabels to set the
          404  +labels for the x-axis.
   401    405   
   402    406   [list_end]
   403    407   [para]
   404    408   
   405    409   
   406    410   [call [cmd ::Plotchart::create3DRibbonPlot] [arg w] [arg yaxis] [arg zaxis]]
   407    411   
................................................................................
  2167   2171   [para]
  2168   2172   
  2169   2173   For [emph {vertical barcharts}]:
  2170   2174   
  2171   2175   [list_begin definitions]
  2172   2176   [call [cmd \$barchart] plot [arg series] [arg ydata] [arg colour] [opt dir] [opt brightness]]
  2173   2177   
  2174         -Add a data series to a barchart.
         2178  +Add a data series to a barchart. The bars are tagged with a tag "data_\$series" to identify them.
  2175   2179   
  2176   2180   [list_begin arguments]
  2177   2181   [arg_def string series in]
  2178   2182   Name of the series the values belong to.
  2179   2183   
  2180   2184   [arg_def list ydata in]
  2181   2185   A list of values, one for each x-axis label.
................................................................................
  2217   2221   [para]
  2218   2222   
  2219   2223   For [emph {horizontal barcharts}]:
  2220   2224   
  2221   2225   [list_begin definitions]
  2222   2226   [call [cmd \$barchart] plot [arg series] [arg xdata] [arg colour] [opt dir] [opt brightness]]
  2223   2227   
  2224         -Add a data series to a barchart.
         2228  +Add a data series to a barchart. The bars are tagged with a tag "data_\$series" to identify them.
  2225   2229   
  2226   2230   [list_begin arguments]
  2227   2231   [arg_def string series in]
  2228   2232   Name of the series the values belong to.
  2229   2233   
  2230   2234   [arg_def list xdata in]
  2231   2235   A list of values, one for each y-axis label.

Changes to modules/plotchart/plotchart.tcl.

  2253   2253      foreach {xmin xmax xstep} $xscale {break}
  2254   2254      foreach {ymin ymax ystep} $yscale {break}
  2255   2255      foreach {zmin zmax zstep} $zscale {break}
  2256   2256   
  2257   2257      viewPort           $w $pxmin $pymin $pxmax $pymax
  2258   2258      world3DCoordinates $w $xmin  $ymin  $zmin  $xmax  $ymax $zmax
  2259   2259   
         2260  +   set names {}
         2261  +   foreach {keyword value} $args {
         2262  +       switch -- $keyword {
         2263  +           "-xlabels" {
         2264  +                set names $value
         2265  +           }
         2266  +       }
         2267  +   }
  2260   2268      Draw3DAxes         $w $xmin  $ymin  $zmin  $xmax  $ymax $zmax \
  2261         -                         $xstep $ystep $zstep
         2269  +                         $xstep $ystep $zstep $names
  2262   2270      DefaultLegend      $w
  2263   2271      DefaultBalloon     $w
  2264   2272   
  2265   2273      SetColours $w grey black
  2266   2274   
  2267   2275      #
  2268   2276      # TODO: Take care of the compatibility for coordsToPixel and friends