Tk Library Source Code

Check-in [6a99822bc9]
Login

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

Overview
Comment:New methods implemented for Plotchart (some not finished yet - undocumented)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:6a99822bc9ae5338e40d0d822b881638b72cb9a8
User & Date: arjenmarkus 2007-05-14 17:36:15
Context
2007-05-17
15:57
2007-5-17 Aaron Faupell <afaupell@users.sourceforge.net> * ico.tcl: fixed problem with reading BMPs and updated getFileIcon to search for additional icons (read CLSID) * ico.man: updated example and added verbage to getFileIcon check-in: b1dbdc287d user: afaupell tags: trunk
2007-05-14
17:36
New methods implemented for Plotchart (some not finished yet - undocumented) check-in: 6a99822bc9 user: arjenmarkus tags: trunk
2007-05-11
22:54
simplified endrow width check check-in: 910f1026a0 user: hobbs tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to examples/plotchart/plotdemos1.tcl.

13
14
15
16
17
18
19

20
21
22
23
24
25
26
27
..
34
35
36
37
38
39
40


41
42
43
44
45
46
47

48
49
50



51
52
53
54
55
56
57
...
136
137
138
139
140
141
142































#
# Main code
#
canvas .c  -background white -width 400 -height 200
canvas .c2 -background white -width 400 -height 200
canvas .c3 -background white -width 400 -height 200

pack   .c .c2 .c3 -fill both -side top

toplevel .h
canvas .h.c  -background white -width 400 -height 200
canvas .h.c2 -background white -width 400 -height 200
pack   .h.c .h.c2 -fill both -side top

toplevel .v
................................................................................

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

$s dataconfig series1 -colour "red"



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

   set xold $xnew
   set yold $ynew
}




$s xtext "X-coordinate"
$s ytext "Y-data"
$s title "Aha!"

tkwait visibility .c
$s saveplot "aha.ps"
................................................................................
$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} }





































>
|







 







>
>







>



>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
..
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
...
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

#
# Main code
#
canvas .c  -background white -width 400 -height 200
canvas .c2 -background white -width 400 -height 200
canvas .c3 -background white -width 400 -height 200
canvas .c4 -background white -width 400 -height 200
pack   .c .c2 .c3 .c4 -fill both -side top

toplevel .h
canvas .h.c  -background white -width 400 -height 200
canvas .h.c2 -background white -width 400 -height 200
pack   .h.c .h.c2 -fill both -side top

toplevel .v
................................................................................

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

$s dataconfig series1 -colour "red"
$s dataconfig series2 -colour "blue"
$s dataconfig series3 -colour "magenta"

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

$s interval series2 50.0 40.0 60.0 52.0
$s interval series2 60.0 40.0 60.0

$s xtext "X-coordinate"
$s ytext "Y-data"
$s title "Aha!"

tkwait visibility .c
$s saveplot "aha.ps"
................................................................................
$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::createTXPlot .c4 {2006-01-01 2007-01-01 120} {0.0 100.0 20.0}]

if { 0 } {
set xd    5.0
set yd   20.0
set xold  0.0
set yold 50.0

$s dataconfig series1 -colour "red"
$s dataconfig series2 -colour "blue"

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

$s interval series2 50.0 40.0 60.0 52.0
$s interval series2 60.0 40.0 60.0

$s xtext "X-coordinate"
$s ytext "Y-data"
$s title "Aha!"
}

Changes to modules/plotchart/ChangeLog.






1
2
3
4
5
6
7





2007-05-03 Arjen Markus  <arjenmarkus@users.sourceforge.net>
        * plotpriv.tcl: Expanded the saveplot method (other file formats
                        than PostScript via Img)

2007-04-30 Arjen Markus  <arjenmarkus@users.sourceforge.net>
        * plotchart.tcl: Added radial chart
        * plotpriv.tcl:  Added routines for radial chart
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
2007-05-14 Arjen Markus  <arjenmarkus@users.sourceforge.net>
        * plotchart.tcl: Added an interval and a trend method for XY plots
        * plotpriv.tcl: Implementation of the interval and trend methods
        * plotdemo1.tcl: Examples of these methods

2007-05-03 Arjen Markus  <arjenmarkus@users.sourceforge.net>
        * plotpriv.tcl: Expanded the saveplot method (other file formats
                        than PostScript via Img)

2007-04-30 Arjen Markus  <arjenmarkus@users.sourceforge.net>
        * plotchart.tcl: Added radial chart
        * plotpriv.tcl:  Added routines for radial chart

Changes to modules/plotchart/plotaxis.tcl.

564
565
566
567
568
569
570





















































        set dx 10
        set dy 10
    }

    $legendw move legend   $dx $dy
    $legendw move legendbg $dx $dy
}




























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
        set dx 10
        set dy 10
    }

    $legendw move legend   $dx $dy
    $legendw move legendbg $dx $dy
}

# DrawTimeaxis --
#    Draw the date/time-axis
# Arguments:
#    w           Name of the canvas
#    tmin        Minimum date/time
#    tmax        Maximum date/time
#    tstep       Step size in days
# Result:
#    None
# Side effects:
#    Axis drawn in canvas
#
proc ::Plotchart::DrawTimeaxis { w tmin tmax tdelt } {
    variable scaling

    set scaling($w,tdelt) $tdelt

    $w delete taxis

    $w create line $scaling($w,pxmin) $scaling($w,pymax) \
                   $scaling($w,pxmax) $scaling($w,pymax) \
                   -fill black -tag taxis

    set format ""
    if { [info exists scaling($w,-format,x)] } {
        set format $scaling($w,-format,x)
    }

    set ttmin  [clock scan $tmin]
    set ttmax  [clock scan $tmax]
    set t      [expr {int($ttmin)}]
    set ttdelt [expr {$tdelt*86400.0}]

    set scaling($w,taxis) {}

    while { $t < $ttmax+0.5*$ttdelt } {

        foreach {xcrd ycrd} [coordsToPixel $w $t $scaling($w,ymin)] {break}

        lappend scaling($w,taxis) $xcrd

        if { $format != "" } {
            set tlabel [clock format $t -format $format]
        } else {
            set tlabel [clock format $t -format "%Y-%m-%d"]
        }
        $w create text $xcrd $ycrd -text $tlabel -tag taxis -anchor n
        set t [expr {int($t+$ttdelt)}]
    }

    set scaling($w,tdelt) $tdelt
}

Changes to modules/plotchart/plotchart.man.

707
708
709
710
711
712
713







































714
715
716
717
718
719
720
bar starts at the y-axis on the left. To completely fill the range
of the x-axis, you should draw a bar at the maximum x-coordinate.

[para]
For [emph {xy plots}]:

[list_begin definitions]







































[call [cmd \$xyplot] contourlines [arg xcrd] [arg ycrd] [arg values] [opt classes]]

Draw contour lines for the values given on the grid. The grid is defined
by the xcrd and ycrd arguments (they give the x- and y-coordinates of
the grid cell corners). The values are given at these corners. The
classes determine which contour lines are drawn. If a value on one of
the corners is missing, the contour lines in that cell will not be







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







707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
bar starts at the y-axis on the left. To completely fill the range
of the x-axis, you should draw a bar at the maximum x-coordinate.

[para]
For [emph {xy plots}]:

[list_begin definitions]
[call [cmd \$xyplot] trend [arg series] [arg xcrd] [arg ycrd]]

Draw or update a trend line using the data given sofar.

[list_begin arg]
[arg_def string series in]
Name of the data series the trend line belongs to.

[arg_def float xcrd in]
X-coordinate of the new data point

[arg_def float ycrd in]
Y-coordinate of the new data point
[list_end]

[call [cmd \$xyplot] interval [arg series] [arg xcrd] [arg ymin] [arg ymax] [opt ycentr]]

Add a vertical error interval to the plot. The interval is drawn from
ymin to ymax. If the ycentr argument is given, a symbol is drawn at that
position.

[list_begin arg]
[arg_def string series in]
Name of the data series the interval belongs to.

[arg_def float xcrd in]
X-coordinate of the interval

[arg_def float ymin in]
Minimum y-coordinate of the interval.

[arg_def float ymax in]
Maximum y-coordinate of the interval.

[arg_def float ycentr in]
Y-coordinate to draw the symbol at (optional)

[list_end]

[call [cmd \$xyplot] contourlines [arg xcrd] [arg ycrd] [arg values] [opt classes]]

Draw contour lines for the values given on the grid. The grid is defined
by the xcrd and ycrd arguments (they give the x- and y-coordinates of
the grid cell corners). The values are given at these corners. The
classes determine which contour lines are drawn. If a value on one of
the corners is missing, the contour lines in that cell will not be

Changes to modules/plotchart/plotchart.tcl.

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39


40
41
42
43
44
45
46
...
170
171
172
173
174
175
176
















177
178
179
180
181
182
183
....
1084
1085
1086
1087
1088
1089
1090
























































1091
1092
1093
1094
1095
1096
1097
                    coords3DToPixel polarToPixel \
                    pixelToCoords pixelToIndex determineScale \
                    createXYPlot createPolarPlot createPiechart \
                    createBarchart createHorizontalBarchart \
                    createTimechart createStripchart \
                    createIsometricPlot create3DPlot \
                    createGanttChart createHistogram colorMap \
                    create3DBars createRadialchart


   #
   # Array linking procedures with methods
   #
   set methodProc(xyplot,title)          DrawTitle
   set methodProc(xyplot,xtext)          DrawXtext
   set methodProc(xyplot,ytext)          DrawYtext
   set methodProc(xyplot,plot)           DrawData


   set methodProc(xyplot,grid)           DrawGrid
   set methodProc(xyplot,contourlines)   DrawIsolines
   set methodProc(xyplot,contourfill)    DrawShades
   set methodProc(xyplot,contourbox)     DrawBox
   set methodProc(xyplot,saveplot)       SavePlot
   set methodProc(xyplot,dataconfig)     DataConfig
   set methodProc(xyplot,xconfig)        XConfig
................................................................................
   set methodProc(3dbars,config)         Config3DBars
   set methodProc(3dbars,balloon)        DrawBalloon
   set methodProc(3dbars,balloonconfig)  ConfigBalloon
   set methodProc(radialchart,title)     DrawTitle
   set methodProc(radialchart,plot)      DrawRadial
   set methodProc(radialchart,saveplot)  SavePlot
   set methodProc(radialchart,balloon)   DrawBalloon

















   #
   # Auxiliary parameters
   #
   variable torad
   set torad [expr {3.1415926/180.0}]

................................................................................
   set settings($w,style)  $style
   set settings($w,number) [llength $names]

   DrawRadialSpokes $w $names
   DefaultLegend  $w
   DefaultBalloon $w

























































   return $newchart
}

# Load the private procedures
#
source [file join [file dirname [info script]] "plotpriv.tcl"]
source [file join [file dirname [info script]] "plotaxis.tcl"]







|
>








>
>







 







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







 







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







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
...
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
....
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
                    coords3DToPixel polarToPixel \
                    pixelToCoords pixelToIndex determineScale \
                    createXYPlot createPolarPlot createPiechart \
                    createBarchart createHorizontalBarchart \
                    createTimechart createStripchart \
                    createIsometricPlot create3DPlot \
                    createGanttChart createHistogram colorMap \
                    create3DBars createRadialchart \
                    createTXPlot

   #
   # Array linking procedures with methods
   #
   set methodProc(xyplot,title)          DrawTitle
   set methodProc(xyplot,xtext)          DrawXtext
   set methodProc(xyplot,ytext)          DrawYtext
   set methodProc(xyplot,plot)           DrawData
   set methodProc(xyplot,interval)       DrawInterval
   set methodProc(xyplot,trend)          DrawTrendLine
   set methodProc(xyplot,grid)           DrawGrid
   set methodProc(xyplot,contourlines)   DrawIsolines
   set methodProc(xyplot,contourfill)    DrawShades
   set methodProc(xyplot,contourbox)     DrawBox
   set methodProc(xyplot,saveplot)       SavePlot
   set methodProc(xyplot,dataconfig)     DataConfig
   set methodProc(xyplot,xconfig)        XConfig
................................................................................
   set methodProc(3dbars,config)         Config3DBars
   set methodProc(3dbars,balloon)        DrawBalloon
   set methodProc(3dbars,balloonconfig)  ConfigBalloon
   set methodProc(radialchart,title)     DrawTitle
   set methodProc(radialchart,plot)      DrawRadial
   set methodProc(radialchart,saveplot)  SavePlot
   set methodProc(radialchart,balloon)   DrawBalloon
   set methodProc(txplot,title)          DrawTitle
   set methodProc(txplot,xtext)          DrawXtext
   set methodProc(txplot,ytext)          DrawYtext
   set methodProc(txplot,plot)           DrawTimeData
   set methodProc(txplot,interval)       DrawInterval
   set methodProc(txplot,saveplot)       SavePlot
   set methodProc(txplot,dataconfig)     DataConfig
   set methodProc(txplot,xconfig)        XConfig
   set methodProc(txplot,yconfig)        YConfig
   set methodProc(txplot,xticklines)     DrawXTicklines
   set methodProc(txplot,yticklines)     DrawYTicklines
   set methodProc(txplot,background)     BackgroundColour
   set methodProc(txplot,legendconfig)   LegendConfigure
   set methodProc(txplot,legend)         DrawLegend
   set methodProc(txplot,balloon)        DrawBalloon
   set methodProc(txplot,balloonconfig)  ConfigBalloon

   #
   # Auxiliary parameters
   #
   variable torad
   set torad [expr {3.1415926/180.0}]

................................................................................
   set settings($w,style)  $style
   set settings($w,number) [llength $names]

   DrawRadialSpokes $w $names
   DefaultLegend  $w
   DefaultBalloon $w

   return $newchart
}

# createTXPlot --
#    Create a command for drawing a TX plot (x versus date/time)
# Arguments:
#    w           Name of the canvas
#    tscale      Minimum, maximum and step for date/time-axis (initial)
#                (values must be valid dates and the step is in days)
#    yscale      Minimum, maximum and step for vertical axis
# Result:
#    Name of a new command
# Note:
#    The entire canvas will be dedicated to the TX plot.
#    The plot will be drawn with axes
#
proc ::Plotchart::createTXPlot { w tscale xscale } {
   variable data_series

   foreach s [array names data_series "$w,*"] {
      unset data_series($s)
   }

   set newchart "txplot_$w"
   interp alias {} $newchart {} ::Plotchart::PlotHandler txplot $w

   foreach {pxmin pymin pxmax pymax} [MarginsRectangle $w] {break}

   foreach {tmin tmax tdelt} $tscale {break}

   set xmin  [clock scan $tmin]
   set xmax  [clock scan $tmax]
   set xdelt [expr {86400*$tdelt}]

   foreach {ymin ymax ydelt} $xscale {break}

   if { $xdelt == 0.0 || $ydelt == 0.0 } {
      return -code error "Step size can not be zero"
   }

   if { ($xmax-$xmin)*$xdelt < 0.0 } {
      set xdelt [expr {-$xdelt}]
   }
   if { ($ymax-$ymin)*$ydelt < 0.0 } {
      set ydelt [expr {-$ydelt}]
   }

   viewPort         $w $pxmin $pymin $pxmax $pymax
   worldCoordinates $w $xmin  $ymin  $xmax  $ymax

   DrawYaxis        $w $ymin  $ymax  $ydelt
   DrawTimeaxis     $w $tmin  $tmax  $tdelt
   DrawMask         $w
   DefaultLegend    $w
   DefaultBalloon   $w

   return $newchart
}

# Load the private procedures
#
source [file join [file dirname [info script]] "plotpriv.tcl"]
source [file join [file dirname [info script]] "plotaxis.tcl"]

Changes to modules/plotchart/plotpriv.tcl.

23
24
25
26
27
28
29
30
31
32
33





34
35
36
37
38
39
40
41
42
43
44
45
46
...
428
429
430
431
432
433
434

























































435
436
437
438
439
440
441
....
1163
1164
1165
1166
1167
1168
1169













































































       #
       # Wait for the canvas to become visible - just in case.
       # Then write the file
       #
       update idletasks
       $w postscript -file $filename
   } else {
       puts ">>$args"
       if { [llength $args] == 2 && [lindex $args 0] == "-format" } {
           package require Img
           set format [lindex $args 1]





           raise [winfo toplevel $w]
           puts "Raised";update idletasks
          # tkwait visibility [winfo toplevel $w]
           after 2000 {set ::Plotchart::waited 0}
           vwait ::Plotchart::waited
           puts "Visible";update idletasks
           set img [image create photo -data $w -format window]
           $img write $filename -format $format
       } else {
           return -code error "Unknown option: $args - must be: -format img-format"
       }
   }
}
................................................................................
      foreach {pxminorg pyminorg} [coordsToPixel $w $xminorg $ymin] {break}
      foreach {pxmin pymin}       [coordsToPixel $w $xmin    $ymin] {break}
      $w move data [expr {$pxminorg-$pxmin+1}] 0
   }

   DrawData $w $series $xcrd $ycrd
}


























































# DrawSymbolPixel --
#    Draw a symbol in an xy-plot, polar plot or stripchart
# Arguments:
#    w           Name of the canvas
#    series      Data series
#    pxcrd       Next x (pixel) coordinate
................................................................................
   } else {
       set fillcolour ""
   }

   set id [$w create polygon $coords -outline $colour -width $thickness -fill $fillcolour]
   $w lower $id
}




















































































<



>
>
>
>
>

<



<







 







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







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
....
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
       #
       # Wait for the canvas to become visible - just in case.
       # Then write the file
       #
       update idletasks
       $w postscript -file $filename
   } else {

       if { [llength $args] == 2 && [lindex $args 0] == "-format" } {
           package require Img
           set format [lindex $args 1]

           #
           # This is a kludge:
           # Somehow tkwait does not always work (on Windows XP, that is)
           #
           raise [winfo toplevel $w]

          # tkwait visibility [winfo toplevel $w]
           after 2000 {set ::Plotchart::waited 0}
           vwait ::Plotchart::waited

           set img [image create photo -data $w -format window]
           $img write $filename -format $format
       } else {
           return -code error "Unknown option: $args - must be: -format img-format"
       }
   }
}
................................................................................
      foreach {pxminorg pyminorg} [coordsToPixel $w $xminorg $ymin] {break}
      foreach {pxmin pymin}       [coordsToPixel $w $xmin    $ymin] {break}
      $w move data [expr {$pxminorg-$pxmin+1}] 0
   }

   DrawData $w $series $xcrd $ycrd
}

# DrawInterval --
#    Draw the data as an error interval in an XY-plot
# Arguments:
#    w           Name of the canvas
#    series      Data series
#    xcrd        X coordinate
#    ymin        Minimum y coordinate
#    ymax        Maximum y coordinate
#    ycentr      Central y coordinate (optional)
# Result:
#    None
# Side effects:
#    New interval drawn in canvas
#
proc ::Plotchart::DrawInterval { w series xcrd ymin ymax {ycentr {}} } {
   variable data_series
   variable scaling

   #
   # Check for missing values
   #
   if { $xcrd == "" || $ymin == "" || $ymax == "" } {
       return
   }

   #
   # Draw the line piece
   #
   set colour "black"
   if { [info exists data_series($w,$series,-colour)] } {
      set colour $data_series($w,$series,-colour)
   }

   foreach {pxcrd pymin} [coordsToPixel $w $xcrd $ymin] {break}
   foreach {pxcrd pymax} [coordsToPixel $w $xcrd $ymax] {break}
   if { $ycentr != "" } {
       foreach {pxcrd pycentr} [coordsToPixel $w $xcrd $ycentr] {break}
   }

   $w create line $pxcrd $pymin $pxcrd $pymax \
                        -fill $colour -tag data
   $w create line [expr {$pxcrd-3}] $pymin [expr {$pxcrd+3}] $pymin \
                        -fill $colour -tag data
   $w create line [expr {$pxcrd-3}] $pymax [expr {$pxcrd+3}] $pymax \
                        -fill $colour -tag data

   if { $ycentr != "" } {
      set symbol "dot"
      if { [info exists data_series($w,$series,-symbol)] } {
         set symbol $data_series($w,$series,-symbol)
      }
      DrawSymbolPixel $w $series $pxcrd $pycentr $symbol $colour "data"
   }

   $w lower data
}

# DrawSymbolPixel --
#    Draw a symbol in an xy-plot, polar plot or stripchart
# Arguments:
#    w           Name of the canvas
#    series      Data series
#    pxcrd       Next x (pixel) coordinate
................................................................................
   } else {
       set fillcolour ""
   }

   set id [$w create polygon $coords -outline $colour -width $thickness -fill $fillcolour]
   $w lower $id
}

# DrawTrendLine --
#    Draw a trend line based on the given data in an XY-plot
# Arguments:
#    w           Name of the canvas
#    series      Data series
#    xcrd        Next x coordinate
#    ycrd        Next y coordinate
# Result:
#    None
# Side effects:
#    New/updated trend line drawn in canvas
#
proc ::Plotchart::DrawTrendLine { w series xcrd ycrd } {
    variable data_series
    variable scaling

    #
    # Check for missing values
    #
    if { $xcrd == "" || $ycrd == "" } {
        return
    }

    #
    # Compute the coefficients of the line
    #
    if { [info exists data_series($w,$series,xsum)] } {
        set nsum  [expr {$data_series($w,$series,nsum)  + 1.0}]
        set xsum  [expr {$data_series($w,$series,xsum)  + $xcrd}]
        set x2sum [expr {$data_series($w,$series,x2sum) + $xcrd*$xcrd}]
        set ysum  [expr {$data_series($w,$series,ysum)  + $ycrd}]
        set xysum [expr {$data_series($w,$series,xysum) + $ycrd*$xcrd}]
    } else {
        set nsum  [expr {1.0}]
        set xsum  [expr {$xcrd}]
        set x2sum [expr {$xcrd*$xcrd}]
        set ysum  [expr {$ycrd}]
        set xysum [expr {$ycrd*$xcrd}]
    }

    if { $nsum*$x2sum != $xsum*$xsum } {
        set a [expr {($nsum*$xysum-$xsum*$ysum)/($nsum*$x2sum - $xsum*$xsum)}]
    } else {
        set a 0.0
    }
    set b [expr {($ysum-$a*$xsum)/$nsum}]

    set xmin $scaling($w,xmin)
    set xmax $scaling($w,xmax)

    foreach {pxmin pymin} [coordsToPixel $w $xmin [expr {$a*$xmin+$b}]] {break}
    foreach {pxmax pymax} [coordsToPixel $w $xmax [expr {$a*$xmax+$b}]] {break}

    #
    # Draw the actual line
    #
    set colour "black"
    if { [info exists data_series($w,$series,-colour)] } {
        set colour $data_series($w,$series,-colour)
    }

    if { [info exists data_series($w,$series,trend)] } {
        $w coords $data_series($w,$series,trend) $pxmin $pymin $pxmax $pymax
    } else {
        set data_series($w,$series,trend) \
            [$w create line $pxmin $pymin $pxmax $pymax -fill $colour -tag data]
    }

    $w lower data

    set data_series($w,$series,nsum)  $nsum
    set data_series($w,$series,xsum)  $xsum
    set data_series($w,$series,x2sum) $x2sum
    set data_series($w,$series,ysum)  $ysum
    set data_series($w,$series,xysum) $xysum
}

Changes to modules/plotchart/scaling.tcl.

70
71
72
73
74
75
76
















































77
78
79
80
81
82
83
..
84
85
86
87
88
89
90




   }
   if { [tgt $nicemin $xmin] } {
      set nicemin [expr {$nicemin-$step*$factor}]
   }

   return [list $nicemin $nicemax [expr {$step*$factor}]]
}

















































if 0 {
    #
    # Some simple test cases
    #
    namespace import ::Plotchart::determineScale
    puts [determineScale 0.1 1.0]
................................................................................
    puts [determineScale 0.001 0.01]
    puts [determineScale -0.2 0.9]
    puts [determineScale -0.25 0.85]
    puts [determineScale -0.25 0.7999]
    puts [determineScale 10001 10010]
    puts [determineScale 10001 10015]
}











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







 







>
>
>
>
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
   }
   if { [tgt $nicemin $xmin] } {
      set nicemin [expr {$nicemin-$step*$factor}]
   }

   return [list $nicemin $nicemax [expr {$step*$factor}]]
}

# determineTimeScale --
#    Determine nice date/time values for an axis from the given extremes
#
# Arguments:
#    tmin      Minimum date/time
#    tmax      Maximum date/time
# Result:
#    A list of three values, a nice minimum and maximum
#    and stepsize
# Note:
#    tmin is assumed to be smaller or equal tmax
#
proc ::Plotchart::determineTimeScale { tmin tmax } {
    set ttmin [clock scan $tmin]
    set ttmax [clock scan $tmax]

    set dt [expr {abs($ttmax-$ttmin)}]

    if { $dt == 0.0 } {
        set dt 86400.0
        set ttmin [expr {$ttmin-$dt}]
        set ttmax [expr {$ttmin+$dt}]
    }

    foreach {limit step} {2.0 0.5 5.0 1.0 10.0 2.0 50.0 7.0 300.0 30.0 1.0e10 365.0} {
        if { $dt/86400.0 < $limit } {
            break
        }
    }

    set nicemin [expr {$step*floor($ttmin/$step)}]
    set nicemax [expr {$step*floor($ttmax/$step)}]

    if { $nicemax < $ttmax } {
        set nicemax [expr {$nicemax+$step}]
    }
    if { $nicemin > $ttmin } {
        set nicemin [expr {$nicemin-$step}]
    }

    set nicemin [expr {int($nicemin)}]
    set nicemax [expr {int($nicemax)}]

    return [list [clock format $nicemin -format "%Y-%m-%d %H:%M:%S"] \
                 [clock format $nicemax -format "%Y-%m-%d %H:%M:%S"] \
                 $step]
}

if 0 {
    #
    # Some simple test cases
    #
    namespace import ::Plotchart::determineScale
    puts [determineScale 0.1 1.0]
................................................................................
    puts [determineScale 0.001 0.01]
    puts [determineScale -0.2 0.9]
    puts [determineScale -0.25 0.85]
    puts [determineScale -0.25 0.7999]
    puts [determineScale 10001 10010]
    puts [determineScale 10001 10015]
}
if 1 {
    puts [::Plotchart::determineTimeScale "2007-01-15" "2007-01-16"]
    puts [::Plotchart::determineTimeScale "2007-03-15" "2007-06-16"]
}