From b3617d72c2065a272d49d51492c021e67e1638c1 Mon Sep 17 00:00:00 2001 From: cramakri <cramakri> Date: Tue, 17 Apr 2012 20:11:04 +0000 Subject: [PATCH] LMS-2881 Refactored toggleDisplayedVisualizations. SVN: 24941 --- .../source/html/browser/basynthec-browser.js | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/eu_basynthec/source/html/browser/basynthec-browser.js b/eu_basynthec/source/html/browser/basynthec-browser.js index 80080a86e66..945cd892fa0 100644 --- a/eu_basynthec/source/html/browser/basynthec-browser.js +++ b/eu_basynthec/source/html/browser/basynthec-browser.js @@ -53,11 +53,15 @@ StrainWrapper.prototype = new AbstractThingWrapper(); StrainWrapper.prototype.constructor = StrainWrapper; StrainWrapper.prototype.isStrain = function() { return true; } +var presenterModeTypeDataSet = "DATA_SET", presenterModeTypeStrain = "STRAIN"; + /** * An object responsible for managing the view */ function AppPresenter() { this.didCreateVis = false; + this.presenterMode = presenterModeTypeDataSet; + this.visualizationContainers = []; } /** Hides the explanation and shows the element to display the explanation again */ @@ -75,39 +79,47 @@ AppPresenter.prototype.showExplanation = function() { /** Show the data sets grouped by type */ AppPresenter.prototype.switchToDataSetTypeView = function() { + this.presenterMode = presenterModeTypeDataSet; this.hideExplanation(); - this.toggleDisplayedVisualizations(dataSetTypeVis, strainVis); + this.toggleDisplayedVisualizations(dataSetTypeVis); + inspectorView.updateView(); } /** Show the data sets by strain*/ AppPresenter.prototype.switchToStrainView = function() { + this.presenterMode = presenterModeTypeDataSet; this.hideExplanation(); - this.toggleDisplayedVisualizations(strainVis, dataSetTypeVis); + this.toggleDisplayedVisualizations(strainVis); + inspectorView.updateView(); } /** Show the data sets by strains with OD600 data*/ AppPresenter.prototype.switchToOD600View = function() { + this.presenterMode = presenterModeTypeStrain; this.hideExplanation(); - this.toggleDisplayedVisualizations(strainVis, dataSetTypeVis); + this.toggleDisplayedVisualizations(strainVis); + inspectorView.removeAll(250); } /** Utility function to gracefully switch from one visualization to another */ -AppPresenter.prototype.toggleDisplayedVisualizations = function(visToShow, visToHide) +AppPresenter.prototype.toggleDisplayedVisualizations = function(visToShow) { - // TODO: Only include visToShow and hide all other visualizations, since we know what they are - visToShow - .style("display", "inline") - .transition() - .duration(1000) - .style("opacity", 1); - - visToHide - .transition() - .duration(1000) - .style("opacity", 0) - .style("display", "none"); + this.visualizationContainers.forEach(function(vis) { + if (vis == visToShow) { + vis.style("display", "inline") + .transition() + .duration(1000) + .style("opacity", 1); + } else { + vis + .transition() + .duration(1000) + .style("opacity", 0) + .style("display", "none") + } + }); } /** @@ -182,6 +194,8 @@ AppPresenter.prototype.createVis = function() strainVis.style("width", w + "px"); strainView = new StrainView(); + this.visualizationContainers = [dataSetTypeVis, strainVis]; + inspectorView = new InspectorView(); this.didCreateVis = true; @@ -189,7 +203,12 @@ AppPresenter.prototype.createVis = function() AppPresenter.prototype.updateInspectors = function(duration) { - inspectorView.updateView(duration); + if (this.presenterMode == presenterModeTypeDataSet) + { + inspectorView.updateView(duration); + } else { + // Do nothing. + } } /** Download a file referenced in a table. */ @@ -607,6 +626,16 @@ InspectorView.prototype.updateView = function(duration) .remove(); } +/** Removes all nodes from the view, without affecting the model */ +InspectorView.prototype.removeAll = function(duration) +{ + var inspector = inspectors.selectAll("div.inspector").data([]); + inspector.exit().transition() + .duration(duration) + .style("opacity", "0") + .remove(); +} + function dataSetLabel(d) { return d.bis.dataSetTypeCode + " registered on " + timeformat(new Date(d.bis.registrationDetails.registrationDate)); } function downloadTableFile(d) { presenter.downloadTableFile(d) } -- GitLab