Attach buttons to graph elements
3 Comments
Calling plot on a graph returns a GraphPlot object with properties described here: https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.graphplot-properties.html
I would first try setting a ButtonDownFcn on the GraphPlot object, and verify that clicks on and near the graph are recognized appropriately.
Another option is to use a UIContextMenu on the GraphPlot object, with menu items for various operations.
I haven't used a GraphPlot object before, but by my reading of the documentation, there doesn't appear to be a built-in way to distinguish which node/edge was clicked on.
If all else fails, yes, you should be able to turn HitTest off, capture the click by the axes, and do the necessary math to figure out what node or edge was clicked.
In fact, that's the approach I have always used, in professional software I've written in MATLAB, to do any mouse interaction with an object in an axes. I never use the object's ButtonDownFcn because I found it to be insufficient 20 years ago.
Answers (0)
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!