|
1 | 1 |
|
2 | 2 | #include "Interface.h" |
3 | 3 |
|
| 4 | +#include <string> |
| 5 | + |
4 | 6 | #include "imgui-SFML.h" |
5 | 7 | #include "imgui.h" |
6 | 8 | #include "implot.h" |
@@ -206,9 +208,9 @@ void Interface::draw(sf::RenderWindow& window) { |
206 | 208 | ImGui::Checkbox("Show scale", &Settings::PLOT_SHOW_SCALE); |
207 | 209 |
|
208 | 210 | static const std::pair<const char*, Settings::PLOT_TYPES> typeNames[] = { {"Bars", Settings::PLOT_TYPES::BARS}, {"Lines", Settings::PLOT_TYPES::LINES}, |
209 | | - {"Heatmap", Settings::PLOT_TYPES::HEATMAP} }; |
| 211 | + {"Heatmap", Settings::PLOT_TYPES::HEATMAP}, {"Pie", Settings::PLOT_TYPES::PIE} }; |
210 | 212 | static int typeChoosed = 0; |
211 | | - if (ImGui::SliderInt("Plot type", &typeChoosed, 0, 2, typeNames[typeChoosed].first)) |
| 213 | + if (ImGui::SliderInt("Plot type", &typeChoosed, 0, 3, typeNames[typeChoosed].first)) |
212 | 214 | Settings::PLOT_TYPE = typeNames[typeChoosed].second; |
213 | 215 |
|
214 | 216 | ImGui::Separator(); |
@@ -374,7 +376,11 @@ void Interface::draw(sf::RenderWindow& window) { |
374 | 376 | ImGui::SameLine(); |
375 | 377 | } |
376 | 378 |
|
377 | | - if (ImPlot::BeginPlot("##MainPlot", {-1, plotSizeHeight}, ImPlotFlags_NoMenus | ImPlotFlags_NoMouseText)) { |
| 379 | + ImPlotFlags plotFlags = ImPlotFlags_NoMenus | ImPlotFlags_NoMouseText; |
| 380 | + if (Settings::PLOT_TYPE == Settings::PLOT_TYPES::PIE) |
| 381 | + plotFlags |= ImPlotFlags_NoLegend; |
| 382 | + |
| 383 | + if (ImPlot::BeginPlot("##MainPlot", {-1, plotSizeHeight}, plotFlags)) { |
378 | 384 | static std::pair<unsigned, unsigned> gridSize; |
379 | 385 |
|
380 | 386 | if (!Settings::PLOT_SHOW_SCALE || Settings::PLOT_TYPE == Settings::PLOT_TYPES::HEATMAP) |
@@ -408,6 +414,32 @@ void Interface::draw(sf::RenderWindow& window) { |
408 | 414 | ImPlot::PopStyleColor(); ImPlot::PopStyleColor(); ImPlot::PopStyleColor(); |
409 | 415 | } |
410 | 416 | } |
| 417 | + else if(Settings::PLOT_TYPE == Settings::PLOT_TYPES::PIE) { |
| 418 | + ImPlot::SetupAxesLimits(0, 1, 0, 1, ImPlotCond_Always); |
| 419 | + |
| 420 | + if(numbersSize > 0) { |
| 421 | + // cache label strings so ImPlot receives stable pointers each frame |
| 422 | + static std::vector<std::string> pieLabels; |
| 423 | + static std::vector<const char*> pieLabelIds; |
| 424 | + static unsigned pieLabelsInitialized = 0; |
| 425 | + |
| 426 | + if(pieLabels.size() != numbersSize) { |
| 427 | + pieLabels.resize(numbersSize); |
| 428 | + pieLabelIds.resize(numbersSize); |
| 429 | + pieLabelsInitialized = 0; |
| 430 | + } |
| 431 | + |
| 432 | + for(unsigned i = pieLabelsInitialized; i < numbersSize; ++i) |
| 433 | + pieLabels[i] = std::to_string(i); |
| 434 | + |
| 435 | + pieLabelsInitialized = numbersSize; |
| 436 | + |
| 437 | + for(unsigned i = 0; i < numbersSize; ++i) |
| 438 | + pieLabelIds[i] = pieLabels[i].c_str(); |
| 439 | + |
| 440 | + ImPlot::PlotPieChart(pieLabelIds.data(), &numbers[0], numbersSize, 0.5, 0.5, 0.48, "%.0f"); |
| 441 | + } |
| 442 | + } |
411 | 443 | else if(Settings::PLOT_TYPE == Settings::PLOT_TYPES::LINES) { |
412 | 444 | ImPlot::SetupAxesLimits(0, numbersSize - 1, 0, Settings::SHUFFLE_MAX_VALUE, ImPlotCond_Always); |
413 | 445 |
|
|
0 commit comments