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 48

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

powered by: WebSVN 2.1.0

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