Skip to content

Commit

Permalink
Show hidden neighbors #76
Browse files Browse the repository at this point in the history
  • Loading branch information
metincansiper committed Oct 12, 2016
1 parent 91252ef commit 77b18d6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 12 deletions.
27 changes: 27 additions & 0 deletions sample-app/sampleapp-components/js/general-action-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions sample-app/sampleapp-components/js/sample-app-cytoscape-sbgn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
]);

Expand Down
14 changes: 10 additions & 4 deletions sample-app/sampleapp-components/js/sample-app-menu-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -329,9 +330,6 @@ $(document).ready(function () {
});

triggerIncrementalLayout = function(){
if(!sbgnStyleRules['rearrange-after-expand-collapse']) {
return;
}
beforePerformLayout();

var preferences = {
Expand All @@ -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() == "") {
Expand Down
26 changes: 18 additions & 8 deletions src/utilities/sbgn-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit 77b18d6

Please sign in to comment.