Adding the first part of the graphing POD and changed the drawLabel function to have a saner api

This commit is contained in:
Martin Kamerbeek 2006-05-02 14:48:42 +00:00
parent c7e5d5ee24
commit a4254f51b4
6 changed files with 916 additions and 46 deletions

View file

@ -9,6 +9,13 @@ use Data::Dumper;
our @ISA = qw(WebGUI::Image::Graph::XYGraph);
#-------------------------------------------------------------------
=head1 configurationForm
Creates the configuration form for this plugin. See WebGUI::Image::Graph for
more information.
=cut
sub configurationForm {
my $self = shift;
@ -34,6 +41,26 @@ my $f = WebGUI::HTMLForm->new($self->session);
}
#-------------------------------------------------------------------
=head1 drawBar ( bar, location, barWidth )
Draws a bar defined by bar and with width barWidth at location.
=head2 bar
A hashref defining the bar. Must contain keys 'height', 'strokeColor' and
'fillColor'.
=head2 location
A hashref containing the location of the bottom-left corner of the bar. Keys 'x'
and 'y' must specify the x- and y-coordinates respectively.
=head2 barWidth
The width of the bar in pixels.
=cut
sub drawBar {
my $self = shift;
my $bar = shift;
@ -55,6 +82,12 @@ sub drawBar {
}
#-------------------------------------------------------------------
=head1 drawGraph
Draws all the bars.
=cut
sub drawGraph {
my ($currentBar, %location);
my $self = shift;
@ -82,6 +115,26 @@ sub drawGraph {
}
#-------------------------------------------------------------------
=head1 drawSideBySide ( bars, location, barWidth )
Draws the bars in side by side mode. Meaning that per datsetindex the bars
representing a single dataset are grouped.
=head2 bars
An arrayref containing all the bar description hashrefs as described in drawBar.
=head2 location
Hashref containing the initial coordinates of the lower-left corner of the
chart. Pass coords in keys 'x' and 'y'.
=head2 barWidth
The width of each bar in pixels.
=cut
sub drawSideBySideBar {
my $self = shift;
my $bars = shift;
@ -97,6 +150,28 @@ sub drawSideBySideBar {
}
#-------------------------------------------------------------------
=head1 drawStacked ( bars, location, barWidth )
Draws the bars in side by side mode. Meaning that per datset-index the bars
representing a single dataset are stacked on top of each other.
=head2 bars
An arrayref containing all the bar description hashrefs as described in drawBar.
=head2 location
Hashref containing the initial coordinates of the lower-left corner of the
chart. Pass coords in keys 'x' and 'y'.
=head2 barWidth
The width of each bar in pixels.
=cut
sub drawStackedBar {
my $self = shift;
my $bars = shift;
@ -112,6 +187,13 @@ sub drawStackedBar {
}
#-------------------------------------------------------------------
=head1 formNamespace
Returns the form namespace of this plugin. See WegBUI::Image::Graph for
more elaborate information.
=cut
sub formNamespace {
my $self = shift;
@ -119,6 +201,13 @@ sub formNamespace {
}
#-------------------------------------------------------------------
=head1 getAnchorSpacing
Returns the distance in pixels between two anchors on the x axis that define teh
placement of bars and labels.
=cut
sub getAnchorSpacing {
my $self = shift;
@ -133,6 +222,12 @@ sub getAnchorSpacing {
}
#-------------------------------------------------------------------
=head1 getBarSpacing
Returns the width of the gap between two bars within a group in pixels.
=cut
sub getBarSpacing {
my $self = shift;
@ -140,6 +235,13 @@ sub getBarSpacing {
}
#-------------------------------------------------------------------
=head1 getConfiguration
Returns the configuration hashref for this plugin. Refer to WebGUI::IMage::Graph
for a more detailed description.
=cut
sub getConfiguration {
my $self = shift;
@ -152,6 +254,12 @@ sub getConfiguration {
}
#-------------------------------------------------------------------
=head1 getGroupSpacing
Returns the width of the gap between two groups of bars in pixels.
=cut
sub getGroupSpacing {
my $self = shift;
@ -159,6 +267,13 @@ sub getGroupSpacing {
}
#-------------------------------------------------------------------
=head1 getFirstAnchorLocation
Returns a hashref containing the location of the leftmost x-axis anchor.
Location coordinates are encoded in keys 'x' and 'y'.
=cut
sub getFirstAnchorLocation {
my $self = shift;
@ -169,6 +284,12 @@ sub getFirstAnchorLocation {
}
#-------------------------------------------------------------------
=head1 processDataset
Processes the dataset. Used by drawGraph.
=cut
sub processDataSet {
my ($barProperties);
my $self = shift;
@ -192,6 +313,16 @@ sub processDataSet {
}
#-------------------------------------------------------------------
=head1 setBarSpacing ( gap )
Sets the distance between two bars in a group in pixels.
=head2 gap
The distance in pixels.
=cut
sub setBarSpacing {
my $self = shift;
my $gap = shift;
@ -200,6 +331,17 @@ sub setBarSpacing {
}
#-------------------------------------------------------------------
=head1 setConfiguration ( config )
Applies the given configuration hash to this plugin. See WebGUI::Image::Graph
for more info.
=head2 config
The configuration hash.
=cut
sub setConfiguration {
my $self = shift;
my $config = shift;
@ -213,6 +355,16 @@ sub setConfiguration {
}
#-------------------------------------------------------------------
=head1 setGroupSpacing ( gap )
Sets the distance between two groups of bars in pixels.
=head2 gap
The distance in pixels.
=cut
sub setGroupSpacing {
my $self = shift;
my $gap = shift;

View file

@ -9,6 +9,12 @@ use Data::Dumper;
our @ISA = qw(WebGUI::Image::Graph::XYGraph);
#-------------------------------------------------------------------
=head1 drawGraph
Draws all the lines.
=cut
sub drawGraph {
my ($currentBar, %location);
my $self = shift;
@ -27,6 +33,28 @@ sub drawGraph {
}
#-------------------------------------------------------------------
=head1 drawLine ( line, location, interval )
Draws a bar defined by bar and with width barWidth at location.
=head2 line
A hashref defining the line. Must contain keys 'strokeColor' and
'dataset', the latter one being an arrayref containing all points of the line.
=head2 location
A hashref containing the location of the bottom-left corner of the line's
origin. Keys 'x' and 'y' must specify the x- and y-coordinates respectively.
=head2 interval
The distance between x-axis anchors in pixels.
=cut
sub drawLine {
my $self = shift;
my $line = shift;
@ -54,6 +82,13 @@ sub drawLine {
}
#-------------------------------------------------------------------
=head1 formNamespace
Returns the form namespace of this plugin. See WegBUI::Image::Graph for
more elaborate information.
=cut
sub formNamespace {
my $self = shift;
@ -61,6 +96,13 @@ sub formNamespace {
}
#-------------------------------------------------------------------
=head1 getAnchorSpacing
Returns the distance in pixels between two anchors on the x axis that define teh
placement of bars and labels.
=cut
sub getAnchorSpacing {
my $self = shift;
@ -75,6 +117,13 @@ sub getAnchorSpacing {
}
#-------------------------------------------------------------------
=head1 getFirstAnchorLocation
Returns a hashref containing the location of the leftmost x-axis anchor.
Location coordinates are encoded in keys 'x' and 'y'.
=cut
sub getFirstAnchorLocation {
my $self = shift;
@ -84,15 +133,17 @@ sub getFirstAnchorLocation {
}
}
# palette nog laten werken!
#-------------------------------------------------------------------
=head1 processDataset
Processes the dataset. Used by drawGraph.
=cut
sub processDataSet {
my ($barProperties);
my $self = shift;
# my $maxElements = List::Util::max(map {scalar @$_} @{$self->{_datasets}});
# my $numberOfDatasets = scalar @{$self->{_datasets}};
my $palette = $self->getPalette;
foreach (@{$self->{_datasets}}) {
push (@{$self->{_lines}}, {