Skip to content

Commit 881a721

Browse files
committed
tidy stuff up
1 parent 1b95bb2 commit 881a721

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/Interface.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11

22
#include "Interface.h"
33

4-
#include <string>
5-
64
#include "imgui-SFML.h"
75
#include "imgui.h"
86
#include "implot.h"
@@ -418,26 +416,20 @@ void Interface::draw(sf::RenderWindow& window) {
418416
ImPlot::SetupAxesLimits(0, 1, 0, 1, ImPlotCond_Always);
419417

420418
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;
434421

435-
pieLabelsInitialized = numbersSize;
422+
if(labelsIds.size() != numbersSize) {
423+
labels.resize(numbersSize);
424+
labelsIds.resize(numbersSize);
436425

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+
}
439431

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");
441433
}
442434
}
443435
else if(Settings::PLOT_TYPE == Settings::PLOT_TYPES::LINES) {

0 commit comments

Comments
 (0)