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 54

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

powered by: WebSVN 2.1.0

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