diff options
-rw-r--r-- | ext/tk/ChangeLog.tkextlib | 30 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/blt/barchart.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/blt/component.rb | 342 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/blt/graph.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/blt/stripchart.rb | 2 | ||||
-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 |
9 files changed, 537 insertions, 48 deletions
diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib index 85fd938e3a..9c9f2bf368 100644 --- a/ext/tk/ChangeLog.tkextlib +++ b/ext/tk/ChangeLog.tkextlib @@ -1,3 +1,21 @@ +2005-03-29 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> + + * 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. + 2005-03-26 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> * lib/tkextlib/blt.rb: add commands for zooming. @@ -16,19 +34,19 @@ * lib/tkextlib/blt/htext.rb: add TkVariable object to access special Tcl variables. - * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: typo fix. + * lib/tkextlib/treectrl/tktreectrl.rb: typo fix. - * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: proper treatment + * lib/tkextlib/treectrl/tktreectrl.rb: proper treatment of 'font' option of element_configure. - * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: bug fix on item_sort. + * lib/tkextlib/treectrl/tktreectrl.rb: bug fix on item_sort. - * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: add methods to + * lib/tkextlib/treectrl/tktreectrl.rb: add methods to call TreeCtrl commands for bindings. - * ext/tk/sample/tkextlib/blt/*: add some sample scripts. + * sample/tkextlib/blt/*: add some sample scripts. - * ext/tk/sample/tkextlib/treectrl/*: add some sample scripts. + * sample/tkextlib/treectrl/*: add some sample scripts. 2005-03-18 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> diff --git a/ext/tk/lib/tkextlib/blt/barchart.rb b/ext/tk/lib/tkextlib/blt/barchart.rb index d8ecad834f..c253194582 100644 --- a/ext/tk/lib/tkextlib/blt/barchart.rb +++ b/ext/tk/lib/tkextlib/blt/barchart.rb @@ -26,6 +26,7 @@ module Tk::BLT end private :__strval_optkeys +=begin BarElement_ID = ['blt_barchart_bar'.freeze, '00000'.taint].freeze def bar(elem=nil, keys={}) @@ -40,6 +41,7 @@ module Tk::BLT tk_send('bar', elem, keys) Element.new(self, elem, :without_creating=>true) end +=end def extents(item) num_or_str(tk_send_without_enc('extents', item)) diff --git a/ext/tk/lib/tkextlib/blt/component.rb b/ext/tk/lib/tkextlib/blt/component.rb index c5152ddab4..a42c39d0eb 100644 --- a/ext/tk/lib/tkextlib/blt/component.rb +++ b/ext/tk/lib/tkextlib/blt/component.rb @@ -78,6 +78,19 @@ module Tk::BLT ret = itemcget(['axis', id], option) end def axis_configure(id, slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure(['axis', id], slot, value) end def axis_configinfo(id, slot=nil) @@ -113,6 +126,32 @@ module Tk::BLT current_itemconfiginfo(['element', id], slot) end + def bar_cget(id, option) + itemcget(['bar', id], option) + end + def bar_configure(id, slot, value=None) + itemconfigure(['bar', id], slot, value) + end + def bar_configinfo(id, slot=nil) + itemconfiginfo(['bar', id], slot) + end + def current_bar_configinfo(id, slot=nil) + current_itemconfiginfo(['bar', id], slot) + end + + def line_cget(id, option) + itemcget(['line', id], option) + end + def line_configure(id, slot, value=None) + itemconfigure(['line', id], slot, value) + end + def line_configinfo(id, slot=nil) + itemconfiginfo(['line', id], slot) + end + def current_line_configinfo(id, slot=nil) + current_itemconfiginfo(['line', id], slot) + end + def gridline_cget(option) itemcget('grid', option) end @@ -294,6 +333,16 @@ module Tk::BLT @chart.current_axis_configinfo(@id, key) end + def command(cmd=nil, &b) + if cmd + configure('command', cmd) + elsif b + configure('command', Proc.new(&b)) + else + cget('command') + end + end + def delete @chart.axis_delete(@id) self @@ -385,10 +434,26 @@ module Tk::BLT ################# class Element < TkObject + extend Tk + extend TkItemFontOptkeys + extend TkItemConfigOptkeys + + extend Tk::BLT::PlotComponent::OptKeys + + ElementTypeName = 'element' + ElementTypeToClass = { ElementTypeName=>self } + ElementID_TBL = TkCore::INTERP.create_table + + TkCore::INTERP.init_ip_env{ ElementID_TBL.clear } + OBJ_ID = ['blt_chart_element'.freeze, '00000'.taint].freeze OBJ_TBL={} - def self.id2obj(chart, id) + def Element.type2class(type) + ElementTypeToClass[type] + end + + def Element.id2obj(chart, id) cpath = chart.path return id unless OBJ_TBL[cpath] OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id @@ -419,11 +484,12 @@ module Tk::BLT end @parent = @chart = chart @cpath = @chart.path + @typename = self.class::ElementTypeName Element::OBJ_TBL[@cpath][@element] = self keys = _symbolkey2str(keys) unless keys.delete('without_creating') # @chart.element_create(@element, keys) - tk_call(@chart, 'element', 'create', @element, keys) + tk_call(@chart, @typename, 'create', @element, keys) end end @@ -436,17 +502,21 @@ module Tk::BLT end def cget(option) - @chart.element_cget(@id, option) + # @chart.element_cget(@id, option) + @chart.__send__(@typename + '_cget', @id, option) end def configure(key, value=None) - @chart.element_configure(@id, key, value) + # @chart.element_configure(@id, key, value) + @chart.__send__(@typename + '_configure', @id, key, value) self end def configinfo(key=nil) - @chart.element_configinfo(@id, key) + # @chart.element_configinfo(@id, key) + @chart.__send__(@typename + '_configinfo', @id, key) end def current_configinfo(key=nil) - @chart.current_element_configinfo(@id, key) + # @chart.current_element_configinfo(@id, key) + @chart.__send__('current_' << @typename << '_configinfo', @id, key) end def activate(*args) @@ -455,7 +525,8 @@ module Tk::BLT end def closest(x, y, var, keys={}) - @chart.element_closest(x, y, var, @id, keys) + # @chart.element_closest(x, y, var, @id, keys) + @chart.__send__(@typename + '_closest', x, y, var, @id, keys) end def deactivate @@ -481,6 +552,15 @@ module Tk::BLT end end + class Bar < Element + ElementTypeName = 'bar'.freeze + ElementTypeToClass[ElementTypeName] = self + end + class Line < Element + ElementTypeName = 'line'.freeze + ElementTypeToClass[ElementTypeName] = self + end + ################# class GridLine < TkObject @@ -781,7 +861,7 @@ module Tk::BLT fail RuntimeError, "#{self} is an abstract class" end args, fontkeys = _parse_create_args(keys) - idnum = tk_call_without_enc(chart.path, 'create', + idnum = tk_call_without_enc(chart.path, 'marker', 'create', self::MarkerTypeName, *args) chart.marker_configure(idnum, fontkeys) unless fontkeys.empty? idnum.to_i # 'item id' is an integer number @@ -789,7 +869,8 @@ module Tk::BLT def self.create_type(chart, type, keys={}) args, fontkeys = _parse_create_args(keys) - idnum = tk_call_without_enc(chart.path, 'create', type, *args) + idnum = tk_call_without_enc(chart.path, 'marker', 'create', + type, *args) chart.marker_configure(idnum, fontkeys) unless fontkeys.empty? id = idnum.to_i # 'item id' is an integer number obj = self.allocate @@ -797,10 +878,10 @@ module Tk::BLT @parent = @chart = chart @path = chart.path @id = id - unless Tk::BLT::PlotComponent::MarkerID_TBL[@path] - Tk::BLT::PlotComponent::MarkerID_TBL[@path] = {} + unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] = {} end - Tk::BLT::PlotComponent::MarkerID_TBL[@path][@id] = self + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path][@id] = self } obj end @@ -810,10 +891,10 @@ module Tk::BLT @path = parent.path @id = create_self(*args) # an integer number as 'item id' - unless Tk::BLT::PlotComponent::MarkerID_TBL[@path] - Tk::BLT::PlotComponent::MarkerID_TBL[@path] = {} + unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path] = {} end - Tk::BLT::PlotComponent::MarkerID_TBL[@path][@id] = self + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@path][@id] = self end def create_self(*args) self.class.create(@chart, *args) # return an integer as 'item id' @@ -973,6 +1054,32 @@ module Tk::BLT _component_bindinfo('element', tag, context) end + def bar_bind(tag, context, *args) + _component_bind('bar', tag, context, *args) + end + def bar_bind_append(tag, context, *args) + _component_bind_append('bar', tag, context, *args) + end + def bar_bind_remove(tag, context) + _component_bind_remove('bar', tag, context) + end + def bar_bindinfo(tag, context=nil) + _component_bindinfo('bar', tag, context) + end + + def line_bind(tag, context, *args) + _component_bind('line', tag, context, *args) + end + def line_bind_append(tag, context, *args) + _component_bind_append('line', tag, context, *args) + end + def line_bind_remove(tag, context) + _component_bind_remove('line', tag, context) + end + def line_bindinfo(tag, context=nil) + _component_bindinfo('line', tag, context) + end + def legend_bind(tag, context, *args) _component_bind('legend', tag, context, *args) end @@ -1017,7 +1124,7 @@ module Tk::BLT end def axis_names(*pats) simplelist(tk_send('axis', 'names', *pats)).collect{|axis| - Axis.id2obj(self, axis) + Tk::BLT::PlotComponent::Axis.id2obj(self, axis) } end def axis_transform(id, val) @@ -1029,9 +1136,12 @@ module Tk::BLT end def axis_use(id, target=nil) if target - Axis.id2obj(self, tk_send('axis', 'use', tagid(id), tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('axis', 'use', + tagid(id), tagid(target))) else - Axis.id2obj(self, tk_send('axis', 'use', tagid(id))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('axis', 'use', tagid(id))) end end @@ -1082,7 +1192,7 @@ module Tk::BLT end def element_names(*pats) simplelist(tk_send('element', 'names', *pats)).collect{|elem| - Element.id2obj(self, elem) + Tk::BLT::PlotComponent::Element.id2obj(self, elem) } end def element_show(*names) @@ -1099,6 +1209,102 @@ module Tk::BLT ################### + def bar_create(id=nil, keys={}) + # tk_send('bar', 'create', tagid(id), keys) + Tk::BLT::PlotComponent::Bar.new(self, id, keys) + end + alias bar bar_create + def bar_activate(id, *indices) + tk_send('bar', 'activate', tagid(id), *indices) + self + end + def bar_closest(x, y, var, *args) + if args[-1].kind_of?(Hash) + keys = args.pop + bool(tk_send('bar', 'activate', x, y, var, + *(hash_kv(keys).concat(args)))) + else + bool(tk_send('bar', 'activate', x, y, var, *args)) + end + end + def bar_deactivate(*ids) + tk_send('bar', 'deactivate', *(ids.collect{|id| tagid(id)})) + self + end + def bar_delete(*ids) + tk_send('bar', 'delete', *(ids.collect{|id| tagid(id)})) + self + end + def bar_exist?(id) + bool(tk_send('bar', 'exists', tagid(id))) + end + def bar_names(*pats) + simplelist(tk_send('bar', 'names', *pats)).collect{|elem| + Tk::BLT::PlotComponent::Element.id2obj(self, elem) + } + end + def bar_show(*names) + if names.empty? + simplelist(tk_send('bar', 'show')) + else + tk_send('bar', 'show', *names) + self + end + end + def bar_type(id) + tk_send('bar', 'type', tagid(id)) + end + + ################### + + def line_create(id=nil, keys={}) + # tk_send('line', 'create', tagid(id), keys) + Tk::BLT::PlotComponent::Line.new(self, id, keys) + end + alias bar line_create + def line_activate(id, *indices) + tk_send('line', 'activate', tagid(id), *indices) + self + end + def line_closest(x, y, var, *args) + if args[-1].kind_of?(Hash) + keys = args.pop + bool(tk_send('line', 'activate', x, y, var, + *(hash_kv(keys).concat(args)))) + else + bool(tk_send('line', 'activate', x, y, var, *args)) + end + end + def line_deactivate(*ids) + tk_send('line', 'deactivate', *(ids.collect{|id| tagid(id)})) + self + end + def line_delete(*ids) + tk_send('line', 'delete', *(ids.collect{|id| tagid(id)})) + self + end + def line_exist?(id) + bool(tk_send('line', 'exists', tagid(id))) + end + def line_names(*pats) + simplelist(tk_send('line', 'names', *pats)).collect{|elem| + Tk::BLT::PlotComponent::Element.id2obj(self, elem) + } + end + def line_show(*names) + if names.empty? + simplelist(tk_send('line', 'show')) + else + tk_send('line', 'show', *names) + self + end + end + def line_type(id) + tk_send('line', 'type', tagid(id)) + end + + ################### + def gridline_off tk_send_without_enc('grid', 'off') self @@ -1124,9 +1330,12 @@ module Tk::BLT end def legend_get(pos, y=nil) if y - Element.id2obj(self, tk_send('legend', 'get', _at(pos, y))) + Tk::BLT::PlotComponent::Element.id2obj(self, + tk_send('legend', 'get', + _at(pos, y))) else - Element.id2obj(self, tk_send('legend', 'get', pos)) + Tk::BLT::PlotComponent::Element.id2obj(self, + tk_send('legend', 'get', pos)) end end @@ -1142,7 +1351,7 @@ module Tk::BLT end def pen_names(*pats) simplelist(tk_send('pen', 'names', *pats)).collect{|pen| - Pen.id2obj(self, pen) + Tk::BLT::PlotComponent::Pen.id2obj(self, pen) } end @@ -1211,7 +1420,7 @@ module Tk::BLT end def marker_names(*pats) simplelist(tk_send('marker', 'names', *pats)).collect{|id| - Marker.id2obj(self, id) + Tk::BLT::PlotComponent::Marker.id2obj(self, id) } end def marker_type(id) @@ -1220,21 +1429,23 @@ module Tk::BLT ################### - alias line_cget element_cget - alias line_configure element_configure - alias line_configinfo element_configinfo - alias current_line_configinfo current_element_configinfo - alias line_bind element_bind - alias line_bind_append element_bind_append - alias line_bind_remove element_bind_remove - alias line_bindinfo element_bindinfo - - ################### - def xaxis_cget(option) itemcget('xaxis', option) end def xaxis_configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure('xaxis', slot, value) end def xaxis_configinfo(slot=nil) @@ -1279,9 +1490,11 @@ module Tk::BLT end def xaxis_use(target=nil) if target - Axis.id2obj(self, tk_send('xaxis', 'use', tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('xaxis', 'use', + tagid(target))) else - Axis.id2obj(self, tk_send('xaxis', 'use')) + Tk::BLT::PlotComponent::Axis.id2obj(self, tk_send('xaxis', 'use')) end end @@ -1289,6 +1502,19 @@ module Tk::BLT itemcget('x2axis', option) end def x2axis_configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure('x2axis', slot, value) end def x2axis_configinfo(slot=nil) @@ -1333,9 +1559,11 @@ module Tk::BLT end def x2axis_use(target=nil) if target - Axis.id2obj(self, tk_send('x2axis', 'use', tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('x2axis', 'use', + tagid(target))) else - Axis.id2obj(self, tk_send('x2axis', 'use')) + Tk::BLT::PlotComponent::Axis.id2obj(self, tk_send('x2axis', 'use')) end end @@ -1343,6 +1571,19 @@ module Tk::BLT itemcget('yaxis', option) end def yaxis_configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure('yaxis', slot, value) end def yaxis_configinfo(slot=nil) @@ -1387,9 +1628,11 @@ module Tk::BLT end def yaxis_use(target=nil) if target - Axis.id2obj(self, tk_send('yaxis', 'use', tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('yaxis', 'use', + tagid(target))) else - Axis.id2obj(self, tk_send('yaxis', 'use')) + Tk::BLT::PlotComponent::Axis.id2obj(self, tk_send('yaxis', 'use')) end end @@ -1397,6 +1640,19 @@ module Tk::BLT itemcget('y2axis', option) end def y2axis_configure(slot, value=None) + if slot.kind_of?(Hash) + slot = _symbolkey2str(slot) + if cmd = slot.delete('command') + slot['command'] = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end + elsif slot == :command || slot == 'command' + cmd = value + value = proc{|w, tick| + cmd.call(TkComm.window(w), TkComm.num_or_str(tick)) + } + end itemconfigure('y2axis', slot, value) end def y2axis_configinfo(slot=nil) @@ -1441,9 +1697,11 @@ module Tk::BLT end def y2axis_use(target=nil) if target - Axis.id2obj(self, tk_send('y2axis', 'use', tagid(target))) + Tk::BLT::PlotComponent::Axis.id2obj(self, + tk_send('y2axis', 'use', + tagid(target))) else - Axis.id2obj(self, tk_send('y2axis', 'use')) + Tk::BLT::PlotComponent::Axis.id2obj(self, tk_send('y2axis', 'use')) end end end diff --git a/ext/tk/lib/tkextlib/blt/graph.rb b/ext/tk/lib/tkextlib/blt/graph.rb index b16c72458a..e9fbdd587a 100644 --- a/ext/tk/lib/tkextlib/blt/graph.rb +++ b/ext/tk/lib/tkextlib/blt/graph.rb @@ -26,6 +26,7 @@ module Tk::BLT end private :__strval_optkeys +=begin BarElement_ID = ['blt_graph_bar'.freeze, '00000'.taint].freeze def bar(elem=nil, keys={}) @@ -40,6 +41,7 @@ module Tk::BLT tk_send('bar', elem, keys) Element.new(self, elem, :without_creating=>true) end +=end def extents(item) num_or_str(tk_send_without_enc('extents', item)) diff --git a/ext/tk/lib/tkextlib/blt/stripchart.rb b/ext/tk/lib/tkextlib/blt/stripchart.rb index b8cbf8bc34..64c5c1abf8 100644 --- a/ext/tk/lib/tkextlib/blt/stripchart.rb +++ b/ext/tk/lib/tkextlib/blt/stripchart.rb @@ -26,6 +26,7 @@ module Tk::BLT end private :__strval_optkeys +=begin BarElement_ID = ['blt_stripchart_bar'.freeze, '00000'.taint].freeze def bar(elem=nil, keys={}) @@ -40,6 +41,7 @@ module Tk::BLT tk_send('bar', elem, keys) Element.new(self, elem, :without_creating=>true) end +=end def extents(item) num_or_str(tk_send_without_enc('extents', item)) 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 |