[Tioga-users] Generating Tioga plots from within Ruby

David MacMahon davidm at astro.berkeley.edu
Mon Apr 28 16:01:31 EDT 2008


I'm still learning  Tioga, but after looking through most of the  
tutorial (thanks!) it seems that the typical use pattern for Tioga is  
this...

# Setup stuff
class MyClass
   def initalize()
     # save reference to FigureMaker.default
     # setup defaults
     # define figure with name and block
   end
end
MyClass.new

Then, to make the pdf from within Ruby (i.e. not from the command  
line), I need to call...

FigureMaker.default.make_pdf(figure_name_or_number)

...which will then do some initializing stuff, call my figure's  
block, and then do some finishing stuff.

What I would find convenient is a more "immediate" version of  
make_pdf that could be called like this...

FigureMaker.default.make_pdf_immediately() do |t|
   # whatever the block that I passed to def_figure would have done
end

In fact, make_pdf could behave this way if a block is given and  
behave the original way of a block is not given.  Note that the  
FigureMaker instance would pass itself into the block (as alluded to  
with the "|t|" parameter in the pseudo-code).  Even better still,  
FigureMaker.make_pdf could forward the call and block to the  
FigureMaker.default so that one could just say...

FigureMaker.make_pdf() do |t|
   # t will be FigureMaker.default
   # whatever the block that I passed to def_figure would have done
end

I think this can all be accomplished with one small change and one  
small addition.  Here is the change...

--- split/Tioga/lib/FigMkr.rb   2008-04-28 12:51:40.000000000 -0700
+++ split/Tioga/lib/FigMkr.patched.rb   2008-04-28 12:52:07.000000000  
-0700
@@ -2332 +2332 @@
-            cmd.call
+            cmd.call(self)

...and here is the addition...

module Tioga
   class FigureMaker
     def self.make_pdf(name='immediate', &block)
       self.default.def_figure(name, &block)
       self.default.make_pdf(name)
     end
   end
end

With these in place, one can so something like...

require 'rubygems'
require 'Tioga/FigureMaker'

include Tioga
include FigureConstants

FigureMaker.make_pdf('blue') do |t|
   t.fill_color = Blue
   t.fill_frame
end

Any chance these changes (possibly fleshed out a little more vis a  
vis the FigureMaker#make_pdf instance method) could be incorporated  
in the next Tioga version?

Thanks,
Dave



More information about the Tioga-users mailing list