summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/tk/sample/tkextlib/tcllib
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/ext/tk/sample/tkextlib/tcllib
Fresh start
Diffstat (limited to 'jni/ruby/ext/tk/sample/tkextlib/tcllib')
-rw-r--r--jni/ruby/ext/tk/sample/tkextlib/tcllib/Orig_LICENSE.txt46
-rw-r--r--jni/ruby/ext/tk/sample/tkextlib/tcllib/datefield.rb29
-rw-r--r--jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos1.rb158
-rw-r--r--jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos2.rb71
-rw-r--r--jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos3.rb83
-rw-r--r--jni/ruby/ext/tk/sample/tkextlib/tcllib/xyplot.rb17
6 files changed, 404 insertions, 0 deletions
diff --git a/jni/ruby/ext/tk/sample/tkextlib/tcllib/Orig_LICENSE.txt b/jni/ruby/ext/tk/sample/tkextlib/tcllib/Orig_LICENSE.txt
new file mode 100644
index 0000000..975f23e
--- /dev/null
+++ b/jni/ruby/ext/tk/sample/tkextlib/tcllib/Orig_LICENSE.txt
@@ -0,0 +1,46 @@
+
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+ >>> The following text is the original 'license.term' of tklib <<<
+ >>> extension. <<<
+ >>> Original Tcl files are not include in this directory, because <<<
+ >>> of all of them are rewritten to Ruby files. <<<
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+This software is copyrighted by Ajuba Solutions and other parties.
+The following terms apply to all files associated with the software unless
+explicitly disclaimed in individual files.
+
+The authors hereby grant permission to use, copy, modify, distribute,
+and license this software and its documentation for any purpose, provided
+that existing copyright notices are retained in all copies and that this
+notice is included verbatim in any distributions. No written agreement,
+license, or royalty fee is required for any of the authorized uses.
+Modifications to this software may be copyrighted by their authors
+and need not follow the licensing terms described here, provided that
+the new terms are clearly indicated on the first page of each file where
+they apply.
+
+IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY
+FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
+ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY
+DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
+INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE
+IS PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE
+NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
+MODIFICATIONS.
+
+GOVERNMENT USE: If you are acquiring this software on behalf of the
+U.S. government, the Government shall have only "Restricted Rights"
+in the software and related documentation as defined in the Federal
+Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you
+are acquiring the software on behalf of the Department of Defense, the
+software shall be classified as "Commercial Computer Software" and the
+Government shall have only "Restricted Rights" as defined in Clause
+252.227-7013 (c) (1) of DFARs. Notwithstanding the foregoing, the
+authors grant the U.S. Government and others acting in its behalf
+permission to use and distribute the software in accordance with the
+terms specified in this license.
diff --git a/jni/ruby/ext/tk/sample/tkextlib/tcllib/datefield.rb b/jni/ruby/ext/tk/sample/tkextlib/tcllib/datefield.rb
new file mode 100644
index 0000000..3550af7
--- /dev/null
+++ b/jni/ruby/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/jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos1.rb b/jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos1.rb
new file mode 100644
index 0000000..7f35a38
--- /dev/null
+++ b/jni/ruby/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/jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos2.rb b/jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos2.rb
new file mode 100644
index 0000000..cb657a4
--- /dev/null
+++ b/jni/ruby/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/jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos3.rb b/jni/ruby/ext/tk/sample/tkextlib/tcllib/plotdemos3.rb
new file mode 100644
index 0000000..66b8fe7
--- /dev/null
+++ b/jni/ruby/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/jni/ruby/ext/tk/sample/tkextlib/tcllib/xyplot.rb b/jni/ruby/ext/tk/sample/tkextlib/tcllib/xyplot.rb
new file mode 100644
index 0000000..2aa101e
--- /dev/null
+++ b/jni/ruby/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