epezent / implot

Immediate Mode Plotting
MIT License
4.65k stars 517 forks source link

Odd Issue when switching between Implot.AddText / Implot.Image #373

Open aDioS786 opened 2 years ago

aDioS786 commented 2 years ago

Hi I get this issue, probably something wrong am doing/got wrong understanding. I have a check where it only loads images when texture is available, if not available then show some text. The issue is when this switch happens from showing text to image, the image does gets loaded but on canvas all I see if black screen and the bottom right coordinates doesn't referesh at all the way they usually show current x,y coordinates when moving mouse around. If i double click on canvas then my image shows up.

if (image_texture != nullptr) ImPlot::PlotImage("", (void*)my_texture, ImVec2(0, 0), ImVec2(1920, 1080.000000), ImVec2(0, 0), ImVec2(1, 1), ColorEdit4); else ImPlot::PlotText("Image Not Found.", ImPlot::GetPlotSize().x / 2, ImPlot::GetPlotSize().y / 2);

Also is there a way to focus on certain coordinates on canvas say if i click on x-text in legend then it move focus to that individual object?

Thanks

epezent commented 2 years ago

For one, you are misusing PlotText -- you are passing pixel coordinates (i.e. return value of GetPlotSize()), not plot coordinates. ImPlot::PlotText("Image Not Found.", 960, 540); would be more appropriate.

But there is another issue. ImPlot automatically fits to plotted elements on the first frame of an axis' lifetime unless you specify ImPlotAxisFlags_NoInitialFit. After that, you have to initiate a manual fit (i.e. double-click). So, because your image may not be available on the first frame, the plot won't automatically be set to limits of 0,1920 and 0,1080 unless you explicitly do that. Fortunately, we have an API for that. Call the following just after BegniPlot and before any plotting:

void SetupAxesLimits(0, 1920, 0, 1080, ImPlotCond_Once);

You could also call the following before BeginPlot when the image is loaded (or whatever event you desire) to initiate a fit:

void SetNextAxisToFit(ImAxis axis);
aDioS786 commented 2 years ago

Thanks, now the problem is if i set the condition to always then it locks zoom/right/left movement. What am trying to do now is say we set the axes to 1920/1080 now if i Restore down the window size it may go to a size of 650/500 (by click then middle icon next to "x-close". I can't get the text centred if i try set the axes again by using viewport size which gives me correct x/y. So outcome am looking for is if i make the screen shorter then it still shows text in mid screen if i maximize then it still show sin middle.

aDioS786 commented 2 years ago

Also how can i focus on specific legend items, say I plotted 10 circles all with different legen name and diff location. How can i move or centre my view to that legend when maybe i click on sometext on screen or may be on legend name on left.