1#!/usr/bin/env ruby 2require 'tk' 3require 'tkextlib/blt' 4 5file = File.join(File.dirname(File.expand_path(__FILE__)), 6 'images', 'buckskin.gif') 7bgTexture = TkPhotoImage.new(:file=>file) 8 9TkOption.add('*Graph.Tile', bgTexture) 10TkOption.add('*Label.Tile', bgTexture) 11TkOption.add('*Frame.Tile', bgTexture) 12TkOption.add('*Htext.Tile', bgTexture) 13TkOption.add('*TileOffset', 0) 14TkOption.add('*HighlightThickness', 0) 15TkOption.add('*Element.ScaleSybols', false) 16TkOption.add('*Element.Smooth', :linear) 17TkOption.add('*activeLine.Color', 'yellow4') 18TkOption.add('*activeLine.Fill', 'yellow') 19TkOption.add('*activeLine.LineWidth', 0) 20TkOption.add('*Element.Pixels', 3) 21TkOption.add('*Graph.halo', '7i') 22 23if Tk.root.winfo_screenvisual != 'staticgray' 24 TkOption.add('*print.background', 'yellow') 25 TkOption.add('*quit.background', 'red') 26end 27 28length = 250000 29graph = Tk::BLT::Graph.new(:title=>"Scatter Plot\n#{length} points") 30graph.xaxis_configure(:loose=>false, :title=>'X Axis Label') 31graph.yaxis_configure(:title=>'Y Axis Label') 32graph.legend_configure(:activerelief=>:sunken, :background=>'') 33 34Tk::BLT::Table.add(Tk.root, graph, [0,0], :fill=>:both) 35 36v_x = Tk::BLT::Vector.new(length) 37v_y = Tk::BLT::Vector.new(length) 38v_x.expr("random(#{v_x})") 39v_y.expr("random(#{v_y})") 40v_x.sort(v_y) 41 42plot = Tk::BLT::PlotComponent::Element.new(graph, :symbol=>:square, 43 :color=>'green4', :fill=>'green2', 44 :linewidth=>0, :outlinewidth=>1, 45 :pixels=>4, :label=>'plot', 46 :xdata=>v_x, :ydata=>v_y) 47 48Tk.root.minsize(0, 0) 49 50#graph.zoom_stack 51#graph.crosshairs 52#graph.active_legend 53#graph.closest_point 54Tk::BLT.zoom_stack(graph) 55Tk::BLT.crosshairs(graph) 56Tk::BLT.active_legend(graph) 57Tk::BLT.closest_point(graph) 58 59Tk::BLT::Busy.hold(graph) 60Tk.update 61Tk::BLT::Busy.release(graph) 62 63Tk.mainloop 64