ratatui-org / ratatui

Rust library that's all about cooking up terminal user interfaces (TUIs) 👨‍🍳🐀
https://ratatui.rs
MIT License
8.79k stars 263 forks source link

logarithmic axes in Chart #1052

Open sarah-ek opened 2 months ago

sarah-ek commented 2 months ago

Problem

chart only allows a linear scale for the x and y axes

Solution

make chart a stateful widget so the x and y axes can be changed at runtime from linear to logarithmic

Alternatives

make separate widgets for log scaled charts, but that would lead to having 4 widgets that do very similar things

joshka commented 2 months ago

This is a good idea, but it shouldn't require the widget to be made stateful as that is usually only necessary when there's state that has to be modified during rendering. I think this can probably be a normal property on the Axis type.

Would you consider raising a PR for this?

I think maybe this would look like:

sarah-ek commented 2 months ago

I'm not very familiar with the internals of the library but i can try

joshka commented 2 months ago

I'm not very familiar with the internals of the library but i can try

No problem - we try to write code in a style that makes it easy for anyone to add features by following the same ideas as what is already there. Keep things consistent with what you see and you'll be mostly ok, and for the rest we can provide feedback that helps guide things in the right direction. Don't hesitate to reach out here or in the feature discussion channel on discord / matrix if needed.

joshka commented 2 weeks ago

Also note that there is an existing bug with the positioning of labels on the axes (https://github.com/ratatui-org/ratatui/issues/334) This will have to be fixed here too as the labels when using log axes should be positioned on the correct points too.

This likely needs a bit more design work to work well. How should axes labels generally be handled here? Should this just be automatically assigned based on the visible values? Should this be manually configured? Should labels have both a position and text? I haven't personally used the chart widget in earnest. It's worth spending a bit of time looking at real world examples of the use of the widget (search github) and understanding how they'd change / use this and the fix for #334.