-
Notifications
You must be signed in to change notification settings - Fork 60
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
domainPadding does not work as expected #472
Comments
domainPadding seems to be messing with scrolling (panning) as well. I don't have a full example, but the issue that I had is when setting domainPadding={10} and enabled panning (on the x axis) with a preset viewport, I was only able to scroll within the viewport and not through the whole graph. After commenting out the domainPadding, everything worked as expected |
If you do want to provide a full example @trujic1000 we can take a look. |
@zibs Here's a minimal reproduction code
The issue can be described as follows:
|
Hi @ljukas thanks for the detailed bug report! I took a look into this issue. The cause of the bar inset differential you're seeing is due to how we generate the x axis in cartesian charts. Every chart type (including bar charts with categorical data) scales its x axis using a linear scale where we account for the domain padding here. This scale is then used to generate the points array here. In order to generate the points array as you expect in your reproduction, we would need to support different scale types (for this example, likely https://d3js.org/d3-scale/band). @zibs going to mark this as an enhancement and then spin out a separate issue for the panning issue reported by @trujic1000 |
For future contributors, I created a branch with the reproductions in this thread https://github.com/FormidableLabs/victory-native-xl/tree/fix/472-bar-domain-padding-clip-bounds I attempted a fix by adjusting the |
@djm158 Thanks for the reply. This means the documentation is incorrect: DomainPadding should draw the chart for example 20 points from the left when I have in my app written a new CartesianChart wrapper so this can be done more predictable. Instead of the inverting you do here and doing domainPadding on the domain I instead just add padding the range as can be seen here: This means we dont need to use band scales or similar. In my implementation I use the exact some way to generate the ox as you linked above. Another weird quirk from the victory-native cartesian chart regarding the output range is that given no domainPadding at all, the leftMost point of the chart will be 4, instead of 0. This chart, gives the following chartBounds:
You can see that the left most point is not on the edge, like the last point is in this screenshot I think this is because you generate some padding from calculating stuff for the axis even though no axis is rendered. This is the same chart generated via my cartesianChart component As you can se here the left most and rightmost points are on the edge You can find my reimplementation of the CartesianChart and related stuff here: This is very basic implementation so there is not press-stuff or zoom etc. This is just so I can render basic charts correctly without weird padding etc |
@ljukas great bug report! I'm also struggling with this issue, trying to get precise bar widths/paddings. In my case, I depend on touch interactions etc. Do you think a workaround would be support a custom (x) scale function as prop to @djm158 @zibs thanks for your work with this library! if this is a low-prio bug, would you accept a PR with the above suggestions? |
Describe Your Environment
What version of victory-native-xl are you using? (can be found by running
npm list --depth 0 victory-native
)[email protected]
What version of React and React Native are you using?
"react": "18.2.0",
"react-native": "0.74.5",
What version of Reanimated and React Native Skia are you using?
"react-native-reanimated": "3.12.1",
"@shopify/react-native-skia": "1.2.3",
Are you using Expo or React Native CLI?
Expo
What platform are you on? (e.g., iOS, Android)
Both
Describe the Problem
Using domainPadding does not insert the points with the set value. Which results in making predictable bar graphs very hard.
This very simple code renders a very basic bar graph.
Data is the following:
Which results in the following points by default:
We can se here that the first bar has its midpoint in
x = 4
We now want to use barWidth together with domainPadding to make sure each bar renders within the bounds and no part of each bar is outside the rendered area (as it is by default). So we set barWidth to 50, and domainPadding left and right to 25. My logic here would be that the rendered chart is moved from the left and right side 25 "pixels" and the rendered x would now be 4 + 25 for the first point and 327 - 25 for the last point. Hence moving the graph according to the domainPadding.
However, doing this as below.
Leads to the following chart data:
As seen here the first bar is not inset 4 + 25, but instead to 25.64.... This leads to some of the bar not being inside the drawn area.
This can easily be seen in the rendered graph
Expected behavior: [What you expect to happen]
I expect domainPadding to actually move the graph the given number
Actual behavior: [What actually happens]
DomainPadding does render the graph at the expected position instead it does some calculation internally and ends up with the incorrect position for the graphed points
The text was updated successfully, but these errors were encountered: