Skip to content

Fix hovermode default logic for stacked scatter traces #3646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/components/fx/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
} else {
// flag for 'horizontal' plots:
// determines the state of the mode bar 'compare' hovermode button
layoutOut._isHoriz = isHoriz(fullData);
layoutOut._isHoriz = isHoriz(fullData, layoutOut);
hovermodeDflt = layoutOut._isHoriz ? 'y' : 'x';
}
}
Expand All @@ -55,17 +55,19 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
}
};

function isHoriz(fullData) {
var out = true;
function isHoriz(fullData, fullLayout) {
var stackOpts = fullLayout._scatterStackOpts || {};

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

if(trace.orientation !== 'h') {
out = false;
break;
if(trace.orientation !== 'h' && groupOpts.orientation !== 'h') {
return false;
}
}

return out;
return true;
}
18 changes: 18 additions & 0 deletions test/jasmine/tests/fx_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ describe('Fx defaults', function() {
expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true');
});

it('should default (cartesian horizontal version, stacked scatter)', function() {
var layoutOut = _supply([{
orientation: 'h',
stackgroup: '1',
x: [1, 2, 3],
y: [1, 2, 1]
}, {
stackgroup: '1',
x: [1, 2, 3],
y: [1, 2, 1]
}])
.layout;

expect(layoutOut.hovermode).toBe('y', 'hovermode to y');
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true');
});

it('should default (gl3d version)', function() {
var layoutOut = _supply([{
type: 'scatter3d',
Expand Down