Skip to content

Commit 0b7a924

Browse files
committed
fixup gl2d dramode logic (:lock: it with tests)
1 parent baabafe commit 0b7a924

File tree

2 files changed

+81
-11
lines changed

2 files changed

+81
-11
lines changed

src/plot_api/plot_api.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,17 +2141,17 @@ function _relayout(gd, aobj) {
21412141
ai.match(/^(bar|box|font)/)) {
21422142
flags.docalc = true;
21432143
}
2144-
else if(fullLayout._has('gl2d')) {
2145-
if(ai.indexOf('axis') !== -1 || ai === 'plot_bgcolor') {
2146-
flags.doplot = true;
2147-
}
2148-
2149-
if(ai === 'dragmode' &&
2150-
(vi === 'lasso' || vi === 'select') &&
2151-
!(vOld === 'lasso' || vOld === 'select')
2152-
) {
2153-
flags.docalc = true;
2154-
}
2144+
else if(fullLayout._has('gl2d') &&
2145+
(ai.indexOf('axis') !== -1 || ai === 'plot_bgcolor')
2146+
) {
2147+
flags.doplot = true;
2148+
}
2149+
else if(fullLayout._has('gl2d') &&
2150+
(ai === 'dragmode' &&
2151+
(vi === 'lasso' || vi === 'select') &&
2152+
!(vOld === 'lasso' || vOld === 'select'))
2153+
) {
2154+
flags.docalc = true;
21552155
}
21562156
else if(ai === 'hiddenlabels') flags.docalc = true;
21572157
else if(proot.indexOf('legend') !== -1) flags.dolegend = true;

test/jasmine/tests/plot_api_test.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,76 @@ describe('Test plot api', function() {
254254
});
255255
});
256256

257+
describe('Plotly.relayout subroutines switchboard', function() {
258+
var mockedMethods = [
259+
'layoutReplot',
260+
'doLegend',
261+
'layoutStyles',
262+
'doTicksRelayout',
263+
'doModeBar',
264+
'doCamera'
265+
];
266+
267+
beforeAll(function() {
268+
mockedMethods.forEach(function(m) {
269+
spyOn(subroutines, m);
270+
});
271+
});
272+
273+
function mock(gd) {
274+
mockedMethods.forEach(function(m) {
275+
subroutines[m].calls.reset();
276+
});
277+
278+
Plots.supplyDefaults(gd);
279+
Plots.doCalcdata(gd);
280+
return gd;
281+
}
282+
283+
it('should trigger recalc when switching into select or lasso dragmode', function() {
284+
var gd = mock({
285+
data: [{
286+
type: 'scattergl',
287+
x: [1, 2, 3],
288+
y: [1, 2, 3]
289+
}],
290+
layout: {
291+
dragmode: 'zoom'
292+
}
293+
});
294+
295+
function expectModeBarOnly() {
296+
expect(gd.calcdata).toBeDefined();
297+
expect(subroutines.doModeBar).toHaveBeenCalled();
298+
expect(subroutines.layoutReplot).not.toHaveBeenCalled();
299+
}
300+
301+
function expectRecalc() {
302+
expect(gd.calcdata).toBeUndefined();
303+
expect(subroutines.doModeBar).not.toHaveBeenCalled();
304+
expect(subroutines.layoutReplot).toHaveBeenCalled();
305+
}
306+
307+
Plotly.relayout(gd, 'dragmode', 'pan');
308+
expectModeBarOnly();
309+
310+
Plotly.relayout(mock(gd), 'dragmode', 'lasso');
311+
expectRecalc();
312+
313+
Plotly.relayout(mock(gd), 'dragmode', 'select');
314+
expectModeBarOnly();
315+
316+
Plotly.relayout(mock(gd), 'dragmode', 'lasso');
317+
expectModeBarOnly();
318+
319+
Plotly.relayout(mock(gd), 'dragmode', 'zoom');
320+
expectModeBarOnly();
321+
322+
Plotly.relayout(mock(gd), 'dragmode', 'select');
323+
expectRecalc();
324+
});
325+
});
326+
257327
describe('Plotly.restyle subroutines switchboard', function() {
258328
beforeEach(function() {
259329
spyOn(PlotlyInternal, 'plot');

0 commit comments

Comments
 (0)