#include "breedqplot.h" #include "DEC-0.0/processor/Settings.h" #include static const int TOP_OFFSET = 100; static const int LINE_THICKNESS = 2; BreedQPlot::BreedQPlot(QWidget *parent) : QWidget(parent) { } void BreedQPlot::drawGraphics(QCustomPlot *customPlot, int popInd) { //std::cout << "draw " << std::endl; customPlot->legend->clearItems(); customPlot->clearGraphs(); customPlot->clearPlottables(); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); QCPBars *malesGene = new QCPBars(customPlot->xAxis, customPlot->yAxis); QCPBars *femalesGene = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(malesGene); customPlot->addPlottable(femalesGene); QPen pen; pen.setWidthF(1.2); femalesGene->setName("Females genes"); pen.setColor(QColor(255, 131, 0)); femalesGene->setPen(pen); femalesGene->setBrush(QColor(255, 131, 0, 50)); malesGene->setName("Males genes"); pen.setColor(QColor(1, 92, 191)); malesGene->setPen(pen); malesGene->setBrush(QColor(1, 92, 191, 50)); // stack bars ontop of each other: malesGene->moveAbove(femalesGene); QVector ticks; QVector labels; QVector mVals; QVector fVals; for (int i = 0; i < Settings::malesGene.size(); i++) { ticks.push_back(i); labels.push_back("Ind" + QString::number(i + 1)); } customPlot->xAxis->setAutoTicks(false); customPlot->xAxis->setAutoTickLabels(false); customPlot->xAxis->setTickVector(ticks); customPlot->xAxis->setTickVectorLabels(labels); customPlot->xAxis->setTickLabelRotation(60); customPlot->xAxis->setSubTickCount(0); customPlot->xAxis->setTickLength(0, 4); customPlot->xAxis->grid()->setVisible(true); //customPlot->xAxis->setRange(0, Settings::malesGene[popInd].size()); // prepare y axis: //customPlot->yAxis->setRange(0, 12.1); customPlot->yAxis->setPadding(5); // a bit more space to the left border customPlot->yAxis->setLabel("Male/Female genotype"); customPlot->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); customPlot->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); customPlot->yAxis->grid()->setSubGridPen(gridPen); for (int i = 0; i < Settings::malesGene.size(); i++) { //std::cout << "draw " << i << std::endl; fVals.push_back(Settings::femalesGene[i][popInd]); mVals.push_back(Settings::malesGene[i][popInd]); } femalesGene->setData(ticks, fVals); malesGene->setData(ticks, mVals); // setup legend: customPlot->legend->setVisible(true); customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter); customPlot->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); customPlot->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(10); customPlot->legend->setFont(legendFont); customPlot->rescaleAxes(); customPlot->replot(); }