diff --git a/sample-app/sampleapp-components/js/general-action-functions.js b/sample-app/sampleapp-components/js/general-action-functions.js index d02b691..597885c 100644 --- a/sample-app/sampleapp-components/js/general-action-functions.js +++ b/sample-app/sampleapp-components/js/general-action-functions.js @@ -240,6 +240,33 @@ var generalActionFunctions = { } } + return result; + }, + showAndPerformIncrementalLayout: function(param) { + var eles = param.eles; + + var result = {}; + result.positionAndSizes = generalActionFunctions.getNodePositionsAndSizes(); + result.eles = eles.showEles(); + + if(param.positionAndSizes) { + generalActionFunctions.returnToPositionsAndSizes(param.positionAndSizes); + } + else { + triggerIncrementalLayout(); + } + + return result; + }, + undoShowAndPerformIncrementalLayout: function(param) { + var eles = param.eles; + + var result = {}; + result.positionAndSizes = generalActionFunctions.getNodePositionsAndSizes(); + result.eles = eles.hideEles(); + + generalActionFunctions.returnToPositionsAndSizes(param.positionAndSizes); + return result; } }; \ No newline at end of file diff --git a/sample-app/sampleapp-components/js/register-undo-redo-actions.js b/sample-app/sampleapp-components/js/register-undo-redo-actions.js index 250007a..f277b47 100644 --- a/sample-app/sampleapp-components/js/register-undo-redo-actions.js +++ b/sample-app/sampleapp-components/js/register-undo-redo-actions.js @@ -26,6 +26,7 @@ var registerUndoRedoActions = function () { ur.action("changeStyleCss", generalActionFunctions.changeStyleCss, generalActionFunctions.changeStyleCss); ur.action("changeBendPoints", generalActionFunctions.changeBendPoints, generalActionFunctions.changeBendPoints); ur.action("changeFontProperties", generalActionFunctions.changeFontProperties, generalActionFunctions.changeFontProperties); + ur.action("showAndPerformIncrementalLayout", generalActionFunctions.showAndPerformIncrementalLayout, generalActionFunctions.undoShowAndPerformIncrementalLayout); // register SBGN actions ur.action("addStateAndInfo", SBGNActionFunctions.addStateAndInfo, SBGNActionFunctions.removeStateAndInfo); diff --git a/sample-app/sampleapp-components/js/sample-app-cytoscape-sbgn.js b/sample-app/sampleapp-components/js/sample-app-cytoscape-sbgn.js index 68624b2..cb40d7c 100644 --- a/sample-app/sampleapp-components/js/sample-app-cytoscape-sbgn.js +++ b/sample-app/sampleapp-components/js/sample-app-cytoscape-sbgn.js @@ -444,6 +444,26 @@ var SBGNContainer = Backbone.View.extend({ cy.elements().unselect(); cy.elements('[sbgnclass="' + sbgnclass + '"]').select(); } + }, + { + id: 'ctx-menu-show-hidden-neighbours', + title: 'Show Hidden Neighbours', + selector: 'node', + onClickFunction: function (event) { + // TODO move this content to another function (We should find a suitable code base for it) + // and call that function here + var cyTarget = event.cyTarget; + var hiddenNeighbours = sbgnFiltering.getNeighboursOfGivenEles(cyTarget).filter(':hidden'); + if(hiddenNeighbours.length === 0) { + return; + } + + var param = { + eles: hiddenNeighbours + }; + + cy.undoRedo().do("showAndPerformIncrementalLayout", param); + } } ]); diff --git a/sample-app/sampleapp-components/js/sample-app-menu-functions.js b/sample-app/sampleapp-components/js/sample-app-menu-functions.js index 56c3743..9371faf 100644 --- a/sample-app/sampleapp-components/js/sample-app-menu-functions.js +++ b/sample-app/sampleapp-components/js/sample-app-menu-functions.js @@ -93,6 +93,7 @@ var beforePerformLayout = function(){ //A function to trigger incremental layout. Its definition is inside document.ready() var triggerIncrementalLayout; +var triggerIncrementalLayoutAfterExpandCollapse; var getExpandCollapseOptions = function() { return { @@ -329,9 +330,6 @@ $(document).ready(function () { }); triggerIncrementalLayout = function(){ - if(!sbgnStyleRules['rearrange-after-expand-collapse']) { - return; - } beforePerformLayout(); var preferences = { @@ -347,8 +345,16 @@ $(document).ready(function () { sbgnLayoutProp.applyLayout(preferences, false); // layout must not be undoable }; + triggerIncrementalLayoutAfterExpandCollapse = function(){ + if(!sbgnStyleRules['rearrange-after-expand-collapse']) { + return; + } + + triggerIncrementalLayout(); + }; + // set layoutBy option of expand collapse extension - cy.setExpandCollapseOption('layoutBy', triggerIncrementalLayout); + cy.setExpandCollapseOption('layoutBy', triggerIncrementalLayoutAfterExpandCollapse); $("body").on("change", "#file-input", function (e) { if ($("#file-input").val() == "") { diff --git a/src/utilities/sbgn-filtering.js b/src/utilities/sbgn-filtering.js index 4d86ad0..c34e97d 100644 --- a/src/utilities/sbgn-filtering.js +++ b/src/utilities/sbgn-filtering.js @@ -16,18 +16,28 @@ var sbgnFiltering = { getProcessesOfSelected: function(){ var selectedEles = cy.elements(":selected"); - selectedEles = this.expandNodes(selectedEles); - return selectedEles; + return this.getProcessesOfGivenEles(selectedEles); }, getNeighboursOfSelected: function(){ var selectedEles = cy.elements(":selected"); - selectedEles = selectedEles.add(selectedEles.parents("node[sbgnclass='complex']")); - selectedEles = selectedEles.add(selectedEles.descendants()); - var neighborhoodEles = selectedEles.neighborhood(); - var elesToHighlight = selectedEles.add(neighborhoodEles); - elesToHighlight = elesToHighlight.add(elesToHighlight.descendants()); - return elesToHighlight; + return this.getNeighboursOfGivenEles(selectedEles); + }, + + getProcessesOfGivenEles: function(eles){ + var processesOfGivenEles = eles; + processesOfGivenEles = this.expandNodes(processesOfGivenEles); + return processesOfGivenEles; + }, + + getNeighboursOfGivenEles: function(eles){ + var neighbourOfGivenEles = eles; + neighbourOfGivenEles = neighbourOfGivenEles.add(neighbourOfGivenEles.parents("node[sbgnclass='complex']")); + neighbourOfGivenEles = neighbourOfGivenEles.add(neighbourOfGivenEles.descendants()); + var neighborhoodEles = neighbourOfGivenEles.neighborhood(); + var result = neighbourOfGivenEles.add(neighborhoodEles); + result = result.add(result.descendants()); + return result; }, expandNodes: function(nodesToShow){