From 35956fdcf0ea392c13355187cc7301f96763fcff Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Thu, 14 Nov 2013 14:52:11 +0000
Subject: [PATCH] BIS-549 SP-1006 : Added support for colors in the UI.

SVN: 30152
---
 .../1/as/webapps/sample-graph/html/index.html |  4 +++
 .../1/as/webapps/sample-graph/html/webapp.js  | 34 +++++++++++++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/deep_sequencing_unit/source/core-plugins/ngs-sample-overview-graph/1/as/webapps/sample-graph/html/index.html b/deep_sequencing_unit/source/core-plugins/ngs-sample-overview-graph/1/as/webapps/sample-graph/html/index.html
index 71687da83af..d5749143d5f 100644
--- a/deep_sequencing_unit/source/core-plugins/ngs-sample-overview-graph/1/as/webapps/sample-graph/html/index.html
+++ b/deep_sequencing_unit/source/core-plugins/ngs-sample-overview-graph/1/as/webapps/sample-graph/html/index.html
@@ -54,6 +54,10 @@
 		        <li class="active"><a id="bottom-up">Bottom Up</a></li>
 		        <li><a id="top-down">Top Down</a></li>
 		      </ul>
+              <ul class="nav">
+                <li class="active"><a id="with-colors">Colors</a></li>
+                <li><a id="no-colors">B&amp;W</a></li>
+              </ul>
 	        </div>
 	      </div>
 	    </div>
diff --git a/deep_sequencing_unit/source/core-plugins/ngs-sample-overview-graph/1/as/webapps/sample-graph/html/webapp.js b/deep_sequencing_unit/source/core-plugins/ngs-sample-overview-graph/1/as/webapps/sample-graph/html/webapp.js
index f6ba20ac71d..c75b3f51949 100644
--- a/deep_sequencing_unit/source/core-plugins/ngs-sample-overview-graph/1/as/webapps/sample-graph/html/webapp.js
+++ b/deep_sequencing_unit/source/core-plugins/ngs-sample-overview-graph/1/as/webapps/sample-graph/html/webapp.js
@@ -33,8 +33,8 @@ var LINE_HEIGHT = 20;
 var FIRST_COLLAPSED_COLUMN = 2;
 
 // The colors used for the different samples. The colors are used when one sample has multiple parents or children to disambiguate.
-//var sampleColors = d3.scale.category10();
-var sampleColors = d3.scale.ordinal().range(['#999']);
+var sampleColors = d3.scale.category10();
+//var sampleColors = d3.scale.ordinal().range(['#999']);
 
 // The color used when the connection between two samples is unambiguous
 var oneToOneColor = "#999"
@@ -274,6 +274,7 @@ function SampleGraphPresenter(model) {
 	this.selectedNode = null;
 	this.didCreateVis = false;
 	this.useBottomUpMode();
+	this.useWithColorsMode();
 	this.initializePresenter();
 }
 
@@ -334,6 +335,16 @@ SampleGraphPresenter.prototype.useTopDownMode = function() {
 	this.calcuateVisibleColumnOffsets();
 };
 
+SampleGraphPresenter.prototype.useWithColorsMode = function() {
+	this.withColorsMode = true;
+	sampleColors = d3.scale.category10();
+};
+
+SampleGraphPresenter.prototype.useNoColorsMode = function() {
+	this.withColorsMode = false;
+	sampleColors = d3.scale.ordinal().range(['#999']);
+};
+
 /**
  * Return a function that gives the outgoing edges for a sample.
  *
@@ -468,6 +479,23 @@ function clickedTopDown() {
 	presenter.draw();
 }
 
+function clickedWithColors() {
+	if (presenter.withColorsMode) return;
+
+	displayActiveMode($('#with-colors'), $('#no-colors'));
+	presenter.useWithColorsMode();
+	presenter.initializeGraphSamples();
+	presenter.draw();
+}
+
+function clickedNoColors() {
+	if (!presenter.withColorsMode) return;
+
+	displayActiveMode($('#no-colors'), $('#with-colors'));
+	presenter.useNoColorsMode();
+	presenter.initializeGraphSamples();
+	presenter.draw();
+}
 
 function textBBoxForGraphNode(node) {
 	var bbox = presenter.renderer.columns.selectAll("text.sample")[node.col][node.visibleIndex].getBBox();
@@ -915,6 +943,8 @@ function enterApp(data)
 {
 	$('#bottom-up').click(clickedBottomUp);
 	$('#top-down').click(clickedTopDown);
+	$('#with-colors').click(clickedWithColors);
+	$('#no-colors').click(clickedNoColors);
 	presenter = new SampleGraphPresenter(model);
 	presenter.useBottomUpMode()
     model.requestGraphData(function() { presenter.initializeGraphSamples(); presenter.draw() });
-- 
GitLab