Skip to content

Commit 2e8db74

Browse files
committed
PR feedback: enriching event callback data - indices
1 parent 1e56d7f commit 2e8db74

File tree

3 files changed

+31
-44
lines changed

3 files changed

+31
-44
lines changed

src/plots/gl2d/scene2d.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ proto.updateTraces = function(fullData, calcData) {
452452
// update / create trace objects
453453
for(i = 0; i < fullData.length; i++) {
454454
fullTrace = fullData[i];
455-
this._inputs[fullTrace.uid] = fullTrace._input;
455+
this._inputs[fullTrace.uid] = i;
456456
var calcTrace = calcData[i],
457457
traceObj = this.traces[fullTrace.uid];
458458

@@ -507,13 +507,17 @@ proto.draw = function() {
507507
);
508508

509509
var nextSelection = result && result.object._trace.handlePick(result);
510+
var curveIndex;
510511

511512
if(nextSelection && mouseUp) {
513+
curveIndex = this._inputs[nextSelection.trace.uid];
512514
this.graphDiv.emit('plotly_click', {
513515
points: [{
514516
x: nextSelection.traceCoord[0],
515517
y: nextSelection.traceCoord[1],
516-
data: this._inputs[nextSelection.trace.uid],
518+
curveNumber: curveIndex,
519+
pointNumber: nextSelection.pointIndex,
520+
data: this.fullData[curveIndex]._input,
517521
fullData: this.fullData,
518522
xaxis: this.xaxis,
519523
yaxis: this.yaxis
@@ -550,11 +554,14 @@ proto.draw = function() {
550554

551555
// this needs to happen before the next block that deletes traceCoord data
552556
// also it's important to copy, otherwise data is lost by the time event data is read
557+
curveIndex = this._inputs[nextSelection.trace.uid];
553558
this.graphDiv.emit('plotly_hover', {
554559
points: [{
555560
x: nextSelection.traceCoord[0],
556561
y: nextSelection.traceCoord[1],
557-
data: this._inputs[nextSelection.trace.uid],
562+
curveNumber: curveIndex,
563+
pointNumber: nextSelection.pointIndex,
564+
data: this.fullData[curveIndex]._input,
558565
fullData: this.fullData,
559566
xaxis: this.xaxis,
560567
yaxis: this.yaxis

src/traces/scattergl/convert.js

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ proto.handlePick = function(pickResult) {
128128
this.color[index] :
129129
this.color,
130130
name: this.name,
131+
pointIndex: index,
131132
hoverinfo: this.hoverinfo
132133
};
133134
};

test/jasmine/tests/gl2d_click_test.js

+20-41
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ describe('Test hover and click interactions', function() {
2020

2121
var mockCopy, gd;
2222

23+
function check(pt) {
24+
expect(Object.keys(pt)).toEqual([
25+
'x', 'y', 'curveNumber', 'pointNumber', 'data', 'fullData', 'xaxis', 'yaxis'
26+
]);
27+
28+
expect(pt.x).toEqual(15.772);
29+
expect(pt.y).toEqual(0.387);
30+
expect(pt.curveNumber).toEqual(0);
31+
expect(pt.pointNumber).toEqual(33);
32+
expect(pt.fullData.length).toEqual(1);
33+
expect(typeof pt.data.uid).toEqual('string');
34+
expect(pt.xaxis.domain.length).toEqual(2);
35+
expect(pt.yaxis.domain.length).toEqual(2);
36+
}
37+
2338
beforeAll(function() {
2439
jasmine.addMatchers(customMatchers);
2540
});
@@ -54,14 +69,7 @@ describe('Test hover and click interactions', function() {
5469

5570
var pt = futureData.points[0];
5671

57-
expect(Object.keys(pt)).toEqual(['x', 'y', 'data', 'fullData', 'xaxis', 'yaxis']);
58-
59-
expect(pt.x).toEqual(15.772);
60-
expect(pt.y).toEqual(0.387);
61-
expect(pt.fullData.length).toEqual(1);
62-
expect(typeof pt.data.uid).toEqual('string');
63-
expect(pt.xaxis.domain.length).toEqual(2);
64-
expect(pt.yaxis.domain.length).toEqual(2);
72+
check(pt);
6573

6674
done();
6775
}, 250);
@@ -91,14 +99,7 @@ describe('Test hover and click interactions', function() {
9199

92100
var pt = futureData.points[0];
93101

94-
expect(Object.keys(pt)).toEqual(['x', 'y', 'data', 'fullData', 'xaxis', 'yaxis']);
95-
96-
expect(pt.x).toEqual(15.772);
97-
expect(pt.y).toEqual(0.387);
98-
expect(pt.fullData.length).toEqual(1);
99-
expect(typeof pt.data.uid).toEqual('string');
100-
expect(pt.xaxis.domain.length).toEqual(2);
101-
expect(pt.yaxis.domain.length).toEqual(2);
102+
check(pt);
102103

103104
done();
104105
}, 250);
@@ -128,15 +129,7 @@ describe('Test hover and click interactions', function() {
128129

129130
var pt = futureData.points[0];
130131

131-
expect(Object.keys(pt)).toEqual(['x', 'y', 'data', 'fullData', 'xaxis', 'yaxis']);
132-
133-
expect(pt.x).toEqual(15.772);
134-
expect(pt.y).toEqual(0.387);
135-
expect(pt.fullData.length).toEqual(1);
136-
expect(typeof pt.data.uid).toEqual('string');
137-
expect(pt.xaxis.domain.length).toEqual(2);
138-
expect(pt.yaxis.domain.length).toEqual(2);
139-
132+
check(pt);
140133

141134
done();
142135
}, 250);
@@ -211,14 +204,7 @@ describe('Test hover and click interactions', function() {
211204

212205
var pt = futureData.points[0];
213206

214-
expect(Object.keys(pt)).toEqual(['x', 'y', 'data', 'fullData', 'xaxis', 'yaxis']);
215-
216-
expect(pt.x).toEqual(15.772);
217-
expect(pt.y).toEqual(0.387);
218-
expect(pt.fullData.length).toEqual(1);
219-
expect(typeof pt.data.uid).toEqual('string');
220-
expect(pt.xaxis.domain.length).toEqual(2);
221-
expect(pt.yaxis.domain.length).toEqual(2);
207+
check(pt);
222208

223209
done();
224210

@@ -248,14 +234,7 @@ describe('Test hover and click interactions', function() {
248234

249235
var pt = futureData.points[0];
250236

251-
expect(Object.keys(pt)).toEqual(['x', 'y', 'data', 'fullData', 'xaxis', 'yaxis']);
252-
253-
expect(pt.x).toEqual(15.772);
254-
expect(pt.y).toEqual(0.387);
255-
expect(pt.fullData.length).toEqual(1);
256-
expect(typeof pt.data.uid).toEqual('string');
257-
expect(pt.xaxis.domain.length).toEqual(2);
258-
expect(pt.yaxis.domain.length).toEqual(2);
237+
check(pt);
259238

260239
done();
261240
}, 250);

0 commit comments

Comments
 (0)