Skip to content
This repository was archived by the owner on Jul 29, 2019. It is now read-only.

Click event reports an error #2102

Closed
ghost opened this issue Sep 19, 2016 · 5 comments
Closed

Click event reports an error #2102

ghost opened this issue Sep 19, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 19, 2016

I created an event that fires when the user clicks on the graph2d object.

Example:

   function onGraphChange ()
   {
      delayRenderUpdate = RENDER_STEP_SIZE*4;
   }
   graph2d.on('click',onGraphChange);

When it fires in the browser, I see the following error traceback:

DataAxis.screenToValue @ vis.js:26773
Graph2d.getEventProperties @ vis.js:25293
(anonymous function) @ vis.js:25090
etc.

Digging into the code, this corresponds to:

  DataAxis.prototype.screenToValue = function (x) {
    return this.scale.screenToValue(x); // problem is on this line
  };

I just started using vis.js today, so I'm not sure what is intended here.

UPDATE:
Just discovered this happens regardless of whether I have an event defined or not. I deleted the event, reloaded (CTRL+F5) the view, and clicked on the graph2d. Same problem.

@mojoaxel
Copy link
Member

@tescott Can you please provide a simple example (e.g. on jsbin) that shows when the problem occurs. Thx!

@ghost
Copy link
Author

ghost commented Sep 19, 2016

Sure thing! Here's an example: http://jsbin.com/qayajuzeza/1/edit?html,output

I'm using Chrome. I hit F12 to bring up the Dev Tools. Click anywhere on the graph and you'll see the error appear in the Dev Tools console.

@ghost
Copy link
Author

ghost commented Sep 20, 2016

I'm wondering if this is due to no data being present. If I have a Graph2d that has some data points, I don't get the error when I click on the graph.

@mojoaxel
Copy link
Member

I can confirm this! http://jsbin.com/nizehoj/1/edit?html,output

@mojoaxel mojoaxel added this to the v4.17 milestone Sep 20, 2016
@mojoaxel mojoaxel removed this from the Minor Release v4.17 milestone Nov 5, 2016
@Tooa
Copy link
Member

Tooa commented Dec 16, 2016

The problem is that this.scale is undefined. The value is initialized here and receives a value here.

I'm wondering if this is due to no data being present. If I have a Graph2d that has some data points, I don't get the error when I click on the graph.

This means that the _redrawLabels (which sets the scale) is only called when some data is given. The method is called from redraw here. Thus, we have to find out why the method is only called when some data is given. The method is called from here, whereas _updateYAxis is called from here. We are close. The code is only executed for if (groupIds.length > 0) (reference). And guess what - groupIds is empty when no data is provided.

Just discovered this happens regardless of whether I have an event defined or not. I deleted the event, reloaded (CTRL+F5) the view, and clicked on the graph2d. Same problem.

This is because Graph2D has an internal click event here.

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

No branches or pull requests

3 participants