cytoscape / cytoscape.js-compound-drag-and-drop

Compound node drag-and-drop UI for adding and removing children
MIT License
33 stars 16 forks source link

cytoscape-compound-drag-and-drop

DOI

Description

Compound node drag-and-drop UI for adding and removing children (demo)

Dependencies

Usage instructions

Download the library:

Import the library as appropriate for your project:

ES import:

import cytoscape from 'cytoscape';
import compoundDragAndDrop from 'cytoscape-compound-drag-and-drop';

cytoscape.use( compoundDragAndDrop );

CommonJS require:

let cytoscape = require('cytoscape');
let compoundDragAndDrop = require('cytoscape-compound-drag-and-drop');

cytoscape.use( compoundDragAndDrop ); // register extension

AMD:

require(['cytoscape', 'cytoscape-compound-drag-and-drop'], function( cytoscape, compoundDragAndDrop ){
  compoundDragAndDrop( cytoscape ); // register extension
});

Plain HTML/JS has the extension registered for you automatically, because no require() is needed.

Definitions

API

Create an instance of the drag-and-drop UI:

const cdnd = cy.compoundDragAndDrop(options);

The options object is outlined below with the default values:

const options = {
  grabbedNode: node => true, // filter function to specify which nodes are valid to grab and drop into other nodes
  dropTarget: (dropTarget, grabbedNode) => true, // filter function to specify which parent nodes are valid drop targets
  dropSibling: (dropSibling, grabbedNode) => true, // filter function to specify which orphan nodes are valid drop siblings
  newParentNode: (grabbedNode, dropSibling) => ({}), // specifies element json for parent nodes added by dropping an orphan node on another orphan (a drop sibling). You can chose to return the dropSibling in which case it becomes the parent node and will be preserved after all its children are removed.
  boundingBoxOptions: { // same as https://js.cytoscape.org/#eles.boundingBox, used when calculating if one node is dragged over another
    includeOverlays: false,
    includeLabels: true
  },
  overThreshold: 10, // make dragging over a drop target easier by expanding the hit area by this amount on all sides
  outThreshold: 10 // make dragging out of a drop target a bit harder by expanding the hit area by this amount on all sides
};

There are a number of functions available on the cdnd object:

cdnd.disable(); // disables the UI

cdnd.enable(); // re-enables the UI

cdnd.destroy(); // removes the UI

Events

These events are emitted by the extension during its gesture cycle.

For these events:

Classes

These classes are applied to nodes during the gesture cycle. You can use them in your stylesheet to customise the look of the nodes during different phases of the gesture.

Caveats

Build targets

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:

  1. Build the extension : npm run build:release
  2. Commit the build : git commit -am "Build for release"
  3. Bump the version number and tag: npm version major|minor|patch
  4. Push to origin: git push && git push --tags
  5. Publish to npm: npm publish .
  6. If publishing to bower for the first time, you'll need to run bower register cytoscape-compound-drag-and-drop https://github.com/cytoscape/cytoscape.js-compound-drag-and-drop.git
  7. Make a new release for Zenodo.