mirror of
https://github.com/gwm17/implot.git
synced 2024-11-23 02:38:53 -05:00
add more benchmarks
This commit is contained in:
parent
5c3d64cd9e
commit
3206209777
10
implot.cpp
10
implot.cpp
|
@ -579,7 +579,7 @@ void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImPlotTickCollect
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddTicksCustom(const double* values, const char** labels, int n, ImPlotTickCollection& ticks) {
|
void AddTicksCustom(const double* values, const char* const labels[], int n, ImPlotTickCollection& ticks) {
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
ImPlotTick tick(values[i], false, true);
|
ImPlotTick tick(values[i], false, true);
|
||||||
if (labels != NULL) {
|
if (labels != NULL) {
|
||||||
|
@ -2201,21 +2201,21 @@ void FitNextPlotAxes(bool x, bool y, bool y2, bool y3) {
|
||||||
gp.NextPlotData.FitY[2] = y3;
|
gp.NextPlotData.FitY[2] = y3;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNextPlotTicksX(const double* values, int n_ticks, const char** labels, bool show_default) {
|
void SetNextPlotTicksX(const double* values, int n_ticks, const char* const labels[], bool show_default) {
|
||||||
ImPlotContext& gp = *GImPlot;
|
ImPlotContext& gp = *GImPlot;
|
||||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksX() needs to be called before BeginPlot()!");
|
IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksX() needs to be called before BeginPlot()!");
|
||||||
gp.NextPlotData.ShowDefaultTicksX = show_default;
|
gp.NextPlotData.ShowDefaultTicksX = show_default;
|
||||||
AddTicksCustom(values, labels, n_ticks, gp.XTicks);
|
AddTicksCustom(values, labels, n_ticks, gp.XTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char** labels, bool show_default) {
|
void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char* const labels[], bool show_default) {
|
||||||
IM_ASSERT_USER_ERROR(n_ticks > 1, "The number of ticks must be greater than 1");
|
IM_ASSERT_USER_ERROR(n_ticks > 1, "The number of ticks must be greater than 1");
|
||||||
static ImVector<double> buffer;
|
static ImVector<double> buffer;
|
||||||
FillRange(buffer, n_ticks, x_min, x_max);
|
FillRange(buffer, n_ticks, x_min, x_max);
|
||||||
SetNextPlotTicksX(&buffer[0], n_ticks, labels, show_default);
|
SetNextPlotTicksX(&buffer[0], n_ticks, labels, show_default);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNextPlotTicksY(const double* values, int n_ticks, const char** labels, bool show_default, int y_axis) {
|
void SetNextPlotTicksY(const double* values, int n_ticks, const char* const labels[], bool show_default, int y_axis) {
|
||||||
ImPlotContext& gp = *GImPlot;
|
ImPlotContext& gp = *GImPlot;
|
||||||
IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksY() needs to be called before BeginPlot()!");
|
IM_ASSERT_USER_ERROR(gp.CurrentPlot == NULL, "SetNextPlotTicksY() needs to be called before BeginPlot()!");
|
||||||
IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < IMPLOT_Y_AXES, "y_axis needs to be between 0 and IMPLOT_Y_AXES");
|
IM_ASSERT_USER_ERROR(y_axis >= 0 && y_axis < IMPLOT_Y_AXES, "y_axis needs to be between 0 and IMPLOT_Y_AXES");
|
||||||
|
@ -2223,7 +2223,7 @@ void SetNextPlotTicksY(const double* values, int n_ticks, const char** labels, b
|
||||||
AddTicksCustom(values, labels, n_ticks, gp.YTicks[y_axis]);
|
AddTicksCustom(values, labels, n_ticks, gp.YTicks[y_axis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char** labels, bool show_default, int y_axis) {
|
void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char* const labels[], bool show_default, int y_axis) {
|
||||||
IM_ASSERT_USER_ERROR(n_ticks > 1, "The number of ticks must be greater than 1");
|
IM_ASSERT_USER_ERROR(n_ticks > 1, "The number of ticks must be greater than 1");
|
||||||
static ImVector<double> buffer;
|
static ImVector<double> buffer;
|
||||||
FillRange(buffer, n_ticks, y_min, y_max);
|
FillRange(buffer, n_ticks, y_min, y_max);
|
||||||
|
|
12
implot.h
12
implot.h
|
@ -361,8 +361,8 @@ void PlotStems(const char* label_id, const float* xs, const float* ys, int count
|
||||||
void PlotStems(const char* label_id, const double* xs, const double* ys, int count, double y_ref = 0, int offset = 0, int stride = sizeof(double));
|
void PlotStems(const char* label_id, const double* xs, const double* ys, int count, double y_ref = 0, int offset = 0, int stride = sizeof(double));
|
||||||
|
|
||||||
// Plots a pie chart. If the sum of values > 1 or normalize is true, each value will be normalized. Center and radius are in plot units. #label_fmt can be set to NULL for no labels.
|
// Plots a pie chart. If the sum of values > 1 or normalize is true, each value will be normalized. Center and radius are in plot units. #label_fmt can be set to NULL for no labels.
|
||||||
void PlotPieChart(const char** label_ids, const float* values, int count, float x, float y, float radius, bool normalize = false, const char* label_fmt = "%.1f", float angle0 = 90);
|
void PlotPieChart(const char* const label_ids[], const float* values, int count, float x, float y, float radius, bool normalize = false, const char* label_fmt = "%.1f", float angle0 = 90);
|
||||||
void PlotPieChart(const char** label_ids, const double* values, int count, double x, double y, double radius, bool normalize = false, const char* label_fmt = "%.1f", double angle0 = 90);
|
void PlotPieChart(const char* const label_ids[], const double* values, int count, double x, double y, double radius, bool normalize = false, const char* label_fmt = "%.1f", double angle0 = 90);
|
||||||
|
|
||||||
// Plots a 2D heatmap chart. Values are expected to be in row-major order. #label_fmt can be set to NULL for no labels.
|
// Plots a 2D heatmap chart. Values are expected to be in row-major order. #label_fmt can be set to NULL for no labels.
|
||||||
void PlotHeatmap(const char* label_id, const float* values, int rows, int cols, float scale_min, float scale_max, const char* label_fmt = "%.1f", const ImPlotPoint& bounds_min = ImPlotPoint(0,0), const ImPlotPoint& bounds_max = ImPlotPoint(1,1));
|
void PlotHeatmap(const char* label_id, const float* values, int rows, int cols, float scale_min, float scale_max, const char* label_fmt = "%.1f", const ImPlotPoint& bounds_min = ImPlotPoint(0,0), const ImPlotPoint& bounds_max = ImPlotPoint(1,1));
|
||||||
|
@ -393,12 +393,12 @@ void LinkNextPlotLimits(double* xmin, double* xmax, double* ymin, double* ymax,
|
||||||
void FitNextPlotAxes(bool x = true, bool y = true, bool y2 = true, bool y3 = true);
|
void FitNextPlotAxes(bool x = true, bool y = true, bool y2 = true, bool y3 = true);
|
||||||
|
|
||||||
// Set the X axis ticks and optionally the labels for the next plot.
|
// Set the X axis ticks and optionally the labels for the next plot.
|
||||||
void SetNextPlotTicksX(const double* values, int n_ticks, const char** labels = NULL, bool show_default = false);
|
void SetNextPlotTicksX(const double* values, int n_ticks, const char* const labels[] = NULL, bool show_default = false);
|
||||||
void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char** labels = NULL, bool show_default = false);
|
void SetNextPlotTicksX(double x_min, double x_max, int n_ticks, const char* const labels[] = NULL, bool show_default = false);
|
||||||
|
|
||||||
// Set the Y axis ticks and optionally the labels for the next plot.
|
// Set the Y axis ticks and optionally the labels for the next plot.
|
||||||
void SetNextPlotTicksY(const double* values, int n_ticks, const char** labels = NULL, bool show_default = false, int y_axis = 0);
|
void SetNextPlotTicksY(const double* values, int n_ticks, const char* const labels[] = NULL, bool show_default = false, int y_axis = 0);
|
||||||
void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char** labels = NULL, bool show_default = false, int y_axis = 0);
|
void SetNextPlotTicksY(double y_min, double y_max, int n_ticks, const char* const labels[] = NULL, bool show_default = false, int y_axis = 0);
|
||||||
|
|
||||||
// Select which Y axis will be used for subsequent plot elements. The default is '0', or the first (left) Y axis. Enable 2nd and 3rd axes with ImPlotFlags_YAxisX.
|
// Select which Y axis will be used for subsequent plot elements. The default is '0', or the first (left) Y axis. Enable 2nd and 3rd axes with ImPlotFlags_YAxisX.
|
||||||
void SetPlotYAxis(int y_axis);
|
void SetPlotYAxis(int y_axis);
|
||||||
|
|
|
@ -1403,8 +1403,12 @@ void PlotCandlestick(const char* label_id, const double* xs, const double* opens
|
||||||
|
|
||||||
namespace ImPlot {
|
namespace ImPlot {
|
||||||
|
|
||||||
struct BenchmarkItem {
|
//-----------------------------------------------------------------------------
|
||||||
BenchmarkItem() {
|
// BENCHMARK
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
struct BenchData {
|
||||||
|
BenchData() {
|
||||||
float y = (float)RandomRange(0,1);
|
float y = (float)RandomRange(0,1);
|
||||||
Data = new float[1000];
|
Data = new float[1000];
|
||||||
for (int i = 0; i < 1000; ++i) {
|
for (int i = 0; i < 1000; ++i) {
|
||||||
|
@ -1412,34 +1416,49 @@ struct BenchmarkItem {
|
||||||
}
|
}
|
||||||
Col = ImVec4((float)RandomRange(0,1),(float)RandomRange(0,1),(float)RandomRange(0,1),1);
|
Col = ImVec4((float)RandomRange(0,1),(float)RandomRange(0,1),(float)RandomRange(0,1),1);
|
||||||
}
|
}
|
||||||
~BenchmarkItem() { delete[] Data; }
|
~BenchData() { delete[] Data; }
|
||||||
float* Data;
|
float* Data;
|
||||||
ImVec4 Col;
|
ImVec4 Col;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum BenchMode {
|
||||||
|
Line = 0,
|
||||||
|
Shaded = 1,
|
||||||
|
Scatter = 2,
|
||||||
|
Bars = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BenchRecord {
|
||||||
|
int Mode;
|
||||||
|
bool AA;
|
||||||
|
ImVector<ImPlotPoint> Data;
|
||||||
|
};
|
||||||
|
|
||||||
void ShowBenchmarkTool() {
|
void ShowBenchmarkTool() {
|
||||||
static const int max_lines = 500;
|
static const int max_items = 500;
|
||||||
static BenchmarkItem items[max_lines];
|
static BenchData items[max_items];
|
||||||
static bool running = false;
|
static bool running = false;
|
||||||
static int frames = 60;
|
static int frames = 60;
|
||||||
static int L = 0;
|
static int L = 0;
|
||||||
static int F = 0;
|
static int F = 0;
|
||||||
static double t1, t2;
|
static double t1, t2;
|
||||||
|
static int mode = BenchMode::Line;
|
||||||
|
const char* names[] = {"Line","Shaded","Scatter","Bars"};
|
||||||
|
|
||||||
static ImVector<ImVector<ImPlotPoint>> records;
|
static ImVector<BenchRecord> records;
|
||||||
|
|
||||||
if (running) {
|
if (running) {
|
||||||
F++;
|
F++;
|
||||||
if (F == frames) {
|
if (F == frames) {
|
||||||
t2 = ImGui::GetTime();
|
t2 = ImGui::GetTime();
|
||||||
records.back().push_back(ImPlotPoint(L, frames / (t2 - t1)));
|
records.back().Data.push_back(ImPlotPoint(L, frames / (t2 - t1)));
|
||||||
L += 5;
|
L += 5;
|
||||||
F = 0;
|
F = 0;
|
||||||
t1 = ImGui::GetTime();
|
t1 = ImGui::GetTime();
|
||||||
}
|
}
|
||||||
if (L > max_lines) {
|
if (L > max_items) {
|
||||||
running = false;
|
running = false;
|
||||||
L = max_lines;
|
L = max_items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1457,35 +1476,67 @@ void ShowBenchmarkTool() {
|
||||||
if (ImGui::Button("Benchmark")) {
|
if (ImGui::Button("Benchmark")) {
|
||||||
running = true;
|
running = true;
|
||||||
L = F = 0;
|
L = F = 0;
|
||||||
records.push_back(ImVector<ImPlotPoint>());
|
records.push_back(BenchRecord());
|
||||||
records.back().reserve(max_lines + 1);
|
records.back().Data.reserve(max_items+1);
|
||||||
|
records.back().Mode = mode;
|
||||||
|
records.back().AA = ImPlot::GetStyle().AntiAliasedLines;
|
||||||
t1 = ImGui::GetTime();
|
t1 = ImGui::GetTime();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
ImGui::SetNextItemWidth(200);
|
||||||
|
ImGui::Combo("##Mode",&mode,names,4);
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines);
|
ImGui::Checkbox("Anti-Aliased Lines", &ImPlot::GetStyle().AntiAliasedLines);
|
||||||
if (was_running) { ImGui::PopItemFlag(); ImGui::PopStyleVar(); }
|
if (was_running) { ImGui::PopItemFlag(); ImGui::PopStyleVar(); }
|
||||||
|
|
||||||
ImGui::ProgressBar((float)L / (float)(max_lines - 1));
|
ImGui::ProgressBar((float)L / (float)(max_items - 1));
|
||||||
|
|
||||||
ImPlot::SetNextPlotLimits(0,1000,0,1,ImGuiCond_Always);
|
ImPlot::SetNextPlotLimits(0,1000,0,1,ImGuiCond_Always);
|
||||||
if (ImPlot::BeginPlot("##Bench",NULL,NULL,ImVec2(-1,0),ImPlotFlags_NoChild,0,0,0,0)) {
|
if (ImPlot::BeginPlot("##Bench",NULL,NULL,ImVec2(-1,0),ImPlotFlags_NoChild | ImPlotFlags_CanvasOnly,ImPlotAxisFlags_NoDecorations,ImPlotAxisFlags_NoDecorations)) {
|
||||||
if (running) {
|
if (running) {
|
||||||
for (int i = 0; i < L; ++i) {
|
if (mode == BenchMode::Line) {
|
||||||
ImGui::PushID(i);
|
for (int i = 0; i < L; ++i) {
|
||||||
ImPlot::SetNextLineStyle(items[i].Col);
|
ImGui::PushID(i);
|
||||||
ImPlot::PlotLine("##item", items[i].Data, 1000);
|
ImPlot::SetNextLineStyle(items[i].Col);
|
||||||
ImGui::PopID();
|
ImPlot::PlotLine("##item", items[i].Data, 1000);
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mode == BenchMode::Shaded) {
|
||||||
|
for (int i = 0; i < L; ++i) {
|
||||||
|
ImGui::PushID(i);
|
||||||
|
ImPlot::SetNextFillStyle(items[i].Col,0.5f);
|
||||||
|
ImPlot::PlotShaded("##item", items[i].Data, 1000);
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mode == BenchMode::Scatter) {
|
||||||
|
for (int i = 0; i < L; ++i) {
|
||||||
|
ImGui::PushID(i);
|
||||||
|
ImPlot::SetNextLineStyle(items[i].Col);
|
||||||
|
ImPlot::PlotScatter("##item", items[i].Data, 1000);
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (mode == BenchMode::Bars) {
|
||||||
|
for (int i = 0; i < L; ++i) {
|
||||||
|
ImGui::PushID(i);
|
||||||
|
ImPlot::SetNextFillStyle(items[i].Col,0.5f);
|
||||||
|
ImPlot::PlotBars("##item", items[i].Data, 1000);
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImPlot::SetNextPlotLimits(0,500,0,500,ImGuiCond_Always);
|
ImPlot::SetNextPlotLimits(0,500,0,500,ImGuiCond_Always);
|
||||||
static char buffer[8];
|
static char buffer[64];
|
||||||
if (ImPlot::BeginPlot("##Stats", "Lines (1,000 pts each)", "Framerate (Hz)", ImVec2(-1,0), ImPlotFlags_NoChild)) {
|
if (ImPlot::BeginPlot("##Stats", "Items (1,000 pts each)", "Framerate (Hz)", ImVec2(-1,0), ImPlotFlags_NoChild)) {
|
||||||
for (int run = 0; run < records.size(); ++run) {
|
for (int run = 0; run < records.size(); ++run) {
|
||||||
sprintf(buffer, "Run %d", run + 1);
|
sprintf(buffer, "B%d-%s%s", run + 1, names[records[run].Mode], records[run].AA ? "-AA" : "");
|
||||||
ImPlot::PlotLine(buffer, records[run].Data, records[run].Size);
|
ImPlot::PlotLine(buffer, records[run].Data.Data, records[run].Data.Size);
|
||||||
}
|
}
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
}
|
}
|
||||||
|
|
|
@ -715,7 +715,7 @@ void AddTicksLogarithmic(const ImPlotRange& range, int nMajor, ImPlotTickCollect
|
||||||
// Populates a list of ImPlotTicks with time formatted ticks.
|
// Populates a list of ImPlotTicks with time formatted ticks.
|
||||||
void AddTicksTime(const ImPlotRange& range, int nMajor, ImPlotTickCollection& ticks);
|
void AddTicksTime(const ImPlotRange& range, int nMajor, ImPlotTickCollection& ticks);
|
||||||
// Populates a list of ImPlotTicks with custom spaced and labeled ticks
|
// Populates a list of ImPlotTicks with custom spaced and labeled ticks
|
||||||
void AddTicksCustom(const double* values, const char** labels, int n, ImPlotTickCollection& ticks);
|
void AddTicksCustom(const double* values, const char* const labels[], int n, ImPlotTickCollection& ticks);
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// [SECTION] Styling Utils
|
// [SECTION] Styling Utils
|
||||||
|
|
|
@ -1359,7 +1359,7 @@ inline void RenderPieSlice(ImDrawList& DrawList, const ImPlotPoint& center, doub
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void PlotPieChartEx(const char** label_ids, const T* values, int count, T x, T y, T radius, bool normalize, const char* fmt, T angle0) {
|
void PlotPieChartEx(const char* const label_ids[], const T* values, int count, T x, T y, T radius, bool normalize, const char* fmt, T angle0) {
|
||||||
IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "PlotPieChart() needs to be called between BeginPlot() and EndPlot()!");
|
IM_ASSERT_USER_ERROR(GImPlot->CurrentPlot != NULL, "PlotPieChart() needs to be called between BeginPlot() and EndPlot()!");
|
||||||
ImDrawList & DrawList = *GetPlotDrawList();
|
ImDrawList & DrawList = *GetPlotDrawList();
|
||||||
T sum = 0;
|
T sum = 0;
|
||||||
|
@ -1409,12 +1409,12 @@ void PlotPieChartEx(const char** label_ids, const T* values, int count, T x, T y
|
||||||
}
|
}
|
||||||
|
|
||||||
// float
|
// float
|
||||||
void PlotPieChart(const char** label_ids, const float* values, int count, float x, float y, float radius, bool normalize, const char* fmt, float angle0) {
|
void PlotPieChart(const char* const label_ids[], const float* values, int count, float x, float y, float radius, bool normalize, const char* fmt, float angle0) {
|
||||||
return PlotPieChartEx(label_ids, values, count, x, y, radius, normalize, fmt, angle0);
|
return PlotPieChartEx(label_ids, values, count, x, y, radius, normalize, fmt, angle0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// double
|
// double
|
||||||
void PlotPieChart(const char** label_ids, const double* values, int count, double x, double y, double radius, bool normalize, const char* fmt, double angle0) {
|
void PlotPieChart(const char* const label_ids[], const double* values, int count, double x, double y, double radius, bool normalize, const char* fmt, double angle0) {
|
||||||
return PlotPieChartEx(label_ids, values, count, x, y, radius, normalize, fmt, angle0);
|
return PlotPieChartEx(label_ids, values, count, x, y, radius, normalize, fmt, angle0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user