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
belchertown.py: Losing precision by converting chart options to integer #185
Comments
Thanks again for taking a look! I added the If you want to submit another PR which cleans that up, that'll be appreciated. I think If in the same PR you want to fix my typo on the |
If you are going to submit a PR, you should import weewx's |
Reworking the option naming is something I have thought about as well. It would be really cool to be able to use as many Highcharts options as possible, for example An idea for solving the first issue might be to introduce some kind of type annotation in Edit: The second issue would also be solvable by only converting options the code actually knows about to lowercase before further processing it. The unknown options can then simply be passed on. |
When I started out to make the charts more user-customizable, I took a note from weewx's ImageGenerator. I liked how Tom had the option leaves setup and everything works pretty well. I wanted to try and keep a mapping out of it. And that was possible with the Series options since those are just nested dicts, but for other items like the yaxis min/max/softmin/softmax, gapsize, connectnulls, etc. I had to maintain the mapping. So I told myself that if I was going to maintain mapping then I should follow the camelCase that Highcharts is using. So I failed there with the But then I had the idea that the average user probably doesn't care about camelCase, they just want their stuff to work. Somewhere in that thought process I guess I veered off a bit and fragmented things. So I agree, something like (If you're bored, 😃 You can read a lot about my thoughts during the development process in some of the 1.0 milestone issues where we were testing.) I also don't want to maintain a mapping of all of Highcharts options in my code since that seems redundant and a lot of overhead (for example, when they add a new feature, Belchertown has to add the ability to know that feature exists) I agree some sort of way to remove the mapping would be great but as it sits today I'm not sure that's possible. So I've been adding mapping to the code if/when someone asks for it. |
weewx-belchertown/bin/user/belchertown.py
Line 1148 in 507bbf2
This line converts the value of options not covered in the code beforehand to integer. Unfortunately, this leads to loss of precision for options that can actually reasonably be floats like
yaxis_tickinterval
. Looking at the generated JSON for the pressure chart fromgraphs.conf.example
[1] shows the value fortickInterval
, which is supposed to be 0.01, getting truncated to 0, for example.As I was not sure how you would like to approach the issue, I decided to open this report instead of a pull request right away. My suggestion would be converting everything to float altogether. As JavaScript has only one number type, which is a 64-bit floating point type, anyway, Highcharts, as a JavaScript library, should be perfectly fine with floats passed for any option requiring a number.
[1] The
yaxis_tickinterval
specified for the pressure chart in thegraphs.conf.example
is capitalized in a different way thanbelchertown.js
expects it.belchertown.js
checks foryaxis_tickinterval
but the file containsyAxis_tickInterval
which does not work no matter the value. This is, however, unrelated to the issue and even with the correct capitalization 0.01 gets truncated to 0.Edit: A bit of rewording.
The text was updated successfully, but these errors were encountered: