gpt4 book ai didi

javascript - MxGraph 中节点、边和 Canvas 的自定义(不同)右键菜单

转载 作者:行者123 更新时间:2023-12-02 22:40:33 24 4
gpt4 key购买 nike

我需要在右键单击上下文菜单中提供不同的操作/选项,具体取决于用户是单击节点、边缘还是空白 Canvas 区域。

我一直在研究drawio/jgraph源代码,特别是menus.js文件,以了解右键菜单如何特定于上下文。 Draw.io 应用程序似乎在 Canvas 上与顶点和边上有不同的右键菜单。但是我还没有遇到过区分单击的对象的代码。

对此的任何帮助或指示将不胜感激。

最佳答案

您应该扩展graph.popupMenuHandler.factoryMethod功能,让我给您一个代码示例

graph成为您的图表对象

graph.popupMenuHandler.factoryMethod = function(menu, cell, evt)
{
if(cell.edge){
menu.addItem('First edge option', null, function()
{
alert('This is the first option of edge ');
})
menu.addItem('Second edge option', null, function()
{
alert('This is the second option of edge ');
})
}
if(cell.vertex){
menu.addItem('First vertex option', null, function()
{
alert('This is the first option of vertex ');
})
menu.addItem('Second vertex option', null, function()
{
alert('This is the second option of vertex ');
})
}
}

希望这有帮助:)

关于javascript - MxGraph 中节点、边和 Canvas 的自定义(不同)右键菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58608369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com