Skip to content

Commit 937f5cf

Browse files
committed
fix and 🔒 ticks and tick labels hide/show edits
1 parent 05f58ce commit 937f5cf

File tree

2 files changed

+108
-6
lines changed

2 files changed

+108
-6
lines changed

src/plots/ternary/ternary.js

+38-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ function Ternary(options, fullLayout) {
3434
this.graphDiv = options.graphDiv;
3535
this.init(fullLayout);
3636
this.makeFramework(fullLayout);
37+
38+
// unfortunately, we have to keep track of some axis tick settings
39+
// as ternary subplots do not implement the 'ticks' editType
40+
this.aTickLayout = null;
41+
this.bTickLayout = null;
42+
this.cTickLayout = null;
3743
}
3844

3945
module.exports = Ternary;
@@ -375,12 +381,33 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
375381
};
376382

377383
proto.drawAxes = function(doTitles) {
378-
var _this = this,
379-
gd = _this.graphDiv,
380-
titlesuffix = _this.id.substr(7) + 'title',
381-
aaxis = _this.aaxis,
382-
baxis = _this.baxis,
383-
caxis = _this.caxis;
384+
var _this = this;
385+
var gd = _this.graphDiv;
386+
var titlesuffix = _this.id.substr(7) + 'title';
387+
var layers = _this.layers;
388+
var aaxis = _this.aaxis;
389+
var baxis = _this.baxis;
390+
var caxis = _this.caxis;
391+
var newTickLayout;
392+
393+
newTickLayout = strTickLayout(aaxis);
394+
if(_this.aTickLayout !== newTickLayout) {
395+
layers.aaxis.selectAll('.ytick').remove();
396+
_this.aTickLayout = newTickLayout;
397+
}
398+
399+
newTickLayout = strTickLayout(baxis);
400+
if(_this.bTickLayout !== newTickLayout) {
401+
layers.baxis.selectAll('.xtick').remove();
402+
_this.bTickLayout = newTickLayout;
403+
}
404+
405+
newTickLayout = strTickLayout(caxis);
406+
if(_this.cTickLayout !== newTickLayout) {
407+
layers.caxis.selectAll('.ytick').remove();
408+
_this.cTickLayout = newTickLayout;
409+
}
410+
384411
// 3rd arg true below skips titles, so we can configure them
385412
// correctly later on.
386413
Axes.doTicksSingle(gd, aaxis, true);
@@ -430,6 +457,11 @@ proto.drawAxes = function(doTitles) {
430457
}
431458
};
432459

460+
function strTickLayout(axLayout) {
461+
return axLayout.ticks + String(axLayout.ticklen) + String(axLayout.showticklabels);
462+
}
463+
464+
433465
// hard coded paths for zoom corners
434466
// uses the same sizing as cartesian, length is MINZOOM/2, width is 3px
435467
var CLEN = constants.MINZOOM / 2 + 0.87;

test/jasmine/tests/ternary_test.js

+70
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,76 @@ describe('ternary plots', function() {
382382
.then(done);
383383
});
384384

385+
it('should be able to hide/show ticks and tick labels', function(done) {
386+
var gd = createGraphDiv();
387+
var fig = Lib.extendDeep({}, require('@mocks/ternary_simple.json'));
388+
389+
function assertCnt(selector, expected, msg) {
390+
var sel = d3.select(gd).selectAll(selector);
391+
expect(sel.size()).toBe(expected, msg);
392+
}
393+
394+
function toggle(selector, astr, vals, exps) {
395+
return Plotly.relayout(gd, astr, vals[0]).then(function() {
396+
assertCnt(selector, exps[0], astr + ' ' + vals[0]);
397+
return Plotly.relayout(gd, astr, vals[1]);
398+
})
399+
.then(function() {
400+
assertCnt(selector, exps[1], astr + ' ' + vals[1]);
401+
return Plotly.relayout(gd, astr, vals[0]);
402+
})
403+
.then(function() {
404+
assertCnt(selector, exps[0], astr + ' ' + vals[0]);
405+
});
406+
}
407+
408+
Plotly.plot(gd, fig)
409+
.then(function() {
410+
return toggle(
411+
'.aaxis > .ytick > text',
412+
'ternary.aaxis.showticklabels',
413+
[true, false], [4, 0]
414+
);
415+
})
416+
.then(function() {
417+
return toggle(
418+
'.baxis > .xtick > text',
419+
'ternary.baxis.showticklabels',
420+
[true, false], [5, 0]
421+
);
422+
})
423+
.then(function() {
424+
return toggle(
425+
'.caxis > .ytick > text',
426+
'ternary.caxis.showticklabels',
427+
[true, false], [4, 0]
428+
);
429+
})
430+
.then(function() {
431+
return toggle(
432+
'.aaxis > path.ytick',
433+
'ternary.aaxis.ticks',
434+
['outside', ''], [4, 0]
435+
);
436+
})
437+
.then(function() {
438+
return toggle(
439+
'.baxis > path.xtick',
440+
'ternary.baxis.ticks',
441+
['outside', ''], [5, 0]
442+
);
443+
})
444+
.then(function() {
445+
return toggle(
446+
'.caxis > path.ytick',
447+
'ternary.caxis.ticks',
448+
['outside', ''], [4, 0]
449+
);
450+
})
451+
.catch(failTest)
452+
.then(done);
453+
});
454+
385455
it('should render a-axis and c-axis with negative offsets', function(done) {
386456
var gd = createGraphDiv();
387457

0 commit comments

Comments
 (0)