1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-13 22:48:50 -05:00
* 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

https://github.com/epezent/implot/pull/144#issuecomment-725849368

* 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 <ozlb@users.noreply.github.com>
This commit is contained in:
Evan Pezent 2021-07-07 21:06:15 -07:00 committed by GitHub
parent 65aa2c8264
commit 8c1bbf4d8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 3057 additions and 2027 deletions

View File

@ -30,6 +30,7 @@ ImPlot is an immediate mode, GPU accelerated plotting library for [Dear ImGui](h
- and more likely to come - and more likely to come
- mix/match multiple plot items on a single plot - mix/match multiple plot items on a single plot
- configurable axes ranges and scaling (linear/log) - configurable axes ranges and scaling (linear/log)
- subplots
- time formatted x-axes (US formatted or ISO 8601) - time formatted x-axes (US formatted or ISO 8601)
- reversible and lockable axes - reversible and lockable axes
- up to three independent y-axes - up to three independent y-axes

1633
implot.cpp

File diff suppressed because it is too large Load Diff

View File

@ -54,6 +54,7 @@ struct ImPlotContext; // ImPlot context (opaque struct, see implot_inte
// Enums/Flags // Enums/Flags
typedef int ImPlotFlags; // -> enum ImPlotFlags_ typedef int ImPlotFlags; // -> enum ImPlotFlags_
typedef int ImPlotAxisFlags; // -> enum ImPlotAxisFlags_ typedef int ImPlotAxisFlags; // -> enum ImPlotAxisFlags_
typedef int ImPlotSubplotFlags; // -> enum ImPlotSubplotFlags_
typedef int ImPlotCol; // -> enum ImPlotCol_ typedef int ImPlotCol; // -> enum ImPlotCol_
typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_ typedef int ImPlotStyleVar; // -> enum ImPlotStyleVar_
typedef int ImPlotMarker; // -> enum ImPlotMarker_ typedef int ImPlotMarker; // -> enum ImPlotMarker_
@ -63,7 +64,7 @@ typedef int ImPlotOrientation; // -> enum ImPlotOrientation_
typedef int ImPlotYAxis; // -> enum ImPlotYAxis_; typedef int ImPlotYAxis; // -> enum ImPlotYAxis_;
typedef int ImPlotBin; // -> enum ImPlotBin_ typedef int ImPlotBin; // -> enum ImPlotBin_
// Options for plots. // Options for plots (see BeginPlot).
enum ImPlotFlags_ { enum ImPlotFlags_ {
ImPlotFlags_None = 0, // default 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") ImPlotFlags_NoTitle = 1 << 0, // the plot title will not be displayed (titles are also hidden if preceeded by double hashes, e.g. "##MyPlot")
@ -82,7 +83,7 @@ enum ImPlotFlags_ {
ImPlotFlags_CanvasOnly = ImPlotFlags_NoTitle | ImPlotFlags_NoLegend | ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMousePos 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_ { enum ImPlotAxisFlags_ {
ImPlotAxisFlags_None = 0, // default 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) ImPlotAxisFlags_NoLabel = 1 << 0, // the axis label will not be displayed (axis labels also hidden if the supplied string name is NULL)
@ -102,6 +103,22 @@ enum ImPlotAxisFlags_ {
ImPlotAxisFlags_NoDecorations = ImPlotAxisFlags_NoLabel | ImPlotAxisFlags_NoGridLines | ImPlotAxisFlags_NoTickMarks | ImPlotAxisFlags_NoTickLabels 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. // Plot styling colors.
enum ImPlotCol_ { enum ImPlotCol_ {
// item styling colors // item styling colors
@ -301,7 +318,7 @@ struct ImPlotStyle {
ImVec2 AnnotationPadding; // = 2,2 text padding around annotation labels 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 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 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 // style colors
ImVec4 Colors[ImPlotCol_COUNT]; // Array of styling colors. Indexable with ImPlotCol_ enums. ImVec4 Colors[ImPlotCol_COUNT]; // Array of styling colors. Indexable with ImPlotCol_ enums.
// colormap // colormap
@ -380,6 +397,67 @@ IMPLOT_API bool BeginPlot(const char* title_id,
// of an if statement conditioned on BeginPlot(). See example above. // of an if statement conditioned on BeginPlot(). See example above.
IMPLOT_API void EndPlot(); 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 // Plot Items
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -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. // 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); 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 // Plot Tools
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -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! // 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); 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). // Set the location of the current plot's mouse position text (default = South|East).
IMPLOT_API void SetMousePosLocation(ImPlotLocation location); IMPLOT_API void SetMousePosLocation(ImPlotLocation location);

View File

@ -174,64 +174,11 @@ struct HugeTimeData {
static const int Size = 60*60*24*366; static const int Size = 60*60*24*366;
}; };
void ShowDemoWindow(bool* p_open) { //-----------------------------------------------------------------------------
double DEMO_TIME = ImGui::GetTime(); // DEMOS
static bool show_imgui_metrics = false; //-----------------------------------------------------------------------------
static bool show_implot_metrics = false;
static bool show_imgui_style_editor = false;
static bool show_implot_style_editor = false;
static bool show_implot_benchmark = false;
if (show_imgui_metrics) {
ImGui::ShowMetricsWindow(&show_imgui_metrics);
}
if (show_implot_metrics) {
ImPlot::ShowMetricsWindow(&show_implot_metrics);
}
if (show_imgui_style_editor) {
ImGui::Begin("Style Editor (ImGui)", &show_imgui_style_editor);
ImGui::ShowStyleEditor();
ImGui::End();
}
if (show_implot_style_editor) {
ImGui::SetNextWindowSize(ImVec2(415,762), ImGuiCond_Appearing);
ImGui::Begin("Style Editor (ImPlot)", &show_implot_style_editor);
ImPlot::ShowStyleEditor();
ImGui::End();
}
if (show_implot_benchmark) {
ImGui::SetNextWindowSize(ImVec2(530,740), ImGuiCond_Appearing);
ImGui::Begin("ImPlot Benchmark Tool", &show_implot_benchmark);
ImPlot::ShowBenchmarkTool();
ImGui::End();
return;
}
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(600, 750), ImGuiCond_FirstUseEver);
ImGui::Begin("ImPlot Demo", p_open, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("Tools")) {
ImGui::MenuItem("Metrics (ImGui)", NULL, &show_imgui_metrics);
ImGui::MenuItem("Metrics (ImPlot)", NULL, &show_implot_metrics);
ImGui::MenuItem("Style Editor (ImGui)", NULL, &show_imgui_style_editor);
ImGui::MenuItem("Style Editor (ImPlot)", NULL, &show_implot_style_editor);
ImGui::MenuItem("Benchmark", NULL, &show_implot_benchmark);
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
//-------------------------------------------------------------------------
ImGui::Text("ImPlot says hello. (%s)", IMPLOT_VERSION);
// display warning about 16-bit indices
static bool showWarning = sizeof(ImDrawIdx)*8 == 16 && (ImGui::GetIO().BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) == false;
if (showWarning) {
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1,1,0,1));
ImGui::TextWrapped("WARNING: ImDrawIdx is 16-bit and ImGuiBackendFlags_RendererHasVtxOffset is false. Expect visual glitches and artifacts! See README for more information.");
ImGui::PopStyleColor();
}
ImGui::Spacing(); void ShowDemo_Help() {
if (ImGui::CollapsingHeader("Help")) {
ImGui::Text("ABOUT THIS DEMO:"); ImGui::Text("ABOUT THIS DEMO:");
ImGui::BulletText("Sections below are demonstrating many aspects of the library."); ImGui::BulletText("Sections below are demonstrating many aspects of the library.");
ImGui::BulletText("The \"Tools\" menu above gives access to: Style Editors (ImPlot/ImGui)\n" ImGui::BulletText("The \"Tools\" menu above gives access to: Style Editors (ImPlot/ImGui)\n"
@ -260,23 +207,31 @@ void ShowDemoWindow(bool* p_open) {
ImGui::Text("USER GUIDE:"); ImGui::Text("USER GUIDE:");
ShowUserGuide(); ShowUserGuide();
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Configuration")) { //-----------------------------------------------------------------------------
void ShowDemo_Configuration() {
ImGui::ShowFontSelector("Font"); ImGui::ShowFontSelector("Font");
ImGui::ShowStyleSelector("ImGui Style"); ImGui::ShowStyleSelector("ImGui Style");
ImPlot::ShowStyleSelector("ImPlot Style"); ImPlot::ShowStyleSelector("ImPlot Style");
ImPlot::ShowColormapSelector("ImPlot Colormap"); ImPlot::ShowColormapSelector("ImPlot Colormap");
float indent = ImGui::CalcItemWidth() - ImGui::GetFrameHeight(); float indent = ImGui::CalcItemWidth() - ImGui::GetFrameHeight();
ImGui::Indent(ImGui::CalcItemWidth() - ImGui::GetFrameHeight()); ImGui::Separator();
ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines); ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines);
ImGui::Separator();
ImGui::Checkbox("Use Local Time", &ImPlot::GetStyle().UseLocalTime);
ImGui::Checkbox("Use ISO 8601", &ImPlot::GetStyle().UseISO8601);
ImGui::Checkbox("Use 24 Hour Clock", &ImPlot::GetStyle().Use24HourClock);
ImGui::Unindent(indent); ImGui::Unindent(indent);
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Line Plots")) { //-----------------------------------------------------------------------------
void ShowDemo_LinePlots() {
static float xs1[1001], ys1[1001]; static float xs1[1001], ys1[1001];
for (int i = 0; i < 1001; ++i) { for (int i = 0; i < 1001; ++i) {
xs1[i] = i * 0.001f; xs1[i] = i * 0.001f;
ys1[i] = 0.5f + 0.5f * sinf(50 * (xs1[i] + (float)DEMO_TIME / 10)); ys1[i] = 0.5f + 0.5f * sinf(50 * (xs1[i] + (float)ImGui::GetTime() / 10));
} }
static double xs2[11], ys2[11]; static double xs2[11], ys2[11];
for (int i = 0; i < 11; ++i) { for (int i = 0; i < 11; ++i) {
@ -291,8 +246,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Filled Line Plots")) { //-----------------------------------------------------------------------------
void ShowDemo_FilledLinePlots() {
static double xs1[101], ys1[101], ys2[101], ys3[101]; static double xs1[101], ys1[101], ys2[101], ys3[101];
srand(0); srand(0);
for (int i = 0; i < 101; ++i) { for (int i = 0; i < 101; ++i) {
@ -324,7 +281,6 @@ void ShowDemoWindow(bool* p_open) {
} }
} }
ImPlot::SetNextPlotLimits(0,100,0,500); ImPlot::SetNextPlotLimits(0,100,0,500);
if (ImPlot::BeginPlot("Stock Prices", "Days", "Price")) { if (ImPlot::BeginPlot("Stock Prices", "Days", "Price")) {
if (show_fills) { if (show_fills) {
@ -342,8 +298,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Shaded Plots##")) { //-----------------------------------------------------------------------------
void ShowDemo_ShadedPlots() {
static float xs[1001], ys[1001], ys1[1001], ys2[1001], ys3[1001], ys4[1001]; static float xs[1001], ys[1001], ys1[1001], ys2[1001], ys3[1001], ys4[1001];
srand(0); srand(0);
for (int i = 0; i < 1001; ++i) { for (int i = 0; i < 1001; ++i) {
@ -368,8 +326,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Scatter Plots")) { //-----------------------------------------------------------------------------
void ShowDemo_ScatterPlots() {
srand(0); srand(0);
static float xs1[100], ys1[100]; static float xs1[100], ys1[100];
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
@ -391,8 +351,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Stairstep Plots")) { //-----------------------------------------------------------------------------
void ShowDemo_StairstepPlots() {
static float ys1[101], ys2[101]; static float ys1[101], ys2[101];
for (int i = 0; i < 101; ++i) { for (int i = 0; i < 101; ++i) {
ys1[i] = 0.5f + 0.4f * sinf(50 * i * 0.01f); ys1[i] = 0.5f + 0.4f * sinf(50 * i * 0.01f);
@ -405,9 +367,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Bar Plots")) {
//-----------------------------------------------------------------------------
void ShowDemo_BarPlots() {
static bool horz = false; static bool horz = false;
static ImS8 midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90}; static ImS8 midtm[10] = {83, 67, 23, 89, 83, 78, 91, 82, 85, 90};
static ImS16 final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100}; static ImS16 final[10] = {80, 62, 56, 99, 55, 78, 88, 78, 90, 100};
@ -444,8 +407,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Error Bars")) { //-----------------------------------------------------------------------------
void ShowDemo_ErrorBars() {
static float xs[5] = {1,2,3,4,5}; static float xs[5] = {1,2,3,4,5};
static float bar[5] = {1,2,5,3,4}; static float bar[5] = {1,2,5,3,4};
static float lin1[5] = {8,8,9,7,8}; static float lin1[5] = {8,8,9,7,8};
@ -476,8 +441,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Stem Plots##")) { void ShowDemo_StemPlots() {
static double xs[51], ys1[51], ys2[51]; static double xs[51], ys1[51], ys2[51];
for (int i = 0; i < 51; ++i) { for (int i = 0; i < 51; ++i) {
xs[i] = i * 0.02; xs[i] = i * 0.02;
@ -493,8 +458,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Infinite Lines")) { void ShowDemo_InfiniteLines() {
static double vals[] = {0.25, 0.5, 0.75}; static double vals[] = {0.25, 0.5, 0.75};
if (ImPlot::BeginPlot("##Infinite",0,0,ImVec2(-1,0),0,ImPlotAxisFlags_NoInitialFit,ImPlotAxisFlags_NoInitialFit)) { if (ImPlot::BeginPlot("##Infinite",0,0,ImVec2(-1,0),0,ImPlotAxisFlags_NoInitialFit,ImPlotAxisFlags_NoInitialFit)) {
ImPlot::PlotVLines("VLines",vals,3); ImPlot::PlotVLines("VLines",vals,3);
@ -502,8 +467,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Pie Charts")) { void ShowDemo_PieCharts() {
static const char* labels1[] = {"Frogs","Hogs","Dogs","Logs"}; static const char* labels1[] = {"Frogs","Hogs","Dogs","Logs"};
static float data1[] = {0.15f, 0.30f, 0.2f, 0.05f}; static float data1[] = {0.15f, 0.30f, 0.2f, 0.05f};
static bool normalize = false; static bool normalize = false;
@ -533,8 +498,8 @@ void ShowDemoWindow(bool* p_open) {
} }
ImPlot::PopColormap(); ImPlot::PopColormap();
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Heatmaps")) { void ShowDemo_Heatmaps() {
static float values1[7][7] = {{0.8f, 2.4f, 2.5f, 3.9f, 0.0f, 4.0f, 0.0f}, static float values1[7][7] = {{0.8f, 2.4f, 2.5f, 3.9f, 0.0f, 4.0f, 0.0f},
{2.4f, 0.0f, 4.0f, 1.0f, 2.7f, 0.0f, 0.0f}, {2.4f, 0.0f, 4.0f, 1.0f, 2.7f, 0.0f, 0.0f},
{1.1f, 2.4f, 0.8f, 4.3f, 1.9f, 4.4f, 0.0f}, {1.1f, 2.4f, 0.8f, 4.3f, 1.9f, 4.4f, 0.0f},
@ -577,7 +542,7 @@ void ShowDemoWindow(bool* p_open) {
const int size = 200; const int size = 200;
static double values2[size*size]; static double values2[size*size];
srand((unsigned int)(DEMO_TIME*1000000)); srand((unsigned int)(ImGui::GetTime()*1000000));
for (int i = 0; i < size*size; ++i) for (int i = 0; i < size*size; ++i)
values2[i] = RandomRange(0.0,1.0); values2[i] = RandomRange(0.0,1.0);
@ -590,8 +555,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::PopColormap(); ImPlot::PopColormap();
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Histograms")) { void ShowDemo_Histogram() {
static int bins = 50; static int bins = 50;
static bool cumulative = false; static bool cumulative = false;
static bool density = true; static bool density = true;
@ -651,7 +616,9 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::PlotLine("Theoretical",x,y,100); ImPlot::PlotLine("Theoretical",x,y,100);
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
}
void ShowDemo_Histogram2D() {
static int count = 500000; static int count = 500000;
static int xybins[2] = {200,200}; static int xybins[2] = {200,200};
static bool density2 = false; static bool density2 = false;
@ -664,6 +631,7 @@ void ShowDemoWindow(bool* p_open) {
double max_count = 0; double max_count = 0;
ImPlotAxisFlags flags = ImPlotAxisFlags_AutoFit|ImPlotAxisFlags_Foreground; ImPlotAxisFlags flags = ImPlotAxisFlags_AutoFit|ImPlotAxisFlags_Foreground;
ImPlot::PushColormap("Hot"); ImPlot::PushColormap("Hot");
ImPlot::SetNextPlotLimits(-6,6,-6,6);
if (ImPlot::BeginPlot("##Hist2D",0,0,ImVec2(ImGui::GetContentRegionAvail().x-100-ImGui::GetStyle().ItemSpacing.x,0),0,flags,flags)) { if (ImPlot::BeginPlot("##Hist2D",0,0,ImVec2(ImGui::GetContentRegionAvail().x-100-ImGui::GetStyle().ItemSpacing.x,0),0,flags,flags)) {
max_count = ImPlot::PlotHistogram2D("Hist2D",dist1.Data,dist2.Data,count,xybins[0],xybins[1],density2,ImPlotLimits(-6,6,-6,6)); max_count = ImPlot::PlotHistogram2D("Hist2D",dist1.Data,dist2.Data,count,xybins[0],xybins[1],density2,ImPlotLimits(-6,6,-6,6));
ImPlot::EndPlot(); ImPlot::EndPlot();
@ -672,8 +640,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::ColormapScale(density2 ? "Density" : "Count",0,max_count,ImVec2(100,0)); ImPlot::ColormapScale(density2 ? "Density" : "Count",0,max_count,ImVec2(100,0));
ImPlot::PopColormap(); ImPlot::PopColormap();
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Digital Plots")) { void ShowDemo_DigitalPlots() {
ImGui::BulletText("Digital plots do not respond to Y drag and zoom, so that"); ImGui::BulletText("Digital plots do not respond to Y drag and zoom, so that");
ImGui::Indent(); ImGui::Indent();
ImGui::Text("you can drag analog plots over the rising/falling digital edge."); ImGui::Text("you can drag analog plots over the rising/falling digital edge.");
@ -724,8 +692,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Images")) { void ShowDemo_Images() {
ImGui::BulletText("Below we are displaying the font texture, which is the only texture we have\naccess to in this demo."); ImGui::BulletText("Below we are displaying the font texture, which is the only texture we have\naccess to in this demo.");
ImGui::BulletText("Use the 'ImTextureID' type as storage to pass pointers or identifiers to your\nown texture data."); ImGui::BulletText("Use the 'ImTextureID' type as storage to pass pointers or identifiers to your\nown texture data.");
ImGui::BulletText("See ImGui Wiki page 'Image Loading and Displaying Examples'."); ImGui::BulletText("See ImGui Wiki page 'Image Loading and Displaying Examples'.");
@ -744,8 +712,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Realtime Plots")) { void ShowDemo_RealtimePlots() {
ImGui::BulletText("Move your mouse to change the data!"); ImGui::BulletText("Move your mouse to change the data!");
ImGui::BulletText("This example assumes 60 FPS. Higher FPS requires larger buffer size."); ImGui::BulletText("This example assumes 60 FPS. Higher FPS requires larger buffer size.");
static ScrollingBuffer sdata1, sdata2; static ScrollingBuffer sdata1, sdata2;
@ -780,8 +748,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Markers and Text")) { void ShowDemo_MarkersAndText() {
static float mk_size = ImPlot::GetStyle().MarkerSize; static float mk_size = ImPlot::GetStyle().MarkerSize;
static float mk_weight = ImPlot::GetStyle().MarkerWeight; static float mk_weight = ImPlot::GetStyle().MarkerWeight;
ImGui::DragFloat("Marker Size",&mk_size,0.1f,2.0f,10.0f,"%.2f px"); ImGui::DragFloat("Marker Size",&mk_size,0.1f,2.0f,10.0f,"%.2f px");
@ -820,8 +788,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Log Scale")) { void ShowDemo_LogAxes() {
static double xs[1001], ys1[1001], ys2[1001], ys3[1001]; static double xs[1001], ys1[1001], ys2[1001], ys3[1001];
for (int i = 0; i < 1001; ++i) { for (int i = 0; i < 1001; ++i) {
xs[i] = i*0.1f; xs[i] = i*0.1f;
@ -840,7 +808,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
if (ImGui::CollapsingHeader("Time Formatted Axes")) {
void ShowDemo_TimeAxes() {
static double t_min = 1609459200; // 01/01/2021 @ 12:00:00am (UTC) static double t_min = 1609459200; // 01/01/2021 @ 12:00:00am (UTC)
static double t_max = 1640995200; // 01/01/2022 @ 12:00:00am (UTC) static double t_max = 1640995200; // 01/01/2022 @ 12:00:00am (UTC)
@ -885,8 +854,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Multiple Y-Axes")) { void ShowDemo_MultipleYAxes() {
static float xs[1001], xs2[1001], ys1[1001], ys2[1001], ys3[1001]; static float xs[1001], xs2[1001], ys1[1001], ys2[1001], ys3[1001];
for (int i = 0; i < 1001; ++i) { for (int i = 0; i < 1001; ++i) {
xs[i] = (i*0.1f); xs[i] = (i*0.1f);
@ -929,14 +898,15 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Linked Axes")) { void ShowDemo_LinkedAxes() {
static double xmin = 0, xmax = 1, ymin = 0, ymax = 1; static double xmin = 0, xmax = 1, ymin = 0, ymax = 1;
static bool linkx = true, linky = true; static bool linkx = true, linky = true;
int data[2] = {0,1}; int data[2] = {0,1};
ImGui::Checkbox("Link X", &linkx); ImGui::Checkbox("Link X", &linkx);
ImGui::SameLine(); ImGui::SameLine();
ImGui::Checkbox("Link Y", &linky); ImGui::Checkbox("Link Y", &linky);
if (BeginAlignedPlots("AlignedGroup")) {
ImPlot::LinkNextPlotLimits(linkx ? &xmin : NULL , linkx ? &xmax : NULL, linky ? &ymin : NULL, linky ? &ymax : NULL); ImPlot::LinkNextPlotLimits(linkx ? &xmin : NULL , linkx ? &xmax : NULL, linky ? &ymin : NULL, linky ? &ymax : NULL);
if (ImPlot::BeginPlot("Plot A")) { if (ImPlot::BeginPlot("Plot A")) {
ImPlot::PlotLine("Line",data,2); ImPlot::PlotLine("Line",data,2);
@ -947,9 +917,11 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::PlotLine("Line",data,2); ImPlot::PlotLine("Line",data,2);
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
ImPlot::EndAlignedPlots();
} }
//------------------------------------------------------------------------- }
if (ImGui::CollapsingHeader("Equal Axes")) {
void ShowDemo_EqualAxes() {
static double xs[1000], ys[1000]; static double xs[1000], ys[1000];
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
double angle = i * 2 * PI / 999.0; double angle = i * 2 * PI / 999.0;
@ -960,9 +932,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Auto-Fitting Data")) {
void ShowDemo_AutoFittingData() {
ImGui::BulletText("The Y-axis has been configured to auto-fit to only the data visible in X-axis range."); ImGui::BulletText("The Y-axis has been configured to auto-fit to only the data visible in X-axis range.");
ImGui::BulletText("Zoom and pan the X-axis. Disable Stems to see a difference in fit."); ImGui::BulletText("Zoom and pan the X-axis. Disable Stems to see a difference in fit.");
ImGui::BulletText("If ImPlotAxisFlags_RangeFit is disabled, the axis will fit ALL data."); ImGui::BulletText("If ImPlotAxisFlags_RangeFit is disabled, the axis will fit ALL data.");
@ -989,20 +960,128 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
}; };
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Querying")) { ImPlotPoint SinewaveGetter(void* data, int i) {
float f = *(float*)data;
return ImPlotPoint(i,sinf(f*i));
}
void ShowDemo_SubplotsSizing() {
static ImPlotSubplotFlags flags = ImPlotSubplotFlags_None;
ImGui::CheckboxFlags("ImPlotSubplotFlags_NoResize", (unsigned int*)&flags, ImPlotSubplotFlags_NoResize);
ImGui::CheckboxFlags("ImPlotSubplotFlags_NoTitle", (unsigned int*)&flags, ImPlotSubplotFlags_NoTitle);
static int rows = 3;
static int cols = 3;
ImGui::SliderInt("Rows",&rows,1,5);
ImGui::SliderInt("Cols",&cols,1,5);
static float rratios[] = {5,1,1,1,1,1};
static float cratios[] = {5,1,1,1,1,1};
ImGui::DragScalarN("Row Ratios",ImGuiDataType_Float,rratios,rows,0.01f,0);
ImGui::DragScalarN("Col Ratios",ImGuiDataType_Float,cratios,cols,0.01f,0);
if (ImPlot::BeginSubplots("My Subplots", rows, cols, ImVec2(-1,400), flags, rratios, cratios)) {
for (int i = 0; i < rows*cols; ++i) {
if (ImPlot::BeginPlot("",NULL,NULL,ImVec2(),ImPlotFlags_NoLegend,ImPlotAxisFlags_NoTickLabels,ImPlotAxisFlags_NoTickLabels)) {
char buffer[8];
float fi = 0.01f * (i+1);
sprintf(buffer, "data%d", i);
if (i == 0)
ImPlot::SetNextLineStyle(ImVec4(0,1,0,1));
ImPlot::PlotLineG(buffer,SinewaveGetter,&fi,1000);
ImPlot::EndPlot();
}
}
ImPlot::EndSubplots();
}
}
void ShowDemo_SubplotItemSharing() {
static ImPlotSubplotFlags flags = ImPlotSubplotFlags_ShareItems;
ImGui::CheckboxFlags("ImPlotSubplotFlags_ShareItems", (unsigned int*)&flags, ImPlotSubplotFlags_ShareItems);
ImGui::CheckboxFlags("ImPlotSubplotFlags_ColMajor", (unsigned int*)&flags, ImPlotSubplotFlags_ColMajor);
static int rows = 2;
static int cols = 3;
static int id[] = {0,1,2,3,4,5};
static int curj = -1;
if (ImPlot::BeginSubplots("##ItemSharing", rows, cols, ImVec2(-1,400), flags)) {
for (int i = 0; i < rows*cols; ++i) {
if (ImPlot::BeginPlot("")) {
float fc = 0.01f;
ImPlot::PlotLineG("common",SinewaveGetter,&fc,1000);
for (int j = 0; j < 6; ++j) {
if (id[j] == i) {
char label[8];
float fj = 0.01f * (j+2);
sprintf(label, "data%d", j);
ImPlot::PlotLineG(label,SinewaveGetter,&fj,1000);
if (ImPlot::BeginDragDropSourceItem(label)) {
curj = j;
ImGui::SetDragDropPayload("MY_DND",NULL,0);
ImPlot::ItemIcon(GetLastItemColor()); ImGui::SameLine();
ImGui::TextUnformatted(label);
ImPlot::EndDragDropSource();
}
}
}
if (ImPlot::BeginDragDropTarget()) {
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("MY_DND"))
id[curj] = i;
ImPlot::EndDragDropTarget();
}
ImPlot::EndPlot();
}
}
ImPlot::EndSubplots();
}
}
void ShowDemo_SubplotAxisLinking() {
static ImPlotSubplotFlags flags = ImPlotSubplotFlags_LinkRows | ImPlotSubplotFlags_LinkCols;
ImGui::CheckboxFlags("ImPlotSubplotFlags_LinkRows", (unsigned int*)&flags, ImPlotSubplotFlags_LinkRows);
ImGui::CheckboxFlags("ImPlotSubplotFlags_LinkCols", (unsigned int*)&flags, ImPlotSubplotFlags_LinkCols);
ImGui::CheckboxFlags("ImPlotSubplotFlags_LinkAllX", (unsigned int*)&flags, ImPlotSubplotFlags_LinkAllX);
ImGui::CheckboxFlags("ImPlotSubplotFlags_LinkAllY", (unsigned int*)&flags, ImPlotSubplotFlags_LinkAllY);
static int rows = 2;
static int cols = 2;
if (ImPlot::BeginSubplots("##AxisLinking", rows, cols, ImVec2(-1,400), flags)) {
for (int i = 0; i < rows*cols; ++i) {
ImPlot::SetNextPlotLimits(0,1000,-1,1);
if (ImPlot::BeginPlot("")) {
float fc = 0.01f;
ImPlot::PlotLineG("common",SinewaveGetter,&fc,1000);
ImPlot::EndPlot();
}
}
ImPlot::EndSubplots();
}
}
void ShowDemo_Querying() {
static ImVector<ImPlotPoint> data; static ImVector<ImPlotPoint> data;
static ImPlotLimits range, query, select; static ImPlotLimits range, query, select;
static bool init = true;
if (init) {
for (int i = 0; i < 50; ++i)
{
double x = RandomRange(0.0, 1.0);
double y = RandomRange(0.0, 1.0);
data.push_back(ImPlotPoint(x,y));
}
init = false;
}
ImGui::BulletText("Ctrl + click in the plot area to draw points.");
ImGui::BulletText("Middle click (or Ctrl + right click) and drag to create a query rect."); ImGui::BulletText("Middle click (or Ctrl + right click) and drag to create a query rect.");
ImGui::Indent(); ImGui::Indent();
ImGui::BulletText("Hold Alt to expand query horizontally."); ImGui::BulletText("Hold Alt to expand query horizontally.");
ImGui::BulletText("Hold Shift to expand query vertically."); ImGui::BulletText("Hold Shift to expand query vertically.");
ImGui::BulletText("The query rect can be dragged after it's created."); ImGui::BulletText("The query rect can be dragged after it's created.");
ImGui::Unindent(); ImGui::Unindent();
ImGui::BulletText("Ctrl + click in the plot area to draw points.");
if (ImPlot::BeginPlot("##Drawing", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Query, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations)) { ImPlot::SetNextPlotLimits(0,1,0,1);
if (ImPlot::BeginPlot("##Centroid", NULL, NULL, ImVec2(-1,0), ImPlotFlags_Query)) {
if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) { if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(0) && ImGui::GetIO().KeyCtrl) {
ImPlotPoint pt = ImPlot::GetPlotMousePos(); ImPlotPoint pt = ImPlot::GetPlotMousePos();
data.push_back(pt); data.push_back(pt);
@ -1024,7 +1103,7 @@ void ShowDemoWindow(bool* p_open) {
avg.x = avg.x / cnt; avg.x = avg.x / cnt;
avg.y = avg.y / cnt; avg.y = avg.y / cnt;
ImPlot::SetNextMarkerStyle(ImPlotMarker_Square); ImPlot::SetNextMarkerStyle(ImPlotMarker_Square);
ImPlot::PlotScatter("Average", &avg.x, &avg.y, 1); ImPlot::PlotScatter("Centroid", &avg.x, &avg.y, 1);
} }
} }
range = ImPlot::GetPlotLimits(); range = ImPlot::GetPlotLimits();
@ -1035,10 +1114,9 @@ void ShowDemoWindow(bool* p_open) {
ImGui::Text("Limits: [%g,%g,%g,%g]", range.X.Min, range.X.Max, range.Y.Min, range.Y.Max); ImGui::Text("Limits: [%g,%g,%g,%g]", range.X.Min, range.X.Max, range.Y.Min, range.Y.Max);
ImGui::Text("Query: [%g,%g,%g,%g]", query.X.Min, query.X.Max, query.Y.Min, query.Y.Max); ImGui::Text("Query: [%g,%g,%g,%g]", query.X.Min, query.X.Max, query.Y.Min, query.Y.Max);
ImGui::Text("Selection: [%g,%g,%g,%g]", select.X.Min, select.X.Max, select.Y.Min, select.Y.Max); ImGui::Text("Selection: [%g,%g,%g,%g]", select.X.Min, select.X.Max, select.Y.Min, select.Y.Max);
}
ImGui::Separator(); void ShowDemo_Views() {
// mimic's soulthread's imgui_plot demo
static float x_data[512]; static float x_data[512];
static float y_data1[512]; static float y_data1[512];
static float y_data2[512]; static float y_data2[512];
@ -1078,8 +1156,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Legend")) { void ShowDemo_LegendOptions() {
static ImPlotLocation loc = ImPlotLocation_East; static ImPlotLocation loc = ImPlotLocation_East;
static bool h = false; static bool o = true; static bool h = false; static bool o = true;
ImGui::CheckboxFlags("North", (unsigned int*)&loc, ImPlotLocation_North); ImGui::SameLine(); ImGui::CheckboxFlags("North", (unsigned int*)&loc, ImPlotLocation_North); ImGui::SameLine();
@ -1106,8 +1184,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Drag Lines and Points")) { void ShowDemo_DragLines() {
ImGui::BulletText("Click and drag the horizontal and vertical lines."); ImGui::BulletText("Click and drag the horizontal and vertical lines.");
static double x1 = 0.2; static double x1 = 0.2;
static double x2 = 0.8; static double x2 = 0.8;
@ -1132,6 +1210,10 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::DragLineY("f",&f,show_labels,ImVec4(1,0.5f,1,1)); ImPlot::DragLineY("f",&f,show_labels,ImVec4(1,0.5f,1,1));
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
}
void ShowDemo_DragPoints() {
static bool show_labels = true;
ImGui::BulletText("Click and drag any point."); ImGui::BulletText("Click and drag any point.");
ImGui::Checkbox("Show Labels##2",&show_labels); ImGui::Checkbox("Show Labels##2",&show_labels);
ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoTickMarks; ImPlotAxisFlags flags = ImPlotAxisFlags_NoTickLabels | ImPlotAxisFlags_NoTickMarks;
@ -1161,7 +1243,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
if (ImGui::CollapsingHeader("Annotations")) {
void ShowDemo_Annotations() {
static bool clamp = false; static bool clamp = false;
ImGui::Checkbox("Clamp",&clamp); ImGui::Checkbox("Clamp",&clamp);
ImPlot::SetNextPlotLimits(0,2,0,1); ImPlot::SetNextPlotLimits(0,2,0,1);
@ -1184,13 +1267,13 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Drag and Drop")) { void ShowDemo_DragAndDrop() {
ImGui::BulletText("Drag/drop items from the left column."); ImGui::BulletText("Drag/drop items from the left column.");
ImGui::BulletText("Drag/drop items between plots."); ImGui::BulletText("Drag/drop items between plots.");
ImGui::Indent(); ImGui::Indent();
ImGui::BulletText("Plot 1 Targets: Plot, Y-Axes, Legend"); ImGui::BulletText("Plot 1 Targets: Plot, Y-Axes, Legend");
ImGui::BulletText("Plot 1 Sources: Legend Items"); ImGui::BulletText("Plot 1 Sources: Legend Item Labels");
ImGui::BulletText("Plot 2 Targets: Plot, X-Axis, Y-Axis"); ImGui::BulletText("Plot 2 Targets: Plot, X-Axis, Y-Axis");
ImGui::BulletText("Plot 2 Sources: Plot, X-Axis, Y-Axis (hold Ctrl)"); ImGui::BulletText("Plot 2 Sources: Plot, X-Axis, Y-Axis (hold Ctrl)");
ImGui::Unindent(); ImGui::Unindent();
@ -1350,13 +1433,13 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::PopStyleColor(2); ImPlot::PopStyleColor(2);
ImGui::EndChild(); ImGui::EndChild();
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Tables")) { void ShowDemo_Tables() {
#ifdef IMGUI_HAS_TABLE #ifdef IMGUI_HAS_TABLE
static ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_RowBg; static ImGuiTableFlags flags = ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_RowBg;
static bool anim = true; static bool anim = true;
static int offset = 0; static int offset = 0;
ImGui::BulletText("Plots can be used inside of ImGui tables."); ImGui::BulletText("Plots can be used inside of ImGui tables as a means of creating subplots.");
ImGui::Checkbox("Animate",&anim); ImGui::Checkbox("Animate",&anim);
if (anim) if (anim)
offset = (offset + 1) % 100; offset = (offset + 1) % 100;
@ -1388,8 +1471,8 @@ void ShowDemoWindow(bool* p_open) {
ImGui::BulletText("You need to merge the ImGui 'tables' branch for this section."); ImGui::BulletText("You need to merge the ImGui 'tables' branch for this section.");
#endif #endif
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Offset and Stride")) { void ShowDemo_OffsetAndStride() {
static const int k_circles = 11; static const int k_circles = 11;
static const int k_points_per = 50; static const int k_points_per = 50;
static const int k_size = 2 * k_points_per * k_circles; static const int k_size = 2 * k_points_per * k_circles;
@ -1421,8 +1504,8 @@ void ShowDemoWindow(bool* p_open) {
} }
// offset++; uncomment for animation! // offset++; uncomment for animation!
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Data and Getters")) { void ShowDemo_CustomDataAndGetters() {
ImGui::BulletText("You can plot custom structs using the stride feature."); ImGui::BulletText("You can plot custom structs using the stride feature.");
ImGui::BulletText("Most plotters can also be passed a function pointer for getting data."); ImGui::BulletText("Most plotters can also be passed a function pointer for getting data.");
ImGui::Indent(); ImGui::Indent();
@ -1456,8 +1539,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Ticks##")) { void ShowDemo_TickLabels() {
static bool custom_fmt = true; static bool custom_fmt = true;
static bool custom_ticks = false; static bool custom_ticks = false;
static bool custom_labels = true; static bool custom_labels = true;
@ -1487,13 +1570,13 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::SetNextPlotTicksY(0, 1, 6, custom_labels ? ylabels_aux : NULL, false, ImPlotYAxis_3); ImPlot::SetNextPlotTicksY(0, 1, 6, custom_labels ? ylabels_aux : NULL, false, ImPlotYAxis_3);
} }
ImPlot::SetNextPlotLimits(2.5,5,0,10); ImPlot::SetNextPlotLimits(2.5,5,0,10);
if (ImPlot::BeginPlot("Custom Ticks", NULL, NULL, ImVec2(-1,0), ImPlotFlags_YAxis2 | ImPlotFlags_YAxis3)) { if (ImPlot::BeginPlot("##Ticks", NULL, NULL, ImVec2(-1,0), ImPlotFlags_YAxis2 | ImPlotFlags_YAxis3)) {
// nothing to see here, just the ticks // nothing to see here, just the ticks
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Styles")) { void ShowDemo_CustomStyles() {
ImPlot::PushColormap(ImPlotColormap_Deep); ImPlot::PushColormap(ImPlotColormap_Deep);
// normally you wouldn't change the entire style each frame // normally you wouldn't change the entire style each frame
ImPlotStyle backup = ImPlot::GetStyle(); ImPlotStyle backup = ImPlot::GetStyle();
@ -1512,8 +1595,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::GetStyle() = backup; ImPlot::GetStyle() = backup;
ImPlot::PopColormap(); ImPlot::PopColormap();
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Rendering")) { void ShowDemo_CustomRendering() {
if (ImPlot::BeginPlot("##CustomRend")) { if (ImPlot::BeginPlot("##CustomRend")) {
ImVec2 cntr = ImPlot::PlotToPixels(ImPlotPoint(0.5f, 0.5f)); ImVec2 cntr = ImPlot::PlotToPixels(ImPlotPoint(0.5f, 0.5f));
ImVec2 rmin = ImPlot::PlotToPixels(ImPlotPoint(0.25f, 0.75f)); ImVec2 rmin = ImPlot::PlotToPixels(ImPlotPoint(0.25f, 0.75f));
@ -1525,8 +1608,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Context Menus")) { void ShowDemo_LegendPopups() {
ImGui::BulletText("You can implement legend context menus to inject per-item controls and widgets."); ImGui::BulletText("You can implement legend context menus to inject per-item controls and widgets.");
ImGui::BulletText("Right click the legend label/icon to edit custom item attributes."); ImGui::BulletText("Right click the legend label/icon to edit custom item attributes.");
@ -1576,8 +1659,8 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Custom Plotters and Tooltips")) { void ShowDemo_CustomPlottersAndTooltips() {
ImGui::BulletText("You can create custom plotters or extend ImPlot using implot_internal.h."); ImGui::BulletText("You can create custom plotters or extend ImPlot using implot_internal.h.");
double dates[] = {1546300800,1546387200,1546473600,1546560000,1546819200,1546905600,1546992000,1547078400,1547164800,1547424000,1547510400,1547596800,1547683200,1547769600,1547942400,1548028800,1548115200,1548201600,1548288000,1548374400,1548633600,1548720000,1548806400,1548892800,1548979200,1549238400,1549324800,1549411200,1549497600,1549584000,1549843200,1549929600,1550016000,1550102400,1550188800,1550361600,1550448000,1550534400,1550620800,1550707200,1550793600,1551052800,1551139200,1551225600,1551312000,1551398400,1551657600,1551744000,1551830400,1551916800,1552003200,1552262400,1552348800,1552435200,1552521600,1552608000,1552867200,1552953600,1553040000,1553126400,1553212800,1553472000,1553558400,1553644800,1553731200,1553817600,1554076800,1554163200,1554249600,1554336000,1554422400,1554681600,1554768000,1554854400,1554940800,1555027200,1555286400,1555372800,1555459200,1555545600,1555632000,1555891200,1555977600,1556064000,1556150400,1556236800,1556496000,1556582400,1556668800,1556755200,1556841600,1557100800,1557187200,1557273600,1557360000,1557446400,1557705600,1557792000,1557878400,1557964800,1558051200,1558310400,1558396800,1558483200,1558569600,1558656000,1558828800,1558915200,1559001600,1559088000,1559174400,1559260800,1559520000,1559606400,1559692800,1559779200,1559865600,1560124800,1560211200,1560297600,1560384000,1560470400,1560729600,1560816000,1560902400,1560988800,1561075200,1561334400,1561420800,1561507200,1561593600,1561680000,1561939200,1562025600,1562112000,1562198400,1562284800,1562544000,1562630400,1562716800,1562803200,1562889600,1563148800,1563235200,1563321600,1563408000,1563494400,1563753600,1563840000,1563926400,1564012800,1564099200,1564358400,1564444800,1564531200,1564617600,1564704000,1564963200,1565049600,1565136000,1565222400,1565308800,1565568000,1565654400,1565740800,1565827200,1565913600,1566172800,1566259200,1566345600,1566432000,1566518400,1566777600,1566864000,1566950400,1567036800,1567123200,1567296000,1567382400,1567468800,1567555200,1567641600,1567728000,1567987200,1568073600,1568160000,1568246400,1568332800,1568592000,1568678400,1568764800,1568851200,1568937600,1569196800,1569283200,1569369600,1569456000,1569542400,1569801600,1569888000,1569974400,1570060800,1570147200,1570406400,1570492800,1570579200,1570665600,1570752000,1571011200,1571097600,1571184000,1571270400,1571356800,1571616000,1571702400,1571788800,1571875200,1571961600}; double dates[] = {1546300800,1546387200,1546473600,1546560000,1546819200,1546905600,1546992000,1547078400,1547164800,1547424000,1547510400,1547596800,1547683200,1547769600,1547942400,1548028800,1548115200,1548201600,1548288000,1548374400,1548633600,1548720000,1548806400,1548892800,1548979200,1549238400,1549324800,1549411200,1549497600,1549584000,1549843200,1549929600,1550016000,1550102400,1550188800,1550361600,1550448000,1550534400,1550620800,1550707200,1550793600,1551052800,1551139200,1551225600,1551312000,1551398400,1551657600,1551744000,1551830400,1551916800,1552003200,1552262400,1552348800,1552435200,1552521600,1552608000,1552867200,1552953600,1553040000,1553126400,1553212800,1553472000,1553558400,1553644800,1553731200,1553817600,1554076800,1554163200,1554249600,1554336000,1554422400,1554681600,1554768000,1554854400,1554940800,1555027200,1555286400,1555372800,1555459200,1555545600,1555632000,1555891200,1555977600,1556064000,1556150400,1556236800,1556496000,1556582400,1556668800,1556755200,1556841600,1557100800,1557187200,1557273600,1557360000,1557446400,1557705600,1557792000,1557878400,1557964800,1558051200,1558310400,1558396800,1558483200,1558569600,1558656000,1558828800,1558915200,1559001600,1559088000,1559174400,1559260800,1559520000,1559606400,1559692800,1559779200,1559865600,1560124800,1560211200,1560297600,1560384000,1560470400,1560729600,1560816000,1560902400,1560988800,1561075200,1561334400,1561420800,1561507200,1561593600,1561680000,1561939200,1562025600,1562112000,1562198400,1562284800,1562544000,1562630400,1562716800,1562803200,1562889600,1563148800,1563235200,1563321600,1563408000,1563494400,1563753600,1563840000,1563926400,1564012800,1564099200,1564358400,1564444800,1564531200,1564617600,1564704000,1564963200,1565049600,1565136000,1565222400,1565308800,1565568000,1565654400,1565740800,1565827200,1565913600,1566172800,1566259200,1566345600,1566432000,1566518400,1566777600,1566864000,1566950400,1567036800,1567123200,1567296000,1567382400,1567468800,1567555200,1567641600,1567728000,1567987200,1568073600,1568160000,1568246400,1568332800,1568592000,1568678400,1568764800,1568851200,1568937600,1569196800,1569283200,1569369600,1569456000,1569542400,1569801600,1569888000,1569974400,1570060800,1570147200,1570406400,1570492800,1570579200,1570665600,1570752000,1571011200,1571097600,1571184000,1571270400,1571356800,1571616000,1571702400,1571788800,1571875200,1571961600};
double opens[] = {1284.7,1319.9,1318.7,1328,1317.6,1321.6,1314.3,1325,1319.3,1323.1,1324.7,1321.3,1323.5,1322,1281.3,1281.95,1311.1,1315,1314,1313.1,1331.9,1334.2,1341.3,1350.6,1349.8,1346.4,1343.4,1344.9,1335.6,1337.9,1342.5,1337,1338.6,1337,1340.4,1324.65,1324.35,1349.5,1371.3,1367.9,1351.3,1357.8,1356.1,1356,1347.6,1339.1,1320.6,1311.8,1314,1312.4,1312.3,1323.5,1319.1,1327.2,1332.1,1320.3,1323.1,1328,1330.9,1338,1333,1335.3,1345.2,1341.1,1332.5,1314,1314.4,1310.7,1314,1313.1,1315,1313.7,1320,1326.5,1329.2,1314.2,1312.3,1309.5,1297.4,1293.7,1277.9,1295.8,1295.2,1290.3,1294.2,1298,1306.4,1299.8,1302.3,1297,1289.6,1302,1300.7,1303.5,1300.5,1303.2,1306,1318.7,1315,1314.5,1304.1,1294.7,1293.7,1291.2,1290.2,1300.4,1284.2,1284.25,1301.8,1295.9,1296.2,1304.4,1323.1,1340.9,1341,1348,1351.4,1351.4,1343.5,1342.3,1349,1357.6,1357.1,1354.7,1361.4,1375.2,1403.5,1414.7,1433.2,1438,1423.6,1424.4,1418,1399.5,1435.5,1421.25,1434.1,1412.4,1409.8,1412.2,1433.4,1418.4,1429,1428.8,1420.6,1441,1460.4,1441.7,1438.4,1431,1439.3,1427.4,1431.9,1439.5,1443.7,1425.6,1457.5,1451.2,1481.1,1486.7,1512.1,1515.9,1509.2,1522.3,1513,1526.6,1533.9,1523,1506.3,1518.4,1512.4,1508.8,1545.4,1537.3,1551.8,1549.4,1536.9,1535.25,1537.95,1535.2,1556,1561.4,1525.6,1516.4,1507,1493.9,1504.9,1506.5,1513.1,1506.5,1509.7,1502,1506.8,1521.5,1529.8,1539.8,1510.9,1511.8,1501.7,1478,1485.4,1505.6,1511.6,1518.6,1498.7,1510.9,1510.8,1498.3,1492,1497.7,1484.8,1494.2,1495.6,1495.6,1487.5,1491.1,1495.1,1506.4}; double opens[] = {1284.7,1319.9,1318.7,1328,1317.6,1321.6,1314.3,1325,1319.3,1323.1,1324.7,1321.3,1323.5,1322,1281.3,1281.95,1311.1,1315,1314,1313.1,1331.9,1334.2,1341.3,1350.6,1349.8,1346.4,1343.4,1344.9,1335.6,1337.9,1342.5,1337,1338.6,1337,1340.4,1324.65,1324.35,1349.5,1371.3,1367.9,1351.3,1357.8,1356.1,1356,1347.6,1339.1,1320.6,1311.8,1314,1312.4,1312.3,1323.5,1319.1,1327.2,1332.1,1320.3,1323.1,1328,1330.9,1338,1333,1335.3,1345.2,1341.1,1332.5,1314,1314.4,1310.7,1314,1313.1,1315,1313.7,1320,1326.5,1329.2,1314.2,1312.3,1309.5,1297.4,1293.7,1277.9,1295.8,1295.2,1290.3,1294.2,1298,1306.4,1299.8,1302.3,1297,1289.6,1302,1300.7,1303.5,1300.5,1303.2,1306,1318.7,1315,1314.5,1304.1,1294.7,1293.7,1291.2,1290.2,1300.4,1284.2,1284.25,1301.8,1295.9,1296.2,1304.4,1323.1,1340.9,1341,1348,1351.4,1351.4,1343.5,1342.3,1349,1357.6,1357.1,1354.7,1361.4,1375.2,1403.5,1414.7,1433.2,1438,1423.6,1424.4,1418,1399.5,1435.5,1421.25,1434.1,1412.4,1409.8,1412.2,1433.4,1418.4,1429,1428.8,1420.6,1441,1460.4,1441.7,1438.4,1431,1439.3,1427.4,1431.9,1439.5,1443.7,1425.6,1457.5,1451.2,1481.1,1486.7,1512.1,1515.9,1509.2,1522.3,1513,1526.6,1533.9,1523,1506.3,1518.4,1512.4,1508.8,1545.4,1537.3,1551.8,1549.4,1536.9,1535.25,1537.95,1535.2,1556,1561.4,1525.6,1516.4,1507,1493.9,1504.9,1506.5,1513.1,1506.5,1509.7,1502,1506.8,1521.5,1529.8,1539.8,1510.9,1511.8,1501.7,1478,1485.4,1505.6,1511.6,1518.6,1498.7,1510.9,1510.8,1498.3,1492,1497.7,1484.8,1494.2,1495.6,1495.6,1487.5,1491.1,1495.1,1506.4};
@ -1599,7 +1682,175 @@ void ShowDemoWindow(bool* p_open) {
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
} }
//-----------------------------------------------------------------------------
// DEMO WINDOW
//-----------------------------------------------------------------------------
void ShowDemoWindow(bool* p_open) {
static bool show_imgui_metrics = false;
static bool show_implot_metrics = false;
static bool show_imgui_style_editor = false;
static bool show_implot_style_editor = false;
static bool show_implot_benchmark = false;
if (show_imgui_metrics) {
ImGui::ShowMetricsWindow(&show_imgui_metrics);
}
if (show_implot_metrics) {
ImPlot::ShowMetricsWindow(&show_implot_metrics);
}
if (show_imgui_style_editor) {
ImGui::Begin("Style Editor (ImGui)", &show_imgui_style_editor);
ImGui::ShowStyleEditor();
ImGui::End();
}
if (show_implot_style_editor) {
ImGui::SetNextWindowSize(ImVec2(415,762), ImGuiCond_Appearing);
ImGui::Begin("Style Editor (ImPlot)", &show_implot_style_editor);
ImPlot::ShowStyleEditor();
ImGui::End();
}
if (show_implot_benchmark) {
ImGui::SetNextWindowSize(ImVec2(530,740), ImGuiCond_Appearing);
ImGui::Begin("ImPlot Benchmark Tool", &show_implot_benchmark);
ImPlot::ShowBenchmarkTool();
ImGui::End();
return;
}
ImGui::SetNextWindowPos(ImVec2(50, 50), ImGuiCond_FirstUseEver);
ImGui::SetNextWindowSize(ImVec2(600, 750), ImGuiCond_FirstUseEver);
ImGui::Begin("ImPlot Demo", p_open, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar()) {
if (ImGui::BeginMenu("Tools")) {
ImGui::MenuItem("Metrics (ImGui)", NULL, &show_imgui_metrics);
ImGui::MenuItem("Metrics (ImPlot)", NULL, &show_implot_metrics);
ImGui::MenuItem("Style Editor (ImGui)", NULL, &show_imgui_style_editor);
ImGui::MenuItem("Style Editor (ImPlot)", NULL, &show_implot_style_editor);
ImGui::MenuItem("Benchmark", NULL, &show_implot_benchmark);
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
ImGui::Text("ImPlot says hello. (%s)", IMPLOT_VERSION);
// display warning about 16-bit indices
static bool showWarning = sizeof(ImDrawIdx)*8 == 16 && (ImGui::GetIO().BackendFlags & ImGuiBackendFlags_RendererHasVtxOffset) == false;
if (showWarning) {
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1,1,0,1));
ImGui::TextWrapped("WARNING: ImDrawIdx is 16-bit and ImGuiBackendFlags_RendererHasVtxOffset is false. Expect visual glitches and artifacts! See README for more information.");
ImGui::PopStyleColor();
}
ImGui::Spacing();
if (ImGui::BeginTabBar("ImPlotDemoTabs")) {
if (ImGui::BeginTabItem("Plots")) {
if (ImGui::CollapsingHeader("Line Plots"))
ShowDemo_LinePlots();
if (ImGui::CollapsingHeader("Filled Line Plots"))
ShowDemo_FilledLinePlots();
if (ImGui::CollapsingHeader("Shaded Plots##"))
ShowDemo_ShadedPlots();
if (ImGui::CollapsingHeader("Scatter Plots"))
ShowDemo_ScatterPlots();
if (ImGui::CollapsingHeader("Realtime Plots"))
ShowDemo_RealtimePlots();
if (ImGui::CollapsingHeader("Stairstep Plots"))
ShowDemo_StairstepPlots();
if (ImGui::CollapsingHeader("Bar Plots"))
ShowDemo_BarPlots();
if (ImGui::CollapsingHeader("Error Bars"))
ShowDemo_ErrorBars();
if (ImGui::CollapsingHeader("Stem Plots##"))
ShowDemo_StemPlots();
if (ImGui::CollapsingHeader("Infinite Lines"))
ShowDemo_InfiniteLines();
if (ImGui::CollapsingHeader("Pie Charts"))
ShowDemo_PieCharts();
if (ImGui::CollapsingHeader("Heatmaps"))
ShowDemo_Heatmaps();
if (ImGui::CollapsingHeader("Histogram"))
ShowDemo_Histogram();
if (ImGui::CollapsingHeader("Histogram 2D"))
ShowDemo_Histogram2D();
if (ImGui::CollapsingHeader("Digital Plots"))
ShowDemo_DigitalPlots();
if (ImGui::CollapsingHeader("Images"))
ShowDemo_Images();
if (ImGui::CollapsingHeader("Markers and Text"))
ShowDemo_MarkersAndText();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Subplots")) {
if (ImGui::CollapsingHeader("Sizing"))
ShowDemo_SubplotsSizing();
if (ImGui::CollapsingHeader("Item Sharing"))
ShowDemo_SubplotItemSharing();
if (ImGui::CollapsingHeader("Axis Linking"))
ShowDemo_SubplotAxisLinking();
if (ImGui::CollapsingHeader("Tables"))
ShowDemo_Tables();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Axes")) {
if (ImGui::CollapsingHeader("Log Axes"))
ShowDemo_LogAxes();
if (ImGui::CollapsingHeader("Time Axes"))
ShowDemo_TimeAxes();
if (ImGui::CollapsingHeader("Multiple Y-Axes"))
ShowDemo_MultipleYAxes();
if (ImGui::CollapsingHeader("Tick Labels"))
ShowDemo_TickLabels();
if (ImGui::CollapsingHeader("Linked Axes"))
ShowDemo_LinkedAxes();
if (ImGui::CollapsingHeader("Equal Axes"))
ShowDemo_EqualAxes();
if (ImGui::CollapsingHeader("Auto-Fitting Data"))
ShowDemo_AutoFittingData();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Tools")) {
if (ImGui::CollapsingHeader("Offset and Stride"))
ShowDemo_OffsetAndStride();
if (ImGui::CollapsingHeader("Querying"))
ShowDemo_Querying();
if (ImGui::CollapsingHeader("Views"))
ShowDemo_Views();
if (ImGui::CollapsingHeader("Drag Lines"))
ShowDemo_DragLines();
if (ImGui::CollapsingHeader("Drag Points"))
ShowDemo_DragPoints();
if (ImGui::CollapsingHeader("Annotations"))
ShowDemo_Annotations();
if (ImGui::CollapsingHeader("Drag and Drop"))
ShowDemo_DragAndDrop();
if (ImGui::CollapsingHeader("Legend Options"))
ShowDemo_LegendOptions();
if (ImGui::CollapsingHeader("Legend Popups"))
ShowDemo_LegendPopups();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Custom")) {
if (ImGui::CollapsingHeader("Custom Styles"))
ShowDemo_CustomStyles();
if (ImGui::CollapsingHeader("Custom Data and Getters"))
ShowDemo_CustomDataAndGetters();
if (ImGui::CollapsingHeader("Custom Rendering"))
ShowDemo_CustomRendering();
if (ImGui::CollapsingHeader("Custom Plotters and Tooltips"))
ShowDemo_CustomPlottersAndTooltips();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Config")) {
ShowDemo_Configuration();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Help")) {
ShowDemo_Help();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
ImGui::End(); ImGui::End();
} }

View File

@ -139,6 +139,14 @@ static inline void ImMinMaxArray(const T* values, int count, T* min_out, T* max_
} }
*min_out = Min; *max_out = Max; *min_out = Min; *max_out = Max;
} }
// Finds the sim of an array
template <typename T>
static inline T ImSum(const T* values, int count) {
T sum = 0;
for (int i = 0; i < count; ++i)
sum += values[i];
return sum;
}
// Finds the mean of an array // Finds the mean of an array
template <typename T> template <typename T>
static inline double ImMean(const T* values, int count) { static inline double ImMean(const T* values, int count) {
@ -698,6 +706,28 @@ struct ImPlotAxis
inline bool IsLog() const { return ImHasFlag(Flags, ImPlotAxisFlags_LogScale); } inline bool IsLog() const { return ImHasFlag(Flags, ImPlotAxisFlags_LogScale); }
}; };
// Align plots group data
struct ImPlotAlignmentData {
ImPlotOrientation Orientation;
float PadA;
float PadB;
float PadAMax;
float PadBMax;
ImPlotAlignmentData() {
Orientation = ImPlotOrientation_Vertical;
PadA = PadB = PadAMax = PadBMax = 0;
}
void Begin() { PadAMax = PadBMax = 0; }
void Update(float& pad_a, float& pad_b) {
if (PadAMax < pad_a) PadAMax = pad_a;
if (pad_a < PadA) pad_a = PadA;
if (PadBMax < pad_b) PadBMax = pad_b;
if (pad_b < PadB) pad_b = PadB;
}
void End() { PadA = PadAMax; PadB = PadBMax; }
void Reset() { PadA = PadB = PadAMax = PadBMax = 0; }
};
// State information for Plot items // State information for Plot items
struct ImPlotItem struct ImPlotItem
{ {
@ -719,14 +749,52 @@ struct ImPlotItem
~ImPlotItem() { ID = 0; } ~ImPlotItem() { ID = 0; }
}; };
// Holds Legend state labels and item references // Holds Legend state
struct ImPlotLegendData struct ImPlotLegendData
{ {
ImVector<int> Indices; ImVector<int> Indices;
ImGuiTextBuffer Labels; ImGuiTextBuffer Labels;
bool Hovered;
bool Outside;
bool CanGoInside;
bool FlipSideNextFrame;
ImPlotLocation Location;
ImPlotOrientation Orientation;
ImRect Rect;
ImPlotLegendData() {
CanGoInside = true;
Hovered = Outside = FlipSideNextFrame = false;
Location = ImPlotLocation_North | ImPlotLocation_West;
Orientation = ImPlotOrientation_Vertical;
}
void Reset() { Indices.shrink(0); Labels.Buf.shrink(0); } void Reset() { Indices.shrink(0); Labels.Buf.shrink(0); }
}; };
// Holds Items and Legend data
struct ImPlotItemGroup
{
ImGuiID ID;
ImPlotLegendData Legend;
ImPool<ImPlotItem> ItemPool;
int ColormapIdx;
ImPlotItemGroup() { ColormapIdx = 0; }
int GetItemCount() const { return ItemPool.GetBufSize(); }
ImGuiID GetItemID(const char* label_id) { return ImGui::GetID(label_id); /* GetIDWithSeed */ }
ImPlotItem* GetItem(ImGuiID id) { return ItemPool.GetByKey(id); }
ImPlotItem* GetItem(const char* label_id) { return GetItem(GetItemID(label_id)); }
ImPlotItem* GetOrAddItem(ImGuiID id) { return ItemPool.GetOrAddByKey(id); }
ImPlotItem* GetItemByIndex(int i) { return ItemPool.GetByIndex(i); }
int GetItemIndex(ImPlotItem* item) { return ItemPool.GetIndex(item); }
int GetLegendCount() const { return Legend.Indices.size(); }
ImPlotItem* GetLegendItem(int i) { return ItemPool.GetByIndex(Legend.Indices[i]); }
const char* GetLegendLabel(int i) { return Legend.Labels.Buf.Data + GetLegendItem(i)->NameOffset; }
void Reset() { ItemPool.Clear(); Legend.Reset(); ColormapIdx = 0; }
};
// Holds Plot state information that must persist after EndPlot // Holds Plot state information that must persist after EndPlot
struct ImPlotPlot struct ImPlotPlot
{ {
@ -735,8 +803,7 @@ struct ImPlotPlot
ImPlotFlags PreviousFlags; ImPlotFlags PreviousFlags;
ImPlotAxis XAxis; ImPlotAxis XAxis;
ImPlotAxis YAxis[IMPLOT_Y_AXES]; ImPlotAxis YAxis[IMPLOT_Y_AXES];
ImPlotLegendData LegendData; ImPlotItemGroup Items;
ImPool<ImPlotItem> Items;
ImVec2 SelectStart; ImVec2 SelectStart;
ImRect SelectRect; ImRect SelectRect;
ImVec2 QueryStart; ImVec2 QueryStart;
@ -748,21 +815,15 @@ struct ImPlotPlot
bool Querying; bool Querying;
bool Queried; bool Queried;
bool DraggingQuery; bool DraggingQuery;
bool LegendHovered;
bool LegendOutside;
bool LegendFlipSideNextFrame;
bool FrameHovered; bool FrameHovered;
bool FrameHeld;
bool PlotHovered; bool PlotHovered;
int ColormapIdx;
int CurrentYAxis; int CurrentYAxis;
ImPlotLocation MousePosLocation; ImPlotLocation MousePosLocation;
ImPlotLocation LegendLocation;
ImPlotOrientation LegendOrientation;
ImRect FrameRect; ImRect FrameRect;
ImRect CanvasRect; ImRect CanvasRect;
ImRect PlotRect; ImRect PlotRect;
ImRect AxesRect; ImRect AxesRect;
ImRect LegendRect;
ImPlotPlot() { ImPlotPlot() {
Flags = PreviousFlags = ImPlotFlags_None; Flags = PreviousFlags = ImPlotFlags_None;
@ -770,22 +831,46 @@ struct ImPlotPlot
for (int i = 0; i < IMPLOT_Y_AXES; ++i) for (int i = 0; i < IMPLOT_Y_AXES; ++i)
YAxis[i].Orientation = ImPlotOrientation_Vertical; YAxis[i].Orientation = ImPlotOrientation_Vertical;
SelectStart = QueryStart = ImVec2(0,0); SelectStart = QueryStart = ImVec2(0,0);
Initialized = Selecting = Selected = ContextLocked = Querying = Queried = DraggingQuery = LegendHovered = LegendOutside = LegendFlipSideNextFrame = false; Initialized = Selecting = Selected = ContextLocked = Querying = Queried = DraggingQuery = false;
ColormapIdx = CurrentYAxis = 0; CurrentYAxis = 0;
LegendLocation = ImPlotLocation_North | ImPlotLocation_West;
LegendOrientation = ImPlotOrientation_Vertical;
MousePosLocation = ImPlotLocation_South | ImPlotLocation_East; MousePosLocation = ImPlotLocation_South | ImPlotLocation_East;
} }
int GetLegendCount() const { return LegendData.Indices.size(); }
ImPlotItem* GetLegendItem(int i);
const char* GetLegendLabel(int i);
inline bool AnyYInputLocked() const { return YAxis[0].IsInputLocked() || (YAxis[1].Present ? YAxis[1].IsInputLocked() : false) || (YAxis[2].Present ? YAxis[2].IsInputLocked() : false); } inline bool AnyYInputLocked() const { return YAxis[0].IsInputLocked() || (YAxis[1].Present ? YAxis[1].IsInputLocked() : false) || (YAxis[2].Present ? YAxis[2].IsInputLocked() : false); }
inline bool AllYInputLocked() const { return YAxis[0].IsInputLocked() && (YAxis[1].Present ? YAxis[1].IsInputLocked() : true ) && (YAxis[2].Present ? YAxis[2].IsInputLocked() : true ); } inline bool AllYInputLocked() const { return YAxis[0].IsInputLocked() && (YAxis[1].Present ? YAxis[1].IsInputLocked() : true ) && (YAxis[2].Present ? YAxis[2].IsInputLocked() : true ); }
inline bool IsInputLocked() const { return XAxis.IsInputLocked() && YAxis[0].IsInputLocked() && YAxis[1].IsInputLocked() && YAxis[2].IsInputLocked(); } inline bool IsInputLocked() const { return XAxis.IsInputLocked() && YAxis[0].IsInputLocked() && YAxis[1].IsInputLocked() && YAxis[2].IsInputLocked(); }
}; };
// Holds subplot data that must persist afer EndSubplot
struct ImPlotSubplot {
ImGuiID ID;
ImPlotSubplotFlags Flags;
ImPlotSubplotFlags PreviousFlags;
ImPlotItemGroup Items;
int Rows;
int Cols;
int CurrentIdx;
ImRect FrameRect;
ImRect GridRect;
ImVec2 CellSize;
ImVector<ImPlotAlignmentData> RowAlignmentData;
ImVector<ImPlotAlignmentData> ColAlignmentData;
ImVector<float> RowRatios;
ImVector<float> ColRatios;
ImVector<ImPlotRange> RowLinkData;
ImVector<ImPlotRange> ColLinkData;
float TempSizes[2];
bool FrameHovered;
ImPlotSubplot() {
Rows = Cols = CurrentIdx = 0;
FrameHovered = false;
Items.Legend.Location = ImPlotLocation_North;
Items.Legend.Orientation = ImPlotOrientation_Horizontal;
Items.Legend.CanGoInside = false;
}
};
// Temporary data storage for upcoming plot // Temporary data storage for upcoming plot
struct ImPlotNextPlotData struct ImPlotNextPlotData
{ {
@ -860,7 +945,10 @@ struct ImPlotNextItemData {
struct ImPlotContext { struct ImPlotContext {
// Plot States // Plot States
ImPool<ImPlotPlot> Plots; ImPool<ImPlotPlot> Plots;
ImPool<ImPlotSubplot> Subplots;
ImPlotPlot* CurrentPlot; ImPlotPlot* CurrentPlot;
ImPlotSubplot* CurrentSubplot;
ImPlotItemGroup* CurrentItems;
ImPlotItem* CurrentItem; ImPlotItem* CurrentItem;
ImPlotItem* PreviousItem; ImPlotItem* PreviousItem;
@ -892,6 +980,7 @@ struct ImPlotContext {
bool RenderX; bool RenderX;
bool RenderY[IMPLOT_Y_AXES]; bool RenderY[IMPLOT_Y_AXES];
// Axis Locking Flags // Axis Locking Flags
bool ChildWindowMade; bool ChildWindowMade;
@ -909,13 +998,17 @@ struct ImPlotContext {
ImVector<double> Temp1, Temp2; ImVector<double> Temp1, Temp2;
// Misc // Misc
int VisibleItemCount;
int DigitalPlotItemCnt; int DigitalPlotItemCnt;
int DigitalPlotOffset; int DigitalPlotOffset;
ImPlotNextPlotData NextPlotData; ImPlotNextPlotData NextPlotData;
ImPlotNextItemData NextItemData; ImPlotNextItemData NextItemData;
ImPlotInputMap InputMap; ImPlotInputMap InputMap;
ImPlotPoint MousePos[IMPLOT_Y_AXES]; ImPlotPoint MousePos[IMPLOT_Y_AXES];
// Align plots
ImPool<ImPlotAlignmentData> AlignmentData;
ImPlotAlignmentData* CurrentAlignmentH;
ImPlotAlignmentData* CurrentAlignmentV;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -932,7 +1025,11 @@ namespace ImPlot {
// Initializes an ImPlotContext // Initializes an ImPlotContext
IMPLOT_API void Initialize(ImPlotContext* ctx); IMPLOT_API void Initialize(ImPlotContext* ctx);
// Resets an ImPlot context for the next call to BeginPlot // Resets an ImPlot context for the next call to BeginPlot
IMPLOT_API void Reset(ImPlotContext* ctx); IMPLOT_API void ResetCtxForNextPlot(ImPlotContext* ctx);
// Restes an ImPlot context for the next call to BeginAlignedPlots
IMPLOT_API void ResetCtxForNextAlignedPlots(ImPlotContext* ctx);
// Resets an ImPlot context for the next call to BeginSubplot
IMPLOT_API void ResetCtxForNextSubplot(ImPlotContext* ctx);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] Input Utils // [SECTION] Input Utils
@ -955,6 +1052,16 @@ IMPLOT_API void BustPlotCache();
// Shows a plot's context menu. // Shows a plot's context menu.
IMPLOT_API void ShowPlotContextMenu(ImPlotPlot& plot); IMPLOT_API void ShowPlotContextMenu(ImPlotPlot& plot);
//-----------------------------------------------------------------------------
// [SECTION] Subplot Utils
//-----------------------------------------------------------------------------
// Advances to next subplot
IMPLOT_API void SubplotNextCell();
// Shows a subplot's context menu.
IMPLOT_API void ShowSubplotsContextMenu(ImPlotSubplot& subplot);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] Item Utils // [SECTION] Item Utils
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -1044,11 +1151,13 @@ static inline const char* GetFormatY(ImPlotYAxis y) { return GImPlot->NextPlotDa
// Gets the position of an inner rect that is located inside of an outer rect according to an ImPlotLocation and padding amount. // Gets the position of an inner rect that is located inside of an outer rect according to an ImPlotLocation and padding amount.
IMPLOT_API ImVec2 GetLocationPos(const ImRect& outer_rect, const ImVec2& inner_size, ImPlotLocation location, const ImVec2& pad = ImVec2(0,0)); IMPLOT_API ImVec2 GetLocationPos(const ImRect& outer_rect, const ImVec2& inner_size, ImPlotLocation location, const ImVec2& pad = ImVec2(0,0));
// Calculates the bounding box size of a legend // Calculates the bounding box size of a legend
IMPLOT_API ImVec2 CalcLegendSize(ImPlotPlot& plot, const ImVec2& pad, const ImVec2& spacing, ImPlotOrientation orientation); IMPLOT_API ImVec2 CalcLegendSize(ImPlotItemGroup& items, const ImVec2& pad, const ImVec2& spacing, ImPlotOrientation orientation);
// Renders legend entries into a bounding box // Renders legend entries into a bounding box
IMPLOT_API void ShowLegendEntries(ImPlotPlot& plot, const ImRect& legend_bb, bool interactable, const ImVec2& pad, const ImVec2& spacing, ImPlotOrientation orientation, ImDrawList& DrawList); IMPLOT_API bool ShowLegendEntries(ImPlotItemGroup& items, const ImRect& legend_bb, bool interactable, const ImVec2& pad, const ImVec2& spacing, ImPlotOrientation orientation, ImDrawList& DrawList);
// Shows an alternate legend for the plot identified by #title_id, outside of the plot frame (can be called before or after of Begin/EndPlot but must occur in the same ImGui window!). // Shows an alternate legend for the plot identified by #title_id, outside of the plot frame (can be called before or after of Begin/EndPlot but must occur in the same ImGui window!).
IMPLOT_API void ShowAltLegend(const char* title_id, ImPlotOrientation orientation = ImPlotOrientation_Vertical, const ImVec2 size = ImVec2(0,0), bool interactable = true); IMPLOT_API void ShowAltLegend(const char* title_id, ImPlotOrientation orientation = ImPlotOrientation_Vertical, const ImVec2 size = ImVec2(0,0), bool interactable = true);
// Shows an legends's context menu.
IMPLOT_API bool ShowLegendContextMenu(ImPlotLegendData& legend, bool visible);
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// [SECTION] Tick Utils // [SECTION] Tick Utils
@ -1089,6 +1198,8 @@ static inline ImU32 GetStyleColorU32(ImPlotCol idx) { return ImGui::ColorConve
// Draws vertical text. The position is the bottom left of the text rect. // Draws vertical text. The position is the bottom left of the text rect.
IMPLOT_API void AddTextVertical(ImDrawList *DrawList, ImVec2 pos, ImU32 col, const char* text_begin, const char* text_end = NULL); IMPLOT_API void AddTextVertical(ImDrawList *DrawList, ImVec2 pos, ImU32 col, const char* text_begin, const char* text_end = NULL);
// Draws multiline horizontal text centered.
IMPLOT_API void AddTextCentered(ImDrawList* DrawList, ImVec2 top_center, ImU32 col, const char* text_begin, const char* text_end = NULL);
// Calculates the size of vertical text // Calculates the size of vertical text
static inline ImVec2 CalcTextSizeVertical(const char *text) { static inline ImVec2 CalcTextSizeVertical(const char *text) {
ImVec2 sz = ImGui::CalcTextSize(text); ImVec2 sz = ImGui::CalcTextSize(text);

View File

@ -61,32 +61,30 @@ namespace ImPlot {
ImPlotItem* RegisterOrGetItem(const char* label_id, bool* just_created) { ImPlotItem* RegisterOrGetItem(const char* label_id, bool* just_created) {
ImPlotContext& gp = *GImPlot; ImPlotContext& gp = *GImPlot;
ImGuiID id = ImGui::GetID(label_id); ImPlotItemGroup& Items = *gp.CurrentItems;
ImGuiID id = Items.GetItemID(label_id);
if (just_created != NULL) if (just_created != NULL)
*just_created = gp.CurrentPlot->Items.GetByKey(id) == NULL; *just_created = Items.GetItem(id) == NULL;
ImPlotItem* item = gp.CurrentPlot->Items.GetOrAddByKey(id); ImPlotItem* item = Items.GetOrAddItem(id);
if (item->SeenThisFrame) if (item->SeenThisFrame)
return item; return item;
item->SeenThisFrame = true; item->SeenThisFrame = true;
int idx = gp.CurrentPlot->Items.GetIndex(item); int idx = Items.GetItemIndex(item);
item->ID = id; item->ID = id;
if (ImGui::FindRenderedTextEnd(label_id, NULL) != label_id) { if (ImGui::FindRenderedTextEnd(label_id, NULL) != label_id) {
gp.CurrentPlot->LegendData.Indices.push_back(idx); Items.Legend.Indices.push_back(idx);
item->NameOffset = gp.CurrentPlot->LegendData.Labels.size(); item->NameOffset = Items.Legend.Labels.size();
gp.CurrentPlot->LegendData.Labels.append(label_id, label_id + strlen(label_id) + 1); Items.Legend.Labels.append(label_id, label_id + strlen(label_id) + 1);
} }
else { else {
item->Show = true; item->Show = true;
} }
if (item->Show)
gp.VisibleItemCount++;
return item; return item;
} }
ImPlotItem* GetItem(const char* label_id) { ImPlotItem* GetItem(const char* label_id) {
ImPlotContext& gp = *GImPlot; ImPlotContext& gp = *GImPlot;
ImGuiID id = ImGui::GetID(label_id); return gp.CurrentItems->GetItem(label_id);
return gp.CurrentPlot->Items.GetByKey(id);
} }
ImPlotItem* GetCurrentItem() { ImPlotItem* GetCurrentItem() {
@ -140,9 +138,11 @@ void BustItemCache() {
ImPlotContext& gp = *GImPlot; ImPlotContext& gp = *GImPlot;
for (int p = 0; p < gp.Plots.GetBufSize(); ++p) { for (int p = 0; p < gp.Plots.GetBufSize(); ++p) {
ImPlotPlot& plot = *gp.Plots.GetByIndex(p); ImPlotPlot& plot = *gp.Plots.GetByIndex(p);
plot.ColormapIdx = 0; plot.Items.Reset();
plot.Items.Clear(); }
plot.LegendData.Reset(); for (int p = 0; p < gp.Subplots.GetBufSize(); ++p) {
ImPlotSubplot& subplot = *gp.Subplots.GetByIndex(p);
subplot.Items.Reset();
} }
} }
@ -152,12 +152,15 @@ void BustColorCache(const char* plot_title_id) {
BustItemCache(); BustItemCache();
} }
else { else {
ImPlotPlot* plot = gp.Plots.GetByKey(ImGui::GetCurrentWindow()->GetID(plot_title_id)); ImGuiID id = ImGui::GetCurrentWindow()->GetID(plot_title_id);
if (plot == NULL) ImPlotPlot* plot = gp.Plots.GetByKey(id);
return; if (plot != NULL)
plot->ColormapIdx = 0; plot->Items.Reset();
plot->Items.Clear(); else {
plot->LegendData.Reset(); ImPlotSubplot* subplot = gp.Subplots.GetByKey(id);
if (subplot != NULL)
subplot->Items.Reset();
}
} }
} }