johnnyflinn / ngCytoscape

Angular directive for cytoscape.js
http://johnnyflinn.github.io/ngCytoscape
MIT License
17 stars 18 forks source link

events need to specify which graph they belong to #6

Open johnnyflinn opened 8 years ago

johnnyflinn commented 8 years ago

Multi-Graph pages cannot easily identify which event corresponds with which graph without digging through the cy object.

jkourou commented 8 years ago

Hey. Do you have any update on this?

Thx for all the work.

johnnyflinn commented 8 years ago

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.

johnnyflinn commented 8 years ago

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 });

jkourou commented 8 years ago

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.

johnnyflinn commented 8 years ago

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
    })
})
jkourou commented 8 years ago

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.

jkourou commented 8 years ago

Worked like a charm with: graph.on('tap', 'node', function(evt) { // do stuff }

Cheers!

johnnyflinn commented 8 years ago

Glad to hear it.