Skip to content

Show correct curve number in gl2d hover data #1427

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

Merged
merged 3 commits into from
Mar 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/plots/gl2d/scene2d.js
Original file line number Diff line number Diff line change
@@ -51,7 +51,6 @@ function Scene2D(options, fullLayout) {

// trace set
this.traces = {};
this._inputs = {};

// create axes spikes
this.spikes = createSpikes(this.glplot);
@@ -362,7 +361,6 @@ proto.destroy = function() {
this.container.removeChild(this.mouseContainer);

this.fullData = null;
this._inputs = null;
this.glplot = null;
this.stopped = true;
};
@@ -487,7 +485,6 @@ proto.updateTraces = function(fullData, calcData) {
// update / create trace objects
for(i = 0; i < fullData.length; i++) {
fullTrace = fullData[i];
this._inputs[fullTrace.uid] = i;
var calcTrace = calcData[i],
traceObj = this.traces[fullTrace.uid];

@@ -500,16 +497,22 @@ proto.updateTraces = function(fullData, calcData) {
};

proto.emitPointAction = function(nextSelection, eventType) {
var uid = nextSelection.trace.uid;
var trace;

var curveIndex = this._inputs[nextSelection.trace.uid];
for(var i = 0; i < this.fullData.length; i++) {
if(this.fullData[i].uid === uid) {
trace = this.fullData[i];
}
}

this.graphDiv.emit(eventType, {
points: [{
x: nextSelection.traceCoord[0],
y: nextSelection.traceCoord[1],
curveNumber: curveIndex,
curveNumber: trace.index,
pointNumber: nextSelection.pointIndex,
data: this.fullData[curveIndex]._input,
data: trace._input,
fullData: this.fullData,
xaxis: this.xaxis,
yaxis: this.yaxis
8 changes: 8 additions & 0 deletions test/jasmine/karma.conf.js
Original file line number Diff line number Diff line change
@@ -35,6 +35,14 @@ function func(config) {
// See CONTRIBUTING.md for additional notes on reporting.
func.defaultConfig.logLevel = config.LOG_INFO;

// without this, console logs in the plotly.js code don't print to
// the terminal since karma v1.5.0
//
// See https://github.com/karma-runner/karma/commit/89a7a1c#commitcomment-21009216
func.defaultConfig.browserConsoleLogOptions = {
level: 'log'
};

config.set(func.defaultConfig);
}

72 changes: 42 additions & 30 deletions test/jasmine/tests/gl2d_click_test.js
Original file line number Diff line number Diff line change
@@ -371,38 +371,50 @@ describe('Test hover and click interactions', function() {

var modifiedMockCopy = Lib.extendDeep({}, mock4);

Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout)

.then(new Promise(function() {

gd.on('plotly_hover', function(data) {
futureData = data;
});

hover(435, 216);

window.setTimeout(function() {

expect(futureData.points.length).toEqual(1);

var pt = futureData.points[0];
function _hover() {
hover(435, 216);

expect(Object.keys(pt)).toEqual([
'x', 'y', 'curveNumber', 'pointNumber', 'data', 'fullData', 'xaxis', 'yaxis'
]);

expect(pt.x).toEqual(8);
expect(pt.y).toEqual(18);
expect(pt.curveNumber).toEqual(2);
expect(pt.pointNumber).toEqual(0);
expect(pt.fullData.length).toEqual(3);
expect(typeof pt.data.uid).toEqual('string');
expect(pt.xaxis.domain.length).toEqual(2);
expect(pt.yaxis.domain.length).toEqual(2);
return new Promise(function(resolve) {
setTimeout(resolve, 350);
});
}

done();
}, 350);
}));
Plotly.plot(gd, modifiedMockCopy.data, modifiedMockCopy.layout).then(function() {
gd.on('plotly_hover', function(data) {
futureData = data;
});
})
.then(_hover)
.then(function() {
expect(futureData.points.length).toEqual(1);

var pt = futureData.points[0];

expect(Object.keys(pt)).toEqual([
'x', 'y', 'curveNumber', 'pointNumber', 'data', 'fullData', 'xaxis', 'yaxis'
]);

expect(pt.x).toEqual(8);
expect(pt.y).toEqual(18);
expect(pt.curveNumber).toEqual(2);
expect(pt.pointNumber).toEqual(0);
expect(pt.fullData.length).toEqual(3);
expect(typeof pt.data.uid).toEqual('string');
expect(pt.xaxis.domain.length).toEqual(2);
expect(pt.yaxis.domain.length).toEqual(2);

return Plotly.restyle(gd, 'visible', false, [1, 2]);
})
.then(_hover)
.then(function() {
var pt = futureData.points[0];

expect(pt.x).toEqual(8);
expect(pt.y).toEqual(18);
expect(pt.curveNumber).toEqual(2, 'matches input data index');
expect(pt.pointNumber).toEqual(0);
})
.then(done);
});

it('scattergl-fancy', function(done) {