Skip to content

Commit b4af46f

Browse files
committed
clear ternary axis titles when ternary subplots are removed
- to do so more easily, make Titles.draw return the title group element.
1 parent 5422da9 commit b4af46f

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/components/titles/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ var numStripRE = / [XY][0-9]* /;
5151
* offset - shift up/down in the rotated frame (unused?)
5252
* containerGroup - if an svg <g> element already exists to hold this
5353
* title, include here. Otherwise it will go in fullLayout._infolayer
54+
*
55+
* @return {selection} d3 selection of title container group
5456
*/
5557
Titles.draw = function(gd, titleClass, options) {
5658
var cont = options.propContainer;
@@ -111,7 +113,7 @@ Titles.draw = function(gd, titleClass, options) {
111113
.attr('class', titleClass);
112114
el.exit().remove();
113115

114-
if(!elShouldExist) return;
116+
if(!elShouldExist) return group;
115117

116118
function titleLayout(titleEl) {
117119
Lib.syncOrAsync([drawTitle, scootTitle], titleEl);
@@ -236,4 +238,6 @@ Titles.draw = function(gd, titleClass, options) {
236238
});
237239
}
238240
el.classed('js-placeholder', isplaceholder);
241+
242+
return group;
239243
};

src/plots/ternary/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout)
6767
oldTernary.plotContainer.remove();
6868
oldTernary.clipDef.remove();
6969
oldTernary.clipDefRelative.remove();
70+
oldTernary.layers['a-title'].remove();
71+
oldTernary.layers['b-title'].remove();
72+
oldTernary.layers['c-title'].remove();
7073
}
7174
}
7275
};

src/plots/ternary/ternary.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ proto.drawAxes = function(doTitles) {
380380
var apad = Math.max(aaxis.showticklabels ? aaxis.tickfont.size / 2 : 0,
381381
(caxis.showticklabels ? caxis.tickfont.size * 0.75 : 0) +
382382
(caxis.ticks === 'outside' ? caxis.ticklen * 0.87 : 0));
383-
Titles.draw(gd, 'a' + titlesuffix, {
383+
_this.layers['a-title'] = Titles.draw(gd, 'a' + titlesuffix, {
384384
propContainer: aaxis,
385385
propName: _this.id + '.aaxis.title',
386386
placeholder: _(gd, 'Click to enter Component A title'),
@@ -391,10 +391,11 @@ proto.drawAxes = function(doTitles) {
391391
}
392392
});
393393

394+
394395
var bpad = (baxis.showticklabels ? baxis.tickfont.size : 0) +
395396
(baxis.ticks === 'outside' ? baxis.ticklen : 0) + 3;
396397

397-
Titles.draw(gd, 'b' + titlesuffix, {
398+
_this.layers['b-title'] = Titles.draw(gd, 'b' + titlesuffix, {
398399
propContainer: baxis,
399400
propName: _this.id + '.baxis.title',
400401
placeholder: _(gd, 'Click to enter Component B title'),
@@ -405,7 +406,7 @@ proto.drawAxes = function(doTitles) {
405406
}
406407
});
407408

408-
Titles.draw(gd, 'c' + titlesuffix, {
409+
_this.layers['c-title'] = Titles.draw(gd, 'c' + titlesuffix, {
409410
propContainer: caxis,
410411
propName: _this.id + '.caxis.title',
411412
placeholder: _(gd, 'Click to enter Component C title'),

test/jasmine/tests/ternary_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,42 @@ describe('ternary plots', function() {
5959
});
6060

6161
it('should be able to delete and add traces', function(done) {
62+
function checkTitles(cnt) {
63+
expect(d3.selectAll('.g-atitle').size()).toBe(cnt, 'aaxis title');
64+
expect(d3.selectAll('.g-btitle').size()).toBe(cnt, 'baxis title');
65+
expect(d3.selectAll('.g-ctitle').size()).toBe(cnt, 'caxis title');
66+
}
67+
6268
expect(countTernarySubplot()).toEqual(1);
6369
expect(countTraces('scatter')).toEqual(1);
70+
checkTitles(1);
6471

6572
Plotly.deleteTraces(gd, [0]).then(function() {
6673
expect(countTernarySubplot()).toEqual(0);
6774
expect(countTraces('scatter')).toEqual(0);
75+
checkTitles(0);
6876

6977
var trace = Lib.extendDeep({}, mock.data[0]);
7078

7179
return Plotly.addTraces(gd, [trace]);
7280
}).then(function() {
7381
expect(countTernarySubplot()).toEqual(1);
7482
expect(countTraces('scatter')).toEqual(1);
83+
checkTitles(1);
7584

7685
var trace = Lib.extendDeep({}, mock.data[0]);
7786

7887
return Plotly.addTraces(gd, [trace]);
7988
}).then(function() {
8089
expect(countTernarySubplot()).toEqual(1);
8190
expect(countTraces('scatter')).toEqual(2);
91+
checkTitles(1);
8292

8393
return Plotly.deleteTraces(gd, [0]);
8494
}).then(function() {
8595
expect(countTernarySubplot()).toEqual(1);
8696
expect(countTraces('scatter')).toEqual(1);
97+
checkTitles(1);
8798

8899
done();
89100
});

0 commit comments

Comments
 (0)