-
Notifications
You must be signed in to change notification settings - Fork 563
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
SetNextPlotLimitX/Y in case of drag and drop? #165
Comments
@mvphilip, if I understand correctly, you want the plot to auto-fit (or allow for a manual refit) when new data is dropped onto it, but can't because new drops occur between Because ImPlot doesn't cache plot data and thus renders everything on the fly instead of at the at the end, it's not possible to change a plot's limits mid-plot (i.e. between static bool need_refit = false;
if (need_refit) {
ImPlot::FitNextPlotAxes();
need_reft = false;
}
if (ImPlot::BeginPlot("MyPlot")) {
// render shown data
for (int i = 0; i < data.size(); ++i) {
if (data[i].show)
ImPlot::PlotLine(data[i].label, data[i].x, data[i].y, data[i].size());
}
// check for incoming drops
if (ImGui::BeginDragDropTarget()) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("DND_PLOT")) {
int i = *(int*)payload->Data;
data[i].show = true;
need_refit = true;
}
ImGui::EndDragDropTarget();
}
ImPlot::EndPlot();
} Adapt this to whatever data structures you are using. Feel free to replace Hope this helps. |
As a note to my future self, there might be an easy path forward to allowing fits and setting axes limits mid-plot. Let's keep this issue open until I have more time to investigate. |
Thanks a lot for the suggestion! -mp |
Just highlighting that I would greatly value ability to set limits after begin plot - I usually want to respond to a scroll or pan event by setting one of the axes manually. Example lock y axis and manually set its range when zooming or panning. Right now this is only possible on the next frame which causes some jumpiness, and similar use cases mean a lot of variables just to capture a request that needs to be processed in next frame (eg refit requested). FWIW, hooking into the zoom/pan behaviour is probably good enough, not sure what the best API for that is. |
@yamen thanks for the feedback. I will think carefully about how we might achieve this. In the meantime, could you thoroughly explain what it is you are trying to do? As you suggested with input hooks, there might be an easier, more straightforward way to satisfy your needs. Second, I want to take the opportunity to layout the sequence of input/rendering events in ImPlot. This may help you think about the problem better and maybe suggest where we might inject the functionality you need.
I realize this is a lot to process, and I glossed over a bunch of details. But hopefully this will help everyone understand how ImPlot does immediate mode plotting and why it's challenging for us to make certain state changes between Furthermore, I wouldn't say this order of execution is perfect either. As I type this out, I see some issues and areas we could improve (e.g. axis grid/ticks and plot data may be desynced one frame after input events). |
@epezent what an amazingly thorough response. Probably worth popping into the Wiki for future reference, as I think it will aid others when making suggestions or feature requests. I will explain my use case below, but from the looks of the above workflow, the "point of no return" seems to be the start of the transformation cache / rendering, which also happens to be the last step of The other way to view the root cause is that "fitting" is done after scrolling / panning / zooming - ie, the data is only ever processed after axis ranges are fixed. I can see why this is desirable from a pipeline point of view and as default behaviour, but the user does know about their data before its plotted and can override the defaults a little better perhaps. As to the use case:
What I've tried and the results, example is for a mouse scroll zoom:
This ended up being a bit of an essay. Hopefully it makes sense on parsing... |
Thank you for the equally thorough response! Let me mull over this for a few days. If your work allows, could you post some GIFs of what you have done so far? |
This is a GIF recorded at 33fps which shows the issue, the jumpiness is worse in reality. Here you can first see how trying to zoom beyond data range causes the X-axis min to first go below 0, and then to clamp back to 0 the frame after. Similarly, as we zoom into data, the Y-axis first does normal zoom behaviour, then flicks into the data range. Worth noting that panning is actually quite smooth, because although there might be jumps they are very minor compared to mouse wheel scrolling which jumps 10%. |
@yamen , see #200. Not sure if this will meet all your needs, but at the least it should enable the behavior you were after in #165 (comment) |
Such fantastic work, thanks so much!
On Mon, 29 Mar 2021 at 7:02 am, Evan Pezent ***@***.***> wrote:
@yamen <https://github.com/yamen> , see #200
<#200>. Not sure if this will meet
all your needs, but at the least it should enable the behavior you were
after in #165 (comment)
<#165 (comment)>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#165 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACVTZ3FB64WM33SFV7BOKTTF6DPFANCNFSM4WDQ447Q>
.
--
Sent from Gmail Mobile
|
Hello, Is there a recommended way to set plot limits if using the drag and drop demo? As the data is not available before a BeginPlot it's not possible for me to programmatically set limits. There is an assert in the code so I suppose this use case is not supported?
Thanks and what a great tool you've made here!
-mp
The text was updated successfully, but these errors were encountered: