Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exception on registering events to the renderer #134

Closed
ahmetkizilay opened this issue Apr 9, 2015 · 5 comments
Closed

exception on registering events to the renderer #134

ahmetkizilay opened this issue Apr 9, 2015 · 5 comments

Comments

@ahmetkizilay
Copy link
Contributor

I am trying to register an event callback with renderer.on('scale', fn) but vivagraph (0.7.8) throws an exception.

the error is that inside the on method publicEvents.addEventListener is not a defined function. I checked with the inspector and publicEvents does not have that function indeed. In fact, it looks like there is a wrong assignment here for publicEvents, because it seems to contain methods that belong to the graph module.

see the js fiddle here: http://jsfiddle.net/sym6b55k/

public_events

@ahmetkizilay
Copy link
Contributor Author

and patching the code like this seems to work:

    on: function(eventName, callback) {
      // publicEvents.addEventListener(eventName, callback);
      publicEvents.on(eventName, callback);
      return this;
    },

    off: function(eventName, callback) {
      // publicEvents.removeEventListener(eventName, callback);
      publicEvents.off(eventName, callback);
      return this;
    }

@ahmetkizilay
Copy link
Contributor Author

in addition to that fix, we also need to change the following line on renderer.js:

var eventify = require('ngraph.graph');

it should be

var eventify = require('ngraph.events');

https://github.com/anvaka/VivaGraphJS/blob/master/src/View/renderer.js#L9

after this fix, publicEvents object has only three methods on, off, and fire, which makes more sense.

ahmetkizilay added a commit to ahmetkizilay/VivaGraphJS that referenced this issue Apr 9, 2015
…vaka#134

There was a bug with setting the eventify variable on `renderer.js`.
Instead of ngraph.events, the variable is set from the `ngraph.graph`
After this fix, publicEvents object has on and off methods to register
events.

event registration methods for the renderer erroneously uses
`publicEvents.addEventListener` and `publicEvents.removeEventListener`
method. changed the method name to `on` and `off`, respectively.
@anvaka
Copy link
Owner

anvaka commented Apr 9, 2015

Thanks for reporting this and fixing! Do you want to send the pull request?

anvaka added a commit that referenced this issue Apr 9, 2015
fixed wrong js loading for eventify and publicEvents event methods #134
anvaka added a commit that referenced this issue Apr 9, 2015
@anvaka
Copy link
Owner

anvaka commented Apr 9, 2015

Thank you once again for the PR. This is merged and released as v0.7.9

@anvaka anvaka closed this as completed Apr 9, 2015
@gg4u
Copy link

gg4u commented Sep 19, 2018

@ahmetkizilay Could you please explain how eventify worked in your example ?

I tried to registered renderer.on('scroll', fn) But nothing happened.

In your example I tried to see what is passed to the function:

renderer.on('scale', function(e) { console.log(e, renderer) })

it prints the scale value but cannot see where does it take that property from renderer.

My intention is to explore if I can handle events better in SVG, and use only one listener to the renderer / graph container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants