Skip to content

Commit 9dfc929

Browse files
authored
Merge pull request #1393 from plotly/cartesian-clean-ax-titles
Clear cartesian axis titles when deleting subplots
2 parents cab2b85 + c466e69 commit 9dfc929

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/plots/cartesian/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,14 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
166166

167167
if(hadCartesian && !hasCartesian) {
168168
var subplotLayers = oldFullLayout._cartesianlayer.selectAll('.subplot');
169+
var axIds = Axes.listIds({ _fullLayout: oldFullLayout });
169170

170171
subplotLayers.call(purgeSubplotLayers, oldFullLayout);
171172
oldFullLayout._defs.selectAll('.axesclip').remove();
173+
174+
for(i = 0; i < axIds.length; i++) {
175+
oldFullLayout._infolayer.select('.' + axIds[i] + 'title').remove();
176+
}
172177
}
173178
};
174179

test/jasmine/tests/cartesian_test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,40 @@ describe('relayout', function() {
306306
});
307307

308308
});
309+
310+
describe('subplot creation / deletion:', function() {
311+
312+
afterEach(destroyGraphDiv);
313+
314+
it('should clear orphan subplot when adding traces to blank graph', function(done) {
315+
316+
function assertCartesianSubplot(len) {
317+
expect(d3.select('.subplot.xy').size()).toEqual(len);
318+
expect(d3.select('.subplot.x2y2').size()).toEqual(len);
319+
expect(d3.select('.x2title').size()).toEqual(len);
320+
expect(d3.select('.x2title').size()).toEqual(len);
321+
expect(d3.select('.ytitle').size()).toEqual(len);
322+
expect(d3.select('.ytitle').size()).toEqual(len);
323+
}
324+
325+
Plotly.plot(createGraphDiv(), [], {
326+
xaxis: { title: 'X' },
327+
yaxis: { title: 'Y' },
328+
xaxis2: { title: 'X2', anchor: 'y2' },
329+
yaxis2: { title: 'Y2', anchor: 'x2' }
330+
})
331+
.then(function(gd) {
332+
assertCartesianSubplot(1);
333+
334+
return Plotly.addTraces(gd, [{
335+
type: 'scattergeo',
336+
lon: [10, 20, 30],
337+
lat: [20, 30, 10]
338+
}]);
339+
})
340+
.then(function() {
341+
assertCartesianSubplot(0);
342+
})
343+
.then(done);
344+
});
345+
});

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,28 @@ describe('Test gl plot interactions', function() {
363363
})
364364
.then(done);
365365
});
366+
367+
it('should clear orphan cartesian subplots on addTraces', function(done) {
368+
369+
Plotly.newPlot(gd, [], {
370+
xaxis: { title: 'X' },
371+
yaxis: { title: 'Y' }
372+
})
373+
.then(function() {
374+
return Plotly.addTraces(gd, [{
375+
type: 'scattergl',
376+
x: [1, 2, 3, 4, 5, 6, 7],
377+
y: [0, 5, 8, 9, 8, 5, 0]
378+
}]);
379+
})
380+
.then(function() {
381+
expect(d3.select('.subplot.xy').size()).toEqual(0);
382+
expect(d3.select('.xtitle').size()).toEqual(0);
383+
expect(d3.select('.ytitle').size()).toEqual(0);
384+
})
385+
.then(done);
386+
387+
});
366388
});
367389

368390
describe('gl3d event handlers', function() {

0 commit comments

Comments
 (0)