Open johnnyflinn opened 8 years ago
Hey. Do you have any update on this?
Thx for all the work.
Unfortunately not. I've been a bit preoccupied as of late. I imagine I'll address this issue when I move the library to webpack. I was hoping to get started with it here in the next week or so. Sorry.
I believe this can be accomplished by returning the graph ID with each event. Something like...
_this.$rootScope.$broadcast('cy:edge:' + evt.type, evt, id);
Listening would be:
$scope.$on('cy:edge:mouseover', function(ng, cy, id){ //Do Stuff });
While this would accomplish some level of control, what I am actually trying to do is bind specific events to specific charts.
I have a different controller for each graph in the same page. I want the controller to attach the events to the specific chart it controls. What actually happens is that all events that are set in each controller, run together as soon as the event occurs. Hence a 'cy:edge:tap' event that does x in chart xx, is executed with a 'cy:edge:tap' event that does y in chart yy.
You could argue I could put the events in one place and check the id and execute a different line of code, but I would like to bind the event separately in each charts controller.
Let me know if I am making sense. Thanks.
From the angular side of things, I think I would have to broadcast the id. 'cy:edge:tap:graphid'. Your controller would have to listen for that specific id:
$scope.$on("cy:node:click:graphid,...
In the interim, you could always bind directly to the event from the graph instance.
cytoData.getGraph('graphid').then(function(graph){
graph.on('node', 'click', function(evt){
/// do stuff
})
})
When I try to bind the event from the graph instance as you suggested I get The selector click is invalid
edit: I probably get selector invalid because I use Angular's jqLite and on
does not support selectors. I will load jQuery and get back to you.
edit2: Heh! graph.on('node', 'click', function(evt){...
selector and event just needed to be reversed. Talk about being tired :) Will revert with comments as I work on this solution now. Thx.
Worked like a charm with:
graph.on('tap', 'node', function(evt) { // do stuff }
Cheers!
Glad to hear it.
Multi-Graph pages cannot easily identify which event corresponds with which graph without digging through the cy object.