1#!/usr/bin/env ruby 2require 'tk' 3require 'tkextlib/blt' 4 5load File.join(File.dirname(File.expand_path(__FILE__)), 6 'scripts', 'stipples.rb') 7 8TkOption.add('*graph.x.Title', 'X Axis Label') 9TkOption.add('*graph.y.Title', 'Y Axis Label') 10TkOption.add('*graph.title', 'A Simple Barchart') 11TkOption.add('*graph.x.Font', 'Times 10') 12TkOption.add('*graph.Element.Relief', :raised) 13 14visual = Tk.root.winfo_screenvisual 15if visual != 'staticgray' && visual != 'grayscale' 16 TkOption.add('*graph.LineMarker.color', 'yellow') 17 TkOption.add('*graph.Element.Background', 'white') 18 TkOption.add('*graph.Legend.activeForeground', 'pink') 19 TkOption.add('*print.background', 'yellow') 20 TkOption.add('*quit.background', 'red') 21 TkOption.add('*graph.background', 'palegreen') 22 TkOption.add('*graph.plotBackground', 'lightblue') 23end 24 25htext = Tk::BLT::Htext.new(:widgetname=>'.htext', :text=><<EOD) 26 This is an example of the barchart widget. The barchart has 27 many components; x and y axis, legend, crosshairs, elements, etc. 28 To create a postscript file "bar.ps", press the %% 29 30 ruby { 31 b = TkButton.new(Tk::BLT::Htext::Htext_Widget.window, 32 :widgetname=>'print', :text=>'Print', 33 :command=>proc{ 34 $graph.postsript(:output=>'bar.ps') 35 }) 36 Tk::BLT::Htext::Htext_Widget.window.append(b) 37 } 38 39%% button. 40%% 41 42 ruby { 43 $graph = Tk::BLT::Barchart.new(:widgetname=>'.htext.graph', 44 :relief=>:raised, :borderwidth=>2) 45 $graph.xaxis_configure(:rotate=>90, :stepsize=>0) 46 Tk::BLT::Htext::Htext_Widget.window.append($graph, 47 :fill=>:both, :padx=>4) 48 } 49 50%% 51 Hit the %% 52 53 ruby { 54 b = TkButton.new(Tk::BLT::Htext::Htext_Widget.window, 55 :widgetname=>'quit', :text=>'Quit', 56 :command=>proc{ exit }) 57 Tk::BLT::Htext::Htext_Widget.window.append(b) 58 } 59 60%% button when you've seen enough.%% 61 62 ruby { 63 l = TkLabel.new(Tk::BLT::Htext::Htext_Widget.window, :bitmap=>'BLT') 64 Tk::BLT::Htext::Htext_Widget.window.append(l, :padx=>20) 65 } 66 67%% 68EOD 69 70names = %w(One Two Three Four Five Six Seven Eight) 71if visual == 'staticgray' || visual == 'grayscale' 72 fgcolors = %w(white white white white white white white white) 73 bgcolors = %w(black black black black black black black black) 74else 75 fgcolors = %w(yellow orange red magenta purple blue cyan green) 76 bgcolors = %w(yellow4 orange4 red4 magenta4 purple4 blue4 cyan4 green4) 77end 78 79numColors = names.length 80 81Tk::TCL_PRECISION.value = 15 82 83x = Tk::BLT::Vector.new 84y = Tk::BLT::Vector.new 85x.seq(-5.0, 5.0, 0.2) 86y.expr("sin(#{x})") 87barWidth = 0.19 88 89$graph.element_create('sin', :relief=>:raised, :borderwidth=>1, 90 :x=>x, :y=>y, :barwidth=>barWidth) 91 92Tk::BLT::Table.add(Tk.root, htext, :fill=>:both) 93 94Tk.root.minsize(0, 0) 95 96Tk::BLT.zoom_stack($graph) 97Tk::BLT.crosshairs($graph) 98Tk::BLT.active_legend($graph) 99Tk::BLT.closest_point($graph) 100 101Tk.mainloop 102