~ubuntu-branches/ubuntu/intrepid/ruby1.8/intrepid-updates

« back to all changes in this revision

Viewing changes to ext/tk/sample/tkextlib/tcllib/plotdemos2.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2007-03-13 22:11:58 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070313221158-h3oql37brlaf2go2
Tags: 1.8.6-1
* new upstream version, 1.8.6.
* libruby1.8 conflicts with libopenssl-ruby1.8 (< 1.8.6) (closes: #410018)
* changed packaging style to cdbs from dbs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/ruby
 
2
 
 
3
require 'tk'
 
4
require 'tkextlib/tcllib/plotchart'
 
5
 
 
6
###############################
 
7
 
 
8
c1 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
 
9
c2 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
 
10
Tk.pack(c1,c2, :fill=>:both, :side=>:top)
 
11
 
 
12
###############################
 
13
# Set up a strip chart
 
14
###############################
 
15
slipchart = Tk::Tcllib::Plotchart::Stripchart.new(c1, [0.0, 100.0, 10.0], 
 
16
                                                      [0.0, 100.0, 20.0])
 
17
 
 
18
TkTimer.new(500, -1, proc{|obj| # obj --> TkTimer object
 
19
              slipchart, xold, xd, yold, yd = obj.return_value
 
20
              xnew = xold + xd
 
21
              ynew = yold + (rand() - 0.5) * yd
 
22
              ynew2 = yold + (rand() - 0.5) * 2.0 * yd
 
23
              slipchart.plot('series1', xnew, ynew)
 
24
              slipchart.plot('series2', xnew, ynew2)
 
25
              obj.stop if xnew >= 200
 
26
              [slipchart, xnew, xd, ynew, yd] # return_value
 
27
            }).start(100, proc{
 
28
                       # init return_value
 
29
                       [slipchart, 0.0, 15.0, 50.0, 30.0]
 
30
                     })
 
31
 
 
32
slipchart.title "Aha!"
 
33
 
 
34
###############################
 
35
# Set up an isometric plot
 
36
###############################
 
37
s = Tk::Tcllib::Plotchart::IsometricPlot.new(c2, [0.0, 100.0], [0.0, 200.0], 
 
38
                                             :noaxes)
 
39
 
 
40
s.set_zoom_pan
 
41
 
 
42
s.plot('rectangle',        [10.0, 10.0, 50.0, 50.0], 'green')
 
43
s.plot('filled-rectangle', [20.0, 20.0, 40.0, 40.0], 'red')
 
44
s.plot('filled-circle',    [70.0, 70.0, 40.0], 'yellow')
 
45
s.plot('circle',           [70.0, 70.0, 42.0])
 
46
 
 
47
###############################
 
48
# Check the symbols
 
49
###############################
 
50
h = TkToplevel.new(:title=>'h')
 
51
c = TkCanvas.new(h, :bg=>'white', :width=>400, :height=>200).pack(:fill=>:both)
 
52
 
 
53
s = Tk::Tcllib::Plotchart::XYPlot.new(c, [0.0, 100.0, 10.0], 
 
54
                                         [0.0, 100.0, 20.0]) 
 
55
s.dataconfig('series1', :colour=>'red',   :type=>:symbol)
 
56
s.dataconfig('series2', :colour=>'green', :type=>:both)
 
57
 
 
58
s.yconfig(:format=>"%12.2e")
 
59
 
 
60
x = 5.0
 
61
%w(plus cross circle up down dot upfilled downfilled).each{|sym|
 
62
  s.dataconfig('series1', :symbol=>sym)
 
63
  s.dataconfig('series2', :symbol=>sym)
 
64
  s.plot('series1', x, 50.0)
 
65
  s.plot('series2', x, 20)
 
66
  x += 10
 
67
}
 
68
 
 
69
##############################
 
70
 
 
71
Tk.mainloop