Skip to content
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

Modebar toggle spikes fixup #4241

Merged
merged 3 commits into from
Oct 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 14 additions & 15 deletions src/components/modebar/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function handleCartesian(gd, ev) {
var fullLayout = gd._fullLayout;
var aobj = {};
var axList = axisIds.list(gd, null, true);
var allSpikesEnabled = 'on';
var allSpikesEnabled = fullLayout._cartesianSpikesEnabled;

var ax, i;

Expand All @@ -214,15 +214,18 @@ function handleCartesian(gd, ev) {

if(!ax.fixedrange) {
axName = ax._name;
if(val === 'auto') aobj[axName + '.autorange'] = true;
else if(val === 'reset') {
if(val === 'auto') {
aobj[axName + '.autorange'] = true;
} else if(val === 'reset') {
if(ax._rangeInitial === undefined) {
aobj[axName + '.autorange'] = true;
} else {
var rangeInitial = ax._rangeInitial.slice();
aobj[axName + '.range[0]'] = rangeInitial[0];
aobj[axName + '.range[1]'] = rangeInitial[1];
}

// N.B. "reset" also resets showspikes
if(ax._showSpikeInitial !== undefined) {
aobj[axName + '.showspikes'] = ax._showSpikeInitial;
if(allSpikesEnabled === 'on' && !ax._showSpikeInitial) {
Expand All @@ -245,7 +248,6 @@ function handleCartesian(gd, ev) {
}
}
}
fullLayout._cartesianSpikesEnabled = allSpikesEnabled;
} else {
// if ALL traces have orientation 'h', 'hovermode': 'x' otherwise: 'y'
if(astr === 'hovermode' && (val === 'x' || val === 'y')) {
Expand All @@ -258,12 +260,13 @@ function handleCartesian(gd, ev) {
allSpikesEnabled = 'off';
}
}
fullLayout._cartesianSpikesEnabled = allSpikesEnabled;
}

aobj[astr] = val;
}

fullLayout._cartesianSpikesEnabled = allSpikesEnabled;

Registry.call('_guiRelayout', gd, aobj);
}

Expand Down Expand Up @@ -581,26 +584,22 @@ modeBarButtons.toggleSpikelines = {
val: 'on',
click: function(gd) {
var fullLayout = gd._fullLayout;
var allSpikesEnabled = fullLayout._cartesianSpikesEnabled;

fullLayout._cartesianSpikesEnabled = fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on';

var aobj = setSpikelineVisibility(gd);

Registry.call('_guiRelayout', gd, aobj);
fullLayout._cartesianSpikesEnabled = allSpikesEnabled === 'on' ? 'off' : 'on';
Registry.call('_guiRelayout', gd, setSpikelineVisibility(gd));
}
};

function setSpikelineVisibility(gd) {
var fullLayout = gd._fullLayout;
var areSpikesOn = fullLayout._cartesianSpikesEnabled === 'on';
var axList = axisIds.list(gd, null, true);
var aobj = {};

var ax, axName;

for(var i = 0; i < axList.length; i++) {
ax = axList[i];
axName = ax._name;
aobj[axName + '.showspikes'] = fullLayout._cartesianSpikesEnabled === 'on' ? true : ax._showSpikeInitial;
var ax = axList[i];
aobj[ax._name + '.showspikes'] = areSpikesOn ? true : ax._showSpikeInitial;
}

return aobj;
Expand Down
33 changes: 33 additions & 0 deletions test/jasmine/tests/modebar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,20 +1201,23 @@ describe('ModeBar', function() {
expect(gd._fullLayout.hovermode).toBe('x');
assertActive(hovermodeButtons, buttonCompare);
});

it('should makes spikelines visible', function() {
buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');

buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
});

it('should not become disabled when hovermode is switched off closest', function() {
buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');

buttonCompare.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
});

it('should keep the state on changing the hovermode', function() {
buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
Expand All @@ -1228,6 +1231,36 @@ describe('ModeBar', function() {
buttonClosest.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
});

it('should work after clicking on "autoScale2d"', function() {
var buttonAutoScale = selectButton(modeBar, 'autoScale2d');
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, clicking on the "autoScale2d" modebar button on a graph that has _cartesianSpikesEnabled: 'off' on first draw, results in

gd._fullLayout._cartesianSpikesEnabled // => 'on'

which is obviously wrong.


buttonAutoScale.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');

buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');

buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
});

it('should work after clicking on "resetScale2d"', function() {
var buttonResetScale = selectButton(modeBar, 'resetScale2d');
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');

buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');

buttonResetScale.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');

buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
buttonToggle.click();
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
});
});
});

Expand Down