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

Fix: Prevent loss of domain information when template field is present in layout #7283

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

marthacryan
Copy link
Collaborator

@marthacryan marthacryan commented Nov 22, 2024

Alternative fix to plotly/plotly.py#4794. Other fix is #7282.

Context:

  • @alexcjohnson noted that Fix: Switch template edit type to plot #7282 didn't seem like the right fix because changing editType from 'calc' to 'plot' is more of a downgrade than something that should fix this issue.
  • I pointed out this particular line should be resetting the _inputDomain, but that this line was returning in diffFlags before it reached the yaxis to reset it
  • Alex said that the fact that we're resetting _inputDomain in the changed function was actually incorrect. It should be reset in its own separate crawl of the layout.
  • We decided to put the reset of _inputDomain into the diffLayout function because it has access to both the old layout and the new layout.

newFullLayout[key].domain = oldFullLayout[key].domain;
} else if (newDomain[0] !== oldDomain[0] || newDomain[1] !== oldDomain[1]) {
// what you're asking for HAS changed, so clear _inputDomain and let us start from scratch
newFullLayout[key]._inputDomain = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think nestedProperty(...).set(null) is actually equivalent to delete newFullLayout[key]._inputDomain

Copy link
Contributor

Choose a reason for hiding this comment

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

@alexcjohnson Using delete may be slower comparing to setting to null. No?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose that’s faster and should be equivalent. This is not a high volume operation so I wouldn’t be too concerned about it, but we can leave it if you prefer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was using this syntax for consistency with the other places in the codebase that delete this field, but I don't have a strong opinion on which we use.

Copy link
Contributor

Choose a reason for hiding this comment

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

@marthacryan Maybe worth leaving a comment explaining why we do nothing in the else case? (I know we discussed but... for posterity)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yeah good point Emily!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@alexcjohnson I added a comment explaining the else case based off of this explanation from you about that case:
"this situation is perhaps actually ambiguous: did you pass back in the previous layout as modified by Plotly.js, so we should assume you really wanted _inputDomain to still apply? or did you explicitly set the new domain and it just happened to match the old final calculated domain - in which case we should clear _inputDomain. I guess generally oldDomain will be some random floating point number so it's unlikely you matched it exactly. better to assume you passed back in the same layout object and change nothing in this case."

Let me know if you have any corrections!

@archmoj
Copy link
Contributor

archmoj commented Nov 25, 2024

@marthacryan Thanks very much for another excellent PR. 🏆
Please use Fix: prefix in the PR title and also add a draft log.
You may also consider revisiting the PR title so that it reflects the fix from the user's perspective.

@marthacryan marthacryan changed the title Clear inputDomain in diffLayout Fix: Clear inputDomain in diffLayout Nov 25, 2024
@archmoj
Copy link
Contributor

archmoj commented Nov 25, 2024

@marthacryan Could you please add a test to lock the bug you fixed in this PR?
You may add a it block (and then if you like to just run the new test, temporarily change it from it to fit) in test/jasmine/tests/plot_api_test.js and use npm run test-jasmine plot_api.
Obviously this new test should fail before your changes and should pass after the changes.
Thank you!

@marthacryan
Copy link
Collaborator Author

@marthacryan Could you please add a test to lock the bug you fixed in this PR? You may add a it block (and then if you like to just run the new test, temporarily change it from it to fit) in test/jasmine/tests/plot_api_test.js and use npm run test-jasmine plot_api. Obviously this new test should fail before your changes and should pass after the changes. Thank you!

@archmoj Done! I added it to the axes_tests.js file instead because there were a lot of relevant tests and utils in that file. It fails on master but passes on this branch.

@marthacryan marthacryan changed the title Fix: Clear inputDomain in diffLayout Fix: Prevent loss of domain information when template field is present in layout Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants