1
0
Fork 0
mirror of https://github.com/gwm17/implot.git synced 2024-11-26 20:28:50 -05:00

internal refactors and misc improvements

This commit is contained in:
Evan Pezent 2020-06-04 09:56:50 -05:00
parent a70bbe5cff
commit 2a5a78565b
3 changed files with 278 additions and 260 deletions

File diff suppressed because it is too large Load Diff

View File

@ -238,9 +238,9 @@ void PlotErrorBars(const char* label_id, const double* xs, const double* ys, con
void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float)); void PlotErrorBars(const char* label_id, const float* xs, const float* ys, const float* neg, const float* pos, int count, int offset = 0, int stride = sizeof(float));
void PlotErrorBars(const char* label_id, const double* xs, const double* ys, const double* neg, const double* pos, int count, int offset = 0, int stride = sizeof(double)); void PlotErrorBars(const char* label_id, const double* xs, const double* ys, const double* neg, const double* pos, int count, int offset = 0, int stride = sizeof(double));
// Plots a pie chart. If the sum of values > 1, each value will be normalized. Center and radius are in plot coordinates. // 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 coordinates.
void PlotPieChart(const char** label_ids, float* values, int count, float x, float y, float radius, const char* label_fmt = "%.1f%%", float angle0 = 90); 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** label_ids, double* values, int count, double x, double y, double radius, const char* label_fmt = "%.1f%%", double 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);
// 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));
@ -297,7 +297,7 @@ void SetColormap(ImPlotColormap colormap, int samples = 0);
void SetColormap(const ImVec4* colors, int num_colors); void SetColormap(const ImVec4* colors, int num_colors);
// Returns the size of the current colormap // Returns the size of the current colormap
int GetColormapSize(); int GetColormapSize();
/// Returns a color from the Color map given an index > 0 (modulo will be performed) // Returns a color from the Color map given an index > 0 (modulo will be performed)
ImVec4 GetColormapColor(int index); ImVec4 GetColormapColor(int index);
// Linearly interpolates a color from the current colormap given t between 0 and 1. // Linearly interpolates a color from the current colormap given t between 0 and 1.
ImVec4 LerpColormap(float t); ImVec4 LerpColormap(float t);

View File

@ -295,20 +295,26 @@ void ShowDemoWindow(bool* p_open) {
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
if (ImGui::CollapsingHeader("Pie Charts")) { if (ImGui::CollapsingHeader("Pie Charts")) {
static const char* labels1[] = {"Frogs","Hogs","Dogs","Logs"}; static const char* labels1[] = {"Frogs","Hogs","Dogs","Logs"};
static t_float pre_normalized[] = {0.15f, 0.30f, 0.45f, 0.10f}; static float data1[] = {0.15f, 0.30f, 0.2f, 0.05f};
static bool normalize = false;
ImGui::SetNextItemWidth(250);
ImGui::DragFloat4("Values", data1, 0.01f, 0, 1);
if ((data1[0] + data1[1] + data1[2] + data1[3]) < 1) {
ImGui::SameLine();
ImGui::Checkbox("Normalize", &normalize);
}
SetNextPlotLimits(0,1,0,1,ImGuiCond_Always); SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
if (ImPlot::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) { if (ImPlot::BeginPlot("##Pie1", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
ImPlot::PlotPieChart(labels1, pre_normalized, 4, 0.5f, 0.5f, 0.4f); ImPlot::PlotPieChart(labels1, data1, 4, 0.5f, 0.5f, 0.4f, normalize, "%.2f");
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
ImGui::SameLine(); ImGui::SameLine();
ImPlot::SetColormap(ImPlotColormap_Cool, 5); ImPlot::SetColormap(ImPlotColormap_Cool, 5);
SetNextPlotLimits(0,1,0,1,ImGuiCond_Always); SetNextPlotLimits(0,1,0,1,ImGuiCond_Always);
static const char* labels2[] = {"One##1","One##2","Two","Three","Five"}; static const char* labels2[] = {"A","B","C","D","E"};
static t_float not_normalized[] = {1,1,2,3,5}; static t_float data2[] = {1,1,2,3,5};
if (ImPlot::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) { if (ImPlot::BeginPlot("##Pie2", NULL, NULL, ImVec2(250,250), ImPlotFlags_Legend, 0, 0)) {
ImPlot::PlotPieChart(labels2, not_normalized, 5, 0.5f, 0.5f, 0.4f, NULL, 0); ImPlot::PlotPieChart(labels2, data2, 5, 0.5f, 0.5f, 0.4f, true, "%.0f", 180);
ImPlot::EndPlot(); ImPlot::EndPlot();
} }
ImPlot::SetColormap(ImPlotColormap_Default); ImPlot::SetColormap(ImPlotColormap_Default);