Skip to content

Conversation

etpinard
Copy link
Contributor

Fixes #2897

I initially wanted to fix this issue by implementing editType: 'ticks' in ternary axes (and polar axes which use Axis.doTicks in a similar way), but that turned out to be a little too messy for a bug-fix PR. I'm even starting to second-guess editType: 'ticks' all together.

So, ternary axis tick and tick labels updates as now as bad as for polar subplots - where they make use of a "state" fields (one for each axis) on the ternary subplot objects. Oh well, at least we now have a few tests locking the behavior down.

cc @alexcjohnson @antoinerg

@etpinard etpinard added bug something broken status: reviewable labels Sep 10, 2018
exports.layoutAttributes = require('./layout_attributes');

exports.supplyLayoutDefaults = require('./layout/defaults');
exports.supplyLayoutDefaults = require('./layout_defaults');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call flattening this structure 👍

};

function strTickLayout(axLayout) {
return axLayout.ticks + String(axLayout.ticklen) + String(axLayout.showticklabels);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other inherited attributes that have editType: 'ticks' in cartesian... how did you know which ones need to be included here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Axes.doTicks is able to re-style existing nodes (e.g. relayout calls involving tickfont) e.g. see this test:

it('should be able to relayout axis tickfont attributes', function(done) {
var gd = createGraphDiv();
var fig = Lib.extendDeep({}, require('@mocks/ternary_simple.json'));
function _assert(family, color, size) {
var tick = d3.select('g.aaxis > g.ytick > text').node();
expect(tick.style['font-family']).toBe(family, 'font family');
expect(parseFloat(tick.style['font-size'])).toBe(size, 'font size');
expect(tick.style.fill).toBe(color, 'font color');
}
Plotly.plot(gd, fig).then(function() {
_assert('"Open Sans", verdana, arial, sans-serif', 'rgb(204, 204, 204)', 12);
return Plotly.relayout(gd, 'ternary.aaxis.tickfont.size', 5);
})
.then(function() {
_assert('"Open Sans", verdana, arial, sans-serif', 'rgb(204, 204, 204)', 5);
return Plotly.relayout(gd, 'ternary.aaxis.tickfont', {
family: 'Roboto',
color: 'red',
size: 20
});
})
.then(function() {
_assert('Roboto', 'rgb(255, 0, 0)', 20);
})
.catch(failTest)
.then(done);
});

but it can't handle hide/show. Cartesian axes rely on this block:

plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick').remove();
plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick').remove();
if(plotinfo.gridlayer) plotinfo.gridlayer.selectAll('path').remove();
if(plotinfo.zerolinelayer) plotinfo.zerolinelayer.selectAll('path').remove();
fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();
fullLayout._infolayer.select('.g-' + ya._id + 'title').remove();

which isn't compatible with non-cartesian subplots.

'.aaxis > .ytick > text',
'ternary.aaxis.showticklabels',
[true, false], [4, 0]
);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor style comment: you can put the extra function wrapping inside the definition of toggle, so that the individual calls are just .then(toggle(...))

Regardless toggle is a very nice simplification!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Done in -> 68e0628

@alexcjohnson
Copy link
Collaborator

Nice fix. 💃

@etpinard etpinard merged commit 1fceea8 into master Sep 11, 2018
@etpinard etpinard deleted the ternary-noticks branch September 11, 2018 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug something broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

showticklabels in ternary is broken if false

2 participants