# Statistics / Graphs widget

**URL:** <https://www.ruby-forum.com/t/statistics-graphs-widget/121101>\
**Category:** Ruby-Gnome 2\
**Created:** [November 23, 2007, 6:55pm UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101 "2007-11-23T18:55:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 23, 2007, 6:55pm UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/1 "2007-11-23T18:55:06Z")

</div>

Hello,

is there a simple way to draw graphics in a ruby-gtk app ? I mean  
something  
like the CPU load graph in gnome-system-monitor.

I’ll also need to draw statistics later. I’m interested in a any  
suggestion 🙂

Regards,  
Christophe H.

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 23, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/2 "2007-11-23T19:19:10Z")

</div>

Christophe,

Here’s something to keep in mind:

All applications using the Ruby-Gnome2 bindings suffer from garbage  
collection pauses of upwards of 1/5th of a second (on a P3-1.2ghz…  
much worse on handhelds, etc.).

This is due to implementation issues in the bindings and may be fixed  
some day, but for now, if you plan to animate the graph at anything  
above about 2 frames per second, I recommend you use a different  
language/binding combination (as far as I know Python/GTK+ doesn’t have  
the same problem).

More info:

> **[Ruby’s Garbage Collection Problem](https://gnomecoder.wordpress.com/2007/10/02/rubys-garbage-collection-problem/)**
>
> EDIT: This post deals with Ruby 1.8, and specifically Ruby with the Ruby-Gtk bindings loaded.  The problems have been worked around in the Luz project, and Ruby 1.9 is also much smoother– eno…

> **[Ruby Garbage Collection Update](https://gnomecoder.wordpress.com/2007/11/19/ruby-garbage-collection-update/)**
>
> I have some more information about the Ruby/GTK+ garbage collection situation that I talked about in my previous post. I am now all-but-convinced that the unavoidable 200+ millisecond application p…

-Ian

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 23, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/3 "2007-11-23T22:29:07Z")

</div>

Am Freitag, den 23.11.2007, 15:18 -0300 schrieb Ian McIntosh:

> Christophe,
> 
> Here’s something to keep in mind:
> 
> All applications using the Ruby-Gnome2 bindings suffer from garbage  
> collection pauses of upwards of 1/5th of a second (on a P3-1.2ghz…  
> much worse on handhelds, etc.).

Hi,

this is not compleatly true. With KlÃ¶tzle i made a stop motion animation  
programm, which has a live preview from a video camera. This works smoth  
with up to 15 frames / second on a 1.25 Ghz Mac Mini.

You only have to trigger the garbage collector yourself. In my case it  
is enought once per second.

Cheers  
detlef

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 23, 2007, 10:36pm UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/4 "2007-11-23T22:36:44Z")

</div>

- dcad  
392 objects, 0.001476 GC time, 391 remain
  - 393 objects, 0.001331 GC time, 391 remain  
393 objects, 0.001326 GC time, 391 remain
  - 393 objects, 0.002924 GC time, 391 remain
  - …gtk loaded…
  - 11648 objects, 0.014791 GC time, 5172 remain
  - 5174 objects, 0.052599 GC time, 5171 remain
  - 5173 objects, 0.018333 GC time, 5171 remain
  - 5173 objects, 0.056349 GC time, 5169 remain
  - 5171 objects, 0.056296 GC time, 5169 remain

dcad

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 23, 2007, 10:48pm UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/5 "2007-11-23T22:48:26Z")

</div>

(Oops sorry about that last post, Evolution flipped out on me after  
pasting formatted text, I shouldn’t be allowed to use a computer…)

detlef,

In your 15 fps app, you need a new frame every 0.066 (1/15) seconds,  
right?

On my PC, in my testing, simply including the ruby-gnome bindings causes  
garbage collection time to jump from around 0.002 to 0.056 (see results  
below).

So it would seem possible to do 15fps, assuming it took minimal time to  
generate a frame.

However, it seems that the garbage collection process takes longer the  
more GObjects you have. So if you expand your GUI, you’ll notice longer  
pauses in your animation. It’s really a crazy situation… 😃

I haven’t tested the GC time of a Ruby/Gtk+ app on a Maemo, OLPC, etc.,  
but since they have much slower CPUs I assume that the situation is  
worse there.

-Ian

403 objects, 0.047237 GC time, 390 remain  
392 objects, 0.001476 GC time, 391 remain  
393 objects, 0.001331 GC time, 391 remain  
393 objects, 0.001326 GC time, 391 remain  
393 objects, 0.002924 GC time, 391 remain  
…gtk loaded…  
11648 objects, 0.014791 GC time, 5172 remain  
5174 objects, 0.052599 GC time, 5171 remain  
5173 objects, 0.018333 GC time, 5171 remain  
5173 objects, 0.056349 GC time, 5169 remain  
5171 objects, 0.056296 GC time, 5169 remain

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 24, 2007, 1:03am UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/6 "2007-11-24T01:03:38Z")

</div>

Ok, it’s not a problem for me, as the animation will be around 1  
frame each 5 seconds.

Have you got an idea about which widget I should use ?

Regards,

Christophe H.

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 27, 2007, 9:19pm UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/7 "2007-11-27T21:19:16Z")

</div>

this widget interests me also.  
i’d start with an empty widget, and use it’s Gdk::Drawable, but i hope  
people here have a better idea.

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 27, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/8 "2007-11-27T23:08:24Z")

</div>

On Nov 24, 2007 1:02 AM, Christophe H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ok, it’s not a problem for me, as the animation will be around 1  
> frame each 5 seconds.
> 
> Have you got an idea about which widget I should use ?

Normally, GtkDrawingArea is used in such a case.

> **[Learn GNOME](https://help.gnome.org)**

It should work properly if you will use “higher-level” GDK drawing  
primitives (drawing rectangles, polygons, pictures), but it will  
probably be too slow if you draw pixels, in which case you’ll need to  
use a C extension alongside your ruby program.

–  
Guillaume C. - [NVC Communication Obstacles Game](http://zarb.org/~gc/)

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [December 3, 2007, 2:26am UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/9 "2007-12-03T02:26:18Z")

</div>

Grism looks very nice, hopefully others can present with such good  
styled apps too.

---

<div class="post-metadata">

**Author:** ![Christophe\_H](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ec9cab/32.png) [@Christophe\_H](https://www.ruby-forum.com/u/Christophe_H)\
**Post date:** [November 28, 2007, 9:47am UTC](https://www.ruby-forum.com/t/statistics-graphs-widget/121101/10 "2007-11-28T09:47:35Z")

</div>

In Grism ([www.grism.org](http://www.grism.org)), I draw stock charts using a GtkDrawingArea and  
a  
Cairo context. The charts are not animated, but if you resize the chart  
window, the chart automatically resizes (actually, it preforms a  
redraw).  
Based my experience with the performance of this operation, you will not  
have any problems with performance.

Cheers,  
Nick
