# Displaying gruff graphs

**URL:** <https://rubytalk.org/t/displaying-gruff-graphs/45538>\
**Category:** ruby-talk\
**Created:** [31 March 2008 15:48 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538 "2008-03-31T15:48:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_Reyes](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Victor\_Reyes](https://rubytalk.org/u/Victor_Reyes)\
**Post date:** [31 March 2008 15:48 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/1 "2008-03-31T15:48:52Z")

</div>

Team,

Once a graph is written to disk, g.write("filename.png"), how can it be  
displayed in Ruby?  
I would like to re-create the graph and re-displayed often enough to give  
the appearance of "real time"

Thank you

Victor

---

<div class="post-metadata">

**Author:** ![Mark\_Holton](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mark\_Holton](https://rubytalk.org/u/Mark_Holton)\
**Post date:** [31 March 2008 15:59 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/2 "2008-03-31T15:59:06Z")

</div>

You could make periodical Ajax calls to the Controller creating the graph.

[http://www.prototypejs.org/api/ajax#method-ajax.periodicalupdater](http://www.prototypejs.org/api/ajax#method-ajax.periodicalupdater)

> **···**
>
> On Mon, Mar 31, 2008 at 8:48 AM, Victor Reyes \<victor.reyes@gmail.com\> wrote:
> 
> > Team,
> > 
> > Once a graph is written to disk, g.write("filename.png"), how can it be  
> > displayed in Ruby?  
> > I would like to re-create the graph and re-displayed often enough to give  
> > the appearance of "real time"
> > 
> > Thank you
> > 
> > Victor

---

<div class="post-metadata">

**Author:** ![Alex\_Fenton](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@Alex\_Fenton](https://rubytalk.org/u/Alex_Fenton)\
**Post date:** [31 March 2008 16:40 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/3 "2008-03-31T16:40:04Z")

</div>

Victor Reyes wrote:

> Once a graph is written to disk, g.write("filename.png"), how can it be  
> displayed in Ruby?  
> I would like to re-create the graph and re-displayed often enough to give  
> the appearance of "real time"

It's not clear whether you meant via a browser or in a desktop app. If you want to show it on the desktop, you'll need some sort of GUI toolkit to display a window then draw the bitmap in it.

You have a lot of choices: wxRuby, FXRuby, QT/Ruby, Tk, Ruby/GTK etc etc. They vary widely in suitability for different platforms, ease of installation, features, aesthetics.

I use wxRuby b/c it's easy to install (gem install wxruby) and looks good on all the big platforms. A simple 25-line example that would regularly redraw an updated graph is below:

hth  
alex

> **···**
>
> \_\_  
> require 'wx'  
> require 'tempfile'
> 
> # A frame that draws a regularly updated graph from Gruff every X millisecs  
> class GruffFrame \< Wx::Frame  
> &nbsp;&nbsp;&nbsp;def initialize(refresh\_delay = 5000)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super(nil, :title =\> 'Gruff')  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wx::Timer.every(refresh\_delay) { refresh }  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;evt\_paint :on\_paint  
> &nbsp;&nbsp;&nbsp;end
> 
> &nbsp;&nbsp;&nbsp;# Writes the gruff graph to a file then reads it back to draw it  
> &nbsp;&nbsp;&nbsp;def on\_paint  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Set up your graph here  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;graph = Gruff::Lines.new # ....  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Write to a tempfile and read back  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp = Tempfile.new('gruff')  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;graph.write(tmp.path)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bmp = Wx::Bitmap.new(tmp.path, Wx::BITMAP\_TYPE\_PNG)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Draw it on the Frame  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paint do | dc |  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dc.draw\_bitmap(bmp, 0, 0, false)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;&nbsp;end  
> end
> 
> Wx::App.run { GruffFrame.new.show }

---

<div class="post-metadata">

**Author:** ![Victor\_Reyes](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Victor\_Reyes](https://rubytalk.org/u/Victor_Reyes)\
**Post date:** [31 March 2008 17:19 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/4 "2008-03-31T17:19:17Z")

</div>

Mark, thank you for your answer and time.

Alex, this is exactly what I am looking for. I am trying to do two things at  
the same time: Learning Ruby well and second learning to use gruff so I can  
use it at work.  
I copied your sample code where I incorporated the sample gruff code that I  
got from the web. When I run it, a wx frame flashes quickly and end. Some  
errors are displayed on the screen.  
Would you mind if I send you directly my piece of code? It is very very  
simple. It only adds about five (5) lines to your sample code.

Thank you for your help.

Victor

PS: The following are the errors:  
C:\$user\vmr\Ruby\>ruby rdg00.rb  
c:/ruby/lib/ruby/gems/1.8/gems/gruff-0.3.1/lib/gruff/base.rb:465:in `write':  
no encode delegate for this image format `C:/DOCUME~1/REYESV~1  
:ImageMagickError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/gruff-0.3.1/lib/gruff/base.rb:465:in  
`write'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from rdg00.rb:25:in `on\_paint'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32/lib/wx/classes/evthandler.rb:123:in  
`call'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32/lib/wx/classes/evthandler.rb:123:in  
`acquire\_handler'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32/lib/wx/classes/window.rb:44:in  
`call'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32/lib/wx/classes/window.rb:44:in  
`evt\_paint'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32/lib/wx/classes/app.rb:16:in  
`call'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32/lib/wx/classes/app.rb:16:in  
`process\_event'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32/lib/wx/classes/app.rb:16:in  
`main\_loop'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32/lib/wx/classes/app.rb:16:in  
`run'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from rdg00.rb:34

> **···**
>
> On 3/31/08, Alex Fenton \<aff28@deleteme.cam.ac.uk\> wrote:
> 
> > Victor Reyes wrote:
> > 
> > \> Once a graph is written to disk, g.write("filename.png"), how can it be  
> > \> displayed in Ruby?  
> > \> I would like to re-create the graph and re-displayed often enough to  
> > give  
> > \> the appearance of "real time"
> > 
> > It's not clear whether you meant via a browser or in a desktop app. If  
> > you want to show it on the desktop, you'll need some sort of GUI toolkit  
> > to display a window then draw the bitmap in it.
> > 
> > You have a lot of choices: wxRuby, FXRuby, QT/Ruby, Tk, Ruby/GTK etc  
> > etc. They vary widely in suitability for different platforms, ease of  
> > installation, features, aesthetics.
> > 
> > I use wxRuby b/c it's easy to install (gem install wxruby) and looks  
> > good on all the big platforms. A simple 25-line example that would  
> > regularly redraw an updated graph is below:
> > 
> > hth  
> > alex  
> > \_\_  
> > require 'wx'  
> > require 'tempfile'
> > 
> > # A frame that draws a regularly updated graph from Gruff every X  
> > millisecs  
> > class GruffFrame \< Wx::Frame  
> > &nbsp;&nbsp;&nbsp;def initialize(refresh\_delay = 5000)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super(nil, :title =\> 'Gruff')  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wx::Timer.every(refresh\_delay) { refresh }  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;evt\_paint :on\_paint  
> > &nbsp;&nbsp;&nbsp;end
> > 
> > &nbsp;&nbsp;&nbsp;# Writes the gruff graph to a file then reads it back to draw it  
> > &nbsp;&nbsp;&nbsp;def on\_paint  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Set up your graph here  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;graph = Gruff::Lines.new # ....  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Write to a tempfile and read back  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tmp = Tempfile.new('gruff')  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;graph.write(tmp.path)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bmp = Wx::Bitmap.new(tmp.path, Wx::BITMAP\_TYPE\_PNG)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Draw it on the Frame  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;paint do | dc |  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dc.draw\_bitmap(bmp, 0, 0, false)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;&nbsp;end  
> > end
> > 
> > Wx::App.run { GruffFrame.new.show }

---

<div class="post-metadata">

**Author:** ![Victor\_Reyes](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Victor\_Reyes](https://rubytalk.org/u/Victor_Reyes)\
**Post date:** [31 March 2008 19:32 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/5 "2008-03-31T19:32:21Z")

</div>

I finally got this working with wx by hard-coding the file path. The graphs  
(pie) is displayed, but now I have a small glitch, of course.  
The frame is a about 1/4 of what it needs to be, and so I have to resize it  
with the mouse.  
Perhaps I need to make the frame where the graph is displayed a bit larger.  
Is there anyway to make the size of the frame "dynamic" based on the size of  
the image to be displayed?  
In the mean time I will look in the wx documentation.

Thank you

Victor

> **···**
>
> On 3/31/08, Victor Reyes \<victor.reyes@gmail.com\> wrote:
> 
> > Mark, thank you for your answer and time.
> > 
> > Alex, this is exactly what I am looking for. I am trying to do two things  
> > at  
> > the same time: Learning Ruby well and second learning to use gruff so I  
> > can  
> > use it at work.  
> > I copied your sample code where I incorporated the sample gruff code that  
> > I  
> > got from the web. When I run it, a wx frame flashes quickly and end. Some  
> > errors are displayed on the screen.  
> > Would you mind if I send you directly my piece of code? It is very very  
> > simple. It only adds about five (5) lines to your sample code.
> > 
> > Thank you for your help.
> > 
> > Victor
> > 
> > PS: The following are the errors:  
> > C:\$user\vmr\Ruby\>ruby rdg00.rb  
> > c:/ruby/lib/ruby/gems/1.8/gems/gruff-0.3.1/lib/gruff/base.rb:465:in  
> > `write':  
> > no encode delegate for this image format `C:/DOCUME~1/REYESV~1  
> > :ImageMagickError)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/gruff-0.3.1  
> > /lib/gruff/base.rb:465:in  
> > `write'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from rdg00.rb:25:in `on\_paint'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32  
> > /lib/wx/classes/evthandler.rb:123:in  
> > `call'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32  
> > /lib/wx/classes/evthandler.rb:123:in  
> > `acquire\_handler'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32  
> > /lib/wx/classes/window.rb:44:in  
> > `call'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32  
> > /lib/wx/classes/window.rb:44:in  
> > `evt\_paint'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32  
> > /lib/wx/classes/app.rb:16:in  
> > `call'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32  
> > /lib/wx/classes/app.rb:16:in  
> > `process\_event'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32  
> > /lib/wx/classes/app.rb:16:in  
> > `main\_loop'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from c:/ruby/lib/ruby/gems/1.8/gems/wxruby-1.9.5-i386-mswin32  
> > /lib/wx/classes/app.rb:16:in  
> > `run'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from rdg00.rb:34
> > 
> > On 3/31/08, Alex Fenton \<aff28@deleteme.cam.ac.uk\> wrote:  
> > \>
> > 
> > \> Victor Reyes wrote:  
> > \>  
> > \> \> Once a graph is written to disk, g.write("filename.png"), how can it  
> > be  
> > \> \> displayed in Ruby?  
> > \> \> I would like to re-create the graph and re-displayed often enough to  
> > \> give  
> > \> \> the appearance of "real time"  
> > \>  
> > \>  
> > \> It's not clear whether you meant via a browser or in a desktop app. If  
> > \> you want to show it on the desktop, you'll need some sort of GUI toolkit  
> > \> to display a window then draw the bitmap in it.  
> > \>  
> > \> You have a lot of choices: wxRuby, FXRuby, QT/Ruby, Tk, Ruby/GTK etc  
> > \> etc. They vary widely in suitability for different platforms, ease of  
> > \> installation, features, aesthetics.  
> > \>  
> > \> I use wxRuby b/c it's easy to install (gem install wxruby) and looks  
> > \> good on all the big platforms. A simple 25-line example that would  
> > \> regularly redraw an updated graph is below:  
> > \>  
> > \> hth  
> > \> alex  
> > \> \_\_  
> > \> require 'wx'  
> > \> require 'tempfile'  
> > \>  
> > \> # A frame that draws a regularly updated graph from Gruff every X  
> > \> millisecs  
> > \> class GruffFrame \< Wx::Frame  
> > \> def initialize(refresh\_delay = 5000)  
> > \> super(nil, :title =\> 'Gruff')  
> > \> Wx::Timer.every(refresh\_delay) { refresh }  
> > \> evt\_paint :on\_paint  
> > \> end  
> > \>  
> > \> # Writes the gruff graph to a file then reads it back to draw it  
> > \> def on\_paint  
> > \> # Set up your graph here  
> > \> graph = Gruff::Lines.new # ....  
> > \> # Write to a tempfile and read back  
> > \> tmp = Tempfile.new('gruff')  
> > \> graph.write(tmp.path)  
> > \> bmp = Wx::Bitmap.new(tmp.path, Wx::BITMAP\_TYPE\_PNG)  
> > \> # Draw it on the Frame  
> > \> paint do | dc |  
> > \> dc.draw\_bitmap(bmp, 0, 0, false)  
> > \> end  
> > \> end  
> > \> end  
> > \>  
> > \> Wx::App.run { GruffFrame.new.show }  
> > \>  
> > \>

---

<div class="post-metadata">

**Author:** ![Alex\_Fenton2](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Alex\_Fenton2](https://rubytalk.org/u/Alex_Fenton2)\
**Post date:** [31 March 2008 21:10 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/6 "2008-03-31T21:10:04Z")

</div>

Victor Reyes wrote:

> I finally got this working with wx by hard-coding the file path.

That other first error looks like an ImageMagick problem. Sorry I can't help with that as I'm too lazy to install it; I just used wxRuby's own image file writing features to test it out quickly.

> The graphs  
> (pie) is displayed, but now I have a small glitch, of course.  
> The frame is a about 1/4 of what it needs to be, and so I have to resize it  
> with the mouse.  
> Perhaps I need to make the frame where the graph is displayed a bit larger.  
> Is there anyway to make the size of the frame "dynamic" based on the size of  
> the image to be displayed?

You can either constrain the frame to be a particular size, and prevent it being resized, or dynamically resize the graph image as the frame is resized by the user's use of the mouse.

For the former, when you call super in the GruffFrame constructor, add the argument :style =\> Wx::DEFAULT\_FRAME\_STYLE ^ Wx::RESIZE\_BORDER

(i.e. use the default frame style, minus the mouse-draggable resize handle in the corner)

Then in the GruffFrame#initialize method, set the Frame's client\_size to the size you want the image, e.g.

self.client\_size = [480, 320]

(The "client size" is the space within the Frame that is available for drawing on - its total pixel size minus the window borders, title bar etc. This way of setting the frame size will given consistent results across Linux, Windows and OS X)

If you want the latter, a resizeable frame, on each refresh, tell Gruff what size of PNG you want. According to the docs, you can pass the Gruff Graph constructor a size as a string. So call new like this:

graph = Gruff::Lines.new("#{client\_size.width}x#{client\_size.height}")

If you go down this route, you'll probably also want to refresh the graph if the Frame is resized; use evt\_size in the frame constructor for this:

evt\_size { | evt | refresh; evt.skip }

> In the mean time I will look in the wx documentation.

I expect you've found [http://wxruby.rubyforge.org/doc/](http://wxruby.rubyforge.org/doc/)

If you've got further questions about wxRuby, there's a friendly mailing list which is a better place than c.l.r. for specifically wxRuby questions: [http://rubyforge.org/mail/?group\_id=35](http://rubyforge.org/mail/?group_id=35)

alex

---

<div class="post-metadata">

**Author:** ![Victor\_Reyes](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Victor\_Reyes](https://rubytalk.org/u/Victor_Reyes)\
**Post date:** [1 April 2008 12:44 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/7 "2008-04-01T12:44:16Z")

</div>

Alex,

I do truly appreciate your time to explain this new stuff to me.  
I will try to digest the info you provided me and also I will try to gather  
more info from the wx doc.  
Do you know if wx runs under AIX (IBM UNIX)?

Thank you

Victor

> **···**
>
> On Mon, Mar 31, 2008 at 5:10 PM, Alex Fenton \<alex@deleteme.pressure.to\> wrote:
> 
> > Victor Reyes wrote:
> > 
> > \> I finally got this working with wx by hard-coding the file path.
> > 
> > That other first error looks like an ImageMagick problem. Sorry I can't  
> > help with that as I'm too lazy to install it; I just used wxRuby's own  
> > image file writing features to test it out quickly.
> > 
> > \> The graphs  
> > \> (pie) is displayed, but now I have a small glitch, of course.  
> > \> The frame is a about 1/4 of what it needs to be, and so I have to resize  
> > it  
> > \> with the mouse.  
> > \> Perhaps I need to make the frame where the graph is displayed a bit  
> > larger.  
> > \> Is there anyway to make the size of the frame "dynamic" based on the  
> > size of  
> > \> the image to be displayed?
> > 
> > You can either constrain the frame to be a particular size, and prevent  
> > it being resized, or dynamically resize the graph image as the frame is  
> > resized by the user's use of the mouse.
> > 
> > For the former, when you call super in the GruffFrame constructor, add  
> > the argument :style =\> Wx::DEFAULT\_FRAME\_STYLE ^ Wx::RESIZE\_BORDER
> > 
> > (i.e. use the default frame style, minus the mouse-draggable resize  
> > handle in the corner)
> > 
> > Then in the GruffFrame#initialize method, set the Frame's client\_size to  
> > the size you want the image, e.g.
> > 
> > self.client\_size = [480, 320]
> > 
> > (The "client size" is the space within the Frame that is available for  
> > drawing on - its total pixel size minus the window borders, title bar  
> > etc. This way of setting the frame size will given consistent results  
> > across Linux, Windows and OS X)
> > 
> > If you want the latter, a resizeable frame, on each refresh, tell Gruff  
> > what size of PNG you want. According to the docs, you can pass the  
> > Gruff Graph constructor a size as a string. So call new like this:
> > 
> > graph = Gruff::Lines.new("#{client\_size.width}x#{client\_size.height}")
> > 
> > If you go down this route, you'll probably also want to refresh the  
> > graph if the Frame is resized; use evt\_size in the frame constructor for  
> > this:
> > 
> > evt\_size { | evt | refresh; evt.skip }
> > 
> > \> In the mean time I will look in the wx documentation.
> > 
> > I expect you've found [http://wxruby.rubyforge.org/doc/](http://wxruby.rubyforge.org/doc/)
> > 
> > If you've got further questions about wxRuby, there's a friendly mailing  
> > list which is a better place than c.l.r. for specifically wxRuby  
> > questions: [http://rubyforge.org/mail/?group\_id=35](http://rubyforge.org/mail/?group_id=35)
> > 
> > alex

---

<div class="post-metadata">

**Author:** ![Victor\_Reyes](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Victor\_Reyes](https://rubytalk.org/u/Victor_Reyes)\
**Post date:** [1 April 2008 13:20 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/8 "2008-04-01T13:20:49Z")

</div>

I found the answer to my last question. WxRuby runs under MS Windows, Linux  
and OS X.

Victor

> **···**
>
> On Tue, Apr 1, 2008 at 8:44 AM, Victor Reyes \<victor.reyes@gmail.com\> wrote:
> 
> > Alex,
> > 
> > I do truly appreciate your time to explain this new stuff to me.  
> > I will try to digest the info you provided me and also I will try to  
> > gather  
> > more info from the wx doc.  
> > Do you know if wx runs under AIX (IBM UNIX)?
> > 
> > Thank you
> > 
> > Victor
> > 
> > On Mon, Mar 31, 2008 at 5:10 PM, Alex Fenton \<alex@deleteme.pressure.to\> \> wrote:
> > 
> > \> Victor Reyes wrote:  
> > \>  
> > \> \> I finally got this working with wx by hard-coding the file path.  
> > \>  
> > \> That other first error looks like an ImageMagick problem. Sorry I can't  
> > \> help with that as I'm too lazy to install it; I just used wxRuby's own  
> > \> image file writing features to test it out quickly.  
> > \>  
> > \> \> The graphs  
> > \> \> (pie) is displayed, but now I have a small glitch, of course.  
> > \> \> The frame is a about 1/4 of what it needs to be, and so I have to  
> > resize  
> > \> it  
> > \> \> with the mouse.  
> > \> \> Perhaps I need to make the frame where the graph is displayed a bit  
> > \> larger.  
> > \> \> Is there anyway to make the size of the frame "dynamic" based on the  
> > \> size of  
> > \> \> the image to be displayed?  
> > \>  
> > \> You can either constrain the frame to be a particular size, and prevent  
> > \> it being resized, or dynamically resize the graph image as the frame is  
> > \> resized by the user's use of the mouse.  
> > \>  
> > \> For the former, when you call super in the GruffFrame constructor, add  
> > \> the argument :style =\> Wx::DEFAULT\_FRAME\_STYLE ^ Wx::RESIZE\_BORDER  
> > \>  
> > \> (i.e. use the default frame style, minus the mouse-draggable resize  
> > \> handle in the corner)  
> > \>  
> > \> Then in the GruffFrame#initialize method, set the Frame's client\_size to  
> > \> the size you want the image, e.g.  
> > \>  
> > \> self.client\_size = [480, 320]  
> > \>  
> > \> (The "client size" is the space within the Frame that is available for  
> > \> drawing on - its total pixel size minus the window borders, title bar  
> > \> etc. This way of setting the frame size will given consistent results  
> > \> across Linux, Windows and OS X)  
> > \>  
> > \> If you want the latter, a resizeable frame, on each refresh, tell Gruff  
> > \> what size of PNG you want. According to the docs, you can pass the  
> > \> Gruff Graph constructor a size as a string. So call new like this:  
> > \>  
> > \> graph = Gruff::Lines.new("#{client\_size.width}x#{client\_size.height}")  
> > \>  
> > \> If you go down this route, you'll probably also want to refresh the  
> > \> graph if the Frame is resized; use evt\_size in the frame constructor for  
> > \> this:  
> > \>  
> > \> evt\_size { | evt | refresh; evt.skip }  
> > \>  
> > \> \> In the mean time I will look in the wx documentation.  
> > \>  
> > \> I expect you've found [http://wxruby.rubyforge.org/doc/](http://wxruby.rubyforge.org/doc/)  
> > \>  
> > \> If you've got further questions about wxRuby, there's a friendly mailing  
> > \> list which is a better place than c.l.r. for specifically wxRuby  
> > \> questions: [http://rubyforge.org/mail/?group\_id=35](http://rubyforge.org/mail/?group_id=35)  
> > \>  
> > \> alex  
> > \>  
> > \>

---

<div class="post-metadata">

**Author:** ![Alex\_Fenton](https://avatars.discourse-cdn.com/v4/letter/a/ecccb3/32.png) [@Alex\_Fenton](https://rubytalk.org/u/Alex_Fenton)\
**Post date:** [1 April 2008 15:55 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/9 "2008-04-01T15:55:04Z")

</div>

Victor Reyes wrote:

\> Do you know if wx runs under AIX (IBM UNIX)?

Yes: [Supported Platforms - WxWiki](http://www.wxwidgets.org/docs/platform.htm)

Victor Reyes wrote:

> I found the answer to my last question. WxRuby runs under MS Windows, Linux  
> and OS X.

Almost - it supports a number of desktop environments: Windows, OS X, and GTK. The latter should work on any Unix-ish system where you can build GTK and wxWidgets.

We provide binary builds (i686 and AMD64) for Linux because it's the dominant desktop \*nix OS, and thus well tested and widely used there.

AFAIK no-one has ever posted about building wxRuby on other \*nix systems. But on any setup that can build Ruby and WxWidgets (see link above) it should be possible to compile wxRuby - this includes the BSDs and the commercial Unices like AIX.

I'd guess it'd be easiest using gcc rather than IBM's own compiler.

alex

---

<div class="post-metadata">

**Author:** ![Victor\_Reyes](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@Victor\_Reyes](https://rubytalk.org/u/Victor_Reyes)\
**Post date:** [1 April 2008 16:01 UTC](https://rubytalk.org/t/displaying-gruff-graphs/45538/10 "2008-04-01T16:01:31Z")

</div>

I will attempt to compile wx under AIX with the gcc compiler.

Victor

> **···**
>
> On Tue, Apr 1, 2008 at 11:55 AM, Alex Fenton \<aff28@deleteme.cam.ac.uk\> wrote:
> 
> > Victor Reyes wrote:
> > 
> > \> Do you know if wx runs under AIX (IBM UNIX)?
> > 
> > Yes: [Supported Platforms - WxWiki](http://www.wxwidgets.org/docs/platform.htm)
> > 
> > Victor Reyes wrote:
> > 
> > \> I found the answer to my last question. WxRuby runs under MS Windows,  
> > Linux  
> > \> and OS X.
> > 
> > Almost - it supports a number of desktop environments: Windows, OS X,  
> > and GTK. The latter should work on any Unix-ish system where you can  
> > build GTK and wxWidgets.
> > 
> > We provide binary builds (i686 and AMD64) for Linux because it's the  
> > dominant desktop \*nix OS, and thus well tested and widely used there.
> > 
> > AFAIK no-one has ever posted about building wxRuby on other \*nix  
> > systems. But on any setup that can build Ruby and WxWidgets (see link  
> > above) it should be possible to compile wxRuby - this includes the BSDs  
> > and the commercial Unices like AIX.
> > 
> > I'd guess it'd be easiest using gcc rather than IBM's own compiler.
> > 
> > alex
