mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
basic diagram functionality
This commit is contained in:
parent
37283e51c3
commit
47330653da
@ -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<LineChart>(contentArea.resize(-5), "test title");
|
||||
auto plotData = extractData(stat, [](StatisticDataSetEntry val){ return val.resources[EGameResID::GOLD]; });
|
||||
chart = std::make_shared<LineChart>(contentArea.resize(-5), "test title", plotData);
|
||||
}
|
||||
|
||||
LineChart::LineChart(Rect position, std::string title) : CIntObject()
|
||||
std::map<ColorRGBA, std::vector<float>> CStatisticScreen::extractData(StatisticDataSet stat, std::function<float(StatisticDataSetEntry val)> 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<float> tmpColorSet;
|
||||
std::map<ColorRGBA, std::vector<float>> 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<ColorRGBA, std::vector<float>> 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<CLabel>(pos.w / 2, 20, FONT_MEDIUM, ETextAlignment::CENTER, Colors::WHITE, title));
|
||||
|
||||
canvas = std::make_shared<GraphicalPrimitiveCanvas>(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);
|
||||
}
|
||||
|
@ -19,14 +19,12 @@ class LineChart;
|
||||
class CStatisticScreen : public CWindowObject
|
||||
{
|
||||
std::shared_ptr<FilledTexturePlayerColored> filledBackground;
|
||||
|
||||
std::vector<std::shared_ptr<CIntObject>> layout;
|
||||
|
||||
std::shared_ptr<CToggleButton> buttonCsvSave;
|
||||
|
||||
StatisticDataSet statistic;
|
||||
|
||||
std::shared_ptr<LineChart> chart;
|
||||
|
||||
std::map<ColorRGBA, std::vector<float>> extractData(StatisticDataSet stat, std::function<float(StatisticDataSetEntry val)> selector);
|
||||
public:
|
||||
CStatisticScreen(StatisticDataSet stat);
|
||||
};
|
||||
@ -36,5 +34,5 @@ class LineChart : public CIntObject
|
||||
std::shared_ptr<GraphicalPrimitiveCanvas> canvas;
|
||||
std::vector<std::shared_ptr<CIntObject>> layout;
|
||||
public:
|
||||
LineChart(Rect position, std::string title);
|
||||
LineChart(Rect position, std::string title, std::map<ColorRGBA, std::vector<float>> data);
|
||||
};
|
||||
|
@ -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 <typename Handler>
|
||||
void serialize(Handler &h)
|
||||
{
|
||||
|
@ -93,8 +93,6 @@ struct DLL_LINKAGE StatisticDataSetEntry
|
||||
|
||||
class DLL_LINKAGE StatisticDataSet
|
||||
{
|
||||
std::vector<StatisticDataSetEntry> data;
|
||||
|
||||
public:
|
||||
void add(StatisticDataSetEntry entry);
|
||||
static StatisticDataSetEntry createEntry(const PlayerState * ps, const CGameState * gs);
|
||||
@ -128,6 +126,7 @@ public:
|
||||
h & movementPointsUsed;
|
||||
}
|
||||
};
|
||||
std::vector<StatisticDataSetEntry> data;
|
||||
std::map<PlayerColor, PlayerAccumulatedValueStorage> accumulatedValues;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h)
|
||||
|
Loading…
Reference in New Issue
Block a user