almende / vis

⚠️ This project is not maintained anymore! Please go to https://github.com/visjs
7.85k stars 1.48k forks source link

Error when clicking on graph2d with yAxisOrientation: 'right' #3458

Open gowlin opened 7 years ago

gowlin commented 7 years ago

This error prevents being abel to listen to click or doubleClick events on graph2d.

See: http://jsbin.com/wehodih/edit?html,js,console,output

When clicking on a graph2d with yAxisOrientation: 'right' I get the following error in the console:

modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:45809 Uncaught TypeError: Cannot read property 'screenToValue' of undefined at DataAxis.screenToValue (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:45809) at Graph2d.getEventProperties (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:44276) at Graph2d. (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:44073) at Graph2d.Emitter.emit (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:26373) at Array.listener (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:33732) at Array.propagatedHandler (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:28492) at Object.emit (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:31027) at TapRecognizer.emit (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:30636) at TapRecognizer.tryEmit (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:30063) at TapRecognizer.recognize (modules.js?hash=d66c5d3f6eeb8621e52bbf2fff6272b1fdb03db7:30110)

dalzell99 commented 6 years ago

If you change return this.scale.screenToValue(x); to return this.scale ? this.scale.screenToValue(x) : 0; in DataAxis.prototype.screenToValue then it seems to fix it but I haven't fully tested yet.

I traced the issue back to yAxisLeftUsed being false in LineGraph.prototype._updateYAxis. This causes this.yAxisLeft.redraw() to not be called. this._redrawLabels() then doesn't get called which is where the scale is set.