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

Subplots #203

Merged
merged 32 commits into from
Jul 8, 2021
Merged

Subplots #203

merged 32 commits into from
Jul 8, 2021

Conversation

epezent
Copy link
Owner

@epezent epezent commented Mar 29, 2021

This PR extends the work of @ozlb's aligned plots #144. It adds a new API for creating both 1D and 2D sublots with automatic alignment along rows and columns. I expect this PR to be a WIP for a few weeks, as I want to make subplots a first-class feature and I have several ImPlotSubplotFlags_ options in mind for them.

Looping in interested parties and regulars: @yaman, @peterwilson136, @Mrgoodbytes13, @arximboldi, @ocornut, @bear24rw, @jvannugteren, @mindv0rtex, @PeterJohnson, @hoffstadt

What features would you like to see in a subplot API? How could this be more useful than plots inside of ImGui tables?

Current API prototype (feel free to try, but very rough at the moment). Usage is a simple a matter of surrounding rows*cols calls to Begin/EndPlot inside of Begin/EndSubplot. Plots are arranged in row-major order. Currently it is not possible to plot out of order (and I don't see an easy path forward for that). IDs are handled behind the scenes, so no need to Push/Pop IDs or use different titles. The ImVe2 size parameter of BeginPlot is ignored when inside of a Subplot context, as the size is determind from the parameter passed to BeginSubplot. Otherwise, everything else is the same as using BeginPlot.

ImGui::Begin("Subplots Test");
if (ImPlot::BeginSubplot("Subplots", 3, 3, ImVec2(800,600))) {
    for (int i = 0; i < 9; ++i) {
        if (ImPlot::BeginPlot("Subplot","X","Y") {
            ...
            ImPlot::EndPlot();
        }
    }
    ImPlot::EndSubplot();
}
ImGui::End();

subplot

@yan-zaretskiy
Copy link
Contributor

Two things that come to mind:

@peterwilson136
Copy link

peterwilson136 commented Mar 29, 2021

Some things also, (they might be a bit pedantic)

  1. Multi line titles and labels for axis
  2. Right hand side Y axis labels
  3. Control over the scale of the axes, ie, instead of 1+e06, something such as 1m
  4. Perhaps this might be a tricky one, but when you use ImPlotAxisFlags_Time, can there be another flag that (if specific days are skipped), the plot continues on as if its the next day from when there was a gap., ie,
    1 2 3 7 8 9 11... but representing specific dates / times on the axis? Edit - This would be for something like hours worked in a week, say mon-fri, sat + sun are skipped so have a continuous x-axis of mon-fri for each week.

@epezent
Copy link
Owner Author

epezent commented Mar 30, 2021

@mindv0rtex, I added two flags ImPlotSubplotFlags_LinkRows and ImPlotSubplotFlags_LinkCols that can enable axis linking:

subplots

@bear24rw
Copy link
Contributor

bear24rw commented Mar 31, 2021

One thing that would be super useful for my application is the ability to resize the rows and columns. I currently achieve this in my app by using an invisible button between the plots as demonstrated here.

image

This currently works "okay" but i have the issue of time alignment if the y ticks change width on one of the plots which this branch aims so solve:

image

EDIT: Simply using ImPlot::BeginAlignedPlots in my application "just worked" :) The ability for implot to provide the plot resizing feature as a built-in is less important to me now that I can achieve alignment.

@epezent
Copy link
Owner Author

epezent commented Jun 18, 2021

subplot

Some new features to report:

  • titles
  • shared legends and items
  • draggable splitters

@PeterJohnson
Copy link
Contributor

This looks amazing! Can the split locations be read / initialized? (I have an application where we need to persist the user-edited layout across application restarts).

@epezent
Copy link
Owner Author

epezent commented Jun 18, 2021

Yes, that's what I'm planning. It's not currently implemented in full, but:

IMPLOT_API bool BeginSubplots(const char* title_id,
                             int rows,
                             int cols,
                             const ImVec2& size,
                             ImPlotSubplotFlags flags = ImPlotSubplotFlags_None,
                             float* row_sizes = NULL,
                             float* col_sizes = NULL);

You can set row and col sizes by passing arrays as optional args. These are percentages of total plot width/height, so each array sums to 1. If the user manipulates the splitters, these arrays will be updated and returned as an out paramter.

@epezent epezent mentioned this pull request Jun 18, 2021
@epezent epezent merged commit 8c1bbf4 into master Jul 8, 2021
@epezent epezent deleted the subplots branch July 8, 2021 05:19
ocornut added a commit to ocornut/implot that referenced this pull request Jun 26, 2023
…ap in BeginSubplots(). (epezent#203)

Likely this was pulled from SplitterBehavior(), where it made senses but only given the possibility user would call SetItemAllowOverlap() after.
AFAIK after debugging the code I _think_ this has no meaningful side-effect. Also removed same thing in Tables code in core lib.
Flag added in epezent@4a1ee88.
ocornut added a commit that referenced this pull request Jun 28, 2023
…ap in BeginSubplots(). (#203)

Likely this was pulled from SplitterBehavior(), where it made senses but only given the possibility user would call SetItemAllowOverlap() after.
AFAIK after debugging the code I _think_ this has no meaningful side-effect. Also removed same thing in Tables code in core lib.
Flag added in 4a1ee88.
azonenberg pushed a commit to ngscopeclient/implot that referenced this pull request Aug 16, 2023
…ap in BeginSubplots(). (epezent#203)

Likely this was pulled from SplitterBehavior(), where it made senses but only given the possibility user would call SetItemAllowOverlap() after.
AFAIK after debugging the code I _think_ this has no meaningful side-effect. Also removed same thing in Tables code in core lib.
Flag added in epezent@4a1ee88.
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