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 43

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

powered by: WebSVN 2.1.0

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