line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tk::ForDummies::Graph::Pie;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2291
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
72
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#==================================================================
|
8
|
|
|
|
|
|
|
# Author : Djibril Ousmanou
|
9
|
|
|
|
|
|
|
# Copyright : 2010
|
10
|
|
|
|
|
|
|
# Update : 20/09/2010 20:45:26
|
11
|
|
|
|
|
|
|
# AIM : Create pie graph
|
12
|
|
|
|
|
|
|
#==================================================================
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION);
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
61
|
|
15
|
|
|
|
|
|
|
$VERSION = '1.08';
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use base qw/Tk::Derived Tk::Canvas::GradientColor/;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
646
|
|
18
|
|
|
|
|
|
|
use Tk::Balloon;
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Tk::ForDummies::Graph::Utils qw (:DUMMIES);
|
21
|
|
|
|
|
|
|
use Tk::ForDummies::Graph qw (:DUMMIES);
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Construct Tk::Widget 'Pie';
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub Populate {
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my ( $CompositeWidget, $RefParameters ) = @_;
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Get initial parameters
|
30
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies} = $CompositeWidget->_InitConfig();
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$CompositeWidget->SUPER::Populate($RefParameters);
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$CompositeWidget->Advertise( 'GradientColor' => $CompositeWidget );
|
35
|
|
|
|
|
|
|
$CompositeWidget->Advertise( 'canvas' => $CompositeWidget->SUPER::Canvas );
|
36
|
|
|
|
|
|
|
$CompositeWidget->Advertise( 'Canvas' => $CompositeWidget->SUPER::Canvas );
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# remove highlightthickness if necessary
|
39
|
|
|
|
|
|
|
unless ( exists $RefParameters->{-highlightthickness} ) {
|
40
|
|
|
|
|
|
|
$CompositeWidget->configure( -highlightthickness => 0 );
|
41
|
|
|
|
|
|
|
}
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$CompositeWidget->ConfigSpecs(
|
44
|
|
|
|
|
|
|
-title => [ 'PASSIVE', 'Title', 'Title', undef ],
|
45
|
|
|
|
|
|
|
-titlecolor => [ 'PASSIVE', 'Titlecolor', 'TitleColor', 'black' ],
|
46
|
|
|
|
|
|
|
-titlefont =>
|
47
|
|
|
|
|
|
|
[ 'PASSIVE', 'Titlefont', 'TitleFont', $CompositeWidget->{RefInfoDummies}->{Font}{DefaultTitle} ],
|
48
|
|
|
|
|
|
|
-titleposition => [ 'PASSIVE', 'Titleposition', 'TitlePosition', 'center' ],
|
49
|
|
|
|
|
|
|
-width => [ 'SELF', 'width', 'Width', $CompositeWidget->{RefInfoDummies}->{Canvas}{Width} ],
|
50
|
|
|
|
|
|
|
-height => [ 'SELF', 'height', 'Height', $CompositeWidget->{RefInfoDummies}->{Canvas}{Height} ],
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
-linewidth => [ 'PASSIVE', 'Linewidth', 'LineWidth', 2 ],
|
53
|
|
|
|
|
|
|
-startangle => [ 'PASSIVE', 'Startangle', 'StartAngle', 0 ],
|
54
|
|
|
|
|
|
|
-colordata =>
|
55
|
|
|
|
|
|
|
[ 'PASSIVE', 'Colordata', 'ColorData', $CompositeWidget->{RefInfoDummies}->{Legend}{Colors} ],
|
56
|
|
|
|
|
|
|
);
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$CompositeWidget->Delegates( DEFAULT => $CompositeWidget, );
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# recreate graph after widget resize
|
61
|
|
|
|
|
|
|
$CompositeWidget->enabled_automatic_redraw();
|
62
|
|
|
|
|
|
|
$CompositeWidget->disabled_gradientcolor();
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub plot {
|
66
|
|
|
|
|
|
|
my ( $CompositeWidget, $RefData ) = @_;
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
unless ( defined $RefData ) {
|
69
|
|
|
|
|
|
|
$CompositeWidget->_error('data not defined');
|
70
|
|
|
|
|
|
|
return;
|
71
|
|
|
|
|
|
|
}
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
unless ( scalar @{$RefData} == 2 ) {
|
74
|
|
|
|
|
|
|
$CompositeWidget->_error('You must have 2 arrays in data array');
|
75
|
|
|
|
|
|
|
return;
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Check array size
|
79
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Data}{NumberXValues} = scalar @{ $RefData->[0] };
|
80
|
|
|
|
|
|
|
foreach my $RefArray ( @{$RefData} ) {
|
81
|
|
|
|
|
|
|
unless ( scalar @{$RefArray} == $CompositeWidget->{RefInfoDummies}->{Data}{NumberXValues} ) {
|
82
|
|
|
|
|
|
|
$CompositeWidget->_error( 'Make sure that every array has the same size in plot data method', 1 );
|
83
|
|
|
|
|
|
|
return;
|
84
|
|
|
|
|
|
|
}
|
85
|
|
|
|
|
|
|
}
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Check array size
|
88
|
|
|
|
|
|
|
foreach my $data ( @{ $RefData->[1] } ) {
|
89
|
|
|
|
|
|
|
if ( defined $data and !_isANumber($data) ) {
|
90
|
|
|
|
|
|
|
$data = $CompositeWidget->{RefInfoDummies}->{Data}{SubstitutionValue};
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
}
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Data}{MaxValue} = _MaxArray( $RefData->[1] );
|
95
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Data}{NbrSlice} = scalar @{ $RefData->[0] };
|
96
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Data}{RefAllData} = $RefData;
|
97
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Data}{PlotDefined} = 1;
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
$CompositeWidget->_GraphForDummiesConstruction;
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return;
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _titlepie {
|
105
|
|
|
|
|
|
|
my ($CompositeWidget) = @_;
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $Title = $CompositeWidget->cget( -title );
|
108
|
|
|
|
|
|
|
my $TitleColor = $CompositeWidget->cget( -titlecolor );
|
109
|
|
|
|
|
|
|
my $TitleFont = $CompositeWidget->cget( -titlefont );
|
110
|
|
|
|
|
|
|
my $titleposition = $CompositeWidget->cget( -titleposition );
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Title verification
|
113
|
|
|
|
|
|
|
unless ($Title) {
|
114
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Height} = 0;
|
115
|
|
|
|
|
|
|
return;
|
116
|
|
|
|
|
|
|
}
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Space before the title
|
119
|
|
|
|
|
|
|
my $WidthEmptyBeforeTitle = $CompositeWidget->{RefInfoDummies}->{Canvas}{WidthEmptySpace};
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Coordinates title
|
122
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrex}
|
123
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Canvas}{WidthEmptySpace}
|
124
|
|
|
|
|
|
|
+ ( $CompositeWidget->{RefInfoDummies}->{Pie}{Width} / 2 );
|
125
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrey}
|
126
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Canvas}{HeightEmptySpace}
|
127
|
|
|
|
|
|
|
+ ( $CompositeWidget->{RefInfoDummies}->{Title}{Height} / 2 );
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# display title
|
130
|
|
|
|
|
|
|
my $anchor;
|
131
|
|
|
|
|
|
|
if ( $titleposition eq 'left' ) {
|
132
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrex} = $WidthEmptyBeforeTitle;
|
133
|
|
|
|
|
|
|
$anchor = 'nw';
|
134
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{'-width'} = 0;
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
elsif ( $titleposition eq 'right' ) {
|
137
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrex}
|
138
|
|
|
|
|
|
|
= $WidthEmptyBeforeTitle + $CompositeWidget->{RefInfoDummies}->{Axis}{Xaxis}{Width};
|
139
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{'-width'} = 0;
|
140
|
|
|
|
|
|
|
$anchor = 'ne';
|
141
|
|
|
|
|
|
|
}
|
142
|
|
|
|
|
|
|
else {
|
143
|
|
|
|
|
|
|
$anchor = 'center';
|
144
|
|
|
|
|
|
|
}
|
145
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{IdTitre} = $CompositeWidget->createText(
|
146
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrex},
|
147
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrey},
|
148
|
|
|
|
|
|
|
-text => $Title,
|
149
|
|
|
|
|
|
|
-width => $CompositeWidget->{RefInfoDummies}->{Pie}{Width},
|
150
|
|
|
|
|
|
|
-anchor => $anchor,
|
151
|
|
|
|
|
|
|
-tags => [ $CompositeWidget->{RefInfoDummies}->{TAGS}{AllTagsDummiesGraph}, ],
|
152
|
|
|
|
|
|
|
);
|
153
|
|
|
|
|
|
|
return if ( $anchor =~ m{^left|right$} );
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# get title information
|
156
|
|
|
|
|
|
|
my ($Height);
|
157
|
|
|
|
|
|
|
( $CompositeWidget->{RefInfoDummies}->{Title}{Ctitrex},
|
158
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrey},
|
159
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Width}, $Height
|
160
|
|
|
|
|
|
|
) = $CompositeWidget->bbox( $CompositeWidget->{RefInfoDummies}->{Title}{IdTitre} );
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# Title too long
|
163
|
|
|
|
|
|
|
if ( $CompositeWidget->{RefInfoDummies}->{Title}{Ctitrey}
|
164
|
|
|
|
|
|
|
< $CompositeWidget->{RefInfoDummies}->{Canvas}{HeightEmptySpace} )
|
165
|
|
|
|
|
|
|
{
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# delete title
|
168
|
|
|
|
|
|
|
$CompositeWidget->delete( $CompositeWidget->{RefInfoDummies}->{Title}{IdTitre} );
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrex} = $WidthEmptyBeforeTitle;
|
171
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrey}
|
172
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Canvas}{HeightEmptySpace}
|
173
|
|
|
|
|
|
|
+ ( $CompositeWidget->{RefInfoDummies}->{Title}{Height} / 2 );
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# cut title
|
176
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{'-width'} = 0;
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# display title
|
179
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{IdTitre} = $CompositeWidget->createText(
|
180
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrex},
|
181
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{Ctitrey},
|
182
|
|
|
|
|
|
|
-text => $Title,
|
183
|
|
|
|
|
|
|
-width => $CompositeWidget->{RefInfoDummies}->{Title}{'-width'},
|
184
|
|
|
|
|
|
|
-anchor => 'nw',
|
185
|
|
|
|
|
|
|
-tags => [ $CompositeWidget->{RefInfoDummies}->{TAGS}{AllTagsDummiesGraph}, ],
|
186
|
|
|
|
|
|
|
);
|
187
|
|
|
|
|
|
|
}
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
$CompositeWidget->itemconfigure(
|
190
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Title}{IdTitre},
|
191
|
|
|
|
|
|
|
-font => $TitleFont,
|
192
|
|
|
|
|
|
|
-fill => $TitleColor,
|
193
|
|
|
|
|
|
|
);
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
return;
|
196
|
|
|
|
|
|
|
}
|
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub _ViewData {
|
199
|
|
|
|
|
|
|
my ($CompositeWidget) = @_;
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $legendmarkercolors = $CompositeWidget->cget( -colordata );
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# Height legend
|
204
|
|
|
|
|
|
|
$CompositeWidget->_Legend();
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Coordinates for rectangle pie
|
207
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{x1}
|
208
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Canvas}{WidthEmptySpace};
|
209
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{y1}
|
210
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Canvas}{HeightEmptySpace}
|
211
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Title}{Height}
|
212
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Canvas}{HeightEmptySpace};
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{x2}
|
215
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Pie}{x1} + $CompositeWidget->{RefInfoDummies}->{Pie}{Width};
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{y2}
|
218
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Canvas}{Height}
|
219
|
|
|
|
|
|
|
- ( 2 * $CompositeWidget->{RefInfoDummies}->{Canvas}{WidthEmptySpace} )
|
220
|
|
|
|
|
|
|
- $CompositeWidget->{RefInfoDummies}->{Legend}{Height};
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
# Calculate the number of degrees for value = 1
|
223
|
|
|
|
|
|
|
my $Somme = 0;
|
224
|
|
|
|
|
|
|
foreach my $data ( @{ $CompositeWidget->{RefInfoDummies}->{Data}{RefAllData}->[1] } ) {
|
225
|
|
|
|
|
|
|
$Somme += $data;
|
226
|
|
|
|
|
|
|
}
|
227
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{DegreeOneValue} = 360 / $Somme;
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
# pie
|
230
|
|
|
|
|
|
|
my ( $degrees, $start ) = ( 0, $CompositeWidget->cget( -startangle ) );
|
231
|
|
|
|
|
|
|
my $IndiceColor = 0;
|
232
|
|
|
|
|
|
|
my $IndexLegend = 0;
|
233
|
|
|
|
|
|
|
for my $Indice ( 0 .. $CompositeWidget->{RefInfoDummies}->{Data}{NbrSlice} - 1 ) {
|
234
|
|
|
|
|
|
|
my $Value = $CompositeWidget->{RefInfoDummies}->{Data}{RefAllData}->[1]->[$Indice];
|
235
|
|
|
|
|
|
|
$degrees = $CompositeWidget->{RefInfoDummies}->{Pie}{DegreeOneValue} * $Value;
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
my $Color = $legendmarkercolors->[$IndiceColor];
|
238
|
|
|
|
|
|
|
unless ( defined $Color ) {
|
239
|
|
|
|
|
|
|
$IndiceColor = 0;
|
240
|
|
|
|
|
|
|
$Color = $legendmarkercolors->[$IndiceColor];
|
241
|
|
|
|
|
|
|
}
|
242
|
|
|
|
|
|
|
my $tag
|
243
|
|
|
|
|
|
|
= $IndexLegend
|
244
|
|
|
|
|
|
|
. $CompositeWidget->{RefInfoDummies}->{TAGS}{Legend}
|
245
|
|
|
|
|
|
|
. $CompositeWidget->{RefInfoDummies}->{TAGS}{Pie};
|
246
|
|
|
|
|
|
|
$CompositeWidget->createArc(
|
247
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{x1},
|
248
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{y1},
|
249
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{x2},
|
250
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Pie}{y2},
|
251
|
|
|
|
|
|
|
-extent => $degrees,
|
252
|
|
|
|
|
|
|
-fill => $Color,
|
253
|
|
|
|
|
|
|
-start => $start,
|
254
|
|
|
|
|
|
|
-tags => [ $tag, $CompositeWidget->{RefInfoDummies}->{TAGS}{AllTagsDummiesGraph}, ],
|
255
|
|
|
|
|
|
|
-width => $CompositeWidget->cget( -linewidth ),
|
256
|
|
|
|
|
|
|
);
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}{Pie}{$tag}{color} = $Color;
|
259
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}{Pie}{$tag}{percent}
|
260
|
|
|
|
|
|
|
= "$Value (" . _roundValue( ( $Value * 100 ) / $Somme ) . '%)';
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
$start += $degrees;
|
263
|
|
|
|
|
|
|
$IndiceColor++;
|
264
|
|
|
|
|
|
|
$IndexLegend++;
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
}
|
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
return 1;
|
269
|
|
|
|
|
|
|
}
|
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
sub _CheckHeightPie {
|
272
|
|
|
|
|
|
|
my ($CompositeWidget) = @_;
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
my $total
|
275
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Canvas}{HeightEmptySpace}
|
276
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Title}{Height}
|
277
|
|
|
|
|
|
|
+ ( 2 * $CompositeWidget->{RefInfoDummies}->{Canvas}{HeightEmptySpace} )
|
278
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Legend}{Height}
|
279
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Title}{Height};
|
280
|
|
|
|
|
|
|
while ( $total > $CompositeWidget->{RefInfoDummies}->{Canvas}{Height} ) {
|
281
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Canvas}{Height}
|
282
|
|
|
|
|
|
|
+= $CompositeWidget->{RefInfoDummies}->{Legend}{Height};
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
$CompositeWidget->configure( -height => $CompositeWidget->{RefInfoDummies}->{Canvas}{Height} );
|
285
|
|
|
|
|
|
|
}
|
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
return;
|
288
|
|
|
|
|
|
|
}
|
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub _Legend {
|
291
|
|
|
|
|
|
|
my ($CompositeWidget) = @_;
|
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
SETLEGEND:
|
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
# One legend width
|
296
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{LengthOneLegend}
|
297
|
|
|
|
|
|
|
= +$CompositeWidget->{RefInfoDummies}->{Legend}{SpaceBeforeCube} # Espace entre chaque légende
|
298
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Legend}{WCube} # Cube (largeur)
|
299
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Legend}{SpaceAfterCube} # Espace apres cube
|
300
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Legend}{WidthText} # longueur du texte de la légende
|
301
|
|
|
|
|
|
|
;
|
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
# Number of legends per line
|
304
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{NbrPerLine}
|
305
|
|
|
|
|
|
|
= int( $CompositeWidget->{RefInfoDummies}->{Pie}{Width}
|
306
|
|
|
|
|
|
|
/ $CompositeWidget->{RefInfoDummies}->{Legend}{LengthOneLegend} );
|
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
if ( $CompositeWidget->{RefInfoDummies}->{Legend}{NbrPerLine} == 0 ) {
|
309
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{NbrPerLine} = 1;
|
310
|
|
|
|
|
|
|
}
|
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
# Number of legends (total)
|
313
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{NbrLegend}
|
314
|
|
|
|
|
|
|
= scalar @{ $CompositeWidget->{RefInfoDummies}->{Data}{RefAllData}->[0] };
|
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
=for NumberLines:
|
317
|
|
|
|
|
|
|
We calculate the number of lines set for the legend graph.
|
318
|
|
|
|
|
|
|
If wa can set 11 legends per line, then for 3 legend, we will need one line
|
319
|
|
|
|
|
|
|
and for 12 legends, we will need 2 lines
|
320
|
|
|
|
|
|
|
If NbrLeg / NbrPerLine = integer => get number of lines
|
321
|
|
|
|
|
|
|
If NbrLeg / NbrPerLine = float => int(float) + 1 = get number of lines
|
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=cut
|
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{NbrLine}
|
326
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Legend}{NbrLegend}
|
327
|
|
|
|
|
|
|
/ $CompositeWidget->{RefInfoDummies}->{Legend}{NbrPerLine};
|
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
unless (
|
330
|
|
|
|
|
|
|
int( $CompositeWidget->{RefInfoDummies}->{Legend}{NbrLine} )
|
331
|
|
|
|
|
|
|
== $CompositeWidget->{RefInfoDummies}->{Legend}{NbrLine} )
|
332
|
|
|
|
|
|
|
{
|
333
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{NbrLine}
|
334
|
|
|
|
|
|
|
= int( $CompositeWidget->{RefInfoDummies}->{Legend}{NbrLine} ) + 1;
|
335
|
|
|
|
|
|
|
}
|
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
# Total Height of Legend
|
338
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{Height} = $CompositeWidget->{RefInfoDummies}->{Legend}{NbrLine}
|
339
|
|
|
|
|
|
|
* $CompositeWidget->{RefInfoDummies}->{Legend}{HLine};
|
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
# Get number legend text max per line to reajust our graph
|
342
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{CurrentNbrPerLine}
|
343
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Legend}{NbrPerLine};
|
344
|
|
|
|
|
|
|
if ( $CompositeWidget->{RefInfoDummies}->{Legend}{NbrLegend}
|
345
|
|
|
|
|
|
|
< $CompositeWidget->{RefInfoDummies}->{Legend}{NbrPerLine} )
|
346
|
|
|
|
|
|
|
{
|
347
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{CurrentNbrPerLine}
|
348
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Legend}{NbrLegend};
|
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
}
|
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
# Get the biggest length of legend text
|
353
|
|
|
|
|
|
|
my @LengthLegend = map { length; } @{ $CompositeWidget->{RefInfoDummies}->{Data}{RefAllData}->[0] };
|
354
|
|
|
|
|
|
|
my $BiggestLegend = _MaxArray( \@LengthLegend );
|
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
# 100 pixel => 13 characters, 1 pixel => 0.13 pixels then 1 character = 7.69 pixels
|
357
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{WidthOneCaracter} = 7.69;
|
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
# Max pixel width for a legend text for us
|
360
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{LengthTextMax}
|
361
|
|
|
|
|
|
|
= int( $CompositeWidget->{RefInfoDummies}->{Legend}{WidthText}
|
362
|
|
|
|
|
|
|
/ $CompositeWidget->{RefInfoDummies}->{Legend}{WidthOneCaracter} );
|
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
# We have free space
|
365
|
|
|
|
|
|
|
my $Diff = $CompositeWidget->{RefInfoDummies}->{Legend}{LengthTextMax} - $BiggestLegend;
|
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
# Get new size width for a legend text with one pixel security
|
368
|
|
|
|
|
|
|
if ( $Diff > 1 ) {
|
369
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Legend}{WidthText}
|
370
|
|
|
|
|
|
|
-= ( $Diff - 1 ) * $CompositeWidget->{RefInfoDummies}->{Legend}{WidthOneCaracter};
|
371
|
|
|
|
|
|
|
goto SETLEGEND;
|
372
|
|
|
|
|
|
|
}
|
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
$CompositeWidget->_CheckHeightPie();
|
375
|
|
|
|
|
|
|
|
376
|
|
|
|
|
|
|
return;
|
377
|
|
|
|
|
|
|
}
|
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
sub _ViewLegend {
|
380
|
|
|
|
|
|
|
my ($CompositeWidget) = @_;
|
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
my $legendmarkercolors = $CompositeWidget->cget( -colordata );
|
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
my $IndexColor = 0;
|
385
|
|
|
|
|
|
|
my $IndexLegend = 0;
|
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
# Balloon
|
388
|
|
|
|
|
|
|
my %MsgBalloon;
|
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
for my $NumberLine ( 0 .. $CompositeWidget->{RefInfoDummies}->{Legend}{NbrLine} ) {
|
391
|
|
|
|
|
|
|
my $x1Cube = $CompositeWidget->{RefInfoDummies}->{Canvas}{WidthEmptySpace}
|
392
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Legend}{SpaceBeforeCube};
|
393
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
my $y1Cube
|
395
|
|
|
|
|
|
|
= $CompositeWidget->{RefInfoDummies}->{Pie}{y2}
|
396
|
|
|
|
|
|
|
+ $CompositeWidget->{RefInfoDummies}->{Canvas}{HeightEmptySpace}
|
397
|
|
|
|
|
|
|
+ ( $NumberLine * $CompositeWidget->{RefInfoDummies}->{Legend}{HLine} );
|
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
my $x2Cube = $x1Cube + $CompositeWidget->{RefInfoDummies}->{Legend}{WCube};
|
400
|
|
|
|
|
|
|
my $y2Cube = $y1Cube - $CompositeWidget->{RefInfoDummies}->{Legend}{HCube};
|
401
|
|
|
|
|
|
|
my $xText = $x2Cube + $CompositeWidget->{RefInfoDummies}->{Legend}{SpaceAfterCube};
|
402
|
|
|
|
|
|
|
my $yText = $y2Cube;
|
403
|
|
|
|
|
|
|
my $MaxLength = $CompositeWidget->{RefInfoDummies}->{Legend}{LengthTextMax};
|
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
LEGEND:
|
406
|
|
|
|
|
|
|
for my $NumberLegInLine ( 0 .. $CompositeWidget->{RefInfoDummies}->{Legend}{NbrPerLine} - 1 ) {
|
407
|
|
|
|
|
|
|
last LEGEND
|
408
|
|
|
|
|
|
|
unless ( defined $CompositeWidget->{RefInfoDummies}->{Data}{RefAllData}->[0]->[$IndexLegend] );
|
409
|
|
|
|
|
|
|
my $LineColor = $legendmarkercolors->[$IndexColor];
|
410
|
|
|
|
|
|
|
unless ( defined $LineColor ) {
|
411
|
|
|
|
|
|
|
$IndexColor = 0;
|
412
|
|
|
|
|
|
|
$LineColor = $legendmarkercolors->[$IndexColor];
|
413
|
|
|
|
|
|
|
}
|
414
|
|
|
|
|
|
|
my $Tag = $IndexLegend . $CompositeWidget->{RefInfoDummies}->{TAGS}{Legend};
|
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
$CompositeWidget->createRectangle(
|
417
|
|
|
|
|
|
|
$x1Cube, $y1Cube, $x2Cube, $y2Cube,
|
418
|
|
|
|
|
|
|
-fill => $LineColor,
|
419
|
|
|
|
|
|
|
-outline => $LineColor,
|
420
|
|
|
|
|
|
|
-tags => [ $Tag, $CompositeWidget->{RefInfoDummies}->{TAGS}{AllTagsDummiesGraph}, ],
|
421
|
|
|
|
|
|
|
);
|
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
# Cut legend text if too long
|
424
|
|
|
|
|
|
|
my $Legende = $CompositeWidget->{RefInfoDummies}->{Data}{RefAllData}->[0]->[$IndexLegend];
|
425
|
|
|
|
|
|
|
my $NewLegend = $Legende;
|
426
|
|
|
|
|
|
|
if ( length $NewLegend > $MaxLength ) {
|
427
|
|
|
|
|
|
|
$MaxLength -= 3;
|
428
|
|
|
|
|
|
|
$NewLegend =~ s/^(.{$MaxLength}).*/$1/;
|
429
|
|
|
|
|
|
|
$NewLegend .= '...';
|
430
|
|
|
|
|
|
|
}
|
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
my $Id = $CompositeWidget->createText(
|
433
|
|
|
|
|
|
|
$xText, $yText,
|
434
|
|
|
|
|
|
|
-text => $NewLegend,
|
435
|
|
|
|
|
|
|
-anchor => 'nw',
|
436
|
|
|
|
|
|
|
-tags => [ $Tag, $CompositeWidget->{RefInfoDummies}->{TAGS}{AllTagsDummiesGraph}, ],
|
437
|
|
|
|
|
|
|
);
|
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
$IndexColor++;
|
440
|
|
|
|
|
|
|
$IndexLegend++;
|
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
# cube
|
443
|
|
|
|
|
|
|
$x1Cube += $CompositeWidget->{RefInfoDummies}->{Legend}{LengthOneLegend};
|
444
|
|
|
|
|
|
|
$x2Cube += $CompositeWidget->{RefInfoDummies}->{Legend}{LengthOneLegend};
|
445
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
# Text
|
447
|
|
|
|
|
|
|
$xText += $CompositeWidget->{RefInfoDummies}->{Legend}{LengthOneLegend};
|
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
my $PieTag = $Tag . $CompositeWidget->{RefInfoDummies}->{TAGS}{Pie};
|
450
|
|
|
|
|
|
|
$CompositeWidget->bind(
|
451
|
|
|
|
|
|
|
$Tag,
|
452
|
|
|
|
|
|
|
'',
|
453
|
|
|
|
|
|
|
sub {
|
454
|
|
|
|
|
|
|
my $OtherColor = $CompositeWidget->{RefInfoDummies}->{Balloon}{ColorData}->[0];
|
455
|
|
|
|
|
|
|
if ( $OtherColor eq $CompositeWidget->{RefInfoDummies}{Pie}{$PieTag}{color} ) {
|
456
|
|
|
|
|
|
|
$OtherColor = $CompositeWidget->{RefInfoDummies}->{Balloon}{ColorData}->[1];
|
457
|
|
|
|
|
|
|
}
|
458
|
|
|
|
|
|
|
$CompositeWidget->itemconfigure( $PieTag, -fill => $OtherColor, );
|
459
|
|
|
|
|
|
|
}
|
460
|
|
|
|
|
|
|
);
|
461
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
$CompositeWidget->bind(
|
463
|
|
|
|
|
|
|
$Tag,
|
464
|
|
|
|
|
|
|
'',
|
465
|
|
|
|
|
|
|
sub {
|
466
|
|
|
|
|
|
|
$CompositeWidget->itemconfigure( $PieTag,
|
467
|
|
|
|
|
|
|
-fill => $CompositeWidget->{RefInfoDummies}{Pie}{$PieTag}{color}, );
|
468
|
|
|
|
|
|
|
}
|
469
|
|
|
|
|
|
|
);
|
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
$MsgBalloon{$Tag} = "$Legende - " . $CompositeWidget->{RefInfoDummies}{Pie}{$PieTag}{percent};
|
472
|
|
|
|
|
|
|
$MsgBalloon{$PieTag} = "$Legende - " . $CompositeWidget->{RefInfoDummies}{Pie}{$PieTag}{percent};
|
473
|
|
|
|
|
|
|
|
474
|
|
|
|
|
|
|
}
|
475
|
|
|
|
|
|
|
}
|
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
#Balloon
|
478
|
|
|
|
|
|
|
unless ( defined $CompositeWidget->{RefInfoDummies}->{Balloon}{Obj} ) {
|
479
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Balloon}{Obj} = $CompositeWidget->Balloon(
|
480
|
|
|
|
|
|
|
-statusbar => $CompositeWidget,
|
481
|
|
|
|
|
|
|
-background => $CompositeWidget->{RefInfoDummies}->{Balloon}{Background},
|
482
|
|
|
|
|
|
|
);
|
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
$CompositeWidget->{RefInfoDummies}->{Balloon}{Obj}->attach(
|
485
|
|
|
|
|
|
|
$CompositeWidget,
|
486
|
|
|
|
|
|
|
-balloonposition => 'mouse',
|
487
|
|
|
|
|
|
|
-msg => \%MsgBalloon,
|
488
|
|
|
|
|
|
|
);
|
489
|
|
|
|
|
|
|
}
|
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
return;
|
492
|
|
|
|
|
|
|
}
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
1;
|
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
__END__
|