NAME
Venn::Chart - Create a Venn diagram using GD.
SYNOPSIS
#!/usr/bin/perl
use warnings;
use Carp;
use strict;
use Venn::Chart;
# Create the Venn::Chart constructor
my $VennChart = new Venn::Chart( 400, 400 ) or die("error : $!");
# Set a title and a legend for our chart
$VennChart->set( -title => 'Venn diagram' );
$VennChart->set_legends( 'Team 1', 'Team 2', 'Team 3' );
# 3 lists for the Venn diagram
my @Team1 = qw/abel edward momo albert jack julien chris/;
my @Team2 = qw/edward isabel antonio delta albert kevin jake/;
my @Team3 = qw/gerald jake kevin lucia john edward/;
# Create a diagram with gd object
my $gd_venn = $VennChart->plot( \@Team1, \@Team2, \@Team3 );
# Create a Venn diagram image in png, gif and jpeg format
open( my $fh_venn, '>', "VennChart.png" );
binmode $fh_venn;
print {$fh_venn} $gd_venn->png;
close($fh_venn);
# Create an histogram image of Venn diagram (png, gif and jpeg format).
my $gd_histogram = $VennChart->plot_histogram;
open( my $fh_histo, '>', "VennHistogram.png" );
binmode $fh_histo;
print {$fh_histo} $gd_histogram->png;
close($fh_histo);
DESCRIPTION
Venn::Chart create a Venn diagram image using GD module with 2 or 3 data lists. A title and a legend can be added in the chart. It is possible to create an histogram chart with the different data regions of Venn diagram using GD::Graph module.
CONSTRUCTOR/METHODS
new
This constructor allows you to create a new Venn::Chart object.
$VennChart = new Venn::Chart($width, $height)
The new() method is the main constructor for the Venn::Chart module. It creates a new blank image of the specified width and height.
# Create Venn::Chart constructor
my $VennChart = new Venn::Chart( 400, 400 );
The default width and height size are 500 pixels.
set
Set the image title and colors of the diagrams.
$VennChart->set( -attrib => value, ... )
- -colors => array reference
-
Specifies the RGBA colors of the 2 or 3 lists. This allocates a color with the specified red, green, and blue components, plus the specified alpha channel for each circle. The alpha value may range from 0 (opaque) to 127 (transparent). The alphaBlending function changes the way this alpha channel affects the resulting image.
-colors => [ [ 98, 66, 238, 0 ], [ 98, 211, 124, 0 ], [ 110, 205, 225, 0 ] ],
Default : [ [ 189, 66, 238, 0 ], [ 255, 133, 0, 0 ], [ 0, 107, 44, 0 ] ]
$VennChart->set(
-title => 'Venn diagram',
-colors => [ [ 98, 66, 238, 0 ], [ 98, 211, 124, 0 ], [ 110, 205, 225, 0 ] ],
);
set_legends
Set the image legends. This method set a legend which represents the title of each 2 or 3 diagrams (circles).
$VennChart->set_legends( legend1, legend2, legend3 )
# Set title and a legend for our chart
$VennChart->set_legends('Diagram1', 'Diagram2', 'Diagram3');
plot
Plots the chart, and returns the GD::Image object.
$VennChart->plot( array reference list )
my $gd = $VennChart->plot(\@list1, \@list2, \@list3);
To create your image, do whatever your current version of GD allows you to do to save the file. For example:
open(IMAGE, '>', 'venn.png') or die("Error : $!");
binmode IMAGE;
print IMAGE $gd->png;
close IMAGE;
get_list_regions
Get a list of array reference which contains data for each intersection or unique region between the 2 or 3 lists.
$VennChart->get_list_regions()
- Case : 2 lists
-
my $gd_venn = $VennChart->plot( \@Team1, \@Team2 ); my @ref_lists = $VennChart->get_list_regions();
@ref_lists will contain 3 array references.
@{$ref_lists}[0] => unique elements of @Team1 between @Team1 and @Team2 @{$ref_lists}[1] => unique elements of @Team2 between @Team1 and @Team2 @{$ref_lists}[2] => intersection elements between @Team1 and @Team2
- Case : 3 lists
-
my $gd_venn = $VennChart->plot( \@Team1, \@Team2, \@Team3 ); my @ref_lists = $VennChart->get_list_regions();
@ref_lists will contain 7 array references.
@{$ref_lists}[0] => unique elements of @Team1 between @Team1, @Team2 and @Team3 @{$ref_lists}[1] => unique elements of @Team2 between @Team1, @Team2 and @Team3 @{$ref_lists}[2] => intersection elements between @Team1 and @Team2 @{$ref_lists}[3] => unique elements of @Team3 between @Team1, @Team2 and @Team3 @{$ref_lists}[4] => intersection elements between @Team3 and @Team1 @{$ref_lists}[5] => intersection elements between @Team3 and @Team2 @{$ref_lists}[6] => intersection elements between @Team1, @Team2 and @Team3
Example :
my @Team1 = qw/abel edward momo albert jack julien chris/;
my @Team2 = qw/edward isabel antonio delta albert kevin jake/;
my @Team3 = qw/gerald jake kevin lucia john edward/;
my $gd_venn = $VennChart->plot( \@Team1, \@Team2, \@Team3 );
my @lists = $VennChart->get_list_regions();
Result of @lists
[ 'jack', 'momo', 'chris', 'abel', 'julien' ], # Unique of @Team1
[ 'delta', 'isabel', 'antonio' ], # Unique of @Team2
[ 'albert' ], # Intersection between @Team1 and @Team2
[ 'john', 'gerald', 'lucia' ], # Unique of @Team3
[], # Intersection between @Team3 and @Team1
[ 'jake', 'kevin' ], # Intersection between @Team3 and @Team2
[ 'edward' ] # Intersection between @Team1, @Team2 and @Team3
get_regions
Get an array displaying the object number of each region of the Venn diagram.
$VennChart->get_regions()
my $gd_venn = $VennChart->plot( \@Team1, \@Team2, \@Team3 );
my @regions = $VennChart->get_regions;
@regions contains 5, 3, 1, 3, 0, 2, 1
get_colors_regions
Get an array contains the colors (in an array reference) used for each region in Venn diagram.
$VennChart->get_colors_regions()
my @colors_regions = $VennChart->get_colors_regions;
@colors_regions = (
[R, G, B, A], [R, G, B, A], [R, G, B, A],
[R, G, B, A], [R, G, B, A], [R, G, B, A],
[R, G, B, A]
);
@{$colors_regions}[0] => color of @{$ref_lists}[0]
@{$colors_regions}[1] => color of @{$ref_lists}[1]
@{$colors_regions}[2] => color of @{$ref_lists}[2]
@{$colors_regions}[3] => color of @{$ref_lists}[3]
@{$colors_regions}[4] => color of @{$ref_lists}[4]
@{$colors_regions}[5] => color of @{$ref_lists}[5]
@{$colors_regions}[6] => color of @{$ref_lists}[6]
plot_histogram
Plots an histogram displaying each region of the Venn diagram which returns the GD::Image object.
$VennChart->plot_histogram
To create the histogram, the Venn diagram have to be already created.
# Create histogram of Venn diagram image in png, gif and jpeg format
my $gd_histogram = $VennChart->plot_histogram;
open(HISTO, '>', 'VennHistogram.png') or die("Error : $!");
binmode HISTO;
print HISTO $gd_histogram->png;
close HISTO;
If you want to create and design the histogram yourself, use GD::Graph module and play with data obtained with "get_regions" methods.
AUTHOR
Djibril Ousmanou, <djibel at cpan.org>
BUGS
Please report any bugs or feature requests to bug-venn-chart at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Venn-Chart. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SEE ALSO
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Venn::Chart
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
LICENSE AND COPYRIGHT
Copyright 2010 Djibril Ousmanou.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.