From 48c47be341ea058d8c725bbabd960edd4ba7c25f Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Wed, 12 Dec 2012 13:19:05 +0000
Subject: [PATCH] BIS-229 SP-419 : Added scrolling to clicked element after the
 graph is changed. Implementation could be improved still.

SVN: 27920
---
 .../1/as/webapps/sample-graph/html/webapp.js        | 13 +++++++++++++
 1 file changed, 13 insertions(+)

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 eb15ecd1770..bbe4389eea7 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
@@ -276,6 +276,7 @@ SampleGraphModel.prototype.coalesceGraphData = function(data, callback) {
 function SampleGraphPresenter(model) {
 	this.model = model;
 	this.renderer = new DagreGraphRenderer();
+	this.selectedNode = null;
 	this.didCreateVis = false;
 	this.useBottomUpMode();
 	this.initializePresenter();
@@ -440,6 +441,7 @@ SampleGraphPresenter.prototype.draw = function()
 SampleGraphPresenter.prototype.toggleExpand = function(svgNode, d) {
 	// toggle visiblity
 	d.userEdgesVisible = (null == d.userEdgesVisible) ? !d.edgesVisible :!d.userEdgesVisible;
+	this.selectedNode = svgNode.parentNode;
 	this.draw();
 }
 
@@ -736,6 +738,17 @@ DagreGraphRenderer.prototype.draw = function()
 	// Resize the visualization
 	viz.attr("width", vizWidth + 20); // add space for the ring at the end
 	viz.attr("height", vizHeight + LINE_HEIGHT); // add a space to make it look less cramped
+
+	// If the user clicked on a node, scroll to make it visible
+	if (presenter.selectedNode) {
+		var root = $("#root");
+		var left = $(presenter.selectedNode).position().left + root.scrollLeft() - 50;
+		root.scrollLeft(left);
+
+		// WebKit only
+		// presenter.selectedNode.scrollIntoViewIfNeeded(true);
+
+	}
 }
 
 /**
-- 
GitLab