-
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
add tickLabelPadding prop #176
Conversation
@rshen91 thanks for the work you are doing here. |
@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 Report
@@ 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
Continue to review full report at Codecov.
|
src/components/react_canvas/axis.tsx
Outdated
@@ -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 |
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 update this description to clarify why we are suppressing the padding here?
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.
comment improved in commit c70edf4
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.
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.
@@ -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.
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); |
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 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?
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.
Should the 'w many tick labels' story have tickLabelPadding added to it?
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 padding to all axes for tick label rotation story in this commit 60d95aa
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.
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
.
stories/styling.tsx
Outdated
@@ -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'), |
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.
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).
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.
story added in commit 617d869 in new pr
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:
This functionality is also included as a theme for the bottom tick label padding:
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