mirror of
https://github.com/gwm17/implot.git
synced 2025-01-30 19:08:51 -05:00
add benchmark test, update double click fit, fix demo math include
This commit is contained in:
parent
3c1ef11525
commit
23931c7f07
21
implot.cpp
21
implot.cpp
|
@ -259,6 +259,7 @@ struct ImNextPlotData {
|
||||||
struct ImPlotContext {
|
struct ImPlotContext {
|
||||||
ImPlotContext() {
|
ImPlotContext() {
|
||||||
CurrentPlot = NULL;
|
CurrentPlot = NULL;
|
||||||
|
FitThisFrame = FitX = FitY = false;
|
||||||
RestorePlotPalette();
|
RestorePlotPalette();
|
||||||
}
|
}
|
||||||
/// ALl Plots
|
/// ALl Plots
|
||||||
|
@ -387,7 +388,7 @@ struct ImPlotContext {
|
||||||
|
|
||||||
// Data extents
|
// Data extents
|
||||||
ImRect Extents;
|
ImRect Extents;
|
||||||
bool FitThisFrame;
|
bool FitThisFrame; bool FitX; bool FitY;
|
||||||
int VisibleItemCount;
|
int VisibleItemCount;
|
||||||
// Render flags
|
// Render flags
|
||||||
bool RenderX, RenderY;
|
bool RenderX, RenderY;
|
||||||
|
@ -863,10 +864,16 @@ bool BeginPlot(const char* title, const char* x_label, const char* y_label, cons
|
||||||
|
|
||||||
// DOUBLE CLICK -----------------------------------------------------------
|
// DOUBLE CLICK -----------------------------------------------------------
|
||||||
|
|
||||||
if ( IO.MouseDoubleClicked[0] && gp.Hov_Frame && gp.Hov_Grid && !hov_legend && !hov_query)
|
if ( IO.MouseDoubleClicked[0] && gp.Hov_Frame && (hov_x_axis_region || hov_y_axis_region) && !hov_legend && !hov_query) {
|
||||||
gp.FitThisFrame = true;
|
gp.FitThisFrame = true;
|
||||||
else
|
gp.FitX = hov_x_axis_region;
|
||||||
|
gp.FitY = hov_y_axis_region;
|
||||||
|
}
|
||||||
|
else {
|
||||||
gp.FitThisFrame = false;
|
gp.FitThisFrame = false;
|
||||||
|
gp.FitX = false;
|
||||||
|
gp.FitY = false;
|
||||||
|
}
|
||||||
|
|
||||||
// FOCUS ------------------------------------------------------------------
|
// FOCUS ------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1238,13 +1245,13 @@ void EndPlot() {
|
||||||
// FIT DATA --------------------------------------------------------------
|
// FIT DATA --------------------------------------------------------------
|
||||||
|
|
||||||
if (gp.FitThisFrame && (gp.VisibleItemCount > 0 || plot.Queried)) {
|
if (gp.FitThisFrame && (gp.VisibleItemCount > 0 || plot.Queried)) {
|
||||||
if (!HasFlag(plot.XAxis.Flags, ImAxisFlags_LockMin) && !NanOrInf(gp.Extents.Min.x))
|
if (gp.FitX && !HasFlag(plot.XAxis.Flags, ImAxisFlags_LockMin) && !NanOrInf(gp.Extents.Min.x))
|
||||||
plot.XAxis.Min = gp.Extents.Min.x;
|
plot.XAxis.Min = gp.Extents.Min.x;
|
||||||
if (!HasFlag(plot.XAxis.Flags, ImAxisFlags_LockMax) && !NanOrInf(gp.Extents.Max.x))
|
if (gp.FitX && !HasFlag(plot.XAxis.Flags, ImAxisFlags_LockMax) && !NanOrInf(gp.Extents.Max.x))
|
||||||
plot.XAxis.Max = gp.Extents.Max.x;
|
plot.XAxis.Max = gp.Extents.Max.x;
|
||||||
if (!HasFlag(plot.YAxis.Flags, ImAxisFlags_LockMin) && !NanOrInf(gp.Extents.Min.y))
|
if (gp.FitY && !HasFlag(plot.YAxis.Flags, ImAxisFlags_LockMin) && !NanOrInf(gp.Extents.Min.y))
|
||||||
plot.YAxis.Min = gp.Extents.Min.y;
|
plot.YAxis.Min = gp.Extents.Min.y;
|
||||||
if (!HasFlag(plot.YAxis.Flags, ImAxisFlags_LockMax) && !NanOrInf(gp.Extents.Max.y))
|
if (gp.FitY && !HasFlag(plot.YAxis.Flags, ImAxisFlags_LockMax) && !NanOrInf(gp.Extents.Max.y))
|
||||||
plot.YAxis.Max = gp.Extents.Max.y;
|
plot.YAxis.Max = gp.Extents.Max.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,15 @@
|
||||||
// ImPlot v0.1 WIP
|
// ImPlot v0.1 WIP
|
||||||
|
|
||||||
#include <implot.h>
|
#include <implot.h>
|
||||||
#include <iostream>
|
#include <math.h>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
float RandomRange( float min, float max ) {
|
||||||
|
float scale = rand() / (float) RAND_MAX;
|
||||||
|
return min + scale * ( max - min );
|
||||||
|
}
|
||||||
|
|
||||||
struct ScrollingData {
|
struct ScrollingData {
|
||||||
int MaxSize = 1000;
|
int MaxSize = 1000;
|
||||||
int Offset = 0;
|
int Offset = 0;
|
||||||
|
@ -54,11 +59,21 @@ struct RollingData {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Put big data here
|
struct BenchmarkItem {
|
||||||
struct DemoData {
|
BenchmarkItem() {
|
||||||
DemoData() {
|
float y = RandomRange(0,1);
|
||||||
|
Xs = new float[1000];
|
||||||
|
Ys = new float[1000];
|
||||||
|
for (int i = 0; i < 1000; ++i) {
|
||||||
|
Xs[i] = i*0.001f;
|
||||||
|
Ys[i] = y + RandomRange(-0.01f,0.01f);
|
||||||
}
|
}
|
||||||
|
Col = ImVec4(RandomRange(0,1),RandomRange(0,1),RandomRange(0,1),1);
|
||||||
|
}
|
||||||
|
~BenchmarkItem() { delete Xs; delete Ys; }
|
||||||
|
float* Xs;
|
||||||
|
float* Ys;
|
||||||
|
ImVec4 Col;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,8 +82,6 @@ namespace ImGui {
|
||||||
|
|
||||||
void ShowImPlotDemoWindow(bool* p_open) {
|
void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
|
|
||||||
static DemoData data;
|
|
||||||
|
|
||||||
ImVec2 main_viewport_pos = ImGui::GetMainViewport()->Pos;
|
ImVec2 main_viewport_pos = ImGui::GetMainViewport()->Pos;
|
||||||
ImGui::SetNextWindowPos(ImVec2(main_viewport_pos.x + 650, main_viewport_pos.y + 20), ImGuiCond_FirstUseEver);
|
ImGui::SetNextWindowPos(ImVec2(main_viewport_pos.x + 650, main_viewport_pos.y + 20), ImGuiCond_FirstUseEver);
|
||||||
ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver);
|
ImGui::SetNextWindowSize(ImVec2(550, 680), ImGuiCond_FirstUseEver);
|
||||||
|
@ -77,9 +90,13 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
if (ImGui::CollapsingHeader("Help")) {
|
if (ImGui::CollapsingHeader("Help")) {
|
||||||
ImGui::Text("USER GUIDE:");
|
ImGui::Text("USER GUIDE:");
|
||||||
ImGui::BulletText("Left click and drag within the plot area to pan X and Y axes.");
|
ImGui::BulletText("Left click and drag within the plot area to pan X and Y axes.");
|
||||||
|
ImGui::Indent();
|
||||||
ImGui::BulletText("Left click and drag on an axis to pan an individual axis.");
|
ImGui::BulletText("Left click and drag on an axis to pan an individual axis.");
|
||||||
|
ImGui::Unindent();
|
||||||
ImGui::BulletText("Scroll in the plot area to zoom both X any Y axes.");
|
ImGui::BulletText("Scroll in the plot area to zoom both X any Y axes.");
|
||||||
|
ImGui::Indent();
|
||||||
ImGui::BulletText("Scroll on an axis to zoom an individual axis.");
|
ImGui::BulletText("Scroll on an axis to zoom an individual axis.");
|
||||||
|
ImGui::Unindent();
|
||||||
ImGui::BulletText("Right click and drag to box select data.");
|
ImGui::BulletText("Right click and drag to box select data.");
|
||||||
ImGui::Indent();
|
ImGui::Indent();
|
||||||
ImGui::BulletText("Hold Alt to expand box selection horizontally.");
|
ImGui::BulletText("Hold Alt to expand box selection horizontally.");
|
||||||
|
@ -92,6 +109,9 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
ImGui::BulletText("Hold Shift to expand query vertically.");
|
ImGui::BulletText("Hold Shift to expand query vertically.");
|
||||||
ImGui::Unindent();
|
ImGui::Unindent();
|
||||||
ImGui::BulletText("Double left click to fit all visible data.");
|
ImGui::BulletText("Double left click to fit all visible data.");
|
||||||
|
ImGui::Indent();
|
||||||
|
ImGui::BulletText("Double left click on an axis to fit the individual axis.");
|
||||||
|
ImGui::Unindent();
|
||||||
ImGui::BulletText("Double right click to open the plot context menu.");
|
ImGui::BulletText("Double right click to open the plot context menu.");
|
||||||
ImGui::BulletText("Click legend label icons to show/hide plot items.");
|
ImGui::BulletText("Click legend label icons to show/hide plot items.");
|
||||||
}
|
}
|
||||||
|
@ -194,6 +214,7 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
if (ImGui::CollapsingHeader("Realtime Plots")) {
|
if (ImGui::CollapsingHeader("Realtime Plots")) {
|
||||||
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.");
|
||||||
static bool paused = false;
|
static bool paused = false;
|
||||||
static ScrollingData sdata1, sdata2;
|
static ScrollingData sdata1, sdata2;
|
||||||
static RollingData rdata1, rdata2;
|
static RollingData rdata1, rdata2;
|
||||||
|
@ -505,9 +526,22 @@ void ShowImPlotDemoWindow(bool* p_open) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// if (ImGui::CollapsingHeader("Benchmark")) {
|
if (ImGui::CollapsingHeader("Benchmark")) {
|
||||||
|
static const int n_items = 100;
|
||||||
// }
|
static BenchmarkItem items[n_items];
|
||||||
|
ImGui::BulletText("Make sure VSync is disabled.");
|
||||||
|
ImGui::BulletText("%d lines with %d points each @ %.3f FPS.",n_items,1000,ImGui::GetIO().Framerate);
|
||||||
|
if (ImGui::BeginPlot("##Bench",NULL,NULL,{-1,300})) {
|
||||||
|
char buff[16];
|
||||||
|
for (int i = 0; i < 100; ++i) {
|
||||||
|
sprintf(buff, "item_%d",i);
|
||||||
|
ImGui::PushPlotColor(ImPlotCol_Line, items[i].Col);
|
||||||
|
ImGui::Plot(buff, items[i].Xs, items[i].Ys, 1000);
|
||||||
|
ImGui::PopPlotColor();
|
||||||
|
}
|
||||||
|
ImGui::EndPlot();
|
||||||
|
}
|
||||||
|
}
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user