summaryrefslogtreecommitdiff
path: root/ext/tk/sample/tkextlib/tcllib
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-01 09:38:48 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-01 09:38:48 +0000
commitffcedd79505ea2e99f859c7cea2fb2221c948d4c (patch)
tree02232516faf0e1959ecb5d5b7aca25a52f9f87ca /ext/tk/sample/tkextlib/tcllib
parent73cf1d02bac2dbdd5d7f673a33d81444a00c865e (diff)
* ext/tk/lib/tcltklib : bug fix
* ext/tk/lib/tk : bug fix and add Tcl/Tk extension support libraries git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/tkextlib/tcllib')
-rw-r--r--ext/tk/sample/tkextlib/tcllib/datefield.rb29
-rw-r--r--ext/tk/sample/tkextlib/tcllib/plotdemos1.rb158
-rw-r--r--ext/tk/sample/tkextlib/tcllib/plotdemos2.rb71
-rw-r--r--ext/tk/sample/tkextlib/tcllib/plotdemos3.rb83
-rw-r--r--ext/tk/sample/tkextlib/tcllib/xyplot.rb17
5 files changed, 358 insertions, 0 deletions
diff --git a/ext/tk/sample/tkextlib/tcllib/datefield.rb b/ext/tk/sample/tkextlib/tcllib/datefield.rb
new file mode 100644
index 0000000000..1b0a29c0b9
--- /dev/null
+++ b/ext/tk/sample/tkextlib/tcllib/datefield.rb
@@ -0,0 +1,29 @@
+#!/usr/bin/ruby
+
+require 'tk'
+require 'tkextlib/tcllib/datefield'
+require 'parsedate'
+
+Tk.root.title('Datefield example')
+
+
+my_date1 = TkVariable.new
+my_date2 = TkVariable.new
+my_date1.trace('w'){
+ begin
+ t = Time.local(*(ParseDate.parsedate(my_date1.value)))
+ my_date2.value = t.strftime('%A')
+ rescue
+ # ignore error
+ end
+}
+
+df = Tk::Tcllib::Datefield.new(:textvariable=>my_date1)
+Tk.grid(TkLabel.new(:text=>'Enter a date:', :anchor=>:e), df, :sticky=>:ew)
+Tk.grid(TkLabel.new(:text=>'That date ia a:', :anchor=>:e),
+ TkLabel.new(:textvariable=>my_date2, :relief=>:sunken, :width=>12),
+ :sticky=>:ew)
+
+df.set_focus
+
+Tk.mainloop
diff --git a/ext/tk/sample/tkextlib/tcllib/plotdemos1.rb b/ext/tk/sample/tkextlib/tcllib/plotdemos1.rb
new file mode 100644
index 0000000000..6077d8ab2c
--- /dev/null
+++ b/ext/tk/sample/tkextlib/tcllib/plotdemos1.rb
@@ -0,0 +1,158 @@
+#!/usr/bin/ruby
+
+require 'tk'
+require 'tkextlib/tcllib/plotchart'
+
+###############################
+
+c1 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
+c2 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
+c3 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
+Tk.pack(c1,c2,c3, :fill=>:both, :side=>:top)
+
+h = TkToplevel.new(:title=>'h')
+hc1 = TkCanvas.new(h, :background=>'white', :width=>400, :height=>200)
+hc2 = TkCanvas.new(h, :background=>'white', :width=>400, :height=>200)
+Tk.pack(hc1,hc2, :fill=>:both, :side=>:top)
+
+v = TkToplevel.new(:title=>'v')
+vc1 = TkCanvas.new(v, :background=>'white', :width=>400, :height=>200)
+vc2 = TkCanvas.new(v, :background=>'white', :width=>400, :height=>200)
+vc3 = TkCanvas.new(v, :background=>'white', :width=>400, :height=>200)
+Tk.pack(vc1,vc2,vc3, :fill=>:both, :side=>:top)
+
+###############################
+
+s = Tk::Tcllib::Plotchart::XYPlot.new(c1, [0.0, 100.0, 10.0],
+ [0.0, 100.0, 20.0])
+
+
+xd = 5.0
+yd = 20.0
+xold = 0.0
+yold = 50.0
+
+s.dataconfig('series1', :color=>'red')
+
+(0..19).each{|i|
+ xnew = xold + xd
+ ynew = yold + (rand() - 0.5) * yd
+ ynew2 = yold + (rand() - 0.5) * 2.0 * yd
+ s.plot('series1', xnew, ynew)
+ s.plot('series2', xnew, ynew2)
+ xold = xnew
+ yold = ynew
+}
+
+s.xtext "X-coordinate"
+s.ytext "Y-data"
+s.title "Aha!"
+
+c1.wait_visibility
+
+s.save_plot "aha.ps"
+
+###############################
+
+s = Tk::Tcllib::Plotchart::Piechart.new(c2)
+
+s.plot([ ["Long names", 10], ["Short names", 30],
+ ["Average", 40], ["Ultra-short names", 5] ])
+
+#
+# Note: title should be shifted up
+# - distinguish a separate title area
+#
+s.title "Okay - this works"
+
+###############################
+
+s = Tk::Tcllib::Plotchart::PolarPlot.new(c3, [3.0, 1.0])
+
+0.step(359, 10){|angle|
+ rad = 1.0+Math.cos(angle*Math::PI/180.0)
+ s.plot('cardioid', rad, angle)
+}
+
+s.title "Cardioid"
+
+###############################
+
+s = Tk::Tcllib::Plotchart::Barchart.new(hc1, %w(A B C D E),
+ [0.0, 10.0, 2.0], 2)
+
+s.plot('series1', [1.0, 4.0, 6.0, 1.0, 7.0], 'red')
+s.plot('series2', [0.0, 3.0, 7.0, 9.3, 2.0], 'green')
+s.title "Arbitrary data"
+
+###############################
+
+s = Tk::Tcllib::Plotchart::Barchart.new(hc2, %w(A B C D E),
+ [0.0, 20.0, 5.0], :stacked)
+
+s.plot('series1', [1.0, 4.0, 6.0, 1.0, 7.0], 'red')
+s.plot('series2', [0.0, 3.0, 7.0, 9.3, 2.0], 'green')
+s.title "Stacked diagram"
+
+###############################
+
+s = Tk::Tcllib::Plotchart::HorizontalBarchart.new(vc1, [0.0, 10.0, 2.0],
+ %w(A B C D E), 2)
+
+s.plot('series1', [1.0, 4.0, 6.0, 1.0, 7.0], 'red')
+s.plot('series2', [0.0, 3.0, 7.0, 9.3, 2.0], 'green')
+s.title "Arbitrary data"
+
+###############################
+
+s = Tk::Tcllib::Plotchart::HorizontalBarchart.new(vc2, [0.0, 20.0, 5.0],
+ %w(A B C D E), :stacked)
+
+s.plot('series1', [1.0, 4.0, 6.0, 1.0, 7.0], 'red')
+s.plot('series2', [0.0, 3.0, 7.0, 9.3, 2.0], 'green')
+s.title "Stacked diagram"
+
+###############################
+
+s = Tk::Tcllib::Plotchart::Timechart.new(vc3, "1 january 2004",
+ "31 december 2004", 4)
+
+s.period("Spring", "1 march 2004", "1 june 2004", 'green')
+s.period("Summer", "1 june 2004", "1 september 2004", 'yellow')
+s.vertline("1 jan", "1 january 2004")
+s.vertline("1 apr", "1 april 2004")
+s.vertline("1 jul", "1 july 2004")
+s.vertline("1 oct", "1 october 2004")
+s.milestone("Longest day", "21 july 2004")
+s.title "Seasons (northern hemisphere)"
+
+###############################
+
+z = TkToplevel.new(:title=>'3D')
+
+zc1 = TkCanvas.new(z, :background=>'white', :width=>400, :height=>300)
+zc2 = TkCanvas.new(z, :background=>'white', :width=>400, :height=>250)
+Tk.pack(zc1,zc2)
+
+s = Tk::Tcllib::Plotchart::Plot3D.new(zc1,
+ [0, 10, 3], [-10, 10, 10], [0, 10, 2.5])
+
+s.title "3D Plot"
+s.plot_function{|x, y|
+ # cowboyhat
+ x1 = x.to_f/9.0
+ y1 = y.to_f/9.0
+ 3.0 * (1.0-(x1*x1+y1*y1))*(1.0-(x1*x1+y1*y1))
+}
+
+s = Tk::Tcllib::Plotchart::Plot3D.new(zc2,
+ [0, 10, 3], [-10, 10, 10], [0, 10, 2.5])
+s.title "3D Plot - data "
+s.colour("green", "black")
+s.plot_data([ [1.0, 2.0, 1.0, 0.0],
+ [1.1, 3.0, 1.1, -0.5],
+ [3.0, 1.0, 4.0, 5.0] ])
+
+###############################
+
+Tk.mainloop
diff --git a/ext/tk/sample/tkextlib/tcllib/plotdemos2.rb b/ext/tk/sample/tkextlib/tcllib/plotdemos2.rb
new file mode 100644
index 0000000000..3fd57f3804
--- /dev/null
+++ b/ext/tk/sample/tkextlib/tcllib/plotdemos2.rb
@@ -0,0 +1,71 @@
+#!/usr/bin/ruby
+
+require 'tk'
+require 'tkextlib/tcllib/plotchart'
+
+###############################
+
+c1 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
+c2 = TkCanvas.new(:background=>'white', :width=>400, :height=>200)
+Tk.pack(c1,c2, :fill=>:both, :side=>:top)
+
+###############################
+# Set up a strip chart
+###############################
+slipchart = Tk::Tcllib::Plotchart::Stripchart.new(c1, [0.0, 100.0, 10.0],
+ [0.0, 100.0, 20.0])
+
+TkTimer.new(500, -1, proc{|obj| # obj --> TkTimer object
+ slipchart, xold, xd, yold, yd = obj.return_value
+ xnew = xold + xd
+ ynew = yold + (rand() - 0.5) * yd
+ ynew2 = yold + (rand() - 0.5) * 2.0 * yd
+ slipchart.plot('series1', xnew, ynew)
+ slipchart.plot('series2', xnew, ynew2)
+ obj.stop if xnew >= 200
+ [slipchart, xnew, xd, ynew, yd] # return_value
+ }).start(100, proc{
+ # init return_value
+ [slipchart, 0.0, 15.0, 50.0, 30.0]
+ })
+
+slipchart.title "Aha!"
+
+###############################
+# Set up an isometric plot
+###############################
+s = Tk::Tcllib::Plotchart::IsometricPlot.new(c2, [0.0, 100.0], [0.0, 200.0],
+ :noaxes)
+
+s.set_zoom_pan
+
+s.plot('rectangle', [10.0, 10.0, 50.0, 50.0], 'green')
+s.plot('filled-rectangle', [20.0, 20.0, 40.0, 40.0], 'red')
+s.plot('filled-circle', [70.0, 70.0, 40.0], 'yellow')
+s.plot('circle', [70.0, 70.0, 42.0])
+
+###############################
+# Check the symbols
+###############################
+h = TkToplevel.new(:title=>'h')
+c = TkCanvas.new(h, :bg=>'white', :width=>400, :height=>200).pack(:fill=>:both)
+
+s = Tk::Tcllib::Plotchart::XYPlot.new(c, [0.0, 100.0, 10.0],
+ [0.0, 100.0, 20.0])
+s.dataconfig('series1', :colour=>'red', :type=>:symbol)
+s.dataconfig('series2', :colour=>'green', :type=>:both)
+
+s.yconfig(:format=>"%12.2e")
+
+x = 5.0
+%w(plus cross circle up down dot upfilled downfilled).each{|sym|
+ s.dataconfig('series1', :symbol=>sym)
+ s.dataconfig('series2', :symbol=>sym)
+ s.plot('series1', x, 50.0)
+ s.plot('series2', x, 20)
+ x += 10
+}
+
+##############################
+
+Tk.mainloop
diff --git a/ext/tk/sample/tkextlib/tcllib/plotdemos3.rb b/ext/tk/sample/tkextlib/tcllib/plotdemos3.rb
new file mode 100644
index 0000000000..3b74b1f592
--- /dev/null
+++ b/ext/tk/sample/tkextlib/tcllib/plotdemos3.rb
@@ -0,0 +1,83 @@
+#!/usr/bin/ruby
+
+require 'tk'
+require 'tkextlib/tcllib/plotchart'
+
+###############################
+# Set up a strip chart
+###############################
+
+Tk::Tcllib::Plotchart::Stripchart.new([0.0, 100.0, 10.0],
+ [0.0, 100.0, 20.0],
+ :background=>'white',
+ :width=>400, :height=>200){|chart|
+ title "Aha!"
+ pack(:fill=>:both, :side=>:top)
+
+ series1 = Tk::Tcllib::Plotchart::PlotSeries.new(chart)
+ series2 = Tk::Tcllib::Plotchart::PlotSeries.new(chart)
+
+ xd = 15.0
+ yd = 30.0
+
+ TkTimer.new(500, -1, proc{|obj| # obj --> TkTimer object
+ xold, yold = obj.return_value
+ xnew = xold + xd
+ ynew = yold + (rand() - 0.5) * yd
+ ynew2 = yold + (rand() - 0.5) * 2.0 * yd
+
+ series1.plot(xnew, ynew)
+ series2.plot(xnew, ynew2)
+
+ obj.stop if xnew >= 200
+
+ [xnew, ynew] # return_value
+ }).start(100, proc{ [0.0, 50.0] }) # init return_value
+}
+
+###############################
+# Set up an isometric plot
+###############################
+Tk::Tcllib::Plotchart::IsometricPlot.new([0.0, 100.0], [0.0, 200.0], :noaxes,
+ :background=>'white',
+ :width=>400, :height=>200){|chart|
+ pack(:fill=>:both, :side=>:top)
+ set_zoom_pan
+
+ chart.plot('rectangle', [10.0, 10.0, 50.0, 50.0], 'green')
+ chart.plot('filled-rectangle', [20.0, 20.0, 40.0, 40.0], 'red')
+ chart.plot('filled-circle', [70.0, 70.0, 40.0], 'yellow')
+ chart.plot('circle', [70.0, 70.0, 42.0])
+}
+
+###############################
+# Check the symbols
+###############################
+TkToplevel.new(:title=>'h'){|h|
+ Tk::Tcllib::Plotchart::XYPlot.new(h, [0.0, 100.0, 10.0],
+ [0.0, 100.0, 20.0],
+ :bg=>'white',
+ :width=>400, :height=>200){|chart|
+ pack(:fill=>:both)
+
+ yconfig(:format=>"%12.2e")
+
+ series1 = Tk::Tcllib::Plotchart::PlotSeries.new(chart, :colour=>'red',
+ :type=>:symbol)
+ series2 = Tk::Tcllib::Plotchart::PlotSeries.new(chart, :colour=>'green',
+ :type=>:both)
+
+ x = 5.0
+ %w(plus cross circle up down dot upfilled downfilled).each{|sym|
+ series1.dataconfig(:symbol=>sym)
+ series2.dataconfig(:symbol=>sym)
+ series1.plot(x, 50.0)
+ series2.plot(x, 20)
+ x += 10
+ }
+ }
+}
+
+##############################
+
+Tk.mainloop
diff --git a/ext/tk/sample/tkextlib/tcllib/xyplot.rb b/ext/tk/sample/tkextlib/tcllib/xyplot.rb
new file mode 100644
index 0000000000..116609e34f
--- /dev/null
+++ b/ext/tk/sample/tkextlib/tcllib/xyplot.rb
@@ -0,0 +1,17 @@
+#!/usr/bin/ruby
+
+require 'tk'
+require 'tkextlib/tcllib/plotchart'
+
+TkCanvas.new(:background=>'white', :width=>400, :height=>200){|c|
+ pack(:fill=>:both)
+ Tk::Tcllib::Plotchart::XYPlot.new(c, [0.0, 100.0, 10.0],
+ [0.0, 100.0, 20.0]){
+ [ [0.0, 32.0], [10.0, 50.0], [25.0, 60.0], [78.0, 11.0] ].each{|x, y|
+ plot('series1', x, y)
+ }
+ title("Data series")
+ }
+}
+
+Tk.mainloop