4bb4 / implot-rs

Rust bindings to https://github.com/epezent/implot
Apache License 2.0
51 stars 22 forks source link

Candlestick charts #21

Open Boscop opened 3 years ago

Boscop commented 3 years ago

Thanks for this crate! I'd be really interested in the candlestick chart type. I'd also be interested to work on that myself, if nobody else is.

Btw, can multiple charts be layered on top of another? E.g. layering a candlestick chart with other plot types (indicators) as overlay?

4bb4 commented 3 years ago

Thanks for this crate!

Glad it's useful to people, even though I'm not putting in as much effort as it could use at the moment

I'd be really interested in the candlestick chart type.

As far as I can tell, the candlestick plot you can see in the C++ repo's preview images is actually not part of the regular implot API, but rather an example for how to build a custom plot type: https://github.com/epezent/implot/blob/master/implot_demo.cpp#L1730. If you'd like to have this functionality from the Rust bindings, there are a few different ways we could make this happen:

  1. Get the author of the C++ library underlying these bindings to add candle stick plots as a proper plot type
  2. Implement a Rust version of the demo code I linked above in the bindings here
  3. Implement a Rust version of the demo code I linked in your own code base on top of implot-rs

The best long-term option would be 1 in my opinion, because that would make the feature available to the most people. The problem with this is that the bindings here are currently somewhat blocked from moving to a newer version of the C++ library because of the problem mentioned in https://github.com/4bb4/implot-rs/issues/13 (TL;DR: to update implot, I need to update imgui, and to do that, I need to bring along a newer imgui-wgpu-rs, and that leads to stubborn crash somewhere in the depths of the rendering code I have not yet been able to fix). This means that even if implot itself adds candlestick charts tomorrow, as long as I can't fix that problem, I can't move the bindings along to a new version. That said, there seems to have been some activity on the imgui-wgpu-rs side of things, so I might give upgrading another shot soon. Also, it would probably not hurt to feature-request a candlestick chart in the C++ repo anyway just in case the issues here with WGPU get resolved over time.

I'd like to avoid option 2, because since the Rust crate is really just bindings so far, adding separate functionality seems a bit out of scope. Option 3 is the least favourable in the sense that then other people can't benefit from your work, but if you'd like a candlestick chart ASAP it is probably the fastest.

Btw, can multiple charts be layered on top of another?

I'm not sure I understand correctly what you mean, but if you mean whether you can draw for example a bar plot in the same plot window as some lines and for example a scatter plot: yes, you can. Create a single plot, like this, then build multiple different plot items within it, like this and they should be drawn in the same plot window (I believe they are layered on top of each other, the first item to be drawn in code will be on the lowest layer, if I remember correctly).

Apologies for the wall of text and long reply time, I hope it helps anyway.