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

« back to all changes in this revision

Viewing changes to ext/tk/sample/demos-jp/plot.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
#
 
2
# 2-D plot widget demo (called by 'widget')
 
3
#
 
4
 
 
5
# toplevel widget ��¸�ߤ���к������
 
6
if defined?($plot_demo) && $plot_demo
 
7
  $plot_demo.destroy 
 
8
  $plot_demo = nil
 
9
end
 
10
 
 
11
# demo �Ѥ� toplevel widget ������
 
12
$plot_demo = TkToplevel.new {|w|
 
13
  title("Plot Demonstration")
 
14
  iconname("Plot")
 
15
  positionWindow(w)
 
16
}
 
17
 
 
18
# label ����
 
19
TkLabel.new($plot_demo, 'font'=>$font, 'wraplength'=>'4i', 'justify'=>'left', 
 
20
            'text'=>"���Υ�����ɥ��ϴ�ñ��2�����Υץ��åȤ�ޤ�������Х� widget�Ǥ���ɽ�����줿����ޥ����ܥ���1�ǥɥ�å����ƥǡ����򤤤��뤳�Ȥ��Ǥ��ޤ���"){
 
21
  pack('side'=>'top')
 
22
}
 
23
 
 
24
# frame ����
 
25
$plot_buttons = TkFrame.new($plot_demo) {|frame|
 
26
  TkButton.new(frame) {
 
27
    #text 'λ��'
 
28
    text '�Ĥ���'
 
29
    command proc{
 
30
      tmppath = $plot_demo
 
31
      $plot_demo = nil
 
32
      tmppath.destroy
 
33
    }
 
34
  }.pack('side'=>'left', 'expand'=>'yes')
 
35
 
 
36
  TkButton.new(frame) {
 
37
    text '�����ɻ���'
 
38
    command proc{showCode 'plot'}
 
39
  }.pack('side'=>'left', 'expand'=>'yes')
 
40
}
 
41
$plot_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
 
42
 
 
43
# font ����
 
44
plotFont = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*'
 
45
 
 
46
# canvas ����
 
47
$plot_canvas = TkCanvas.new($plot_demo,'relief'=>'raised','width'=>450,'height'=>300)
 
48
$plot_canvas.pack('side'=>'top', 'fill'=>'x')
 
49
 
 
50
# plot ����
 
51
TkcLine.new($plot_canvas, 100, 250, 400, 250, 'width'=>2)
 
52
TkcLine.new($plot_canvas, 100, 250, 100,  50, 'width'=>2)
 
53
TkcText.new($plot_canvas, 225, 20, 
 
54
            'text'=>"��ñ�ʥץ��å�", 'font'=>plotFont, 'fill'=>'brown')
 
55
 
 
56
(0..10).each {|i|
 
57
  x = 100 + (i * 30)
 
58
  TkcLine.new($plot_canvas, x, 250, x, 245, 'width'=>2)
 
59
  TkcText.new($plot_canvas, x, 254, 
 
60
              'text'=>10*i, 'font'=>plotFont, 'anchor'=>'n')
 
61
}
 
62
(0..5).each {|i|
 
63
  y = 250 - (i * 40)
 
64
  TkcLine.new($plot_canvas, 100, y, 105, y, 'width'=>2)
 
65
  TkcText.new($plot_canvas, 96, y, 
 
66
              'text'=>"#{i*50}.0", 'font'=>plotFont, 'anchor'=>'e')
 
67
}
 
68
 
 
69
for xx, yy in [[12,56],[20,94],[33,98],[32,120],[61,180],[75,160],[98,223]]
 
70
  x = 100 + (3*xx)
 
71
  y = 250 - (4*yy)/5
 
72
  item = TkcOval.new($plot_canvas, x-6, y-6, x+6, y+6, 
 
73
                     'width'=>1, 'outline'=>'black', 'fill'=>'SkyBlue2')
 
74
  item.addtag 'point'
 
75
end
 
76
 
 
77
$plot_canvas.itembind('point', 'Any-Enter', 
 
78
                      proc{$plot_canvas.itemconfigure 'current','fill','red'})
 
79
$plot_canvas.itembind('point', 'Any-Leave', 
 
80
                      proc{$plot_canvas.itemconfigure 'current','fill','SkyBlue2'})
 
81
$plot_canvas.itembind('point', '1', 
 
82
                      proc{|x,y| plotDown $plot_canvas,x,y}, "%x %y")
 
83
$plot_canvas.itembind('point', 'ButtonRelease-1', 
 
84
                      proc{$plot_canvas.dtag 'selected'})
 
85
$plot_canvas.bind('B1-Motion', 
 
86
                  proc{|x,y| plotMove $plot_canvas,x,y}, "%x %y")
 
87
 
 
88
$plot = {'lastX'=>0, 'lastY'=>0}
 
89
 
 
90
# plotDown --
 
91
# This method is invoked when the mouse is pressed over one of the 
 
92
# data points.  It sets up state to allow the point to be dragged.
 
93
#
 
94
# Arguments:
 
95
# w -           The canvas window.
 
96
# x, y -        The coordinates of the mouse press.
 
97
 
 
98
def plotDown (w, x, y)
 
99
  w.dtag 'selected'
 
100
  w.addtag_withtag 'selected', 'current'
 
101
  w.raise 'current'
 
102
  $plot['lastX'] = x
 
103
  $plot['lastY'] = y
 
104
end
 
105
 
 
106
# plotMove --
 
107
# This method is invoked during mouse motion events.  It drags the
 
108
# current item.
 
109
#
 
110
# Arguments:
 
111
# w -           The canvas window.
 
112
# x, y -        The coordinates of the mouse.
 
113
 
 
114
def plotMove (w, x, y)
 
115
  w.move 'selected', x - $plot['lastX'], y - $plot['lastY']
 
116
  $plot['lastX'] = x
 
117
  $plot['lastY'] = y
 
118
end
 
119