diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-03-29 10:27:32 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-03-29 10:27:32 +0000 |
commit | 10fa84d750eced2f5c8fcfb5630d2d04e3a04cb5 (patch) | |
tree | cbb6b4949c30f48663e44b9ebc0b429a1990cbde /ext/tk/sample | |
parent | 42959f502945d18c8ce793b1840d4140b1eb7278 (diff) | |
download | ruby-10fa84d750eced2f5c8fcfb5630d2d04e3a04cb5.tar.gz |
* lib/tkextlib/blt/component.rb: cannot create elements except
default type of element.
* lib/tkextlib/blt/barchart.rb: ditto.
* lib/tkextlib/blt/graph.rb: ditto.
* lib/tkextlib/blt/stripchart.rb: ditto.
* lib/tkextlib/blt/component.rb: axis command option gets
proper object type of arguments.
* sample/tkextlib/blt/calendar.rb: new sample.
* sample/tkextlib/blt/pareto.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample')
-rw-r--r-- | ext/tk/sample/tkextlib/blt/calendar.rb | 117 | ||||
-rw-r--r-- | ext/tk/sample/tkextlib/blt/images/chalk.gif | bin | 0 -> 4378 bytes | |||
-rw-r--r-- | ext/tk/sample/tkextlib/blt/images/rain.gif | bin | 0 -> 3785 bytes | |||
-rw-r--r-- | ext/tk/sample/tkextlib/blt/pareto.rb | 90 |
4 files changed, 207 insertions, 0 deletions
diff --git a/ext/tk/sample/tkextlib/blt/calendar.rb b/ext/tk/sample/tkextlib/blt/calendar.rb new file mode 100644 index 0000000000..4fc6d64d9e --- /dev/null +++ b/ext/tk/sample/tkextlib/blt/calendar.rb @@ -0,0 +1,117 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/blt' + +require 'date' + +dir = File.join(File.dirname(File.expand_path(__FILE__)), 'images') +file = File.join(dir, 'chalk.gif') +active = File.join(dir, 'rain.gif') + +texture1 = TkPhotoImage.new(:file=>file) +texture2 = TkPhotoImage.new(:file=>active) + +TkOption.add('*Tile', texture1) + +TkOption.add('*HighlightThickness', 0) +TkOption.add('*calendar.weekframe*Tile', texture2) +TkOption.add('*Calendar.Label.borderWidth', 0) +TkOption.add('*Calendar.Label.relief', :sunken) +TkOption.add('*Calendar.Frame.borderWidth', 2) +TkOption.add('*Calendar.Frame.relief', :raised) +TkOption.add('*Calendar.Label.font', 'Helvetica 11') +TkOption.add('*Calendar.Label.foreground', 'navyblue') +TkOption.add('*button.foreground', 'navyblue') +TkOption.add('*background', 'grey85') +TkOption.add('*Label.ipadX', 200) + +TkOption.add('*tile', texture2) + +class BLT_Calendar_sample + @@monthInfo = [ + nil, # dummy + ['January', 31], + ['February', 28], + ['March', 31], + ['April', 30], + ['May', 31], + ['June', 30], + ['July', 31], + ['August', 31], + ['Septembar', 30], + ['October', 31], + ['November', 30], + ['December', 31] + ] + + @@abbrDays = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ] + + def initialize() + today = Date.today + + if TkComm.bool(Tk.info(:commands, '.calendar')) + Tk.destroy('.calendar') + end + cal = Tk::BLT::Tile::Frame.new(:widgetname=>'.calendar', + :classname=>'Calendar', + :width=>'3i', :height=>'3i') + + mon = Tk::BLT::Tile::Label.new(cal, :font=>'Courier 14 bold', + :text=>"#{@@monthInfo[today.month][0]} " + + "#{today.year}") + Tk::BLT::Table.add(cal, mon, [1, 0], :cspan=>7, :pady=>10) + + week_f = Tk::BLT::Tile::Frame.new(cal, :widgetname=>'weekframe', + :relief=>:sunken, :borderwidth=>1) + Tk::BLT::Table.add(cal, week_f, [2, 0], :columnspan=>7, :fill=>:both) + + @@abbrDays.each_with_index{|dayName, idx| + Tk::BLT::Table.add(cal, + Tk::BLT::Tile::Label.new(cal, :text=>dayName, + :font=>'Helvetica 12'), + [2, idx], :pady=>2, :padx=>2) + } + + Tk::BLT::Table.itemconfigure(cal, 'c*', 'r2', :pad=>4) + + numDays = @@monthInfo[today.month][1] + week = 0 + cnt = 1 + + wkday = today.wday - ((today.day - 1) % 7) + wkday += 7 if wkday < 0 + + while cnt <= numDays + Tk::BLT::Table.add(cal, + Tk::BLT::Tile::Label.new(cal, :text=>cnt){ + self.configure(:borderwidth=>1, + :relief=>:sunken) if cnt == today.day + }, + [week+3, wkday], :fill=>:both, :ipadx=>10, :ipady=>4) + cnt += 1 + wkday += 1 + if wkday == 7 + week += 1 + wkday = 0 + end + end + + Tk::BLT::Tile::Frame.new(cal, :borderwidth=>1, :relief=>:sunken){|f| + Tk::BLT::Table.add(f, + Tk::BLT::Tile::Button.new(f, :widgetname=>'button', + :command=>proc{exit}, + :borderwidth=>2, + :text=>'Quit'), + :padx=>4, :pady=>4) + Tk::BLT::Table.add(cal, f, [week+4, 5], :cspan=>2, :pady=>4) + } + + Tk::BLT::Table.add(Tk.root, cal, :fill=>:both) + Tk::BLT::Table.itemconfigure(cal, 'r0', :resize=>:none) + end +end + +BLT_Calendar_sample.new + +Tk.mainloop diff --git a/ext/tk/sample/tkextlib/blt/images/chalk.gif b/ext/tk/sample/tkextlib/blt/images/chalk.gif Binary files differnew file mode 100644 index 0000000000..30d29a7221 --- /dev/null +++ b/ext/tk/sample/tkextlib/blt/images/chalk.gif diff --git a/ext/tk/sample/tkextlib/blt/images/rain.gif b/ext/tk/sample/tkextlib/blt/images/rain.gif Binary files differnew file mode 100644 index 0000000000..d7bb417939 --- /dev/null +++ b/ext/tk/sample/tkextlib/blt/images/rain.gif diff --git a/ext/tk/sample/tkextlib/blt/pareto.rb b/ext/tk/sample/tkextlib/blt/pareto.rb new file mode 100644 index 0000000000..94d5f3f97f --- /dev/null +++ b/ext/tk/sample/tkextlib/blt/pareto.rb @@ -0,0 +1,90 @@ +#!/usr/bin/env ruby + +require 'tk' +require 'tkextlib/blt' + +# Example of a pareto chart. +# +# The pareto chart mixes line and bar elements in the same graph. +# Each processing operating is represented by a bar element. The +# total accumulated defects is displayed with a single line element. +b = Tk::BLT::Barchart.new(:title=>'Defects Found During Inspection', + :font=>'Helvetica 12', :plotpady=>[12, 4], + :width=>'6i', :height=>'5i') +Tk::BLT::Table.add(Tk.root, b, :fill=>:both) + +data = [ + ["Spot Weld", 82, 'yellow'], + ["Lathe", 49, 'orange'], + ["Gear Cut", 38, 'green'], + ["Drill", 24, 'blue'], + ["Grind", 17, 'red'], + ["Lapping", 12, 'brown'], + ["Press", 8, 'purple'], + ["De-burr", 4, 'pink'], + ["Packaging", 3, 'cyan'], + ["Other", 12, 'magenta'] +] + +# Create an X-Y graph line element to trace the accumulated defects. +b.line_create('accum', :label=>'', :symbol=>:none, :color=>'red') + +# Define a bitmap to be used to stipple the background of each bar. +pattern1 = Tk::BLT::Bitmap.define([ [4, 4], [1, 2, 4, 8] ]) + +# For each process, create a bar element to display the magnitude. +count = 0 +sum = 0 +ydata = [0] +xdata = [0] +labels = [] + +data.each{|label, value, color| + count += 1 + b.element_create(label, :xdata=>count, :ydata=>value, :foreground=>color, + :relief=>:solid, :borderwidth=>1, :stipple=>pattern1, + :background=>'lightblue') + labels[count] = label + # Get the total number of defects. + sum += value + ydata << sum + xdata << count +} + +# Configure the coordinates of the accumulated defects, +# now that we know what they are. +b.element_configure('accum', :xdata=>xdata, :ydata=>ydata) + +# Add text markers to label the percentage of total at each point. +xdata.zip(ydata){|x, y| + percent = (y * 100.0) / sum + if x == 0 + text = ' 0%' + else + text = '%.1f' % percent + end + b.marker_create(:text, :coords=>[x, y], :text=>text, :font=>'Helvetica 10', + :foreground=>'red4', :anchor=>:center, :yoffset=>-5) +} + +# Display an auxillary y-axis for percentages. +b.axis_configure('y2', :hide=>false, :min=>0.0, :max=>100.0, + :title=>'Percentage') + +# Title the y-axis +b.axis_configure('y', :title=>'Defects') + +# Configure the x-axis to display the process names, instead of numbers. +b.axis_configure('x', :title=>'Process', :rotate=>90, :subdivisions=>0, + :command=>proc{|w, val| + val = val.round + labels[val]? labels[val]: val + }) + +# No legend needed. +b.legend_configure(:hide=>true) + +# Configure the grid lines. +b.gridline_configure(:mapx=>:x, :color=>'lightblue') + +Tk.mainloop |