cytoscape-grid-guide
Description
Guideline example | Grid example |
---|
| |
A sophisticated and highly customizable Cytoscape.js extension for grid and guideline interactions, distributed under The MIT License. The following features are provided:
- Grid: Shows a grid in the canvas (with specified size).
- Auto resizing nodes: Nodes are resized to fit perfectly to grid.
- Alignment guidelines on drag: As a node is dragged different types of guidelines are drawn to indicate both horizontal and vertical alignment of the dragged node with others. Two nodes are considered aligned when the difference between their x or y coordinates are within the specified tolerance:
- Reference guidelines: When the dragged node aligns horizontally or vertically with the position of the mouse when the node is picked for drag, this guideline is drawn.
- Geometric guidelines: When the dragged node (center or edge) aligns horizontally or vertically with another node (center or edge) within specified range, this guideline is drawn.
- Distribution guidelines: This type of guideline is drawn in one of these two different cases:
- when the center of the dragged node is in the middle of the closer edges of two other nodes horizontally or vertically (i.e. dragged node is in the middle of two other nodes)
- when the distance between the dragged node A to node C is exactly twice the distance to node B horizontally or vertically (i.e. node B is in the middle of the dragged node A and another node C)
- Snapping nodes: Nodes are snapped either to the grid or alignment location. The following options are available:
- Snap to grid on mouse release: Upon release of the mouse during drag, the node snaps to theclosest grid location.
- Snap to grid during drag: During drag the node snaps to the closest grid location; dragging is discrete.
- Snap to alignment location on mouse release: Note that guidelines are drawn when the node is within a certain 'tolerance' amount to perfect alignment. Upon release of the mouse during drag, the node snaps to shown guideline to form perfect alignment.
- Snap to alignment location during drag: Note that guidelines are drawn when the node is within a certain 'tolerance' amount to perfect alignment. During drag, the node snaps to shown guideline to form perfect alignment.
The users are allowed to customize various things about the functionality including:
- grid size and color
- snap type
- alignment guideline tolerance
- colors and line styles of each type of guidelines
- range of geometric and distribution guidelines (i.e. do not consider nodes that are outside this range for alignment)
- whether or not edge to center alignment should be ignored
- whether to snap nodes to the center of the grid or to the lines of the grid
Please cite the following paper when using this extension:
U. Dogrusoz , A. Karacelik, I. Safarli, H. Balci, L. Dervishi, and M.C. Siper, "Efficient methods and readily customizable libraries for managing complexity of large networks", PLoS ONE, 13(5): e0197238, 2018.
Demo
Click here for demo
API
-
cy.gridGuide(options)
Sets stated options any time wanted.
-
eles.align(horizontal, vertical, alignTo)
Aligns vertically/horizontally dimensions of eles to first element of eles
( or if alignTo is specified aligns to it). horizontal
param may get top
, center
, bottom
and vertical
param may get left
, center
, right
and horizontal
.
For example the code below aligns selected nodes to top left of first selected node.
cy.nodes(":selected").align("top", "left")
Default Undo/Redo Actions
ur.do("align", {
nodes: cy.nodes(":selected"),
vertical: "left",
horizontal: "top",
alignTo: cy.nodes(":selected")[0],
})
Default Options
var options = {
snapToGridOnRelease: true,
snapToGridDuringDrag: false,
snapToAlignmentLocationOnRelease: false,
snapToAlignmentLocationDuringDrag: false,
distributionGuidelines: false,
geometricGuideline: false,
initPosAlignment: false,
centerToEdgeAlignment: false,
resize: false,
parentPadding: false,
drawGrid: true,
gridSpacing: 20,
snapToGridCenter: true,
zoomDash: true,
panGrid: false,
gridStackOrder: -1,
gridColor: '#dedede',
lineWidth: 1.0,
guidelinesStackOrder: 4,
guidelinesTolerance: 2.00,
guidelinesStyle: {
strokeStyle: "#8b7d6b",
geometricGuidelineRange: 400,
range: 100,
minDistRange: 10,
distGuidelineOffset: 10,
horizontalDistColor: "#ff0000",
verticalDistColor: "#00ff00",
initPosAlignmentColor: "#0000ff",
lineDash: [0, 0],
horizontalDistLine: [0, 0],
verticalDistLine: [0, 0],
initPosAlignmentLine: [0, 0],
},
parentSpacing: -1
};
Dependencies
Usage instructions
Download the library:
- via npm:
npm install cytoscape-grid-guide
, - via bower:
bower install cytoscape-grid-guide
, or - via direct download in the repository (probably from a tag).
require()
the library as appropriate for your project:
CommonJS:
var cytoscape = require('cytoscape');
var gridGuide = require('cytoscape-grid-guide');
gridGuide( cytoscape );
AMD:
require(['cytoscape', 'cytoscape-grid-guide'], function( cytoscape, gridGuide ){
gridGuide( cytoscape );
});
Plain HTML/JS has the extension registered for you automatically, because no require()
is needed.
Publishing instructions
This project is set up to automatically be published to npm and bower. To publish:
- Set the version number environment variable:
export VERSION=1.2.3
- Publish:
gulp publish
- If publishing to bower for the first time, you'll need to run
bower register cytoscape-grid-guide https://github.com/iVis-at-Bilkent/cytoscape.js-grid-guide.git
Team