-
Notifications
You must be signed in to change notification settings - Fork 121
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
feat(axis): add tickLabelPadding prop #217
Conversation
Codecov Report
@@ Coverage Diff @@
## master #217 +/- ##
==========================================
+ Coverage 97.76% 97.77% +0.01%
==========================================
Files 36 36
Lines 2636 2654 +18
Branches 588 612 +24
==========================================
+ Hits 2577 2595 +18
Misses 52 52
Partials 7 7
Continue to review full report at Codecov.
|
Copying from earlier PR
added commit |
hey @rshen91 is good to review or still a WIP? |
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.
left a few more comments and a question for discussion
@@ -17,7 +17,7 @@ export class CanvasTextBBoxCalculator implements BBoxCalculator { | |||
this.attachedRoot.appendChild(this.offscreenCanvas); | |||
this.scaledFontSize = scaledFontSize; | |||
} | |||
compute(text: string, fontSize = 16, fontFamily = 'Arial', padding: number = 1): Option<BBox> { | |||
compute(text: string, padding: number, fontSize = 16, fontFamily = 'Arial'): Option<BBox> { |
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.
@markov00 What do you think about doing some validation to prevent negative padding and if the supplied padding argumen is less than 1, set the padding to 1 instead? And we could also surface this in our configuration warnings once we have those. We are already accounting for padding in the computation of the label and if the user specifies a negative padding, then the text box would not be wide enough for the label.
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.
Yes I'm ok to add some validation here to prevent negative padding.
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.
Added commit edb1f4b to address
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.
test added in 1507d9c to address
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.
Just to confirm - should we set the padding to 1 when it's specified by the user at 0? Or should the validation only catch negative values? Thanks!
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.
Clarified in zoom with Emma about this 👌
hardcoded in axis.tsx marked optional in specs.ts feat(axis_utils axis axis_utils.test): tickLabelPadding in axis_utils
refactor(added testUserInput number in knob): wip broken build
docs(axis): add storybook knob to tickLabelPadding prop feat(axis): add bottom axis tick label padding prop feat(rotations): add tickLabelPadding prop feat(bar_chart): add tickLabelPadding prop
feat(axis_utils): specify tickLabelPadding from axisSpec or axisConfig feat(bbox_calc axis_utils): remove optional padding for tickLabelPadding
refactor(axis_utils rendering): change parameter order and whitespace docs(chart_state): remove testUserInput test prop
style(stories/axis.tsx): remove explicit renderer for axis basic refactor(bar_chart rotations stories): remove tickLabelPadding
feat(specs.ts stories/axis.tsx): included tickLabelPadding prop hardcoded in axis.tsx marked optional in specs.ts style(react_canvas/axis): improve comment for padding 0
style(specs.ts): improve comment for tickLabelPadding spec
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.
Everything seems to work correctly. I've just add a comment to address before merge.
I'm still seeing various indentation errors, but we will fix this moving from tslint + prettier to eslint + prettier soon.
jenkins test this please |
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.
LGTM! 🚀
@emmacunningham @rshen91 what do you think if we extend this PR to support custom axis styles?
|
if (!this.context) { | ||
return none; | ||
} | ||
|
||
// Avoid having negative padding that can obscure text |
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.
I'd say generally comments as simple as this can be left for tests. Meaning you should create test cases that validate this line of code. That way if someone removes these lines of code, the tests break.
Not saying you can't leave comments, but do so for more complex code that requires explanation.
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.
Ok! I think I wrote one that gets to the issue in commit 1507d9c
. Let me know what you think thanks!
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.
FYI Github will auto link and format the commit hash when you just put the hash or short hash like this 1507d9c but when you wrap the hash in backticks, or anything else for that matter, it doesn't create the link like this 1507d9c
. Here is a link to all the url fun https://help.github.com/en/articles/autolinked-references-and-urls
You can also paste code snippets by selecting code lines, use shift+click for multiple lines, and select copy permalink
Then you will get something like this...
Lines 14 to 16 in f2b90df
"scripts": { | |
"cz": "git-cz", | |
"build:clean": "rm -rf ./dist", |
Just FYI - It took me a while to realize how many helpful tools GH has for our use.
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.
improved comment in commit d8dd8f4
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.
LGTM, tested locally.
@rshen91 let's chat on zoom about how to do this.
Commit 776239a to address |
src/lib/axes/axis_utils.ts
Outdated
const tickLabelPadding = | ||
axisSpec.style && axisSpec.style.tickLabelPadding | ||
? axisSpec.style.tickLabelPadding | ||
: axisConfig.tickLabelStyle.padding; |
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.
Can we rename this parameter name to themeAxisConfig
to make it clearer where this is coming from? I think eventually we'll want to think about how to better merge spec-specific and theme-general styles but for now, would be nice to update the parameter name.
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.
Thank you for helping me with this! The commit with the changes in naming and improving axis_utils test is addressed in commit d8dd8f4
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.
@rshen91 I've added two comments, the one of the if
check needs to be addressed before merging.
the other can be done also on a different PR if we want
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.
LGTM! 🚀
🎉 This PR is included in version 7.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
# [7.1.0](elastic/elastic-charts@v7.0.2...v7.1.0) (2019-07-03) ### Features * **axis:** add tickLabelPadding prop ([opensearch-project#217](elastic/elastic-charts#217)) ([080df95](elastic/elastic-charts@080df95)), closes [opensearch-project#94](elastic/elastic-charts#94)
Summary
Closes #94
This is a duplicate of the closed PR #176 (closed in error)
Allows users to specify a tick label padding for charts. In storybook, when debug is checked, the user can add a specified tick label padding number to the bottom axis and rotations with ordinal axis.
In storybook this can be seen in the following charts:
This functionality is also included as a theme for the bottom tick label padding:
In the Stylings stories, there is a tickLabelPadding both prop and theme story included to show both the axis spec and theme manipulating tickLabelPadding.
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.- [ ] This was checked for cross-browser compatibility, including a check against IE11- [ ] Proper documentation or storybook story was added for features that require explanation or tutorials