Skip to content

Commit f84f7c3

Browse files
committed
fix #4237 - track current _cartesianSpikesEnabled value
... during modebar button on-click logic for cartesian axes. Previously, we assume that _cartesianSpikesEnabled was always on when clicking on the other modebar buttons for cartesian axes. This is obviously wrong.
1 parent 6fc270e commit f84f7c3

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/components/modebar/buttons.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function handleCartesian(gd, ev) {
199199
var fullLayout = gd._fullLayout;
200200
var aobj = {};
201201
var axList = axisIds.list(gd, null, true);
202-
var allSpikesEnabled = 'on';
202+
var allSpikesEnabled = fullLayout._cartesianSpikesEnabled;
203203

204204
var ax, i;
205205

@@ -224,6 +224,8 @@ function handleCartesian(gd, ev) {
224224
aobj[axName + '.range[0]'] = rangeInitial[0];
225225
aobj[axName + '.range[1]'] = rangeInitial[1];
226226
}
227+
228+
// N.B. "reset" also resets showspikes
227229
if(ax._showSpikeInitial !== undefined) {
228230
aobj[axName + '.showspikes'] = ax._showSpikeInitial;
229231
if(allSpikesEnabled === 'on' && !ax._showSpikeInitial) {
@@ -246,7 +248,6 @@ function handleCartesian(gd, ev) {
246248
}
247249
}
248250
}
249-
fullLayout._cartesianSpikesEnabled = allSpikesEnabled;
250251
} else {
251252
// if ALL traces have orientation 'h', 'hovermode': 'x' otherwise: 'y'
252253
if(astr === 'hovermode' && (val === 'x' || val === 'y')) {
@@ -259,12 +260,13 @@ function handleCartesian(gd, ev) {
259260
allSpikesEnabled = 'off';
260261
}
261262
}
262-
fullLayout._cartesianSpikesEnabled = allSpikesEnabled;
263263
}
264264

265265
aobj[astr] = val;
266266
}
267267

268+
fullLayout._cartesianSpikesEnabled = allSpikesEnabled;
269+
268270
Registry.call('_guiRelayout', gd, aobj);
269271
}
270272

test/jasmine/tests/modebar_test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,36 @@ describe('ModeBar', function() {
12311231
buttonClosest.click();
12321232
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
12331233
});
1234+
1235+
it('should work after clicking on "autoScale2d"', function() {
1236+
var buttonAutoScale = selectButton(modeBar, 'autoScale2d');
1237+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
1238+
1239+
buttonAutoScale.click();
1240+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
1241+
1242+
buttonToggle.click();
1243+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
1244+
1245+
buttonToggle.click();
1246+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
1247+
});
1248+
1249+
it('should work after clicking on "resetScale2d"', function() {
1250+
var buttonResetScale = selectButton(modeBar, 'resetScale2d');
1251+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
1252+
1253+
buttonToggle.click();
1254+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
1255+
1256+
buttonResetScale.click();
1257+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
1258+
1259+
buttonToggle.click();
1260+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('on');
1261+
buttonToggle.click();
1262+
expect(gd._fullLayout._cartesianSpikesEnabled).toBe('off');
1263+
});
12341264
});
12351265
});
12361266

0 commit comments

Comments
 (0)