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(xy): specify pixel width for bars #1114

Merged
merged 11 commits into from
Apr 13, 2021

Conversation

markov00
Copy link
Member

@markov00 markov00 commented Apr 12, 2021

Summary

This PR adds the ability to specify the width of bars in pixel or as the ratio of the current computed width.
This option is exposed as part of the BarSeriesStyle.rect object

widthPixel?: Pixels;
widthRatio?: Ratio;

If widthPixel is used, then each bar width will use exactly that width in pixel. This width is limited to the max width available for the bars (that excludes the bar padding)
If widthRatio is used, then each bar width will use the ratio of the max computed width.
If both are expressed, then the widthRatio will express the max available size, where the widthPixel express the derired/min width.

fix #497

Checklist

Delete any items that do not apply to this PR.

  • Any consumer-facing exports were added to src/index.ts (and stories only import from ../src except for test data & storybook)
  • 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

Copy link
Contributor

@monfera monfera left a comment

Choose a reason for hiding this comment

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

Looks good, minor comments added

@codecov-io
Copy link

codecov-io commented Apr 12, 2021

Codecov Report

Merging #1114 (e3a5176) into master (64bdd88) will increase coverage by 0.51%.
The diff coverage is 100.00%.

❗ Current head e3a5176 differs from pull request most recent head 379f60b. Consider uploading reports for the commit 379f60b to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1114      +/-   ##
==========================================
+ Coverage   72.09%   72.61%   +0.51%     
==========================================
  Files         382      398      +16     
  Lines       11953    12270     +317     
  Branches     2613     2644      +31     
==========================================
+ Hits         8618     8910     +292     
- Misses       3310     3327      +17     
- Partials       25       33       +8     
Flag Coverage Δ
unittests 72.20% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/utils/themes/theme.ts 100.00% <ø> (ø)
src/chart_types/xy_chart/rendering/bars.ts 84.31% <100.00%> (+0.31%) ⬆️
src/mocks/series/utils.ts 100.00% <0.00%> (ø)
src/mocks/series/data.ts 100.00% <0.00%> (ø)
src/mocks/annotations/annotations.ts 66.66% <0.00%> (ø)
src/mocks/scale/index.ts 100.00% <0.00%> (ø)
src/mocks/index.ts 100.00% <0.00%> (ø)
src/mocks/geometries.ts 92.85% <0.00%> (ø)
src/mocks/store/index.ts 100.00% <0.00%> (ø)
src/mocks/theme.ts 86.66% <0.00%> (ø)
... and 9 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 f644cc4...379f60b. Read the comment docs.

@markov00 markov00 marked this pull request as ready for review April 12, 2021 17:21
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.

Looks good to me. Two minor comments

@@ -52,7 +55,7 @@ export const Example = () => {
},
};

const theme = {
const theme: RecursivePartial<Theme> = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit

Suggested change
const theme: RecursivePartial<Theme> = {
const theme: PartialTheme = {

Copy link
Member Author

Choose a reason for hiding this comment

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

done 27f5971

Comment on lines 402 to 405
/** The width of the rect in pixel */
widthPixel?: Pixels;
/** The ratio of the width limited to [0,1] */
widthRatio?: Ratio;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a comment here about using both?

If both are expressed, then the widthRatio will express the max available size, where the widthPixel express the derired/min width.

Copy link
Member Author

Choose a reason for hiding this comment

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

done 27f5971

@markov00 markov00 merged commit 58de413 into elastic:master Apr 13, 2021
@markov00 markov00 deleted the 2021_04_12-fixed_bar_width branch April 13, 2021 09:01
nickofthyme pushed a commit that referenced this pull request Apr 13, 2021
# [28.1.0](v28.0.1...v28.1.0) (2021-04-13)

### Bug Fixes

* **legend:** sizing for short labels with scrollbar ([#1115](#1115)) ([6e1f223](6e1f223))
* **xy:** negative bar highlight and click ([#1109](#1109)) ([ec17cb2](ec17cb2)), closes [#1100](#1100)

### Features

* **a11y:** improve chart figure ([#1104](#1104)) ([815cf39](815cf39))
* **partition:** order slices and sectors ([#1112](#1112)) ([74df29b](74df29b))
* **partitions:** small multipies events pass on smAccessorValue ([#1106](#1106)) ([a3234fe](a3234fe))
* **xy:** optionally rounds the domain to nice values ([#1087](#1087)) ([f644cc4](f644cc4))
* **xy:** specify pixel and ratio width for bars ([#1114](#1114)) ([58de413](58de413))
* mosaic ([#1113](#1113)) ([64bdd88](64bdd88))
@nickofthyme
Copy link
Collaborator

🎉 This PR is included in version 28.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nickofthyme nickofthyme added the released Issue released publicly label Apr 13, 2021
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
released Issue released publicly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bar charts on linear scales with static bar width
4 participants