Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Updating Gtk2::Ex::Graph::GD

by deadpickle (Pilgrim)
on Mar 07, 2009 at 19:56 UTC ( [id://749083]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Updating Gtk2::Ex::Graph::GD
in thread Updating Gtk2::Ex::Graph::GD

Here is a working, scrolling GD::Graph built using Gtk2.
#!/usr/bin/perl -w use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; use Gtk2::Ex::Graph::GD; use GD::Graph::Data; my $met_data1; my $met_image1; my $met_graph1; my $met_data2; my $met_image2; my $met_graph2; my @utc; my @temp; my @pres; my @rh1; my @rh2; my $utc_entry; my $temp_entry; my $pres_entry; my $rh1_entry; my $rh2_entry; my $utc = 00; my $temp = 25.4; my $pres = 1019.3; my $rh1 = 20.0; my $rh2 = 20.4; my $timer_graph = Glib::Timeout->add(5000, \&graph); &data_build; Gtk2->main; sub data_build { my $data_window = Gtk2::Window->new('toplevel'); $data_window->signal_connect(delete_event=> sub{Gtk2->main_quit}); $data_window->set_title('Sonde Data'); $data_window->set_position('center'); $data_window->set_default_size(350,350); my $data_table = Gtk2::Table->new(7,2,FALSE); my $utc_label = Gtk2::Label->new("UTC"); $utc_entry = Gtk2::Entry->new(); $utc_entry->set_editable(0); my $temp_label = Gtk2::Label->new("Temperature"); $temp_entry = Gtk2::Entry->new(); $temp_entry->set_editable(0); my $pres_label = Gtk2::Label->new("Pressure"); $pres_entry = Gtk2::Entry->new(); $pres_entry->set_editable(0); my $rh1_label = Gtk2::Label->new("Relative Humidity(1)"); $rh1_entry = Gtk2::Entry->new(); $rh1_entry->set_editable(0); my $rh2_label = Gtk2::Label->new("Relative Humidity(2)"); $rh2_entry = Gtk2::Entry->new(); $rh2_entry->set_editable(0); $met_data1 = GD::Graph::Data->new([ [ 0], [ 0], [ 1100] ]) or die GD::Graph::Data->error; $met_data2 = GD::Graph::Data->new([ [ 0], [ 0], [ 0] ]) or die GD::Graph::Data->error; $met_graph1 = Gtk2::Ex::Graph::GD->new(350, 200, 'lines'); $met_graph2 = Gtk2::Ex::Graph::GD->new(350, 200, 'lines'); $met_graph1->set( x_label => 'UTC', y1_label => 'Celcius', y2_label => 'Millibars', y1_max_value => 32, y1_min_value => 0, y2_max_value => 1100, y2_min_value => 0, y1_tick_number => 14, y2_tick_number => 14, two_axes => 1, line_width => 3, transparent => 0, dclrs => [ qw(red blue) ], x_label_position => 1/2, ); $met_graph2->set( x_label => 'UTC', y1_label => 'Percent', y1_max_value => 100, y1_min_value => 0, y1_tick_number => 14, line_width => 3, transparent => 0, dclrs => [ qw(green) ], line_types => [ 1, 2], x_label_position => 1/2, ); $met_image1 = $met_graph1->get_image($met_data1); $met_image2 = $met_graph2->get_image($met_data2); $data_table->attach_defaults($utc_label,0,1,0,1); $data_table->attach_defaults($utc_entry,1,2,0,1); $data_table->attach_defaults($temp_label,0,1,1,2); $data_table->attach_defaults($temp_entry,1,2,1,2); $data_table->attach_defaults($pres_label,0,1,2,3); $data_table->attach_defaults($pres_entry,1,2,2,3); $data_table->attach_defaults($rh1_label,0,1,3,4); $data_table->attach_defaults($rh1_entry,1,2,3,4); $data_table->attach_defaults($rh2_label,0,1,4,5); $data_table->attach_defaults($rh2_entry,1,2,4,5); $data_table->attach_defaults($met_image1,0,2,5,6); $data_table->attach_defaults($met_image2,0,2,6,7); $data_window->add($data_table); $data_window->show_all; return 1; } sub graph{ my $utc_data; my $temp_data; my $count; $utc = $utc + 5; push(@utc,$utc); my $length = @utc; shift(@utc) if $length > 10; $utc_entry->set_text($utc); $temp = $temp - 0.05; push(@temp,$temp); $length = @temp; shift(@temp) if $length > 10; $temp_entry->set_text($temp); $pres = $pres - 3.2; push(@pres,$pres); $length = @pres; shift(@pres) if $length > 10; $pres_entry->set_text($pres); $rh1 = $rh1 - 0.01; push(@rh1,$rh1); $length = @rh1; shift(@rh1) if $length > 10; $rh1_entry->set_text($rh1); $rh2 = $rh2 - 0.02; push(@rh2,$rh2); $length = @rh2; shift(@rh2) if $length > 10; $rh2_entry->set_text($rh2); my $num = $met_data1->num_points(); if ($met_data1->num_points() == 10) { for($count=0;$count<=$num-1;$count++) { $met_data1->set_x($count,$utc[$count]); $met_data1->set_y(1,$count,$temp[$count]); $met_data1->set_y(2,$count,$pres[$count]); $met_data2->set_x($count,$utc[$count]); $met_data2->set_y(1,$count,$rh1[$count]); $met_data2->set_y(2,$count,$rh2[$count]); } }else{ $met_data1->add_point($utc,$temp,$pres); $met_data2->add_point($utc,$rh1,$rh2); } $num = $met_data1->num_points(); my @values = $met_data1->y_values(1); my $graph; $graph = GD::Graph::lines->new(350,200); $met_graph1->{graph} = undef; $met_graph1->{graph} = $graph; $met_graph1->{graph}->set(%{$met_graph1->{graphhash}}) if $met_gra +ph1->{graphhash}; $met_image1 = $met_graph1->get_image($met_graph1->{graphdata}); $graph = GD::Graph::lines->new(350,200); $met_graph2->{graph} = undef; $met_graph2->{graph} = $graph; $met_graph2->{graph}->set(%{$met_graph2->{graphhash}}) if $met_gra +ph2->{graphhash}; $met_image2 = $met_graph2->get_image($met_graph2->{graphdata}); return 1; }

Replies are listed 'Best First'.
Re^5: Updating Gtk2::Ex::Graph::GD
by zentara (Archbishop) on Mar 07, 2009 at 20:39 UTC
    Wow, very nice example for Gtk2,..... but I might go with a Canvas type widget for animated graphs. The table layout is very nice....Gtk2 has nice tables that can have spanning cells, like in html.

    Hey deadpickle, I just heard about a new 3d gtk2 scenegraph canvas....called "clutter".


    I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness
      Did a quick google on it. Is it like Goo::Canvas? If it is I would love to check it out since goo is sparsely documented. Though I'm having trouble installing it.
        From what I can gather, it's like a 3-d canvas. I havn't had a chance to install yet.... alot of dependencies....but it appears to be a "layered 2-d scenegraph", where multiple 2d canvases are layered to give a 3d effect. The canvas aspect supposedly gives you persistence of objects. Essentially, it should allow you to program a 3d canvas.

        I probably won't get to testing it until later this month.


        I'm not really a human, but I play one on earth My Petition to the Great Cosmic Conciousness

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://749083]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (9)
As of 2024-04-18 13:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found