|
1 | 1 |
|
2 | 2 | #include "Interface.h" |
3 | 3 |
|
4 | | -#include <string> |
5 | | - |
6 | 4 | #include "imgui-SFML.h" |
7 | 5 | #include "imgui.h" |
8 | 6 | #include "implot.h" |
@@ -418,26 +416,20 @@ void Interface::draw(sf::RenderWindow& window) { |
418 | 416 | ImPlot::SetupAxesLimits(0, 1, 0, 1, ImPlotCond_Always); |
419 | 417 |
|
420 | 418 | 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); |
| 419 | + static std::vector<std::string> labels(numbersSize); |
| 420 | + static std::vector<const char*> labelsIds; |
434 | 421 |
|
435 | | - pieLabelsInitialized = numbersSize; |
| 422 | + if(labelsIds.size() != numbersSize) { |
| 423 | + labels.resize(numbersSize); |
| 424 | + labelsIds.resize(numbersSize); |
436 | 425 |
|
437 | | - for(unsigned i = 0; i < numbersSize; ++i) |
438 | | - pieLabelIds[i] = pieLabels[i].c_str(); |
| 426 | + for(unsigned i = 0; i < numbersSize; ++i) { |
| 427 | + labels[i] = std::to_string(i); |
| 428 | + labelsIds[i] = labels[i].c_str(); |
| 429 | + } |
| 430 | + } |
439 | 431 |
|
440 | | - ImPlot::PlotPieChart(pieLabelIds.data(), &numbers[0], numbersSize, 0.5, 0.5, 0.48, "%.0f"); |
| 432 | + ImPlot::PlotPieChart(labelsIds.data(), &numbers[0], numbersSize, 0.5, 0.5, 0.48, "%.0f"); |
441 | 433 | } |
442 | 434 | } |
443 | 435 | else if(Settings::PLOT_TYPE == Settings::PLOT_TYPES::LINES) { |
|
0 commit comments