2eac77fc |
1 | #!perl -w |
2 | use strict; |
3 | use Imager::Graph::Pie; |
4 | use lib 't/lib'; |
5 | use Imager::Font::Test; |
6 | use Test::More; |
7 | |
8 | ++$|; |
9 | |
10 | use Imager qw(:handy); |
11 | |
12 | plan tests => 3; |
13 | |
14 | my $font = Imager::Font::Test->new(); |
15 | |
16 | my @data; |
17 | |
18 | for (0 .. 10) { |
19 | push @data, $_; |
20 | } |
21 | |
22 | my $api_graph = Imager::Graph::Pie->new(); |
23 | $api_graph->add_data_series(\@data, 'Positive Slope'); |
24 | $api_graph->set_style('ocean'); |
25 | $api_graph->set_labels([0 .. 10]); |
26 | |
27 | $api_graph->set_image_width(800); |
28 | $api_graph->set_image_height(600); |
29 | $api_graph->set_graph_size(500); |
30 | $api_graph->set_font($font); |
31 | $api_graph->set_image_background('FF00FF'); |
32 | $api_graph->set_channels(3); |
33 | $api_graph->set_line_color('00FF00'); |
34 | $api_graph->set_title('Tester Title'); |
35 | $api_graph->set_title_font_size(14); |
36 | $api_graph->set_title_font_color('444444'); |
37 | $api_graph->set_title_horizontal_align('left'); |
38 | $api_graph->set_title_vertical_align('bottom'); |
39 | $api_graph->set_text_font_size(18); |
40 | $api_graph->set_text_font_color('FFFFFF'); |
41 | $api_graph->set_graph_background_color('00FF00'); |
42 | $api_graph->set_graph_foreground_color('FF00FF'); |
43 | $api_graph->set_legend_font_color('0000FF'); |
44 | $api_graph->set_legend_font($font); |
45 | $api_graph->set_legend_font_size(17); |
46 | $api_graph->set_legend_patch_size(30); |
47 | $api_graph->set_legend_patch_gap(20); |
48 | $api_graph->set_legend_horizontal_align('left'); |
49 | $api_graph->set_legend_vertical_align('top'); |
50 | $api_graph->set_legend_padding(5); |
51 | $api_graph->set_legend_outside_padding(12); |
52 | $api_graph->set_legend_fill('000000'); |
53 | $api_graph->set_legend_border('222222'); |
54 | $api_graph->set_legend_orientation('horizontal'); |
55 | $api_graph->set_callout_font_color('FF0000'); |
56 | $api_graph->set_callout_font($font); |
57 | $api_graph->set_callout_font_size(45); |
58 | $api_graph->set_callout_line_color('FF2211'); |
59 | $api_graph->set_callout_leader_inside_length(10); |
60 | $api_graph->set_callout_leader_outside_length(20); |
61 | $api_graph->set_callout_leader_length(30); |
62 | $api_graph->set_callout_gap(5); |
63 | $api_graph->set_label_font_color('55FFFF'); |
64 | $api_graph->set_label_font($font); |
65 | $api_graph->set_label_font_size(16); |
66 | $api_graph->set_drop_shadow_fill_color('113333'); |
67 | $api_graph->set_drop_shadow_offset(25); |
68 | $api_graph->set_drop_shadowXOffset(30); |
69 | $api_graph->set_drop_shadowYOffset(5); |
70 | $api_graph->set_drop_shadow_filter({ type=>'mosaic', size => 20 }); |
71 | $api_graph->set_outline_color('FF00FF'); |
72 | $api_graph->set_data_area_fills([qw(FF0000 00FF00 0000FF)]); |
73 | $api_graph->set_data_line_colors([qw(FF0000 00FF00 0000FF)]); |
74 | |
75 | my $api_img = $api_graph->draw( |
76 | features => [qw(legend outline labels)], |
77 | ) || die $api_graph->error; |
78 | |
79 | ok($api_img); |
80 | |
81 | my $style_graph = Imager::Graph::Pie->new(); |
82 | |
83 | $style_graph->add_data_series(\@data, 'Positive Slope'); |
84 | $style_graph->set_style('ocean'); |
85 | $style_graph->set_labels([0 .. 10]); |
86 | |
87 | my $style_img = $style_graph->draw( |
88 | features => [qw(legend outline labels)], |
89 | font => $font, # base font * set_font() |
90 | back => 'FF00FF', # Background color/fill - set_image_background() |
91 | size => 500, # Size of the graph * set_size() |
92 | width => 800, # width of the image * set_width() |
93 | height => 600, # height of the image * set_height() |
94 | channels => 3, # # of channels in the image - set_channels() |
95 | line => '00FF00', # color of lines - set_line_color() |
96 | title => { |
97 | text => 'Tester Title', # title for the chart * set_title() |
98 | size => '14', # size of the title font - set_title_font_size() |
99 | color => '444444', # color of the title - set_title_font_color() |
100 | halign => 'left', # horizontal alignment of the title - set_title_horizontal_align() |
101 | valign => 'bottom', # vertical alignment of the title - set_title_vertical_align() |
102 | }, |
103 | text => { |
104 | color => 'FFFFFF', # default color of text - set_text_font_color() |
105 | size => '18', # default size of text - set_text_font_size() |
106 | }, |
107 | bg => '00FF00', # background color of the graph - set_graph_background_color() |
108 | fg => 'FF00FF', # foreground color of the graph - set_graph_foreground_color() |
109 | legend => { |
110 | color => '0000FF', # text color for the legend - set_legend_font_color() |
111 | font => $font, # font to be used for the legend - set_legend_font() |
112 | size => 17, # font size to be used for labels |
113 | # in the legend - set_legend_font_size() |
114 | patchsize => 30, # the size in pixels? percent? - set_legend_patch_size() |
115 | # of the color patches in |
116 | # the legend. |
117 | patchgap => 20, # gap between the color patches. - set_legend_patch_gap() |
118 | # in pixels? percent? |
119 | halign => 'left', # horizontal alignment of the - set_legend_horizontal_align() |
120 | # legend within the graph |
121 | valign => 'top', # vertical alignment of the - set_legend_vertical_align() |
122 | # legend within the graph |
123 | padding => '5', # the space between the patches - set_legend_padding() |
124 | # of color and the outside of |
125 | # the legend box |
126 | outsidepadding => '12', # the space between the - set_legend_outside_padding() |
127 | # border of the legend, |
128 | # and the outside edge of the |
129 | # legend |
130 | fill => '000000', # A fill for the background - set_legend_fill() |
131 | # of the legend. |
132 | border => '222222', # The color of the border of - set_legend_border() |
133 | # the legend. |
134 | orientation => 'horizontal', # the orientation of the - set_legend_orientation() |
135 | # legend |
136 | }, |
137 | callout => { |
138 | color => 'FF0000', # the color of the callout text - set_callout_font_color() |
139 | font => $font, # the font to use for callouts - set_callout_font() |
140 | size => 45, # the font size for callout text - set_callout_font_size() |
141 | line => 'FF2211', # the color of the line from the - set_callout_line_color() |
142 | # callout to the graph |
143 | inside => '10', # the length in pixels? of the - set_callout_leader_inside_length() |
144 | # leader... |
145 | outside => '20', # the other side of the leader? - set_callout_leader_outside_length() |
146 | leadlen => '30', # the length of the horizontal - set_callout_leader_length() |
147 | # part of the leader |
148 | gap => '5', # the space between the callout - set_callout_gap() |
149 | # leader and the callout text |
150 | }, |
151 | label => { |
152 | color => '55FFFF', # the color of the label text - set_label_font_color() |
153 | font => $font, # font used for labels - set_label_font() |
154 | size => 16, # the font size used for labels - set_label_font_size() |
155 | }, |
156 | dropshadow => { |
157 | fill => '113333', # the color used for drop shadows - set_drop_shadow_fill_color() |
158 | off => 25, # the offset of the dropshadow... - set_drop_shadow_offset() |
159 | # in percent? pixels? |
160 | offx => 30, # horizontal offset of the - set_drop_shadowXOffset() |
161 | # dropshadow |
162 | offy => 5, # vertical offset of the dropshadow - set_drop_shadowYOffset() |
163 | filter => { type=>'mosaic', size => 20 }, |
164 | |
165 | # the filter description passed to - set_drop_shadow_filter() |
166 | # Imager's filter method to blur |
167 | # the drop shadow. Default: an 11 |
168 | # element convolution filter. |
169 | }, |
170 | outline => { |
171 | line => 'FF00FF', # the color of the outline - set_outline_color() |
172 | # around data areas |
173 | }, |
174 | fills => [ |
175 | qw(FF0000 00FF00 0000FF) |
176 | # An array ref describing how to fill data areas - set_data_area_fills() |
177 | # in the graph. used by pie, column, stacked |
178 | # column graphs |
179 | ], |
180 | colors => [ |
181 | qw(FF0000 00FF00 0000FF) |
182 | # An array ref of colors, used by line graphs. - set_data_line_colors() |
183 | ], |
184 | |
185 | ) || die $style_graph->error; |
186 | |
187 | ok($api_img); |
188 | |
189 | my ($api_content, $style_content); |
190 | |
191 | $style_img->write(data => \$style_content, type=>'raw') or die "Err: ".$style_img->errstr; |
192 | $api_img->write(data => \$api_content, type=>'raw') or die "Err: ".$api_img->errstr; |
193 | |
194 | open (my $file, ">", '/var/www/tmp/pie_api.tiff'); |
195 | print $file $api_content; |
196 | close $file; |
197 | |
198 | ok($style_content eq $api_content); |
199 | |
200 | |
201 | |