ruby/ 40755 1750 144 0 7306407465 10777 5ustar michaelusersruby/gd_graph/ 40755 1750 144 0 7306407500 12540 5ustar michaelusersruby/gd_graph/lib/ 40755 1750 144 0 7306407510 13307 5ustar michaelusersruby/gd_graph/lib/graph.rb100644 1750 144 10700 7306405633 15054 0ustar michaelusers# # GD::Graph and GD::Graph3d Perl wrapper # (pipes generated code to Perl interpreter) # # $Id: graph.rb,v 1.1 2001/06/03 10:04:11 michael Exp $ # Copyright (c) 2001 by Michael Neumann (neumann@s-direktnet.de) # # Release under the same terms of Ruby itself. # module GD module Graph # these diagrams are available DIAGRAMS = %w(Bars Lines Points LinesPoints Area Mixed Pie Bars3d Lines3d Pie3d) class Font def initialize(font, size=nil) if size.nil? @font = font # gdXXX else if font.is_a? Array @font = "['#{font[0]}', '#{font[1]}', #{font[2]}], #{size}" else @font = font.inspect end end end def to_s @font end end class Graph def initialize(modname, width, height, perl_intr) @modname, @width, @height = modname, width, height @set = nil @data = nil @set_func = {} @perl_intr = perl_intr || "/usr/bin/env perl 2>/dev/null" end def set(hash) @set = hash end def plot(data) @data = data end def set_text_clr(color_name) @set_func['text_color'] = color_name.inspect end def set_title_font(font) @set_func['title_font'] = font.to_s end # pie only --------------------------------------------- def set_label_font(font) @set_func['label_font'] = font.to_s end # pie and axes ----------------------------------------- def set_value_font(font) @set_func['value_font'] = font.to_s end # axestyle graphs only --------------------------------- def set_legend(*legend_keys) @set_func['legend'] = legend_keys.collect{|i| i.inspect}.join(", ") end def set_legend_font(font) @set_func['legent_font'] = font.to_s end def set_x_label_font(font) @set_func['x_label_font'] = font.to_s end def set_y_label_font(font) @set_func['y_label_font'] = font.to_s end def set_x_axis_font(font) @set_func['x_axis_font'] = font.to_s end def set_y_axis_font(font) @set_func['y_axis_font'] = font.to_s end # output method --------------------------- def jpeg(o) save("jpeg", o) end def png(o) save("png", o) end def gif(o) save("gif", o) end def gd(o) save("gd", o) end def gd2(o) save("gd2", o) end private # --------------------------------- def save(format, output) raise "no data found" if @data.nil? pipe = IO.popen(@perl_intr, "r+") pipe << "use GD::Graph::#@modname;" pipe << "use GD::Graph::Data;" pipe << "use GD::Graph::colour;" pipe << "my $graph = GD::Graph::#@modname->new(#@width, #@height);" output_set(@set, pipe) unless @set.nil? output_setfunc(pipe) output_data(@data, pipe) pipe << "my $gd = $graph->plot($data);\n" pipe << "print $gd->#{format}();\n" pipe.close_write output << pipe.read pipe.close end # output functions -------------------------- def output_set(hash, output) output << "$graph->set(\n" first = true hash.each {|key,value| if first first = false else output << ", " end output << "#{key} => #{value.inspect}\n" } output << ");\n" end def output_setfunc(output) @set_func.each do |k,v| output << "$graph->set_#{k}(#{v});" end end def output_data(data, output) output << "my $data = GD::Graph::Data->new([\n" data.each {|arr| output << "[" output << arr.collect {|e| if e.nil? "undef" else e.inspect end }.join(", ") output << "],\n" } output << "]);\n" end end # class Graph # create the diagram classes --------------------- DIAGRAMS.each do |klass| eval %{ class #{klass} < Graph def initialize(w, h, pi=nil); super('#{klass.downcase}', w, h, pi) end end } end end # module Graph end # module GD if __FILE__ == $0 for i in GD::Graph::DIAGRAMS do graph = eval("GD::Graph::"+i).new(800, 600) graph.set( :x_label => 'Day of week', :y_label => 'Number of hits', :title => 'Access Hits of my Web site' ) graph.plot([ ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], [1203, nil, 3955, 2880, 3012, 1233,1232] ]) f = File.new(i.to_s + ".jpg", "w+") graph.jpeg(f) f.close end end ruby/gd_graph/README100644 1750 144 1302 7306406106 13512 0ustar michaelusers$Id: README,v 1.2 2001/06/03 10:07:02 michael Exp $ GD::Graph/GD::Graph3d for Ruby Copyright (C) 2001 by Michael Neumann (neumann@s-direktnet.de) License is the same as Ruby's PREREQUISITES ============= You need Perl's GD::Graph and/or GD::Graph3d installed, where both depend on GD.pm installed. Not to say, that you need a Perl interpreter :-) INSTALL ======= Type "ruby install.rb" in current directory. Make sure you have root priviledges before you do this. The file graph.rb is installed in the site_ruby directory into the directory "gd". DOCUMENTATION ============= See graph.rb or consult the man pages of Perl's GD::Graph and GD::Graph3d. (http://www.perldoc.com/cpan/GD/Graph.html). ruby/gd_graph/install.rb100644 1750 144 1006 7306406106 14626 0ustar michaelusers#!/usr/bin/env ruby # # $Id: install.rb,v 1.2 2001/06/03 10:07:02 michael Exp $ # Install Ruby's GD::Graph # DIR = "gd" FILES = %w(graph.rb) require "rbconfig" require "ftools" include Config RV = CONFIG["MAJOR"] + "." + CONFIG["MINOR"] DSTPATH = CONFIG["sitedir"] + "/" + RV + "/" + DIR begin File.mkpath DSTPATH, true for name in FILES do File.install "lib/#{name}", "#{DSTPATH}/#{name}", 0644, true end rescue puts "install failed!" puts $! else puts "install succeed!" end