Skip to content

Improve padding logic for updatemenus #989

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

Merged
merged 2 commits into from
Sep 29, 2016
Merged

Conversation

rreusser
Copy link
Contributor

@rreusser rreusser commented Sep 28, 2016

See #985
cc @etpinard

This PR improves padding logic for updatemenus. It implements pad: {t, r, b, l} at the individual-updatemenu level. I didn't apply unit testing, but did beef up the image mock to really ensure that I've tested the permutations.

The general logic:

  1. After computing the minimum required size of the container in order to fit the content, it adds the padding onto each side.
  2. After expanding the padding, the anchor logic is applied.

The order of operations makes a slight difference, but the general concept is that this applies within the container first, then to the overall layout as expected. I think this is by far the most intuitive and easy way to accomplish this, and meets the need.

Unfortunately it's not that straightforward to document image mocks, and I'd rather not have (literally) sixty mocks to verify all aspects of the positioning, and I think it's best to avoid testing visual alignment in the unit tests.

So on that note, here's the improved mock with the anchor annotated in blue and padding annotated in red:

screen-shot-2016-09-28-at-17 22 49

@rreusser
Copy link
Contributor Author

Note that I did not set a minimum value: 0 for padding. Since we don't share the full generality of the html box model, I feel like negative padding could be a usefully obscure option to have available since we don't have pixel margins to worth with.

@rreusser
Copy link
Contributor Author

rreusser commented Sep 28, 2016

Relayout test to be added; battery is at 5% so will be up, but not right at the moment. Otherwise complete and reviewable.

@etpinard etpinard added the feature something new label Sep 28, 2016
@etpinard etpinard added this to the v1.18.0 milestone Sep 28, 2016
Copy link
Contributor

@etpinard etpinard left a comment

Choose a reason for hiding this comment

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

@rreusser this is looking great. Nice addition!

Ping me again once that relayout test is in.

@@ -11,6 +11,7 @@
var fontAttrs = require('../../plots/font_attributes');
var colorAttrs = require('../color/attributes');
var extendFlat = require('../../lib/extend').extendFlat;
var padAttrs = require('../../plots/pad_attributes');
Copy link
Contributor

@etpinard etpinard Sep 28, 2016

Choose a reason for hiding this comment

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

That's where pad_attributes.js belongs at the moment, but I hate to see so many files pile up in the src/plots/ root.

Maybe we could add a src/plots/common/folder? or src/components/common/? or even a src/common/ for similar shared modules.

Copy link
Contributor Author

@rreusser rreusser Sep 28, 2016

Choose a reason for hiding this comment

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

Agreed. Font attributes would probably go with it? At least internal reorg is easy refactoring (especially since static requires so that errors fail bundling), so can try to cut down on plots/ bit by bit (pun?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Font attributes would probably go with it?

yep, exactly.

so can try to cut down on plots/ bit by bit (pun?)

No action required in this PR. I just wanted to mention something I've been thinking about for a while now.

l: paddedWidth * ({right: 1, center: 0.5}[xanchor] || 0),
r: paddedWidth * ({left: 1, center: 0.5}[xanchor] || 0),
b: paddedHeight * ({top: 1, middle: 0.5}[yanchor] || 0),
t: paddedHeight * ({bottom: 1, middle: 0.5}[yanchor] || 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow. That was easy. I love it!

@rreusser
Copy link
Contributor Author

@etpinard will do. Have run out of steam at the moment, but will aim to have it good to go first thing tomorrow.

@rreusser
Copy link
Contributor Author

ping @etpinard — added relayout tests that at least confirms a couple basic things about padding getting updated and making some sense.

@etpinard
Copy link
Contributor

This is working great. Thanks! 💃

@rreusser merge away

@rreusser rreusser merged commit fce36fa into master Sep 29, 2016
@rreusser rreusser deleted the fix-updatemenus-padding branch September 29, 2016 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants