cytoscape-automove
Description
An extension for Cytoscape.js that automatically updates node positions based on specified rules (demo)
Common usecases:
- Making one node move in step with another node
- Constraining a node within a boundary
- Using a node to represent an n-ary interaction
Dependencies
Usage instructions
Download the library:
- via npm:
npm install cytoscape-automove
, - via bower:
bower install cytoscape-automove
, or - via direct download in the repository (probably from a tag).
Import the library as appropriate for your project:
ES import:
import cytoscape from 'cytoscape';
import automove from 'cytoscape-automove';
cytoscape.use( automove );
CommonJS require:
let cytoscape = require('cytoscape');
let automove = require('cytoscape-automove');
cytoscape.use( automove );
AMD:
require(['cytoscape', 'cytoscape-automove'], function( cytoscape, automove ){
automove( cytoscape );
});
Plain HTML/JS has the extension registered for you automatically, because no require()
is needed.
API
Each time cy.automove()
is called, the specified rules are added to the core instance:
let defaults = {
nodesMatching: function( node ){ return false; },
reposition: 'mean',
when: undefined,
meanIgnores: function( node ){ return false; },
meanOnSelfPosition: function( node ){ return true; },
dragWith: function( node ){ return false; }
};
let options = defaults;
let rule = cy.automove( options );
A rule has a number of functions available:
rule.apply();
rule.enabled();
rule.toggle();
rule.disable();
rule.enable();
rule.destroy();
You can also remove all the rules you previously specified:
cy.automove('destroy');
Events
automove
: Emitted on a node when its position is changed by a rule
node.on('automove', function( event, rule ){})
Build targets
npm run test
: Run Mocha tests in ./test
npm run build
: Build ./src/**
into cytoscape-automove.js
npm run watch
: Automatically build on changes with live reloading (N.b. you must already have an HTTP server running)npm run dev
: Automatically build on changes with live reloading with webpack dev servernpm run lint
: Run eslint on the source
N.b. all builds use babel, so modern ES features can be used in the src
.
Publishing instructions
This project is set up to automatically be published to npm and bower. To publish:
- Build the extension :
npm run build:release
- Commit the build :
git commit -am "Build for release"
- Bump the version number and tag:
npm version major|minor|patch
- Push to origin:
git push && git push --tags
- Publish to npm:
npm publish .
- If publishing to bower for the first time, you'll need to run
bower register cytoscape-automove https://github.com/cytoscape/cytoscape.js-automove.git
- Make a new release for Zenodo.