-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ternary w/o ticks fixes #2993
Ternary w/o ticks fixes #2993
Conversation
|
||
exports.supplyLayoutDefaults = require('./layout/defaults'); | ||
exports.supplyLayoutDefaults = require('./layout_defaults'); |
There was a problem hiding this comment.
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 👍
@@ -430,6 +457,11 @@ proto.drawAxes = function(doTitles) { | |||
} | |||
}; | |||
|
|||
function strTickLayout(axLayout) { | |||
return axLayout.ticks + String(axLayout.ticklen) + String(axLayout.showticklabels); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
plotly.js/test/jasmine/tests/ternary_test.js
Lines 352 to 383 in 2a667d0
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:
plotly.js/src/plots/cartesian/axes.js
Lines 1550 to 1555 in 2a667d0
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.
test/jasmine/tests/ternary_test.js
Outdated
'.aaxis > .ytick > text', | ||
'ternary.aaxis.showticklabels', | ||
[true, false], [4, 0] | ||
); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
Nice fix. 💃 |
Fixes #2897
I initially wanted to fix this issue by implementing
editType: 'ticks'
in ternary axes (and polar axes which useAxis.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-guesseditType: '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