-
Notifications
You must be signed in to change notification settings - Fork 133
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
Support Y-axis custom labels #187
Comments
Hello again @slok, this is a very good point, indeed the code that places the Y Axis labels is a bit rough and unfinished. However we might be able to do better than to let the users provide custom labels. I am a bit vary of letting the user provide the labels, since it a) exposes the user to the internals of the LineChart and b) would be confusing. (a) The LineChart owns the logic of allocating values to the Y axis and we might want to change or improve that logic in the future. If we let the user provide labels we might end up in a situation from which we can't get out without breaking API changes. With that, here is a counter proposal and I would love to get your opinion about this. We could do this change in three steps:
I believe that we might have very similar result to the picture you uploaded if we do these three things and we still remain in control of the internals without exposing ourselves to breaking API changes. Let me know what you think. Secondly, if you agree with this approach, please let me know if you would be interested in helping with any of these steps, in which case I can give exact code pointers. As always, open to other ideas of course. |
Many thanks for your thoughts and the detailed explanation @mum4k it's a pleasure opening issues in this repository :) I see your concerns with breaking the API, I have the same opinion. As always I'm happy to help in whatever I can and I like what you propose, so... I'm in! Apart from this, I understand that if you only let the users select the unit you are abstracting all the unit formatting to them, an that's very good, but could you explain me (only to understand more deeply) In what way would affect the user letting them set an optional formatter as dependency injection? (using a function or an implementation of some kind of interface). Best. |
Thanks a lot @slok for persisting and rephrasing your question. Turns out I misunderstood your note when you filled this issue. Indeed there is nothing wrong with letting the user provide an optional formatter, i.e. a function that just takes the float64 value and formats it into a string. I believe your idea is much better than mine in point (1). I would be happy to accept a PR adding a LineChart option that takes such formatter. We could use this instead of (1) above with the understanding that the LineChart still won't choose "pretty" values until we also do (2) and (3). Optionally we could also develop some common formatter(s), say starting with the time formatter and include them with the LineChart, that is up to you really. I am really glad you're in and willing to help, your PR was written very cleanly and was easy to review so already looking forward to the next one. If you want, you can send a work-in-progress PR with just the API first (the new option and the formatter func definition) - assuming you would like to get a quick feedback on it. Now some code pointers you might find useful:
So it should be fairly simple to provide a custom one and plumb it through the call stack. The only catch is that the Value object is used by both the Y axis and the X axis. Lastly all the widgets use the same pattern for options, we should add a new option somewhere here: Hope this gives you the pointers you need. Once we finish (1), I will be happy to give more pointers for (2) and (3), but at that point you will likely know all you need about the LineChart implementation. Feel free to contact me at any time if you will have any additional questions or ideas. |
Hi!
At this moment, X-axis supports a slice of labels to customize what is rendered on the X-axis.
I haven't seen this for the Y-axis. If this is not implemented, would be nice to have the same feature for the Y-axis. The motivation behind this is to have the ability to do something similar to this:
A simple (without having too much knowledge about the internals of the library) possible solution could be to allow setting a "transforming" function that accepts the
y
axis value/number as an argument and returns the string to render on the Axis. This way we could convert the Y value to any unit and display the units also.What are your thoughts on this? would be this possible?
Thank you!
The text was updated successfully, but these errors were encountered: