Skip to content

Commit 18b36a6

Browse files
committed
Manually trigger rehover behavior
1 parent 5881ad5 commit 18b36a6

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

src/plot_api/plot_api.js

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ Plotly.plot = function(gd, data, layout, config) {
343343
gd.emit('plotly_afterplot');
344344
}
345345

346-
Lib.syncOrAsync([
346+
var seq = [
347347
Plots.previousPromises,
348348
addFrames,
349349
drawFramework,
@@ -353,8 +353,14 @@ Plotly.plot = function(gd, data, layout, config) {
353353
subroutines.layoutStyles,
354354
drawAxes,
355355
drawData,
356-
finalDraw
357-
], gd, cleanUp);
356+
finalDraw,
357+
];
358+
359+
if(gd._fullLayout._rehover) {
360+
seq.push(function() { Plots.rehover(gd); });
361+
}
362+
363+
Lib.syncOrAsync(seq, gd, cleanUp);
358364

359365
// even if everything we did was synchronous, return a promise
360366
// so that the caller doesn't care which route we took
@@ -1206,8 +1212,7 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
12061212

12071213
if(flags.fullReplot) {
12081214
seq.push(Plotly.plot);
1209-
}
1210-
else {
1215+
} else {
12111216
seq.push(Plots.previousPromises);
12121217

12131218
Plots.supplyDefaults(gd);
@@ -1216,6 +1221,10 @@ Plotly.restyle = function restyle(gd, astr, val, traces) {
12161221
if(flags.docolorbars) seq.push(subroutines.doColorBars);
12171222
}
12181223

1224+
if(gd._fullLayout._rehover) {
1225+
seq.push(function() { Plots.rehover(gd); });
1226+
}
1227+
12191228
Queue.add(gd,
12201229
restyle, [gd, specs.undoit, specs.traces],
12211230
restyle, [gd, specs.redoit, specs.traces]
@@ -1696,9 +1705,11 @@ Plotly.relayout = function relayout(gd, astr, val) {
16961705
}
16971706

16981707
var aobj = {};
1699-
if(typeof astr === 'string') aobj[astr] = val;
1700-
else if(Lib.isPlainObject(astr)) aobj = astr;
1701-
else {
1708+
if(typeof astr === 'string') {
1709+
aobj[astr] = val;
1710+
} else if(Lib.isPlainObject(astr)) {
1711+
aobj = astr;
1712+
} else {
17021713
Lib.warn('Relayout fail.', astr, val);
17031714
return Promise.reject();
17041715
}
@@ -1716,8 +1727,7 @@ Plotly.relayout = function relayout(gd, astr, val) {
17161727

17171728
if(flags.layoutReplot) {
17181729
seq.push(subroutines.layoutReplot);
1719-
}
1720-
else if(Object.keys(aobj).length) {
1730+
} else if(Object.keys(aobj).length) {
17211731
seq.push(Plots.previousPromises);
17221732
Plots.supplyDefaults(gd);
17231733

@@ -1727,6 +1737,10 @@ Plotly.relayout = function relayout(gd, astr, val) {
17271737
if(flags.domodebar) seq.push(subroutines.doModeBar);
17281738
}
17291739

1740+
if(gd._fullLayout._rehover) {
1741+
seq.push(function() { Plots.rehover(gd); });
1742+
}
1743+
17301744
Queue.add(gd,
17311745
relayout, [gd, specs.undoit],
17321746
relayout, [gd, specs.redoit]
@@ -2122,6 +2136,10 @@ Plotly.update = function update(gd, traceUpdate, layoutUpdate, traces) {
21222136
if(relayoutFlags.domodebar) seq.push(subroutines.doModeBar);
21232137
}
21242138

2139+
if(gd._fullLayout._rehover) {
2140+
seq.push(function() { Plots.rehover(gd); });
2141+
}
2142+
21252143
Queue.add(gd,
21262144
update, [gd, restyleSpecs.undoit, relayoutSpecs.undoit, restyleSpecs.traces],
21272145
update, [gd, restyleSpecs.redoit, relayoutSpecs.redoit, restyleSpecs.traces]

src/plots/cartesian/graph_interact.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,19 @@ fx.init = function(gd) {
118118
// This is on `gd._fullLayout`, *not* fullLayout because the reference
119119
// changes by the time this is called again.
120120
gd._fullLayout._rehover = function() {
121-
fx.hover(gd, evt, subplot);
121+
if(gd._fullLayout._hoversubplot === plotinfo.id) {
122+
fx.hover(gd, evt, subplot);
123+
}
122124
};
125+
126+
// Track the hovered subplot. This prevents rehover from accidetally
127+
// reapplying a hover label after the mouse has left the plot or if
128+
// the mouse has entered another subplot.
129+
gd._fullLayout._hoversubplot = plotinfo.id;
130+
123131
gd._fullLayout._rehover();
132+
133+
fx.hover(gd, evt, subplot);
124134
fullLayout._lasthover = maindrag;
125135
fullLayout._hoversubplot = subplot;
126136
};
@@ -135,6 +145,11 @@ fx.init = function(gd) {
135145
maindrag.onmouseout = function(evt) {
136146
if(gd._dragging) return;
137147

148+
// When the mouse leaves this maindrag, unset the hovered subplot.
149+
// This may cause problems if it leaves the subplot directly *onto*
150+
// another subplot, but that's a tiny corner case at the moment.
151+
gd._fullLayout._hoversubplot = null;
152+
138153
dragElement.unhover(gd, evt);
139154
};
140155

src/plots/plots.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,11 @@ plots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts)
19051905
}
19061906
}
19071907

1908-
var seq = [plots.previousPromises, interruptPreviousTransitions, prepareTransitions, executeTransitions];
1908+
function rehover() {
1909+
plots.rehover(gd);
1910+
}
1911+
1912+
var seq = [plots.previousPromises, interruptPreviousTransitions, prepareTransitions, rehover, executeTransitions];
19091913

19101914
var transitionStarting = Lib.syncOrAsync(seq, gd);
19111915

@@ -2026,6 +2030,10 @@ plots.doCalcdata = function(gd, traces) {
20262030

20272031
calcdata[i] = cd;
20282032
}
2033+
};
20292034

2030-
if(gd._fullLayout._rehover) gd._fullLayout._rehover();
2035+
plots.rehover = function(gd) {
2036+
if(gd._fullLayout._rehover) {
2037+
gd._fullLayout._rehover();
2038+
}
20312039
};

0 commit comments

Comments
 (0)