1#! /bin/sh
2# -*- tcl -*- \
3exec tclsh "$0" ${1+"$@"}
4
5package require Tcl 8.4
6package require Tk
7
8package require Plotchart
9
10# plotdemos2.tcl --
11#    Second test program for the Plotchart package
12#
13
14#
15# Main code
16#
17canvas .c  -background white -width 400 -height 200
18canvas .c2 -background white -width 400 -height 200
19pack   .c .c2 -fill both -side top
20
21#
22# Set up a strip chart
23#
24set s [::Plotchart::createStripchart .c {0.0 100.0 10.0} {0.0 100.0 20.0}]
25
26proc gendata {slipchart xold xd yold yd} {
27   set xnew [expr {$xold+$xd}]
28   set ynew [expr {$yold+(rand()-0.5)*$yd}]
29   set ynew2 [expr {$yold+(rand()-0.5)*2.0*$yd}]
30   $slipchart plot series1 $xnew $ynew
31   $slipchart plot series2 $xnew $ynew2
32
33   if { $xnew < 200 } {
34   after 500 [list gendata $slipchart $xnew $xd $ynew $yd]
35   }
36}
37
38after 100 [list gendata $s 0.0 15.0 50.0 30.0]
39
40$s title "Aha!"
41
42#
43# Set up an isometric plot
44#
45set s [::Plotchart::createIsometricPlot .c2 {0.0 100.0} {0.0 200.0} noaxes]
46::Plotchart::setZoomPan .c2
47$s plot rectangle        10.0 10.0 50.0 50.0 green
48$s plot filled-rectangle 20.0 20.0 40.0 40.0 red
49$s plot filled-circle    70.0 70.0 40.0 yellow
50$s plot circle           70.0 70.0 42.0
51
52#
53# Check the symbols
54#
55toplevel .h
56canvas   .h.c -bg white -width 400 -height 200
57pack     .h.c -fill both
58set s [::Plotchart::createXYPlot .h.c {0.0 100.0 10.0} {0.0 100.0 20.0}]
59
60$s dataconfig series1 -colour red   -type symbol
61$s dataconfig series2 -colour green -type both
62
63$s yconfig -format "%12.2e"
64
65set x 5.0
66foreach symbol {plus cross circle up down dot upfilled downfilled} {
67   $s dataconfig series1 -symbol $symbol
68   $s dataconfig series2 -symbol $symbol
69   $s plot series1 $x 50.0
70   $s plot series2 $x 20
71   set x [expr {$x+10}]
72}
73
74#
75# Second window: XY-plot with background and a Pareto plot
76# Note:
77# The data series is filled upwards, so that a white polygon
78# hides the shading above the line. You need to let the
79# series cover the whole axis, otherwise the effect is lost.
80#
81toplevel .t2
82canvas .t2.c  -background white -width 400 -height 200
83canvas .t2.c2 -background white -width 400 -height 200
84pack .t2.c .t2.c2 -fill both
85
86set s [::Plotchart::createXYPlot .t2.c {0.0 100.0 10.0} {0.0 100.0 20.0}]
87
88$s background gradient green top-down
89
90$s dataconfig series1 -filled up -fillcolour white
91
92$s plot series1  0.0 20.0
93$s plot series1 10.0 20.0
94$s plot series1 30.0 50.0
95$s plot series1 35.0 45.0
96$s plot series1 45.0 25.0
97$s plot series1 75.0 55.0
98$s plot series1 100.0 55.0
99
100$s plaintext 30.0 60.0 "Peak" south
101
102set s2 [::Plotchart::createXYPlot .t2.c2 {0.0 100.0 10.0} {0.0 100.0 20.0}]
103
104set image [image create photo bg -file [file join [file dirname [info script]] tcllogo.gif]]
105$s2 background image $image
106
107#$s2 dataconfig series1 -filled up -fillcolour white
108
109$s2 plot series1  0.0 20.0
110$s2 plot series1 10.0 20.0
111$s2 plot series1 30.0 50.0
112$s2 plot series1 35.0 45.0
113$s2 plot series1 45.0 25.0
114$s2 plot series1 75.0 55.0
115$s2 plot series1 100.0 55.0
116
117$s2 plaintext 30.0 60.0 "Peak" south
118
119#
120# Not ready for prime time
121if { 0 } {
122set s3 [::Plotchart::createBarchart .t2.c3 {{} "Type 1" "Type 2" "Type 3" } \
123             {0.0 50.0 10.0} 1]
124
125set s4 [::Plotchart::createRightAxis .t2.c3 {0.0 100.0 20.0}]
126
127set data {0.0 20.0 5.0 30.0}
128$s3 plot series1 {0.0 20.0 5.0 30.0} blue
129$s4 plot series2  0.5  0.0
130$s4 plot series2  1.5 20.0
131$s4 plot series2  2.5  5.0
132$s4 plot series2  2.5 30.0
133}
134