Skip to content
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

AlignedPlots: Y/X axis padding over multiple plots #144

Closed
wants to merge 8 commits into from
Closed

AlignedPlots: Y/X axis padding over multiple plots #144

wants to merge 8 commits into from

Conversation

ozlb
Copy link
Contributor

@ozlb ozlb commented Nov 9, 2020

To have same Y axis padding, ImPlot::BeginSubPlots() must be called before 1st ImPlot::BeginPlot() and ImPlot::EndSubPlots() must be called after last ImPlot::EndPlot().
Peek 2020-11-10 22-44

#53 (comment)

@ozlb
Copy link
Contributor Author

ozlb commented Nov 9, 2020

@epezent
This is a working draft but final version requires a SubPlot ID pool to have the possibility to handle multiple sub plots. Thoughts?

@epezent
Copy link
Owner

epezent commented Nov 11, 2020

@ozlb, thanks for looking into this. A few questions:

  • Yes, I think you'll need a pool which stores padding information. You'll need to add either a string or int ID to the function signature to do this. I suggest adding a new struct to implot_internal.h that stores all the necessary state information.
  • In your example, the top plot has the widest labels, and so it propagates to the bottom plot in one frame. In the reverse case, the top plot won't update until the next frame. How noticeable is the delay? Can you show an example where the bottom plot has the widest labels?
  • Can you show an example with auxiliary y-axis?
  • What happens when a plot has an axis title?
  • What happens when a plot has neither an axis title or tick labels?
  • After thinking about it, I think we might want to change the name of this function to BeginAlignedLabels/EndAlignedLabels. I think BeginSubplot would need to offer additional functionality to warrant the name, e.g. similar to matplotlib subplots. That of course is also an option, but I think plots inside of ImGui Tables pretty much covers most use cases already. (e.g. grids of plots).

@ozlb
Copy link
Contributor Author

ozlb commented Nov 11, 2020

  • new signature with ID: ok
  • bottom to top propagation: the delay is only for a single cycle because on the next one if padding will not change it will match the saved.
  • I’m regularly testing with 3 y axis, no problem
  • axis labels or tick labels and ticks are calculated before at plot bb (3), so are included
  • i renamed in ImPlot::BeginAlignedPlots()

@epezent
Copy link
Owner

epezent commented Nov 11, 2020

Awesome! One other thing: can we add support for vertical alignment when ImGui::SameLine() is used?

new signature ID, ImPool  to store padding data, demo
@ozlb
Copy link
Contributor Author

ozlb commented Nov 11, 2020

Peek 2020-11-11 23-32
About the 1 cycle delay for back propagation if you notice carefully you can see it, but i think it's acceptable and not annoying.

vertical will align Y axis, horizontal will align X axis.
*signature changed
@ozlb
Copy link
Contributor Author

ozlb commented Nov 11, 2020

Awesome! One other thing: can we add support for vertical alignment when ImGui::SameLine() is used?

I changed signature of function to handle vertically/horizontally using already existing enum ImPlotOrientation. If you don't like or if it's confusing with other functionalities, we can use a boolean flag or new enum. Thoughts?

Peek 2020-11-12 00-26

@epezent
Copy link
Owner

epezent commented Nov 12, 2020

I changed signature of function to handle vertically/horizontally using already existing enum ImPlotOrientation.

Love it! Another thought:

If we changed ImPlotOrientation to be a flag, then it could be possible to pass ImPlotOrientation_Horizontal | ImPlotOrientatoin_Vertical for 2D grids of plots. Is that overkill?

Otherwise this looks great, I'll try to take a look tonight or tomorrow.

@ozlb ozlb changed the title SubPlots: Y axis padding over multiple plots AlignedPlots: Y/X axis padding over multiple plots Nov 12, 2020
@ozlb
Copy link
Contributor Author

ozlb commented Nov 12, 2020

If we changed ImPlotOrientation to be a flag, then it could be possible to pass ImPlotOrientation_Horizontal | ImPlotOrientatoin_Vertical for 2D grids of plots. Is that overkill?

signature is ok, but to use as flag, enum ImPlotOrientation_ need to be changed and start from 1.

// Used to orient items on a plot (e.g. legends, labels, etc.) or align plots
enum ImPlotOrientation_ {
    ImPlotOrientation_None       = 0,      // 
    ImPlotOrientation_Horizontal = 1 << 0, // left/right
    ImPlotOrientation_Vertical   = 1 << 1, // up/down
};

I cross check where is used for legends, labels and should not be problematic.

@ozlb
Copy link
Contributor Author

ozlb commented Nov 12, 2020

Ready for your final approval / refinements / decorations.

@epezent
Copy link
Owner

epezent commented Nov 16, 2020

@ozlb , sorry I haven't addressed this. I wanted to first merge organizational changes I've been making in implot_internal.h with the addition of ImPlotFlags_Equal. That's done, and so this needs to have a few conflicts resolved.

@ozlb
Copy link
Contributor Author

ozlb commented Nov 16, 2020

I will resolve the conflicts and update PR.

@ozlb
Copy link
Contributor Author

ozlb commented Nov 16, 2020

Sync. to v0.9 and ready for your final approval / refinements / decorations.

@dnedry2
Copy link

dnedry2 commented Jan 23, 2021

Would it be possible to also add crosshair alignment for plot groups?
ie:
aligned

@ozlb
Copy link
Contributor Author

ozlb commented Jan 27, 2021

interesing, but before I need to sync to latest version so hopefully it will be merged into master.

@yamen
Copy link

yamen commented Mar 16, 2021

I came here to look for a way to do this, and here's a PR with exactly what I need! This is fantastic work.

I think crosshair alignment should be covered separately, as it only depends on X-value linking, which already has a working solution. Once we get visual alignment of X-axis, the rest will work fine.

@epezent
Copy link
Owner

epezent commented Mar 17, 2021

@yamen and @ozlb , I hope to integrate this soon. I know this a feature that many will enjoy. Sorry for the delay.

@arximboldi
Copy link

Oh yes!

This was referenced Mar 29, 2021
@dgm3333
Copy link

dgm3333 commented May 24, 2021

Can I vote for the ozlb code getting pulled into the main branch - I've got a couple of plots I ended up aligning by modifying the axis text :-( but this would be much better.

@dgm3333
Copy link

dgm3333 commented May 24, 2021

Incidentally (as it's related to alignment)
There also seems to be an oddity I can't consistently replicate where if you don't call the SetNextPlotLimitsX before EVERY linked plot the xmin gets set to 0 for all of them (but it seems sometimes OK not to??).
Also I originally assumed you didn't have to manually call SetNextPlotLimitsX (as it's not in the original demo script), but this isn't the case - should the link ALSO call SetNextPlotLimitsX since xmin/max/etc are being set to a value?

if (ImGui::CollapsingHeader("Linked Axes")) {
    static double xmin = 10, xmax = 11, ymin = 0, ymax = 1;
    static bool linkx = true, linky = true;
    int data[2] = {0,1};
    int series[2] = { 10,11 };
    ImGui::Checkbox("Link X", &linkx);
    ImGui::SameLine();
    ImGui::Checkbox("Link Y", &linky);
    ImPlot::LinkNextPlotLimits(linkx ? &xmin : NULL , linkx ? &xmax : NULL, linky ? &ymin : NULL, linky ? &ymax : NULL);
    //ImPlot::SetNextPlotLimitsX(xmin, xmax, ImGuiCond_Once);
    if (ImPlot::BeginPlot("Plot A")) {
        ImPlot::PlotLine("Line",series,data,2);
        ImPlot::EndPlot();
    }
    ImPlot::LinkNextPlotLimits(linkx ? &xmin : NULL , linkx ? &xmax : NULL, linky ? &ymin : NULL, linky ? &ymax : NULL);
    //ImPlot::SetNextPlotLimitsX(xmin, xmax, ImGuiCond_Once);
    if (ImPlot::BeginPlot("Plot B")) {
        ImPlot::PlotLine("Line",series, data,2);
        ImPlot::EndPlot();
    }
}

(using master branches of imgui and implot compiling win64 c++20 under Visual Studio)

epezent added a commit that referenced this pull request Jul 8, 2021
* SubPlots: Y axis padding over multiple plots

* Align Plots Group

new signature ID, ImPool  to store padding data, demo

* Align plots orientation (vertically, horizontally)

vertical will align Y axis, horizontal will align X axis.
*signature changed

* ImPlotOrientation used as flag for 2D grids of aligned plots

#144 (comment)

* AlignPlots updates to merge with v.0.9

* Sync to v0.9 20210127

* subplots proto

* make link flags work

* stuff

* add multi-line centered titles

* subplots work

* flag ideas

* better subplot positioning

* resizable subplots

* subplot shared items

* subplot ratios

* some cleanup and refactor

* some cleanup and refactor

* refactors and demo reorganization

* context menus...almost done!

* context menus, bug fixes

* active id

* make implot use ButtonBehavior throughout

* bug fixes

* more bug fixes

* tweaks

* fix id issue

* finish work on subplots

Co-authored-by: ozlb <[email protected]>
@epezent epezent closed this Jul 8, 2021
@epezent
Copy link
Owner

epezent commented Jul 8, 2021

Merged as a part of #203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants