Skip to content

Commit

Permalink
Added support for guidelines when moving with arrow keys -- single node
Browse files Browse the repository at this point in the history
  • Loading branch information
kinimesi committed Feb 24, 2017
1 parent 5468735 commit 4f5ad22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
19 changes: 13 additions & 6 deletions cytoscape-grid-guide.js
Original file line number Diff line number Diff line change
Expand Up @@ -1695,16 +1695,18 @@ module.exports = function (cy, snap, resize, discreteDrag, drawGrid, guidelines,
// Guidelines
var activeTopMostNodes = null;
var guidelinesGrabHandler = function(e){
guidelines.lines.destroy();
var nodes = e.cyTarget.selected() ? e.cy.$(":selected") : e.cyTarget;
activeTopMostNodes = guidelines.getTopMostNodes(nodes.nodes());
guidelines.lines.init(activeTopMostNodes);
}
var guidelinesDragHandler = function(){
guidelines.lines.update(activeTopMostNodes);
if (activeTopMostNodes){
guidelines.lines.update(activeTopMostNodes);
}
};
var guidelinesFreeHandler = function(e){
guidelines.lines.destroy();
activeTopMostNodes = null;
guidelines.lines.clear();
};
var guidelinesWindowResizeHandler = function(e){
guidelines.lines.resize();
Expand All @@ -1718,24 +1720,29 @@ module.exports = function (cy, snap, resize, discreteDrag, drawGrid, guidelines,
guidelines.lines.init(activeTopMostNodes);
}
}
var guidelinesUnselectHandler = function(e){
guidelines.lines.clear();
};

function setGuidelines(enable) {
if (enable){
cy.on("tapstart", "node", guidelinesTapHandler);
cy.on("grab", guidelinesGrabHandler);
cy.on("pan", guidelinesPanHandler);
cy.on("drag", guidelinesDragHandler);
cy.on("position", "node", guidelinesDragHandler);
cy.on("free", guidelinesFreeHandler);
cy.on("unselect", "node", guidelinesUnselectHandler);
$(window).on("resize", guidelinesWindowResizeHandler);
}
else{
cy.off("tapstart", "node", guidelinesTapHandler);
cy.off("grab", guidelinesGrabHandler);
cy.off("grab select", guidelinesGrabHandler);
cy.off("pan", guidelinesPanHandler);
cy.off("drag", guidelinesDragHandler);
cy.off("free", guidelinesFreeHandler);
cy.off("unselect", guidelinesUnselectHandler);
$(window).off("resize", guidelinesWindowResizeHandler);
}
// console.log(cy._private.listeners); // <-- to check accumulation
}

// Parent Padding
Expand Down
19 changes: 13 additions & 6 deletions src/events_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,18 @@ module.exports = function (cy, snap, resize, discreteDrag, drawGrid, guidelines,
// Guidelines
var activeTopMostNodes = null;
var guidelinesGrabHandler = function(e){
guidelines.lines.destroy();
var nodes = e.cyTarget.selected() ? e.cy.$(":selected") : e.cyTarget;
activeTopMostNodes = guidelines.getTopMostNodes(nodes.nodes());
guidelines.lines.init(activeTopMostNodes);
}
var guidelinesDragHandler = function(){
guidelines.lines.update(activeTopMostNodes);
if (activeTopMostNodes){
guidelines.lines.update(activeTopMostNodes);
}
};
var guidelinesFreeHandler = function(e){
guidelines.lines.destroy();
activeTopMostNodes = null;
guidelines.lines.clear();
};
var guidelinesWindowResizeHandler = function(e){
guidelines.lines.resize();
Expand All @@ -124,24 +126,29 @@ module.exports = function (cy, snap, resize, discreteDrag, drawGrid, guidelines,
guidelines.lines.init(activeTopMostNodes);
}
}
var guidelinesUnselectHandler = function(e){
guidelines.lines.clear();
};

function setGuidelines(enable) {
if (enable){
cy.on("tapstart", "node", guidelinesTapHandler);
cy.on("grab", guidelinesGrabHandler);
cy.on("pan", guidelinesPanHandler);
cy.on("drag", guidelinesDragHandler);
cy.on("position", "node", guidelinesDragHandler);
cy.on("free", guidelinesFreeHandler);
cy.on("unselect", "node", guidelinesUnselectHandler);
$(window).on("resize", guidelinesWindowResizeHandler);
}
else{
cy.off("tapstart", "node", guidelinesTapHandler);
cy.off("grab", guidelinesGrabHandler);
cy.off("grab select", guidelinesGrabHandler);
cy.off("pan", guidelinesPanHandler);
cy.off("drag", guidelinesDragHandler);
cy.off("free", guidelinesFreeHandler);
cy.off("unselect", guidelinesUnselectHandler);
$(window).off("resize", guidelinesWindowResizeHandler);
}
// console.log(cy._private.listeners); // <-- to check accumulation
}

// Parent Padding
Expand Down

0 comments on commit 4f5ad22

Please sign in to comment.