Update of /cvsroot/fxruby/FXRuby/examples
In directory usw-pr-cvs1:/tmp/cvs-serv11544
Added Files:
Tag: release10
gdchart.rb
Log Message:
Added a new example that uses the Ruby/GDChart module to create a
chart image and then display it in an FXImageView widget.
--- NEW FILE: gdchart.rb ---
require 'fox'
require 'GDChart'
require 'tempfile'
include Fox
class GDChartViewer < FXMainWindow
def initialize(app)
# Invoke base class initialize first
super(app, "GDChart Viewer", nil, nil, DECOR_ALL,
0, 0, 850, 600, 0, 0)
# Sunken border for image widget
imagebox = FXHorizontalFrame.new(self,
FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y)
# Make image widget
@imageview = FXImageView.new(imagebox, nil, nil, 0,
LAYOUT_FILL_X|LAYOUT_FILL_Y|HSCROLLER_NEVER|VSCROLLER_NEVER)
# Construct a PNG image and store it in the image viewer
@imageview.image = createChart
# Resize main window client area to fit image size
resize(@imageview.contentWidth, @imageview.contentHeight)
end
def createChart
# Create a simple chart
GDChart.title = "A Chart"
GDChart.xtitle = "X-axis"
GDChart.ytitle = "Y-axis"
data = [1, 2, 3, 4, 5, 6]
labels = ["label 1", "label 2", "label 3", "label 4", "label 5", "label 6"]
# Write chart data out as GIF to a temporary file
File.open('gdchart.gif', 'w') do |f|
GDChart.out_graph(200, 200, f, GDChart::LINE, labels.length, labels, 1, data)
end
# Reopen it and construct image
img = nil
File.open('gdchart.gif', 'rb') do |f|
img = FXGIFIcon.new(getApp(), f.read)
end
img
end
def create
super
show(PLACEMENT_SCREEN)
end
end
if __FILE__ == $0
# Make application
application = FXApp.new("GDChart Viewer", "FoxTest")
# Open display
application.init(ARGV)
# Make window
window = GDChartViewer.new(application)
# Create it
application.create
# Run
application.run
end
|