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..71f36cb 100644 --- a/src/Interface.cpp +++ b/src/Interface.cpp @@ -206,9 +206,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 +374,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 +412,26 @@ 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) { + static std::vector labels(numbersSize); + static std::vector labelsIds; + + if(labelsIds.size() != numbersSize) { + labels.resize(numbersSize); + labelsIds.resize(numbersSize); + + for(unsigned i = 0; i < numbersSize; ++i) { + labels[i] = std::to_string(i); + labelsIds[i] = labels[i].c_str(); + } + } + + ImPlot::PlotPieChart(labelsIds.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);