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

feat(axis): add tickLabelPadding prop #217

Merged
merged 22 commits into from
Jul 3, 2019
Merged

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented May 22, 2019

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:

  • Axis basic
  • Axis tick label rotation

Screen Shot 2019-05-21 at 10 48 32 AM

This functionality is also included as a theme for the bottom tick label padding:

Screen Shot 2019-05-21 at 10 49 29 AM

In the Stylings stories, there is a tickLabelPadding both prop and theme story included to show both the axis spec and theme manipulating tickLabelPadding.
PR217

Checklist

Use strikethroughs to 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

  • Unit tests were updated or added to match the most common scenarios
  • Each commit follows the convention

@codecov-io
Copy link

codecov-io commented May 22, 2019

Codecov Report

Merging #217 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/lib/themes/light_theme.ts 100% <ø> (ø) ⬆️
src/lib/series/specs.ts 100% <ø> (ø) ⬆️
src/lib/themes/dark_theme.ts 100% <ø> (ø) ⬆️
src/lib/series/rendering.ts 97.91% <100%> (+0.02%) ⬆️
src/lib/axes/axis_utils.ts 100% <100%> (ø) ⬆️
src/lib/axes/canvas_text_bbox_calculator.ts 100% <100%> (ø) ⬆️
src/lib/utils/commons.ts 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fc6640d...725177f. Read the comment docs.

@rshen91
Copy link
Contributor Author

rshen91 commented May 22, 2019

Copying from earlier PR

Have you tested to see what happens if there is an axis-specific padding configuration versus if it's on the theme itself? May be useful to have a story showing the difference (see the custom series styling stories for an example).

added commit 617d8695

@rshen91 rshen91 mentioned this pull request May 22, 2019
2 tasks
@markov00
Copy link
Member

hey @rshen91 is good to review or still a WIP?

@rshen91 rshen91 requested a review from markov00 May 22, 2019 20:53
@rshen91
Copy link
Contributor Author

rshen91 commented May 22, 2019

hey @rshen91 is good to review or still a WIP?

Sorry about that @markov00! Please feel free to review when you have a chance

Copy link
Contributor

@emmacunningham emmacunningham left a 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

src/components/react_canvas/axis.tsx Outdated Show resolved Hide resolved
stories/axis.tsx Outdated Show resolved Hide resolved
stories/styling.tsx Outdated Show resolved Hide resolved
src/lib/series/specs.ts Outdated Show resolved Hide resolved
src/lib/series/rendering.ts Outdated Show resolved Hide resolved
@@ -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> {
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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!

Copy link
Contributor Author

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 👌

rshen91 added 9 commits May 23, 2019 08:10
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
@markov00 markov00 changed the title add tickLabelPadding prop feat: add tickLabelPadding prop May 31, 2019
@markov00 markov00 added :chart Chart element related issue enhancement New feature or request labels May 31, 2019
Copy link
Member

@markov00 markov00 left a 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.

src/lib/themes/light_theme.ts Show resolved Hide resolved
@markov00
Copy link
Member

markov00 commented Jun 6, 2019

jenkins test this please

@emmacunningham emmacunningham changed the title feat: add tickLabelPadding prop feat(axis): add tickLabelPadding prop Jun 6, 2019
@emmacunningham emmacunningham removed the :chart Chart element related issue label Jun 6, 2019
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@markov00
Copy link
Member

markov00 commented Jun 10, 2019

@emmacunningham @rshen91 what do you think if we extend this PR to support custom axis styles?
because what is the meaning of having only the padding as a separate spec property here?
What if we extend this to have something that accept custom style for axis like:

<Axis
  id={getAxisId('bottom')}	        
  position={Position.Bottom}	        
  title={'Bottom axis'}	          
  showOverlappingTicks={true}
  style={{
    tickLabelStyle: {
      padding: 10
    }
  }}
/>	 

@markov00 markov00 self-requested a review June 10, 2019 17:03
if (!this.context) {
return none;
}

// Avoid having negative padding that can obscure text
Copy link
Collaborator

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.

Copy link
Contributor Author

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!

Copy link
Collaborator

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

image

Then you will get something like this...

"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.

Copy link
Contributor Author

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

Copy link
Collaborator

@nickofthyme nickofthyme left a comment

Choose a reason for hiding this comment

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

LGTM, tested locally.

@emmacunningham
Copy link
Contributor

emmacunningham commented Jul 1, 2019

@rshen91 let's chat on zoom about how to do this.

@emmacunningham @rshen91 what do you think if we extend this PR to support custom axis styles?
because what is the meaning of having only the padding as a separate spec property here?
What if we extend this to have something that accept custom style for axis like:

<Axis
  id={getAxisId('bottom')}	        
  position={Position.Bottom}	        
  title={'Bottom axis'}	          
  showOverlappingTicks={true}
  style={{
    tickLabelStyle: {
      padding: 10
    }
  }}
/>	 

Commit 776239a to address

const tickLabelPadding =
axisSpec.style && axisSpec.style.tickLabelPadding
? axisSpec.style.tickLabelPadding
: axisConfig.tickLabelStyle.padding;
Copy link
Contributor

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.

Copy link
Contributor Author

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

@rshen91 rshen91 requested a review from emmacunningham July 3, 2019 15:04
Copy link
Member

@markov00 markov00 left a 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

src/lib/axes/axis_utils.ts Outdated Show resolved Hide resolved
src/lib/series/specs.ts Show resolved Hide resolved
@rshen91 rshen91 requested a review from markov00 July 3, 2019 17:11
Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

@rshen91 rshen91 merged commit 4d40936 into elastic:master Jul 3, 2019
markov00 pushed a commit that referenced this pull request Jul 3, 2019
# [7.1.0](v7.0.2...v7.1.0) (2019-07-03)

### Features

* **axis:** add tickLabelPadding prop ([#217](#217)) ([4d40936](4d40936)), closes [#94](#94)
@markov00
Copy link
Member

markov00 commented Jul 3, 2019

🎉 This PR is included in version 7.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@markov00 markov00 added the released Issue released publicly label Jul 3, 2019
@rshen91 rshen91 deleted the rshen-94 branch July 3, 2019 19:37
AMoo-Miki pushed a commit to AMoo-Miki/OpenSearch-Dashboards that referenced this pull request Feb 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:axis Axis related issue enhancement New feature or request released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tick label padding to axis spec
5 participants