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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9c92f8b
SubPlots: Y axis padding over multiple plots
ozlb Nov 9, 2020
066c60d
Align Plots Group
ozlb Nov 11, 2020
0857ece
Align plots orientation (vertically, horizontally)
ozlb Nov 11, 2020
2afebb0
ImPlotOrientation used as flag for 2D grids of aligned plots
ozlb Nov 12, 2020
0f62978
AlignPlots updates to merge with v.0.9
ozlb Nov 16, 2020
39dfb5b
Merge branch 'master' into SubPlots
ozlb Nov 16, 2020
e125749
Sync to v0.9 20210127
ozlb Jan 27, 2021
0a3d0cc
Merge branch 'master' into SubPlots
ozlb Jan 27, 2021
e6e530f
tidy update AlignedPlots
epezent Mar 28, 2021
5116ce2
subplots proto
epezent Mar 29, 2021
9898e2e
make link flags work
epezent Mar 30, 2021
cec3934
stuff
epezent Mar 30, 2021
7352176
add multi-line centered titles
epezent Mar 31, 2021
4e5bfdb
subplots work
epezent Apr 8, 2021
5a2a380
add a few more subplot flags
epezent Jun 10, 2021
8a7ef0b
flag ideas
epezent Jun 11, 2021
673fbcf
better subplot positioning
epezent Jun 11, 2021
88e9489
resizable subplots
epezent Jun 16, 2021
29b467e
subplot shared items
epezent Jun 18, 2021
df57bd4
subplot ratios
epezent Jun 18, 2021
9095431
some cleanup and refactor
epezent Jun 19, 2021
893628a
some cleanup and refactor
epezent Jun 19, 2021
439da77
refactors and demo reorganization
epezent Jun 19, 2021
c561592
context menus...almost done!
epezent Jun 19, 2021
27bda62
context menus, bug fixes
epezent Jun 19, 2021
1a5d2b7
active id
epezent Jun 20, 2021
4a1ee88
make implot use ButtonBehavior throughout
epezent Jun 21, 2021
09d8ef1
bug fixes
epezent Jun 21, 2021
a45975a
more bug fixes
epezent Jun 22, 2021
b58ca9d
tweaks
epezent Jun 23, 2021
833cb3b
fix id issue
epezent Jun 27, 2021
273b4f7
finish work on subplots
epezent Jul 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ImPlot is an immediate mode, GPU accelerated plotting library for [Dear ImGui](h
- and more likely to come
- mix/match multiple plot items on a single plot
- configurable axes ranges and scaling (linear/log)
- subplots
- time formatted x-axes (US formatted or ISO 8601)
- reversible and lockable axes
- up to three independent y-axes
Expand Down
2,061 changes: 1,317 additions & 744 deletions implot.cpp

Large diffs are not rendered by default.

121 changes: 106 additions & 15 deletions implot.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,19 @@
struct ImPlotContext; // ImPlot context (opaque struct, see implot_internal.h)

// Enums/Flags
typedef int ImPlotFlags; // -> enum ImPlotFlags_
typedef int ImPlotAxisFlags; // -> enum ImPlotAxisFlags_
typedef int ImPlotCol; // -> enum ImPlotCol_
typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_
typedef int ImPlotMarker; // -> enum ImPlotMarker_
typedef int ImPlotColormap; // -> enum ImPlotColormap_
typedef int ImPlotLocation; // -> enum ImPlotLocation_
typedef int ImPlotOrientation; // -> enum ImPlotOrientation_
typedef int ImPlotYAxis; // -> enum ImPlotYAxis_;
typedef int ImPlotBin; // -> enum ImPlotBin_

// Options for plots.
typedef int ImPlotFlags; // -> enum ImPlotFlags_
typedef int ImPlotAxisFlags; // -> enum ImPlotAxisFlags_
typedef int ImPlotSubplotFlags; // -> enum ImPlotSubplotFlags_
typedef int ImPlotCol; // -> enum ImPlotCol_
typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_
typedef int ImPlotMarker; // -> enum ImPlotMarker_
typedef int ImPlotColormap; // -> enum ImPlotColormap_
typedef int ImPlotLocation; // -> enum ImPlotLocation_
typedef int ImPlotOrientation; // -> enum ImPlotOrientation_
typedef int ImPlotYAxis; // -> enum ImPlotYAxis_;
typedef int ImPlotBin; // -> enum ImPlotBin_

// Options for plots (see BeginPlot).
enum ImPlotFlags_ {
ImPlotFlags_None = 0, // default
ImPlotFlags_NoTitle = 1 << 0, // the plot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MyPlot")
Expand All @@ -82,7 +83,7 @@ enum ImPlotFlags_ {
ImPlotFlags_CanvasOnly = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMousePos
};

// Options for plot axes (X and Y).
// Options for plot axes (see BeginPlot).
enum ImPlotAxisFlags_ {
ImPlotAxisFlags_None = 0, // default
ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels also hidden if the supplied string name is NULL)
Expand All @@ -102,6 +103,22 @@ enum ImPlotAxisFlags_ {
ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels
};

// Options for subplots (see BeginSubplot).
enum ImPlotSubplotFlags_ {
ImPlotSubplotFlags_None = 0, // default
ImPlotSubplotFlags_NoTitle = 1 << 0, // the subplot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MySubplot")
ImPlotSubplotFlags_NoLegend = 1 << 1, // the legend will not be displayed (only applicable if ImPlotSubplotFlags_ShareItems is enabled)
ImPlotSubplotFlags_NoMenus = 1 << 2, // the user will not be able to open context menus with right-click
ImPlotSubplotFlags_NoResize = 1 << 3, // resize splitters between subplot cells will be not be provided
ImPlotSubplotFlags_NoAlign = 1 << 4, // subplot edges will not be aligned vertically or horizontally
ImPlotSubplotFlags_ShareItems = 1 << 5, // items across all subplots will be shared and rendered into a single legend entry
ImPlotSubplotFlags_LinkRows = 1 << 6, // link the y-axis limits of all plots in each row (does not apply auxiliary y-axes)
ImPlotSubplotFlags_LinkCols = 1 << 7, // link the x-axis limits of all plots in each column
ImPlotSubplotFlags_LinkAllX = 1 << 8, // link the x-axis limits in every plot in the subplot
ImPlotSubplotFlags_LinkAllY = 1 << 9 , // link the y-axis limits in every plot in the subplot (does not apply to auxiliary y-axes)
ImPlotSubplotFlags_ColMajor = 1 << 10 // subplots are added in column major order instead of the default row major order
};

// Plot styling colors.
enum ImPlotCol_ {
// item styling colors
Expand Down Expand Up @@ -301,7 +318,7 @@ struct ImPlotStyle {
ImVec2 AnnotationPadding; // = 2,2 text padding around annotation labels
ImVec2 FitPadding; // = 0,0 additional fit padding as a percentage of the fit extents (e.g. ImVec2(0.1f,0.1f) adds 10% to the fit extents of X and Y)
ImVec2 PlotDefaultSize; // = 400,300 default size used when ImVec2(0,0) is passed to BeginPlot
ImVec2 PlotMinSize; // = 300,225 minimum size plot frame can be when shrunk
ImVec2 PlotMinSize; // = 200,150 minimum size plot frame can be when shrunk
// style colors
ImVec4 Colors[ImPlotCol_COUNT]; // Array of styling colors. Indexable with ImPlotCol_ enums.
// colormap
Expand Down Expand Up @@ -380,6 +397,67 @@ IMPLOT_API bool BeginPlot(const char* title_id,
// of an if statement conditioned on BeginPlot(). See example above.
IMPLOT_API void EndPlot();

//-----------------------------------------------------------------------------
// Begin/EndSubplots
//-----------------------------------------------------------------------------

// Starts a subdivided plotting context. If the function returns true,
// EndSubplots() MUST be called! Call BeginPlot/EndPlot AT MOST [rows*cols]
// times in between the begining and end of the subplot context. Plots are
// added in row major order.
//
// Example:
//
// if (BeginSubplots("My Subplot",2,3,ImVec2(800,400)) {
// for (int i = 0; i < 6; ++i) {
// if (BeginPlot(...)) {
// ImPlot::PlotLine(...);
// ...
// EndPlot();
// }
// }
// EndSubplots();
// }
//
// Procudes:
//
// [0][1][2]
// [3][4][5]
//
// Important notes:
//
// - #title_id must be unique to the current ImGui ID scope. If you need to avoid ID
// collisions or don't want to display a title in the plot, use double hashes
// (e.g. "MyPlot##HiddenIdText" or "##NoTitle").
// - #rows and #cols must be greater than 0.
// - #size is the size of the entire grid of subplots, not the individual plots
// - #row_ratios and #col_ratios must have AT LEAST #rows and #cols elements,
// respectively. These are the sizes of the rows and columns expressed in ratios.
// If the user adjusts the dimensions, the arrays are updated with new ratios.
//
// Important notes regarding BeginPlot from inside of BeginSubplots:
//
// - The #title_id parameter of _BeginPlot_ (see above) does NOT have to be
// unique when called inside of a subplot context. Subplot IDs are hashed
// for your convenience so you don't have call PushID or generate unique title
// strings. Simply pass an empty string to BeginPlot unless you want to title
// each subplot.
// - The #size parameter of _BeginPlot_ (see above) is ignored when inside of a
// subplot context. The actual size of the subplot will be based on the
// #size value you pass to _BeginSubplots_ and #row/#col_ratios if provided.

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

// Only call EndSubplots() if BeginSubplots() returns true! Typically called at the end
// of an if statement conditioned on BeginSublots(). See example above.
IMPLOT_API void EndSubplots();

//-----------------------------------------------------------------------------
// Plot Items
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -573,6 +651,19 @@ IMPLOT_API ImPlotLimits GetPlotQuery(ImPlotYAxis y_axis = IMPLOT_AUTO);
// Set the current plot query bounds. Query must be enabled with ImPlotFlags_Query.
IMPLOT_API void SetPlotQuery(const ImPlotLimits& query, ImPlotYAxis y_axis = IMPLOT_AUTO);

//-----------------------------------------------------------------------------
// Algined Plots
//-----------------------------------------------------------------------------

// Consider using Begin/EndSubplots first. They are more feature rich and
// accomplish the same behaviour by default. The functions below offer lower
// level control of plot alignment.

// Align axis padding over multiple plots in a single row or column. If this function returns true, EndAlignedPlots() must be called. #group_id must be unique.
IMPLOT_API bool BeginAlignedPlots(const char* group_id, ImPlotOrientation orientation = ImPlotOrientation_Vertical);
// Only call EndAlignedPlots() if BeginAlignedPlots() returns true!
IMPLOT_API void EndAlignedPlots();

//-----------------------------------------------------------------------------
// Plot Tools
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -604,7 +695,7 @@ IMPLOT_API bool DragPoint(const char* id, double* x, double* y, bool show_label

// The following functions MUST be called BETWEEN Begin/EndPlot!

// Set the location of the current plot's legend (default = North|West).
// Set the location of the current plot's (or subplot's) legend.
IMPLOT_API void SetLegendLocation(ImPlotLocation location, ImPlotOrientation orientation = ImPlotOrientation_Vertical, bool outside = false);
// Set the location of the current plot's mouse position text (default = South|East).
IMPLOT_API void SetMousePosLocation(ImPlotLocation location);
Expand Down
Loading