-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 the ability to round bar index scale #1282
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 785cec5:
|
@ericsoco seems interesting to have the option, however I'm not sure about the naming, having |
I agree about the prop name. Something like |
@plouc -- I can look into added to TS defs and a unit test; can also take a look at adding to the website if it's not too complex! Also, I realize now that |
eb5be3c
to
1bf8cae
Compare
@ericsoco Thank you for the adjustments, maybe what we suggested was confusing, the property should be |
No worries, I can make these changes now (and fix the failing lint). |
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.
Also need to update the canvas implementation to pass the value through to the generate bars methods or it will crash. I made the mistake with valueScale :O.
nivo/packages/bar/src/BarCanvas.js
Line 58 in 484235f
valueScale, |
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.
Code looks really good! https://dlqum.sse.codesandbox.io/bar/
Only minor change is I think we should change the website values to default to the default values of the component.
667781e
to
785cec5
Compare
@wyze oof good catch! Fixed. |
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.
Looks great! Thanks. https://z5c1z.sse.codesandbox.io/bar/
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
Thank you @ericsoco! |
@ericsoco I'm looking back at this issue and I see your bar chart uses time series data for its X-axis but I don't see any way to do so without converting their value to a string (which causes every bar to have a tick). Can any one of you guys clarify how that was done? |
@jamesdh I have string values for x-axis formatted as I don't have a tick on every bar because I'm not using Nivo to render the x-axis labels / ticks, this is a hybrid component that functions as a slider (using Material-UI) with a bar chart overlaid. I think what I just told you is probably not helpful for your use case...sorry! |
* Rebase * Fix lint * Refactor from `nice` to `indexScale: {round}` per comments * Add unit tests * Add TypeScript defs * Add `indexedScale` to website * Rebase; update tests to match style * Address comments * Tiny typo fix * Pick up more comments * Correct website default values
I noticed that
ResponsiveBar
charts with many, narrow bars were varying in width. Thesvg
container was the correct width, but the bars within it were offset from the left/right edges.Screencap:
After some digging, I narrowed it down to the use of
d3-scale.scaleBand.rangeRound()
withinBar
'scommon.js::getIndexedScale()
. This diff puts this nicing behavior behind anice
prop, which defaults totrue
to maintain current functionality unless a developer opts out withnice=false
.The above test with
nice=false
:I didn't add anything to the Bar demo site; I can if you like, but this prop feels niche / edge-case enough that it may not need to be surfaced in the demo site.