Skip to content

Commit 2c76d79

Browse files
committed
enable unified hovermode via template
1 parent 6de4c75 commit 2c76d79

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/plots/cartesian/layout_defaults.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
249249
handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions);
250250
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);
251251

252-
var unifiedHover = layoutIn.hovermode && ['x unified', 'y unified'].indexOf(layoutIn.hovermode) !== -1;
253-
var unifiedSpike = unifiedHover && axLetter === layoutIn.hovermode.charAt(0);
252+
var hovermode = layoutOut.hovermode || layoutIn.hovermode;
253+
var unifiedHover = hovermode && ['x unified', 'y unified'].indexOf(hovermode) !== -1;
254+
var unifiedSpike = unifiedHover && axLetter === hovermode.charAt(0);
254255
var spikecolor = coerce2('spikecolor', unifiedHover ? axLayoutOut.color : undefined);
255256
var spikethickness = coerce2('spikethickness', unifiedHover ? 1.5 : undefined);
256257
var spikedash = coerce2('spikedash', unifiedHover ? 'dot' : undefined);

test/jasmine/tests/hover_label_test.js

+18
Original file line numberDiff line numberDiff line change
@@ -4093,6 +4093,24 @@ describe('hovermode: (x|y)unified', function() {
40934093
.then(done);
40944094
});
40954095

4096+
it('unified hover modes should work for x/y cartesian traces via template', function(done) {
4097+
var mockCopy = Lib.extendDeep({}, mock);
4098+
delete mockCopy.layout.hovermode;
4099+
mockCopy.layout.template = {
4100+
layout: {
4101+
hovermode: 'y unified'
4102+
}
4103+
};
4104+
Plotly.newPlot(gd, mockCopy)
4105+
.then(function(gd) {
4106+
_hover(gd, { yval: 6 });
4107+
4108+
assertLabel({title: '6', items: ['trace 0 : 2', 'trace 1 : 5']});
4109+
})
4110+
.catch(failTest)
4111+
.then(done);
4112+
});
4113+
40964114
it('x unified should work for x/y cartesian traces with legendgroup', function(done) {
40974115
var mockLegendGroup = require('@mocks/legendgroup.json');
40984116
var mockCopy = Lib.extendDeep({}, mockLegendGroup);

0 commit comments

Comments
 (0)