C<Image::Magick::Chart> - Use Image::Magick to create charts. |
draw_frame()
draw_horizontal_bars()
draw_title()
draw_x_axis_labels()
draw_x_axis_ticks()
draw_y_axis_labels()
draw_y_axis_ticks()
new(...)
write()
Image::Magick::Chart
- Use Image::Magick to create charts.
#!/usr/bin/perl
use Image::Magick::Chart::HorizontalBars;
Image::Magick::Chart::HorizontalBars -> new ( antialias => 0, # 0 => No antialias; 1 => Antialias. bar_width => 8, # Pixels. bg_color => 'white', colorspace => 'RGB', depth => 8, # Bits per channel. fg_color => 'blue', font => 'Courier', frame_color => 'black', frame_option => 1, # 0 => None; 1 => Draw it. height => 0, image => '', output_file_name => 'image-1.png', padding => [30, 30, 30, 30], # [12 noon, 3, 6, 9]. pointsize => 14, # Points. tick_length => 4, # Pixels. title => 'Percent (%)', width => 0, x_axis_data => [0, 20, 40, 60, 80, 100], x_axis_labels => [0, 20, 40, 60, 80, 100], x_axis_labels_option => 1, # 0 => None; 1 => Draw them. x_axis_ticks_option => 2, # 0 => None; 1 => Below x-axis; 2 => Across frame. x_data => [15, 5, 70, 25, 45, 20, 65], x_data_option => 1, x_pixels_per_unit => 3, # Horizontal width of each data unit. y_axis_data => [1 .. 7, 8], # 7 data points, plus 1 to make image pretty. y_axis_labels => [(map{"($_)"} reverse (1 .. 7) ), ''], y_axis_labels_option => 1, # 0 => None; 1 => Draw them. y_axis_ticks_option => 1, # 0 => None; 1 => Left of y-axis; 2 => Across frame. y_pixels_per_unit => 20, ) -> draw();
This code is part of examples/test-chart.pl.
Note: You do not need to specify all the options above, of course, but only those you wish to differ from the defaults. I've included all options in examples/test-chart.pl just to save you the effort of having to type them in.
See Image::Magick's documentation page www/perl.html for the list of values supported by each Image::Magick option.
Image::Magick::Chart
is a pure Perl module.
This module uses Image::Magick
as the base of a set of modules which create simple images
of various types. Only Image::Magick::Chart::HorizontalBars
is available at this time.
See examples/image-*.png for sample output, and examples/test-chart.pl for the program which created those samples.
You control the size of the image by specifying the data values for X and Y, and also by specifying the scaling factors in the X and Y directions in terms of pixels per unit of data.
Eg: In the above code, the x-axis data ranges up to 100 (sic), and the x-axis scaling factor is 3 pixels/unit, so the part of the image occupied by the data will be 3 * 100 + 1 pixels wide. The 1 is for the y-axis.
The 100 comes from max(last value in @$x_axis_data, last value in @$x_data).
This module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.
See http://savage.net.au/Perl-modules.html for details.
See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro.
new(...)
returns an Image::Magick::Chart
object.
This is the class's contructor.
Usage: Image::Magick::Chart -> new().
Note: Actually, you don't normally do this.
Instead, you call: Image::Magick::Chart::HorizontalBars -> new(...)
-> draw().
This method takes a set of parameters. Only the output_file_name parameter is mandatory.
For each parameter you wish to use, call new as new(param_1 => value_1, ...).
Parameters:
See the 'image' option if you wish to use a pre-existing object of type Image::Magick.
Using a value of 1 will make your output file slightly larger.
The default value is 0.
This parameter is optional.
The default value is 8 pixels.
This parameter is optional.
See the 'image' option if you wish to use a pre-existing object of type Image::Magick.
The default value is 'white'.
This parameter is optional.
See the 'image' option if you wish to use a pre-existing object of type Image::Magick.
This parameter is optional.
The default value is 8.
This parameter is optional.
Image::Magick::Chart::HorizontalBars
.
The default value is 'black'.
This parameter is optional.
The default value is 'Courier'.
This parameter is optional.
The default color is 'black'.
This parameter is optional.
The default value is 1.
This parameter is optional.
If you use a pre-existing object of type Image::Magick, this module will get the values for width and height from that image.
This parameter is optional.
This module creates this object by default, but you can pass in to the constructor a pre-existing object of type Image::Magick, and this module will use your object.
If you use you own object, I assume you have set these parameters for your image:
By which I mean this module will not attempt to set those 4 options when you pass in a pre-existing object.
This parameter is optional.
There is no default.
This parameter is mandatory.
You must provide an array ref of 4 values for this parameter.
A clockface is used to define the meanings of the 4 values, thus:
Or, if you prefer 3 am, and you think in Spanish, then it's the hour beloved by facists and other psychopaths: 'de la madrugada'.
The default value is [30, 30, 30, 30].
This parameter is optional.
The default value is 14.
This parameter is optional.
The default value is 4 pixels.
This parameter is optional.
The default value is '' (the empty string).
This parameter is optional.
If you use a pre-existing object of type Image::Magick, this module will get the values for width and height from that image.
This parameter is optional.
The values in this array ref are multiplied by the value of the x_pixels_per_unit parameter, to determine where the x-axis labels and x-axis tick marks are drawn.
The default value is [], meaning neither labels nor tick marks will be drawn along the x-axis.
This parameter is optional.
Warning: Do not confuse this parameter with the x_data parameter.
In order to draw the x_axis_data values (abscissas) themselves as x-axis labels, just pass in the same array ref for both the x_axis_data parameter and the x_axis_labels parameter.
The default value is [], meaning no labels are drawn below the x-axis.
This parameter is optional.
The default value is 1.
This parameter is optional.
The quotes are just to stop the zero disappearing when POD is converted to HTML.
The lengths of the tick marks below the x-axis is given by the value of the tick_length parameter.
The default value is 1.
This parameter is optional.
Also, these values are drawn on top of (to the right of) the bars. This can be turned off with the x_data_option parameter.
This parameter is optional.
The default value is 1.
This parameter is optional.
The default value is 3, meaning each unit of data in the x-axis direction will occupy 3 pixels horizontally.
This value is used in conjunction with the x_axis_data and x_data parameters.
Eg: In the above code, the x-axis data ranges up to 100 (sic), and the x-axis scaling factor is 3 pixels/unit, so the part of the image occupied by the data will be 3 * 100 + 1 pixels wide. The 1 is for the y-axis.
The 100 comes from max(last value in @$x_axis_data, last value in @$x_data).
This parameter is optional.
The values in this array ref are multiplied by the value of the y_pixels_per_unit parameter, to determine where the y-axis labels and y-axis tick marks are drawn.
The number of elements in this array ref should be the same as the number of elements in the array ref given by the x_data parameter.
Or, if you want the image to look pretty, put one more value into the y_axis_data array ref, as seen in the code above. Do the same with the y_axis_labels parameter - just make the final value in @$y_axis_labels a '' (the empty string).
The default value is [], meaning neither labels nor tick marks will be drawn along the y-axis.
This parameter is optional.
The default value is [], meaning no labels are drawn left of the y-axis.
This parameter is optional.
The default value is 1.
This parameter is optional.
The special value undef means this module calculates an abscissa at which to start writing y-axis labels.
This calculation will only produce a pretty-looking column of y-axis labels when all labels are
the same width in pixels. See sub draw_y_axis_labels()
for the calculation.
The default value is undef.
This parameter is optional.
The quotes are just to stop the zero disappearing when POD is converted to HTML.
The lengths of the tick marks left of the y-axis is given by the value of the tick_length parameter.
The default value is 1.
This parameter is optional.
The default value is 20, meaning each unit of data in the y-axis direction will occupy 20 pixels vertically.
This value is used in conjunction with the y_axis_data parameter.
Eg: In the above code, the y-axis data ranges up to 8, and the y-axis scaling factor is 20 pixels/unit, so the part of the image occupied by the data will be 20 * 8 + 1 pixels high. The 1 is for the x-axis.
The 8 comes from the last value in @$y_axis_data.
Notice how the label corresponding this value of 8 is '', just to make the image pretty by making the area occupied by the data (the framed area) a bit higher.
This parameter is optional.
draw_frame()
Called by method draw()
in Image::Magick::Chart::HorizontalBars
.
These is no need to call this method yourself.
draw_horizontal_bars()
Called by method draw()
in Image::Magick::Chart::HorizontalBars
.
These is no need to call this method yourself.
draw_title()
Called by method draw()
in Image::Magick::Chart::HorizontalBars
.
These is no need to call this method yourself.
draw_x_axis_labels()
Called by method draw()
in Image::Magick::Chart::HorizontalBars
.
These is no need to call this method yourself.
draw_x_axis_ticks()
Called by method draw()
in Image::Magick::Chart::HorizontalBars
.
These is no need to call this method yourself.
draw_y_axis_labels()
Called by method draw()
in Image::Magick::Chart::HorizontalBars
.
These is no need to call this method yourself.
draw_y_axis_ticks()
Called by method draw()
in Image::Magick::Chart::HorizontalBars
.
These is no need to call this method yourself.
new(...)
Returns a object of type Image::Magick::Chart
.
See above, in the section called 'Constructor and initialization' for details.
write()
Called by method draw()
in Image::Magick::Chart::HorizontalBars
.
These is no need to call this method yourself.
Image::Magick::Chart
was written by Ron Savage <ron@savage.net.au> in 2005.
Home page: http://savage.net.au/index.html
Australian copyright (c) 2005, Ron Savage. | |
All Programs of mine are 'OSI Certified Open Source Software'; | |
you can redistribute them and/or modify them under the terms of | |
The Artistic License, a copy of which is available at: | |
http://www.opensource.org/licenses/index.html |
C<Image::Magick::Chart> - Use Image::Magick to create charts. |