cytoscape.js-context-menus
cytoscape.js-context-menus copied to clipboard
Pop up menu appears outside cytoscape network, even when nothing is clicked
Hi, I noticed that my pop up menu appears outside cytoscape network, even when nothing is clicked. May I know how to solve it please?
My code is
<CytoscapeComponent
elements={props.elements}
style={ {
height: sizeHeight + 'px',
cursor: my_cursor
} }
cy={cy => {
cy.on('add', 'node', _evt => {
cy.layout(layout).run()
cy.fit()
setCy(cy)
})
cy.on('mouseover', 'node', (evt) => {
changeCursor('pointer')
//makePopper(evt.target)
});
cy.on('mouseout', 'node', (evt) => {
changeCursor('default')
});
var options = {
// Customize event to bring up the context menu
// Possible options https://js.cytoscape.org/#events/user-input-device-events
evtType: 'cxttap',
// List of initial menu items
// A menu item must have either onClickFunction or submenu or both
menuItems: [
{
content: 'test',
selector: 'node',
onClickFunction: function (evt) {
console.log(evt.target.data('123'))// The function to be executed on click
//console.log('remove element');
},
show: false
},
{
id: 'test',
content: 'test1',
selector: 'node',
coreAsWell: false,
show: true,
onClickFunction: function (evt) {
console.log('test')// The function to be executed on click
//console.log('remove element');
},
}
],
// css classes that menu items will have
menuItemClasses: [
// add class names to this list
],
// css classes that context menu will have
contextMenuClasses: [
// add class names to this list
]
};
cy.contextMenus(options);
}}
Thank you
I observed similar things with an angular app before. It goes away after you click or pan, zoom to the canvas. It might hide the context menu items later with an event. For now, you might try emitting the event manually.
Thanks, how exactly do I do that? May I get a code sample please? Sorry, am very very new to javascript :/
Try cy.zoom(cy.zoom())
it will set the zoom level
Hi I did that but it didnt work. Any other suggestions?
<CytoscapeComponent
elements={props.elements}
style={ {
height: sizeHeight + 'px',
cursor: my_cursor
} }
cy={cy => {
cy.on('add', 'node', _evt => {
cy.layout(layout).run()
cy.fit()
setCy(cy)
})
cy.on('mouseover', 'node', (evt) => {
changeCursor('pointer')
//makePopper(evt.target)
});
cy.on('mouseout', 'node', (evt) => {
changeCursor('default')
});
var options = {
// Customize event to bring up the context menu
// Possible options https://js.cytoscape.org/#events/user-input-device-events
evtType: 'cxttap',
// List of initial menu items
// A menu item must have either onClickFunction or submenu or both
menuItems: [
{
content: 'test',
selector: 'node',
onClickFunction: function (evt) {
console.log(evt.target.data('123'))// The function to be executed on click
//console.log('remove element');
},
show: false
},
{
id: 'test',
content: 'test1',
selector: 'node',
coreAsWell: false,
show: true,
onClickFunction: function (evt) {
console.log('test')// The function to be executed on click
//console.log('remove element');
},
}
],
// css classes that menu items will have
menuItemClasses: [
// add class names to this list
],
// css classes that context menu will have
contextMenuClasses: [
// add class names to this list
]
};
cy.contextMenus(options);
cy.zoom(cy.zoom);
}}
I included your suggestion at the bottom
@jonng1000 You should not write your application logic code in there. Follow some react.js tutorials, read docs about it. I'm not sure maybe it is because of this. Normal I would have put my JS logic inside componentDidMount
@jonng1000 I tried this.cy.pan(this.cy.pan());
it was working
Ok thanks so much for your help! =)