Skip to content

Commit 448cb14

Browse files
authoredMar 18, 2019
Merge pull request #3646 from plotly/isHoriz-fix-for-stacked-scatter-traces
Fix hovermode default logic for stacked scatter traces
2 parents 0588483 + 9a41583 commit 448cb14

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed
 

‎src/components/fx/layout_defaults.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
2828
} else {
2929
// flag for 'horizontal' plots:
3030
// determines the state of the mode bar 'compare' hovermode button
31-
layoutOut._isHoriz = isHoriz(fullData);
31+
layoutOut._isHoriz = isHoriz(fullData, layoutOut);
3232
hovermodeDflt = layoutOut._isHoriz ? 'y' : 'x';
3333
}
3434
}
@@ -55,17 +55,19 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
5555
}
5656
};
5757

58-
function isHoriz(fullData) {
59-
var out = true;
58+
function isHoriz(fullData, fullLayout) {
59+
var stackOpts = fullLayout._scatterStackOpts || {};
6060

6161
for(var i = 0; i < fullData.length; i++) {
6262
var trace = fullData[i];
63+
var subplot = trace.xaxis + trace.yaxis;
64+
var subplotStackOpts = stackOpts[subplot] || {};
65+
var groupOpts = subplotStackOpts[trace.stackgroup] || {};
6366

64-
if(trace.orientation !== 'h') {
65-
out = false;
66-
break;
67+
if(trace.orientation !== 'h' && groupOpts.orientation !== 'h') {
68+
return false;
6769
}
6870
}
6971

70-
return out;
72+
return true;
7173
}

‎test/jasmine/tests/fx_test.js

+18
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ describe('Fx defaults', function() {
5858
expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true');
5959
});
6060

61+
it('should default (cartesian horizontal version, stacked scatter)', function() {
62+
var layoutOut = _supply([{
63+
orientation: 'h',
64+
stackgroup: '1',
65+
x: [1, 2, 3],
66+
y: [1, 2, 1]
67+
}, {
68+
stackgroup: '1',
69+
x: [1, 2, 3],
70+
y: [1, 2, 1]
71+
}])
72+
.layout;
73+
74+
expect(layoutOut.hovermode).toBe('y', 'hovermode to y');
75+
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
76+
expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true');
77+
});
78+
6179
it('should default (gl3d version)', function() {
6280
var layoutOut = _supply([{
6381
type: 'scatter3d',

0 commit comments

Comments
 (0)
Please sign in to comment.