-
Notifications
You must be signed in to change notification settings - Fork 420
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
Using minimum of 0 as default #48
Comments
Setting the minimum value to zero as default would remove the ability to create a diagram with normalized bars. I think we should create a property to switch between normalized and non-normalized and use non-normalized as default. This would solve the confusion and preserve the feature to create normalized charts. |
@simonnickel would setting the chart's minimumValue to 0 not solve this for you? @hackingotter the chart would still be normalized, with 0 being used as the internal minimum value, instead of 10 (as in @simonnickel's example). |
@terryworona Yes, that was the solution. But I did not expect that I have to set it. An additional setting like useMinimumValueAsHeightBase (just with a better name) with NO as default would help to make it clear. Like I said: I would not expect the bar to cut my values as default behavior. |
@terryworona Maybe I missunderstand something but when you set minimumValue in JBChartView to 0 as default @simonnickel I share your opinion as I was confused by this, too. I think this would make things much more clear. |
@hackingotter yes, you are correct; very subtle bug. I do prefer to expose the minimum and maximum values in case someone wants to add padding (especially useful for line charts). |
Alright, made some changes:
The only gotcha with the pattern is the assumption that the y-axis starts at 0 (minimumValue default = 0). A very quick look at the documentation should provide some insight though. |
I think there is an error in your code. Its about _hasMinimumValue: The chart will be normalized if _hasMinimumValue is NO, right? I would suggest to create a method |
The minimumValue and maximumValue accessors in both the bar and line chart views are only utilized when normalizing a height via:
Regardless if hasMinimumValue returns true or false, the returned value from minimumValue will be normalized regardless. Perhaps I am missing something? Maybe take me through the code path your thinking? |
hasMinimumValue always is YES, as there is no method in JBChartView could set it to NO, only one that sets it to YES. Then I looked at JBLineChartView:
It will alway return So if you call resetMinimumValue as you don't want the bars to be cut the minimumValue will be 0 and hasMinimumValue will be YES. And this is the error. At this point the cachedMinHeight should be returned to cut the bars and not 0. To solve this hasMinimumValue somhow has to be set to NO. That's how I read the code. Maybe I'm wrong. This really isn't as easy as it seems. And maybe I also missunderstand "normalized". Does it include cutting the bars or does it only mean, that the bars are converted to be in the right relation to each other? |
Normalization is just taking a series of data and having it speak a common language; in our case, it's adjusting their heights to be relative the chart's bounds (height). hasMinimumValue will in fact always return YES, but that is because we chose to make the default 0. If we chose to NOT make the default minimum 0, then we can remove this piece and have it return the chart's actual minimum value. What exactly in the current implementation breaking for you? |
Now I would like the bars to be cut so the difference between them can be seen better. In earlier versions this would have been the default behaviour but now it is not possible anymore. As I explained before the reason for this is, that hasMinimumValue is always YES. The 3rd paragraph i don't understand. I would solve the problem simply by adding a method like And if |
Ah I see what you mean. By defaulting the minimumValue to 0.0, you can never tell the chart to use the actual minimum of the dataSource. By automatically defaulting to 0.0 for the minimum, I was address @simonnickel's concern. I think it's best to default to the chart's min and max values, and noting in the readme and documentation that the minimum value can be manually set to 0 if that's what you need. |
@hackingotter fixed pushed to v2.5.1 commit: 49206a0 @hackingotter for your case, I would try setting the minimumValue = smallest chart value - 10. Similarly, to add top padding maximumValue = largest chart value + 10. |
Thanks but this was just an example I used to show you what I meant. Now everything should work again. |
After I updated to the current version I got really confused with a BarChart having a minimum value above 0. In the earlier version 0 was used as the base value for bar height calculation. In the current version the lowest number is used. (Bar with 10, 20, 40 on 40px is shown with heights of 0px, 10px, 40px - not my expected 10px, 20px, 40px). It took some time until I figured out why this happened.
However, I think using 0 as default minimum value is what you would expect using a JBBarChart and therefore should be the default setting.
Btw: great tool and keep on with constant improvements!
The text was updated successfully, but these errors were encountered: