File: testshadexy.tcl

package info (click to toggle)
tklib 0.6%2B20190108-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 15,008 kB
  • sloc: tcl: 75,757; sh: 5,789; ansic: 792; pascal: 359; makefile: 70; sed: 53; exp: 21
file content (72 lines) | stat: -rwxr-xr-x 1,393 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env tclsh
## -*- tcl -*-

# testshadexy.tcl --
#     Demonstrate how to mark data with a shaded background
#
#     TODO:
#     Command to get the (extreme) axis values from a plot
#
package require Plotchart

pack [canvas .c -width 400 -height 300]

set p [::Plotchart::createXYPlot .c {0.0 100.0 10.0} {-5.0 5.0 2.5}]

set x      0.0
set y      0.0
set xbegin {}
set ybegin {}
set dx     5.0

set xold $x
set yold $y

while { $x < 100.0 } {

    set y [expr {0.7 * $y + rand() - 0.5 }]

    $p plot data $x $y

    #
    # Mark the areas where y decreases
    #
    if { $y < $yold && $xbegin == {} } {
        set xbegin $xold
        set ybegin $yold
    }

    if { $y > $yold && $xbegin != {} } {
        $p object rectangle "shade" $xbegin -5.0 $xold 5.0 -tag shade -fill lightgreen -outline lightgreen
        set xbegin {}
    }

    set xold $x
    set yold $y

    set x [expr {$x + $dx}]
}

#
# Do not forget the last one
#
if { $y > $yold && $xbegin != {} } {
    $p object rectangle "shade" $xbegin -5.0 $xold 5.0 -tag shade -fill lightgreen -outline lightgreen
    set xbegin {}
}

.c lower shade

#
# Show a legend and remove an entry ...
#
# Use a trick to get a rectangle for the shade entry in the legend

$p dataconfig shade -type rectangle -colour lightgreen

$p legend data "The data"
$p legend shade "The shading"

after 2000 {
    $p removefromlegend shade
}