From 22acb8299b99cfdc1cb92e0fc97cabef5e3148a2 Mon Sep 17 00:00:00 2001
From: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Date: Fri, 5 Sep 2014 15:49:56 +0000
Subject: [PATCH] [SIGNED-OFF] Bug 13219: Added color to charts

http://bugs.koha-community.org/show_bug.cgi?id=13219
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
---
 .../prog/en/modules/reports/issues_stats.tt        |    8 +--
 reports/issues_stats.pl                            |   55 +++++++++++++++++++-
 2 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt
index 370c928..72a27af 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt
@@ -304,12 +304,12 @@
     datasets: [
         [% FOREACH loopro IN mainloo.looprow %]{
             label: "[% loopro.rowtitle_display or "UNKNOWN VALUE" |html %]",
-            fillColor: "rgba(151,187,205,0.2)",
-            strokeColor: "rgba(151,187,205,1)",
-            pointColor: "rgba(151,187,205,1)",
+            fillColor: "[% loopro.fill %]",
+            strokeColor: "[% loopro.stroke %]",
+            pointColor: "[% loopro.point %]",
             pointStrokeColor: "#fff",
             pointHighlightFill: "#fff",
-            pointHighlightStroke: "rgba(151,187,205,1)",
+            pointHighlightStroke: "[% loopro.highlight %]",
             data: [[% FOREACH loopcel IN loopro.loopcell %]"[% loopcel.value %]", [% END %]]
         }, [% END %]]
     }, {});
diff --git a/reports/issues_stats.pl b/reports/issues_stats.pl
index 938a835..42e81b7 100755
--- a/reports/issues_stats.pl
+++ b/reports/issues_stats.pl
@@ -172,6 +172,7 @@ sub calculate {
 	my @looprow;
 	my %globalline;
 	my $grantotal =0;
+    my $colors = get_colors();
 # extract parameters
 	my $dbh = C4::Context->dbh;
 
@@ -471,6 +472,7 @@ sub calculate {
 	push @loopcol, {coltitle => "NULL", coltitle_display => 'NULL'} if ($emptycol);
 	push @loopline,{rowtitle => "NULL", rowtitle_display => 'NULL'} if ($emptyrow);
 
+    my $loopcount = 0;
 	foreach my $row (@loopline) {
 		my @loopcell;
 		#@loopcol ensures the order for columns is common with column titles
@@ -484,8 +486,16 @@ sub calculate {
 			'rowtitle_display' => $row->{rowtitle_display},
 			'rowtitle' => $rowtitle,
 			'loopcell' => \@loopcell,
-			'totalrow' => $table{$rowtitle}->{totalrow}
+			'totalrow' => $table{$rowtitle}->{totalrow},
+            'fill' => ${$colors}[$loopcount]->{fill},
+            'stroke' => ${$colors}[$loopcount]->{stroke},
+            'point' => ${$colors}[$loopcount]->{point},
+            'highlight' => ${$colors}[$loopcount]->{highlight},
 		};
+        $loopcount++;
+        if ( $loopcount == '6' ) {
+            $loopcount = '0';
+        }
 	}
 	for my $col ( @loopcol ) {
 		my $total = 0;
@@ -516,4 +526,47 @@ sub null_to_zzempty ($) {
 	return $string;		# else return the valid value
 }
 
+sub get_colors {
+    my $colors = [
+        {
+            fill                => "rgba(151,187,205,0.2)",
+            stroke              => "rgba(151,187,205,1)",
+            point               => "rgba(151,187,205,1)",
+            highlight           => "rgba(151,187,205,1)",
+        },
+        {
+            fill                => "rgba(216,191,216,0.2)",
+            stroke              => "rgba(216,191,216,1)",
+            point               => "rgba(216,191,216,1)",
+            highlight           => "rgba(216,191,216,1)",
+        },
+        {
+            fill                => "rgba(240,128,128,0.2)",
+            stroke              => "rgba(240,128,128,1)",
+            point               => "rgba(240,128,128,1)",
+            highlight           => "rgba(240,128,128,1)",
+        },
+        {
+            fill                => "rgba(240,230,140,0.2)",
+            stroke              => "rgba(240,230,140,1)",
+            point               => "rgba(240,230,140,1)",
+            highlight           => "rgba(240,230,140,1)",
+        },
+        {
+            fill                => "rgba(152,251,152,0.2)",
+            stroke              => "rgba(152,251,152,1)",
+            point               => "rgba(152,251,152,1)",
+            highlight           => "rgba(152,251,152,1)",
+        },
+        {
+            fill                => "rgba(216,191,216,0.2)",
+            stroke              => "rgba(216,191,216,1)",
+            point               => "rgba(216,191,216,1)",
+            highlight           => "rgba(216,191,216,1)",
+        },
+   ];
+
+    return $colors;
+}
+
 1;
-- 
1.7.9.5