From 02e0858985383228fbd96cd4927156f3f6b07cdb Mon Sep 17 00:00:00 2001
From: Adam Waldenberg <adam.waldenberg@ejwa.se>
Date: Fri, 14 Feb 2014 17:26:26 +0100
Subject: [PATCH] The two generated pie graphs now use the same colors (Fixes
 issue 26).

The same author should have the same color in the two graphs, something
that is more consistent and logical.
---
 gitinspector/blame.py         |  2 +-
 gitinspector/changes.py       |  2 +-
 gitinspector/html/html.header | 15 +++++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/gitinspector/blame.py b/gitinspector/blame.py
index 98956c8..d175aed 100644
--- a/gitinspector/blame.py
+++ b/gitinspector/blame.py
@@ -229,7 +229,7 @@ class BlameOutput(Outputable):
 		blame_xml += "<tfoot><tr> <td colspan=\"5\">&nbsp;</td> </tr></tfoot></tbody></table>"
 		blame_xml += "<div class=\"chart\" id=\"blame_chart\"></div></div>"
 		blame_xml += "<script type=\"text/javascript\">"
-		blame_xml += "    $.plot($(\"#blame_chart\"), [{0}], {{".format(chart_data)
+		blame_xml += "    blame_plot = $.plot($(\"#blame_chart\"), [{0}], {{".format(chart_data)
 		blame_xml += "        series: {"
 		blame_xml += "            pie: {"
 		blame_xml += "                innerRadius: 0.4,"
diff --git a/gitinspector/changes.py b/gitinspector/changes.py
index 5765cc6..2cfe7f5 100644
--- a/gitinspector/changes.py
+++ b/gitinspector/changes.py
@@ -241,7 +241,7 @@ class ChangesOutput(Outputable):
 			changes_xml += ("<tfoot><tr> <td colspan=\"5\">&nbsp;</td> </tr></tfoot></tbody></table>")
 			changes_xml += "<div class=\"chart\" id=\"changes_chart\"></div></div>"
 			changes_xml += "<script type=\"text/javascript\">"
-			changes_xml += "    $.plot($(\"#changes_chart\"), [{0}], {{".format(chart_data)
+			changes_xml += "    changes_plot = $.plot($(\"#changes_chart\"), [{0}], {{".format(chart_data)
 			changes_xml += "        series: {"
 			changes_xml += "            pie: {"
 			changes_xml += "                innerRadius: 0.4,"
diff --git a/gitinspector/html/html.header b/gitinspector/html/html.header
index c2559f9..6036998 100644
--- a/gitinspector/html/html.header
+++ b/gitinspector/html/html.header
@@ -142,6 +142,21 @@
 						this.hoveredElement.removeClass("piehover");
 					}}
 				}});
+
+				// Make sure the two pie charts use the same colors.
+
+				var author_colors = {{}};
+				$.each(changes_plot.getData(), function(i, v) {{
+					author_colors[v["label"]] = v["color"];
+				}});
+
+				$.each(blame_plot.getData(), function(i, v) {{
+					if (author_colors[v["label"]] != undefined) {{
+						v["color"] = author_colors[v["label"]];
+					}}
+				}});
+
+				blame_plot.draw();
 			}});
 		</script>
 		<style type="text/css">