Skip to content
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

Set Cartesian axis attributes via template #4670

Merged
merged 7 commits into from
Mar 25, 2020
Merged

Conversation

archmoj
Copy link
Contributor

@archmoj archmoj commented Mar 22, 2020

Commit 5f8b280 addresses #4667 i.e. to set axis type, rangebreaks and tickformatstops from
template.

@plotly/plotly_js

@archmoj archmoj added bug something broken status: reviewable labels Mar 22, 2020
@archmoj archmoj added this to the v1.53.0 milestone Mar 22, 2020
@archmoj archmoj changed the title Set axis type, rangebreaks and tickformatstops from template apply template in handleArrayContainerDefaults Mar 23, 2020
@nicolaskruchten
Copy link
Contributor

I think we should leave #4671 alone for now please... this code already works as desired for e.g. annotations. Check out this Python example: https://plot.ly/python/templates/#including-tuple-elements-in-a-theme

@archmoj
Copy link
Contributor Author

archmoj commented Mar 23, 2020

In JS, it appears those were not working before | after.

@nicolaskruchten @alexcjohnson am I missing something?

@nicolaskruchten
Copy link
Contributor

This works for me with the production bundle: https://codepen.io/nicolaskruchten/pen/wvaENrm?editors=0010

@nicolaskruchten
Copy link
Contributor

@alexcjohnson I'll let you judge the safety of these changes, keeping in mind that I would rather keep existing bugs in the interests of getting 1.53 and 1.54 done ASAP and not introducing subtle new bugs. For 1.53 we just need rangebreaks and hovermode = "* unified" to work with templates IMO.

@alexcjohnson
Copy link
Collaborator

@archmoj the way templates interact with container arrays is a bit subtle as it contains features for both defaults for all array items and overrides for specific items (which may not be at the same index in the array), but in general it works. Take a look at the original templates PR #2761, esp. this test and the arrayTemplater function

Please use those for context before deciding what's a bug.

@archmoj archmoj changed the title apply template in handleArrayContainerDefaults Set Cartesian axis attributes via template Mar 23, 2020
@nicolaskruchten
Copy link
Contributor

Ah, with respect to your before/after: you need to set name for that to work... https://plot.ly/javascript/reference/#layout-annotations-items-annotation-name

if(containerOut.type === 'date') {
var rangebreaks = containerIn.rangebreaks;
if(axType === 'date') {
var rangebreaks = containerIn.rangebreaks || axTemplate.rangebreaks;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't quite right... [] is truthy, also axTemplate.rangeBreaks items will extend the array if it contains named items.

Can we instead do:

handleArrayContainerDefaults(...);

if (containerOut.rangebreaks.length) {
   // setConvert and gl / splom check
}
else {
   delete containerOut.rangebreaks;
}

Same for tickformatstops

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 idea. Done in f824902.

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

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

💃 Love it. Thanks for catching these!

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.

3 participants