epezent / implot

Immediate Mode Plotting
MIT License
4.79k stars 531 forks source link

Any way to get the ImGui::PlotLines mouse hover functionality? #274

Closed ET3D-ET3D closed 3 years ago

ET3D-ET3D commented 3 years ago

I want to have the same functionality as ImGui::PlotLines, where I hover the mouse over the plot I get the X axis value and the value of the plot at that x. What ImPlot shows are the x and y where the mouse pointer is, which isn't helpful. Any way to get the PlotLines functionality?

epezent commented 3 years ago

We don't currently offer this functionality. It's certainly something we'd like to, but such an API design will take some thought since ImPlot (unlike ImGui::PlotLines) can plot more generic data than timeseries, or data that increases monotonically along the x-axis.

In the meantime, you can reference the candle stick demo in implot_demo.cpp, which implements such hover behavior using binary search:

https://github.com/epezent/implot/blob/3e96fd7c02134ec6c725d5ef3e35390e69adfc79/implot_demo.cpp#L2000-L2012

ET3D-ET3D commented 3 years ago

Thanks. Sounds like a simple enough solution.