2004-07-01 05:38:48 -04:00
|
|
|
#!/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],
|
2004-10-11 00:51:21 -04:00
|
|
|
[0.0, 100.0, 20.0],
|
|
|
|
:background=>'white',
|
|
|
|
:width=>400, :height=>200){|chart|
|
2004-07-01 05:38:48 -04:00
|
|
|
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
|
2004-10-11 00:51:21 -04:00
|
|
|
xold, yold = obj.return_value
|
|
|
|
xnew = xold + xd
|
|
|
|
ynew = yold + (rand() - 0.5) * yd
|
|
|
|
ynew2 = yold + (rand() - 0.5) * 2.0 * yd
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
series1.plot(xnew, ynew)
|
|
|
|
series2.plot(xnew, ynew2)
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
obj.stop if xnew >= 200
|
2004-07-01 05:38:48 -04:00
|
|
|
|
2004-10-11 00:51:21 -04:00
|
|
|
[xnew, ynew] # return_value
|
|
|
|
}).start(100, proc{ [0.0, 50.0] }) # init return_value
|
2004-07-01 05:38:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
###############################
|
|
|
|
# Set up an isometric plot
|
|
|
|
###############################
|
|
|
|
Tk::Tcllib::Plotchart::IsometricPlot.new([0.0, 100.0], [0.0, 200.0], :noaxes,
|
2004-10-11 00:51:21 -04:00
|
|
|
:background=>'white',
|
|
|
|
:width=>400, :height=>200){|chart|
|
2004-07-01 05:38:48 -04:00
|
|
|
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],
|
2004-10-11 00:51:21 -04:00
|
|
|
[0.0, 100.0, 20.0],
|
|
|
|
:bg=>'white',
|
|
|
|
:width=>400, :height=>200){|chart|
|
2004-07-01 05:38:48 -04:00
|
|
|
pack(:fill=>:both)
|
|
|
|
|
|
|
|
yconfig(:format=>"%12.2e")
|
|
|
|
|
|
|
|
series1 = Tk::Tcllib::Plotchart::PlotSeries.new(chart, :colour=>'red',
|
2004-10-11 00:51:21 -04:00
|
|
|
:type=>:symbol)
|
2004-07-01 05:38:48 -04:00
|
|
|
series2 = Tk::Tcllib::Plotchart::PlotSeries.new(chart, :colour=>'green',
|
2004-10-11 00:51:21 -04:00
|
|
|
:type=>:both)
|
2004-07-01 05:38:48 -04:00
|
|
|
|
|
|
|
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
|