Esempio n. 1
0
void PlottingDialog::drawLumHistogram(QImage *img){
    QCPBars *lBar = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    ui->customPlot->addPlottable(lBar);
    int bins = 16; // edit this to define the number of bins in which the histogram is separated
    QVector<double> keyLData(bins);
    QVector<double> valueLData(bins, 0);
    qreal currentLightness;
    for(int x=0;x<img->width();x++) {
        for(int y=0;y<img->height();y++){
            currentLightness = qFloor(QColor(img->pixel(x,y)).lightnessF() * bins);
            //qDebug() << "CurrentLightness" << currentLightness;
            //only special case: 100% luminance -> last expression returns BINS == ilegal access!
            currentLightness = (currentLightness == bins) ? bins -1 : currentLightness;
            valueLData[currentLightness]++;
        }
    }
    int totalPix = img->width() * img->height();
    for (int i=0;i<bins;i++){
        keyLData[i] = (i/(double)bins);
        valueLData[i] = valueLData[i] / (double) totalPix;
    }
    qDebug() << keyLData;
    qDebug() << valueLData;
    lBar->setData(keyLData, valueLData);
    ui->customPlot->xAxis->setLabel("Luminance %");
    ui->customPlot->xAxis->setRange(0,1);
    lBar->setWidth(1/(2*(double)bins));
    ui->customPlot->yAxis->setLabel("Image %");
    ui->customPlot->yAxis->setRange(0,1);
    ui->customPlot->replot();
}
void Window::plotHistogram(QVector<double> key, QVector<double> nonEq, QVector<double> eqValue, QVector<double> lutValue)
{
    QCustomPlot *histogramPlot = ui->histogramPlot;

    histogramPlot->clearGraphs();

    // Non Equalized
    QCPBars *nonEqHistBars = new QCPBars(histogramPlot->xAxis, histogramPlot->yAxis);
    histogramPlot->addPlottable(nonEqHistBars);
    nonEqHistBars->setWidth(1);
    nonEqHistBars->setData(key, nonEq);
    nonEqHistBars->setPen(Qt::NoPen);
    nonEqHistBars->setBrush(QColor(10, 140, 70, 160));

    //    // Equalized
    //    QCPBars *eqHistBars = new QCPBars(histogramPlot->xAxis, histogramPlot->yAxis);
    //    histogramPlot->addPlottable(eqHistBars);
    //    eqHistBars->setWidth(1);
    //    eqHistBars->setData(key, eqValue);
    //    eqHistBars->setPen(Qt::NoPen);
    //    eqHistBars->setBrush(QColor(10, 100, 50, 70));
    ////    eqHistBars->moveAbove(eqHistBars);

    //    // LUT
    //    QCPGraph *lut = histogramPlot->addGraph();
    //    lut->setData(key, lutValue);
    //    lut->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
    //    lut->setLineStyle(QCPGraph::lsStepCenter);
    //    lut->setPen(QPen(QColor(120, 120, 120), 2));

    histogramPlot->replot();
    histogramPlot->rescaleAxes();


}
Esempio n. 3
0
void RImageDock::drawHist()
{
    cv::Mat tempHist;
    matHist.convertTo(tempHist, CV_64F);

    int nBins = matHist.rows;
    double minHist;
    double maxHist;
    cv::minMaxLoc(matHist, &minHist, &maxHist);

    QVector<double> x(nBins); // y must be the histogram values
    for (int i=0; i< nBins; ++i)
    {
      x[i] = dataMin + histWidth*i; // x goes from 0 to nBins-1
    }

    // Pointer to matHist data.
    const double* matHistPtr = tempHist.ptr<double>(0);
    std::vector<double> matHistStdVect(matHistPtr, matHistPtr + matHist.rows);
    QVector<double> y = QVector<double>::fromStdVector(matHistStdVect);

    // create graph and assign data to it:
    customPlot = new QCustomPlot();
    customPlot->xAxis->setLabel("Intensity bins");
    customPlot->yAxis->setLabel("Pixels");

    QCPBars *myBars = new QCPBars(customPlot->xAxis, customPlot->yAxis);
    customPlot->addPlottable(myBars);
    myBars->setData(x, y);
    myBars->setWidth(1);

//    customPlot->addGraph();
//    customPlot->graph(0)->setData(x, y);

    customPlot->yAxis->setScaleType(QCPAxis::stLogarithmic);
    customPlot->rescaleAxes();
    // set axes ranges, so we see all data:
    //customPlot->xAxis->setRange(0, nBins+100);
    double maxXRange = std::min(dataMax, (double) 4*percentileHigh);
    double minXRange = std::min(0.0, (double) percentileLow);
    customPlot->xAxis->setRange(minXRange, maxXRange);
    customPlot->yAxis->setRange(1, maxHist);

//    customPlot->plottable(0)->setPen(QPen(QColor(0, 0, 255, 50))); // line color blue for first graph
//    customPlot->plottable(0)->setBrush(QBrush(QColor(0, 0, 255, 50)));
    customPlot->plottable(0)->setPen(QPen(QColor(125, 125, 125, 50))); // line color blue for first graph
    customPlot->plottable(0)->setBrush(QBrush(QColor(125, 125, 125, 50)));
    customPlot->setInteraction(QCP::iRangeDrag, true);
    customPlot->setInteraction(QCP::iRangeZoom, true);
    customPlot->axisRect(0)->setRangeDrag(Qt::Horizontal);
    customPlot->axisRect(0)->setRangeZoom(Qt::Horizontal);

    qDebug("customPlot ready for emit signal.");
    emit plotSignal(customPlot);

}
Esempio n. 4
0
bool BarGraph::update(const GRT::VectorDouble &sample ) {

    if( !initialized ) return false;

    this->data = sample;

    //If the plot is hidden then there is no point in updating the graph
    if( this->isHidden() ) {
        return true;
    }

    QCustomPlot *plot = ui->graph;
    QVector<double> keyData;
    QVector<double> valueData;
    QVector<double> tickVector;
    QVector<QString> tickLabels;
    const unsigned int K = (unsigned int)data.size();

    plot->clearPlottables();

    QCPBars *bar = new QCPBars(plot->xAxis,plot->yAxis);
    plot->addPlottable( bar );

    //Add the data to the graph
    for(unsigned int k=0; k<K; k++) {
        keyData << k+1;
        valueData << data[k];
    }
    bar->setData(keyData, valueData);

    //Add the tick labels
    for(unsigned int k=0; k<K; k++) {
        tickVector << double(k+1);
        tickLabels << QString::fromStdString( GRT::Util::intToString( k+1 ) );
    }
    plot->xAxis->setAutoTicks(false);
    plot->xAxis->setAutoTickLabels(false);
    plot->xAxis->setTickVector( tickVector );
    plot->xAxis->setTickVectorLabels( tickLabels );
    plot->xAxis->setLabel("Features");
    plot->yAxis->setLabel("Values");

    plot->rescaleAxes();
    plot->replot();

    return true;
}
Esempio n. 5
0
/**
 * @brief widgetBarChart::drawYear draw a given year on a bar chart
 * @param sel the index of the selected year
 */
void widgetBarChart::drawYear(const int &sel) {
    QCPBars *bar = new QCPBars(ui->widgetBarChart_2->xAxis,ui->widgetBarChart_2->yAxis);
    bar->setName(_meas->yearRange().at(sel));
    bar->setWidth(BAR_WIDTH);
    QPen pen;
    bar->setBrush(COLOUR_LIST[sel%5]);
    pen.setWidthF(PEN_WIDTH);

    QVector<double> valueData, keyData;
    ui->widgetBarChart_2->addPlottable(bar);
    double i = 0.25 + 0.2*ui->widgetBarChart_2->xAxis->plottables().size();
    QList<QListWidgetItem*> tempList = ui->listBarChartMunicipality->selectedItems();
    for(QList<QListWidgetItem*>::Iterator it = tempList.begin(); it != tempList.end(); ++it) {
        QListWidgetItem *tempItem = *it;
        keyData << i;
        i+=1.5;
        try {
            valueData.append(_meas->findMuni(tempItem->text()).getYear(_meas->yearRange().at(sel)).value());
        } catch (std::string s) {
            valueData.append(0.0);
        }
    }
    bar->setData(keyData,valueData);
    bar->keyAxis()->setTickVector(keyData);
    ui->widgetBarChart_2->legend->setVisible(true);
    ui->widgetBarChart_2->replot();
}
Esempio n. 6
0
/**
 * @brief TimerWindow::slotUpdatePlotHorizontal 更新横向绘图槽
 * @param data 数据
 * @param labels 文本
 */
void TimerWindow::slotUpdatePlotHorizontal(QVector<double> &data, QVector<QString> &labels)
{
    qDebug()<<"slotUpdatePlotHorizontal";
    delete(customPlot);
    customPlot = new QCustomPlot();
    customPlot->setFixedSize(500, 250);
    vLayoutMain->addWidget(customPlot);

    // create empty bar chart objects:
    QCPBars *regen = new QCPBars(customPlot->yAxis, customPlot->xAxis);//横向
    customPlot->addPlottable(regen);

    // set names and colors:
    QPen pen;
    regen->setName("Regenerative");
    pen.setColor(QColor("#D26079"));
    regen->setPen(pen);
    regen->setBrush(QColor("#D26079"));

    // prepare x axis with country labels:
    QVector<double> ticks;
    double maxValue = 0;
    //查找最大值
    for(int i = 0; i < labels.size(); i++){
        ticks << i + 1;
        maxValue = maxValue > data.at(i) ? maxValue : data.at(i);
    }
    customPlot->yAxis->setAutoTicks(false);
    customPlot->yAxis->setAutoTickLabels(false);
    customPlot->yAxis->setTickVector(ticks);
    customPlot->yAxis->setTickVectorLabels(labels);
    customPlot->yAxis->setTickLabelRotation(0);
    customPlot->yAxis->setSubTickCount(0);
    customPlot->yAxis->setTickLength(0, 4);
    customPlot->yAxis->grid()->setVisible(true);
    customPlot->yAxis->setRange(0, ticks.size() + 1);
    customPlot->yAxis->setLabel("姓名");

    // prepare y axis:
//    customPlot->xAxis->
    customPlot->xAxis->setRange(0, maxValue + maxValue / 10);
    customPlot->xAxis->setPadding(5); // a bit more space to the left border
    customPlot->xAxis->setLabel("本周时长 (小时)");
    customPlot->xAxis->grid()->setSubGridVisible(true);
    QPen gridPen;
    gridPen.setStyle(Qt::SolidLine);
    gridPen.setColor(QColor(0, 0, 0, 25));
    customPlot->xAxis->grid()->setPen(gridPen);
    gridPen.setStyle(Qt::DotLine);
    customPlot->xAxis->grid()->setSubGridPen(gridPen);

    /*
    // setup legend:
    customPlot->legend->setVisible(false);
    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->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
*/

    regen->setData(ticks, data);
    customPlot->replot();
    customPlot->setHidden(false);
    qDebug()<<"slotUpdatePlotHorizontal end";
}
Esempio n. 7
0
void MainWindow::makePlot()
{
    /*
    QRegExp rx("(\\ |\\n)");
    QStringList query = szoveg.split(rx);
    for (int i=0; i<query.size(); i++)
        QMessageBox::information(0, "info", query[i]);

    int szohossz[3];
    for (int i=0; i<3; i++)
        szohossz[i] = query[i].size();
    for (int i=0; i<3; i++)
        QMessageBox::information(0, "info", QString::number(szohossz[i]));*/

    // create empty bar chart objects:
    QCPBars *regen = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    QCPBars *nuclear = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    QCPBars *fossil = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    ui->customPlot->addPlottable(regen);
    ui->customPlot->addPlottable(nuclear);
    ui->customPlot->addPlottable(fossil);
    // set names and colors:
    QPen pen;
    pen.setWidthF(1.2);
    fossil->setName("Fossil fuels");
    pen.setColor(QColor(255, 131, 0));
    fossil->setPen(pen);
    fossil->setBrush(QColor(255, 131, 0, 50));
    nuclear->setName("Nuclear");
    pen.setColor(QColor(1, 92, 191));
    nuclear->setPen(pen);
    nuclear->setBrush(QColor(1, 92, 191, 50));
    regen->setName("Regenerative");
    pen.setColor(QColor(150, 222, 0));
    regen->setPen(pen);
    regen->setBrush(QColor(150, 222, 0, 70));
    // stack bars ontop of each other:
    nuclear->moveAbove(fossil);
    regen->moveAbove(nuclear);

    // prepare x axis with country labels:
    QVector<double> ticks;
    QVector<QString> labels;
    ticks << 1 << 2 << 3 << 4 << 5 << 6 << 7;
    labels << "Japan" << "Germany" << "France" << "UK" << "Italy" << "Canada";
    ui->customPlot->xAxis->setAutoTicks(false);
    ui->customPlot->xAxis->setAutoTickLabels(false);
    ui->customPlot->xAxis->setTickVector(ticks);
    ui->customPlot->xAxis->setTickVectorLabels(labels);
    ui->customPlot->xAxis->setTickLabelRotation(60);
    ui->customPlot->xAxis->setSubTickCount(0);
    ui->customPlot->xAxis->setTickLength(0, 4);
    ui->customPlot->xAxis->grid()->setVisible(true);
    ui->customPlot->xAxis->setRange(0, 8);

    // prepare y axis:
    ui->customPlot->yAxis->setRange(0, 12.1);
    ui->customPlot->yAxis->setPadding(5); // a bit more space to the left border
    ui->customPlot->yAxis->setLabel("Power Consumption in\nKilowatts per Capita (2007)");
    ui->customPlot->yAxis->grid()->setSubGridVisible(false);
    QPen gridPen;
    gridPen.setStyle(Qt::SolidLine);
    gridPen.setColor(QColor(0, 0, 0, 25));
    ui->customPlot->yAxis->grid()->setPen(gridPen);
    gridPen.setStyle(Qt::DotLine);
    ui->customPlot->yAxis->grid()->setSubGridPen(gridPen);

    // Add data:
    QVector<double> fossilData, nuclearData, regenData;
    fossilData  << 0.86*10.5 << 0.83*5.5 << 0.84*5.5 << 0.52*5.8 << 0.89*5.2 << 0.90*4.2 << 0.67*11.2;
    nuclearData << 0.08*10.5 << 0.12*5.5 << 0.12*5.5 << 0.40*5.8 << 0.09*5.2 << 0.00*4.2 << 0.07*11.2;
    regenData   << 0.06*10.5 << 0.05*5.5 << 0.04*5.5 << 0.06*5.8 << 0.02*5.2 << 0.07*4.2 << 0.25*11.2;
    fossil->setData(ticks, fossilData);
    nuclear->setData(ticks, nuclearData);
    regen->setData(ticks, regenData);

    // setup legend:
    ui->customPlot->legend->setVisible(true);
    ui->customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter);
    ui->customPlot->legend->setBrush(QColor(255, 255, 255, 200));
    QPen legendPen;
    legendPen.setColor(QColor(130, 130, 130, 200));
    ui->customPlot->legend->setBorderPen(legendPen);
    QFont legendFont = font();
    legendFont.setPointSize(10);
    ui->customPlot->legend->setFont(legendFont);
    ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
}
/*!
 * Function: slot_get_graph
 * Description: When "Get Graph" is clicked, this function is responsible for generating the graph based on the data passed,
 * a full description of each part is given below
 * @param bool check when it is check
 */
void MainWindow::slot_get_graph(bool)
{


    Stub *stub = new Stub(); //! stub contains data for testing purpose.

    //! This is the variable for bar width; the value will be calculated and scaled accordingly, depending on how
    //! many checkboxes were selected
    double barWidth = 0;
    double i = 0;  //! loop index; counts how many checkboxes where checked
    int barsAdded = 0;


    //! Creating the legend box
    ui -> customPlot -> legend -> clearItems();
    ui -> customPlot -> axisRect()->insetLayout()->setInsetAlignment(0,Qt::AlignTop|Qt::AlignRight);
    ui -> customPlot -> legend -> setVisible(true);
    ui->customPlot->clearPlottables(); //! clear the graph

    //! Set graph interval
    ui->customPlot->xAxis->setAutoTickStep(0);
    ui->customPlot->xAxis->setTicks(1);
    ui->customPlot->xAxis->setTickStep(1.0);
    ui->customPlot->xAxis->setSubTickCount(0);

    chartcolour *colourSelect = new chartcolour();

    ui->customPlot->legend->clearItems();       //!Clears the existing data from the legend
    ui->customPlot->axisRect()->setAutoMargins(QCP::msLeft | QCP::msTop | QCP::msBottom);
    ui->customPlot->axisRect()->setMargins(QMargins(0,0,150,0));
    ui->customPlot->axisRect()->insetLayout()->setInsetPlacement(0, QCPLayoutInset::ipFree);
    ui->customPlot->axisRect()->insetLayout()->setInsetRect(0, QRectF(1.1,0,0.1,0.1));



    //! Scaling the bar width based on the number of cities checked
        if (ui->barrie->isChecked()) {
            ++i;
        }
        if (ui->calgary->isChecked()) {
            ++i;
        }
        if (ui->hamilton->isChecked()) {
            ++i;
        }
        if (ui->london->isChecked()) {
            ++i;
        }
        if (ui->ottawa->isChecked()) {
            ++i;
        }
        if (ui->sudbury->isChecked()) {
            ++i;
        }
        if (ui->thunderBay->isChecked()) {
            ++i;
        }
        if (ui->toronto->isChecked()) {
            ++i;
        }

        if (ui->windsor->isChecked()) {
            ++i;
        }
        if (ui->winnipeg->isChecked()) {
            ++i;
        }


    //! Calculating the new bar width
    double totalWidth = 0.8;
    barWidth = totalWidth / i;
    double setBack = totalWidth/2;
    double offset = 0;


    //! Plot data and create a bar graph for Barrie if this city is selected
    if(ui->barrie->isChecked()) {   //! if barrie is checked
            QCPBars *myBars = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars->setWidth(barWidth);
            myBars->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars->setName("Barrie");

            ui->customPlot->addPlottable(myBars);
            //! Barrie data
            QVector<double> barrieDatatemp = stub->getData("Barrie");
            QVector<double> barrieData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                barrieData << barrieDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                barrieData << barrieDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                barrieData << barrieDatatemp.at(2);
            }
            //!valueYears << 2009-setBack+offset << 2010-setBack+offset<< 2011-setBack+offset;
            ++barsAdded;


            myBars->setData(valueYears, barrieData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();
        }


        //! Plot data and create a bar graph for Calgary if this city is selected
        if (ui->calgary->isChecked()) {
            //! This is for Calgary
            QCPBars *myBars2 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars2->setWidth(barWidth);
            myBars2->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));


            ui->customPlot->addPlottable(myBars2);
            //! now we can modify properties of myBars
            myBars2->setName("Calgary");

            //! Calgary Data
            QVector<double> calgaryDatatemp = stub->getData("Calgary");
            QVector<double> calgaryData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                calgaryData << calgaryDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                calgaryData << calgaryDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                calgaryData << calgaryDatatemp.at(2);
            }

           //! valueYears2 << 2009-setBack+offset << 2010-setBack+offset<< 2011-setBack+offset;
            //!2008.60+barWidth*barsAdded << 2009.60+barWidth*barsAdded << 2010.60+barWidth*barsAdded;
            ++barsAdded;

            myBars2->setData(valueYears, calgaryData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();
        }

        //!Plot data and create a bar graph for London if this city is selected
        if (ui->london->isChecked()) {
            QCPBars *myBars3 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars3->setWidth(barWidth);
            myBars3->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars3->setName("London");

            ui->customPlot->addPlottable(myBars3);
            //! London data
            QVector<double> londonDatatemp = stub->getData("London");
            QVector<double> londonData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                londonData << londonDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                londonData << londonDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                londonData << londonDatatemp.at(2);
            }

           //! valueYears << 2009-setBack+offset << 2010-setBack+offset<< 2011-setBack+offset;
            ++barsAdded;


            myBars3->setData(valueYears, londonData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();


        }


        //!Plot data and create a bar graph for Hamilton if this city is selected
        if (ui->hamilton->isChecked()) {
            QCPBars *myBars4 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars4->setWidth(barWidth);
            myBars4->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars4->setName("Hamilton");

            ui->customPlot->addPlottable(myBars4);
            //! Hamilton data
            QVector<double> hamiltonDatatemp = stub->getData("Hamilton");
            QVector<double> hamiltonData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                hamiltonData << hamiltonDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                hamiltonData << hamiltonDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                hamiltonData << hamiltonDatatemp.at(2);
            }

            ++barsAdded;


            myBars4->setData(valueYears, hamiltonData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();

        }

        //! Plot data and create a bar graph for Ottawa if this city is selected
        if (ui->ottawa->isChecked()) {
            QCPBars *myBars5 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars5->setWidth(barWidth);
            myBars5->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars5->setName("Ottawa");

            ui->customPlot->addPlottable(myBars5);
            //! Ottawa data
            QVector<double> ottawaDatatemp = stub->getData("Ottawa");
            QVector<double> ottawaData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                ottawaData << ottawaDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                ottawaData << ottawaDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                ottawaData << ottawaDatatemp.at(2);
            }

            ++barsAdded;


            myBars5->setData(valueYears, ottawaData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();

        }

        //! Plot data and create a bar graph for Sudbury (Greater) if this city is selected
        if (ui->sudbury->isChecked()) {
            QCPBars *myBars6 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars6->setWidth(barWidth);
            myBars6->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars6->setName("Sudbury");

            ui->customPlot->addPlottable(myBars6);
            //! Sudbury data
            QVector<double> sudburyDatatemp = stub->getData("Sudbury (Greater)");
            QVector<double> sudburyData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                sudburyData << sudburyDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                sudburyData << sudburyDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                sudburyData << sudburyDatatemp.at(2);
            }


            ++barsAdded;


            myBars6->setData(valueYears, sudburyData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();

        }


        //! Plot data and create a bar graph for Thunder Bay if this city is selected
        if (ui->thunderBay->isChecked()) {
            QCPBars *myBars7 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars7->setWidth(barWidth);
            myBars7->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars7->setName("Thunder Bay");

            ui->customPlot->addPlottable(myBars7);
            //! Thunder Bay data
            QVector<double> thunderDatatemp = stub->getData("Thunder Bay");
            QVector<double> thunderData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                thunderData << thunderDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                thunderData << thunderDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                thunderData << thunderDatatemp.at(2);
            }

            ++barsAdded;


            myBars7->setData(valueYears, thunderData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();
        }

        //! Plot data and create a bar graph for Toronto if this city is selected
        if (ui->toronto->isChecked()) {
            QCPBars *myBars8 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars8->setWidth(barWidth);
            myBars8->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars8->setName("Toronto");

            ui->customPlot->addPlottable(myBars8);
            //! Sudbury data
            QVector<double> torontoDatatest = stub->getData("Toronto");
            QVector<double> torontoData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                torontoData << torontoDatatest.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                torontoData << torontoDatatest.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                torontoData << torontoDatatest.at(2);
            }
            ++barsAdded;


            myBars8->setData(valueYears, torontoData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();
        }


        //! Plot data and create a bar graph for Winnipeg if this city is selected
        if (ui->winnipeg->isChecked()) {
            QCPBars *myBars9 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars9->setWidth(barWidth);
            myBars9->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars9->setName("Winnipeg");

            ui->customPlot->addPlottable(myBars9);
            //! Sudbury data
            QVector<double> winnipegDatatemp = stub->getData("Winnipeg");
            QVector<double> winnipegData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                winnipegData << winnipegDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                winnipegData << winnipegDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                winnipegData << winnipegDatatemp.at(2);
            }

            ++barsAdded;


            myBars9->setData(valueYears, winnipegData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();
        }

        //! Plot data and create a bar graph for Windsor if this city is selected
        if (ui->windsor->isChecked()) {
            QCPBars *myBars10 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
            myBars10->setWidth(barWidth);
            myBars10->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded))));
            myBars10->setName("Windor");

            ui->customPlot->addPlottable(myBars10);
            //! Sudbury data
            QVector<double> windsorDatatemp = stub->getData("Windsor");
            QVector<double> windsorData;
            QVector<double> valueYears;

            offset = (barWidth*barsAdded)+(barWidth/2);

            /*!
                Checks which years are checked.  Plots the years selected, and scales the graph accordingly.
              */
            if(ui->twoThousandNine->isChecked())
            {
                valueYears << 2009-setBack+offset;
                windsorData << windsorDatatemp.at(0);
            }
            if(ui->twoThousandTen->isChecked())
            {
                valueYears << 2010-setBack+offset;
                windsorData << windsorDatatemp.at(1);
            }
            if(ui->twoThousandEleven->isChecked())
            {
                valueYears << 2011-setBack+offset;
                windsorData << windsorDatatemp.at(2);
            }

            ++barsAdded;


            myBars10->setData(valueYears, windsorData);

            ui->customPlot->rescaleAxes();
            ui->customPlot->replot();
        }
}
Esempio n. 9
0
/**
 * @brief TimerWindow::slotUpdateVerticalPlot 更新纵向绘图槽
 * @param data 数据
 * @param labels 文本
 */
void TimerWindow::slotUpdateVerticalPlot(QVector<double> &data, QVector<QString> &labels)
{
    qDebug()<<"slotUpdateVerticalPlot";
    delete(customPlot);
    customPlot = new QCustomPlot();
    customPlot->setFixedSize(500, 250);
    vLayoutMain->addWidget(customPlot);

    //只取labels的month/day
    QDate tmpDate;
    for(int index = 0; index < labels.size(); ++index){
//        qDebug()<<"before"<<labels.at(index);
        tmpDate = QDate::fromString(labels.at(index),"yyyy-MM-dd");
        labels.replace(index, QString::number(tmpDate.month())+"/"+QString::number(tmpDate.day()));
//        qDebug()<<"after"<<labels.at(index);
    }

    // create empty bar chart objects:
    QCPBars *regen = new QCPBars(customPlot->xAxis, customPlot->yAxis);
    customPlot->addPlottable(regen);

    // set names and colors:
    QPen pen;
    regen->setName("Regenerative");
    pen.setColor(QColor("#D26079"));
    regen->setPen(pen);
    regen->setBrush(QColor("#D26079"));

    QVector<double> ticks;
    double maxValue = 0;
    //查找最大值
    for(int i = 0; i < labels.size(); i++){
        ticks << i + 1;
        maxValue = maxValue > data.at(i) ? maxValue : data.at(i);
    }
    customPlot->xAxis->setAutoTicks(false);
    customPlot->xAxis->setAutoTickLabels(false);
    customPlot->xAxis->setTickVector(ticks);
    customPlot->xAxis->setTickVectorLabels(labels);
    customPlot->xAxis->setTickLabelRotation(0);
    customPlot->xAxis->setSubTickCount(0);
    customPlot->xAxis->setTickLength(0, 4);
    customPlot->xAxis->grid()->setVisible(true);
    customPlot->xAxis->setRange(0, ticks.size() + 1);
    customPlot->xAxis->setLabel("日期");

    // prepare y axis:
    customPlot->yAxis->setRange(0, maxValue + maxValue / 10);
    customPlot->yAxis->setPadding(5); // a bit more space to the left border
    customPlot->yAxis->setLabel("时长 (小时)");
    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);

/*
    // setup legend:
    customPlot->legend->setVisible(false);
    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->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
*/

    regen->setData(ticks, data);
    customPlot->replot();

//    for(int i=0; i < labels.size(); i++){
//        qDebug()<<data.at(i)<<labels.at(i);
//    }
    qDebug()<<"slotUpdateVerticalPlot end";
}
void CPerformance::graphColors(QCustomPlot *customPlot)
{
    QVector<double> datax = QVector<double>() << 1 << 2 << 3 << 4  << 5;

    customPlot->clearPlottables();

//    QCPPlotTitle *title = new QCPPlotTitle(customPlot, "Colors Performance");

//    ///To print only one time the title
//    if(customPlot->plotLayout()->rowCount() < 2)
//    {
//        customPlot->plotLayout()->insertRow(0);
//    }

//    title->setTextColor(QColor(255, 255, 255));
//    customPlot->plotLayout()->addElement(0, 0, title);

    QCPBarsGroup *group1 = new QCPBarsGroup(customPlot);
    QCPBars *bars = new QCPBars(customPlot->xAxis, customPlot->yAxis);

    customPlot->addPlottable(bars);
    bars->setData(datax, blueRights);
    bars->setBrush(QColor(25, 115, 215, 50));
    bars->setPen(QColor(25, 115, 215));
    bars->setWidth(0.15);

    group1->insert(1, bars);
//        bars->setBarsGroup(group1);
    bars->setName("Blue");
//        customPlot->plottable(0)->setName("squareRights");

    bars = new QCPBars(customPlot->xAxis, customPlot->yAxis);

    customPlot->addPlottable(bars);
    bars->setData(datax,redRights);
    bars->setBrush(QColor(240, 0, 0, 50));
    bars->setPen(QColor(240, 0, 0));
    bars->setWidth(0.15);

    group1->insert(2,bars);
//        bars->setBarsGroup(group1);
    bars->setName("Red");

    bars = new QCPBars(customPlot->xAxis, customPlot->yAxis);

    customPlot->addPlottable(bars);
    bars->setData(datax, greenRights);
    bars->setBrush(QColor(30, 210, 60, 50));
    bars->setPen(QColor(30, 210, 60));
    bars->setWidth(0.15);

    group1->insert(3,bars);
//        bars->setBarsGroup(group1);
    bars->setName("Green");

    bars = new QCPBars(customPlot->xAxis, customPlot->yAxis);

    customPlot->addPlottable(bars);
    bars->setData(datax, yellowRights);
    bars->setBrush(QColor(240, 230, 0, 50));
    bars->setPen(QColor(240, 230, 0));
    bars->setWidth(0.15);

    group1->insert(4,bars);
//        bars->setBarsGroup(group1);
    bars->setName("Yellow");

    bars = new QCPBars(customPlot->xAxis, customPlot->yAxis);

    customPlot->addPlottable(bars);
    bars->setData(datax, blackRights);
    bars->setBrush(QColor(0, 0, 0, 50));
    bars->setPen(QColor(0, 0, 0));
    bars->setWidth(0.15);

    group1->insert(5,bars);
//        bars->setBarsGroup(group1);
    bars->setName("Black");

    customPlot->legend->setVisible(true);
    customPlot->replot();
}
 void GraphHelper::graphSumAmtVsDate(QCustomPlot* plot, std::vector<std::vector<std::string> > &results)
 {
     switch(typeGraph)
     {
     case 0: //Bar graph
     {
         //Initialize myBars
         QCPBars *myBars = new QCPBars(plot->xAxis, plot->yAxis);

         plot->addPlottable(myBars);

         //create the array that will hold the summed amounts for each year
         double* barAmount = new double[numYears];
         for(int i=0; i<numYears;i++){
             barAmount[i] = 0;
         }
         getData(barAmount,results);

         QVector<QString> xLabels;
         QVector<double> years, yValues;

         for (int i = earliest,k = 0,t=0;i<=latest;i++,k++)
         {
             //TODO: add option for user to choose bShowEmptyData(button on ui maybe)
             //only adds the year to the graph if it has an amount
             if(bShowEmptyData || barAmount[k] != 0)
             {
                 //creates the bars and its associated data
                 yValues << barAmount[k];
                 xLabels << QString::number(i);
                 years << t++;
                 numYears = t;
             }
         }
         //Modify properties of myBars:
         myBars->setData(years, yValues);

         //settings for the x and y axis
         plot->rescaleAxes();
         setYAxis(plot);
         setYAxisTitle(plot);
         setXAxis(plot, xLabels,years);

         plot->replot();

         free(barAmount);
         break;
     }
     case 1:
     {
         plot->addGraph();
         plot->graph()->setLineStyle(QCPGraph::lsLine);
         QPen pen;
         pen.setColor(QColor(Qt::blue));
         pen.setWidth(2.5);
         plot->graph()->setPen(pen);

         //create the array that will hold the summed amounts for each year
         double* amount = new double[numYears];
         for(int i=0; i<numYears;i++){
             amount[i] = 0;
         }
         getData(amount,results);

         QVector<QString> xLabels;
         QVector<double> years, yValues;
         for (int i = earliest,k = 0,t=0;i<=latest;i++,k++)
         {
             //TODO: Maybe add option for user to choose bShowEmptyData(button on ui)
             //only adds the year to the graph if it has an amount
             if(bShowEmptyData || amount[k] != 0)
             {
                 //creates the bars and its associated data
                 yValues << amount[k];
                 xLabels << QString::number(i);
                 years << t++;
                 numYears = t;
             }
         }
         //add data to graph
         plot->graph()->setData(years, yValues);
         plot->rescaleAxes();

         //format x and y axis
         setXAxis(plot,xLabels,years);
         setYAxis(plot);
         setYAxisTitle(plot);
         plot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 2));


         plot->replot();
         free(amount);
         break;
     }
     default:
         break;

     }
 }
Esempio n. 12
0
void chartcreate::repaintplot()
{
    QCustomPlot * customPlot = ui->chart_preview;
    // create empty bar chart objects:

    QCPBars *regen = new QCPBars(customPlot->xAxis, customPlot->yAxis);
    QCPBars *nuclear = new QCPBars(customPlot->xAxis, customPlot->yAxis);
    QCPBars *fossil = new QCPBars(customPlot->xAxis, customPlot->yAxis);
    customPlot->addPlottable(regen);
    customPlot->addPlottable(nuclear);
    customPlot->addPlottable(fossil);
    // set names and colors:
    QPen pen;
    pen.setWidthF(1.2);
    fossil->setName("Danone");
    pen.setColor(QColor(255, 131, 0));
    fossil->setPen(pen);
    fossil->setBrush(QColor(255, 131, 0, 50));
    nuclear->setName("AuBonLait");
    pen.setColor(QColor(1, 92, 191));
    nuclear->setPen(pen);
    nuclear->setBrush(QColor(1, 92, 191, 50));
    regen->setName("Yoplait");
    pen.setColor(QColor(150, 222, 0));
    regen->setPen(pen);
    regen->setBrush(QColor(150, 222, 0, 70));
    // stack bars ontop of each other:
    nuclear->moveAbove(fossil);
    regen->moveAbove(nuclear);

    // prepare x axis with country labels:
    QVector<double> ticks;
    QVector<QString> labels;
    ticks << 1 << 2 ;
    labels << "Homme" << "Femme" ;
    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, 8);

    // prepare y axis:
    customPlot->yAxis->setRange(0, 12.1);
    customPlot->yAxis->setPadding(5); // a bit more space to the left border
    customPlot->yAxis->setLabel("Marque de Yaourt Connu");
    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);

    // Add data:
    QVector<double> fossilData, nuclearData, regenData;
    fossilData  << 0.86*10.5 << 0.83*5.5;
    nuclearData << 0.08*10.5 << 0.12*5.5;
    regenData   << 0.06*10.5 << 0.05*5.5;
    fossil->setData(ticks, fossilData);
    nuclear->setData(ticks, nuclearData);
    regen->setData(ticks, regenData);

    // 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->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
}
Esempio n. 13
0
void PlottingDialog::drawRGBHistogram(QImage *img){
    QCPBars *rBar = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    QCPBars *gBar = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    QCPBars *bBar = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    ui->customPlot->addPlottable(rBar);
    ui->customPlot->addPlottable(gBar);
    ui->customPlot->addPlottable(bBar);
    int bins = 16;
    QVector<double> keyRData(bins);
    QVector<double> valueRData(bins, 0);
    QVector<double> keyGData(bins);
    QVector<double> valueGData(bins, 0);
    QVector<double> keyBData(bins);
    QVector<double> valueBData(bins, 0);
    QColor currentPixel;
    int currentRed, currentGreen, currentBlue;
    // now we can modify properties of myBars:
    for(int x=0;x<img->width();x++){
        for(int y=0;y<img->height();y++){
            currentPixel = QColor(img->pixel(x,y));
            currentRed = currentPixel.redF() * bins;
            valueRData[(currentRed == bins) ? bins - 1 : currentRed]++;
            currentGreen = currentPixel.greenF() * bins;
            valueGData[(currentGreen == bins) ? bins - 1 : currentGreen]++;
            currentBlue = currentPixel.blueF() * bins;
            valueBData[(currentBlue == bins) ? bins - 1 : currentBlue]++;
        }
    }
    rBar->setName("R Value");
    rBar->setBrush(QBrush(Qt::red));
    gBar->setName("G Value");
    gBar->setBrush(QBrush(Qt::green));
    bBar->setName("B Value");
    bBar->setBrush(QBrush(Qt::blue));
    int totalPix = img->width() * img->height();
    for(int i = 0;i<bins;i++){
        keyRData[i] = (i/(double) bins);
        keyGData[i] = (i/(double) bins);
        keyBData[i] = (i/(double) bins);
        valueRData[i] = valueRData[i] / (double)totalPix;
        valueGData[i] = valueGData[i] / (double)totalPix;
        valueBData[i] = valueBData[i] / (double)totalPix;
    }
    rBar->setData(keyRData, valueRData);
    gBar->setData(keyGData, valueGData);
    bBar->setData(keyBData, valueBData);
    ui->customPlot->legend->setVisible(true);
    ui->customPlot->xAxis->setLabel("Color %");
    ui->customPlot->xAxis->setRange(0,1);
    rBar->setWidth(1/(4*(double)bins));
    gBar->setWidth(1/(4*(double)bins));
    bBar->setWidth(1/(4*(double)bins));
    ui->customPlot->yAxis->setLabel("Image %");
    ui->customPlot->yAxis->setRange(0,1);
    ui->customPlot->replot();
    qDebug() << "Replotting";
}
 void GraphHelper::graphAmtByType(QCustomPlot* plot, std::vector<std::vector<std::string>> &results)
 {
     switch(typeGraph)
     {
     case 0:
     {
         //Initialize myBars
         QCPBars *myBars = new QCPBars(plot->xAxis, plot->yAxis);

         plot->addPlottable(myBars);

         //create the array that will hold the summed amounts for each year
         double amount[250]= {0};
         QVector<QString> xLabels = getData(amount,results);

         QVector<double> years, yValues;
         int maxYVal = 0;
         for (int k = 0,t=0;k<25;k++)
         {
             //only adds the year to the graph if it has an amount
             if(bShowEmptyData || amount[k] != 0)
             {
                 //creates the bars and its associated data
                 yValues << amount[k];
                 //used to set the y axis range
                 if(maxYVal < amount[k])
                     maxYVal = amount[k];
                 years << t++;
                 numYears = t;
             }
         }

         //Modify properties of myBars:
         myBars->setData(years, yValues);

         //settings for the x and y axis
         plot->rescaleAxes();
         setYAxis(plot);
         setYAxisTitle(plot);
         setXAxis(plot, xLabels,years);
         plot->yAxis->setRange(0, maxYVal+0.5);
         plot->xAxis->setRange(-0.5, numYears-0.5);
         if(graphChoice == 7)
             plot->xAxis->setLabel("Name");
         else
            plot->xAxis->setLabel(QString::number(dateChoice));

         plot->replot();

         break;
     }
     case 1:
     {
         plot->addGraph();
         plot->graph()->setLineStyle(QCPGraph::lsLine);
         QPen pen;
         pen.setColor(QColor(Qt::blue));

         pen.setWidth(2.5);
         plot->graph()->setPen(pen);

         //create the array that will hold the summed amounts for each year
         double amount[250]= {0};
         QVector<QString> xLabels = getData(amount,results);

         QVector<double> years, yValues;
         int maxYVal = 0;
         for (int k = 0,t=0;k<25;k++)
         {
             //only adds the year to the graph if it has an amount
             if(bShowEmptyData || amount[k] != 0)
             {
                 //creates the bars and its associated data
                 yValues << amount[k];
                 //used to set the y axis range
                 if(maxYVal < amount[k])
                     maxYVal = amount[k];
                 years << t++;
                 numYears = t;
             }
         }
         //add data to graph
         plot->graph()->setData(years, yValues);
         plot->graph()->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, 5));
         plot->rescaleAxes();

         //format x and y axis
         setXAxis(plot,xLabels,years);
         setYAxis(plot);
         setYAxisTitle(plot);
         plot->yAxis->setRange(0, maxYVal+0.5);
         plot->xAxis->setRange(-0.5, numYears-0.5);
         if(graphChoice == 7)
             plot->xAxis->setLabel("Name");
         else
             plot->xAxis->setLabel(QString::number(dateChoice));

         plot->replot();
         break;
     }
   }
 }
DrawFinancialChart::DrawFinancialChart(QWidget *parent) :
    QCustomPlot(parent)
{
    resize(600,400);

    legend->setVisible(true);

    // generate two sets of random walk data (one for candlestick and one for ohlc chart):
    int n = 500;
    QVector<double> time(n), value1(n), value2(n);
    QDateTime start = QDateTime(QDate(2014, 6, 11));
    start.setTimeSpec(Qt::UTC);
    double startTime = start.toTime_t();
    double binSize = 3600*24; // bin data in 1 day intervals
    time[0] = startTime;
    value1[0] = 60;
    value2[0] = 20;
    qsrand(9);
    for (int i=1; i<n; ++i)
    {
      time[i] = startTime + 3600*i;
      value1[i] = value1[i-1] + (qrand()/(double)RAND_MAX-0.5)*10;
      value2[i] = value2[i-1] + (qrand()/(double)RAND_MAX-0.5)*3;
    }

    // create candlestick chart:
    QCPFinancial *candlesticks = new QCPFinancial(xAxis, yAxis);
    addPlottable(candlesticks);
    QCPFinancialDataMap data1 = QCPFinancial::timeSeriesToOhlc(time, value1, binSize, startTime);
    candlesticks->setName("Candlestick");
    candlesticks->setChartStyle(QCPFinancial::csCandlestick);
    candlesticks->setData(&data1, true);
    candlesticks->setWidth(binSize*0.9);
    candlesticks->setTwoColored(true);
    candlesticks->setBrushPositive(QColor(245, 245, 245));
    candlesticks->setBrushNegative(QColor(0, 0, 0));
    candlesticks->setPenPositive(QPen(QColor(0, 0, 0)));
    candlesticks->setPenNegative(QPen(QColor(0, 0, 0)));

    // create ohlc chart:
    QCPFinancial *ohlc = new QCPFinancial(xAxis, yAxis);
    addPlottable(ohlc);
    QCPFinancialDataMap data2 = QCPFinancial::timeSeriesToOhlc(time, value2, binSize/3.0, startTime); // divide binSize by 3 just to make the ohlc bars a bit denser
    ohlc->setName("OHLC");
    ohlc->setChartStyle(QCPFinancial::csOhlc);
    ohlc->setData(&data2, true);
    ohlc->setWidth(binSize*0.2);
    ohlc->setTwoColored(true);

    // create bottom axis rect for volume bar chart:
    QCPAxisRect *volumeAxisRect = new QCPAxisRect(this);
    plotLayout()->addElement(1, 0, volumeAxisRect);
    volumeAxisRect->setMaximumSize(QSize(QWIDGETSIZE_MAX, 100));
    volumeAxisRect->axis(QCPAxis::atBottom)->setLayer("axes");
    volumeAxisRect->axis(QCPAxis::atBottom)->grid()->setLayer("grid");
    // bring bottom and main axis rect closer together:
    plotLayout()->setRowSpacing(0);
    volumeAxisRect->setAutoMargins(QCP::msLeft|QCP::msRight|QCP::msBottom);
    volumeAxisRect->setMargins(QMargins(0, 0, 0, 0));
    // create two bar plottables, for positive (green) and negative (red) volume bars:
    QCPBars *volumePos = new QCPBars(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atLeft));
    QCPBars *volumeNeg = new QCPBars(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atLeft));
    for (int i=0; i<n/5; ++i)
    {
      int v = qrand()%20000+qrand()%20000+qrand()%20000-10000*3;
      (v < 0 ? volumeNeg : volumePos)->addData(startTime+3600*5.0*i, qAbs(v)); // add data to either volumeNeg or volumePos, depending on sign of v
    }
    setAutoAddPlottableToLegend(false);
    addPlottable(volumePos);
    addPlottable(volumeNeg);
    volumePos->setWidth(3600*4);
    volumePos->setPen(Qt::NoPen);
    volumePos->setBrush(QColor(100, 180, 110));
    volumeNeg->setWidth(3600*4);
    volumeNeg->setPen(Qt::NoPen);
    volumeNeg->setBrush(QColor(180, 90, 90));

    // interconnect x axis ranges of main and bottom axis rects:
    connect(xAxis, SIGNAL(rangeChanged(QCPRange)), volumeAxisRect->axis(QCPAxis::atBottom), SLOT(setRange(QCPRange)));
    connect(volumeAxisRect->axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), xAxis, SLOT(setRange(QCPRange)));
    // configure axes of both main and bottom axis rect:
    volumeAxisRect->axis(QCPAxis::atBottom)->setAutoTickStep(false);
    volumeAxisRect->axis(QCPAxis::atBottom)->setTickStep(3600*24*4); // 4 day tickstep
    volumeAxisRect->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime);
    volumeAxisRect->axis(QCPAxis::atBottom)->setDateTimeSpec(Qt::UTC);
    volumeAxisRect->axis(QCPAxis::atBottom)->setDateTimeFormat("dd. MMM");
    volumeAxisRect->axis(QCPAxis::atBottom)->setTickLabelRotation(15);
    volumeAxisRect->axis(QCPAxis::atLeft)->setAutoTickCount(3);
    xAxis->setBasePen(Qt::NoPen);
    xAxis->setTickLabels(false);
    xAxis->setTicks(false); // only want vertical grid in main axis rect, so hide xAxis backbone, ticks, and labels
    xAxis->setAutoTickStep(false);
    xAxis->setTickStep(3600*24*4); // 4 day tickstep
    rescaleAxes();
    xAxis->scaleRange(1.025, xAxis->range().center());
    yAxis->scaleRange(1.1, yAxis->range().center());

    // make axis rects' left side line up:
    QCPMarginGroup *group = new QCPMarginGroup(this);
    axisRect()->setMarginGroup(QCP::msLeft|QCP::msRight, group);
    volumeAxisRect->setMarginGroup(QCP::msLeft|QCP::msRight, group);
}
Esempio n. 16
0
void YarrGui::detachPlot(){
    if(ui->plotTree->currentItem() == nullptr){
        std::cerr << "Please select plot to detach...\n";
        return;
    }
    if(ui->plotTree->currentItem()->childCount() > 0){
        std::cerr << "Please select plot to detach...\n";
        return;
    }

    PlotDialog * myPDiag = new PlotDialog();
    QCustomPlot * plotWidget = dynamic_cast<QCustomPlot*>(ui->scanPlots_tabWidget->currentWidget());
    if(plotWidget == nullptr){
        std::cerr << "Severe cast error. Aborting...\n";
        return;
    }

    QCustomPlot * transferPlot = dynamic_cast<QCustomPlot*>(myPDiag->childAt(10, 10));
    if(transferPlot == nullptr){
        std::cerr << "Severe cast error. Aborting...\n";
        return;
    }

    QCPPlotTitle * widgetPT = dynamic_cast<QCPPlotTitle*>(plotWidget->plotLayout()->element(0, 0));
    if(widgetPT == nullptr){
        std::cerr << "Severe cast error. Aborting... \n";
        return;
    }

    if(dynamic_cast<QCPColorMap*>(plotWidget->plottable(0)) != nullptr){
        QCPColorMap * widgetCMap = dynamic_cast<QCPColorMap*>(plotWidget->plottable(0));

        QCPColorScale * widgetCScale = dynamic_cast<QCPColorScale*>(plotWidget->plotLayout()->element(1, 1));
        if(widgetCScale == nullptr) {
            std::cerr << "Severe cast error. Aborting... \n";
            return;
        }

        transferPlot->plotLayout()->insertRow(0);
        transferPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(transferPlot, widgetPT->text()));

        QCPColorMap * transferCMap = new QCPColorMap(transferPlot->xAxis, transferPlot->yAxis);
        transferPlot->addPlottable(transferCMap);
        transferCMap->data()->setSize(80, 336);
        transferCMap->setData(widgetCMap->data(), true);
        QCPColorScale * transferCScale = new QCPColorScale(transferPlot);
        transferPlot->plotLayout()->addElement(1, 1, transferCScale);
        transferCScale->setType(QCPAxis::atRight);
        transferCMap->setColorScale(transferCScale);
        transferCMap->keyAxis()->setLabel(widgetCMap->keyAxis()->label());
        transferCMap->valueAxis()->setLabel(widgetCMap->valueAxis()->label());

        transferCScale->axis()->setLabel(widgetCScale->axis()->label());
        transferCMap->setGradient(QCPColorGradient::gpPolar);
        transferCMap->rescaleDataRange();
    }else if(dynamic_cast<QCPBars*>(plotWidget->plottable(0)) != nullptr){
        QCPBars * widgetBars = dynamic_cast<QCPBars*>(plotWidget->plottable(0));

        QCPBars * transferBars = new QCPBars(transferPlot->xAxis, transferPlot->yAxis);
        transferBars->setData(widgetBars->data(), true);
        transferBars->rescaleAxes();

        transferPlot->plotLayout()->insertRow(0);
        transferPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(transferPlot, widgetPT->text()));
        transferBars->keyAxis()->setLabel(widgetBars->keyAxis()->label());
        transferBars->valueAxis()->setLabel(widgetBars->valueAxis()->label());
    }else{
        std::cerr << "Severe cast error. Aborting... \n";                       //DEBUG
        return;
    }

    transferPlot->rescaleAxes();
    transferPlot->replot();

    myPDiag->setModal(false);
    myPDiag->show();

    removePlot();

    return;
}
Esempio n. 17
0
void YarrGui::doScan(QString qn){
    std::ofstream *tmpOfCout = new std::ofstream("deleteMeCout.txt");
    std::streambuf *coutBuf = std::cout.rdbuf(tmpOfCout->rdbuf());
    std::ofstream *tmpOfCerr = new std::ofstream("deleteMeCerr.txt");
    std::streambuf *cerrBuf = std::cerr.rdbuf(tmpOfCerr->rdbuf());

    int N = ui->feTree->topLevelItemCount();
    int M = scanVec.size();
    for(int j = 0; j < N; j++){
        scanDone = false;
        processorDone = false;

        if(!(ui->feTree->topLevelItem(j)->child(4)->checkState(1))){continue;} //Is the Scan checkbox checked?

        Fei4 * fe = dynamic_cast<Fei4*>(bk->feList.at(j));

        ScanBase * s = nullptr;

        if(qn == "NS")   {s = new Fei4NoiseScan(bk);}
        if(qn == "DS")   {s = new Fei4DigitalScan(bk);}
        if(qn == "AS")   {s = new Fei4AnalogScan(bk);}
        if(qn == "TS")   {s = new Fei4ThresholdScan(bk);}
        if(qn == "ToTS") {s = new Fei4TotScan(bk);}
        if(qn == "GTT")  {s = new Fei4GlobalThresholdTune(bk);}
        if(qn == "GPT")  {s = new Fei4GlobalPreampTune(bk);}
        if(qn == "PTT")  {s = new Fei4PixelThresholdTune(bk);}
        if(qn == "PPT")  {s = new Fei4PixelPreampTune(bk);}
        if(qn == "CS")   {s = &cs;}

        if(s == nullptr){
            std::cerr << "Invalid scan QString parameter passed or scan object construction failed. Returning...\n";
            return;
        }

        QTreeWidgetItem * plotTreeItem = nullptr; //Plot tree item for current FE
        for(int k = 0; k < ui->plotTree->topLevelItemCount(); k++){ //Is the current FE already in the tree? ...
           if(ui->plotTree->topLevelItem(k)->text(0) == ui->feTree->topLevelItem(j)->text(0)){
               plotTreeItem = ui->plotTree->topLevelItem(k);
               break;
           }
        }

        if(plotTreeItem == nullptr){ //... if not: create a branch for it
            plotTreeItem = new QTreeWidgetItem(ui->plotTree);
            plotTreeItem->setText(0, ui->feTree->topLevelItem(j)->text(0));
        }

        QTreeWidgetItem * plotTreeItemDS = new QTreeWidgetItem(); //plot tree item for current scan
        plotTreeItemDS->setText(0, qn);
        plotTreeItem->addChild(plotTreeItemDS);

        fe->histogrammer = new Fei4Histogrammer();
        fe->histogrammer->connect(fe->clipDataFei4, fe->clipHisto);

        fe->ana = new Fei4Analysis(bk, fe->getRxChannel());
        fe->ana->connect(s, fe->clipHisto, fe->clipResult);

        if (qn=="CS"){
            CustomScan * tmp;
            tmp = dynamic_cast<CustomScan*>(s);
            if(tmp->bA.at(OCC_MAP) == true)   {fe->histogrammer->addHistogrammer(new OccupancyMap());}
            if(tmp->bA.at(TOT_MAP) == true)   {fe->histogrammer->addHistogrammer(new TotMap());}
            if(tmp->bA.at(TOT_2_MAP) == true) {fe->histogrammer->addHistogrammer(new Tot2Map());}

            if(tmp->bA.at(OCC_ANA) == true)   {fe->ana->addAlgorithm(new OccupancyAnalysis());}
            if(tmp->bA.at(NOISE_ANA) == true) {fe->ana->addAlgorithm(new NoiseAnalysis());}
            if(tmp->bA.at(TOT_ANA) == true)   {fe->ana->addAlgorithm(new TotAnalysis());}
            if(tmp->bA.at(S_CU_FIT) == true)  {fe->ana->addAlgorithm(new ScurveFitter());}
            if(tmp->bA.at(PIX_THR) == true)   {fe->ana->addAlgorithm(new OccPixelThresholdTune);}
        }else{
            fe->histogrammer->addHistogrammer(new OccupancyMap());

            if (qn == "ToTS" || qn == "GPT" || qn == "PPT"){
                fe->histogrammer->addHistogrammer(new TotMap());
                fe->histogrammer->addHistogrammer(new Tot2Map());
            }

            if(qn == "NS")   {fe->ana->addAlgorithm(new NoiseAnalysis());}
            if(qn == "DS")   {fe->ana->addAlgorithm(new OccupancyAnalysis());}
            if(qn == "AS")   {fe->ana->addAlgorithm(new OccupancyAnalysis());}
            if(qn == "TS")   {fe->ana->addAlgorithm(new ScurveFitter());}
            if(qn == "ToTS") {fe->ana->addAlgorithm(new TotAnalysis());}
            if(qn == "GTT")  {fe->ana->addAlgorithm(new OccGlobalThresholdTune());}
            if(qn == "GPT")  {fe->ana->addAlgorithm(new TotAnalysis());}
            if(qn == "PTT")  {fe->ana->addAlgorithm(new OccPixelThresholdTune());}
            if(qn == "PPT")  {fe->ana->addAlgorithm(new TotAnalysis());}
        }

        s->init();
        ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //1
        s->preScan();
        ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //2

        unsigned int numThreads = std::thread::hardware_concurrency();
        //std::cout << "-> Starting " << numThreads << " processor Threads:" << std::endl;
        std::vector<std::thread> procThreads;
        for (unsigned i=0; i<numThreads; i++){
            procThreads.push_back(std::thread(process, bk, &scanDone));
            //std::cout << "  -> Processor thread #" << i << " started!" << std::endl;
        }

        std::vector<std::thread> anaThreads;
        //std::cout << "-> Starting histogrammer and analysis threads:" << std::endl;
        if (fe->isActive()){
            anaThreads.push_back(std::thread(analysis, fe->histogrammer, fe->ana, &processorDone));
            //std::cout << "  -> Analysis thread of Fe " << fe->getRxChannel() << std::endl;
        }

        s->run();
        ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //3
        s->postScan();
        ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //4
        scanDone = true;

        for (unsigned i=0; i<numThreads; i++){
            procThreads[i].join();
        }
        ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //5

        processorDone = true;

        for(unsigned i=0; i<anaThreads.size(); i++){
            anaThreads[i].join();
        }
        ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //6

        if(qn != "CS") {
            delete s;
        }

//        fe->toFileBinary();
//        fe->ana->plot("Scan_GUI");

        //DEBUG begin [plotting]

        //clear raw data
        while(fe->clipDataFei4->size() != 0){
            fe->clipDataFei4->popData();
        }

        //clear raw data
        while(fe->clipHisto->size() != 0){
            fe->clipHisto->popData();
        }

        while(fe->clipResult->size() != 0){
            HistogramBase * showMe = fe->clipResult->popData();

            //Add tab to plot tab widget
            QCustomPlot * tabScanPlot = new QCustomPlot(ui->scanPlots_tabWidget); // X
            QWidget * addToTabWidget = dynamic_cast<QWidget*>(tabScanPlot);
            QString newTabName = qn + ' ' + ui->feTree->topLevelItem(j)->text(0);
            ui->scanPlots_tabWidget->addTab(addToTabWidget, newTabName);

            //Add plot to scan tree
            QTreeWidgetItem * plotTreeItemP = new QTreeWidgetItem(plotTreeItemDS); // X
            plotTreeItemP->setText(0, "Plot " + QString::number(plotTreeItemDS->childCount())
                                              + " (" + QString::fromStdString(showMe->getName()) + ")");
            plotTreeItemDS->addChild(plotTreeItemP);

            if(dynamic_cast<Histo2d*>(showMe) != nullptr){
                Histo2d * myHist2d = dynamic_cast<Histo2d*>(showMe);
                //Create plot

                QCPColorMap * colorMap = new QCPColorMap(tabScanPlot->xAxis, tabScanPlot->yAxis);
                QCPColorScale * colorScale = new QCPColorScale(tabScanPlot);

                tabScanPlot->addPlottable(colorMap);
                tabScanPlot->plotLayout()->insertRow(0);
                tabScanPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(tabScanPlot, QString::fromStdString(myHist2d->getName())));

                colorMap->setName(QString::fromStdString(myHist2d->getName()));
                colorMap->data()->setSize(80, 336);
                colorMap->data()->setRange(QCPRange(0, 80), QCPRange(0, 336));
                colorMap->keyAxis()->setLabel(QString::fromStdString(myHist2d->getXaxisTitle()));
                colorMap->valueAxis()->setLabel(QString::fromStdString(myHist2d->getYaxisTitle()));
                for(int xCoord = 0; xCoord<80; xCoord++){
                    for(int yCoord = 0; yCoord<336; yCoord++){
                        double colVal = myHist2d->getBin(yCoord + 336*xCoord);              //TODO make better
                        colorMap->data()->setCell(xCoord, yCoord, colVal);
                    }
                }

                tabScanPlot->plotLayout()->addElement(1, 1, colorScale);
                colorScale->setType(QCPAxis::atRight);
                colorMap->setColorScale(colorScale);
                colorScale->axis()->setLabel(QString::fromStdString(myHist2d->getZaxisTitle()));
                colorMap->setGradient(QCPColorGradient::gpPolar);
                colorMap->rescaleDataRange();

            }else if(dynamic_cast<Histo1d*>(showMe) != nullptr){
                Histo1d * myHist1d = dynamic_cast<Histo1d*>(showMe);

                QCPBars * myBars = new QCPBars(tabScanPlot->xAxis, tabScanPlot->yAxis);
                tabScanPlot->addPlottable(myBars);
                myBars->setName(QString::fromStdString(myHist1d->getName()));

                for(unsigned int i = 0; i < myHist1d->size(); i++) {
                    myBars->addData((double)(i+1), myHist1d->getBin(i));
                }

                myBars->rescaleAxes();
                tabScanPlot->plotLayout()->insertRow(0);
                tabScanPlot->plotLayout()->addElement(0, 0, new QCPPlotTitle(tabScanPlot, QString::fromStdString(myHist1d->getName())));
                myBars->keyAxis()->setLabel(QString::fromStdString(myHist1d->getXaxisTitle()));
                myBars->valueAxis()->setLabel(QString::fromStdString(myHist1d->getYaxisTitle()));

            }else{
                std::cerr << "Correct plot type not found or severe cast error\n";                  //DEBUG
                return;
            }

            tabScanPlot->rescaleAxes();
            tabScanPlot->replot();
        }
        ui->scanProgressBar->setValue(ui->scanProgressBar->value() + (int)(100.0/(7.0*N*M))); //7
        delete fe->histogrammer;
        fe->histogrammer = nullptr;
        delete fe->ana;
        fe->ana = nullptr;
    }

    std::cout.rdbuf(coutBuf);
    std::cerr.rdbuf(cerrBuf);
    tmpOfCout->close();
    tmpOfCerr->close();

    std::ifstream tmpInCout("deleteMeCout.txt");
    std::ifstream tmpInCerr("deleteMeCerr.txt");
    std::cout << tmpInCout.rdbuf();
    std::cerr << tmpInCerr.rdbuf();
    tmpInCout.close();
    tmpInCerr.close();

    return;
}
/*
 * makePlot()
 *
 * This function deals with creating a fully modifable bar graph based on the totals
 * of the surveys. It fully sets up the graph with plottting, the legend, and anything related
 * with the graphing.
*/
void MainWindow::makePlot()
{
     ui -> customPlot->clearPlottables();

    // create empty bar chart objects:
    QCPBars *theoretical = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    QCPBars *actual = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    QCPBars *expected = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis);
    ui->customPlot->addPlottable(actual);
    ui->customPlot->addPlottable(expected);
    ui->customPlot->addPlottable(theoretical);

    // set names and colors:
    QPen pen;
    pen.setWidthF(1.2);

    theoretical ->setName("Personal Goal");
    pen.setColor(QColor(255, 131, 0));
    theoretical ->setPen(pen);
    theoretical ->setBrush(QColor(255, 131, 0, 50));

    actual->setName("Actual");
    pen.setColor(QColor(1, 92, 191));
    actual->setPen(pen);
    actual->setBrush(QColor(1, 92, 191, 50));

    expected->setName("Trainer Goal");
    pen.setColor(QColor(150, 222, 0));
    expected->setPen(pen);
    expected->setBrush(QColor(150, 222, 0, 50));

    // prepare x axis with labels:
    QVector<double> actual_ticks , expected_ticks, theoretical_ticks;
    QVector<QString> labels;
    actual_ticks<< 1 << 4 << 7 << 10 << 13;
    expected_ticks << 2 << 5 << 8 << 11 << 14;
    theoretical_ticks << 3 << 6 << 9 << 12 << 15;

    labels << "Prospect" << "PIE" << "FLI" << "PI" << "NCC";
    ui->customPlot->xAxis->setAutoTicks(false);
    ui->customPlot->xAxis->setAutoTickLabels(false);
    ui->customPlot->xAxis->setTickVector(actual_ticks);
    ui->customPlot->xAxis->setTickVectorLabels(labels);
    ui->customPlot->xAxis->setTickLabelRotation(50);
    ui->customPlot->xAxis->setSubTickCount(0);
    ui->customPlot->xAxis->setTickLength(0,5);
    ui->customPlot->xAxis->grid()->setVisible(true);
    ui->customPlot->xAxis->setRange(0, 16);

    // prepare y axis:
    if(actual_total[0] == 0)
        ui->customPlot->yAxis->setRange(0, 9);
    else
        ui->customPlot->yAxis->setRange(0, actual_total[0]+2);

    ui->customPlot->yAxis->setPadding(5);
    ui->customPlot->yAxis->setLabel("Total Surveys Completed");
    ui->customPlot->yAxis->grid()->setSubGridVisible(true);
    QPen gridPen;
    gridPen.setStyle(Qt::SolidLine);
    gridPen.setColor(QColor(0, 0, 0, 25));
    ui->customPlot->yAxis->grid()->setPen(gridPen);
    gridPen.setStyle(Qt::DotLine);
    ui->customPlot->yAxis->grid()->setSubGridPen(gridPen);

    // Add data points:
    QVector<double> theoreticalData, actualData, expectedData;

    theoreticalData << theoretical_total[0] << theoretical_total[1] << theoretical_total[2]<< theoretical_total[3] << theoretical_total[4];
    theoretical->setData(theoretical_ticks, theoreticalData);

    actualData << actual_total[0] << actual_total[1] << actual_total[2] << actual_total[3] << actual_total[4];
    actual->setData(actual_ticks, actualData);

    expectedData << expected_total[0] << expected_total[1] << expected_total[2] << expected_total[3] << expected_total[4];
    expected->setData(expected_ticks, expectedData);

    // setup legend:
    ui->customPlot->legend->setVisible(true);
    ui->customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignRight);
    ui->customPlot->legend->setBrush(QColor(255, 255, 255, 200));
    QPen legendPen;
    legendPen.setColor(QColor(130, 130, 130, 200));
    ui->customPlot->legend->setBorderPen(legendPen);
    QFont legendFont = font();
    legendFont.setPointSize(15);
    ui->customPlot->legend->setFont(legendFont);

}
Esempio n. 19
0
int BarPlot::plotOther()
{
	string dataType = Node->getFirst();

	// Get the types
	// Note the type is not always going to be the within the children of the node (depending on what node is passed)
	// It will be possible to pass in a different node (say a publication type node) when implemented
	vector<node*> types;
	if (Node->getParent() == NULL){
		vector<node*>* temptypes = Node->getChildren();
		for (int i = 0; i < temptypes->size(); i++){
			if (temptypes->at(i)->getSecond() > 0)
				types.push_back(temptypes->at(i));
		}
	}
	else{ types.push_back(Node);}

	// Grab Data and prepare x axis with (professor Name) labels:
	QVector<QString> labels;
	// Search for the prof names
	for (int i = 0; i < types.size(); i++){
		for (int j = 0; j < types.at(i)->getChildren()->size(); j++){
			QString name = QString::fromStdString(types.at(i)->getChildren()->at(j)->getFirst());
			if (!(labels.contains(name)))
				labels.push_back(name);
		}
	}

	// stacked bar chart can get cluttered, ensure no more than 30 different types
	// determine which types to push into an "Others" group
	vector<int> othersNdx;
	if (types.size() > COUNT_MAX){
		vector<double> typeSumCounts;
		for (int i = 0; i < types.size(); i++){
			if (Node->getFourth() > 0.0)
				typeSumCounts.push_back(types.at(i)->getFourth());
			else
				typeSumCounts.push_back(types.at(i)->getSecond());
		}
		while (types.size() - othersNdx.size() > COUNT_MAX){
			othersNdx.push_back(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin());
			typeSumCounts.at(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin()) = std::numeric_limits<double>::infinity();
		}
	}

	QVector<double> ticks;
	for (int i = 1; i <= labels.size(); i++)
		ticks.push_back(i);

	vector<QCPBars*> bars;
	QVector<double> othersCount(labels.size());
	double *othersData = othersCount.data();
	// create a new plottable area for each type, group everything within the "Others" group together
	for (int i = 0; i < types.size(); i++)
	{
		QVector<double> count(labels.size());
		double *data = count.data();
		// Note: not all types have same number of children (profs)
		// this would affect the labels (prof names)
		for (int j = 0; j < types.at(i)->getChildren()->size(); j++){
			int pos = labels.indexOf(QString::fromStdString(types.at(i)->getChildren()->at(j)->getFirst()));
			if (Node->getFourth() > 0.0)
				data[pos] = types.at(i)->getChildren()->at(j)->getFourth();
			else
				data[pos] = types.at(i)->getChildren()->at(j)->getSecond();
		}


		QCPBars *temp = new QCPBars(this->xAxis, this->yAxis);

		if (std::find(othersNdx.begin(), othersNdx.end(), i) != othersNdx.end()){
			for (int j = 0; j < labels.size(); j++)
				othersData[j] += count[j];
		}
		else{
			temp->setName(QString::fromStdString(types.at(i)->getFirst()));
			temp->setData(ticks, count);
			bars.push_back(temp);
			this->addPlottable(temp);
		}
	}
	// Graph "Others" only if there's something in it
	if (std::find(othersCount.begin(), othersCount.end(), (!0)) != othersCount.end()){
		QCPBars *temp = new QCPBars(this->xAxis, this->yAxis);
		temp->setName("Others");
		temp->setData(ticks, othersCount);
		bars.push_back(temp);
		this->addPlottable(temp);
	}
	// stack bars ontop of each other:
	// loop through each of the QCPBar objects in the list bars
	if (bars.size() > 1){
		for (int i = 0; i < (bars.size() - 1); i++)
			bars[i + 1]->moveAbove(bars[i]);
	}
	// set the colors
	QPen pen;
	pen.setWidthF(1.2);
	int C_HUE = 0;
	for (int i = 0; i < bars.size(); i++)
	{
		QColor color_brush, color_pen;
		color_brush.setHsv(C_HUE, BAR_SAT, BAR_VAL);
		color_brush.setAlpha(BAR_ALPHA);
		color_pen.setHsv(C_HUE, BAR_SAT + 30, BAR_VAL + 10);
		color_pen.setAlpha(255);
		pen.setColor(color_pen);
		bars[i]->setPen(pen);
		bars[i]->setBrush(color_brush);
		C_HUE += HUE_MAX / bars.size();
	}

	//this->plotLayout()->addElement(0, 0, new QCPPlotTitle(this, QString::fromStdString(dataType)));
	// prepare x axis:
	this->xAxis->setAutoTicks(false);
	this->xAxis->setAutoTickLabels(false);
	this->xAxis->setTickVector(ticks);
	this->xAxis->setTickVectorLabels(labels);
	this->xAxis->setTickLabelRotation(60);
	this->xAxis->setSubTickCount(0);
	this->xAxis->setTickLength(0, 3);
	this->xAxis->grid()->setVisible(true);


	// prepare y axis:
	this->yAxis->setTickStep(5);
	this->yAxis->setPadding(5); // a bit more space to the left border
	if (Node->getFourth() > 0.0)
		this->yAxis->setLabel("Hours");
	else
		this->yAxis->setLabel("Count");
	this->yAxis->grid()->setSubGridVisible(true);
	QPen gridPen;
	gridPen.setStyle(Qt::SolidLine);
	gridPen.setColor(QColor(0, 0, 0, 25));
	this->yAxis->grid()->setPen(gridPen);
	gridPen.setStyle(Qt::DotLine);
	this->yAxis->grid()->setSubGridPen(gridPen);
	this->yAxis->scaleRange(1.3, this->yAxis->range().center());

	this->rescaleAxes(true);
	this->xAxis->setRange(0.5, 10.5);

	// setup legend:
	QCPLayoutGrid *subLayout = new QCPLayoutGrid;
	QCPLayoutElement *dummyElement = new QCPLayoutElement;

	this->plotLayout()->addElement(0, 1, subLayout); // add sub-layout in the cell to the right of the main axis rect
	subLayout->addElement(0, 0, this->legend); // add legend
	subLayout->addElement(1, 0, dummyElement); // add dummy element below legend
	subLayout->setRowStretchFactor(0, 0.01); // make legend cell (in row 0) take up as little vertical space as possible
	this->plotLayout()->setColumnStretchFactor(1, 0.01); // make the legend cell and dummy element column as small as possible

	this->legend->setVisible(true);
	this->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignRight);
	this->legend->setBrush(QColor(255, 255, 255, 200));
	QPen legendPen;
	legendPen.setColor(QColor(130, 130, 130, 200));
	this->legend->setBorderPen(legendPen);
	QFont legendFont = font();
	legendFont.setPointSize(8);
	this->legend->setFont(legendFont);
	this->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items

	this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectLegend);

	if (std::find(othersCount.begin(), othersCount.end(), (!0)) != othersCount.end()){
		return 1;
	}
	else
		return 0;
}
Esempio n. 20
0
int BarPlot::plotGrant()
{
	string dataType = Node->getFirst();
	// Get the types
	// Note the type is not always going to be the within the children of the node (depending on what node is passed)
	// It will be possible to pass in a different node (say a publication type node) when implemented
	vector<node*> types;
	
	vector<node*>* temptypes = Node->getChildren();
	for (int i = 0; i < temptypes->size(); i++){
		if (temptypes->at(i)->getSecond() > 0)
			types.push_back(temptypes->at(i));
	}

	// Grab Data and prepare x axis with (professor Name) labels:
	QVector<QString> labels;
	//display the types only
	for (int i = 0; i < Node->getChildren()->size(); i++)
		labels.push_back(QString::fromStdString(Node->getChildren()->at(i)->getFirst()));


	// stacked bar chart can get cluttered, ensure no more than 30 different types
	// determine which types to push into an "Others" group
	vector<int> othersNdx;
	if (types.size() > COUNT_MAX){
		vector<double> typeSumCounts;
		for (int i = 0; i < types.size(); i++){
			typeSumCounts.push_back(types.at(i)->getFourth());
		}
		while (types.size() - othersNdx.size() > COUNT_MAX){
			othersNdx.push_back(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin());
			typeSumCounts.at(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin()) = std::numeric_limits<double>::infinity();
		}
	}

	QVector<double> ticks;
	for (int i = 1; i <= labels.size(); i++)
		ticks.push_back(i);

	QVector<double> count(labels.size());
	double *data = count.data();
	// create a new plottable area for each type, group everything within the "Others" group together
	for (int i = 0; i < types.size(); i++){
		data[i] = types.at(i)->getFourth();
	}

	QCPBars *bar = new QCPBars(this->xAxis, this->yAxis);
	bar->setName(QString::fromStdString(dataType));
	bar->setData(ticks, count);
	this->addPlottable(bar);

	// set the colors
	QPen pen;
	pen.setWidthF(1.2);
	int C_HUE = 0;
	QColor color_brush, color_pen;
	color_brush.setHsv(C_HUE, BAR_SAT, BAR_VAL);
	color_brush.setAlpha(BAR_ALPHA);
	color_pen.setHsv(C_HUE, BAR_SAT + 30, BAR_VAL + 10);
	color_pen.setAlpha(255);
	pen.setColor(color_pen);
	bar->setPen(pen);
	bar->setBrush(color_brush);

	// prepare x axis:
	this->xAxis->setAutoTicks(false);
	this->xAxis->setAutoTickLabels(false);
	this->xAxis->setTickVector(ticks);
	this->xAxis->setTickVectorLabels(labels);
	this->xAxis->setTickLabelRotation(60);
	this->xAxis->setSubTickCount(0);
	this->xAxis->setTickLength(0, 3);
	this->xAxis->grid()->setVisible(true);

	// prepare y axis:
	this->yAxis->setTickStep(5);
	this->yAxis->setPadding(5); // a bit more space to the left border
	this->yAxis->setLabel("Amount ($)");
	this->yAxis->grid()->setSubGridVisible(true);
	QPen gridPen;
	gridPen.setStyle(Qt::SolidLine);
	gridPen.setColor(QColor(0, 0, 0, 25));
	this->yAxis->grid()->setPen(gridPen);
	gridPen.setStyle(Qt::DotLine);
	this->yAxis->grid()->setSubGridPen(gridPen);
	this->yAxis->scaleRange(1.3, this->yAxis->range().center());

	this->rescaleAxes(true);
	this->xAxis->setRange(0.5, 10.5);

	// setup legend:
	QCPLayoutGrid *subLayout = new QCPLayoutGrid;
	QCPLayoutElement *dummyElement = new QCPLayoutElement;

	this->plotLayout()->addElement(0, 1, subLayout); // add sub-layout in the cell to the right of the main axis rect
	subLayout->addElement(0, 0, this->legend); // add legend
	subLayout->addElement(1, 0, dummyElement); // add dummy element below legend
	subLayout->setRowStretchFactor(0, 0.01); // make legend cell (in row 0) take up as little vertical space as possible
	this->plotLayout()->setColumnStretchFactor(1, 0.01); // make the legend cell and dummy element column as small as possible

	this->legend->setVisible(true);
	this->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignRight);
	this->legend->setBrush(QColor(255, 255, 255, 200));
	QPen legendPen;
	legendPen.setColor(QColor(130, 130, 130, 200));
	this->legend->setBorderPen(legendPen);
	QFont legendFont = font();
	legendFont.setPointSize(8);
	this->legend->setFont(legendFont);
	this->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items

	this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectLegend);
		return 0;
}