OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [graph.pl] - Blame information for rev 42

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 alirezamon
#!/usr/bin/perl
2
use strict;
3
use warnings;
4
use GD::Graph::bars3d;
5
use Glib qw/TRUE FALSE/;
6
 
7
 
8
 
9
 
10
 
11
sub gen_multiple_charts{
12
        my ($self,$pageref,$charts_ref)=@_;
13
        my @pages=@{$pageref};
14
        my @charts=@{$charts_ref};
15
        my $notebook = Gtk2::Notebook->new;
16
        $notebook->set_scrollable(TRUE);
17
        $notebook->can_focus(FALSE);
18
 
19
 
20
 
21
        foreach my $page (@pages){
22
                my @selects;
23
                my $page_id= "P$page->{page_num}";
24
                my $active = $self->object_get_attribute ($page_id,'active');
25
 
26
                foreach my $chart (@charts){
27
                        push (@selects,$chart->{graph_name})if($page->{page_num} == $chart->{page_num} );
28
 
29
                }
30
                $active =$selects[0] if (!defined $active);
31
 
32
                foreach my $chart (@charts){
33
                        my $graph_id= $page_id."$chart->{graph_name}";
34
 
35
                        if($active eq $chart->{graph_name} && $page->{page_num} == $chart->{page_num}){
36
 
37
                                my $p=  gen_graph  ($self,$chart,@selects);
38
                                $notebook->append_page ($p,Gtk2::Label->new_with_mnemonic ($page->{page_name}));
39
                                $self->object_add_attribute ($graph_id,'type',$chart->{type});
40
                        }
41
 
42
                }
43
 
44
 
45
                #print "$page->{page_name} : @selects \n";
46
 
47
        }
48
 
49
 
50
 
51
 
52
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
53
        $scrolled_win->set_policy( "automatic", "automatic" );
54
        $scrolled_win->add_with_viewport($notebook);
55
        $scrolled_win->show_all;
56
 
57
        my $page_num=$self->object_get_attribute ("chart_notebook","currentpage");
58
        $notebook->set_current_page ($page_num) if(defined $page_num);
59
        $notebook->signal_connect( 'switch-page'=> sub{
60
                $self->object_add_attribute ("chart_notebook","currentpage",$_[2]);     #save the new pagenumber
61
                #print "$self->object_add_attribute (\"chart_notebook\",\"currentpage\",$_[2]);\n";                     
62
        });
63
 
64
        #return ($scrolled_win,$set_win);
65
        return $scrolled_win;
66
 
67
 
68
 
69
 
70
}
71
 
72
 
73
 
74
sub get_uniq_keys {
75
        my ($ref,@x)=@_;
76
 
77
        if(defined $ref) {
78
                                my %r=%$ref;
79
 
80
                                push(@x, sort {$a<=>$b} keys %r);
81
 
82
        my  @x2;
83
        @x2 =  uniq(sort {$a<=>$b} @x) if (scalar @x);
84
        return @x2;
85
        }
86
        return @x;
87
}
88
 
89
 
90
sub gen_graph {
91
        my ($self,$chart,@selects)=@_;
92
        if($chart->{type} eq '2D_line') {return gen_2D_line($self,$chart,@selects);}
93
        return  gen_3D_bar($self,$chart,@selects);
94
}
95
 
96
 
97
 
98
 
99
 
100
sub gen_3D_bar{
101
        my ($self,$chart,@selects)=@_;
102
 
103
        my($width,$hight)=max_win_size();
104
        my $page_id= "P$chart->{page_num}";
105
        my $graph_id= $page_id."$chart->{graph_name}";
106
        #my $graph_name=$chart->{graph_name};
107
        my $result_name= $chart->{result_name};
108
 
109
        my @legend_keys;
110
 
111
 
112
        my @results;
113
        $results[0]= [0];
114
        $results[1]= [0];
115
        #$results[2]= [0];
116
 
117
 
118
 
119
        my $legend_info="This attribute controls placement of the legend within the graph image. The value is supplied as a two-letter string, where the first letter is placement (a B or an R for bottom or right, respectively) and the second is alignment (L, R, C, T, or B for left, right, center, top, or bottom, respectively). ";
120
 
121
my $fontsize="Tiny,Small,MediumBold,Large,Giant";
122
 
123
 
124
 
125
my @ginfo = (
126
#{ label=>"Graph Title", param_name=>"G_Title", type=>"Entry", default_val=>undef, content=>undef, info=>undef, param_parent=>"${graph_name}_param"    , ref_delay=>undef },  
127
{ label=>"Y Axix Title", param_name=>"Y_Title", type=>"Entry", default_val=>$chart->{"Y_Title"}, content=>undef, info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=>undef },
128
  { label=>"X Axix Title", param_name=>"X_Title", type=>"Entry", default_val=>$chart->{"X_Title"}, content=>undef, info=>undef, param_parent=>"${graph_id}_param"    ,ref_delay=>undef },
129
  { label=>"legend placement", param_name=>"legend_placement", type=>'Combo-box', default_val=>'BL', content=>"BL,BC,BR,RT,RC,RB", info=>$legend_info, param_parent=>"${graph_id}_param"    , ref_delay=>1},
130
 
131
 { label=>"Y min", param_name=>"Y_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"Y axix minimum value", param_parent=>"${graph_id}_param"    , ref_delay=> 5},
132
 { label=>"X min", param_name=>"X_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"X axix minimum value", param_parent=>"${graph_id}_param"    , ref_delay=> 5},
133
{ label=>"X max", param_name=>"X_MAX", type=>'Spin-button', default_val=>100, content=>"0,1024,1", info=>"X axix maximum value", param_parent=>"${graph_id}_param"    , ref_delay=> 5},
134
 { label=>"Line Width", param_name=>"LINEw", type=>'Spin-button', default_val=>3, content=>"1,20,1", info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=> 5},
135
#{ label=>"Y Axis Values", param_name=>"y_value", type=>'Combo-box', default_val=>'Original', content=>"Original,Normalized to 1,Normalized to 100", info=>undef, param_parent=>"${graph_name}_param"    , ref_delay=>1},
136
{ label=>"legend font size", param_name=>"legend_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=>1},
137
{ label=>"label font size", param_name=>"label_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=>1},
138
  { label=>"label font size", param_name=>"x_axis_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=>1},
139
);
140
 
141
my $content=join( ',', @selects);
142
 
143
my $dimention=gen_combobox_object ($self,$graph_id,"dimention","2D,3D","3D",'ref',2);
144
my $active_page=gen_combobox_object ($self,$page_id,"active",$content,$selects[0],'ref',2);
145
 
146
 
147
#print "${graph_name}_${dir}_result\n";         
148
                my @ratios;
149
                my @color;
150
                my $min_y=200;
151
                my $i=0;
152
                my @samples =$self->object_get_attribute_order("samples");
153
                @samples = ('no_name') if (scalar @samples == 0);
154
                foreach my $sample (@samples){
155
 
156
                        my $color_num=$self->object_get_attribute($sample,"color");
157
                        my $l_name= $self->object_get_attribute($sample,"line_name");
158
 
159
 
160
                        #push(@color, "my_color$color_num");
161
                        my $ref=$self->object_get_attribute ($sample,$result_name);
162
                        if(defined $ref){
163
                                $i++;
164
                                @ratios=get_uniq_keys($ref,@ratios);
165
                                $color_num=$i+1 if(!defined $color_num);
166
                                push(@color, "my_color$color_num");
167
                                $legend_keys[$i-1]= (defined $l_name)? $l_name : $sample;
168
                        }
169
 
170
 
171
                }#for
172
        $content = join(",", @ratios);
173
        my $ratio_combx=gen_combobox_object ($self,${graph_id},"ratio",$content,$ratios[0],'ref',2);
174
 
175
        @color= ("my_color0") if ((scalar @color) ==0);
176
        @legend_keys=("-")  if ((scalar @legend_keys) ==0);
177
 
178
 
179
        my $ymax=10;
180
        my $ratio = $self->object_get_attribute ($graph_id,"ratio");
181
 
182
 
183
        my @x;
184
        if (defined $ratio){
185
 
186
                foreach my $sample (@samples){
187
                        my $ref=$self->object_get_attribute ($sample,"$result_name");
188
                        if(defined $ref){
189
                                @x=get_uniq_keys($ref->{$ratio},@x);
190
                        }
191
                }
192
                my $i=1;
193
                foreach my $sample (@samples){
194
                        my @y;
195
                        my $ref=$self->object_get_attribute ($sample,"$result_name");
196
                        if(defined $ref){
197
                                foreach my $v (@x){
198
                                        my $w=$ref->{$ratio}->{$v};
199
                                        push(@y,$w);
200
                                        $ymax=$w+1 if($w>$ymax);
201
                                }
202
                                $results[$i]=\@y if(scalar @x);
203
                                $i++;
204
                        }
205
                }
206
 
207
 
208
 
209
 
210
        }
211
 
212
        $results[0]=\@x if(scalar @x);
213
 
214
        $i=1;
215
 
216
        # all results which is larger than ymax will be changed to ymax,
217
        $i=0;
218
 
219
        #foreach my $sample (@samples){
220
                #$i++;
221
                #for (my $j=1;$j<=$s; $j++) {
222
                #       $results[$i][$j]=($results[$i][$j]>$max_y)? $max_y: $results[$i][$j] if (defined $results[$i][$j]);
223
                #}      
224
        #}
225
 
226
 
227
        my $graphs_info;
228
        foreach my $d ( @ginfo){
229
                $graphs_info->{$d->{param_name}}=$self->object_get_attribute( "${graph_id}_param"    ,$d->{param_name});
230
                if(!defined $graphs_info->{$d->{param_name}}){
231
                        $graphs_info->{$d->{param_name}}= $d->{default_val};
232
                        $self->object_add_attribute( "${graph_id}_param"    ,$d->{param_name},$d->{default_val} );
233
                }
234
        }
235
 
236
        my $graph_w=$width/2.5;
237
        my $graph_h=$hight/2.5;
238
        my $graph = new GD::Graph::bars3d($graph_w, $graph_h);
239
        my $dim = $self->object_get_attribute (${graph_id},"dimention");
240
        #my $dir = $self->object_get_attribute ($graph_name,"direction"); 
241
        my $over= ($dim eq "2D")? 0 : 1;
242
        $graph->set(
243
            overwrite => $over,
244
            x_label => $graphs_info->{X_Title},
245
            y_label => $graphs_info->{Y_Title},
246
            title   => $graphs_info->{G_Title},
247
            y_max_value => $ymax,
248
            y_tick_number => 18,
249
            y_label_skip => 2,
250
            x_label_skip => 1,
251
            x_all_ticks => 1,
252
            x_labels_vertical => 1,
253
            box_axis => 0,
254
            y_long_ticks => 1,
255
            legend_placement => $graphs_info->{legend_placement},
256
                dclrs=>\@color,
257
                y_number_format=>"%.1f",
258
 
259
                transparent       => '0',
260
                bgclr             => 'white',
261
                boxclr            => 'white',
262
                fgclr             => 'black',
263
                textclr           => 'black',
264
                labelclr          => 'black',
265
                axislabelclr      => 'black',
266
                legendclr         =>  'black',
267
            #cycle_clrs        => '1',
268
 
269
                 # Draw bars with width 3 pixels
270
    bar_width   => 3,
271
    # Sepearte the bars with 4 pixels
272
    bar_spacing => 10,
273
    # Show the grid
274
    #long_ticks  => 1,
275
    # Show values on top of each bar
276
    #show_values => 1,
277
    );
278
 
279
 
280
        $graph->set_legend(@legend_keys);
281
 
282
        my $font;
283
 
284
        $font=  $self->object_get_attribute( "${graph_id}_param"    ,'label_font');
285
        $graph->set_x_label_font(GD::Font->$font);
286
        $graph->set_y_label_font(GD::Font->$font);
287
        $font=  $self->object_get_attribute( "${graph_id}_param"    ,'legend_font');
288
        $graph->set_legend_font(GD::Font->$font);
289
 
290
        $font=  $self->object_get_attribute( "${graph_id}_param"    ,'x_axis_font');
291
        #$graph->set_values_font(GD::gdGiantFont);
292
        $graph->set_x_axis_font(GD::Font->$font);
293
        $graph->set_y_axis_font(GD::Font->$font);
294
 
295
        #@results=reorder_result(@results);
296
 
297
        my $gd =  $graph->plot( \@results );
298
        my $loader = Gtk2::Gdk::PixbufLoader->new;
299
        $loader->write ($gd->png);
300
        $loader->close;
301
        my $image = Gtk2::Image->new_from_pixbuf($loader->get_pixbuf);
302
 
303
        write_image ($self,$graph_id,$gd);
304
        write_image_result      ($self,$graph_id,$graph,$result_name,$chart->{type},\@results);
305
   # my $image = my_get_image($self,$graph,$data,$graph_name);
306
 
307
 
308
 
309
      # print  Data::Dumper->Dump ([\@results],['ttt']); 
310
 
311
 
312
 
313
 
314
        my $table = Gtk2::Table->new (25, 10, FALSE);
315
 
316
 
317
                my $box = Gtk2::HBox->new (TRUE, 2);
318
                my $filename;
319
                $box->set_border_width (4);
320
                my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
321
                my $frame = Gtk2::Frame->new;
322
                $frame->set_shadow_type ('in');
323
                $frame->add ($image);
324
                $align->add ($frame);
325
 
326
 
327
                my $plus = def_image_button('icons/plus.png',undef,TRUE);
328
                my $minues = def_image_button('icons/minus.png',undef,TRUE);
329
                my $setting = def_image_button('icons/setting.png',undef,TRUE);
330
                my $save = def_image_button('icons/save.png',undef,TRUE);
331
                my $scale= $self->object_get_attribute("${graph_id}_graph_scale",undef);
332
                $scale = 5 if(!defined $scale);
333
                $minues -> signal_connect("clicked" => sub{
334 42 alirezamon
                        $self->object_add_attribute("${graph_id}_graph_scale",undef,$scale*1.05);
335 38 alirezamon
                        set_gui_status($self,"ref",1);
336
                });
337
 
338
                $plus  -> signal_connect("clicked" => sub{
339 42 alirezamon
                        $self->object_add_attribute("${graph_id}_graph_scale",undef,$scale*0.95) if( $scale>0.5);
340 38 alirezamon
                        set_gui_status($self,"ref",5);
341
                });
342
 
343
                $setting -> signal_connect("clicked" => sub{
344
                        get_graph_setting ($self,\@ginfo);
345
                });
346
                set_tip($setting, "Setting");
347
 
348
                $save-> signal_connect("clicked" => sub{
349
                        # my $G = $graph->{graph};
350
                         my @imags=$graph->export_format();
351
                         save_graph_as ($self,\@imags,$graph_id);
352
                });
353
                set_tip($save, "Save graph");
354
 
355
 
356
 
357
                $table->attach_defaults ($align , 0, 9, 0, 25);
358
                my $row=0;
359
                $table->attach (gen_label_in_center('Injection-Ratio'), 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
360
                $table->attach ($ratio_combx, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
361
                $table->attach ($active_page, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
362
                $table->attach ($dimention, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
363
 
364
                #$table->attach ($plus , 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
365
                #$table->attach ($minues, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
366
                $table->attach ($setting, 9, 10, $row,  $row+1,'shrink','shrink',2,2); $row++;
367
                $table->attach ($save, 9, 10, $row,  $row+1,'shrink','shrink',2,2); $row++;
368
                while ($row<10){
369
 
370
                        my $tmp=gen_label_in_left('');
371
                        $table->attach_defaults ($tmp, 9, 10, $row,  $row+1);$row++;
372
                }
373
 
374
        return $table;
375
}
376
 
377
 
378
 
379
 
380
 
381
 
382
 
383
 
384
 
385
 
386
 
387
 
388
 
389
 
390
sub gen_2D_line {
391
 
392
        my ($self,$chart,@selects)=@_;
393
        my($width,$hight)=max_win_size();
394
        my $page_id= "P$chart->{page_num}";
395
        my $graph_id=  $page_id."$chart->{graph_name}";
396
        #my $graph_name=$chart->{graph_name};
397
        my $result_name= $chart->{result_name};
398
        my @x;
399
        my @legend_keys;
400
 
401
 
402
        my @results;
403
        $results[0]=[0];
404
        $results[1]= [0];
405
        my $legend_info="This attribute controls placement of the legend within the graph image. The value is supplied as a two-letter string, where the first letter is placement (a B or an R for bottom or right, respectively) and the second is alignment (L, R, C, T, or B for left, right, center, top, or bottom, respectively). ";
406
 
407
        my $fontsize="Tiny,Small,MediumBold,Large,Giant";
408
 
409
my $content=join( ',', @selects);
410
my $active_page=gen_combobox_object ($self,$page_id,"active",$content,$selects[0],'ref',2);
411
 
412
 
413
 
414
my @ginfo = (
415
#{ label=>"Graph Title", param_name=>"G_Title", type=>"Entry", default_val=>undef, content=>undef, info=>undef, param_parent=>"${graph_name}_param"    , ref_delay=>undef },  
416
{ label=>"Y Axis Title", param_name=>"Y_Title", type=>"Entry", default_val=>$chart->{"Y_Title"}, content=>undef, info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=>undef },
417
  { label=>"X Axis Title", param_name=>"X_Title", type=>"Entry", default_val=>$chart->{"X_Title"}, content=>undef, info=>undef, param_parent=>"${graph_id}_param"    ,ref_delay=>undef },
418
  { label=>"legend placement", param_name=>"legend_placement", type=>'Combo-box', default_val=>'BL', content=>"BL,BC,BR,RT,RC,RB", info=>$legend_info, param_parent=>"${graph_id}_param"    , ref_delay=>1},
419
 
420
 { label=>"Y min", param_name=>"Y_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"Y axis minimum value", param_parent=>"${graph_id}_param"    , ref_delay=> 5},
421
 { label=>"X min", param_name=>"X_MIN", type=>'Spin-button', default_val=>0, content=>"0,1024,1", info=>"X axis minimum value", param_parent=>"${graph_id}_param"    , ref_delay=> 5},
422
{ label=>"X max", param_name=>"X_MAX", type=>'Spin-button', default_val=>100, content=>"0,1024,1", info=>"X axis maximum value", param_parent=>"${graph_id}_param"    , ref_delay=> 5},
423
 { label=>"Line Width", param_name=>"LINEw", type=>'Spin-button', default_val=>3, content=>"1,20,1", info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=> 5},
424
#{ label=>"Y Axis Values", param_name=>"y_value", type=>'Combo-box', default_val=>'Original', content=>"Original,Normalized to 1,Normalized to 100", info=>undef, param_parent=>"${graph_name}_param"    , ref_delay=>1},
425
 
426
{ label=>"legend font size", param_name=>"legend_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"{$graph_id}_param"    , ref_delay=>1},
427
{ label=>"label font size", param_name=>"label_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=>1},
428
  { label=>"label font size", param_name=>"x_axis_font", type=>'Combo-box', default_val=>'MediumBold', content=>$fontsize, info=>undef, param_parent=>"${graph_id}_param"    , ref_delay=>1},
429
);
430
 
431
 
432
 
433
 
434
 
435
                my @color;
436
                my $min_y;#=200;
437
                my $i=0;
438
                my @samples =$self->object_get_attribute_order("samples");
439
                @samples = ('no_name') if (scalar @samples == 0);
440
                foreach my $sample (@samples){
441
                        my $ref=$self->object_get_attribute ($sample,$result_name);
442
                        $i++;
443
                        my $color_num=$self->object_get_attribute($sample,"color");
444
                        my $l_name= $self->object_get_attribute($sample,"line_name");
445
                        $legend_keys[$i-1]= (defined $l_name)? $l_name : $sample;
446
                        $color_num=$i+1 if(!defined $color_num);
447
                        push(@color, "my_color$color_num");
448
 
449
                        if(defined $ref) {
450
                                push(@x, sort {$a<=>$b} keys %{$ref});
451
 
452
                        }
453
 
454
                }#for
455
 
456
        my  @x2;
457
        @x2 =  uniq(sort {$a<=>$b} @x) if (scalar @x);
458
 
459
        my  @x1; #remove x values larger than x_max
460
        my $x_max= $self->object_get_attribute( "${graph_id}_param"    ,'X_MAX');
461
        foreach  my $p (@x2){
462
                if(defined $x_max) {push (@x1,$p) if($p<$x_max);}
463
                else {push (@x1,$p);}
464
        }
465
 
466
        #print "\@x1=@x1\n";
467
        if (scalar @x1){
468
                $results[0]=\@x1;
469
                $i=0;
470
                foreach my $sample (@samples){
471
                        $i++;
472
                        my $j=0;
473
                        my $ref=$self->object_get_attribute ($sample,$result_name);
474
                        if(defined $ref){
475
                                #print "$i\n";
476
                                my %line=%$ref;
477
                                foreach my $k (@x1){
478
                                        $results[$i][$j]=$line{$k};
479
                                        if(defined $line{$k}){
480
                                                $min_y = $line{$k} if (!defined $min_y);
481
                                                $min_y= $line{$k} if ($line{$k}!=0 && $min_y > $line{$k});
482
                                                $j++;
483
                                        }
484
                                }#$k
485
                        }#if
486
                        else {
487
                                $results[$i][$j]=undef;
488
                        }
489
                }#$i            
490
        }#if
491
 
492
        $min_y = 200 if (!defined $min_y);
493
        my $scale= $self->object_get_attribute("${graph_id}_graph_scale",undef);
494
        $scale = 5 if(!defined $scale);
495
 
496
        my $max_y=$min_y* $scale;
497
        my $s=scalar @x1;
498
 
499
        # all results which is larger than ymax will be changed to ymax,
500
        $i=0;
501
 
502
        foreach my $sample (@samples){
503
                $i++;
504
                for (my $j=1;$j<=$s; $j++) {
505
                        $results[$i][$j]=($results[$i][$j]>$max_y)? $max_y: $results[$i][$j] if (defined $results[$i][$j]);
506
                }
507
        }
508
 
509
 
510
        my $graphs_info;
511
        foreach my $d ( @ginfo){
512
                $graphs_info->{$d->{param_name}}=$self->object_get_attribute( "${graph_id}_param"    ,$d->{param_name});
513
                if(!defined $graphs_info->{$d->{param_name}}){
514
                        $graphs_info->{$d->{param_name}}= $d->{default_val};
515
                        $self->object_add_attribute( "${graph_id}_param"    ,$d->{param_name},$d->{default_val} );
516
                }
517
        }
518
 
519
        my $graph_w=$width/2.5;
520
        my $graph_h=$hight/2.5;
521
        my $graph = Gtk2::Ex::Graph::GD->new($graph_w, $graph_h, 'linespoints');
522
 
523
        $graph->set (
524
                x_label         => $graphs_info->{X_Title},
525
                y_label         => $graphs_info->{Y_Title},
526
                y_max_value     => $max_y,
527
                y_min_value             => $graphs_info->{Y_MIN},
528
                                y_tick_number   => 8,
529
               #        x_min_value     => $graphs_info->{X_MIN}, # dosent work?
530
                title           => $graphs_info->{G_Title},
531
                bar_spacing     => 1,
532
                shadowclr       => 'dred',
533
 
534
 
535
 
536
                box_axis       => 0,
537
                skip_undef=> 1,
538
           # transparent     => 1,
539
                transparent       => '0',
540
                bgclr             => 'white',
541
                boxclr            => 'white',
542
                fgclr             => 'black',
543
                textclr           => 'black',
544
                labelclr          => 'black',
545
                axislabelclr      => 'black',
546
                legendclr         =>  'black',
547
            cycle_clrs        => '1',
548
                line_width              => $graphs_info->{LINEw},
549
        #       cycle_clrs              => 'black',
550
                legend_placement => $graphs_info->{legend_placement},
551
                dclrs=>\@color,
552
                y_number_format=>"%.1f",
553
                BACKGROUND=>'black',
554
 
555
                );
556
 
557
 
558
        $graph->set_legend(@legend_keys);
559
 
560
 
561
 
562
 
563
 
564
 
565
 
566
        my $data = GD::Graph::Data->new(\@results) or die GD::Graph::Data->error;
567
        $data->make_strict();
568
 
569
    my $image = my_get_image($self,$graph,$data,$graph_id,$result_name,$chart->{type});
570
 
571
 
572
 
573
      # print  Data::Dumper->Dump ([\@results],['ttt']); 
574
 
575
 
576
 
577
 
578
        my $table = Gtk2::Table->new (25, 10, FALSE);
579
 
580
 
581
                my $box = Gtk2::HBox->new (TRUE, 2);
582
                my $filename;
583
                $box->set_border_width (4);
584
                my   $align = Gtk2::Alignment->new (0.5, 0.5, 0, 0);
585
                my $frame = Gtk2::Frame->new;
586
                $frame->set_shadow_type ('in');
587
                $frame->add ($image);
588
                $align->add ($frame);
589
 
590
 
591
                my $plus = def_image_button('icons/plus.png',undef,TRUE);
592
                my $minues = def_image_button('icons/minus.png',undef,TRUE);
593
                my $setting = def_image_button('icons/setting.png',undef,TRUE);
594
                my $save = def_image_button('icons/save.png',undef,TRUE);
595
 
596
 
597
                $minues -> signal_connect("clicked" => sub{
598 42 alirezamon
                        $self->object_add_attribute("${graph_id}_graph_scale",undef,$scale*1.05);
599 38 alirezamon
                        set_gui_status($self,"ref",1);
600
                });
601
                set_tip($minues, "Zoom out");
602
 
603
                $plus  -> signal_connect("clicked" => sub{
604 42 alirezamon
                        $self->object_add_attribute("${graph_id}_graph_scale",undef,$scale*0.95) if( $scale>0.5);
605 38 alirezamon
                        set_gui_status($self,"ref",5);
606
                });
607
                set_tip($plus, "Zoom in");
608
 
609
                $setting -> signal_connect("clicked" => sub{
610
                        get_graph_setting ($self,\@ginfo);
611
                });
612
                set_tip($setting, "Setting");
613
 
614
                $save-> signal_connect("clicked" => sub{
615
                         my $G = $graph->{graph};
616
                         my @imags=$G->export_format();
617
                        save_graph_as ($self,\@imags,$graph_id);
618
                });
619
                set_tip($save, "Save graph");
620
 
621
 
622
 
623
                $table->attach_defaults ($align , 0, 9, 0, 25);
624
                my $row=0;
625
                $table->attach ($active_page, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
626
                $table->attach ($plus , 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
627
                $table->attach ($minues, 9, 10, $row, $row+1,'shrink','shrink',2,2); $row++;
628
                $table->attach ($setting, 9, 10, $row,  $row+1,'shrink','shrink',2,2); $row++;
629
                $table->attach ($save, 9, 10, $row,  $row+1,'shrink','shrink',2,2); $row++;
630
                while ($row<10){
631
 
632
                        my $tmp=gen_label_in_left('');
633
                        $table->attach_defaults ($tmp, 9, 10, $row,  $row+1);$row++;
634
                }
635
 
636
        return $table;
637
 
638
}
639
 
640
 
641
##############
642
#       save_graph_as
643
##############
644
 
645
sub save_graph_as {
646
        my ($self,$ref,$graph_name)=@_;
647
 
648
        my $file;
649
        my $title ='Save as';
650
 
651
 
652
 
653
        my @extensions=@$ref;
654
        my $open_in=undef;
655
        my $dialog = Gtk2::FileChooserDialog->new(
656
                'Save file', undef,
657
                'save',
658
                'gtk-cancel' => 'cancel',
659
                'gtk-ok'     => 'ok',
660
                );
661
        # if(defined $extension){
662
 
663
                foreach my $ext (@extensions){
664
                        my $filter = Gtk2::FileFilter->new();
665
                        $filter->set_name($ext);
666
                        $filter->add_pattern("*.$ext");
667
                        $dialog->add_filter ($filter);
668
                }
669
 
670
        # }
671
          if(defined  $open_in){
672
                $dialog->set_current_folder ($open_in);
673
                # print "$open_in\n";
674
 
675
        }
676
 
677
        if ( "ok" eq $dialog->run ) {
678
                        $file = $dialog->get_filename;
679
                        my $ext = $dialog->get_filter;
680
                        $ext=$ext->get_name;
681
                        my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
682
                        $file = ($suffix eq ".$ext" )? $file : "$file.$ext";
683
 
684
                        $self->object_add_attribute("graph_save","name",$file);
685
                        $self->object_add_attribute("graph_save","extension",$ext);
686
                        $self->object_add_attribute("graph_save","save",1);
687
                        $self->object_add_attribute("graph_save","save_result",1);
688
                        $self->object_add_attribute("graph_save","graph_name",$graph_name);
689
                        set_gui_status($self,"ref",1);
690
 
691
                         }
692
                        $dialog->destroy;
693
}
694
 
695
 
696
 
697
sub my_get_image {
698
        my ($self,$exgraph, $data, $graph_name, $result_name,$charttype) = @_;
699
        $exgraph->{graphdata} = $data;
700
        my $graph = $exgraph->{graph};
701
        my $font;
702
 
703
        $font=  $self->object_get_attribute( "${graph_name}_param"    ,'label_font');
704
        $graph->set_x_label_font(GD::Font->$font);
705
        $graph->set_y_label_font(GD::Font->$font);
706
        $font=  $self->object_get_attribute( "${graph_name}_param"    ,'legend_font');
707
        $graph->set_legend_font(GD::Font->$font);
708
 
709
        $font=  $self->object_get_attribute( "${graph_name}_param"    ,'x_axis_font');
710
        #$graph->set_values_font(GD::gdGiantFont);
711
        $graph->set_x_axis_font(GD::Font->$font);
712
        $graph->set_y_axis_font(GD::Font->$font);
713
 
714
        my $gd2=$graph->plot($data) or warn $graph->error;
715
        my $loader = Gtk2::Gdk::PixbufLoader->new;
716
 
717
 
718
        #cut the upper side of the image to remove the stright line created by chaanging large results to ymax
719
 
720
 
721
        my $gd1=  GD::Image->new($gd2->getBounds);
722
        my $white= $gd1->colorAllocate(255,255,254);
723
        my ($x,$h)=$gd2->getBounds;
724
        $gd1->transparent($white);
725
        $gd1->copy( $gd2, 0, 0, 0, ,$h*0.05, $x ,$h*.95 );
726
 
727
 
728
        $loader->write ($gd1->png);
729
        $loader->close;
730
 
731
 
732
        write_image ($self,$graph_name,$gd1);
733
        write_image_result      ($self,$graph_name,$graph,$result_name,$charttype);
734
 
735
        my $image = Gtk2::Image->new_from_pixbuf($loader->get_pixbuf);
736
 
737
 
738
        $exgraph->{graphimage} = $image;
739
        my $hotspotlist;
740
        if ($exgraph->{graphtype} eq 'bars' or
741
                $exgraph->{graphtype} eq 'lines' or
742
                $exgraph->{graphtype} eq 'linespoints') {
743
                foreach my $hotspot ($graph->get_hotspot) {
744
                        push @$hotspotlist, $hotspot if $hotspot;
745
                }
746
        }
747
        $exgraph->{hotspotlist} = $hotspotlist;
748
        my $eventbox = $exgraph->{eventbox};
749
        my @children = $eventbox->get_children;
750
        foreach my $child (@children) {
751
                $eventbox->remove($child);
752
        }
753
 
754
 
755
 
756
 
757
#       $eventbox->add ($image);
758
 
759
 
760
#       $eventbox->show_all;
761
        return $image;
762
}
763
 
764
 
765
 
766
############
767
#       get_graph_setting
768
###########
769
 
770
sub get_graph_setting {
771
        my ($self,$ref)=@_;
772
        my $window=def_popwin_size(33,33,'Graph Setting','percent');
773
        my $table = def_table(10, 2, FALSE);
774
        my $row=0;
775
 
776
 
777
my @data=@$ref;
778
foreach my $d (@data) {
779
        $row=noc_param_widget ($self, $d->{label}, $d->{param_name}, $d->{default_val}, $d->{type}, $d->{content}, $d->{info}, $table,$row,1, $d->{param_parent}, $d->{ref_delay});
780
}
781
 
782
 
783
 
784
 
785
        my $scrolled_win = new Gtk2::ScrolledWindow (undef, undef);
786
        $scrolled_win->set_policy( "automatic", "automatic" );
787
        $scrolled_win->add_with_viewport($table);
788
        my $ok = def_image_button('icons/select.png',' OK ');
789
 
790
 
791
        my $mtable = def_table(10, 1, FALSE);
792
        $mtable->attach_defaults($scrolled_win,0,1,0,9);
793
        $mtable->attach($ok,0,1,9,10,'shrink','shrink',2,2);
794
        $window->add ($mtable);
795
        $window->show_all();
796
 
797
        $ok-> signal_connect("clicked" => sub{
798
                $window->destroy;
799
                set_gui_status($self,"ref",1);
800
        });
801
 
802
 
803
 
804
}
805
 
806
 
807
 
808
sub write_image {
809
        my ($self,$graph_name,$image)=@_;
810
        my $save=$self->object_get_attribute("graph_save","save");
811
 
812
 
813
        my $active_graph=$self->object_get_attribute("graph_save","graph_name");
814
        $save=0 if (!defined $save);
815
        $active_graph = 0 if(!defined $active_graph);
816
 
817
        if ($save ==1 && $active_graph eq $graph_name){
818
                my $file=$self->object_get_attribute("graph_save","name");
819
                my $ext=$self->object_get_attribute("graph_save","extension");
820
                $self->object_add_attribute("graph_save","save",0);
821
 
822
                #image
823
                open(my $out, '>', $file);
824
                if (tell $out )
825
                {
826
                        warn "Cannot open '$file' to write: $!";
827
                }else
828
                {
829
                        #my @extens=$graph->export_format();
830
                        binmode $out;
831
                        print $out $image->$ext;# if($ext eq 'png');
832
                        #print $out  $gd1->gif  if($ext eq 'gif');
833
                        close $out;
834
                }
835
        }
836
 
837
}
838
 
839
 
840
sub write_image_result {
841
        my ($self,$graph_name,$graph,$result_name,$charttype,$result_ref)=@_;
842
        my $save=$self->object_get_attribute("graph_save","save_result");
843
        my $active_graph=$self->object_get_attribute("graph_save","graph_name");
844
        $save=0 if (!defined $save);
845
        $active_graph = 0 if(!defined $active_graph);
846
 
847
 
848
 
849
        if ($save ==1 && $active_graph eq $graph_name){
850
                my $file=$self->object_get_attribute("graph_save","name");
851
                my $ext=$self->object_get_attribute("graph_save","extension");
852
                $self->object_add_attribute("graph_save","save_result",0);
853
 
854
                open( my $out, '>', "$file.txt");
855
                if (tell $out )
856
                {
857
                        warn "Cannot open $file.txt to write: $!";
858
                }
859
                else
860
                {
861
                        if($charttype eq '2D_line'){
862
 
863
                                my @samples =$self->object_get_attribute_order("samples");
864
                                foreach my $sample (@samples){
865
                                                my $l_name= $self->object_get_attribute($sample,"line_name");
866
                                                my $ref=$self->object_get_attribute ($sample,$result_name);
867
                                                my @x;
868
                                                if(defined $ref) {
869
 
870
                                                        print $out "$l_name\n";
871
                                                        foreach my $x (sort {$a<=>$b} keys %{$ref}) {
872
                                                                my $y=$ref->{$x};
873
                                                                print $out "\t$x , $y\n";
874
                                                        }
875
                                                        print $out "\n\n";
876
                                                }
877
                                        }#for
878
                                } else{
879
                                        write_3d_graph_results($self,$out,$result_ref);
880
 
881
 
882
                                }
883
 
884
                        close $out;
885
                }
886
        }
887
}
888
 
889
 
890
sub write_3d_graph_results{
891
        my ($self,$out,$result_ref)=@_;
892
 
893
        my @r=@{$result_ref};
894
 
895
        my @samples =$self->object_get_attribute_order("samples");
896
        my $i=0;
897
        if(defined $r[$i]){
898
                my @k=@{$r[$i]};
899
                print $out "@k\n\n";
900
        }
901
 
902
        foreach my $sample (@samples){
903
                $i++;
904
                my $l_name= $self->object_get_attribute($sample,"line_name");
905
                print $out "$l_name:\n";
906
                if(defined $r[$i]){
907
                        my @k=@{$r[$i]};
908
                        print $out "@k\n\n";
909
                }
910
        }
911
}
912
 
913
 
914
 
915
 ################
916
 # get_color_window
917
 ###############
918
 
919
 sub get_color_window{
920
         my ($self,$atrebute1,$atrebute2)=@_;
921
         my $window=def_popwin_size(40,40,"Select line color",'percent');
922
         my ($r,$c)=(4,8);
923
         my $table= def_table(5,6,TRUE);
924
         for (my $col=0;$col<$c;$col++){
925
                  for (my $row=0;$row<$r;$row++){
926
                        my $color_num=$row*$c+$col;
927
                        my $color=def_colored_button("    ",$color_num);
928
                        $table->attach_defaults ($color, $col, $col+1, $row, $row+1);
929
                        $color->signal_connect("clicked"=> sub{
930
                                $self->object_add_attribute($atrebute1,$atrebute2,$color_num);
931
                                #print "$self->object_add_attribute($atrebute1,$atrebute2,$color_num);\n";
932
                                set_gui_status($self,"ref",1);
933
                                $window->destroy;
934
                        });
935
                 }
936
         }
937
 
938
         $window->add($table);
939
 
940
        $window->show_all();
941
 
942
}
943
 
944
 
945
sub reorder_result{
946
        my @results=@_;
947
 
948
        my @app=(
949
        "a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","a10","a11"," "," "," "," ",
950
        "b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","b10","b11","b12","b13","b14","b15"," "," "," "," ",
951
        "c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11"," "," "," "," ",
952
        "d0","d1","d2","d3","d4","d5","d6","d7","d8");
953
 
954
 
955
 
956
        my %nmap=(
957
        "b7" => 0 ,"b9" => 1 ,"b8" => 2 ,"a11"=> 3 ,"b11"=> 4 ,"b12"=> 5 ,"b13"=> 6 ,
958
        "b6" => 7 ,"b5" => 8 ,"a10"=> 9 ,"a8" => 10,"a9" => 11,"b14"=> 12,"b10"=> 13,
959
        "b3" => 14,"b4" => 15,"a5" => 16,"a7" => 17,"a2" => 18,"d8" => 19,"d0" => 20,
960
        "b2" => 21,"a3" => 22,"a6" => 23,"a0" => 24,"a1" => 25,"d1" => 26,"d2" => 27,
961
        "b1" => 28,"b15"=> 29,"c2" => 30,"a4" => 31,"d4" => 32,"d3" => 33,"d5" => 34,
962
        "b0" => 35,"c9" => 36,"c8" => 37,"c3" => 38,"d7" => 39,"d6" => 40,"c7" => 41,
963
        "c11"=> 42,"c10"=> 43,"c5" => 44,"c4" => 45,"c1" => 46,"c0" => 47,"c6" => 48);
964
 
965
        my %worst=(
966
        "a0" => 0 ,"a8" => 1 ,"b7" => 2 ,"d8"=> 3 ,"b1"=> 4 ,"b5"=> 5 ,"b8"=> 6 ,
967
        "a5" => 7 ,"c2" => 8 ,"c10"=> 9 ,"c3" => 10,"c5" => 11,"b12"=> 12,"b3"=> 13,
968
        "d1" => 14,"d7" => 15,"c1" => 16,"c7" => 17,"c0" => 18,"c8" => 19,"b10" => 20,
969
        "b15" => 21,"d2" => 22,"c4" => 23,"c6" => 24,"c9" => 25,"d3" => 26,"a4" => 27,
970
        "b2" => 28,"b13"=> 29,"d4" => 30,"c11" => 31,"d5" => 32,"a2" => 33,"a10" => 34,
971
        "b6" => 35,"b0" => 36,"d0" => 37,"d6" => 38,"a3" => 39,"a9" => 40,"a6" => 41,
972
        "b9"=> 42,"b4"=> 43,"b11" => 44,"b14" => 45,"a1" => 46,"a11" => 47,"a7" => 48);
973
 
974
        my %rnd=(
975
        "d3" => 0 ,"d6" => 1 ,"b8" => 2 ,"c10"=> 3 ,"d5" => 4 ,"d8" => 5 ,"a3" => 6 ,
976
        "b15"=> 7 ,"a9" => 8 ,"c3" => 9 ,"b12"=> 10,"a4" => 11,"b9" => 12,"b6" => 13,
977
        "d2" => 14,"c2" => 15,"b0" => 16,"b13"=> 17,"a5" => 18,"c9" => 19,"a2" => 20,
978
        "c0" => 21,"c7" => 22,"c5" => 23,"b14"=> 24,"b7" => 25,"c4" => 26,"b10"=> 27,
979
        "d1" => 28,"c6" => 29,"b11"=> 30,"a10"=> 31,"b1" => 32,"c1" => 33,"b5" => 34,
980
        "d7" => 35,"d4" => 36,"a6" => 37,"a11"=> 38,"a7" => 39,"b2" => 40,"c11" => 41,
981
        "c8" => 42,"a1" => 43,"a0" => 44,"d0" => 45,"a8" => 46,"b3" => 47,"b4" => 48);
982
 
983
        my @r;
984
 
985
        my $tile=0;
986
        foreach my $p (@app){
987
 
988
 
989
                #my $l=$nmap{$p};
990
                #my $l=$rnd{$p};
991
                my $l=$worst{$p};
992
 
993
 
994
                $r[0][$tile]=$p;
995
                $r[1][$tile]=(defined $l)? $results[1][$l]: undef;
996
                $r[2][$tile]=(defined $l)? $results[2][$l]: undef;
997
                $tile++;
998
        }
999
 
1000
 
1001
 
1002
        return @r;
1003
}
1004
 
1005
1;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.