| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Imager::Graph::Pie; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =head1 NAME | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | Imager::Graph::Pie - a tool for drawing pie charts on Imager images | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | use Imager::Graph::Pie; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | my $chart = Imager::Graph::Pie->new; | 
| 12 |  |  |  |  |  |  | # see Imager::Graph for options | 
| 13 |  |  |  |  |  |  | my $img = $chart->draw( | 
| 14 |  |  |  |  |  |  | data => [ $first_amount, $second_amount ], | 
| 15 |  |  |  |  |  |  | size => 350); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | Imager::Graph::Pie is intender to make it simple to use L to | 
| 20 |  |  |  |  |  |  | create good looking pie graphs. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | Most of the basic layout and color selection is handed off to | 
| 23 |  |  |  |  |  |  | L. | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =over | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =cut | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 4 |  |  | 4 |  | 2990 | use strict; | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 160 |  | 
| 30 | 4 |  |  | 4 |  | 20 | use vars qw(@ISA); | 
|  | 4 |  |  |  |  | 6 |  | 
|  | 4 |  |  |  |  | 212 |  | 
| 31 | 4 |  |  | 4 |  | 3538 | use Imager::Graph; | 
|  | 4 |  |  |  |  | 12 |  | 
|  | 4 |  |  |  |  | 277 |  | 
| 32 |  |  |  |  |  |  | @ISA = qw(Imager::Graph); | 
| 33 | 4 |  |  | 4 |  | 2913 | use Imager::Graph::Util; | 
|  | 4 |  |  |  |  | 11 |  | 
|  | 4 |  |  |  |  | 296 |  | 
| 34 | 4 |  |  | 4 |  | 4255 | use POSIX qw(floor); | 
|  | 4 |  |  |  |  | 30528 |  | 
|  | 4 |  |  |  |  | 32 |  | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 4 |  |  | 4 |  | 4827 | use constant PI => 3.1415926535; | 
|  | 4 |  |  |  |  | 10 |  | 
|  | 4 |  |  |  |  | 13656 |  | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =item $graph->draw(...) | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | Draws a pie graph onto a new image and returns the image. | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | You must at least supply a C parameter and should probably supply a C parameter.  If you supply a C parameter, you must supply a C parameter. | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | The C parameter should be a reference to an array containing the | 
| 45 |  |  |  |  |  |  | data the pie graph should present. | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | The C parameter is a reference to an array of labels, | 
| 48 |  |  |  |  |  |  | corresponding to the values in C. | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | =back | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head1 FEATURES | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | As described in L you can enable extra features for | 
| 55 |  |  |  |  |  |  | your graph.  The features you can use with pie graphs are: | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | =over | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =item show_callouts_onAll_segments() | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | Feature: allcallouts. | 
| 62 |  |  |  |  |  |  | XX | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | all labels are presented as callouts | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =cut | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | sub show_callouts_onAll_segments { | 
| 69 | 1 |  |  | 1 | 1 | 12 | $_[0]->{'custom_style'}->{'features'}->{'allcallouts'} = 1; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =item show_only_label_percentages() | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | Feature: labelspconly | 
| 75 |  |  |  |  |  |  | XX | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | only show the percentage, not the labels. | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =cut | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub show_only_label_percentages { | 
| 82 | 1 |  |  | 1 | 1 | 10 | $_[0]->{'custom_style'}->{'features'}->{'labelspconly'} = 1; | 
| 83 |  |  |  |  |  |  | } | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | =item show_label_percentages() | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | Feature: labelspc | 
| 88 |  |  |  |  |  |  | XX | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | adds the percentage of the pie to each label. | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | =cut | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | sub show_label_percentages { | 
| 95 | 1 |  |  | 1 | 1 | 10 | $_[0]->{'custom_style'}->{'features'}->{'labelspc'} = 1; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =back | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | Inherited features: | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =over | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =item legend | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | adds a legend to your graph.  Requires the labels parameter | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =item labels | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | labels each segment of the graph.  If the label doesn't fit inside the | 
| 111 |  |  |  |  |  |  | segment it is presented as a callout. | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =item outline | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | the pie segments are outlined. | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =item dropshadow | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | the pie is given a drop shadow. | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =back | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | =head1 PIE CHART STYLES | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | The following style values are specific to pie charts: | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | Controlling callouts, the C option: | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | =over | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =item * | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | color - the color of the callout line and the callout text. | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =item * | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | font, size - font and size of the callout text | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | =item * | 
| 140 |  |  |  |  |  |  |  | 
| 141 |  |  |  |  |  |  | outside - the distance the radial callout line goes outside the pie | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =item * | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | leadlen - the length of the horizontal callout line from the end of | 
| 146 |  |  |  |  |  |  | the radial line. | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | =item * | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | gap - the distance between the end of the horizontal callout line and | 
| 151 |  |  |  |  |  |  | the label. | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =item * | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | inside - the length of the radial callout line within the pie. | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =back | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | The outline, line option controls the color of the pie segment | 
| 160 |  |  |  |  |  |  | outlines, if enabled with the C feature. | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | Under C: | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =over | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | =item * | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | maxsegment - any segment below this fraction of the total of the | 
| 169 |  |  |  |  |  |  | segments will be put into the "others" segment.  Default: 0.01 | 
| 170 |  |  |  |  |  |  |  | 
| 171 |  |  |  |  |  |  | =back | 
| 172 |  |  |  |  |  |  |  | 
| 173 |  |  |  |  |  |  | The top level C setting controls the label for the | 
| 174 |  |  |  |  |  |  | "others" segment, default "(others)". | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | =head1 EXAMPLES | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | Assuming: | 
| 179 |  |  |  |  |  |  |  | 
| 180 |  |  |  |  |  |  | # from the Netcraft September 2001 web survey | 
| 181 |  |  |  |  |  |  | # http://www.netcraft.com/survey/ | 
| 182 |  |  |  |  |  |  | my @data   = qw(17874757  8146372   1321544  811406 ); | 
| 183 |  |  |  |  |  |  | my @labels = qw(Apache    Microsoft i_planet  Zeus   ); | 
| 184 |  |  |  |  |  |  |  | 
| 185 |  |  |  |  |  |  | my $pie = Imager::Graph::Pie->new; | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | First a simple graph, normal size, no labels: | 
| 188 |  |  |  |  |  |  |  | 
| 189 |  |  |  |  |  |  | my $img = $pie->draw(data=>\@data) | 
| 190 |  |  |  |  |  |  | or die $pie->error; | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | label the segments: | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | # error handling omitted for brevity from now on | 
| 195 |  |  |  |  |  |  | $img = $pie->draw(data=>\@data, labels=>\@labels, features=>'labels'); | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | just percentages in the segments: | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | $img = $pie->draw(data=>\@data, features=>'labelspconly'); | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | add a legend as well: | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | $img = $pie->draw(data=>\@data, labels=>\@labels, | 
| 204 |  |  |  |  |  |  | features=>[ 'labelspconly', 'legend' ]); | 
| 205 |  |  |  |  |  |  |  | 
| 206 |  |  |  |  |  |  | and a title, but move the legend down, and add a dropshadow: | 
| 207 |  |  |  |  |  |  |  | 
| 208 |  |  |  |  |  |  | $img = $pie->draw(data=>\@data, labels=>\@labels, | 
| 209 |  |  |  |  |  |  | title=>'Netcraft Web Survey', | 
| 210 |  |  |  |  |  |  | legend=>{ valign=>'bottom' }, | 
| 211 |  |  |  |  |  |  | features=>[ qw/labelspconly legend dropshadow/ ]); | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | something a bit prettier: | 
| 214 |  |  |  |  |  |  |  | 
| 215 |  |  |  |  |  |  | $img = $pie->draw(data=>\@data, labels=>\@labels, | 
| 216 |  |  |  |  |  |  | style=>'fount_lin', features=>'legend'); | 
| 217 |  |  |  |  |  |  |  | 
| 218 |  |  |  |  |  |  | suitable for monochrome output: | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | $img = $pie->draw(data=>\@data, labels=>\@labels, | 
| 221 |  |  |  |  |  |  | style=>'mono', features=>'legend'); | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | =cut | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | # this function is too long | 
| 226 |  |  |  |  |  |  | sub draw { | 
| 227 | 24 |  |  | 24 | 1 | 25753 | my ($self, %opts) = @_; | 
| 228 |  |  |  |  |  |  |  | 
| 229 | 24 |  |  |  |  | 171 | my $data_series = $self->_get_data_series(\%opts); | 
| 230 |  |  |  |  |  |  |  | 
| 231 | 24 | 100 |  |  |  | 119 | $self->_valid_input($data_series) | 
| 232 |  |  |  |  |  |  | or return; | 
| 233 |  |  |  |  |  |  |  | 
| 234 | 21 |  |  |  |  | 39 | my @data = @{$data_series->[0]->{'data'}}; | 
|  | 21 |  |  |  |  | 88 |  | 
| 235 |  |  |  |  |  |  |  | 
| 236 | 21 | 100 |  |  |  | 35 | my @labels = @{$self->_get_labels(\%opts) || []}; | 
|  | 21 |  |  |  |  | 106 |  | 
| 237 |  |  |  |  |  |  |  | 
| 238 | 21 |  |  |  |  | 118 | $self->_style_setup(\%opts); | 
| 239 |  |  |  |  |  |  |  | 
| 240 | 21 |  |  |  |  | 243 | my $style = $self->{_style}; | 
| 241 |  |  |  |  |  |  |  | 
| 242 | 21 | 100 |  |  |  | 111 | my $img = $self->_make_img() | 
| 243 |  |  |  |  |  |  | or return; | 
| 244 |  |  |  |  |  |  |  | 
| 245 | 20 |  |  |  |  | 460 | my @chart_box = ( 0, 0, $img->getwidth-1, $img->getheight-1 ); | 
| 246 | 20 | 100 |  |  |  | 811 | if ($style->{title}{text}) { | 
| 247 | 7 | 100 |  |  |  | 74 | $self->_draw_title($img, \@chart_box) | 
| 248 |  |  |  |  |  |  | or return; | 
| 249 |  |  |  |  |  |  | } | 
| 250 |  |  |  |  |  |  |  | 
| 251 | 19 |  |  |  |  | 51 | my $total = 0; | 
| 252 | 19 |  |  |  |  | 62 | for my $item (@data) { | 
| 253 | 134 |  |  |  |  | 217 | $total += $item; | 
| 254 |  |  |  |  |  |  | } | 
| 255 |  |  |  |  |  |  |  | 
| 256 |  |  |  |  |  |  | # consolidate any segments that are too small to display | 
| 257 | 19 |  |  |  |  | 127 | $self->_consolidate_segments(\@data, \@labels, $total); | 
| 258 |  |  |  |  |  |  |  | 
| 259 | 19 | 50 | 100 |  |  | 145 | if ($style->{features}{legend} && (scalar @labels)) { | 
| 260 | 10 | 100 |  |  |  | 76 | $self->_draw_legend($img, \@labels, \@chart_box) | 
| 261 |  |  |  |  |  |  | or return; | 
| 262 |  |  |  |  |  |  | } | 
| 263 |  |  |  |  |  |  |  | 
| 264 |  |  |  |  |  |  | # the following code is fairly ugly | 
| 265 |  |  |  |  |  |  | # it attempts to work out a good layout for the components of the chart | 
| 266 | 17 |  |  |  |  | 33 | my @info; | 
| 267 | 17 |  |  |  |  | 30 | my $index = 0; | 
| 268 | 17 |  |  |  |  | 26 | my $pos = 0; | 
| 269 | 17 |  |  |  |  | 56 | my @ebox = (0, 0, 0, 0); | 
| 270 | 17 | 50 |  |  |  | 79 | defined(my $callout_outside = $self->_get_number('callout.outside')) | 
| 271 |  |  |  |  |  |  | or return; | 
| 272 | 17 | 50 |  |  |  | 71 | defined(my $callout_leadlen = $self->_get_number('callout.leadlen')) | 
| 273 |  |  |  |  |  |  | or return; | 
| 274 | 17 | 50 |  |  |  | 59 | defined(my $callout_gap = $self->_get_number('callout.gap')) | 
| 275 |  |  |  |  |  |  | or return; | 
| 276 | 17 | 50 |  |  |  | 65 | defined(my $label_vpad = $self->_get_number('label.vpad')) | 
| 277 |  |  |  |  |  |  | or return; | 
| 278 | 17 | 50 |  |  |  | 60 | defined(my $label_hpad = $self->_get_number('label.hpad')) | 
| 279 |  |  |  |  |  |  | or return; | 
| 280 | 17 |  |  |  |  | 118 | my $guessradius = | 
| 281 |  |  |  |  |  |  | int($self->_small_extent(\@chart_box) * $style->{pie}{guessfactor} * 0.5); | 
| 282 | 17 |  |  |  |  | 50 | for my $data (@data) { | 
| 283 | 86 |  |  |  |  | 299 | my $item = { data=>$data, index=>$index }; | 
| 284 | 86 |  |  |  |  | 172 | my $size = 2 * PI * $data / $total; | 
| 285 | 86 |  |  |  |  | 158 | $item->{begin} = $pos; | 
| 286 | 86 |  |  |  |  | 116 | $pos += $size; | 
| 287 | 86 |  |  |  |  | 153 | $item->{end} = $pos; | 
| 288 | 86 | 50 |  |  |  | 193 | if (scalar @labels) { | 
| 289 | 86 |  |  |  |  | 207 | $item->{text} = $labels[$index]; | 
| 290 |  |  |  |  |  |  | } | 
| 291 | 86 | 100 |  |  |  | 253 | if ($style->{features}{labelspconly}) { | 
| 292 | 15 |  |  |  |  | 66 | $item->{text} = | 
| 293 |  |  |  |  |  |  | $style->{label}{pconlyformat}->($data/$total * 100); | 
| 294 |  |  |  |  |  |  | } | 
| 295 | 86 | 50 |  |  |  | 214 | if ($item->{text}) { | 
| 296 | 86 | 100 |  |  |  | 362 | if ($style->{features}{labelspc}) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 297 | 24 |  |  |  |  | 113 | $item->{text} = | 
| 298 |  |  |  |  |  |  | $style->{label}{pcformat}->($item->{text}, $data/$total * 100); | 
| 299 | 24 |  |  |  |  | 48 | $item->{label} = 1; | 
| 300 |  |  |  |  |  |  | } | 
| 301 |  |  |  |  |  |  | elsif ($style->{features}{labelspconly}) { | 
| 302 | 15 |  |  |  |  | 82 | $item->{text} = | 
| 303 |  |  |  |  |  |  | $style->{label}{pconlyformat}->($data/$total * 100); | 
| 304 | 15 |  |  |  |  | 31 | $item->{label} = 1; | 
| 305 |  |  |  |  |  |  | } | 
| 306 |  |  |  |  |  |  | elsif ($style->{features}{labels}) { | 
| 307 | 27 |  |  |  |  | 49 | $item->{label} = 1; | 
| 308 |  |  |  |  |  |  | } | 
| 309 | 86 | 100 |  |  |  | 268 | $item->{callout} = 1 if $style->{features}{allcallouts}; | 
| 310 | 86 | 100 |  |  |  | 192 | if (!$item->{callout}) { | 
| 311 | 65 | 100 |  |  |  | 243 | my @lbox = $self->_text_bbox($item->{text}, 'label') | 
| 312 |  |  |  |  |  |  | or return; | 
| 313 | 64 |  |  |  |  | 164 | $item->{lbox} = \@lbox; | 
| 314 | 64 | 100 |  |  |  | 166 | if ($item->{label}) { | 
| 315 | 51 | 100 |  |  |  | 195 | unless ($self->_fit_text(0, 0, 'label', $item->{text}, $guessradius, | 
| 316 |  |  |  |  |  |  | $item->{begin}, $item->{end})) { | 
| 317 | 18 |  |  |  |  | 69 | $item->{callout} = 1; | 
| 318 |  |  |  |  |  |  | } | 
| 319 |  |  |  |  |  |  | } | 
| 320 |  |  |  |  |  |  | } | 
| 321 | 85 | 100 |  |  |  | 225 | if ($item->{callout}) { | 
| 322 | 39 |  |  |  |  | 63 | $item->{label} = 0; | 
| 323 | 39 | 100 |  |  |  | 159 | my @cbox = $self->_text_bbox($item->{text}, 'callout') | 
| 324 |  |  |  |  |  |  | or return; | 
| 325 | 38 |  |  |  |  | 115 | $item->{cbox} = \@cbox; | 
| 326 | 38 |  |  |  |  | 121 | $item->{cangle} = ($item->{begin} + $item->{end}) / 2; | 
| 327 | 38 |  |  |  |  | 120 | my $dist = cos($item->{cangle}) * ($guessradius+ | 
| 328 |  |  |  |  |  |  | $callout_outside); | 
| 329 | 38 |  |  |  |  | 99 | my $co_size = $callout_leadlen + $callout_gap + $item->{cbox}[2]; | 
| 330 | 38 | 100 |  |  |  | 79 | if ($dist < 0) { | 
| 331 | 4 |  |  |  |  | 10 | $dist -= $co_size - $guessradius; | 
| 332 | 4 | 50 |  |  |  | 18 | $dist < $ebox[0] and $ebox[0] = $dist; | 
| 333 |  |  |  |  |  |  | } | 
| 334 |  |  |  |  |  |  | else { | 
| 335 | 34 |  |  |  |  | 56 | $dist += $co_size - $guessradius; | 
| 336 | 34 | 100 |  |  |  | 157 | $dist > $ebox[2] and $ebox[2] = $dist; | 
| 337 |  |  |  |  |  |  | } | 
| 338 |  |  |  |  |  |  | } | 
| 339 |  |  |  |  |  |  | } | 
| 340 | 84 |  |  |  |  | 146 | push(@info, $item); | 
| 341 | 84 |  |  |  |  | 169 | ++$index; | 
| 342 |  |  |  |  |  |  | } | 
| 343 |  |  |  |  |  |  |  | 
| 344 | 15 |  |  |  |  | 78 | my $radius = | 
| 345 |  |  |  |  |  |  | int($self->_small_extent(\@chart_box) * $style->{pie}{size} * 0.5); | 
| 346 | 15 |  |  |  |  | 43 | my $max_width = $chart_box[2] - $chart_box[0] + $ebox[0] - $ebox[2]; | 
| 347 | 15 | 100 |  |  |  | 59 | if ($radius > $max_width / 2) { | 
| 348 | 5 |  |  |  |  | 11 | $radius = int($max_width / 2); | 
| 349 |  |  |  |  |  |  | } | 
| 350 | 15 |  |  |  |  | 28 | $chart_box[0] -= $ebox[0]; | 
| 351 | 15 |  |  |  |  | 26 | $chart_box[2] -= $ebox[2]; | 
| 352 | 15 |  |  |  |  | 43 | my $cx = int(($chart_box[0] + $chart_box[2]) / 2); | 
| 353 | 15 |  |  |  |  | 33 | my $cy = int(($chart_box[1] + $chart_box[3]) / 2); | 
| 354 | 15 | 100 |  |  |  | 70 | if ($style->{features}{dropshadow}) { | 
| 355 | 10 | 50 |  |  |  | 54 | my @shadow_fill = $self->_get_fill('dropshadow.fill') | 
| 356 |  |  |  |  |  |  | or return; | 
| 357 | 10 | 50 |  |  |  | 72 | my $offx = $self->_get_number('dropshadow.offx') | 
| 358 |  |  |  |  |  |  | or return; | 
| 359 | 10 |  |  |  |  | 29 | my $offy = $self->_get_number('dropshadow.offy'); | 
| 360 | 10 |  |  |  |  | 26 | for my $item (@info) { | 
| 361 | 59 |  |  |  |  | 181171 | $img->arc(x=>$cx+$offx, 'y'=>$cy+$offy, r=>$radius+1, aa => 1, | 
| 362 |  |  |  |  |  |  | d1=>180/PI * $item->{begin}, d2=>180/PI * $item->{end}, | 
| 363 |  |  |  |  |  |  | @shadow_fill); | 
| 364 |  |  |  |  |  |  | } | 
| 365 | 10 | 50 |  |  |  | 44295 | $self->_filter_region($img, | 
| 366 |  |  |  |  |  |  | $cx+$offx-$radius-10, $cy+$offy-$radius-10, | 
| 367 |  |  |  |  |  |  | $cx+$offx+$radius+10, $cy+$offy+$radius+10, | 
| 368 |  |  |  |  |  |  | 'dropshadow.filter') | 
| 369 |  |  |  |  |  |  | if $style->{dropshadow}{filter}; | 
| 370 |  |  |  |  |  |  | } | 
| 371 |  |  |  |  |  |  |  | 
| 372 | 15 |  |  |  |  | 363232 | my @fill_box = ( $cx-$radius, $cy-$radius, $cx+$radius, $cy+$radius ); | 
| 373 | 15 |  |  |  |  | 113 | my $fill_aa = $self->_get_number('fill.aa'); | 
| 374 | 15 |  |  |  |  | 57 | for my $item (@info) { | 
| 375 | 84 | 100 |  |  |  | 207448 | $item->{begin} < $item->{end} | 
| 376 |  |  |  |  |  |  | or next; | 
| 377 | 81 | 50 |  |  |  | 551 | my @fill = $self->_data_fill($item->{index}, \@fill_box) | 
| 378 |  |  |  |  |  |  | or return; | 
| 379 | 81 |  |  |  |  | 1725 | $img->arc(x=>$cx, 'y'=>$cy, r=>$radius, aa => $fill_aa, | 
| 380 |  |  |  |  |  |  | d1=>180/PI * $item->{begin}, d2=>180/PI * $item->{end}, | 
| 381 |  |  |  |  |  |  | @fill); | 
| 382 |  |  |  |  |  |  | } | 
| 383 | 15 | 100 |  |  |  | 4088 | if ($style->{features}{outline}) { | 
| 384 | 6 |  |  |  |  | 59 | my %outstyle = $self->_line_style('outline'); | 
| 385 | 6 |  |  |  |  | 22 | my $out_radius = 0.5 + $radius; | 
| 386 | 6 |  |  |  |  | 22 | for my $item (@info) { | 
| 387 | 41 |  |  |  |  | 140 | my $px = int($cx + $out_radius * cos($item->{begin})); | 
| 388 | 41 |  |  |  |  | 92 | my $py = int($cy + $out_radius * sin($item->{begin})); | 
| 389 | 41 | 100 |  |  |  | 145 | $item->{begin} < $item->{end} | 
| 390 |  |  |  |  |  |  | or next; | 
| 391 | 38 |  |  |  |  | 163 | $img->line(x1=>$cx, y1=>$cy, x2=>$px, y2=>$py, %outstyle); | 
| 392 | 38 |  |  |  |  | 3082 | for (my $i = $item->{begin}; $i < $item->{end}; $i += PI/180) { | 
| 393 | 2178 |  |  |  |  | 3234 | my $stroke_end = $i + PI/180; | 
| 394 | 2178 | 100 |  |  |  | 4515 | $stroke_end = $item->{end} if $stroke_end > $item->{end}; | 
| 395 | 2178 |  |  |  |  | 4302 | my $nx = int($cx + $out_radius * cos($stroke_end)); | 
| 396 | 2178 |  |  |  |  | 3520 | my $ny = int($cy + $out_radius * sin($stroke_end)); | 
| 397 | 2178 |  |  |  |  | 7925 | $img->line(x1=>$px, y1=>$py, x2=>$nx, y2=>$ny, %outstyle); | 
| 398 | 2178 |  |  |  |  | 120751 | ($px, $py) = ($nx, $ny); | 
| 399 |  |  |  |  |  |  | } | 
| 400 |  |  |  |  |  |  | } | 
| 401 |  |  |  |  |  |  | } | 
| 402 |  |  |  |  |  |  |  | 
| 403 | 15 |  |  |  |  | 117 | my $callout_inside = $radius - $self->_get_number('callout.inside'); | 
| 404 | 15 |  |  |  |  | 35 | $callout_outside += $radius; | 
| 405 | 15 |  |  |  |  | 28 | my %callout_text; | 
| 406 |  |  |  |  |  |  | my %label_text; | 
| 407 | 0 |  |  |  |  | 0 | my %callout_line; | 
| 408 | 15 |  |  |  |  | 53 | my $leader_aa = $self->_get_number('callout.leadaa'); | 
| 409 | 15 |  |  |  |  | 49 | for my $label (@info) { | 
| 410 | 84 | 100 | 66 |  |  | 4892 | if ($label->{label} && !$label->{callout}) { | 
| 411 |  |  |  |  |  |  | # at this point we know we need the label font, to calculate | 
| 412 |  |  |  |  |  |  | # whether the label will fit if anything else | 
| 413 | 33 | 100 |  |  |  | 156 | unless (%label_text) { | 
| 414 | 8 | 50 |  |  |  | 45 | %label_text = $self->_text_style('label') | 
| 415 |  |  |  |  |  |  | or return; | 
| 416 |  |  |  |  |  |  | } | 
| 417 | 33 |  |  |  |  | 174 | my @loc = $self->_fit_text($cx, $cy, 'label', $label->{text}, $radius, | 
| 418 |  |  |  |  |  |  | $label->{begin}, $label->{end}); | 
| 419 | 33 | 50 |  |  |  | 81 | if (@loc) { | 
| 420 | 33 |  |  |  |  | 75 | my $tcx = ($loc[0]+$loc[2])/2; | 
| 421 | 33 |  |  |  |  | 56 | my $tcy = ($loc[1]+$loc[3])/2; | 
| 422 |  |  |  |  |  |  | #$img->box(xmin=>$loc[0], ymin=>$loc[1], xmax=>$loc[2], ymax=>$loc[3], | 
| 423 |  |  |  |  |  |  | #          color=>Imager::Color->new(0,0,0)); | 
| 424 | 33 |  |  |  |  | 314 | $img->string(%label_text, x=>$tcx-$label->{lbox}[2]/2, | 
| 425 |  |  |  |  |  |  | 'y'=>$tcy+$label->{lbox}[3]/2+$label->{lbox}[1], | 
| 426 |  |  |  |  |  |  | text=>$label->{text}); | 
| 427 |  |  |  |  |  |  | } | 
| 428 |  |  |  |  |  |  | else { | 
| 429 | 0 |  |  |  |  | 0 | $label->{callout} = 1; | 
| 430 | 0 | 0 |  |  |  | 0 | my @cbox = $self->_text_bbox($label->{text}, 'callout') | 
| 431 |  |  |  |  |  |  | or return; | 
| 432 | 0 |  |  |  |  | 0 | $label->{cbox} = \@cbox; | 
| 433 | 0 |  |  |  |  | 0 | $label->{cangle} = ($label->{begin} + $label->{end}) / 2; | 
| 434 |  |  |  |  |  |  | } | 
| 435 |  |  |  |  |  |  | } | 
| 436 | 84 | 100 |  |  |  | 6271 | if ($label->{callout}) { | 
| 437 | 38 | 100 |  |  |  | 153 | unless (%callout_text) { | 
| 438 | 12 | 50 |  |  |  | 64 | %callout_text = $self->_text_style('callout') | 
| 439 |  |  |  |  |  |  | or return; | 
| 440 | 12 |  |  |  |  | 74 | %callout_line = $self->_line_style('callout'); | 
| 441 |  |  |  |  |  |  | } | 
| 442 | 38 |  |  |  |  | 207 | my $ix = floor(0.5 + $cx + $callout_inside * cos($label->{cangle})); | 
| 443 | 38 |  |  |  |  | 140 | my $iy = floor(0.5 + $cy + $callout_inside * sin($label->{cangle})); | 
| 444 | 38 |  |  |  |  | 115 | my $ox = floor(0.5 + $cx + $callout_outside * cos($label->{cangle})); | 
| 445 | 38 |  |  |  |  | 118 | my $oy = floor(0.5 + $cy + $callout_outside * sin($label->{cangle})); | 
| 446 | 38 | 100 |  |  |  | 108 | my $lx = ($ox < $cx) ? $ox - $callout_leadlen : $ox + $callout_leadlen; | 
| 447 | 38 |  |  |  |  | 279 | $img->polyline(points => [ [ $ix, $iy ], | 
| 448 |  |  |  |  |  |  | [ $ox, $oy ], | 
| 449 |  |  |  |  |  |  | [ $lx, $oy ] ], | 
| 450 |  |  |  |  |  |  | %callout_line); | 
| 451 |  |  |  |  |  |  | #my $tx = $lx + $callout_gap; | 
| 452 | 38 |  |  |  |  | 3133 | my $ty = $oy + $label->{cbox}[3]/2+$label->{cbox}[1]; | 
| 453 | 38 | 100 |  |  |  | 90 | if ($lx < $cx) { | 
| 454 | 4 |  |  |  |  | 29 | $img->string(%callout_text, x=>$lx-$callout_gap-$label->{cbox}[2], | 
| 455 |  |  |  |  |  |  | 'y'=>$ty, text=>$label->{text}); | 
| 456 |  |  |  |  |  |  | } | 
| 457 |  |  |  |  |  |  | else { | 
| 458 | 34 |  |  |  |  | 375 | $img->string(%callout_text, x=>$lx+$callout_gap, 'y'=>$ty, | 
| 459 |  |  |  |  |  |  | text=>$label->{text}); | 
| 460 |  |  |  |  |  |  | } | 
| 461 |  |  |  |  |  |  | } | 
| 462 |  |  |  |  |  |  | } | 
| 463 |  |  |  |  |  |  |  | 
| 464 | 15 |  |  |  |  | 2282 | $img; | 
| 465 |  |  |  |  |  |  | } | 
| 466 |  |  |  |  |  |  |  | 
| 467 |  |  |  |  |  |  | sub _valid_input { | 
| 468 | 24 |  |  | 24 |  | 50 | my ($self, $data_series) = @_; | 
| 469 |  |  |  |  |  |  |  | 
| 470 | 24 | 50 | 33 |  |  | 170 | if (!defined $data_series || !scalar @$data_series) { | 
| 471 | 0 |  |  |  |  | 0 | return $self->_error("No data supplied"); | 
| 472 |  |  |  |  |  |  | } | 
| 473 |  |  |  |  |  |  |  | 
| 474 | 24 | 50 |  |  |  | 82 | @$data_series == 1 | 
| 475 |  |  |  |  |  |  | or return $self->_error("Pie charts only allow one data series"); | 
| 476 |  |  |  |  |  |  |  | 
| 477 | 24 |  |  |  |  | 70 | my $data = $data_series->[0]{data}; | 
| 478 |  |  |  |  |  |  |  | 
| 479 | 24 | 100 |  |  |  | 72 | if (!scalar @$data) { | 
| 480 | 1 |  |  |  |  | 9 | return $self->_error("No values in data series"); | 
| 481 |  |  |  |  |  |  | } | 
| 482 |  |  |  |  |  |  |  | 
| 483 | 23 |  |  |  |  | 45 | my $total = 0; | 
| 484 |  |  |  |  |  |  | { | 
| 485 | 23 |  |  |  |  | 29 | my $index = 0; | 
|  | 23 |  |  |  |  | 52 |  | 
| 486 | 23 |  |  |  |  | 60 | for my $item (@$data) { | 
| 487 | 153 | 100 |  |  |  | 441 | $item < 0 | 
| 488 |  |  |  |  |  |  | and return $self->_error("Data index $index is less than zero"); | 
| 489 |  |  |  |  |  |  |  | 
| 490 | 152 |  |  |  |  | 206 | $total += $item; | 
| 491 |  |  |  |  |  |  |  | 
| 492 | 152 |  |  |  |  | 211 | ++$index; | 
| 493 |  |  |  |  |  |  | } | 
| 494 |  |  |  |  |  |  | } | 
| 495 | 22 | 100 |  |  |  | 75 | $total == 0 | 
| 496 |  |  |  |  |  |  | and return $self->_error("Sum of all data values is zero"); | 
| 497 |  |  |  |  |  |  |  | 
| 498 | 21 |  |  |  |  | 71 | return 1; | 
| 499 |  |  |  |  |  |  | } | 
| 500 |  |  |  |  |  |  |  | 
| 501 |  |  |  |  |  |  | =head1 INTERNAL FUNCTIONS | 
| 502 |  |  |  |  |  |  |  | 
| 503 |  |  |  |  |  |  | These are used in the implementation of Imager::Graph, and are | 
| 504 |  |  |  |  |  |  | documented for debuggers and developers. | 
| 505 |  |  |  |  |  |  |  | 
| 506 |  |  |  |  |  |  | =over | 
| 507 |  |  |  |  |  |  |  | 
| 508 |  |  |  |  |  |  | =item _consolidate_segments($data, $labels, $total) | 
| 509 |  |  |  |  |  |  |  | 
| 510 |  |  |  |  |  |  | Consolidate segments that are too small into an 'others' segment. | 
| 511 |  |  |  |  |  |  |  | 
| 512 |  |  |  |  |  |  | =cut | 
| 513 |  |  |  |  |  |  |  | 
| 514 |  |  |  |  |  |  | sub _consolidate_segments { | 
| 515 | 19 |  |  | 19 |  | 102 | my ($self, $data, $labels, $total) = @_; | 
| 516 |  |  |  |  |  |  |  | 
| 517 | 19 |  |  |  |  | 35 | my @others; | 
| 518 | 19 |  |  |  |  | 40 | my $index = 0; | 
| 519 | 19 |  |  |  |  | 52 | for my $item (@$data) { | 
| 520 | 134 | 100 |  |  |  | 499 | if ($item / $total < $self->{_style}{pie}{maxsegment}) { | 
| 521 | 48 |  |  |  |  | 74 | push(@others, $index); | 
| 522 |  |  |  |  |  |  | } | 
| 523 | 134 |  |  |  |  | 184 | ++$index; | 
| 524 |  |  |  |  |  |  | } | 
| 525 | 19 | 100 |  |  |  | 67 | if (@others) { | 
| 526 | 18 |  |  |  |  | 41 | my $others = 0; | 
| 527 | 18 |  |  |  |  | 44 | for my $index (reverse @others) { | 
| 528 | 48 |  |  |  |  | 93 | $others += $data->[$index]; | 
| 529 | 48 |  |  |  |  | 107 | splice(@$labels, $index, 1); | 
| 530 | 48 |  |  |  |  | 111 | splice(@$data, $index, 1); | 
| 531 |  |  |  |  |  |  | } | 
| 532 | 18 | 50 |  |  |  | 112 | push(@$labels, $self->{_style}{otherlabel}) if @$labels; | 
| 533 | 18 |  |  |  |  | 55 | push(@$data, $others); | 
| 534 |  |  |  |  |  |  | } | 
| 535 |  |  |  |  |  |  | } | 
| 536 |  |  |  |  |  |  |  | 
| 537 |  |  |  |  |  |  | # used for debugging | 
| 538 |  |  |  |  |  |  | sub _test_line { | 
| 539 | 0 |  |  | 0 |  | 0 | my ($x, $y, @l) = @_; | 
| 540 |  |  |  |  |  |  |  | 
| 541 | 0 |  |  |  |  | 0 | my $res = $l[0]*$x + $l[1] * $y + $l[2]; | 
| 542 | 0 | 0 |  |  |  | 0 | print "test ", (abs($res) < 0.000001) ? "success\n" : "failure $res\n"; | 
| 543 |  |  |  |  |  |  | } | 
| 544 |  |  |  |  |  |  |  | 
| 545 |  |  |  |  |  |  | =item _fit_text($cx, $cy, $name, $text, $radius, $begin, $end) | 
| 546 |  |  |  |  |  |  |  | 
| 547 |  |  |  |  |  |  | Attempts to fit text into a pie segment with its center at ($cx, $cy) | 
| 548 |  |  |  |  |  |  | with the given radius, covering the angles $begin through $end. | 
| 549 |  |  |  |  |  |  |  | 
| 550 |  |  |  |  |  |  | Returns a list defining the bounding box of the text if it does fit. | 
| 551 |  |  |  |  |  |  |  | 
| 552 |  |  |  |  |  |  | =cut | 
| 553 |  |  |  |  |  |  |  | 
| 554 |  |  |  |  |  |  | sub _fit_text { | 
| 555 | 84 |  |  | 84 |  | 261 | my ($self, $cx, $cy, $name, $text, $radius, $begin, $end) = @_; | 
| 556 |  |  |  |  |  |  |  | 
| 557 |  |  |  |  |  |  | #print "fit: $cx, $cy '$text' $radius $begin $end\n"; | 
| 558 | 84 | 50 |  |  |  | 261 | my @tbox = $self->_text_bbox($text, $name) | 
| 559 |  |  |  |  |  |  | or return; | 
| 560 | 84 |  |  |  |  | 610 | my $tcx = floor(0.5+$cx + cos(($begin+$end)/2) * $radius *3/5); | 
| 561 | 84 |  |  |  |  | 381 | my $tcy = floor(0.5+$cy + sin(($begin+$end)/2) * $radius *3/5); | 
| 562 | 84 |  |  |  |  | 252 | my $topy = $tcy - $tbox[3]/2; | 
| 563 | 84 |  |  |  |  | 117 | my $boty = $topy + $tbox[3]; | 
| 564 | 84 |  |  |  |  | 96 | my @lines; | 
| 565 | 84 |  |  |  |  | 188 | for my $y ($topy, $boty) { | 
| 566 | 166 |  |  |  |  | 526 | my %entry = ( 'y'=>$y ); | 
| 567 | 166 |  |  |  |  | 633 | $entry{line} = [ line_from_points($tcx, $y, $tcx+1, $y) ]; | 
| 568 | 166 |  |  |  |  | 334 | $entry{left} = -$radius; | 
| 569 | 166 |  |  |  |  | 320 | $entry{right} = $radius; | 
| 570 | 166 |  |  |  |  | 243 | for my $angle ($begin, $end) { | 
| 571 | 330 |  |  |  |  | 583 | my $ex = $cx + cos($angle)*$radius; | 
| 572 | 330 |  |  |  |  | 540 | my $ey = $cy + sin($angle)*$radius; | 
| 573 | 330 |  |  |  |  | 817 | my @line = line_from_points($cx, $cy, $ex, $ey); | 
| 574 |  |  |  |  |  |  | #_test_line($cx, $cy, @line); | 
| 575 |  |  |  |  |  |  | #_test_line($ex, $ey, @line); | 
| 576 | 330 |  |  |  |  | 686 | my $goodsign = $line[0] * $tcx + $line[1] * $tcy + $line[2]; | 
| 577 | 330 |  |  |  |  | 657 | for my $pos (@entry{qw/left right/}) { | 
| 578 | 658 |  |  |  |  | 1136 | my $sign = $line[0] * ($pos+$tcx) + $line[1] * $y + $line[2]; | 
| 579 | 658 | 100 |  |  |  | 1346 | if ($goodsign * $sign < 0) { | 
| 580 | 239 | 100 |  |  |  | 276 | if (my @p = intersect_lines(@line, @{$entry{line}})) { | 
|  | 239 |  |  |  |  | 747 |  | 
| 581 |  |  |  |  |  |  | # die "$goodsign $sign ($pos, $tcx) no intersect (@line) (@{$entry{line}})"  ; # this would be wierd | 
| 582 |  |  |  |  |  |  | #_test_line(@p, @line); | 
| 583 |  |  |  |  |  |  | #_test_line(@p, @{$entry{line}}); | 
| 584 | 237 |  |  |  |  | 494 | $pos = $p[0]-$tcx; | 
| 585 |  |  |  |  |  |  | } | 
| 586 |  |  |  |  |  |  | else { | 
| 587 | 2 |  |  |  |  | 13 | return; | 
| 588 |  |  |  |  |  |  | } | 
| 589 |  |  |  |  |  |  |  | 
| 590 |  |  |  |  |  |  | } | 
| 591 |  |  |  |  |  |  |  | 
| 592 |  |  |  |  |  |  | # circle | 
| 593 | 656 |  |  |  |  | 1471 | my $dist2 = ($pos+$tcx-$cx) * ($pos+$tcx-$cx) | 
| 594 |  |  |  |  |  |  | + ($y - $cy) * ($y - $cy); | 
| 595 | 656 | 100 |  |  |  | 1924 | if ($dist2 > $radius * $radius) { | 
| 596 | 204 |  |  |  |  | 649 | my @points = | 
| 597 | 204 |  |  |  |  | 229 | intersect_line_and_circle(@{$entry{line}}, $cx, $cy, $radius); | 
| 598 | 204 |  |  |  |  | 496 | while (@points) { | 
| 599 | 408 |  |  |  |  | 774 | my @p = splice(@points, 0, 2); | 
| 600 | 408 | 100 | 100 |  |  | 2799 | if ($p[0] < $cx && $tcx+$pos < $p[0]) { | 
|  |  | 100 | 100 |  |  |  |  | 
| 601 | 70 |  |  |  |  | 201 | $pos = $p[0]-$tcx; | 
| 602 |  |  |  |  |  |  | } | 
| 603 |  |  |  |  |  |  | elsif ($p[0] > $cx && $tcx+$pos > $p[0]) { | 
| 604 | 106 |  |  |  |  | 529 | $pos = $p[0]-$tcx; | 
| 605 |  |  |  |  |  |  | } | 
| 606 |  |  |  |  |  |  | } | 
| 607 |  |  |  |  |  |  | } | 
| 608 |  |  |  |  |  |  | } | 
| 609 |  |  |  |  |  |  | } | 
| 610 | 164 |  |  |  |  | 469 | push(@lines, \%entry); | 
| 611 |  |  |  |  |  |  | } | 
| 612 | 82 | 100 |  |  |  | 308 | my $left = $lines[0]{left} > $lines[1]{left} ? $lines[0]{left} : $lines[1]{left}; | 
| 613 | 82 | 100 |  |  |  | 233 | my $right = $lines[0]{right} < $lines[1]{right} ? $lines[0]{right} : $lines[1]{right}; | 
| 614 | 82 | 100 |  |  |  | 866 | return if $right - $left < $tbox[2]; | 
| 615 |  |  |  |  |  |  |  | 
| 616 | 66 |  |  |  |  | 458 | return ($tcx+$left, $topy, $tcx+$right, $boty); | 
| 617 |  |  |  |  |  |  | } | 
| 618 |  |  |  |  |  |  |  | 
| 619 |  |  |  |  |  |  | sub _composite { | 
| 620 | 21 |  |  | 21 |  | 136 | ( 'pie', $_[0]->SUPER::_composite() ); | 
| 621 |  |  |  |  |  |  | } | 
| 622 |  |  |  |  |  |  |  | 
| 623 |  |  |  |  |  |  | sub _style_defs { | 
| 624 | 21 |  |  | 21 |  | 40 | my ($self) = @_; | 
| 625 |  |  |  |  |  |  |  | 
| 626 | 21 |  |  |  |  | 31 | my %work = %{$self->SUPER::_style_defs()}; | 
|  | 21 |  |  |  |  | 108 |  | 
| 627 | 21 |  |  |  |  | 82 | $work{otherlabel} = "(others)"; | 
| 628 | 21 |  |  |  |  | 124 | $work{pie} = | 
| 629 |  |  |  |  |  |  | { | 
| 630 |  |  |  |  |  |  | guessfactor=>0.6, | 
| 631 |  |  |  |  |  |  | size=>0.8, | 
| 632 |  |  |  |  |  |  | maxsegment=> 0.01, | 
| 633 |  |  |  |  |  |  | }; | 
| 634 |  |  |  |  |  |  |  | 
| 635 | 21 |  |  |  |  | 72 | \%work; | 
| 636 |  |  |  |  |  |  | } | 
| 637 |  |  |  |  |  |  |  | 
| 638 |  |  |  |  |  |  | 1; | 
| 639 |  |  |  |  |  |  | __END__ |