Skip to content

Commit 609104d

Browse files
committed
fix hovertemplate fallback when hovering on scatter fills
1 parent 682eb66 commit 609104d

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src/components/fx/hover.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,15 @@ function _hover(gd, evt, subplot, noHoverEvent) {
672672
var pt = hoverData[itemnum];
673673
var eventData = helpers.makeEventData(pt, pt.trace, pt.cd);
674674

675-
var ht = false;
676-
if(pt.cd[pt.index] && pt.cd[pt.index].ht) ht = pt.cd[pt.index].ht;
677-
hoverData[itemnum].hovertemplate = ht || pt.trace.hovertemplate || false;
678-
hoverData[itemnum].eventData = [eventData];
675+
if(pt.hovertemplate !== false) {
676+
var ht = false;
677+
if(pt.cd[pt.index] && pt.cd[pt.index].ht) {
678+
ht = pt.cd[pt.index].ht;
679+
}
680+
pt.hovertemplate = ht || pt.trace.hovertemplate || false;
681+
}
679682

683+
pt.eventData = [eventData];
680684
newhoverdata.push(eventData);
681685
}
682686

src/traces/scatter/hover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
179179
y0: yAvg,
180180
y1: yAvg,
181181
color: color,
182-
hovertemplate: '%{name}'
182+
hovertemplate: false
183183
});
184184

185185
delete pointData.index;

test/jasmine/tests/hover_label_test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,6 +1938,38 @@ describe('hover info', function() {
19381938
.catch(failTest)
19391939
.then(done);
19401940
});
1941+
1942+
it('should fallback to regular hover content when hoveron does not support hovertemplate', function(done) {
1943+
var gd = createGraphDiv();
1944+
var fig = Lib.extendDeep({}, require('@mocks/scatter_fill_self_next.json'));
1945+
1946+
fig.data.forEach(function(trace) {
1947+
trace.hoveron = 'points+fills';
1948+
trace.hovertemplate = '%{x} | %{y}';
1949+
});
1950+
1951+
fig.layout.hovermode = 'closest';
1952+
fig.layout.showlegend = false;
1953+
fig.layout.margin = {t: 0, b: 0, l: 0, r: 0};
1954+
1955+
Plotly.plot(gd, fig)
1956+
.then(function() { _hoverNatural(gd, 180, 200); })
1957+
.then(function() {
1958+
assertHoverLabelContent({
1959+
nums: 'trace 1',
1960+
name: ''
1961+
}, 'hovering on a fill');
1962+
})
1963+
.then(function() { _hoverNatural(gd, 50, 95); })
1964+
.then(function() {
1965+
assertHoverLabelContent({
1966+
nums: '0 | 5',
1967+
name: 'trace 1'
1968+
}, 'hovering on a pt');
1969+
})
1970+
.catch(failTest)
1971+
.then(done);
1972+
});
19411973
});
19421974

19431975
describe('hover info on stacked subplots', function() {

0 commit comments

Comments
 (0)