Open ArnaudJamin opened 9 months ago
Yes there is a way, It's quite easy to do. The version I use is older (v0.12) but I'm pretty sure it works the same way in newer versions.
if(ImPlot::BeginPlot(...))
{
// Plot stuff
if (ImPlot::IsPlotHovered() && GImGui->HoveredIdTimer > 0.2)
{
ImPlotPoint mouse = ImPlot::GetPlotMousePos(); // Mouse offsets
within the chart
const int32_t i = static_cast
ImGui::Text("Label 1: $%.2f", dataSet1[i]);
ImGui::Text("Label 2: $%.2f", dataSet2[i]);
ImGui::EndTooltip();
}
ImPlot::EndPlot();
}
David
On Tue, Sep 19, 2023 at 2:01 PM ArnaudJamin @.***> wrote:
Hello,
I'm wondering if ImPlot is able to draw tooltip with values of where the mouse is. Something like this: [image: image] https://user-images.githubusercontent.com/87346845/269080018-f0f00639-81c3-421b-995a-e43714b18681.png
This was done the same way as the "Custom Plotters and Tooltips" demo which require to search through the data. I was wondering if ImPlot might have a faster way to do this, since it already iterate over the data to draw the graph.
Thanks for this great library!
— Reply to this email directly, view it on GitHub https://github.com/epezent/implot/issues/514, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOS57YUGUW6E7TADVOTVJ7LX3H22LANCNFSM6AAAAAA462QQ7A . You are receiving this because you are subscribed to this thread.Message ID: @.***>
I don't think this solution always works. I'm using a circular buffer of ImVec2 where x is the time and y is the value. ImPlot::GetPlotMousePos().x returns the time, so a search in the array would be required.
I use "circular" buffers as well to capture real-time stock data. I found that using x axis as time wasn't very feasible in my case. It was better to use the x axis as a reference to the data. I used std::deque as the datatype. When adding a new element to the list, call .push_front() and when there are enough elements, start calling .pop_back() to limit my data size. This way there is a sliding window from left to right of data that you can easily reference in your tooltip.
Quick example how I reference tons of data within my charts.
using dataset_t = std::deque
struct candles_t { dataset_t open; dataset_t close; dataset_t high; dataset_t low; volume_t volume; timestamp_t timestamp; }
I create functions that implot can use where I can extract whatever data I want. In this case I want the close. ImPlotPoint candleClose(void data, int i) { candles_t c = reinterpret_cast<candles_t*>(data); return ImPlotPoint(i, c->close[i]); }
To plot a I call ImPlot::PlotLineG("Candles", candleClose, &candles, size);
Example of my tooltip [image: image.png]
I hope this helps, David
On Wed, Sep 20, 2023 at 2:21 PM ArnaudJamin @.***> wrote:
I don't think this solution always works. I'm using a circular buffer of ImVec2 where x is the time and y is the value. ImPlot::GetPlotMousePos().x returns the time, so a search in the array would be required.
— Reply to this email directly, view it on GitHub https://github.com/epezent/implot/issues/514#issuecomment-1728372971, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOS57YU2SOJZMNEPFX6LB3DX3NF3VANCNFSM6AAAAAA462QQ7A . You are receiving this because you commented.Message ID: @.***>
check implot_demo tooltip example
I was wondering if implot had a built in functionality to do tooltips without having to search inside the data (which is what the tooltip demo does). Or have a way to get the value at specific "time" without searching.
Thanks!
Hello,
I'm wondering if ImPlot is able to draw tooltip with values of where the mouse is. Something like this:
This was done the same way as the "Custom Plotters and Tooltips" demo which require to search through the data. I was wondering if ImPlot might have a faster way to do this, since it already iterate over the data to draw the graph.
Thanks for this great library!