Skip to content

Commit 6fc270e

Browse files
committed
some linting in modebar button code
1 parent 9abf36a commit 6fc270e

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/components/modebar/buttons.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ function handleCartesian(gd, ev) {
214214

215215
if(!ax.fixedrange) {
216216
axName = ax._name;
217-
if(val === 'auto') aobj[axName + '.autorange'] = true;
218-
else if(val === 'reset') {
217+
if(val === 'auto') {
218+
aobj[axName + '.autorange'] = true;
219+
} else if(val === 'reset') {
219220
if(ax._rangeInitial === undefined) {
220221
aobj[axName + '.autorange'] = true;
221222
} else {
@@ -581,26 +582,22 @@ modeBarButtons.toggleSpikelines = {
581582
val: 'on',
582583
click: function(gd) {
583584
var fullLayout = gd._fullLayout;
585+
var allSpikesEnabled = fullLayout._cartesianSpikesEnabled;
584586

585-
fullLayout._cartesianSpikesEnabled = fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on';
586-
587-
var aobj = setSpikelineVisibility(gd);
588-
589-
Registry.call('_guiRelayout', gd, aobj);
587+
fullLayout._cartesianSpikesEnabled = allSpikesEnabled === 'on' ? 'off' : 'on';
588+
Registry.call('_guiRelayout', gd, setSpikelineVisibility(gd));
590589
}
591590
};
592591

593592
function setSpikelineVisibility(gd) {
594593
var fullLayout = gd._fullLayout;
594+
var areSpikesOn = fullLayout._cartesianSpikesEnabled === 'on';
595595
var axList = axisIds.list(gd, null, true);
596596
var aobj = {};
597597

598-
var ax, axName;
599-
600598
for(var i = 0; i < axList.length; i++) {
601-
ax = axList[i];
602-
axName = ax._name;
603-
aobj[axName + '.showspikes'] = fullLayout._cartesianSpikesEnabled === 'on' ? true : ax._showSpikeInitial;
599+
var ax = axList[i];
600+
aobj[ax._name + '.showspikes'] = areSpikesOn ? true : ax._showSpikeInitial;
604601
}
605602

606603
return aobj;

test/jasmine/tests/modebar_test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,20 +1201,23 @@ describe('ModeBar', function() {
12011201
expect(gd._fullLayout.hovermode).toBe('x');
12021202
assertActive(hovermodeButtons, buttonCompare);
12031203
});
1204+
12041205
it('should makes spikelines visible', function() {
12051206
buttonToggle.click();
12061207
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
12071208

12081209
buttonToggle.click();
12091210
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
12101211
});
1212+
12111213
it('should not become disabled when hovermode is switched off closest', function() {
12121214
buttonToggle.click();
12131215
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
12141216

12151217
buttonCompare.click();
12161218
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
12171219
});
1220+
12181221
it('should keep the state on changing the hovermode', function() {
12191222
buttonToggle.click();
12201223
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');

0 commit comments

Comments
 (0)