Git Product home page Git Product logo

Comments (6)

bgrayburn avatar bgrayburn commented on June 1, 2024

sorry didn't mean to close it

from cytoscape.js-cxtmenu.

maxkfranz avatar maxkfranz commented on June 1, 2024

commands can be function( node ){ return [ /* ... */ ]; } so the commands can be dynamic. You don't have to use the selector to differentiate elements: selector could be node, edge and commands() could specify everything.

from cytoscape.js-cxtmenu.

bgrayburn avatar bgrayburn commented on June 1, 2024

I definitely see the use in that and even how it can be used to accomplish this to some extent. But now if I want all the nodes with a certain class to have a cxtmenu but not the others, would I just return an empty array from the commands function for those without the class? What if I want a single node to have a menu and none others, does the command function need to run for each node? Feel free to close this, I understand how to solve my immediate situation given your advice. Thank you for this and this awesome library! Lots of fun to work with.

from cytoscape.js-cxtmenu.

maxkfranz avatar maxkfranz commented on June 1, 2024

You can use both the commands function and a selector if you like.

You can alternatively use enabled per command. This was missed in the readme. This is usually the best solution, because you maintain the user's muscle memory.

from cytoscape.js-cxtmenu.

bgrayburn avatar bgrayburn commented on June 1, 2024

from cytoscape.js-cxtmenu.

mkhoussid avatar mkhoussid commented on June 1, 2024

I just want to point out, that the following code works,

ctxMenuRef.current = cyRef.current.cxtmenu({
     selector: 'node, edge', // or '*'
     commands: (nodeOrEdge) => {
          if (nodeOrEdge.isNode()) {
               // do something with node
          } else if (nodeOrEdge.isEdge()) {
               // do something with edge
          }
     }
})

and this works,

ctxMenuRef.current = cyRef.current.cxtmenu({
     selector: 'core',
     commands: (coreElement) => {
          // do something with core
     }
})

but this does not work,

ctxMenuRef.current = cyRef.current.cxtmenu({
     selector: 'node, edge, core', // <-- core is never triggered in this case
     commands: (nodeOrEdgeOrCore) => { . . . }
})

from cytoscape.js-cxtmenu.

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.