Skip to content

Commit 046d367

Browse files
committed
coerce hovertemplate at trace-level, starting with scatter(gl)
1 parent 0084efb commit 046d367

File tree

9 files changed

+23
-12
lines changed

9 files changed

+23
-12
lines changed

src/components/fx/hover.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,13 @@ function createHoverText(hoverData, opts, gd) {
765765
if(allHaveZ && hoverData[i].zLabel === undefined) allHaveZ = false;
766766

767767
traceHoverinfo = hoverData[i].hoverinfo || hoverData[i].trace.hoverinfo;
768-
var parts = Array.isArray(traceHoverinfo) ? traceHoverinfo : traceHoverinfo.split('+');
769-
if(parts.indexOf('all') === -1 &&
770-
parts.indexOf(hovermode) === -1) {
771-
showCommonLabel = false;
772-
break;
768+
if(traceHoverinfo) {
769+
var parts = Array.isArray(traceHoverinfo) ? traceHoverinfo : traceHoverinfo.split('+');
770+
if(parts.indexOf('all') === -1 &&
771+
parts.indexOf(hovermode) === -1) {
772+
showCommonLabel = false;
773+
break;
774+
}
773775
}
774776
}
775777

@@ -953,7 +955,8 @@ function createHoverText(hoverData, opts, gd) {
953955
}
954956

955957
// hovertemplate
956-
var trace = d.trace, hovertemplate = opts.hovertemplate || trace.hovertemplate || false;
958+
var trace = d.trace;
959+
var hovertemplate = opts.hovertemplate || hoverData[curveNumber].hovertemplate || false;
957960
if(hovertemplate) {
958961
text = Lib.hovertemplateString(hovertemplate, d, gd._hoverdata[curveNumber], trace);
959962
}
@@ -1356,7 +1359,7 @@ function cleanPoint(d, hovermode) {
13561359

13571360
var infomode = d.hoverinfo || d.trace.hoverinfo;
13581361

1359-
if(infomode !== 'all') {
1362+
if(infomode && infomode !== 'all') {
13601363
infomode = Array.isArray(infomode) ? infomode : infomode.split('+');
13611364
if(infomode.indexOf('x') === -1) d.xLabel = undefined;
13621365
if(infomode.indexOf('y') === -1) d.yLabel = undefined;

src/plots/plots.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,6 @@ plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, trac
11701170
if(!traceOut.hovertemplate) Lib.coerceHoverinfo(traceIn, traceOut, layout);
11711171
}
11721172

1173-
coerce('hovertemplate');
1174-
11751173
if(!Registry.traceIs(traceOut, 'noOpacity')) coerce('opacity');
11761174

11771175
if(Registry.traceIs(traceOut, 'notLegendIsolatable')) {

src/traces/scatter/attributes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
'use strict';
1010

11+
var plotAttrs = require('../../plots/attributes');
1112
var colorAttributes = require('../../components/colorscale/attributes');
1213
var colorbarAttrs = require('../../components/colorbar/attributes');
1314
var fontAttrs = require('../../plots/font_attributes');
@@ -203,6 +204,7 @@ module.exports = {
203204
'or text, then the default is *fills*, otherwise it is *points*.'
204205
].join(' ')
205206
},
207+
hovertemplate: extendFlat({}, plotAttrs.hovertemplate),
206208
line: {
207209
color: {
208210
valType: 'color',

src/traces/scatter/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3838
'lines+markers' : 'lines';
3939
coerce('text');
4040
coerce('hovertext');
41+
coerce('hovertemplate');
4142
coerce('mode', defaultMode);
4243

4344
if(subTypes.hasLines(traceOut)) {

src/traces/scatter/hover.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
9393
y1: yc + rad,
9494
yLabelVal: yLabelVal,
9595

96-
spikeDistance: dxy(di)
96+
spikeDistance: dxy(di),
97+
hovertemplate: trace.hovertemplate
9798
});
9899

99100
fillHoverText(di, trace, pointData);
@@ -177,7 +178,8 @@ module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
177178
x1: xmax,
178179
y0: yAvg,
179180
y1: yAvg,
180-
color: color
181+
color: color,
182+
hovertemplate: '%{name}'
181183
});
182184

183185
delete pointData.index;

src/traces/scattergl/attributes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,4 @@ var attrs = module.exports = overrideAll({
9797
}, 'calc', 'nested');
9898

9999
attrs.x.editType = attrs.y.editType = attrs.x0.editType = attrs.y0.editType = 'calc+clearAxisTypes';
100+
attrs.hovertemplate = extendFlat({}, plotAttrs.hovertemplate);

src/traces/scattergl/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3737

3838
coerce('text');
3939
coerce('hovertext');
40+
coerce('hovertemplate');
4041
coerce('mode', defaultMode);
4142

4243
if(subTypes.hasLines(traceOut)) {

src/traces/scattergl/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,9 @@ function calcHover(pointData, x, y, trace) {
830830

831831
cd: fakeCd,
832832
distance: minDist,
833-
spikeDistance: dxy
833+
spikeDistance: dxy,
834+
835+
hovertemplate: trace.hovertemplate
834836
});
835837

836838
if(di.htx) pointData.text = di.htx;

test/jasmine/tests/hover_label_test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ describe('hover info', function() {
15721572

15731573
assertHoverLabelContent({
15741574
nums: '$1.00',
1575+
name: 'PV learning ...',
15751576
axis: '0.388'
15761577
});
15771578
})

0 commit comments

Comments
 (0)