// Once channel details are known, complete the graph with details that depend upon the channel.
void LteRlcGraphDialog::completeGraph(bool may_be_empty)
{
    QCustomPlot *rp = ui->rlcPlot;

    // If no channel chosen already, try to use currently selected frame.
    findChannel(may_be_empty);

    // Set window title here.
    if (graph_.channelSet) {
        QString dlg_title = tr("LTE RLC Graph (UE=%1 chan=%2%3 %4 - %5)")
                                 .arg(graph_.ueid)
                                 .arg((graph_.channelType == CHANNEL_TYPE_SRB) ? "SRB" : "DRB")
                                 .arg(graph_.channelId)
                                 .arg((graph_.direction == DIRECTION_UPLINK) ? "UL" : "DL")
                                 .arg((graph_.rlcMode == RLC_UM_MODE) ? "UM" : "AM");
        setWindowTitle(dlg_title);
    }
    else {
        setWindowTitle(tr("LTE RLC Graph - no channel selected"));
    }

    // Set colours/styles for each of the traces on the graph.
    QCustomPlot *sp = ui->rlcPlot;
    base_graph_ = sp->addGraph(); // All: Selectable segments
    base_graph_->setPen(QPen(QBrush(Qt::black), 0.25));

    reseg_graph_ = sp->addGraph();
    reseg_graph_->setPen(QPen(QBrush(Qt::lightGray), 0.25));

    acks_graph_ = sp->addGraph();
    acks_graph_->setPen(QPen(QBrush(graph_color_ack), 1.0));

    nacks_graph_ = sp->addGraph();
    nacks_graph_->setPen(QPen(QBrush(graph_color_nack), 0.25));

    // Create tracer
    tracer_ = new QCPItemTracer(sp);
    sp->addItem(tracer_);
    tracer_->setVisible(false);
    toggleTracerStyle(true);

    // Change label on save/export button.
    QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save);
    save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS));

    connect(rp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphClicked(QMouseEvent*)));
    connect(rp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*)));
    connect(rp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*)));
    disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    this->setResult(QDialog::Accepted);

    // Extract the data that the graph can use.
    fillGraph();
}
void MainWindow::initPlotter()
{
    QCustomPlot *cp = this->ui->plotter;
    cp->addGraph();
    cp->addGraph();
    cp->addGraph();
    cp->xAxis->setLabel("Epoch");
    cp->yAxis->setLabel("fitness");
    cp->graph(0)->setPen(QPen(Qt::blue));
    cp->graph(1)->setPen(QPen(Qt::red));
    cp->graph(2)->setPen(QPen(Qt::green));
    cp->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
    cp->setLocale(QLocale(QLocale::Portuguese, QLocale::Brazil));
    cp->legend->setVisible(true);
}
Example #3
0
int main(int argc, char *argv[])
{
  QApplication a(argc, argv);
  QMainWindow window;
  
  // setup customPlot as central widget of window:
  QCustomPlot customPlot;
  window.setCentralWidget(&customPlot);
  
  // create plot (from quadratic plot example):
  QVector<double> x(101), y(101);
  for (int i=0; i<101; ++i)
  {
    x[i] = i/50.0 - 1;
    y[i] = x[i]*x[i];
  }
  customPlot.addGraph();
  customPlot.graph(0)->setData(x, y);
  customPlot.xAxis->setLabel(QLatin1String("x"));
  customPlot.yAxis->setLabel(QLatin1String("y"));
  customPlot.rescaleAxes();
  
  window.setGeometry(100, 100, 500, 400);
  window.show();
  return a.exec();
}
MissionElevationDisplay::MissionElevationDisplay(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MissionElevationDisplay),
    m_uasInterface(NULL),
    m_uasWaypointMgr(NULL),
    m_totalDistance(0),
    m_elevationData(NULL),
    m_useHomeAltOffset(false),
    m_homeAltOffset(0.0),
    m_elevationShown(false)
{
    ui->setupUi(this);

    ui->sampleSpinBox->setEnabled(false);

    QCustomPlot* customPlot = ui->customPlot;
    customPlot->addGraph(); // Mission Elevation Graph (ElevationGraphMissionId)
    customPlot->graph(ElevationGraphMissionId)->setPen(QPen(Qt::blue)); // line color blue for mission data
    customPlot->graph(ElevationGraphMissionId)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue

    customPlot->addGraph(); // Google Elevation Graph (ElevationGraphElevationId)
    customPlot->graph(ElevationGraphElevationId)->setPen(QPen(Qt::red)); // line color red for elevation data
    customPlot->graph(ElevationGraphElevationId)->setBrush(QBrush(QColor(255, 0, 0, 20))); // first graph will be filled with translucent blue
    customPlot->graph(ElevationGraphElevationId)->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDiamond, 10));
    customPlot->xAxis->setLabel("distance (m)");
    customPlot->yAxis->setLabel("altitude (m)");
    // set default ranges for Alt and distance
    customPlot->xAxis->setRange(0,ElevationDefaultDistanceMax); //m
    customPlot->yAxis->setRange(ElevationDefaultAltMin,ElevationDefaultAltMax); //m

    QFont legendFont = font();
    legendFont.setPointSize(9);
    customPlot->legend->setFont(legendFont);

    // set a more compact font size for bottom and left axis tick labels:
    customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 9));
    customPlot->xAxis->setLabelFont(QFont(QFont().family(), 9));
    customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 9));
    customPlot->yAxis->setLabelFont(QFont(QFont().family(), 9));

    customPlot->replot();

    connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
    activeUASSet(UASManager::instance()->getActiveUAS());

    connect(ui->infoButton, SIGNAL(clicked()), this, SLOT(showInfoBox()));
}
CompassMotorCalibrationDialog::CompassMotorCalibrationDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CompassMotorCalibrationDialog),
    m_uasInterface(NULL)
{
    ui->setupUi(this);

    QCustomPlot* customPlot = ui->customPlot;
    customPlot->addGraph();
    customPlot->graph(GRAPH_ID_INTERFERENCE)->setPen(QPen(GRAPH_COLOR_INTERFERENCE)); // line color blue for first graph
    customPlot->graph(GRAPH_ID_INTERFERENCE)->setBrush(QBrush(GRAPH_COLOR_INTERFERENCE_FILL)); // first graph will be filled with translucent blue

    customPlot->xAxis->setLabel("Throttle (%)");

    customPlot->yAxis->setLabel("Interference (%)");
    customPlot->yAxis->setLabelColor(GRAPH_COLOR_INTERFERENCE);
    customPlot->xAxis->setRange(0,100);
    customPlot->yAxis->setRange(0,100);

    customPlot->addGraph();
    customPlot->graph(GRAPH_ID_CURRENT)->setPen(QPen(GRAPH_COLOR_CURRENT)); // line color red for second graph
    customPlot->graph(GRAPH_ID_CURRENT)->setBrush(QBrush(GRAPH_COLOR_CURRENT_FILL));

    customPlot->yAxis2->setVisible(true);
    customPlot->yAxis2->setLabel("Amps (A)");
    customPlot->yAxis2->setLabelColor(GRAPH_COLOR_CURRENT);
    customPlot->xAxis2->setRange(0,100);
    customPlot->yAxis2->setRange(0,50);

    customPlot->replot();

    connect(ui->okButton, SIGNAL(clicked()), this, SLOT(okButtonClicked()));
    connect(this, SIGNAL(about), this, SLOT(rejected()));
    connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
    activeUASSet(UASManager::instance()->getActiveUAS());

    int ok = QMessageBox::warning(this, "Compass Motor Calibration", tr("CAUTION: Starting the compass motor calibration arms the motors.\n"
                                                               "Please make sure you have read and followed all instructions"
                                                               "before untertaking the calibration as serious injury could occur!"),
                         QMessageBox::Ok, QMessageBox::Cancel);
    if (ok == QMessageBox::Cancel){
        QTimer::singleShot(100, this, SLOT(cancelCalibration()));
    }

}
Example #6
0
bool TimeseriesGraph::update(const GRT::VectorDouble &sample ){

    if( !initialized ) return false;

    //Add the new sample to the buffer
    data.push_back( sample );

    //If the plot is hidden then there is no point in updating the graph
    if( this->isHidden() ){
        if( !lockRanges ){
            //Reset the min and max values
            minRange = 99e+99;
            maxRange = -minRange;
        }
        return true;
    }

    QCustomPlot *plot = ui->graph;

    //Clear any previous graphs
    plot->clearGraphs();

    //Get the data to plot
    QVector<double> x( graphWidth );
    vector< QVector<double> > y(numDimensions, QVector<double>(graphWidth) );

    for (unsigned int i=0; i<graphWidth; i++)
    {
      x[i] = i;
      for(unsigned int j=0; j<numDimensions; j++){
          y[j][i] = data[i][j];
          if( !lockRanges ){
            if( data[i][j] < minRange ) minRange = data[i][j];
            else if( data[i][j] > maxRange ) maxRange = data[i][j];
          }
      }
    }

    //Create the graphs
    for(unsigned int j=0; j<numDimensions; j++){
        plot->addGraph();
        plot->graph(j)->setPen( QPen( colors[j%colors.size()] ));
        plot->graph(j)->setData(x, y[j]);
    }

    // give the axes some labels:
    plot->xAxis->setLabel("Time");
    plot->yAxis->setLabel("Values");

    // set axes ranges, so we see all data:
    plot->xAxis->setRange(0, graphWidth);
    plot->yAxis->setRange(minRange, maxRange);
    plot->replot();

    return true;
}
Example #7
0
/** Makes pre-configuration of the chart: sets the lines, grid style, legend etc
 * @brief ChartWidget::initChart
 */
void ChartWidget::prepareChart(){
    QCustomPlot *customPlot = ui->chart;
    customPlot->clearGraphs();
    graphs.clear();

    switch(mode){
    case 0:
        customPlot->xAxis->setLabel("r");
        customPlot->yAxis->setLabel("Concentration");
    case 1:

        customPlot->xAxis->setLabel("r");
        customPlot->yAxis->setLabel("Number of particles");

        graphs.append(customPlot->addGraph());
        graphs.append(customPlot->addGraph());

        graphs[0]->setPen(QPen(Qt::blue,1));
        graphs[1]->setPen(QPen(Qt::red,1));
        break;
    case 2:
        graphs.append(customPlot->addGraph());

        graphs[0]->setPen(QPen(Qt::blue,1));
        customPlot->xAxis->setLabel("r");
        customPlot->yAxis->setLabel("Potential, eV");
    }

        // set some pens, brushes and backgrounds:
        customPlot->xAxis->setBasePen(QPen(Qt::black, 1));
        customPlot->yAxis->setBasePen(QPen(Qt::black, 1));
        customPlot->xAxis->setTickPen(QPen(Qt::black, 1));
        customPlot->yAxis->setTickPen(QPen(Qt::black, 1));
        customPlot->xAxis->setSubTickPen(QPen(Qt::blue, 1));
        customPlot->yAxis->setSubTickPen(QPen(Qt::blue, 1));
        customPlot->xAxis->setTickLabelColor(Qt::black);
        customPlot->yAxis->setTickLabelColor(Qt::black);
        customPlot->xAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));
        customPlot->yAxis->grid()->setPen(QPen(QColor(140, 140, 140), 1, Qt::DotLine));

        customPlot->xAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
        customPlot->yAxis->setUpperEnding(QCPLineEnding::esSpikeArrow);
}
Example #8
0
void CurrencyPane::UpdateGraph(const QMap<double, double> map) {
    QCustomPlot* customPlot = ui->plotWidget;

    if (map.size() < 2) {
        customPlot->hide();
        return;
    }
    if (customPlot->isHidden()) {
        customPlot->show();
    }

    //customPlot->setBackground(Qt::transparent);

    double lastDate = map.lastKey();
    double weekAgo = QDateTime(QDate::currentDate()).addDays(-7).toTime_t();

    double highestVal = 0;
    if (!map.isEmpty()) {
        highestVal = from(map.values().toVector().toStdVector()).max();
    }

    if (customPlot->graphCount() > 0) {
        customPlot->removeGraph(0);
    }
    customPlot->addGraph();
    customPlot->graph()->setName("Net Worth");
    QPen pen;
    pen.setColor(QColor(0, 0, 255, 200));
    customPlot->graph()->setLineStyle(QCPGraph::lsLine);
    customPlot->graph()->setPen(pen);
    customPlot->graph()->setBrush(QBrush(QColor(255/4.0,160,50,150)));
    customPlot->graph()->setData(map.keys().toVector(), map.values().toVector());

    // configure bottom axis to show date and time instead of number:
    customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    customPlot->xAxis->setDateTimeFormat("ddd");
    // set a more compact font size for bottom and left axis tick labels:
    customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
    customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
    // set axis labels:
    customPlot->xAxis->setLabel("Date");
    customPlot->yAxis->setLabel("Total Worth in Chaos");
    // make top and right axes visible but without ticks and labels:
    customPlot->xAxis2->setVisible(true);
    customPlot->yAxis2->setVisible(true);
    customPlot->xAxis2->setTicks(false);
    customPlot->yAxis2->setTicks(false);
    customPlot->xAxis2->setTickLabels(false);
    customPlot->yAxis2->setTickLabels(false);
    // set axis ranges to show all data:
    customPlot->xAxis->setRange(weekAgo, lastDate);
    customPlot->yAxis->setRange(0, highestVal);
    // show legend:
    customPlot->legend->setVisible(true);
}
void BasicGraph::Demo()
{
   QCustomPlot* customPlot = ui.basicGraph;

   // add two new graphs and set their look:
   customPlot->addGraph();
   customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
   customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
   customPlot->addGraph();
   customPlot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
   // generate some points of data (y0 for first, y1 for second graph):
   QVector<double> x(250), y0(250), y1(250);
   for (int i = 0; i<250; ++i)
   {
      x[i] = i;
      y0[i] = exp(-i / 150.0)*cos(i / 10.0); // exponentially decaying cosine
      y1[i] = exp(-i / 150.0); // exponential envelope
   }
   // configure right and top axis to show ticks but no labels:
   // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
   customPlot->xAxis2->setVisible(true);
   customPlot->xAxis2->setTickLabels(false);
   customPlot->yAxis2->setVisible(true);
   customPlot->yAxis2->setTickLabels(false);
   // make left and bottom axes always transfer their ranges to right and top axes:
   connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
   connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
   // pass data points to graphs:
   customPlot->graph(0)->setData(x, y0);
   customPlot->graph(1)->setData(x, y1);
   // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
   customPlot->graph(0)->rescaleAxes();
   // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
   customPlot->graph(1)->rescaleAxes(true);
   // Note: we could have also just called customPlot->rescaleAxes(); instead
   // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
   customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

   

   ExternalReplot();
}
Example #10
0
void Record::createWaveFormPic(Ffmpeg_t *ffmpeg, QString recortPath) {

    std::pair<std::vector<double>, std::vector<double> > dataWaveForm = ffmpeg->getSamplesForWaveformPlotting(recortPath + "/" + m_Name);
    QCustomPlot Plotter;
    Plotter.setBackground(QBrush(Qt::transparent) );
    Plotter.xAxis->setVisible(false);
    Plotter.yAxis->setVisible(false);
    Plotter.axisRect()->setAutoMargins(QCP::msNone);
    Plotter.axisRect()->setMargins(QMargins(0, 5, 0, 5));
    QCPGraph *Waveform = Plotter.addGraph();
    Waveform->setPen(QPen(Qt::green) );

    if (!Waveform)
    {
        qDebug("addGraph failed\n");
    }

    QVector<double> Amplitudes(QVector<double>::fromStdVector(dataWaveForm.first) );
    QVector<double> Time;

    double CurrentTime = 0;
    auto TimeSlotCount = Amplitudes.size();

    for (int64_t i = 1; i < TimeSlotCount; i++)
    {
        Time.append(CurrentTime);
        CurrentTime += 0.5;
    }

    Waveform->setData(Time, Amplitudes);
    Plotter.xAxis->setRange(0, Time.back() );
    Plotter.yAxis->setRange(SHRT_MIN, SHRT_MAX);

    QByteArray ByteArray;
    QBuffer Buffer(&ByteArray);
    Buffer.open(QBuffer::WriteOnly);
    uint32_t time = m_EndTime - m_StartTime;
    for (int i = 1; i < 10000; i*=10) {
        Plotter.toPixmap(time/(i), this->height()).save(&Buffer, "PNG", 0);
        //Plotter.saveJpg(recortPath + "/plot" + QString::number(m_Id) + QString::number(i) + ".jpg", time/(i), this->height());

        QPixmap Pixmap;
        Pixmap.loadFromData(ByteArray, "PNG");
        v_PixWaves.append(Pixmap);

        ByteArray.clear();
        Buffer.reset();
    }
    Buffer.close();
    qDebug() << m_WavePic->margin();
    // místo 2 podle toho jaký zoom
    m_WavePic->setPixmap(v_PixWaves[2]);

}
Example #11
0
void MainWindow::updatePlots()
{
    for(int k=0;k<plotList->size();k++)
    {
        QCustomPlot *customPlot = ui->plotArea->findChild<QCustomPlot*>(plotList->value(k));
        customPlot->addGraph();
       // customPlot->graph(0)->addData(i,i*2);
        customPlot->xAxis->setLabel("x");
        customPlot->yAxis->setLabel("y");
        // set axes ranges, so we see all data:
        customPlot->xAxis->setRange(-100, 100);
        customPlot->yAxis->setRange(-1000, 1000);
        customPlot->replot();
    }
}
Example #12
0
void Graph::createGraph(const std::string& name, QColor color) {
    if (name.length() > 255) {
        std::cout << "LiveGrapher: Graph::createGraph(): "
                  << "name exceeds 255 characters" << std::endl;
        return;
    }
    m_dataSets.emplace_back();

    QCustomPlot* customPlot = m_window->m_ui->plot;
    customPlot->addGraph();
    customPlot->graph()->setName(QString::fromUtf8(name.c_str()));
    customPlot->graph()->setAntialiasedFill(false);
    customPlot->setNoAntialiasingOnDrag(true);

    QPen pen(color);
    customPlot->graph()->setPen(pen);
}
Example #13
0
void Snakes::drawPlot(std::vector<double> inputX, std::vector<double> inputY) {

	QCustomPlot *customPlot = new QCustomPlot();
	customPlot->resize(500, 500);
	
	QVector<double> x = QVector<double>::fromStdVector(inputX);
	QVector<double> y = QVector<double>::fromStdVector(inputY);

	customPlot->addGraph();
	customPlot->graph(0)->setData(x, y);
	customPlot->xAxis->setLabel("x");
	customPlot->yAxis->setLabel("y");
	customPlot->xAxis->setRange(inputX.front(), inputX.back());
	customPlot->yAxis->setRange(inputY.front(), inputY.back());
	customPlot->replot();

	customPlot->show();
}
Example #14
0
void MainWindow::maximizarGrafico1(QMouseEvent* e) {

    QVector<double> x(100);
    QVector<double> y(100);
    wgraficos *w = new wgraficos();
    w->exec();

    QCustomPlot * graph = w->getDatos();

    graph->addGraph();
    for (int i = 0; i < 100; ++i) {
        x[i] = i;
        y[i] = rand();
    }

    graph->graph(0)->setData(x,y);
    graph->replot();

}
Example #15
0
void MainWindow::runOptimization() {
	if (m_CostFunc.IsNull() || g_pointList.size() == 0) {
		return;
	}

    OptimizerParameters initialParams;
    ConvertListOfPointVectorsToParameters(g_pointList, initialParams);

	OptimizerProgress::Pointer progress = OptimizerProgress::New();
    progress->SetParticlesHistory(&g_pointHistory);
    
    OptimizerParameters result;
    if (ui.optiCG->isChecked()) {
        result = optimizeByFRPR(m_CostFunc, initialParams, progress);
    } else if (ui.optiGD->isChecked()) {
        result = optimizeByGD(m_CostFunc, initialParams, progress);
    } else if (ui.optiLBFGS->isChecked()) {
        result = optimizeByLBFGS(m_CostFunc, initialParams, progress);
    }

    // draw cost function
    ConvertParametersToListOfPointVectors(result, g_pointList.size(), g_pointList[0].size(), g_pointList);
    QVector<double> x(g_costHistory.size()), y(g_costHistory.size()); // initialize with entries 0..100
    for (int i = 0; i < x.count(); ++i)
    {
        x[i] = i;
        y[i] = g_costHistory[i];
    }

    QCustomPlot* customPlot = ui.customPlot;
    customPlot->clearGraphs();
    // create graph and assign data to it:
    customPlot->addGraph();
    customPlot->graph(0)->setData(x, y);
    customPlot->rescaleAxes();

    // give the axes some labels:
    customPlot->xAxis->setLabel("iteration");
    customPlot->yAxis->setLabel("cost");
    customPlot->replot();

	updateScene();
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QCustomPlot *customPlot = (QCustomPlot*) (ui->graph);
    // set locale to english, so we get english month names:
      customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));
      // seconds of current time, we'll use it as starting point in time for data:
      double now = QDateTime::currentDateTime().toTime_t();
      srand(8); // set the random seed, so we always get the same random data
      // create multiple graphs:
      for (int gi=0; gi<5; ++gi)
      {
        customPlot->addGraph();
        QPen pen;
        pen.setColor(QColor(0, 0, 255, 200));
        customPlot->graph()->setLineStyle(QCPGraph::lsLine);
        customPlot->graph()->setPen(pen);
        customPlot->graph()->setBrush(QBrush(QColor(255/4.0*gi,160,50,150)));
        // generate random walk data:
        QVector<double> time(250), value(250);
        for (int i=0; i<250; ++i)
        {
          time[i] = now + 24*3600*i;
          if (i == 0)
            value[i] = (i/50.0+1)*(rand()/(double)RAND_MAX-0.5);
          else
            value[i] = fabs(value[i-1])*(1+0.02/4.0*(4-gi)) + (i/50.0+1)*(rand()/(double)RAND_MAX-0.5);
        }
        customPlot->graph()->setData(time, value);
      }
      // configure bottom axis to show date and time instead of number:
      customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
      customPlot->xAxis->setDateTimeFormat("MMMM\nyyyy");
      // set a more compact font size for bottom and left axis tick labels:
      customPlot->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
      customPlot->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
      // set a fixed tick-step to one tick per month:
      customPlot->xAxis->setAutoTickStep(false);
      customPlot->xAxis->setTickStep(2628000); // one month in seconds
      customPlot->xAxis->setSubTickCount(3);
      // apply manual tick and tick label for left axis:
      customPlot->yAxis->setAutoTicks(false);
      customPlot->yAxis->setAutoTickLabels(false);
      customPlot->yAxis->setTickVector(QVector<double>() << 5 << 55);
      customPlot->yAxis->setTickVectorLabels(QVector<QString>() << "Not so\nhigh" << "Very\nhigh");
      // set axis labels:
      customPlot->xAxis->setLabel("Date");
      customPlot->yAxis->setLabel("Random wobbly lines value");
      // make top and right axes visible but without ticks and labels:
      customPlot->xAxis2->setVisible(true);
      customPlot->yAxis2->setVisible(true);
      customPlot->xAxis2->setTicks(false);
      customPlot->yAxis2->setTicks(false);
      customPlot->xAxis2->setTickLabels(false);
      customPlot->yAxis2->setTickLabels(false);
      // set axis ranges to show all data:
      customPlot->xAxis->setRange(now, now+24*3600*249);
      customPlot->yAxis->setRange(0, 60);
      // show legend:
      customPlot->legend->setVisible(true);
}
Example #17
0
bool FeaturePlot::plot(){

    if( !initialized ) return false;

    QCustomPlot *plot = ui->plot;

    //Clear any previous graphs
    plot->clearGraphs();

    const unsigned int M = data.getNumSamples();
    const unsigned int K = data.getNumClasses();
    const unsigned int N = data.getNumDimensions();
    GRT::Vector< GRT::MinMax > ranges = data.getRanges();
    GRT::Vector< unsigned int > classLabels = data.getClassLabels();
    GRT::Vector< GRT::ClassTracker > classTracker = data.getClassTracker();
    double minRange = GRT::grt_numeric_limits<double>::max();
    double maxRange = -minRange;

    //Add a new graph for each class
    for(unsigned int k=0; k<K; k++){
        const unsigned int numSamplesInClass = classTracker[k].counter;

        if( numSamplesInClass > 0 ){
            QVector< double > x( numSamplesInClass );
            QVector< double > y( numSamplesInClass );
            plot->addGraph();
            plot->graph(k)->setPen( QPen( classColors[ k % classColors.size() ] ) );
            plot->graph(k)->setLineStyle( QCPGraph::lsNone );
            plot->graph(k)->setScatterStyle( QCPScatterStyle(QCPScatterStyle::ssCross, 4) );

            unsigned int index = 0;
            for(unsigned int i=0; i<M; i++)
            {
                if( data[i].getClassLabel() == classTracker[k].classLabel ){
                    x[ index ] = data[i][ axisIndexX ];
                    y[ index ] = data[i][ axisIndexY ];
                    index++;

                    for(unsigned int j=0; j<N; j++){
                        if( data[i][j] > maxRange ){
                            maxRange = data[i][j];
                        }else if( data[i][j] < minRange ){
                            minRange = data[i][j];
                        }
                    }
                }
            }

            // pass data points to graphs:
            plot->graph( k )->setData(x, y);
        }
    }

    //Add 20% to the min and max range
    minRange += minRange * 0.2;
    maxRange += maxRange * 0.2;

    plot->xAxis->setVisible( true );
    plot->xAxis->setTickLabels( true );
    plot->yAxis->setVisible( true );
    plot->yAxis->setTickLabels( true );
    plot->xAxis->setLabel( QString::fromStdString("X Axis Index: "  + GRT::Util::toString(axisIndexX)) );
    plot->yAxis->setLabel( QString::fromStdString("Y Axis Index: "  + GRT::Util::toString(axisIndexY)) );
    plot->xAxis->setRange(minRange, maxRange);
    plot->yAxis->setRange(minRange, maxRange);
    plot->replot();

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

    return true;
}
TCPStreamDialog::TCPStreamDialog(QWidget *parent, capture_file *cf, tcp_graph_type graph_type) :
    QDialog(NULL, Qt::Window),
    ui(new Ui::TCPStreamDialog),
    cap_file_(cf),
    ts_offset_(0),
    ts_origin_conn_(true),
    seq_offset_(0),
    seq_origin_zero_(true),
    title_(NULL),
    base_graph_(NULL),
    tput_graph_(NULL),
    seg_graph_(NULL),
    ack_graph_(NULL),
    rwin_graph_(NULL),
    tracer_(NULL),
    packet_num_(0),
    mouse_drags_(true),
    rubber_band_(NULL),
    num_dsegs_(-1),
    num_acks_(-1),
    num_sack_ranges_(-1)
{
    struct segment current;
    int graph_idx = -1;

    ui->setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose, true);

    graph_.type = GRAPH_UNDEFINED;
    set_address(&graph_.src_address, AT_NONE, 0, NULL);
    graph_.src_port = 0;
    set_address(&graph_.dst_address, AT_NONE, 0, NULL);
    graph_.dst_port = 0;
    graph_.stream = 0;
    graph_.segments = NULL;

    struct tcpheader *header = select_tcpip_session(cap_file_, &current);
    if (!header) {
        done(QDialog::Rejected);
        return;
    }

//#ifdef Q_OS_MAC
//    ui->hintLabel->setAttribute(Qt::WA_MacSmallSize, true);
//#endif

    QComboBox *gtcb = ui->graphTypeComboBox;
    gtcb->setUpdatesEnabled(false);
    gtcb->addItem(ui->actionRoundTripTime->text(), GRAPH_RTT);
    if (graph_type == GRAPH_RTT) graph_idx = gtcb->count() - 1;
    gtcb->addItem(ui->actionThroughput->text(), GRAPH_THROUGHPUT);
    if (graph_type == GRAPH_THROUGHPUT) graph_idx = gtcb->count() - 1;
    gtcb->addItem(ui->actionStevens->text(), GRAPH_TSEQ_STEVENS);
    if (graph_type == GRAPH_TSEQ_STEVENS) graph_idx = gtcb->count() - 1;
    gtcb->addItem(ui->actionTcptrace->text(), GRAPH_TSEQ_TCPTRACE);
    if (graph_type == GRAPH_TSEQ_TCPTRACE) graph_idx = gtcb->count() - 1;
    gtcb->addItem(ui->actionWindowScaling->text(), GRAPH_WSCALE);
    if (graph_type == GRAPH_WSCALE) graph_idx = gtcb->count() - 1;
    gtcb->setUpdatesEnabled(true);

    ui->dragRadioButton->setChecked(mouse_drags_);

    ctx_menu_.addAction(ui->actionZoomIn);
    ctx_menu_.addAction(ui->actionZoomInX);
    ctx_menu_.addAction(ui->actionZoomInY);
    ctx_menu_.addAction(ui->actionZoomOut);
    ctx_menu_.addAction(ui->actionZoomOutX);
    ctx_menu_.addAction(ui->actionZoomOutY);
    ctx_menu_.addAction(ui->actionReset);
    ctx_menu_.addSeparator();
    ctx_menu_.addAction(ui->actionMoveRight10);
    ctx_menu_.addAction(ui->actionMoveLeft10);
    ctx_menu_.addAction(ui->actionMoveUp10);
    ctx_menu_.addAction(ui->actionMoveDown10);
    ctx_menu_.addAction(ui->actionMoveRight1);
    ctx_menu_.addAction(ui->actionMoveLeft1);
    ctx_menu_.addAction(ui->actionMoveUp1);
    ctx_menu_.addAction(ui->actionMoveDown1);
    ctx_menu_.addSeparator();
    ctx_menu_.addAction(ui->actionNextStream);
    ctx_menu_.addAction(ui->actionPreviousStream);
    ctx_menu_.addAction(ui->actionSwitchDirection);
    ctx_menu_.addAction(ui->actionGoToPacket);
    ctx_menu_.addSeparator();
    ctx_menu_.addAction(ui->actionDragZoom);
    ctx_menu_.addAction(ui->actionToggleSequenceNumbers);
    ctx_menu_.addAction(ui->actionToggleTimeOrigin);
    ctx_menu_.addAction(ui->actionCrosshairs);
    ctx_menu_.addSeparator();
    ctx_menu_.addAction(ui->actionRoundTripTime);
    ctx_menu_.addAction(ui->actionThroughput);
    ctx_menu_.addAction(ui->actionStevens);
    ctx_menu_.addAction(ui->actionTcptrace);
    ctx_menu_.addAction(ui->actionWindowScaling);

    memset (&graph_, 0, sizeof(graph_));
    graph_.type = graph_type;
    copy_address(&graph_.src_address, &current.ip_src);
    graph_.src_port = current.th_sport;
    copy_address(&graph_.dst_address, &current.ip_dst);
    graph_.dst_port = current.th_dport;
    graph_.stream = header->th_stream;
    findStream();

    ui->streamNumberSpinBox->blockSignals(true);
    ui->streamNumberSpinBox->setMaximum(get_tcp_stream_count() - 1);
    ui->streamNumberSpinBox->setValue(graph_.stream);
    ui->streamNumberSpinBox->blockSignals(false);

    QCustomPlot *sp = ui->streamPlot;
    QCPPlotTitle *file_title = new QCPPlotTitle(sp, cf_get_display_name(cap_file_));
    file_title->setFont(sp->xAxis->labelFont());
    title_ = new QCPPlotTitle(sp);
    sp->plotLayout()->insertRow(0);
    sp->plotLayout()->addElement(0, 0, file_title);
    sp->plotLayout()->insertRow(0);
    sp->plotLayout()->addElement(0, 0, title_);

    base_graph_ = sp->addGraph(); // All: Selectable segments
    base_graph_->setPen(QPen(QBrush(graph_color_1), 0.25));
    tput_graph_ = sp->addGraph(sp->xAxis, sp->yAxis2); // Throughput: Moving average
    tput_graph_->setPen(QPen(QBrush(graph_color_2), 0.5));
    tput_graph_->setLineStyle(QCPGraph::lsLine);
    seg_graph_ = sp->addGraph(); // tcptrace: fwd segments
    seg_graph_->setErrorType(QCPGraph::etValue);
    seg_graph_->setLineStyle(QCPGraph::lsNone);
    seg_graph_->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssDot, Qt::transparent, 0));
    seg_graph_->setErrorPen(QPen(QBrush(graph_color_1), 0.5));
    seg_graph_->setErrorBarSize(pkt_point_size_);
    ack_graph_ = sp->addGraph(); // tcptrace: rev ACKs
    ack_graph_->setPen(QPen(QBrush(graph_color_2), 0.5));
    ack_graph_->setLineStyle(QCPGraph::lsStepLeft);
    rwin_graph_ = sp->addGraph(); // tcptrace: rev RWIN
    rwin_graph_->setPen(QPen(QBrush(graph_color_3), 0.5));
    rwin_graph_->setLineStyle(QCPGraph::lsStepLeft);

    tracer_ = new QCPItemTracer(sp);
    sp->addItem(tracer_);

    // Triggers fillGraph().
    ui->graphTypeComboBox->setCurrentIndex(graph_idx);

    sp->setMouseTracking(true);

    sp->yAxis->setLabelColor(QColor(graph_color_1));
    sp->yAxis->setTickLabelColor(QColor(graph_color_1));

    tracer_->setVisible(false);
    toggleTracerStyle(true);

    QPushButton *save_bt = ui->buttonBox->button(QDialogButtonBox::Save);
    save_bt->setText(tr("Save As" UTF8_HORIZONTAL_ELLIPSIS));

    QPushButton *close_bt = ui->buttonBox->button(QDialogButtonBox::Close);
    if (close_bt) {
        close_bt->setDefault(true);
    }

    ProgressFrame::addToButtonBox(ui->buttonBox, parent);

    connect(sp, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(graphClicked(QMouseEvent*)));
    connect(sp, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(mouseMoved(QMouseEvent*)));
    connect(sp, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(mouseReleased(QMouseEvent*)));
    connect(sp, SIGNAL(axisClick(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)),
            this, SLOT(axisClicked(QCPAxis*,QCPAxis::SelectablePart,QMouseEvent*)));
    connect(sp->yAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(transformYRange(QCPRange)));
    disconnect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
    this->setResult(QDialog::Accepted);
}
Example #19
0
void ChartPage::setupChart()
{
  this->buildingChart=true;

  QCustomPlot *customPlot = ui->chartBlock;
  customPlot->setInteraction(QCP::iRangeDrag, true);
  customPlot->setInteraction(QCP::iSelectPlottables, true);
  customPlot->setInteraction(QCP::iSelectItems, true);
  customPlot->setInteraction(QCP::iRangeZoom, true);
  customPlot->legend->setVisible(true);
  customPlot->legend->setFont(QFont("Helvetica",9));
  // set locale to english, so we get english decimal separator:
  customPlot->setLocale(QLocale(QLocale::English, QLocale::UnitedKingdom));



  // create graph and assign data to it:
  customPlot->addGraph();
  customPlot->graph(0)->setName("Difficulty");
//  customPlot->graph(0)->setData(x, y);
  // give the axes some labels:
  customPlot->xAxis->setLabel("Date");
  customPlot->yAxis->setLabel("Difficulty");
  customPlot->legend->setSelectableParts(QCPLegend::spItems);
  customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables);
  customPlot->axisRect()->setupFullAxesBox();
  customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
  customPlot->xAxis->setDateTimeFormat("dd/MM/yyyy");
  customPlot->xAxis->setAutoTickCount(5);
  //customPlot->yAxis->setAutoTickCount(5);

  // set axes ranges, so we see all data:
  customPlot->yAxis->setRange(-0.1, 3);

  ClientModel *model = this->clientModel;
  // generate some data:
  QVector<double> x(1000), y(1000); //, y1(50000);
  int maxBlocks;
  maxBlocks = model->getNumBlocks();

  if (maxBlocks > 1000)
  {
        maxBlocks=1000;
  }

  int i = 0;
  if (maxBlocks > 0) {
      for (i = 0; i < maxBlocks; i++)
      {
        CBlock blk = model->getBlock(i);
        CBlockIndex* cIndex = model->getBlockIndex(i);
        x[i]=blk.GetBlockTime();
        y[i]=model->getDiff(cIndex);
      }
      customPlot->graph(0)->setData(x, y);
      customPlot->xAxis->setRange(x[i-1]-(60*60*24), x[i-1]);
      this->lastBlockHeight = i;
  }



  customPlot->replot();
  this->buildingChart=false;

}
void convert::force(int nn,double D,double rho,double Cd,double Cm){
    // Define Pi
    //
    const double PI = 4.0*atan(1.0);


    // To cover-up for previous lazyness are we now making local
    // copies of the fields we need - sorry!
    //
    std::vector<double> tmp_;
    tmp_.resize(nt);
    for (int i=0;i<nt;i++){
        tmp_[i] = eta[i*nx*ny+nn];
    }

    // deta/dt
    //
    std::vector<double> detadt;
   detadt.resize(nt);
   gradient(detadt,tmp_,dt,nt);

    // dz/dt
    //
   Double2d dzdt(boost::extents[nz][nt]);
    for (int k=0;k<nz;k++){
        for (int i=0;i<nt;i++){
         dzdt[k][i] = detadt[i]*sigma[k];
        }
    }

    // du/dt on the sigma grid
    //
    Double2d dudt(boost::extents[nz][nt]);
    for (int k=0;k<nz;k++){
        for (int i=0;i<nt;i++){
            tmp_[i] = u[i*nx*ny*nz+nn*nz+k];
        }
        gradient(&dudt[k][0],tmp_,dt,nt); // To-do: this is super sluppy and error prone
     }



    // Acceleration
    //
    Double2d acc(boost::extents[nz][nt]);
    for (int k=0;k<nz;k++){
        for (int i=0;i<nt;i++){
            acc[k][i] = dudt[k][i]-uz[i*nx*ny*nz+nn*nz+k]*dzdt[k][i];
        }
    }

    // The inline force
    //
    double dz,Fd,Fi;
    int index;
    F.resize(nt);

    for (int i=0;i<nt;i++){
        F[i] = 0;
        for (int k=1;k<nz-1;k++){// we ignore the ghost points
            index = i*nx*ny*nz+nn*nz+k;
            dz = (sigma[k+1]-sigma[k])*(eta[i*nx*ny+nn]+h[nn]);

            Fd = 0.5*rho*Cd*D*(u[index]*std::abs(u[index])+u[index+1]*std::abs(u[index+1]))/2;
            Fi = rho*Cm*(PI/4)*pow(D,2)*(acc[k][i]+acc[k+1][i])/2;

            F[i] += (Fd+Fi)*dz;
        }

    }


    QFileInfo fileInfo =  QFileInfo(fileName);
    std::ofstream morisonForce;
    morisonForce.open(fileInfo.baseName().toLatin1() + ".force");
    morisonForce << "time F" << std::endl;
    QVector<double> QV_t,QV_F;
    QV_t.resize(nt);
    QV_F.resize(nt);
    for (int i=1;i<nt-1;i++){
        morisonForce << std::setiosflags(std::ios::fixed) << std::setprecision(10) << t[i] << " " << F[i] << std::endl;
        QV_t[i] = t[i];
        QV_F[i] = F[i];
    }
    morisonForce.close();

    // plot solution
    QCustomPlot *cPlot = new QCustomPlot;
    QWidget *plotWindow = new QWidget;
    QHBoxLayout *plotWindow_layout = new QHBoxLayout;
    plotWindow_layout->addWidget(cPlot);
    plotWindow->setLayout(plotWindow_layout);

    plotWindow->resize(800,400);

    plotWindow->show();
    cPlot->clearGraphs();

    cPlot->addGraph();
    cPlot->graph()->setData(QV_t,QV_F);
    cPlot->xAxis->setLabel("Time, t s");
    cPlot->yAxis->setLabel("Inline force, F N");
    QVector<double>::iterator Xmin = std::min_element(QV_t.begin(), QV_t.end());
    QVector<double>::iterator Xmax = std::max_element(QV_t.begin(), QV_t.end());
    QVector<double>::iterator Ymin = std::min_element(QV_F.begin(), QV_F.end());
    QVector<double>::iterator Ymax = std::max_element(QV_F.begin(), QV_F.end());
    cPlot->xAxis->setRange(*Xmin,*Xmax);
    cPlot->yAxis->setRange(*Ymin,*Ymax);
    cPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
    cPlot->replot();


}
Example #21
0
BOOL BasicGraph::LoadCSVDataFile(QString filename, TimeSeriesData* pOutputData)
{
   int rc;
   char tempString[64];
   FILE* pFile;
   // errno_t err = fopen_s(&pFile, filename.toLatin1().data(), "rt");
   errno_t err = fopen_s(&pFile, "C:/trainingdata/8286/TimeSeries/Average_Z.csv", "rt");
   if (err == 13)
   {
      CJTRACE(TRACE_ERROR_LEVEL, "ERROR: Failed to open file: PERMISSION DENIED", filename.toLatin1().data());
      return FALSE;
   }
   else if (err != 0)
   {
      CJTRACE(TRACE_ERROR_LEVEL, "ERROR: Failed to open file. err=%d, file=%s", err, filename.toLatin1().data());
      return FALSE;
   }
   pOutputData->filename = filename;

   // Get data name
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->name.fromLatin1(tempString);
   pOutputData->name.remove(0, 5);
   CJTRACE(TRACE_ERROR_LEVEL, "Loading data file: %s", filename.toLatin1().data());
   CJTRACE(TRACE_ERROR_LEVEL, "   Name:  %s", pOutputData->name.toLatin1().data());

   // Get time delta in X axis
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->timedelta = atof(&tempString[6]);
   CJTRACE(TRACE_ERROR_LEVEL, "   Delta: %.10lf (sec)", pOutputData->timedelta);

   // Get first X axis value
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->timestart = atof(&tempString[5]);
   CJTRACE(TRACE_ERROR_LEVEL, "   Start: %.10lf (sec)", pOutputData->timestart);

   // Get X axis label
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->Xaxislabel.fromLatin1(tempString);
   pOutputData->Xaxislabel.remove(0, 7);
   CJTRACE(TRACE_ERROR_LEVEL, "   X Axis: %s", pOutputData->Xaxislabel.toLatin1().data());

   // Get Y axis label
   fscanf_s(pFile, "%s", tempString, 64);
   pOutputData->Yaxislabel.fromLatin1(tempString);
   pOutputData->Yaxislabel.remove(0, 7);
   CJTRACE(TRACE_ERROR_LEVEL, "   Y Axis: %s", pOutputData->Yaxislabel.toLatin1().data());

   while (strcmp(tempString, "Values") != 0)
   {
      fscanf_s(pFile, "%s", tempString, 64);  // Data Notes (skip for now)
   }
   
   // Get data values
   rc = 0;
   int count = 0;
   QVector<double> time(0); 
   double nextTime = pOutputData->timestart;

   while (rc != EOF)
   {
      rc = fscanf_s(pFile, "%s", tempString, 64);
      pOutputData->pData.append(atof(tempString));
      time.append(nextTime);
      nextTime += pOutputData->timedelta;
      count++;
      if ((count < 50) || (count % 500 == 0))
      CJTRACE(TRACE_ERROR_LEVEL, "   Value: %d, %.10lf", count, pOutputData->timedelta);
   }
   CJTRACE(TRACE_ERROR_LEVEL, "Data File Read (%d entries)", count);

   QCustomPlot* customPlot = ui.basicGraph;

   // add two new graphs and set their look:
   customPlot->addGraph();
   customPlot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
   // configure right and top axis to show ticks but no labels:
   // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
   customPlot->xAxis2->setVisible(true);
   customPlot->xAxis2->setTickLabels(false);
   customPlot->yAxis2->setVisible(true);
   customPlot->yAxis2->setTickLabels(false);
   // make left and bottom axes always transfer their ranges to right and top axes:
   connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange)));
   connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange)));
   // pass data points to graphs:
   customPlot->graph(0)->setData(time, pOutputData->pData);

   // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
   customPlot->graph(0)->rescaleAxes();
   // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
   //customPlot->graph(1)->rescaleAxes(true);
   // Note: we could have also just called customPlot->rescaleAxes(); instead
   // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
   customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);

   ExternalReplot();

   return TRUE;
}