From 1b95bb23a00fc434d4cfa18b18a44e665e2891e4 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Wed, 3 Dec 2025 23:58:38 +0200 Subject: [PATCH 1/2] feat: initial changes to support pies --- include/Settings.h | 2 +- src/Interface.cpp | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/include/Settings.h b/include/Settings.h index 16c5ab1..fec560f 100644 --- a/include/Settings.h +++ b/include/Settings.h @@ -30,7 +30,7 @@ struct Settings inline static const float PLOT_MIN_DELAY = IF_PLATFORM_WINDOWS(1.f, 0.01f); inline static const float PLOT_MAX_DELAY = 500.f; - enum class PLOT_TYPES { BARS, LINES, HEATMAP }; + enum class PLOT_TYPES { BARS, LINES, HEATMAP, PIE }; inline static PLOT_TYPES PLOT_TYPE = PLOT_TYPES::BARS; inline static bool PLOT_SHOW_SCALE = true; diff --git a/src/Interface.cpp b/src/Interface.cpp index 8098a42..aa3e167 100644 --- a/src/Interface.cpp +++ b/src/Interface.cpp @@ -1,6 +1,8 @@ #include "Interface.h" +#include + #include "imgui-SFML.h" #include "imgui.h" #include "implot.h" @@ -206,9 +208,9 @@ void Interface::draw(sf::RenderWindow& window) { ImGui::Checkbox("Show scale", &Settings::PLOT_SHOW_SCALE); static const std::pair typeNames[] = { {"Bars", Settings::PLOT_TYPES::BARS}, {"Lines", Settings::PLOT_TYPES::LINES}, - {"Heatmap", Settings::PLOT_TYPES::HEATMAP} }; + {"Heatmap", Settings::PLOT_TYPES::HEATMAP}, {"Pie", Settings::PLOT_TYPES::PIE} }; static int typeChoosed = 0; - if (ImGui::SliderInt("Plot type", &typeChoosed, 0, 2, typeNames[typeChoosed].first)) + if (ImGui::SliderInt("Plot type", &typeChoosed, 0, 3, typeNames[typeChoosed].first)) Settings::PLOT_TYPE = typeNames[typeChoosed].second; ImGui::Separator(); @@ -374,7 +376,11 @@ void Interface::draw(sf::RenderWindow& window) { ImGui::SameLine(); } - if (ImPlot::BeginPlot("##MainPlot", {-1, plotSizeHeight}, ImPlotFlags_NoMenus | ImPlotFlags_NoMouseText)) { + ImPlotFlags plotFlags = ImPlotFlags_NoMenus | ImPlotFlags_NoMouseText; + if (Settings::PLOT_TYPE == Settings::PLOT_TYPES::PIE) + plotFlags |= ImPlotFlags_NoLegend; + + if (ImPlot::BeginPlot("##MainPlot", {-1, plotSizeHeight}, plotFlags)) { static std::pair gridSize; if (!Settings::PLOT_SHOW_SCALE || Settings::PLOT_TYPE == Settings::PLOT_TYPES::HEATMAP) @@ -408,6 +414,32 @@ void Interface::draw(sf::RenderWindow& window) { ImPlot::PopStyleColor(); ImPlot::PopStyleColor(); ImPlot::PopStyleColor(); } } + else if(Settings::PLOT_TYPE == Settings::PLOT_TYPES::PIE) { + ImPlot::SetupAxesLimits(0, 1, 0, 1, ImPlotCond_Always); + + if(numbersSize > 0) { + // cache label strings so ImPlot receives stable pointers each frame + static std::vector pieLabels; + static std::vector pieLabelIds; + static unsigned pieLabelsInitialized = 0; + + if(pieLabels.size() != numbersSize) { + pieLabels.resize(numbersSize); + pieLabelIds.resize(numbersSize); + pieLabelsInitialized = 0; + } + + for(unsigned i = pieLabelsInitialized; i < numbersSize; ++i) + pieLabels[i] = std::to_string(i); + + pieLabelsInitialized = numbersSize; + + for(unsigned i = 0; i < numbersSize; ++i) + pieLabelIds[i] = pieLabels[i].c_str(); + + ImPlot::PlotPieChart(pieLabelIds.data(), &numbers[0], numbersSize, 0.5, 0.5, 0.48, "%.0f"); + } + } else if(Settings::PLOT_TYPE == Settings::PLOT_TYPES::LINES) { ImPlot::SetupAxesLimits(0, numbersSize - 1, 0, Settings::SHUFFLE_MAX_VALUE, ImPlotCond_Always); From 881a7211f667d03befe6209cfbb81fd5bf208ec6 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Thu, 4 Dec 2025 00:09:41 +0200 Subject: [PATCH 2/2] tidy stuff up --- src/Interface.cpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/Interface.cpp b/src/Interface.cpp index aa3e167..71f36cb 100644 --- a/src/Interface.cpp +++ b/src/Interface.cpp @@ -1,8 +1,6 @@ #include "Interface.h" -#include - #include "imgui-SFML.h" #include "imgui.h" #include "implot.h" @@ -418,26 +416,20 @@ void Interface::draw(sf::RenderWindow& window) { ImPlot::SetupAxesLimits(0, 1, 0, 1, ImPlotCond_Always); if(numbersSize > 0) { - // cache label strings so ImPlot receives stable pointers each frame - static std::vector pieLabels; - static std::vector pieLabelIds; - static unsigned pieLabelsInitialized = 0; - - if(pieLabels.size() != numbersSize) { - pieLabels.resize(numbersSize); - pieLabelIds.resize(numbersSize); - pieLabelsInitialized = 0; - } - - for(unsigned i = pieLabelsInitialized; i < numbersSize; ++i) - pieLabels[i] = std::to_string(i); + static std::vector labels(numbersSize); + static std::vector labelsIds; - pieLabelsInitialized = numbersSize; + if(labelsIds.size() != numbersSize) { + labels.resize(numbersSize); + labelsIds.resize(numbersSize); - for(unsigned i = 0; i < numbersSize; ++i) - pieLabelIds[i] = pieLabels[i].c_str(); + for(unsigned i = 0; i < numbersSize; ++i) { + labels[i] = std::to_string(i); + labelsIds[i] = labels[i].c_str(); + } + } - ImPlot::PlotPieChart(pieLabelIds.data(), &numbers[0], numbersSize, 0.5, 0.5, 0.48, "%.0f"); + ImPlot::PlotPieChart(labelsIds.data(), &numbers[0], numbersSize, 0.5, 0.5, 0.48, "%.0f"); } } else if(Settings::PLOT_TYPE == Settings::PLOT_TYPES::LINES) {