Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d205d68

Browse filesBrowse files
authored
Merge pull request #3345 from plotly/histogram-hoverChanged-fix
fix #3330 - fix hoverChanged for traces with pointNumbers
2 parents 431fd51 + 6e1b624 commit d205d68
Copy full SHA for d205d68

File tree

Expand file treeCollapse file tree

2 files changed

+35
-10
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-10
lines changed

‎src/components/fx/hover.js

Copy file name to clipboardExpand all lines: src/components/fx/hover.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1565,8 +1565,11 @@ function hoverChanged(gd, evt, oldhoverdata) {
15651565
for(var i = oldhoverdata.length - 1; i >= 0; i--) {
15661566
var oldPt = oldhoverdata[i];
15671567
var newPt = gd._hoverdata[i];
1568+
15681569
if(oldPt.curveNumber !== newPt.curveNumber ||
1569-
String(oldPt.pointNumber) !== String(newPt.pointNumber)) {
1570+
String(oldPt.pointNumber) !== String(newPt.pointNumber) ||
1571+
String(oldPt.pointNumbers) !== String(newPt.pointNumbers)
1572+
) {
15701573
return true;
15711574
}
15721575
}

‎test/jasmine/tests/hover_label_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/hover_label_test.js
+31-9Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ describe('hover info', function() {
942942
describe('histogram hover info', function() {
943943
it('shows the data range when bins have multiple values', function(done) {
944944
var gd = createGraphDiv();
945-
var pts;
946945

947946
Plotly.plot(gd, [{
948947
x: [0, 2, 3, 4, 5, 6, 7],
@@ -954,18 +953,15 @@ describe('hover info', function() {
954953
margin: {l: 0, t: 0, r: 0, b: 0}
955954
})
956955
.then(function() {
957-
gd.on('plotly_hover', function(e) { pts = e.points; });
956+
var pts = null;
957+
gd.once('plotly_hover', function(e) { pts = e.points; });
958958

959959
_hoverNatural(gd, 250, 200);
960-
assertHoverLabelContent({
961-
nums: '3',
962-
axis: '3 - 5'
963-
});
964-
})
965-
.then(function() {
960+
assertHoverLabelContent({nums: '3', axis: '3 - 5'});
961+
if(pts === null) fail('no hover evt triggered');
966962
expect(pts.length).toBe(1);
967-
var pt = pts[0];
968963

964+
var pt = pts[0];
969965
expect(pt.curveNumber).toBe(0);
970966
expect(pt.binNumber).toBe(1);
971967
expect(pt.pointNumbers).toEqual([2, 3, 4]);
@@ -976,6 +972,32 @@ describe('hover info', function() {
976972
expect(pt.xaxis).toBe(gd._fullLayout.xaxis);
977973
expect(pt.yaxis).toBe(gd._fullLayout.yaxis);
978974
})
975+
.then(function() {
976+
var pts = null;
977+
gd.once('plotly_hover', function(e) { pts = e.points; });
978+
979+
_hoverNatural(gd, 250, 200);
980+
expect(pts).toBe(null, 'should not emit hover event on same pt');
981+
})
982+
.then(function() {
983+
var pts = null;
984+
gd.once('plotly_hover', function(e) { pts = e.points; });
985+
986+
_hoverNatural(gd, 350, 200);
987+
assertHoverLabelContent({nums: '2', axis: '6 - 8'});
988+
expect(pts.length).toBe(1);
989+
990+
var pt = pts[0];
991+
expect(pt.curveNumber).toBe(0);
992+
expect(pt.binNumber).toBe(2);
993+
expect(pt.pointNumbers).toEqual([5, 6]);
994+
expect(pt.x).toBe(7);
995+
expect(pt.y).toBe(2);
996+
expect(pt.data).toBe(gd.data[0]);
997+
expect(pt.fullData).toBe(gd._fullData[0]);
998+
expect(pt.xaxis).toBe(gd._fullLayout.xaxis);
999+
expect(pt.yaxis).toBe(gd._fullLayout.yaxis);
1000+
})
9791001
.catch(failTest)
9801002
.then(done);
9811003
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.