尝试在右键单击事件上显示上下文菜单

时间:2019-05-09 21:22:07

标签: events react-graph-vis

我发现自己很着急,因为我试图实现一个事件,该事件在用户右键单击节点或图形边缘时显示上下文菜单。我尝试了不同的方法(使用ref访问诸如getPositions或getNodeAt函数之类的api函数),但似乎没有人能正常工作。这是我正在使用的组件的简化:

export class MainPage extends Component {
constructor(props) {
super(props)

    this.state = {
        graph: {
            nodes: [
                {id: 1, label: "Twitter texts"},
                {id: 2, label: "Reddit comments"},
                {id: 3, label: "Reddit submissions"}
            ],
            edges: []
        },
        options: {
            layout: {
                hierarchical: {
                    levelSeparation: 150,
                    nodeSpacing: 150,
                }
            },
            edges: {
                color: "#000000"
            },
            height: '1000px',
            width: '1300px'
        },
        events: {
            oncontext: this.right_click,
        }
    }
}
right_click = (event) => {
   //show popup...
}
render() {
    return (
                    <div id={"mygraph"}>
                        <Graph
                            graph={this.state.graph}
                            options={this.state.options}
                            events={this.state.events}
                            ref={ref => (this.g = ref)}
                        />;
                    </div>
    )
}
}

我将不胜感激。 问候

0 个答案:

没有答案