Files
DEC/DEC_GUI/derrep2013qplot.cpp
2024-10-03 18:43:04 +07:00

96 lines
3.3 KiB
C++

#include "derrep2013qplot.h"
#include "DEC-0.0/DerevyankoReport.h"
static const int TOP_OFFSET = 100;
static const int LINE_THICKNESS = 2;
DerRep2013QPlot::DerRep2013QPlot(QWidget *parent) :
QWidget(parent)
{
}
void DerRep2013QPlot::setGraphics(QCustomPlot *customPlot, int popNum, QString name, QColor &color)
{
customPlot->addGraph();
customPlot->graph(popNum)->setData(DerevyankoReport::generations[popNum], DerevyankoReport::popSizes[popNum]);
customPlot->graph(popNum)->setPen(QPen(color, LINE_THICKNESS));
customPlot->graph(popNum)->setName(name);
}
int DerRep2013QPlot::randInt(int low, int high)
{
// Random number between low and high
return qrand() % ((high + 1) - low) + low;
}
void DerRep2013QPlot::drawGraphics(QCustomPlot *customPlot)
{
QColor colours[10] = {QColor("cyan"), QColor("magenta"), QColor("red"),
QColor("darkRed"), QColor("darkCyan"), QColor("darkMagenta"),
QColor("green"), QColor("darkGreen"), QColor("yellow"),
QColor("blue")};
QColor color;
customPlot->legend->clearItems();
customPlot->clearGraphs();
customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
int start = 0;
for (int i = 0; i < DerevyankoReport::pops.size(); i++)
{
// QTime time = QTime::currentTime();
// qsrand((uint)time.msec());
// int r = randInt(0, 255);
// int g = randInt(0, 255);
// int b = randInt(0, 255);
color = colours[start];
start++;
if(start == sizeof(colours))
{
start = 0;
}
setGraphics(customPlot, i, DerevyankoReport::populNames[i], color);
}
// setGraphics(customPlot, 0, "pop_f", Qt::blue);
// setGraphics(customPlot, 1, "pop_G", Qt::red);
// setGraphics(customPlot, 2, "pop_e", Qt::yellow);
// setGraphics(customPlot, 3, "pop_F", Qt::magenta);
// setGraphics(customPlot, 4, "pop_d", Qt::black);
// setGraphics(customPlot, 5, "pop_c", Qt::green);
// setGraphics(customPlot, 6, "pop_E", Qt::darkBlue);
// setGraphics(customPlot, 7, "pop_b", Qt::darkRed);
// setGraphics(customPlot, 8, "pop_D", Qt::cyan);
// setGraphics(customPlot, 9, "pop_a", Qt::darkCyan);
// setGraphics(customPlot, 10, "pop_C", Qt::darkMagenta);
// setGraphics(customPlot, 11, "pop_A", Qt::darkYellow);
// setGraphics(customPlot, 12, "pop_B", Qt::gray);
customPlot->legend->setVisible(true);
QFont legendFont = font();
legendFont.setPointSize(8);
customPlot->legend->setFont(legendFont);
customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignRight);
int maxX = 0;
int maxY = 0;
for (int i = 0; i < DerevyankoReport::pops.size(); i++)
{
if (DerevyankoReport::globalGenerations > maxX)
{
maxX = DerevyankoReport::globalGenerations;
}
if (DerevyankoReport::maxYval[i] > maxY)
{
maxY = DerevyankoReport::maxYval[i];
}
}
customPlot->xAxis->setRange(0, maxX + TOP_OFFSET);
customPlot->yAxis->setRange(0, maxY + TOP_OFFSET);
customPlot->xAxis->setLabel("Generations");
customPlot->yAxis->setLabel("popSize");
customPlot->replot();
}