Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3b1ee6b

Browse files
committed
fix ternary hover after zoom/pan events
registered after zooming. This fixes that, and tests the fix.
1 parent b6fc59d commit 3b1ee6b

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/plots/ternary/ternary.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,9 @@ proto.initInteractions = function() {
659659
Plotly.relayout(gd, attrs);
660660
}
661661

662-
dragElement.init(dragOptions);
663-
664662
// finally, set up hover and click
663+
// these event handlers must already be set before dragElement.init
664+
// so it can stash them and override them.
665665
dragger.onmousemove = function(evt) {
666666
fx.hover(gd, evt, _this.id);
667667
gd._fullLayout._lasthover = dragger;
@@ -677,6 +677,8 @@ proto.initInteractions = function() {
677677
dragger.onclick = function(evt) {
678678
fx.click(gd, evt);
679679
};
680+
681+
dragElement.init(dragOptions);
680682
};
681683

682684
function removeZoombox(gd) {

test/jasmine/tests/hover_label_test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,26 @@ describe('hover on fill', function() {
691691
}).then(done);
692692
});
693693

694+
// click and doubleClick copied over from click_test
695+
// TODO require from elsewhere
696+
function click(x, y) {
697+
mouseEvent('mousemove', x, y);
698+
mouseEvent('mousedown', x, y);
699+
mouseEvent('mouseup', x, y);
700+
}
701+
702+
function doubleClick(x, y) {
703+
return new Promise(function(resolve) {
704+
click(x, y);
705+
706+
setTimeout(function() {
707+
click(x, y);
708+
setTimeout(function() { resolve(); }, DBLCLICKDELAY / 2);
709+
}, DBLCLICKDELAY / 2);
710+
});
711+
}
712+
var DBLCLICKDELAY = require('@src/plots/cartesian/constants').DBLCLICKDELAY;
713+
694714
it('should work for scatterternary too', function(done) {
695715
var mock = Lib.extendDeep({}, require('@mocks/ternary_fill.json'));
696716

@@ -706,6 +726,12 @@ describe('hover on fill', function() {
706726
return assertLabelsCorrect([237, 218], [266.75, 265], 'trace 1');
707727
}).then(function() {
708728
return assertLabelsCorrect([237, 251], [247.7, 254], 'trace 0');
729+
}).then(function() {
730+
// trigger an autoscale redraw, which goes through dragElement
731+
return doubleClick(237, 251);
732+
}).then(function() {
733+
// then make sure we can still select a *different* item afterward
734+
return assertLabelsCorrect([237, 218], [266.75, 265], 'trace 1');
709735
}).then(done);
710736
});
711737
});

0 commit comments

Comments
 (0)