Skip to content

Commit

Permalink
Merge pull request #3646 from plotly/isHoriz-fix-for-stacked-scatter-…
Browse files Browse the repository at this point in the history
…traces

Fix hovermode default logic for stacked scatter traces
  • Loading branch information
etpinard authored Mar 18, 2019
2 parents 0588483 + 9a41583 commit 448cb14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
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

0 comments on commit 448cb14

Please sign in to comment.