1#! /bin/sh 2# -*- tcl -*- \ 3exec tclsh "$0" ${1+"$@"} 4 5package require Tcl 8.4 6package require Tk 7package require Plotchart 8 9# plotdemos1.tcl -- 10# Test program 1 for the Plotchart package 11# 12 13# 14# Main code 15# 16canvas .c -background white -width 400 -height 200 17canvas .c2 -background white -width 400 -height 200 18canvas .c3 -background white -width 400 -height 200 19canvas .c4 -background white -width 400 -height 200 20pack .c .c2 .c3 .c4 -fill both -side top 21 22toplevel .h 23canvas .h.c -background white -width 400 -height 200 24canvas .h.c2 -background white -width 400 -height 200 25pack .h.c .h.c2 -fill both -side top 26 27toplevel .v 28canvas .v.c -background white -width 400 -height 200 29canvas .v.c2 -background white -width 400 -height 200 30canvas .v.c3 -background white -width 400 -height 200 31pack .v.c .v.c2 .v.c3 -fill both -side top 32 33set s [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {0.0 100.0 20.0}] 34set r [::Plotchart::createRightAxis .c {0.0 0.1 0.01}] 35 36set xd 5.0 37set yd 20.0 38set xold 0.0 39set yold 50.0 40 41$s dataconfig series1 -colour "red" 42$s dataconfig series2 -colour "blue" 43$s dataconfig series3 -colour "magenta" 44 45for { set i 0 } { $i < 20 } { incr i } { 46 set xnew [expr {$xold+$xd}] 47 set ynew [expr {$yold+(rand()-0.5)*$yd}] 48 set ynew2 [expr {$yold+(rand()-0.5)*2.0*$yd}] 49 $s plot series1 $xnew $ynew 50 $s plot series2 $xnew $ynew2 51 $s trend series3 $xnew $ynew2 52 set xold $xnew 53 set yold $ynew 54} 55 56$s interval series2 50.0 40.0 60.0 52.0 57$s interval series2 60.0 40.0 60.0 58 59$s xtext "X-coordinate" 60$s ytext "Y-data" 61$r ytext "Right axis" 62$s title "Aha!" 63 64# 65# Some data for the right axis 66# 67$r dataconfig right -type both -symbol circle -colour green 68$r plot right 10.0 0.01 69$r plot right 30.0 0.03 70$r plot right 40.0 0.02 71 72tkwait visibility .c 73#$s saveplot "aha.ps" 74 75set s [::Plotchart::createPiechart .c2] 76 77$s plot {"Long names" 10 "Short names" 30 "Average" 40 78 "Ultra-short names" 5} 79# 80# Note: title should be shifted up 81# - distinguish a separate title area 82# 83$s title "Okay - this works" 84 85 86 87set s [::Plotchart::createPolarplot .c3 {3.0 1.0}] 88 89for { set angle 0 } { $angle < 360.0 } { set angle [expr {$angle+10.0}] } { 90 set rad [expr {1.0+cos($angle*$::Plotchart::torad)}] 91 $s plot "cardioid" $rad $angle 92} 93 94$s title "Cardioid" 95 96 97set s [::Plotchart::createBarchart .h.c {A B C D E} {0.0 10.0 2.0} 2.5] 98 99$s legend series1 "Series 1" 100$s legend series2 "Series 2" 101 102$s plot series1 {1.0 4.0 6.0 1.0 7.0} red 103$s plot series2 {0.0 3.0 7.0 9.3 2.0} green 104$s title "Arbitrary data" 105 106 107set s [::Plotchart::createBarchart .h.c2 {A B C D E} {0.0 20.0 5.0} stacked] 108 109$s plot series1 {1.0 4.0 6.0 1.0 7.0} red 110$s plot series2 {0.0 3.0 7.0 9.3 2.0} green 111$s title "Stacked diagram" 112 113 114 115set s [::Plotchart::createHorizontalBarchart .v.c {0.0 10.0 2.0} {A B C D E} 2] 116 117$s plot series1 {1.0 4.0 6.0 1.0 7.0} red 118$s plot series2 {0.0 3.0 7.0 9.3 2.0} green 119$s title "Arbitrary data" 120 121 122set s [::Plotchart::createHorizontalBarchart .v.c2 {0.0 20.0 5.0} {A B C D E} stacked] 123 124$s plot series1 {1.0 4.0 6.0 1.0 7.0} red 125$s plot series2 {0.0 3.0 7.0 9.3 2.0} green 126$s title "Stacked diagram" 127 128 129set s [::Plotchart::createTimechart .v.c3 "1 january 2004" \ 130 "31 december 2004" 4] 131 132$s period "Spring" "1 march 2004" "1 june 2004" green 133$s period "Summer" "1 june 2004" "1 september 2004" yellow 134$s vertline "1 jan" "1 january 2004" 135$s vertline "1 apr" "1 april 2004" 136$s vertline "1 jul" "1 july 2004" 137$s vertline "1 oct" "1 october 2004" 138$s milestone "Longest day" "21 july 2004" 139$s title "Seasons (northern hemisphere)" 140 141proc cowboyhat {x y} { 142 set x1 [expr {$x/9.0}] 143 set y1 [expr {$y/9.0}] 144 145 expr { 3.0 * (1.0-($x1*$x1+$y1*$y1))*(1.0-($x1*$x1+$y1*$y1)) } 146} 147 148toplevel .h3 149canvas .h3.c -bg white -width 400 -height 300 150canvas .h3.c2 -bg white -width 400 -height 250 151pack .h3.c .h3.c2 152 153set s [::Plotchart::create3DPlot .h3.c {0 10 3} {-10 10 10} {0 10 2.5}] 154$s title "3D Plot" 155$s plotfunc cowboyhat 156 157set s [::Plotchart::create3DPlot .h3.c2 {0 10 3} {-10 10 10} {0 10 2.5}] 158$s title "3D Plot - data " 159$s colour "green" "black" 160$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} } 161 162 163set s [::Plotchart::createTXPlot .c4 {2006-01-01 2007-01-01 120} {0.0 100.0 20.0}] 164 165$s dataconfig series1 -colour "red" 166$s dataconfig series2 -colour "blue" 167 168$s xtext "Time" 169$s ytext "Data" 170$s xticklines 171 172$s plot series1 2006-02-01 10.0 173$s plot series1 2006-02-11 50.0 174$s plot series1 2006-03-01 50.0 175$s plot series1 2006-07-01 40.0 176$s plot series1 2006-08-21 20.0 177$s plot series1 2006-08-22 1.0 178$s plot series1 2006-12-11 78.0 179 180$s plot series2 2006-03-01 110.0 181$s plot series2 2006-04-11 50.0 182$s plot series2 2006-07-28 20.0 183$s plot series2 2006-10-21 99.0 184$s plot series2 2006-11-22 1.0 185$s plot series2 2006-12-31 78.0 186