diff --git a/client/mainmenu/CStatisticScreen.cpp b/client/mainmenu/CStatisticScreen.cpp index e0a716fc1..e3c443433 100644 --- a/client/mainmenu/CStatisticScreen.cpp +++ b/client/mainmenu/CStatisticScreen.cpp @@ -17,6 +17,8 @@ #include "../gui/WindowHandler.h" #include "../gui/Shortcut.h" +#include "../render/Graphics.h" + #include "../widgets/Images.h" #include "../widgets/GraphicalPrimitiveCanvas.h" #include "../widgets/TextControls.h" @@ -47,10 +49,35 @@ CStatisticScreen::CStatisticScreen(StatisticDataSet stat) }); buttonCsvSave->setTextOverlay(CGI->generaltexth->translate("vcmi.statisticWindow.csvSave"), EFonts::FONT_SMALL, Colors::YELLOW); - chart = std::make_shared(contentArea.resize(-5), "test title"); + auto plotData = extractData(stat, [](StatisticDataSetEntry val){ return val.resources[EGameResID::GOLD]; }); + chart = std::make_shared(contentArea.resize(-5), "test title", plotData); } -LineChart::LineChart(Rect position, std::string title) : CIntObject() +std::map> CStatisticScreen::extractData(StatisticDataSet stat, std::function selector) +{ + auto tmpData = stat.data; + std::sort(tmpData.begin(), tmpData.end(), [](StatisticDataSetEntry v1, StatisticDataSetEntry v2){ return v1.player == v2.player ? v1.day < v2.day : v1.player < v2.player; }); + + PlayerColor tmpColor = PlayerColor::NEUTRAL; + std::vector tmpColorSet; + std::map> plotData; + for(auto & val : tmpData) + { + if(tmpColor != val.player) + { + if(tmpColorSet.size()) + plotData[graphics->playerColors[tmpColor.getNum()]] = tmpColorSet; + tmpColorSet.clear(); + tmpColor = val.player; + } + tmpColorSet.push_back(selector(val)); + } + plotData[graphics->playerColors[tmpColor.getNum()]] = tmpColorSet; + + return plotData; +} + +LineChart::LineChart(Rect position, std::string title, std::map> data) : CIntObject() { OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE; @@ -62,9 +89,10 @@ LineChart::LineChart(Rect position, std::string title) : CIntObject() layout.push_back(std::make_shared(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title)); canvas = std::make_shared(Rect(0, 0, pos.w, pos.h)); - canvas->addLine(chartArea.topLeft(), chartArea.bottomRight(), Colors::GREEN); // Axis canvas->addLine(chartArea.topLeft() + Point(0, -10), chartArea.topLeft() + Point(0, chartArea.h + 10), Colors::WHITE); canvas->addLine(chartArea.topLeft() + Point(-10, chartArea.h), chartArea.topLeft() + Point(chartArea.w + 10, chartArea.h), Colors::WHITE); + + canvas->addLine(chartArea.topLeft(), chartArea.bottomRight(), Colors::GREEN); } diff --git a/client/mainmenu/CStatisticScreen.h b/client/mainmenu/CStatisticScreen.h index bc369c811..96c28bc87 100644 --- a/client/mainmenu/CStatisticScreen.h +++ b/client/mainmenu/CStatisticScreen.h @@ -19,14 +19,12 @@ class LineChart; class CStatisticScreen : public CWindowObject { std::shared_ptr filledBackground; - std::vector> layout; - std::shared_ptr buttonCsvSave; - StatisticDataSet statistic; - std::shared_ptr chart; + + std::map> extractData(StatisticDataSet stat, std::function selector); public: CStatisticScreen(StatisticDataSet stat); }; @@ -36,5 +34,5 @@ class LineChart : public CIntObject std::shared_ptr canvas; std::vector> layout; public: - LineChart(Rect position, std::string title); + LineChart(Rect position, std::string title, std::map> data); }; diff --git a/lib/Color.h b/lib/Color.h index 6ad89513a..4a9fc41d9 100644 --- a/lib/Color.h +++ b/lib/Color.h @@ -49,6 +49,11 @@ public: , a(ALPHA_OPAQUE) {} + bool operator <(const ColorRGBA &val) const + { + return (r + g + b) < (val.r + val.g + val.b); + } + template void serialize(Handler &h) { diff --git a/lib/gameState/GameStatistics.h b/lib/gameState/GameStatistics.h index 5bc34cd6e..03a870860 100644 --- a/lib/gameState/GameStatistics.h +++ b/lib/gameState/GameStatistics.h @@ -93,8 +93,6 @@ struct DLL_LINKAGE StatisticDataSetEntry class DLL_LINKAGE StatisticDataSet { - std::vector data; - public: void add(StatisticDataSetEntry entry); static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs); @@ -128,6 +126,7 @@ public: h & movementPointsUsed; } }; + std::vector data; std::map accumulatedValues; template void serialize(Handler &h)