void ScatterWidget::addBaseLine(const PointD &p1, const PointD &p2, string legend)
{
    QCPGraph *graph = NULL;
    int nG = ui->scatter->graphCount();
    for(int j=0; j<nG; j++)
    {
        if(ui->scatter->graph(j)->name() == QString::fromStdString(legend))
        {
            graph = ui->scatter->graph(j);
            break;
        }
    }

    if(!graph)
    {
        graph = ui->scatter->addGraph();
        // ----------------------- Scatter Configuration ---------------------------
        graph->setName(QString::fromStdString(legend));
        QColor color_ = colorManager.getNewDifferentColor();
        graph->setPen(QPen(color_));
    }
    QVector<double> keys, vals;
    keys << p1.x << p2.x;
    vals << p1.y << p2.y;
    graph->setData(keys, vals);
}
void MainWindow::onPacketParsed(Packet packet)
{
    _packetsReceivedCount++;

    if(!packet.isCrcValid())
    {
        _crcErrorCount++;
    }

    QString sourceId = ByteArrayUtils::toString(packet.sourceId()).replace(" 0x", "").replace("0x", "");
    if(!_rssValues.contains(sourceId))
    {
        _rssValues.insert(sourceId, QVector<double>());
        _timestampValues.insert(sourceId, QVector<double>());

        QCPGraph* deviceGraph = ui->plotWidget->addGraph();
        deviceGraph->setScatterStyle(QCP::ssDisc);
        deviceGraph->setScatterSize(5);
        deviceGraph->setName(sourceId);
        ensureDistinctColors();
    }

    _rssValues[sourceId].append(packet.rss());
    _timestampValues[sourceId].append(packet.timestamp().toTime_t());
    updatePlot();

    updateStatus();
}
void ScatterWidget::selectionChanged()
{
    /*
   normally, axis base line, axis tick labels and axis labels are selectable separately, but we want
   the user only to be able to select the axis as a whole, so we tie the selected states of the tick labels
   and the axis base line together. However, the axis label shall be selectable individually.

   The selection state of the left and right axes shall be synchronized as well as the state of the
   bottom and top axes.

   Further, we want to synchronize the selection of the graphs with the selection state of the respective
   legend item belonging to that graph. So the user can select a graph by either clicking on the graph itself
   or on its legend item.
   */

    // make top and bottom axes be selected synchronously, and handle axis and tick labels as one selectable object:
    if (ui->scatter->xAxis->selectedParts().testFlag(QCPAxis::spAxis) || ui->scatter->xAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
            ui->scatter->xAxis2->selectedParts().testFlag(QCPAxis::spAxis) || ui->scatter->xAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
    {
        ui->scatter->xAxis2->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
        ui->scatter->xAxis->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
    }
    // make left and right axes be selected synchronously, and handle axis and tick labels as one selectable object:
    if (ui->scatter->yAxis->selectedParts().testFlag(QCPAxis::spAxis) || ui->scatter->yAxis->selectedParts().testFlag(QCPAxis::spTickLabels) ||
            ui->scatter->yAxis2->selectedParts().testFlag(QCPAxis::spAxis) || ui->scatter->yAxis2->selectedParts().testFlag(QCPAxis::spTickLabels))
    {
        ui->scatter->yAxis2->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
        ui->scatter->yAxis->setSelectedParts(QCPAxis::spAxis|QCPAxis::spTickLabels);
    }

    // synchronize selection of graphs with selection of corresponding legend items:
    for (int i=0; i<ui->scatter->graphCount(); ++i)
    {
        QCPGraph *graph = ui->scatter->graph(i);
        QCPPlottableLegendItem *item = ui->scatter->legend->itemWithPlottable(graph);
        if (graph->selected())
        {
            item->setSelected(true);
            //graph->setSelection(QCPDataSelection(graph->data()->dataRange()));
        }
        else
            item->setSelected(false);
    }
     //synchronize selection of graphs with selection of corresponding legend items:
    for (int i=0; i<ui->scatter->lineGraphCount(); ++i)
    {
        QCPLineBasedGraph *graph = ui->scatter->lineGraph(i);
        QCPPlottableLegendItem *item = ui->scatter->legend->itemWithPlottable(graph);
        if (graph->selected())
        {
            item->setSelected(true);
            //graph->setSelection(QCPDataSelection(graph->data()->dataRange()));
        }
        else
            item->setSelected(false);
    }
}
static void createGraph(QCustomPlot *plot, QVector<double> &steps, QVector<double> &data, const Qt::GlobalColor &color, const Qt::PenStyle &style, const int width)
{
	QCPGraph *graph = plot->addGraph();
	QPen pen(color);
	pen.setStyle(style);
	pen.setWidth(width);
	graph->setPen(pen);
	graph->setData(steps, data);
}
Exemple #5
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]);

}
void MainWindow::setupDateTest(QCustomPlot *customPlot)
{
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
	customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
	QCPGraph *g = customPlot->addGraph();
	g->addData(QDateTime(QDate(350,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 1);
	g->addData(QDateTime(QDate(650,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 2);
	g->addData(QDateTime(QDate(740,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 4);
	g->addData(QDateTime(QDate(1000,5,21), QTime(0, 0)).toMSecsSinceEpoch()/1000.0, 8);
	g->rescaleAxes();
#endif
}
Exemple #7
0
	QCPGraph* SensorDashboard::createGraph(const QString& name, const QColor& color)
	{
		QPen pen;
		pen.setBrush(color);

		QCPGraph *graph = mPlot->addGraph();
		graph->setName(name);
		graph->setLineStyle(QCPGraph::lsLine);
		graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone));
		graph->setPen(pen);

		return graph;
	}
Exemple #8
0
void DataExplorer::updateDetails() {
	//qDebug() << "SELECT!";
    ui->runPlot->clearPlottables();
	QVector<QString> labels;
	QVector<double> ticks;
	int colid = 0;
	switch (ui->detailType->currentIndex()) {
	  case 0:
		ui->runPlot->xAxis->setAutoTicks(true);
		ui->runPlot->xAxis->setAutoTickLabels(true);
		for (QCPAbstractPlottable *p : ui->selectEnvironment->selectedPlottables()) {
			int unitid = p->property("UID").toInt();
			int envid = p->property("EID").toInt();
			DataSeries v = exp->runs.keys().at(envid)->run(unitid,ui->runNo->value(),exp);
			QCPGraph *g = ui->runPlot->addGraph();
			g->setName(v.descriptor->name()+" @ "+exp->runs.keys().at(envid)->label);
			g->setProperty("Unit",v.descriptor->unit());
			g->setPen(origcols[colid++%origcols.size()]);
			g->setData(v.getTimestamps(),v.getValues());
		}
		break;
	  case 1:
		for (QCPAbstractPlottable *p : ui->selectEnvironment->selectedPlottables()) {
			int unitid = p->property("UID").toInt();
			int envid = p->property("EID").toInt();
			StatisticalSet vals = exp->runs.keys().at(envid)->integral(unitid,exp);
			QCPStatisticalBox* b = new QCPStatisticalBox(ui->runPlot->xAxis,ui->runPlot->yAxis);
			b->setData(colid,vals.min(),vals.quantile(0.25),vals.median(),vals.quantile(0.75),vals.max());
			b->setProperty("StdDev",vals.getStdDev());
			b->setProperty("avg",vals.avg());
			b->setProperty("avgTime",vals.avgTime());
			qWarning() << exp->data.at(unitid)->descriptor->name() <<  exp->runs.keys().at(envid)->label << vals.avg() << vals.avgTime() << vals.getStdDev();
			ui->runPlot->addPlottable(b);
			labels.append(QString("%1 @ %2").arg(exp->data.at(unitid)->descriptor->name(),exp->runs.keys().at(envid)->label));
			ticks.append(colid++);
			ui->runPlot->xAxis->setAutoTicks(false);
			ui->runPlot->xAxis->setAutoTickLabels(false);
			ui->runPlot->xAxis->setSubTickCount(0);
			ui->runPlot->xAxis->setTickLength(0, 4);
			ui->runPlot->xAxis->setTickLabelRotation(90);
			ui->runPlot->xAxis->setTickVector(ticks);
			ui->runPlot->xAxis->setTickVectorLabels(labels);
		}
		break;
	  case 2: break;
	}
    ui->runPlot->rescaleAxes();
    if (ui->axisFromZero->isChecked())
        ui->runPlot->yAxis->setRangeLower(0);
    ui->runPlot->replot();
}
void SCTPGraphDialog::drawTSNGraph()
{
    GList *listTSN = NULL,*tlist;
    tsn_t *tsn;
    guint8 type;
    guint32 tsnumber=0;

    if (direction == 1) {
        listTSN = g_list_last(selected_assoc->tsn1);
    } else {
        listTSN = g_list_last(selected_assoc->tsn2);
    }

    while (listTSN) {
        tsn = (tsn_t*) (listTSN->data);
        tlist = g_list_first(tsn->tsns);
        while (tlist)
        {
            type = ((struct chunk_header *)tlist->data)->type;
            if (type == SCTP_DATA_CHUNK_ID || type == SCTP_I_DATA_CHUNK_ID || type == SCTP_FORWARD_TSN_CHUNK_ID) {
                tsnumber = g_ntohl(((struct data_chunk_header *)tlist->data)->tsn);
                yt.append(tsnumber);
                xt.append(tsn->secs + tsn->usecs/1000000.0);
                ft.append(tsn->frame_number);
            }
            tlist = g_list_next(tlist);
        }
        listTSN = g_list_previous(listTSN);
    }

    QCPScatterStyle myScatter;
    myScatter.setShape(QCPScatterStyle::ssCircle);
    myScatter.setSize(3);

    int graphcount = ui->sctpPlot->graphCount();
    // create graph and assign data to it:

    // Add TSN graph
    if (xt.size() > 0) {
        QCPGraph *gr = ui->sctpPlot->addGraph();
        gr->setName(QString("TSN"));
        myScatter.setPen(QPen(Qt::black));
        myScatter.setBrush(Qt::black);
        ui->sctpPlot->graph(graphcount)->setScatterStyle(myScatter);
        ui->sctpPlot->graph(graphcount)->setLineStyle(QCPGraph::lsNone);
        ui->sctpPlot->graph(graphcount)->setData(xt, yt);
        typeStrings.insert(graphcount, QString(tr("TSN")));
    }
}
Exemple #10
0
void DataExplorer::pointInfo(QMouseEvent *event)
{
	QCPAbstractPlottable *plottable = ui->runPlot->plottableAt(event->localPos());
	if (!plottable) return;

	double x = ui->runPlot->xAxis->pixelToCoord(event->localPos().x());
	QToolTip::hideText();

	QCPGraph *graph = qobject_cast<QCPGraph*>(plottable);
	if (graph) {
		double key = 0;
		double value = 0;
		bool ok = false;
		double m = std::numeric_limits<double>::max();
		for (QCPData data : graph->data()->values()) {
			double d = qAbs(x - data.key);

			if(d < m) {
				key = data.key;
				value = data.value;

				ok = true;
				m = d;
			}
		}
		if (!ok) return;
		QToolTip::showText(event->globalPos(),
			tr("<center><b>%L1</b><br/>%L2 %L3@ %L4s</center>").
				arg(graph->name().isEmpty() ? "..." : graph->name()).
				arg(value).arg(graph->property("unit").toString()).
				arg(key),
			ui->runPlot, ui->runPlot->rect());
		return;
	}

	QCPStatisticalBox *graphBox = qobject_cast<QCPStatisticalBox*>(plottable);
	if (graphBox) {
		QToolTip::showText(event->globalPos(),
			tr("<center><b>%L1</b><br/></center>Max: %2<br/>Upper: %3<br/>Median: %4<br/>Lower: %5<br/>Min: %6<br/>StdDev: %7<br/>Avg: %8<br/>Avg Time: %9").
				arg(graphBox->name().isEmpty() ? "..." : graphBox->name()).
				arg(graphBox->maximum()).arg(graphBox->upperQuartile()).arg(graphBox->median()).
				arg(graphBox->lowerQuartile()).arg(graphBox->minimum()).
				arg(graphBox->property("StdDev").toDouble()).arg(graphBox->property("avg").toDouble()).
				arg(graphBox->property("avgTime").toDouble()),
			ui->runPlot, ui->runPlot->rect());
	}

}
void MainWindow::setupItemTracerTest_MyTest_addGrap(QCustomPlot *customPlot, QCPAxisRect* pAxisRect)
{


	QCPGraph *graph = customPlot->addGraph(pAxisRect->axis(QCPAxis::atBottom), pAxisRect->axis(QCPAxis::atLeft));
	int n = 200;
	QVector<double> x(n), y(n);
	for (int nIndex=0; nIndex<n; ++nIndex)
	{
		//x[i] = 0.5+i/(double)n*4;
		unsigned int nTimeNow = 0;
		double xValue = 0.5 + nIndex/(double)n*4;
		nTimeNow = QDateTime::currentDateTime().toTime_t() + nIndex;
		x[nIndex] = nTimeNow;
		//y[nIndex] = qSin(x[nIndex])+1.5;//
		y[nIndex] = qSin(xValue)+1.5;//
	}
	graph->setData(x, y);
}
void ConvertProfile(TProfile* prof, QCPGraph &graph){
  //how we put the profile histogram in Qt.
  //passing the graph to alter is just easier :)
  QVector<double> xvals,yvals,xerrs, yerrs;
  int nbins = prof->GetNbinsX();
  //get the values
  for(int i=0; i<nbins;++i){
    xvals.push_back(prof->GetBinCenter(i+1));
    yvals.push_back(prof->GetBinContent(i+1));
    xerrs.push_back(prof->GetBinWidth(i+1)/2.);
    yerrs.push_back(prof->GetBinError(i+1));
  }
  
  graph.setData(xvals, yvals);
  graph.setDataValueError(xvals, yvals, yerrs);//symmetric errors, only in y.
  graph.setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
  graph.setPen(QPen(QColor(120, 120, 120), 2));
  graph.setLineStyle(QCPGraph::LineStyle::lsNone);
  return;
}
Exemple #13
0
void RealTimePlot::updateChannel(int index)
{
    Channel *chan = channels[index];

    // Get parameters from channel
    QCPGraph *line = chan->getPtrGraphLine();
    QCPGraph *marker = chan->getPtrGraphMarker();
    QColor color = chan->getGraphColor();

    // Set parameters of line graph
    line->setPen(QPen(color));
    line->setLineStyle(QCPGraph::lsLine);
    line->setVisible(chan->getVisible(LINE));

    // Set parameters of marker graph
    marker->setName(chan->getName());
    marker->setPen(QPen(color));
    marker->setLineStyle(QCPGraph::lsNone);
    marker->setScatterStyle(chan->getMarkerStyle());
    marker->setVisible(chan->getVisible(MARKER));
}
void ScatterWidget::setData(const std::vector<PointD> &data, string legend)
{
    QCPGraph *graph = NULL;
    int nG = ui->scatter->graphCount();
    for(int i=0; i<nG; i++)
    {
        if(ui->scatter->graph(i)->name() == QString::fromStdString(legend))
        {
            graph = ui->scatter->graph(i);
            break;
        }
    }

    if(!graph)
    {
        graph = ui->scatter->addGraph();
        // ----------------------- Scatter Configuration ---------------------------
        graph->setName(QString::fromStdString(legend));
        QColor color_ = colorManager.getNewDifferentColor();
        graph->setPen(QPen(color_));
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssPlusCircle, 4));
        ui->scatter->legend->setVisible(true);
    }

    double min_x =  INFINITY, min_y =  INFINITY;
    double max_x = -INFINITY, max_y = -INFINITY;

    QVector<QCPGraphData> q_data(data.size());
    for(unsigned int i=0; i<data.size(); i++)
    {
        q_data[i] = QCPGraphData(data[i].x, data[i].y);

        if(ui->recButton->isChecked())
        {
            vector<double> vec2_double(2);
            vec2_double[0] = data[i].x;
            vec2_double[1] = data[i].y;
            vector<string> vec2_string(2);
            vec2_string[0] = legend + "_x";
            vec2_string[1] = legend + "_y";
            logger.addLogCsv(graph->dataCount(), vec2_string, vec2_double);
        }

        max_x = qMax(data[i].x, ui->scatter->xAxis->range().upper);
        min_x = qMin(data[i].x, ui->scatter->xAxis->range().lower);
        max_y = qMax(data[i].y, ui->scatter->yAxis->range().upper);
        min_y = qMin(data[i].y, ui->scatter->yAxis->range().lower);
    }

    graph->data()->set(q_data);
    ui->scatter->xAxis->setRange(min_x, max_x);
    ui->scatter->yAxis->setRange(min_y, max_y);
    ui->scatter->replot();
}
void MainWindow::on_listView_clicked(const QModelIndex &index)
{
    //QModelIndex a = ui->listView->selectedIndexes().back();
    QVariant selected = dataModel->compNameList->data(index,Qt::DisplayRole);
    dataModel->dataViewComp = selected.toString();
    QVector<double> dataViewPrice = dataModel->priceBuff.value(selected.toString());
    QVector<double> xval;
    QVector<double> baseVal;
    if(dataViewPrice.empty()) return;
    double min = dataViewPrice[0];
    for(auto &i : dataViewPrice) min = std::fmin(min,i);
    for(int i = 0; i<dataViewPrice.size(); i++){
        xval<<i;
        baseVal<<min;
    }
    QCustomPlot* p = ui->qcpDataView;;
    p->clearGraphs();

    QCPGraph* timeline = new QCPGraph(p->xAxis,p->yAxis);
    timeline->addData(xval,dataViewPrice);
    QCPGraph* base = new QCPGraph(p->xAxis,p->yAxis);
    base->setData(xval,baseVal);

    p->addPlottable(timeline);
    p->addPlottable(base);

    timeline->setChannelFillGraph(base);
    timeline->setPen(QPen(QColor(0,0,0,0)));
    timeline->setBrush(QColor(0,0,255,100));

    //QVector<double> ticks;
    QVector<QString> labels;

    int L = this->dataModel->dateBuff.values()[0].size()-1;
    int len = 6;
    float step = (float)L/(float)len;
    for(int i = 0; i<= len; i++){
        labels<<this->dataModel->dateBuff.values()[0][i*step].toString("MM/yy");
    }

    p->xAxis->setTickVectorLabels(labels);
    p->xAxis->setAutoTicks(true);
    p->xAxis->setAutoTickLabels(false);

    p->xAxis->setTickLabelRotation(-60);
    //p->xAxis->setSubTickCount(0);
    //p->xAxis->setTickLength(0, len-1);

    p->xAxis->grid()->setVisible(true);
    //p->xAxis->setRange(0, len-2);
    //p->xAxis->setTickVector(ticks);

    p->rescaleAxes();
    p->replot();
}
Exemple #16
0
void OdroidReader::updateCurve(int row, int col) {
	if (col != 0) return;

	bool enable = ui->sensors->item(row,col)->checkState() == Qt::Checked;
	if (enable && graphs.at(row) == nullptr) {
		if (origcols.count() == 0) {
			ui->sensors->item(row,col)->setCheckState(Qt::Unchecked);
			return;
		}
		QColor color = origcols.takeFirst();
		QCPGraph* graph = ui->globalPlot->addGraph();
		DataSeries* series =  data[rowMap[row]];
		graph->setName(series->descriptor->name());
		graph->setProperty("unit",series->descriptor->unit());
		graph->setPen(color);
		graph->setData(series->getTimestamps(), series->getValues());
		connect(series,&DataSeries::newValue,[graph,this](double time, double value) {
			graph->addData(time,value);
			ui->globalPlot->rescaleAxes();
			ui->globalPlot->yAxis->scaleRange(1.2,ui->globalPlot->yAxis->range().center());
			ui->globalPlot->replot();
		});
		graphs[row] = graph;
		ui->sensors->item(row,col)->setBackgroundColor(color);
	} else if (!enable && graphs.at(row) != nullptr){
		disconnect(data.at(rowMap[row]),SIGNAL(newValue(double,double)),0,0);
		origcols.push_front(graphs.at(row)->pen().color());
		ui->globalPlot->removeGraph(graphs.at(row));
		graphs[row] = nullptr;
		ui->sensors->item(row,col)->setBackgroundColor(Qt::white);
	}
void MainWindow::setupAdaptiveSamplingTest(QCustomPlot *customPlot)
{
	qsrand(1);
	QCPGraph *g = customPlot->addGraph();
	int n = 200000;
	QVector<double> x, y;
	x << -6;
	y << 2;
	for (int i=0; i<n/2; ++i)
	{
		x << i/(double)(n/2-1)*4-5;
		if (qrand()%(n/25) == 0)
			y << qrand()/(double)RAND_MAX*7; // generate outliers (must be preserved in adaptive-sampling-algorithm)
		else
			y << qCos(qrand()/(double)RAND_MAX*2*M_PI)*qSqrt(-2*qLn(qrand()/(double)RAND_MAX)) + 5*qSin(x[i]);
	}
	x << 0.5;
	y << 2;
	for (int i=0; i<n/2; ++i)
	{
		x << i/(double)(n/2-1)*4+1;
		if (qrand()%(n/25) == 0)
			y << qrand()/(double)RAND_MAX*7; // generate outliers (must be preserved in adaptive-sampling-algorithm)
		else
			y << qCos(qrand()/(double)RAND_MAX*2*M_PI)*qSqrt(-2*qLn(qrand()/(double)RAND_MAX)) + qSin(5*x[i]);
	}
	x << 6;
	y << -1;
	g->setData(x, y);
	//g->setScatterStyle(QCPScatterStyle::ssPlus);
	//g->setLineStyle(QCPGraph::lsNone);
	g->setAdaptiveSampling(true);

	customPlot->setPlottingHint(QCP::phFastPolylines, true);
	customPlot->rescaleAxes();
	customPlot->xAxis->scaleRange(1, customPlot->xAxis->range().center());
	customPlot->yAxis->scaleRange(1, customPlot->yAxis->range().center());
}
void ScatterWidget::addPacket(const ScatterPacket &packet)
{
    QCPGraph *graph = NULL;
    int nG = ui->scatter->graphCount();
    for(int i=0; i<nG; i++)
    {
        if(ui->scatter->graph(i)->name() == QString::fromStdString(packet.legend))
        {
            graph = ui->scatter->graph(i);
            break;
        }
    }

    if(!graph)
    {
        graph = ui->scatter->addGraph();
        // ----------------------- Scatter Configuration ---------------------------
        graph->setName(QString::fromStdString(packet.legend));
        QColor color_ = colorManager.getNewDifferentColor();
        graph->setPen(QPen(color_));
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssPlusCircle, 4));
        ui->scatter->legend->setVisible(true);
    }

    graph->addData(packet.point.x, packet.point.y);
    //if(packet.point.x > ui->scatter->xAxis->max)

    double max_x = qMax(packet.point.x, ui->scatter->xAxis->range().upper);
    double min_x = qMin(packet.point.x, ui->scatter->xAxis->range().lower);
    double max_y = qMax(packet.point.y, ui->scatter->yAxis->range().upper);
    double min_y = qMin(packet.point.y, ui->scatter->yAxis->range().lower);

    ui->scatter->xAxis->setRange(min_x, max_x);
    ui->scatter->yAxis->setRange(min_y, max_y);

    if(realTimePlot)
        ui->scatter->replot();
    else
        ui->scatter->replot(QCustomPlot::rpQueuedReplot);

    if(ui->recButton->isChecked())
    {
        vector<double> vec2_double(2);
        vec2_double[0] = packet.point.x;
        vec2_double[1] = packet.point.y;
        vector<string> vec2_string(2);
        vec2_string[0] = packet.legend + "_x";
        vec2_string[1] = packet.legend + "_y";
        logger.addLogCsv(graph->dataCount(), vec2_string, vec2_double);
    }
}
  void DataBrokerPlotter::createNewPlot() {
    char text[50];
    // create first curve
    std::string cfgName = name;
    std::string tmpString;
    Plot *newPlot = new Plot;
    QCPGraph *newCurve = qcPlot->addGraph();

    newCurve->setAntialiasedFill(false);

    newPlot->dpId = nextPlotId++;
    sprintf(text, "graph%02d", newPlot->dpId);
    newPlot->name = std::string(text);

    cfgName.append("/");
    cfgName.append(newPlot->name);
    cfgName.append("/");

    newCurve->setPen( QPen(colors[(newPlot->dpId-1) % 8], 0.5) );
    newCurve->setLineStyle( QCPGraph::lsLine );

    newPlot->curve = newCurve;
    
    plots.push_back(newPlot);

    // add datapackage for first plot
    mars::data_broker::DataPackage dbPackageX;// = new mars::data_broker::DataPackage;
    mars::data_broker::DataPackage dbPackageY;// = new mars::data_broker::DataPackage;
    dbPackageX.add("xvalue", (double)0.0);
    dbPackageY.add("yvalue", (double)0.0);
    //dbPackage->add("yvalue", (double)0.0);

    tmpString = name;
    tmpString.append("/");
    tmpString.append(text);
    tmpString.append("/xvalue");
    dataBroker->pushData("data_broker_plotter", tmpString,
                         dbPackageX, this,
                         mars::data_broker::DATA_PACKAGE_READ_WRITE_FLAG);
    dataBroker->registerSyncReceiver(this, "data_broker_plotter",
                                     tmpString, newPlot->dpId*10);
    tmpString = name;
    tmpString.append("/");
    tmpString.append(text);
    tmpString.append("/yvalue");
    dataBroker->pushData("data_broker_plotter", tmpString,
                         dbPackageY, this,
                         mars::data_broker::DATA_PACKAGE_READ_WRITE_FLAG);
    dataBroker->registerSyncReceiver(this, "data_broker_plotter",
                                     tmpString, newPlot->dpId*10+1);
    newPlot->gotData = 0;
    
    tmpString = cfgName;
    tmpString.append("sTime");
    newPlot->sTime = cfg->getOrCreateProperty("DataBrokerPlotter",
                                              tmpString.c_str(),
                                              (double)0.0, this);
    tmpString = cfgName;
    tmpString.append("xRange");
    newPlot->xRange = cfg->getOrCreateProperty("DataBrokerPlotter",
                                               tmpString.c_str(),
                                               (double)0.0, this);
    tmpString = cfgName;
    tmpString.append("yScale");
    newPlot->yScale = cfg->getOrCreateProperty("DataBrokerPlotter",
                                               tmpString.c_str(),
                                               (double)1.0, this);
    tmpString = cfgName;
    tmpString.append("yOffset");
    newPlot->yOffset = cfg->getOrCreateProperty("DataBrokerPlotter",
                                                tmpString.c_str(),
                                                (double)0.0, this);

    cfgParamIdToPlot[newPlot->sTime.paramId] = newPlot;
    cfgParamIdToPlot[newPlot->xRange.paramId] = newPlot;
    cfgParamIdToPlot[newPlot->yScale.paramId] = newPlot;
    cfgParamIdToPlot[newPlot->yOffset.paramId] = newPlot;
    newPlot->cfgParamIdProp[newPlot->sTime.paramId] = &newPlot->sTime;
    newPlot->cfgParamIdProp[newPlot->xRange.paramId] = &newPlot->xRange;
    newPlot->cfgParamIdProp[newPlot->yScale.paramId] = &newPlot->yScale;
    newPlot->cfgParamIdProp[newPlot->yOffset.paramId] = &newPlot->yOffset;
  }
void ScatterPlotWidget::updatePlot(){
    ui->customPlot->clearGraphs();//clearPlottables();

    if(selectedTrips == NULL)
        return;

    //
    ExtraField field;
    switch(attrib1){
    case(FARE_AMOUNT):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Fare Amount (US$)"));
        break;
    case(TIP_AMOUNT):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Tip Amount (US$)"));
        break;
    case(DURATION):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Duration (min)"));
        break;
    case(DISTANCE):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Distance (mi)"));
        break;
    case(TOLL_AMOUNT):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Toll Amount (US$)"));
        break;
    case(AVG_SPEED):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Avg Speed (mi/h)"));
        break;
    case(TIME_OF_DAY):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Hour of day"));
        break;
    case(FIELD1):
        field = Global::getInstance()->getExtraField(0);
        ui->customPlot->xAxis->setLabel(field.axisLabel);
        break;
    case(FIELD2):
        field = Global::getInstance()->getExtraField(1);
        ui->customPlot->xAxis->setLabel(field.axisLabel);
        break;
    case(FIELD3):
        field = Global::getInstance()->getExtraField(2);
        ui->customPlot->xAxis->setLabel(field.axisLabel);
        break;
    case(FIELD4):
        field = Global::getInstance()->getExtraField(3);
        ui->customPlot->xAxis->setLabel(field.axisLabel);
        break;
    default:
        assert(false);
        break;
    }

    //
    switch(attrib2){
    case(FARE_AMOUNT):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Fare Amount (US$)"));
        break;
    case(TIP_AMOUNT):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Tip Amount (US$)"));
        break;
    case(DURATION):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Duration (min)"));
        break;
    case(DISTANCE):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Distance (mi)"));
        break;
    case(TOLL_AMOUNT):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Toll Amount (US$)"));
        break;
    case(AVG_SPEED):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Avg Speed (mi/h)"));
        break;
    case(TIME_OF_DAY):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Hour of day"));
        break;
    case(FIELD1):
        field = Global::getInstance()->getExtraField(0);
        ui->customPlot->yAxis->setLabel(field.axisLabel);
        break;
    case(FIELD2):
        field = Global::getInstance()->getExtraField(1);
        ui->customPlot->yAxis->setLabel(field.axisLabel);
        break;
    case(FIELD3):
        field = Global::getInstance()->getExtraField(2);
        ui->customPlot->yAxis->setLabel(field.axisLabel);
        break;
    case(FIELD4):
        field = Global::getInstance()->getExtraField(3);
        ui->customPlot->yAxis->setLabel(field.axisLabel);
        break;
    default:
        assert(false);
        break;
    }

    //
    bool buildGlobalPlot = (selectionGraph->isEmpty());

    set<Group> groups;
    map<Group,vector<SelectionGraphNode*> > mapGroupToNodes;
    map<Group,vector<SelectionGraphEdge*> > mapGroupToEdges;
    set<Group>::iterator groupIterator;
    selectionGraph->groupNodesAndEdgeByColor(groups,mapGroupToNodes,mapGroupToEdges);
    map<Group,QCPGraph*> mapGroupGraph;

    //
    set<Group> notEmptyGroups;
    map<Group,vector<SelectionGraphNode*> > tempMapGroupToNodes;

    if(buildGlobalPlot){
        QPen pen;
        QCPGraph* graph = ui->customPlot->addGraph();
        QColor color(0,0,0);
        mapGroupGraph[Group(color)] = graph;
        color.setAlphaF(0.05);
        pen.setColor(color);
        graph->setPen(pen);
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCP::ssDisc);
        graph->setScatterSize(10);
    }
    else{
        //
        for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
            vector<SelectionGraphNode*> &groupNodes = mapGroupToNodes[*groupIterator];
            vector<SelectionGraphNode*> validGroupNodes;
            int numGroupNodes = groupNodes.size();

            for(int i = 0 ; i < numGroupNodes ; ++i){
                SelectionGraphNode* node = groupNodes.at(i);
                if(node->inDegree() + node->outDegree() == 0)
                    validGroupNodes.push_back(node);
            }

            vector<SelectionGraphEdge*> &groupEdges = mapGroupToEdges[*groupIterator];
            if(groupEdges.size() + validGroupNodes.size() > 0){
                notEmptyGroups.insert(*groupIterator);
                tempMapGroupToNodes[*groupIterator] = validGroupNodes;
            }
        }

        groups.clear();
        groups = notEmptyGroups;
        mapGroupToNodes.clear();
        mapGroupToNodes = tempMapGroupToNodes;

        //
        for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
            QPen pen;
            QCPGraph* graph = ui->customPlot->addGraph();
            graph->setLineStyle(QCPGraph::lsNone);
            graph->setScatterStyle(QCP::ssDisc);
            graph->setScatterSize(10);

            Group group = *groupIterator;

            QColor color = group.getColor();
            mapGroupGraph[group] = graph;
            color.setAlphaF(0.3);
            pen.setColor(color);
            graph->setPen(pen);
        }
    }

    //int numberOfTrip = selectedTrips->size();
    map<Group,pair<QVector<double>,QVector<double> > > mapGroupData;
    if(buildGlobalPlot){
        int numberOfTrips = selectedTrips->size();
        //QVector<double> x(numberOfTrips), y(numberOfTrips);
        QVector<double> x, y;
        mapGroupData[QColor(0,0,0)] = make_pair(x,y);
    }
    else{
        QVector<double> x, y;
        for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
            Group group = *groupIterator;

            mapGroupData[group.getColor()] = make_pair(x,y);

        }
    }

    // add graphs with different scatter styles:
    KdTrip::TripSet::iterator it = selectedTrips->begin();
    for (; it != selectedTrips->end(); ++it) {
        const KdTrip::Trip * trip = *it;
        QPointF coords = getCoords(trip);

        if(buildGlobalPlot){
            pair<QVector<double>,QVector<double> > &data =
                    mapGroupData[QColor(0,0,0)];
            QVector<double> &x = data.first;
            QVector<double> &y = data.second;
            x << coords.x();
            y << coords.y();
        }
        else{
            for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
                Group currentGroup = *groupIterator;

                assert(mapGroupToNodes.count(currentGroup) > 0 && mapGroupToEdges.count(currentGroup) > 0);

                if(tripSatisfiesConstraints(trip, mapGroupToNodes[currentGroup],mapGroupToEdges[currentGroup])){
                    pair<QVector<double>,QVector<double> > &data =
                            mapGroupData[currentGroup.getColor()];
                    QVector<double> &x = data.first;
                    QVector<double> &y = data.second;
                    x << coords.x();
                    y << coords.y();
                    continue; // make sure the point is only added once
                }
            }
        }
    }

    if(buildGlobalPlot){
        pair<QVector<double>,QVector<double> > &data =
                mapGroupData[QColor(0,0,0)];
        QVector<double> &x = data.first;
        QVector<double> &y = data.second;
        QCPGraph* graph = mapGroupGraph[QColor(0,0,0)];
        graph->setData(x, y);
        graph->rescaleAxes(true);
    }
    else{
        for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
            Group currentGroup = *groupIterator;
            pair<QVector<double>,QVector<double> > &data =
                    mapGroupData[currentGroup.getColor()];
            QVector<double> &x = data.first;
            QVector<double> &y = data.second;
            QCPGraph* graph = mapGroupGraph[currentGroup.getColor()];
            graph->setData(x, y);
            graph->rescaleAxes(true);
        }
    }

    //
    int numGraphs = ui->customPlot->graphCount();
    for(int i = 0 ; i < numGraphs ; ++i){
        ui->customPlot->graph(i)->rescaleAxes(false,true);
    }
    //ui->customPlot->yAxis->scaleRange(1.1, ui->customPlot->yAxis->range().center());
    ui->customPlot->setRangeDrag(Qt::Horizontal|Qt::Vertical);
    ui->customPlot->setRangeZoom(Qt::Horizontal|Qt::Vertical);
    ui->customPlot->setInteractions(QCustomPlot::iRangeDrag | QCustomPlot::iRangeZoom | QCustomPlot::iSelectAxes |
                                    QCustomPlot::iSelectLegend | QCustomPlot::iSelectPlottables | QCustomPlot::iSelectTitle);

    //
    ui->customPlot->replot();
}
void SCTPGraphArwndDialog::drawArwndGraph()
{
    GList *listSACK = NULL, *tlist;
    struct sack_chunk_header *sack_header;
    struct nr_sack_chunk_header *nr_sack_header;
    tsn_t *tsn;
    guint8 type;
    guint32 arwnd=0;

    if (direction == 1) {
        listSACK = g_list_last(selected_assoc->sack1);
        startArwnd = selected_assoc->arwnd1;
    } else {
        listSACK = g_list_last(selected_assoc->sack2);
        startArwnd = selected_assoc->arwnd2;
    }
    while (listSACK) {
        tsn = (tsn_t*) (listSACK->data);
        tlist = g_list_first(tsn->tsns);
        while (tlist) {
            type = ((struct chunk_header *)tlist->data)->type;
            if (type == SCTP_SACK_CHUNK_ID) {
                sack_header =(struct sack_chunk_header *)tlist->data;
                arwnd = g_ntohl(sack_header->a_rwnd);
            } else if (type == SCTP_NR_SACK_CHUNK_ID) {
                nr_sack_header =(struct nr_sack_chunk_header *)tlist->data;
                arwnd = g_ntohl(nr_sack_header->a_rwnd);
            }
            ya.append(arwnd);
            xa.append(tsn->secs + tsn->usecs/1000000.0);
            fa.append(tsn->frame_number);
            tlist = g_list_next(tlist);
        }
        listSACK = g_list_previous(listSACK);
    }

    QCPScatterStyle myScatter;
    myScatter.setShape(QCPScatterStyle::ssCircle);
    myScatter.setSize(3);

    // create graph and assign data to it:

    // Add Arwnd graph
    if (xa.size() > 0) {
        QCPGraph *gr = ui->sctpPlot->addGraph(ui->sctpPlot->xAxis, ui->sctpPlot->yAxis);
        gr->setName(QString(tr("Arwnd")));
        myScatter.setPen(QPen(Qt::red));
        myScatter.setBrush(Qt::red);
        ui->sctpPlot->graph(0)->setScatterStyle(myScatter);
        ui->sctpPlot->graph(0)->setLineStyle(QCPGraph::lsNone);
        ui->sctpPlot->graph(0)->setData(xa, ya);
    }

    ui->sctpPlot->xAxis->setLabel(tr("time [secs]"));
    ui->sctpPlot->yAxis->setLabel(tr("Advertised Receiver Window [Bytes]"));

    // set axes ranges, so we see all data:
    QCPRange myXArwndRange(0, (selected_assoc->max_secs+1));
   // QCPRange myXArwndRange(0, 1);
    QCPRange myYArwndRange(0, startArwnd);
    ui->sctpPlot->xAxis->setRange(myXArwndRange);
    ui->sctpPlot->yAxis->setRange(myYArwndRange);
}
void AP2DataPlot2D::plotMouseMove(QMouseEvent *evt)
{
    if (!ui.showValuesCheckBox->isChecked())
    {
        return;
    }
    QString newresult = "";
    for (int i=0;i<m_graphClassMap.keys().size();i++)
    {

        double key=0;
        double val=0;
        QCPGraph *graph = m_graphClassMap.value(m_graphClassMap.keys()[i]).graph;
        graph->pixelsToCoords(evt->x(),evt->y(),key,val);
        if (i == 0)
        {
            if (m_logLoaded)
            {
                newresult.append("Log Line: " + QString::number(key,'f',0) + "\n");
            }
            else
            {
                newresult.append("Time: " + QDateTime::fromMSecsSinceEpoch(key * 1000.0).toString("hh:mm:ss") + "\n");
            }
        }
        if (m_graphClassMap.keys()[i] == "MODE")
        {
            if (m_graphClassMap.value(m_graphClassMap.keys()[i]).modeMap.keys().size() > 1)
            {
                for (QMap<double,QString>::const_iterator modemapiterator = m_graphClassMap.value(m_graphClassMap.keys()[i]).modeMap.constBegin();modemapiterator!=m_graphClassMap.value(m_graphClassMap.keys()[i]).modeMap.constEnd();modemapiterator++)
                {
                    if (modemapiterator.key() < key)
                    {
                        if (modemapiterator==m_graphClassMap.value(m_graphClassMap.keys()[i]).modeMap.constEnd()-1)
                        {
                            //We're at the end, use the end
                            newresult.append(m_graphClassMap.keys()[i] + ": " + modemapiterator.value() + ((i == m_graphClassMap.keys().size()-1) ? "" : "\n"));
                        }
                        else if ((modemapiterator+1).key() > key)
                        {
                            //This only gets hit if we're not at the end, and we have the proper value
                            newresult.append(m_graphClassMap.keys()[i] + ": " + modemapiterator.value() + ((i == m_graphClassMap.keys().size()-1) ? "" : "\n"));
                            break;
                        }
                    }
                }
            }
            else if (m_graphClassMap.value(m_graphClassMap.keys()[i]).modeMap.keys().size() == 1)
            {
                newresult.append(m_graphClassMap.keys()[i] + ": " + m_graphClassMap.value(m_graphClassMap.keys()[i]).modeMap.begin().value() + ((i == m_graphClassMap.keys().size()-1) ? "" : "\n"));
            }
            else
            {
                newresult.append(m_graphClassMap.keys()[i] + ": " + "Unknown" + ((i == m_graphClassMap.keys().size()-1) ? "" : "\n"));
            }
        }
        else if (graph->data()->contains(key))
        {
            newresult.append(m_graphClassMap.keys()[i] + ": " + QString::number(graph->data()->value(key).value,'f',4) + ((i == m_graphClassMap.keys().size()-1) ? "" : "\n"));
        }
        else if (graph->data()->lowerBound(key) != graph->data()->constEnd())
        {
            newresult.append(m_graphClassMap.keys()[i] + ": " + QString::number((graph->data()->lowerBound(key).value().value),'f',4) + ((i == m_graphClassMap.keys().size()-1) ? "" : "\n"));
        }
        else
        {
            newresult.append(m_graphClassMap.keys()[i] + ": " + "ERR" + ((i == m_graphClassMap.keys().size()-1) ? "" : "\n"));
        }
    }
    QToolTip::showText(QPoint(evt->pos().x() + m_plot->x(),evt->pos().y()+m_plot->y()),newresult);
}
Exemple #23
0
void Dialog::mkSensorModel()
{
	QCPGraph * gr;
	QPen pn;

	double simTime = 60.0;
	double simStepTime = 0.1;

	double tempStart = 25.0;
	double tempCurrent = tempStart;
	double tempSet = 35.0;
	double tempDeltaPrev = 0.0;

	int normalFixDeep = 5;

	int steps = simTime / simStepTime;

	QVector<double> xTime(steps), yTemp(steps), yTempSet(steps);
	QVector<double> normalValues(normalFixDeep);
	normalValues.fill(0);

	QVector<double> tempLabels;
	for (int x=10; x<=50; x+=5) tempLabels.push_back(x);

	QVector<double> timeLabels;
	for (int x=0; x<=simTime; x+=5) timeLabels.push_back(x);

	for (int x=0; x<steps; x++)
	{
		// Calc new temp value
		double tempApply = 0.0; // No change
		double tempDelta = std::abs(tempCurrent - tempSet);
		double stepDir = (tempCurrent < tempSet) ? 1.0 : -1.0;
		if (0.1 < tempDelta)
		{
			if (tempDelta > 10)
			{
				tempApply = 0.19 * 1.0;
			} else {
				tempApply = 0.2 * (1.0 * (tempDelta/10.0) );
			}

			// if (tempApply < 0.01) tempApply = 0.01;

			// qDebug() << tempApply;

			tempApply = tempApply * stepDir;

			// Calc normalzied value
			double lastSum = 0;
			for (int x=0; x<normalFixDeep; x++) lastSum += normalValues[x];
			tempApply = (lastSum + tempApply) / ((double)normalFixDeep + 1.0);

			tempDeltaPrev = tempApply;
			tempCurrent = tempCurrent + tempApply;
			qDebug() << tempCurrent;
		}

		normalValues.push_back(tempApply);
		normalValues.pop_front();

		xTime[x] = (double)x * simStepTime;

		if (10.0 == xTime[x]) tempSet = 40.0;
		if (40.0 == xTime[x]) tempSet = 30.0;

		yTempSet[x] = tempSet;
		yTemp[x] = tempCurrent;
	}

	gr = ui->plot->addGraph();
	gr->setData(xTime, yTemp);
	pn.setColor(Qt::red);
	pn.setWidth(3);
	gr->setPen(pn);
	gr->setName("Реальное значение");

	gr = ui->plot->addGraph();
	gr->setData(xTime, yTempSet);
	pn.setColor(0x008080);
	pn.setWidth(1);
	pn.setStyle(Qt::DashLine);
	gr->setPen(pn);
	gr->setName("Конечное значение");




	ui->plot->xAxis->setLabel("Время, сек");
	ui->plot->xAxis->setRange(0, simTime);
	ui->plot->xAxis->setAutoTicks(false);
	ui->plot->xAxis->setTickVector(timeLabels);

	ui->plot->yAxis->setLabel("Температура, °C");
	ui->plot->yAxis->setRange(20, 50);
	ui->plot->yAxis->setAutoTicks(false);
	ui->plot->yAxis->setTickVector(tempLabels);

	ui->plot->legend->setVisible(true);

	ui->plot->replot();
	ui->plot->savePdf("graph-boiler.pdf", false, 800, 400);
}
Exemple #24
0
void Dialog::mkGraph()
{
	QCPGraph * gr;
	QPen pn;

	QVector<double> timeLabels, tempLabels, drosselLabels;
	for (int x=0; x<mdl.simTime; x+=10) timeLabels.push_back(x);
	for (int x=0; x<=80; x+=5) tempLabels.push_back(x);
	for (int x=0; x<=120; x+=10) drosselLabels.push_back(x);

	gr = ui->plot->addGraph();
	gr->setData(mdl.xTime, mdl.yTempOutput);
	pn.setColor(Qt::red);
	pn.setWidth(3);
	gr->setPen(pn);
	gr->setName("Реальное значение, °C");

	gr = ui->plot->addGraph();
	gr->setData(mdl.xTime, mdl.yTempSet);
	pn.setColor(0x0000FF);
	pn.setWidth(2);
	pn.setStyle(Qt::DotLine);
	gr->setPen(pn);
	gr->setName("Конечное значение, °C");

	gr = ui->plot->addGraph();
	gr->setData(mdl.xTime, mdl.yTempCurrent);
	pn.setColor(0x808000);
	pn.setWidth(2);
	pn.setStyle(Qt::SolidLine);
	gr->setPen(pn);
	gr->setName("Желаемая температура, °C");

	gr = ui->plot->addGraph(0, ui->plot->yAxis2);
	gr->setData(mdl.xTime, mdl.yServoPos);
	pn.setColor(0x006600);
	pn.setWidth(2);
	pn.setStyle(Qt::DotLine);
	gr->setPen(pn);
	gr->setName("Дроссель, %");

	gr = ui->plot->addGraph(0, ui->plot->yAxis2);
	gr->setData(mdl.xTime, mdl.yPressure);
	pn.setColor(0x800080);
	pn.setWidth(2);
	pn.setStyle(Qt::SolidLine);
	gr->setPen(pn);
	gr->setName("Сила нагрева, %");

	ui->plot->xAxis->setLabel("Время, сек");
	ui->plot->xAxis->setRange(0, mdl.simTime);
	ui->plot->xAxis->setAutoTicks(false);
	ui->plot->xAxis->setTickVector(timeLabels);
	//ui->plot->xAxis->setAutoTickCount(15);
	ui->plot->xAxis->setSubTickCount(10);

	ui->plot->yAxis->setLabel("Температура, °C");
	ui->plot->yAxis->setRange(20, 80);
	ui->plot->yAxis->setAutoTicks(false);
	ui->plot->yAxis->setTickVector(tempLabels);
	ui->plot->yAxis->setSubTickCount(5);

	ui->plot->yAxis2->setLabel("Параметры, %");
	ui->plot->yAxis2->setRange(0, 150);
	ui->plot->yAxis2->setVisible(true);
	ui->plot->yAxis2->setAutoTicks(false);
	ui->plot->yAxis2->setTickVector(drosselLabels);

	ui->plot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignLeft|Qt::AlignTop);
	ui->plot->legend->setVisible(true);

	mdl.reset();
	mdl.tempCurrent = 40;
	mdl.pressureCoef = 1.0;
	repaintGraph("ideal");
/*
	mdl.reset();
	mdl.simTime = 180;
	mdl.tempCurrent = 35;
	mdl.pressureCoef = 1.2;
	mdl.paramsChanged.push_back(ParamChange(20.0, 0, 40));
	repaintGraph("hotrun");

	mdl.reset();
	mdl.tempCurrent = 35;
	mdl.pressureCoef = 1.2;
	mdl.paramsChanged.push_back(ParamChange(20.0, 0, 30));
	repaintGraph("hotrun-low");
// return;

	mdl.reset();
	mdl.tempCurrent = 45;
	mdl.pressureCoef = 0.5;
	mdl.paramsChanged.push_back(ParamChange(20.0, 0, 40));
	mdl.paramsChanged.push_back(ParamChange(30.0, 1.2, 0));
	repaintGraph("plow-hi");

	mdl.reset();
	mdl.tempCurrent = 45;
	mdl.pressureCoef = 0.5;
	mdl.paramsChanged.push_back(ParamChange(30.0, 0.8, 0));
	repaintGraph("plow");

	mdl.reset();
	mdl.tempOutput = 40;
	mdl.tempCurrent = 30;
	mdl.paramsChanged.push_back(ParamChange(50.0, 0.8, 0));
	repaintGraph("hotstart");

	mdl.reset();
	mdl.simTime = 180;
	mdl.tempCurrent = 30;
	mdl.paramsChanged.push_back(ParamChange(20.0, 0.8, 0));
	mdl.paramsChanged.push_back(ParamChange(40.0, 0, 40));
	mdl.paramsChanged.push_back(ParamChange(50.0, 0.9, 0));
	mdl.paramsChanged.push_back(ParamChange(90.0, 1.1, 0));
	mdl.paramsChanged.push_back(ParamChange(130.0, 1.0, 0));
	repaintGraph("longrun");

	// ui->plot->savePdf("graph-test.pdf", false, 800, 600);

	// qDebug() << QImageWriter::supportedImageFormats();
	*/
}
Exemple #25
0
void Dialog::mkSensor()
{

    QCPGraph * gr;
    QPen pn;





    int steps = (20) + 1;
    double stepTemp = 0.47;

    QVector<double> xLabels;
    QVector<double> yLabels;
    QVector<double> xD(steps), yD(steps),yDlin(steps);

    for (int x=0; x<steps; x++)
    {
        //xD[x] = 30.0 + (stepTemp * (double)x) + 0.5 * ((double)(100 - qrand()%200) / 100.0);
        xD[x] = 30.0 + x;
        yD[x] = 158 + floor( ((double)x / 0.47) + 1.5 * ((double)(100 - qrand()%200) / 100.0) );
        yDlin[x] = 158.0 + ((double)x / 0.47);
        //if (((int)yD[x])%50 == 0) yLabels.push_back(yD[x]);
        //if (((int)xD[x])%10 == 0) xLabels.push_back(xD[x]);
    }

    for (int x=150; x<=210; x+=10)
    {
        yLabels.push_back(x);
    }

    for (int x=30; x<=50; x+=1)
    {
        xLabels.push_back(x);
    }

    qDebug() << yD;
    qDebug() << xD;

    gr = ui->plot->addGraph();
    gr->setData(xD, yD);
    pn.setColor(Qt::red);
    pn.setWidth(3);
    gr->setPen(pn);

    gr = ui->plot->addGraph();
    gr->setData(xD, yDlin);
    pn.setColor(0x008080);
    pn.setWidth(1);
    pn.setStyle(Qt::DashLine);
    gr->setPen(pn);

    ui->plot->xAxis->setLabel("Температура, °C");
    ui->plot->xAxis->setRange(30, 50);
    ui->plot->xAxis->setAutoTicks(false);
    ui->plot->xAxis->setTickVector(xLabels);
    ui->plot->yAxis->setLabel("Сигнал АЦП");
    ui->plot->yAxis->setRange(145, 215);
    ui->plot->yAxis->setAutoTicks(false);
    ui->plot->yAxis->setTickVector(yLabels);

    ui->plot->replot();
	ui->plot->savePdf("graph-sensor.pdf", false, 800, 400);
}
Exemple #26
0
QCPGraph* tva::postProc::vec2Chart( const postProc::policyChart& policy, const tva::opVecReal& opVx, const tva::vecReal& vy, QCustomPlot *plot )
{
	if (policy.needClear)
	{
		/*int n=*/ plot->clearGraphs();
	}
	size_t size = vy.size();
	tva::vecReal vx;
	// generate data:
	if (opVx.isSettled())
	{
		vx = opVx.get();
	}
	else
	{
		for (size_t i=0; i<size; ++i)
		{
			vx.push_back(i);//index
		}
	}

	//const auto& mx = vx_vy.first;
	//const auto& my = vx_vy.second;
	QVector<double> x, y;
	for (size_t i=0; i<size; ++i)
	{
		x.push_back(vx[i]);//index
		y.push_back(vy[i]);//value
	}

	// create graph and assign data to it:
	QCPGraph * graph;
	if (policy.leftAxis)
	{
		graph	= plot->addGraph();
	}
	else
	{
		graph = plot->addGraph(plot->xAxis, plot->yAxis2);
		plot->yAxis2->setVisible(true);
	}

	//auto * graph = plot->addPlottable();

	{//set graph
		QPen graphPen;

		if (policy.lStyle.isSettled())
		{
			graph->setLineStyle(policy.lStyle.get().style);
			graph->setScatterStyle(policy.lStyle.get().scatter);

			if (policy.lStyle.get().name.isSettled())
			{
				graph->setName(policy.lStyle.get().name.get());
			}

			if (policy.lStyle.get().color.isSettled())
			{
				graphPen.setColor(policy.lStyle.get().color.get());
			}
			else
			{
				graphPen.setColor(QColor(rand()%245+10, rand()%245+10, rand()%245+10));
			}

			//graphPen.setWidthF(rand()/(double)RAND_MAX*2+1);
		}
		else
		{
			tva::chartSetup::lineStyle ls;
			graph->setLineStyle(ls.style);
		}

		graph->setPen(graphPen);
	}

	graph->setData(x, y);

	QCPAxis* xAxis= plot->xAxis;
	QCPAxis* yAxis;// = plot->yAxis;
	if (policy.leftAxis)
	{
		yAxis = plot->yAxis;
	}
	else
	{
		yAxis = plot->yAxis2;
	}

	if (policy.style.isSettled())
	{
		plot->setTitle(policy.style.get().title);
	}

	tva::chartSetup::setupAxisesStyle(policy.style, xAxis, yAxis);
	//
	plot->replot();
	return graph;
}
Exemple #27
0
void Widget::on_pushButtonLagra_clicked()
{
    ui->widget->clearGraphs();

    //
    Graphf* gf = new Graphf();
    gf->setStartX(ui->lineEditLagraStart->text().toDouble());
    gf->setFinishX(ui->lineEditLagraFinish->text().toDouble());
    gf->setPointsCount((gf->finishX - gf->startX) * 10 + 1);
    gf->setStepY((gf->finishX - gf->startX) / (gf->points_count - 1));
    gf->calcf();

    QCPGraph *graph = ui->widget->addGraph();
    graph->setData(gf->fX, gf->fY);
    graph->setPen(QPen(Qt::red, 1));
    graph->setName("f(x)");
    //

    //
    Lagra* l = new Lagra(ui->lineEditLagraPointsCount->text().toInt() + 1);
    l->calcF(gf);

    graph = ui->widget->addGraph();
    graph->setData(gf->fX, l->result);
    graph->setPen(QPen(Qt::blue, 1));
    graph->setName("L(x)");
    //

    //
    QVector<double> Rt(gf->points_count);
    for (int i = 0; i < Rt.size(); i++)
        Rt[i] = qFabs(gf->fY[i] - l->result[i]);

    qDebug() << Rt;
    graph = ui->widget->addGraph();
    graph->setData(gf->fX, Rt);
    graph->setPen(QPen(Qt::black, 1));
    graph->setName("R(x)");
    //

    //
    LagraRp* lrp = NULL;

    int unit_points = l->lX.size();
    if (unit_points - 1 == 5)
    {
        lrp = new LagraRp();
        lrp->calcRp(gf, l);

        graph = ui->widget->addGraph();
        graph->setData(gf->fX, lrp->result);
        graph->setPen(QPen(Qt::green, 1));
        graph->setName("Теоретическая погрешность");
    }
    //

    ui->widget->xAxis->setRange(gf->startX, gf->finishX);
    ui->widget->yAxis->setRange(0, 10);
    ui->widget->replot(); /* Рисуем */

    if (lrp != NULL)
        delete lrp;

    delete l;
    delete gf;
}
Exemple #28
0
void smart_plot::mousePress(QMouseEvent *event)
{
    static double prevKey, prevValue;

    if(event->button() == Qt::MiddleButton)
    {
        QCPAbstractPlottable *plottable = activePlot()->plottableAt(event->localPos());

        if(plottable)
        {
            QCPGraph *graph = qobject_cast<QCPGraph*>(plottable);
            plot_analytics analytics;
            plotStats stats;

            if(graph)
            {
                //Do diff by % range vs
                double mouseKey = graph->keyAxis()->pixelToCoord(event->localPos().x());
                double mouseValue = graph->valueAxis()->pixelToCoord(event->localPos().y());
                double keyRange = graph->keyAxis()->range().size();
                double keyDistance_no_abs = 0;
                double value = 0;
                double key = 0;

                bool ok = false;
                double m = std::numeric_limits<double>::max();
                //QCPGraphDataContainer
                analytics.plotAnalyze( graph, &stats, graph->keyAxis()->range());

                //Iterate through on screen data and see which point is closest
                QCPGraphDataContainer::const_iterator QCPGraphDataBegin = graph->data().data()->findBegin(graph->keyAxis()->range().lower,true);
                QCPGraphDataContainer::const_iterator QCPGraphDataEnd = graph->data().data()->findEnd(graph->keyAxis()->range().upper,true);
                for (QCPGraphDataContainer::const_iterator QCPGraphDataIt=QCPGraphDataBegin; QCPGraphDataIt!=QCPGraphDataEnd; ++QCPGraphDataIt)
                {
                    double valueRange = graph->valueAxis()->range().size();
                    double keyDistance = qAbs(mouseKey - QCPGraphDataIt->key)/keyRange;
                    double valueDistance = qAbs(mouseValue - QCPGraphDataIt->value)/valueRange;

                    if( (valueDistance + keyDistance) < m )
                    {
                        value = QCPGraphDataIt->value;
                        key = QCPGraphDataIt->key;
                        keyDistance_no_abs = mouseKey - QCPGraphDataIt->key;
                        ok = true;
                        m = (valueDistance + keyDistance);
                    }
                }
//                qDebug () << QDateTime::fromTime_t((int)mouseKey) << value;

                if(ok)
                {
                    QToolTip::hideText();

                    if(!qSharedPointerDynamicCast<QCPAxisTickerDateTime>(graph->keyAxis()->ticker()).isNull())
                    {
                        if(QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
                        {
                            quint32 timeDelta = qAbs(mouseKey-prevKey);

                            // add the bracket at the top:
                            QCPItemBracket *bracket = new QCPItemBracket(activePlot());
                            bracket->left->setAxes(graph->keyAxis(), graph->valueAxis());
                            bracket->left->setCoords(prevKey, value);
                            bracket->right->setAxes(graph->keyAxis(), graph->valueAxis());
                            bracket->right->setCoords(mouseKey, value);

                            // add the text label at the top:
                            QCPItemText *wavePacketText = new QCPItemText(activePlot());
                            wavePacketText->position->setParentAnchor(bracket->center);
                            wavePacketText->position->setCoords(0, -10); // move 10 pixels to the top from bracket center anchor
                            wavePacketText->setPositionAlignment(Qt::AlignBottom|Qt::AlignHCenter);
                            wavePacketText->setText(
                                QString("%L1: ΔX->%L2 ΔY->%L3").
                                   arg(graph->name().isEmpty() ? "..." : graph->name()).
                                   arg(seconds_to_DHMS(timeDelta)).
                                   arg(value-prevValue));
                            wavePacketText->setFont(QFont(font().family(), 12));
                            activePlot()->replot();
                        }
                        else if(QApplication::keyboardModifiers().testFlag(Qt::AltModifier))
                        {
                            if(QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
                                graph->addData(graph->keyAxis()->pixelToCoord(event->localPos().x()),
                                               graph->valueAxis()->pixelToCoord(event->localPos().y()));
                            else if(keyDistance_no_abs < 0)
                                graph->addData(key - 1, std::numeric_limits<double>::quiet_NaN());
                            else
                                graph->addData(key + 1, std::numeric_limits<double>::quiet_NaN());

                            activePlot()->replot();
                        }
                        else if(QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
                        {
                            //Delete point
                            graph->data().data()->remove(key);
                            activePlot()->replot();
                        }
                        //Hold Alt to insert NAN(Break link?)
                        else
                        {
                            QDateTime dateTime;
                            dateTime.setTime_t(mouseKey);

                            //activePlot()->xAxis->tick
                            QToolTip::showText(event->globalPos(),
                            QString("<table>"
                                    "<tr>" "<th colspan=\"2\">%L1</th>"  "</tr>"
                                    "<tr>" "<td>X:</td>"   "<td>%L2</td>" "</tr>"
                                    "<tr>" "<td>Y:</td>"   "<td>%L3</td>" "</tr>"
                                    "<tr>" "<td>Min:</td>" "<td>%L4</td>" "</tr>"
                                    "<tr>" "<td>Avg:</td>" "<td>%L5</td>" "</tr>"
                                    "<tr>" "<td>Max:</td>" "<td>%L6</td>" "</tr>"
                                   "</table>").
                               arg(graph->name().isEmpty() ? "..." : graph->name()).
                               arg(dateTime.toString(qSharedPointerDynamicCast<QCPAxisTickerDateTime>(graph->keyAxis()->ticker())->dateTimeFormat())).
                               arg(value).
                               arg(stats.minValue).
                               arg(stats.avgValue).
                               arg(stats.maxValue),
                               activePlot(), activePlot()->rect());
                        }
                    }
                    else
                    {
                        QToolTip::showText(event->globalPos(),
                        QString("<table>"
                                "<tr>" "<th colspan=\"2\">%L1</th>"  "</tr>"
                                "<tr>" "<td>X:</td>"   "<td>%L2</td>" "</tr>"
                                "<tr>" "<td>Y:</td>"   "<td>%L3</td>" "</tr>"
                                "<tr>" "<td>Min:</td>" "<td>%L4</td>" "</tr>"
                                "<tr>" "<td>Avg:</td>" "<td>%L5</td>" "</tr>"
                                "<tr>" "<td>Max:</td>" "<td>%L6</td>" "</tr>"
                               "</table>").
                           arg(graph->name().isEmpty() ? "..." : graph->name()).
                           arg(mouseKey).
                           arg(value).
                           arg(stats.minValue).
                           arg(stats.avgValue).
                           arg(stats.maxValue),
                           activePlot(), activePlot()->rect());
                    }
                }

                prevKey = mouseKey;
                prevValue = value;
            }
        }
    }
}
void FlareScoring::prepareDataPlot(
        DataPlot *plot)
{
    // Return now if plot empty
    if (mMainWindow->dataSize() == 0) return;

    DataPoint dpBottom, dpTop;
    bool success;

    switch (mMainWindow->windowMode())
    {
    case MainWindow::Actual:
        success = getWindowBounds(mMainWindow->data(), dpBottom, dpTop);
        break;
    case MainWindow::Optimal:
        success = getWindowBounds(mMainWindow->optimal(), dpBottom, dpTop);
        break;
    }

    // Add shading for scoring window
    if (success && plot->yValue(DataPlot::Elevation)->visible())
    {
        DataPoint dpLower = mMainWindow->interpolateDataT(mMainWindow->rangeLower());
        DataPoint dpUpper = mMainWindow->interpolateDataT(mMainWindow->rangeUpper());

        const double xMin = plot->xValue()->value(dpLower, mMainWindow->units());
        const double xMax = plot->xValue()->value(dpUpper, mMainWindow->units());

        QVector< double > xElev, yElev;

        xElev << xMin << xMax;
        yElev << plot->yValue(DataPlot::Elevation)->value(dpBottom, mMainWindow->units())
              << plot->yValue(DataPlot::Elevation)->value(dpBottom, mMainWindow->units());

        QCPGraph *graph = plot->addGraph(
                    plot->axisRect()->axis(QCPAxis::atBottom),
                    plot->yValue(DataPlot::Elevation)->axis());
        graph->setData(xElev, yElev);
        graph->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));

        yElev.clear();
        yElev << plot->yValue(DataPlot::Elevation)->value(dpTop, mMainWindow->units())
              << plot->yValue(DataPlot::Elevation)->value(dpTop, mMainWindow->units());

        graph = plot->addGraph(
                    plot->axisRect()->axis(QCPAxis::atBottom),
                    plot->yValue(DataPlot::Elevation)->axis());
        graph->setData(xElev, yElev);
        graph->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));

        QCPItemRect *rect = new QCPItemRect(plot);
        plot->addItem(rect);

        rect->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));
        rect->setBrush(QColor(0, 0, 0, 8));

        rect->topLeft->setType(QCPItemPosition::ptAxisRectRatio);
        rect->topLeft->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->topLeft->setCoords(-0.1, -0.1);

        rect->bottomRight->setType(QCPItemPosition::ptAxisRectRatio);
        rect->bottomRight->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->bottomRight->setCoords(
                    (plot->xValue()->value(dpBottom, mMainWindow->units()) - xMin) / (xMax - xMin),
                    1.1);

        rect = new QCPItemRect(plot);
        plot->addItem(rect);

        rect->setPen(QPen(QBrush(Qt::lightGray), mMainWindow->lineThickness(), Qt::DashLine));
        rect->setBrush(QColor(0, 0, 0, 8));

        rect->topLeft->setType(QCPItemPosition::ptAxisRectRatio);
        rect->topLeft->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->topLeft->setCoords(
                    (plot->xValue()->value(dpTop, mMainWindow->units()) - xMin) / (xMax - xMin),
                    -0.1);

        rect->bottomRight->setType(QCPItemPosition::ptAxisRectRatio);
        rect->bottomRight->setAxes(plot->xAxis, plot->yValue(DataPlot::Elevation)->axis());
        rect->bottomRight->setCoords(1.1, 1.1);
    }
}
void SCTPGraphDialog::drawSACKGraph()
{
    GList *listSACK = NULL, *tlist;
    guint16 gap_start=0, gap_end=0, nr, dup_nr;
    struct sack_chunk_header *sack_header;
    struct gaps *gap;
    tsn_t *tsn;
    guint8 type;
    guint32 tsnumber=0;
    guint32 minTSN;
    guint32 *dup_list;
    int i, j;

    if (direction == 1) {
        minTSN = selected_assoc->min_tsn1;
        listSACK = g_list_last(selected_assoc->sack1);
    } else {
        minTSN = selected_assoc->min_tsn2;
        listSACK = g_list_last(selected_assoc->sack2);
    }
    while (listSACK) {
        tsn = (tsn_t*) (listSACK->data);
        tlist = g_list_first(tsn->tsns);
        while (tlist) {
            type = ((struct chunk_header *)tlist->data)->type;
            if (type == SCTP_SACK_CHUNK_ID) {
                gIsSackChunkPresent = 1;
                sack_header =(struct sack_chunk_header *)tlist->data;
                nr=g_ntohs(sack_header->nr_of_gaps);
                tsnumber = g_ntohl(sack_header->cum_tsn_ack);
                dup_nr=g_ntohs(sack_header->nr_of_dups);
                if (nr>0) {  // Gap Reports green
                    gap = &sack_header->gaps[0];
                    for(i=0;i<nr; i++) {
                        gap_start=g_ntohs(gap->start);
                        gap_end = g_ntohs(gap->end);
                        for (j=gap_start; j<=gap_end; j++) {
                            yg.append(j+tsnumber);
                            xg.append(tsn->secs + tsn->usecs/1000000.0);
                            fg.append(tsn->frame_number);
                        }
                        if (i < nr-1)
                            gap++;
                    }
                }
                if (tsnumber>=minTSN) { // CumTSNAck red
                    ys.append(tsnumber);
                    xs.append(tsn->secs + tsn->usecs/1000000.0);
                    fs.append(tsn->frame_number);
                }
                if (dup_nr > 0) { // Duplicates cyan
                    dup_list = &sack_header->a_rwnd + 2 + nr;
                    for (i = 0; i < dup_nr; i++) {
                        tsnumber = g_ntohl(dup_list[i]);
                        if (tsnumber >= minTSN) {
                            yd.append(tsnumber);
                            xd.append(tsn->secs + tsn->usecs/1000000.0);
                            fd.append(tsn->frame_number);
                        }
                    }
                }
            }
            tlist = g_list_next(tlist);
        }
        listSACK = g_list_previous(listSACK);
    }

    QCPScatterStyle myScatter;
    myScatter.setShape(QCPScatterStyle::ssCircle);
    myScatter.setSize(3);

    int graphcount = ui->sctpPlot->graphCount();
    // create graph and assign data to it:

    // Add SACK graph
    if (xs.size() > 0) {
        QCPGraph *gr = ui->sctpPlot->addGraph();
        gr->setName(QString("SACK"));
        myScatter.setPen(QPen(Qt::red));
        myScatter.setBrush(Qt::red);
        ui->sctpPlot->graph(graphcount)->setScatterStyle(myScatter);
        ui->sctpPlot->graph(graphcount)->setLineStyle(QCPGraph::lsNone);
        ui->sctpPlot->graph(graphcount)->setData(xs, ys);
        typeStrings.insert(graphcount, QString(tr("CumTSNAck")));
        graphcount++;
    }

    // Add Gap Acks
    if (xg.size() > 0) {
        QCPGraph *gr = ui->sctpPlot->addGraph();
        gr->setName(QString("GAP"));
        myScatter.setPen(QPen(Qt::green));
        myScatter.setBrush(Qt::green);
        ui->sctpPlot->graph(graphcount)->setScatterStyle(myScatter);
        ui->sctpPlot->graph(graphcount)->setLineStyle(QCPGraph::lsNone);
        ui->sctpPlot->graph(graphcount)->setData(xg, yg);
        typeStrings.insert(graphcount, QString(tr("Gap Ack")));
        graphcount++;
    }

    // Add NR Gap Acks
    if (xn.size() > 0) {
        QCPGraph *gr = ui->sctpPlot->addGraph();
        gr->setName(QString("NR_GAP"));
        myScatter.setPen(QPen(Qt::blue));
        myScatter.setBrush(Qt::blue);
        ui->sctpPlot->graph(graphcount)->setScatterStyle(myScatter);
        ui->sctpPlot->graph(graphcount)->setLineStyle(QCPGraph::lsNone);
        ui->sctpPlot->graph(graphcount)->setData(xn, yn);
        typeStrings.insert(graphcount, QString(tr("NR Gap Ack")));
        graphcount++;
    }

    // Add Duplicates
    if (xd.size() > 0) {
        QCPGraph *gr = ui->sctpPlot->addGraph();
        gr->setName(QString("DUP"));
        myScatter.setPen(QPen(Qt::cyan));
        myScatter.setBrush(Qt::cyan);
        ui->sctpPlot->graph(graphcount)->setScatterStyle(myScatter);
        ui->sctpPlot->graph(graphcount)->setLineStyle(QCPGraph::lsNone);
        ui->sctpPlot->graph(graphcount)->setData(xd, yd);
        typeStrings.insert(graphcount, QString(tr("Duplicate Ack")));
    }
}