//makePlot created a plot. We now update its data.
void MainWindow::refreshPlot(int *x, int *y, int len, uint8_t plot_index)
{
    //From array to QVector:
    QVector<double> xdata(len), ydata(len);
    qCopy(x, x+len, xdata.begin());
    qCopy(y, y+len, ydata.begin());

    ui->customPlot->graph(plot_index)->setData(xdata, ydata);

    //ToDo: Modify this code to take the max of all curves!

    //In Automatic mode we constantly adjust the axis:
    if(ui->radioButtonXAuto->isChecked())
    {
        array_minmax(x, len, &plot_xmin, &plot_xmax);

        ui->customPlot->xAxis->setRange(plot_xmin, plot_xmax);
        ui->plot_xmin_lineEdit->setText(QString::number(plot_xmin));
        ui->plot_xmax_lineEdit->setText(QString::number(plot_xmax));
    }

    if(ui->radioButtonYAuto->isChecked())
    {
        array_minmax(y, len, &plot_ymin, &plot_ymax);

        ui->customPlot->yAxis->setRange(plot_ymin-10, plot_ymax+10);
        ui->plot_ymin_lineEdit->setText(QString::number(plot_ymin));
        ui->plot_ymax_lineEdit->setText(QString::number(plot_ymax));
    }

    ui->customPlot->replot();
}
Exemple #2
0
//makePlot created a plot. We now update its data.
void MainWindow::refreshPlot(int *x, int *y, int len, uint8_t plot_index)
{
    static int graph_ylim[2*VAR_NUM] = {0,0,0,0,0,0,0,0,0,0,0,0};

    //From array to QVector:
    QVector<double> xdata(len), ydata(len);
    qCopy(x, x+len, xdata.begin());
    qCopy(y, y+len, ydata.begin());

    ui->customPlot->graph(plot_index)->setData(xdata, ydata);

    //ToDo: Modify this code to take the max of all curves!

    //In Automatic mode we constantly adjust the axis:
    if(ui->radioButtonXAuto->isChecked())
    {
        array_minmax(x, len, &plot_xmin, &plot_xmax);

        ui->customPlot->xAxis->setRange(plot_xmin, plot_xmax);
        ui->plot_xmin_lineEdit->setText(QString::number(plot_xmin));
        ui->plot_xmax_lineEdit->setText(QString::number(plot_xmax));
    }
    else
    {
        //X is in manual mode.
    }

    if(ui->radioButtonYAuto->isChecked())
    {
        //Unusued channels (index == 0) aren't used for the automatic gain
        if(data_to_plot[plot_index] == 0)
        {
            //qDebug() << "Ch[" << plot_index << "] is Unused.";

            //Unused channel. We take the min & max from used channels.
            int u = 0;
            for(int k= 0; k < VAR_NUM; k++)
            {
                //Grab min & max from any used channel
                if(data_to_plot[k] != 0)
                {
                    plot_ymin = graph_ylim[k];
                    plot_ymax = graph_ylim[k+VAR_NUM];
                }
                else
                {
                    u++;
                }
            }

            if(u == VAR_NUM)
            {
                //All unused, force to 0:
                plot_ymin = -10;
                plot_ymax = 10;
            }
            //qDebug() << "Min/Max =" << plot_ymin << "," << plot_ymax;
        }
        else
        {
            //Limits for this graph:
            array_minmax(y, len, &plot_ymin, &plot_ymax);
            //qDebug() << "Ch[" << plot_index << "] is used.";
        }

        //Compare to all others and get max(max(())
        graph_ylim[plot_index] = plot_ymin;
        graph_ylim[plot_index+VAR_NUM] = plot_ymax;

        //qDebug() << "Min/Max =" << plot_ymin << "," << plot_ymax;

        array_minmax(graph_ylim, 2*VAR_NUM, &plot_ymin, &plot_ymax);

        //Add 5%:
        plot_ymin = (plot_ymin-(abs(plot_ymin)/20));
        plot_ymax = (plot_ymax+(abs(plot_ymax)/20));

        //Set axis 5% above minimum
        ui->customPlot->yAxis->setRange(plot_ymin, plot_ymax);
        ui->plot_ymin_lineEdit->setText(QString::number(plot_ymin));
        ui->plot_ymax_lineEdit->setText(QString::number(plot_ymax));
    }
    //qDebug() << "Final Min/Max =" << plot_ymin << "," << plot_ymax;
    //qDebug() << "";

    ui->customPlot->replot();
}