Giter VIP home page Giter VIP logo

Comments (2)

maxkfranz avatar maxkfranz commented on May 24, 2024

The events are somewhat analogous to mousedown-mouseup-click: boxstart-boxend-box.

You can track all of the elements that are in a box gesture by keeping a list similar to your example:

const GROUP_THRESHOLD = 100; // time delta that separates one box gesture from another

let boxed = cy.collection();

const sendData = eles => {
  let elsData = eles.map(el => el.data());

  // send the array of data json objs somewhere; just log for now...
  console.log(elsData);
};

const checkGroup = _.debounce(() => {
  sendData(boxed);

  boxed = cy.collection();
}, GROUP_THRESHOLD); // events must be at least this duration apart to make a separate group

const addToBoxed = el => {
  boxed.merge(el);

  checkGroup();
};

cy.on('box', e => { // or 'boxselect'
  const el = e.target;

  addToBoxed(el);
});

I've considered having native support in the core lib for getting a group of enclosed elements at once from a box gesture. The only solution I've seen that could work well for that is to allow for e.target to have more than one element. This would also work for other gestures, and this would generally reduce the number of event objects created for group events. However, this approach is inconsistent with how listeners work in most systems --- e.g. the DOM. It would also be a breaking API change.

So, the pattern posted above works for now.

from react-cytoscapejs.

xhluca avatar xhluca commented on May 24, 2024

Thank you Max! This works perfectly, I'll keep an eye out for changes on the API in case native support is added.

from react-cytoscapejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.