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

add tickLabelPadding prop #176

Closed
wants to merge 0 commits into from
Closed

add tickLabelPadding prop #176

wants to merge 0 commits into from

Conversation

rshen91
Copy link
Contributor

@rshen91 rshen91 commented Apr 17, 2019

Summary

Closes #94

Allows users to specify a debug tick label padding for charts. 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

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

@rshen91 rshen91 changed the title tickLabelPadding prop [WIP] add tickLabelPadding prop Apr 17, 2019
@markov00
Copy link
Member

@rshen91 thanks for the work you are doing here.
@emmacunningham do we want to have this as a props for the axis or as a theme configuration?

@emmacunningham
Copy link
Contributor

@markov00 Ah good point. Perhaps it can be that there's a default padding amount in the theme and if the user wants a specific padding amount for just one axis, then they can use the axis prop to specify it for just one axis?

@codecov-io
Copy link

codecov-io commented Apr 18, 2019

Codecov Report

Merging #176 into master will increase coverage by 0.4%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #176     +/-   ##
=========================================
+ Coverage    97.4%   97.81%   +0.4%     
=========================================
  Files          35       35             
  Lines        2120     2560    +440     
  Branches      315      558    +243     
=========================================
+ Hits         2065     2504    +439     
- Misses         48       49      +1     
  Partials        7        7
Impacted Files Coverage Δ
src/lib/themes/light_theme.ts 100% <ø> (ø) ⬆️
src/lib/series/specs.ts 100% <ø> (ø) ⬆️
src/lib/series/rendering.ts 97.84% <100%> (+0.36%) ⬆️
src/lib/axes/axis_utils.ts 100% <100%> (ø) ⬆️
src/lib/axes/canvas_text_bbox_calculator.ts 100% <100%> (ø) ⬆️
src/state/crosshair_utils.ts 84.12% <0%> (-0.19%) ⬇️
src/specs/settings.tsx 100% <0%> (ø) ⬆️
src/state/annotation_utils.ts 100% <0%> (ø) ⬆️
src/lib/themes/theme.ts 100% <0%> (ø) ⬆️
src/lib/series/domains/y_domain.ts 100% <0%> (ø) ⬆️
... and 21 more

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 e38e8f6...b66f0b5. Read the comment docs.

@emmacunningham emmacunningham added wip work in progress :axis Axis related issue labels Apr 18, 2019
@rshen91 rshen91 requested a review from emmacunningham May 20, 2019 22:42
@emmacunningham emmacunningham removed the wip work in progress label May 21, 2019
@@ -29,7 +29,12 @@ export class Axis extends React.PureComponent<AxisProps> {
return this.renderAxis();
}
renderTickLabel = (tick: AxisTick, i: number) => {
const { padding, ...labelStyle } = this.props.chartTheme.axes.tickLabelStyle;
// suppress padding render from canvas
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 update this description to clarify why we are suppressing the padding here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment improved in commit c70edf4

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for doing that! it would be helpful to include the context that we're already taking padding into account and that the computed bbox dimensions have adjusted for the padding. for someone unfamiliar with the implementation of tick label padding, they would not know why we're just zero-ing out the configured padding setting here, so we want to explain to future developers that we're doing this because padding has already been accounted for and how.

src/state/chart_state.ts Outdated Show resolved Hide resolved
stories/axis.tsx Outdated Show resolved Hide resolved
stories/bar_chart.tsx Outdated Show resolved Hide resolved
stories/rotations.tsx 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.

I wonder if we should do some validation on this argument since we (internally) want this number to be at least 1 or higher (we need to have at least 1 pixel of padding to help with Chrome's inconsistencies in measureText computations).

@markov00 what do think about doing some validation and if the padding amount is less than 1 we set the padding to a default of 1 (and when we start implementing misconfiguration warnings, add a warning if a user tries to specify a padding less than 1)?

stories/axis.tsx Outdated
@@ -82,6 +84,7 @@ storiesOf('Axis', module)
);
})
.add('tick label rotation', () => {
const tickLabelPadding = number('Bottom Axis Tick Label Padding', 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the padding for all of the axes in this story so users can see how the padding would affect each axis & the positioning of the label within the bounding box?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the 'w many tick labels' story have tickLabelPadding added to it?

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 padding to all axes for tick label rotation story in this commit 60d95aa

Copy link
Contributor

Choose a reason for hiding this comment

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

Should the 'w many tick labels' story have tickLabelPadding added to it?

Yeah, the question that will help you make this decision: would adding a knob for tickLabelPadding in a specific story reveal or show people something that is different from what they can find in another story? In the case of w many tick labels, it might be worth showing how padding interacts with showOverlappingLabels.

@@ -172,7 +172,7 @@ storiesOf('Stylings', module)
fontSize: range('tickFontSize', 0, 40, 10, 'Tick Label'),
fontFamily: `'Open Sans', Helvetica, Arial, sans-serif`,
fontStyle: 'normal',
padding: 0,
padding: number('tickLabelPadding', 1, {}, 'Tick Label'),
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

story added in commit 617d869 in new pr

@emmacunningham emmacunningham requested a review from markov00 May 21, 2019 17:05
@rshen91 rshen91 changed the title [WIP] add tickLabelPadding prop add tickLabelPadding prop May 21, 2019
@ghost
Copy link

ghost commented May 22, 2019

Hi @rshen91, we have found your signature in our records, but it seems like you have signed with a different e-mail than the one used in your Git commit. Can you please add both of these e-mails into your Github profile (they can be hidden), so we can match your e-mails to your Github profile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:axis Axis related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tick label padding to axis spec
4 participants