From e6eb07565b60ef938dfbb42a28a31cdd0f69b6d5 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 10 Oct 2007 19:00:38 +0000 Subject: [PATCH] Colors in bar graph now cycle through the palette like pie chart. - fix: Graphing with Graphics Magick Bungled ( fixed line and bar problems, not pie problems) --- docs/changelog/7.x.x.txt | 3 +++ lib/WebGUI/Image/Graph/XYGraph.pm | 29 ++++++++++++++++++--------- lib/WebGUI/Image/Graph/XYGraph/Bar.pm | 13 ++++++++---- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 4101b2f85..0a9427412 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -4,6 +4,9 @@ - Clean up orphaned grouping - fix: purging old asset revisions on large sites never completes - fix: Can't add assets when not using preload.perl. + - Colors in bar graph now cycle through the palette like pie chart. + - fix: Graphing with Graphics Magick Bungled ( fixed line and bar problems, + not pie problems) - fix: wiki recent - fix: Dashboard content positioning field problem - fix: graphing doesn't work with GraphicsMagick diff --git a/lib/WebGUI/Image/Graph/XYGraph.pm b/lib/WebGUI/Image/Graph/XYGraph.pm index ceb7997f7..e56d27c2d 100644 --- a/lib/WebGUI/Image/Graph/XYGraph.pm +++ b/lib/WebGUI/Image/Graph/XYGraph.pm @@ -172,33 +172,31 @@ sub drawLabels { my $self = shift; my $location = shift; - my %anchorPoint = %{$self->getFirstAnchorLocation};# %$location; + my %anchorPoint = %{$self->getFirstAnchorLocation}; # Draw x-axis labels - foreach (@{$self->getLabel}) { - my $text = $self->wrapLabelToWidth($_, $self->getAnchorSpacing->{x}); + foreach my $text (@{$self->getLabel}) { $self->drawLabel($text, ( - alignHorizontal => 'center', alignVertical => 'top', - align => 'Center', + align => 'left', + rotate => 90, x => $anchorPoint{x}, y => $anchorPoint{y}, )); - $anchorPoint{x} += $self->getAnchorSpacing->{x}; #$groupWidth + $self->getGroupSpacing; + $anchorPoint{x} += $self->getAnchorSpacing->{x}; $anchorPoint{y} += $self->getAnchorSpacing->{y}; } # Draw y-axis labels $anchorPoint{x} = $self->getChartOffset->{x} - $self->getLabelOffset; $anchorPoint{y} = $self->getChartOffset->{y} + $self->getChartHeight; -# for (1 .. $self->getYRange / $self->getYGranularity) { foreach (@{$self->getYLabels}) { $self->drawLabel($_, ( alignHorizontal => 'right', alignVertical => 'center', - x => $anchorPoint{x}, #$self->getChartOffset->{x} - $self->getLabelOffset, - y => $anchorPoint{y}, #$self->getChartOffset->{y} + $self->getChartHeight - $self->getPixelsPerUnit * $_*$self->getYGranularity, + x => $anchorPoint{x}, + y => $anchorPoint{y}, )); $anchorPoint{y} -= $self->getPixelsPerUnit * $self->getYGranularity } @@ -244,6 +242,19 @@ sub formNamespace { return $self->SUPER::formNamespace.'_XYGraph'; } +#------------------------------------------------------------------- + +=head2 getAnchorSpacing () + +This method MUST be overridden by all sub classes. + +=cut + +sub getAnchorSpacing { + die "You were supposed to override this method in the sub class."; +} + + #------------------------------------------------------------------- =head2 getAxisColor ( ) diff --git a/lib/WebGUI/Image/Graph/XYGraph/Bar.pm b/lib/WebGUI/Image/Graph/XYGraph/Bar.pm index 6b67c62bd..4c0e69a7a 100644 --- a/lib/WebGUI/Image/Graph/XYGraph/Bar.pm +++ b/lib/WebGUI/Image/Graph/XYGraph/Bar.pm @@ -4,6 +4,7 @@ use strict; use WebGUI::Image::Graph::XYGraph; use List::Util; use POSIX; +use WebGUI::Utility; our @ISA = qw(WebGUI::Image::Graph::XYGraph); @@ -250,7 +251,7 @@ sub getAnchorSpacing { my $numberOfGroups = List::Util::max(map {scalar @$_} @{$self->getDataset}); - my $spacing = ($self->getChartWidth - ($numberOfGroups-1) * $self->getGroupSpacing) / $numberOfGroups + $self->getGroupSpacing; + my $spacing = round(($self->getChartWidth - ($numberOfGroups-1) * $self->getGroupSpacing) / $numberOfGroups + $self->getGroupSpacing); return { x => $spacing, @@ -319,7 +320,7 @@ sub getFirstAnchorLocation { my $self = shift; return { - x => $self->getChartOffset->{x} + ($self->getAnchorSpacing->{x} - $self->getGroupSpacing) / 2, + x => round($self->getChartOffset->{x} + ($self->getAnchorSpacing->{x} - $self->getGroupSpacing) / 2), y => $self->getChartOffset->{y} + $self->getChartHeight } } @@ -344,10 +345,14 @@ sub processDataSet { for my $currentElement (0 .. $maxElements-1) { my @thisSet = (); for my $currentDataset (0 .. $numberOfDatasets - 1) { + my $color = $palette->getColor($currentDataset); + if ($numberOfDatasets == 1) { + $color = $palette->getNextColor; + } push(@thisSet, { height => $self->{_datasets}->[$currentDataset]->[$currentElement] || 0, - fillColor => $palette->getColor($currentDataset)->getFillColor, - strokeColor => $palette->getColor($currentDataset)->getStrokeColor, + fillColor => $color->getFillColor, + strokeColor => $color->getStrokeColor, }); } push(@{$self->{_bars}}, [ @thisSet ]);