Skip to content

Commit

Permalink
Provided API for 'iVis-at-Bilkent/newt#9'
Browse files Browse the repository at this point in the history
  • Loading branch information
metincansiper committed Mar 13, 2017
1 parent d853166 commit 0af2cc8
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 9 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,15 @@ edge.data('bendPointPositions'); // Bend point positions of an edge. Includes x
## API
ChiSE.js is built at the top of SBGNViz.js and any method exposed by SBGNViz.js is exposed in ChiSE.js as well ([SBGNViz.js API](https://github.com/iVis-at-Bilkent/sbgnviz.js#api)). Other ChiSE.js API is presented below.

`chise.startSpinner(classname)`
Starts a spinner at the middle of network container element. You can specify a css class that the
spinner will have. The default classname is 'default-class'. Requires 'fontawesome.css'.

`chise.endSpinner(classname)`
Ends any spinner having a css class with the given name. Requires 'fontawesome.css'.

`chise.addNode(x, y , nodeclass, id, parent, visibility)`
Adds a new node with the given class and at the given coordinates. Optionally you can set the id, parent and visibility of the node. Considers undoable option.

`chise.addEdge(source, target , edgeclass, id, visibility)`
Adds a new edge with the given class and having the given source and target ids. Optionally you can set the id and visibility of the node. Considers undoable option.

`chise.addProcessWithConvenientEdges(source, target , processType)`
Adds a process with convenient edges. For more information please see 'https://github.com/iVis-at-Bilkent/newt/issues/9'. Considers undoable option.

`chise.cloneElements(eles)`
Clone given elements. Considers undoable option. Requires cytoscape-clipboard extension.

Expand Down Expand Up @@ -168,6 +164,7 @@ General and sbgn specific utilities for cytoscape elements. Extends `sbgnviz.ele
* `defaultProperties` Access the default properties for elements by their classes using this map. These properties are considered in addNode() and addEdge().
* `addNode(x, y, sbgnclass, id, parent, visibility)` Similar to `chise.addNode()` but do not considers undoable option.
* `addEdge(source, target, sbgnclass, id, visibility)` Similar to `chise.addEdge()` but do not considers undoable option.
* `addProcessWithConvenientEdges(source, target, processType)` Similar to `chise.addProcessWithConvenientEdges()` but do not considers undoable option.
* `createCompoundForGivenNodes(nodesToMakeCompound, compoundType)` Similar to `chise.createCompoundForGivenNodes()` but do not considers undoable option.
* `removeCompound(compoundToRemove)` Similar to `chise.removeCompound()` but do not considers undoable option.
* `changeParent(nodes, newParent, posDiffX, posDiffY)` Similar to `chise.changeParent()` but do not considers undoable option.
Expand Down Expand Up @@ -205,7 +202,7 @@ Functions to be utilized in defining new actions for `cytoscape.js-undo-redo` ex
an extension library of chise. Extends `sbgnviz.undoRedoActionFunctions`, you can find the ChiSE extensions for `sbgnviz.undoRedoActionFunctions` below.

* `addNode(param)` Do/Redo function for 'addNode' undo redo command.
* `addEdge(param)` Do/Redo function for 'addEdge' undo redo command.
* `addProcessWithConvenientEdges(param)` Do/Redo function for 'addProcessWithConvenientEdges' undo redo command.
* `createCompoundForGivenNodes(param)` Do/Redo function for 'createCompoundForGivenNodes' undo redo command.
* `removeCompound(param)` Undo function for 'createCompoundForGivenNodes' undo redo command.
* `createTemplateReaction(param)` Do/Redo function for 'createTemplateReaction' undo redo command.
Expand Down
71 changes: 70 additions & 1 deletion chise.js

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions src/utilities/element-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,32 @@ elementUtilities.addEdge = function (source, target, sbgnclass, id, visibility)
return newEdge;
};

elementUtilities.addProcessWithConvenientEdges = function(_source, _target, processType) {
// If source and target IDs are given get the elements by IDs
var source = typeof _source === 'string' ? cy.getElementById(_source) : _source;
var target = typeof _target === 'string' ? cy.getElementById(_target) : _target;

// Process parent should be the closest common ancestor of the source and target nodes
var processParent = cy.collection([source[0], target[0]]).commonAncestors().first();

// Process should be at the middle of the source and target nodes
var x = ( source.position('x') + target.position('x') ) / 2;
var y = ( source.position('y') + target.position('y') ) / 2;

// Create the process with given/calculated variables
var process = elementUtilities.addNode(x, y, processType, undefined, processParent.id());

// Create the edges one is between the process and the source node (which should be a consumption),
// the other one is between the process and the target node (which should be a production).
// For more information please refer to SBGN-PD reference card.
var edgeBtwSrc = elementUtilities.addEdge(source.id(), process.id(), 'consumption');
var edgeBtwTgt = elementUtilities.addEdge(process.id(), target.id(), 'production');

// Create a collection including the elements and to be returned
var collection = cy.collection([process[0], edgeBtwSrc[0], edgeBtwTgt[0]]);
return collection;
};

/*
* This method assumes that param.nodesToMakeCompound contains at least one node
* and all of the nodes including in it have the same parent. It creates a compound fot the given nodes an having the given type.
Expand Down
28 changes: 28 additions & 0 deletions src/utilities/main-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ mainUtilities.addEdge = function(source, target , edgeclass, id, visibility) {
}
};

/*
* Adds a process with convenient edges. For more information please see 'https://github.com/iVis-at-Bilkent/newt/issues/9'.
* Considers undoable option.
*/
mainUtilities.addProcessWithConvenientEdges = function(_source, _target, processType) {
// If source and target IDs are given get the elements by IDs
var source = typeof _source === 'string' ? cy.getElementById(_source) : _source;
var target = typeof _target === 'string' ? cy.getElementById(_target) : _target;

// If source or target does not have an EPN class the operation is not valid
if (!elementUtilities.isEPNClass(source) || !elementUtilities.isEPNClass(target)) {
return;
}

if (!options.undoable) {
return elementUtilities.addProcessWithConvenientEdges(_source, _target, processType);
}
else {
var param = {
source: _source,
target: _target,
processType: processType
};

cy.undoRedo().do("addProcessWithConvenientEdges", param);
}
};

/*
* Clone given elements. Considers undoable option. Requires cytoscape-clipboard extension.
*/
Expand Down
1 change: 1 addition & 0 deletions src/utilities/register-undo-redo-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var registerUndoRedoActions = function (undoableDrag) {
ur.action("addNode", undoRedoActionFunctions.addNode, undoRedoActionFunctions.deleteElesSimple);
ur.action("deleteElesSimple", undoRedoActionFunctions.deleteElesSimple, undoRedoActionFunctions.restoreEles);
ur.action("addEdge", undoRedoActionFunctions.addEdge, undoRedoActionFunctions.deleteElesSimple);
ur.action("addProcessWithConvenientEdges", undoRedoActionFunctions.addProcessWithConvenientEdges, undoRedoActionFunctions.deleteElesSimple);
ur.action("deleteElesSmart", undoRedoActionFunctions.deleteElesSmart, undoRedoActionFunctions.restoreEles);
ur.action("createCompoundForGivenNodes", undoRedoActionFunctions.createCompoundForGivenNodes, undoRedoActionFunctions.removeCompound);

Expand Down
14 changes: 14 additions & 0 deletions src/utilities/undo-redo-action-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ undoRedoActionFunctions.addEdge = function (param) {
};
};

undoRedoActionFunctions.addProcessWithConvenientEdges = function(param) {
var result;
if (param.firstTime) {
result = elementUtilities.addProcessWithConvenientEdges(param.source, param.target, param.processType);
}
else {
result = elementUtilities.restoreEles(param);
}

return {
eles: result
};
};

undoRedoActionFunctions.createCompoundForGivenNodes = function (param) {
var nodesToMakeCompound = param.nodesToMakeCompound;
var newCompound;
Expand Down

0 comments on commit 0af2cc8

Please sign in to comment.