Esempio n. 1
0
void LinePlot::scaleCurves(QwtPlotCurve *curve)
{

  /// multiple curves based on units
  const QwtPlotItemList &listPlotItem = m_qwtPlot->itemList();
  QwtPlotCurve *plotCurve;
  QwtPlotItemIterator itPlotItem;
  int curveCount = numberOfCurves();

  switch (curveCount)
  {
    case 0:
    {
      curve->setYAxis(QwtPlot::yLeft);
      m_qwtPlot->enableAxis(QwtPlot::yRight, false);
      break;
    }
    case 1:
    {
      curve->setYAxis(QwtPlot::yRight);
      m_qwtPlot->enableAxis(QwtPlot::yRight, true);
      break;
    }
    default: //scale
      m_qwtPlot->enableAxis(QwtPlot::yRight, false);
      // find min, max of all curves
      // scale
      int i;
      for ( itPlotItem = listPlotItem.begin();itPlotItem!=listPlotItem.end();++itPlotItem)
      {
        if ( (*itPlotItem)->rtti() == QwtPlotItem::Rtti_PlotCurve)
        {
          plotCurve = (QwtPlotCurve*) (*itPlotItem);

          if ((plotCurve->minYValue() != 0) || (plotCurve->maxYValue() != 1))
          {

            QwtArray<double> xData(plotCurve->dataSize());
            QwtArray<double> yData(plotCurve->dataSize());
            for (i = 0; i < plotCurve->dataSize(); i++)
            {
              xData[i] = plotCurve->x(i);
              yData[i] = (plotCurve->y(i) - plotCurve->minYValue())/ (plotCurve->maxYValue() - plotCurve->minYValue());
            }
            // reset data
            plotCurve->setTitle(plotCurve->title().text() + "[" + QString::number(plotCurve->minYValue()) + ", "  + QString::number(plotCurve->maxYValue()) + "]");
            plotCurve->setData(xData,yData);
          }
        }
      }
      break;
  }

}
Esempio n. 2
0
int Plot::closestCurve(int xpos, int ypos, int &dist, int &point)
{
QwtScaleMap map[QwtPlot::axisCnt];
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
	map[axis] = canvasMap(axis);

double dmin = 1.0e10;
int key = -1;
for (QMapIterator<int, QwtPlotCurve *> it = d_curves.begin(); it != d_curves.end(); ++it ) 
	{
	QwtPlotCurve *c = (QwtPlotCurve *)it.data();
	if (!c)
		continue;

	for (int i=0; i<c->dataSize(); i++)
		{
		double cx = map[c->xAxis()].xTransform(c->x(i)) - double(xpos);
		double cy = map[c->yAxis()].xTransform(c->y(i)) - double(ypos);
		double f = qwtSqr(cx) + qwtSqr(cy);
		if (f < dmin)
			{
			dmin = f;
			key = it.key();
			point = i;
			}
		 }
	}
dist = int(sqrt(dmin));
return key;
}
void SmoothCurveDialog::activateCurve(const QString& curveName)
{
    if (smooth_method == SmoothFilter::Average)
	{
	QwtPlotCurve *c = graph->curve(curveName);
	if (!c || c->rtti() != QwtPlotItem::Rtti_PlotCurve)
		return;

	boxPointsLeft->setMaxValue(c->dataSize()/2);
	}
}
void polynomFitDialog::changeCurve(int index)
{
QwtPlotCurve *c = graph->curve(index);
while(c->dataSize()<2)
	{
	index++;
	c = graph->curve(index);
	if(!c || index >= graph->curves()) 
		index=0; //Restart from the beginning
	}
boxName->setCurrentItem(index);
activateCurve(index);
}
Esempio n. 5
0
/**
  * Set the scale of the vertical axis
  * @param from :: Minimum value
  * @param to :: Maximum value
  */
void OneCurvePlot::setYScale(double from, double to)
{
  if (isYLogScale())
  {
    if (from == 0 && to == 0)
    {
      from = 1;
      to = 10;
    }
    else
    {
      double yPositiveMin = to;
      QMap<QString,QwtPlotCurve*>::const_iterator cv = m_stored.begin();
      QwtPlotCurve* curve = NULL;
      do
      {
        if (cv != m_stored.end())
        {
          curve = cv.value();
          ++cv;
        }
        else if (curve == m_curve)
        {
          curve = NULL;
          break;
        }
        else
        {
          curve = m_curve;
        }
        if (!curve) break;
        int n = curve->dataSize();
        for(int i = 0; i < n; ++i)
        {
          double y = curve->y(i);
          if (y > 0 && y < yPositiveMin)
          {
            yPositiveMin = y;
          }
        }
      }while(curve);
      from = yPositiveMin;
    }
  }
  setAxisScale(QwtPlot::yLeft,from,to);
  m_zoomer->setZoomBase();
}
Esempio n. 6
0
//! Rebuild the scales and maps
void QwtPlot::updateAxes()
{
    int i;
    bool resetDone[axisCnt];
    for (i = 0; i < axisCnt; i++)
        resetDone[i] = FALSE;

    //
    //  Adjust autoscalers
    //

    QIntDictIterator<QwtPlotCurve> itc(*d_curves);
    for (QwtPlotCurve *c = itc.toFirst(); c != 0; c = ++itc )
    {
        if (c->dataSize() > 0)  // don't scale curves with no data
        {                       //  (minXValue() et al. would return 0.0)
            int axis = c->xAxis();
            if ( !resetDone[axis] )
            {
                d_as[axis].reset();
                resetDone[axis] = TRUE;
            }
            d_as[axis].adjust(c->minXValue(), c->maxXValue());

            axis = c->yAxis();
            if ( !resetDone[axis] )
            {
                d_as[axis].reset();
                resetDone[axis] = TRUE;
            }
            d_as[axis].adjust(c->minYValue(), c->maxYValue());
        }
    }

    //
    // Adjust scales
    //
    for (i=0; i<axisCnt; i++)
    {
        d_sdiv[i] = d_as[i].scaleDiv();
        d_scale[i]->setScaleDiv(d_sdiv[i]);
    }

    d_grid.setXDiv(d_sdiv[d_grid.xAxis()]);
    d_grid.setYDiv(d_sdiv[d_grid.yAxis()]);
}
void polynomFitDialog::activateCurve(int index)
{
QwtPlotCurve *c = graph->curve(index);
if (!c)
	return;

if (graph->selectorsEnabled() && graph->selectedCurveID() == graph->curveKey(index))
	{
	double start = graph->selectedXStartValue();
	double end = graph->selectedXEndValue();
	boxStart->setText(QString::number(QMIN(start, end), 'g', 15));
	boxEnd->setText(QString::number(QMAX(start, end), 'g', 15));
	}
else
	{
	boxStart->setText(QString::number(c->minXValue(), 'g', 15));
	boxEnd->setText(QString::number(c->maxXValue(), 'g', 15));
	}

boxPoints->setValue(QMAX(c->dataSize(), 100));
};
void polynomFitDialog::fit()
{
QString curve = boxName->currentText();
QStringList curvesList = graph->curvesList();
if (curvesList.contains(curve) <= 0)
	{
	QMessageBox::critical(this,tr("QtiPlot - Warning"),
		tr("The curve <b> %1 </b> doesn't exist anymore! Operation aborted!").arg(curve));
	boxName->clear();
	boxName->insertStringList(curvesList);
	return;
	}

int index = boxName->currentItem();
QwtPlotCurve *c = graph->curve(index);
if (!c || c->dataSize()<2)
	{
	QString s= tr("You can not fit curve:");
	s+="<p><b>'"+boxName->text(index)+"'</b><p>";
	s+=tr("because it has less than 2 points!");
	QMessageBox::warning(0,tr("QtiPlot - Warning"),s);

	changeCurve(index);
	}
else
	{
	ApplicationWindow *app = (ApplicationWindow *)this->parent();
	app->fitNumber++;
	graph->setFitID(app->fitNumber);

	QString result = graph->fitPolynomial(boxName->currentText(),boxOrder->value(),
			boxPoints->value(), boxStart->text().toDouble(),
			boxEnd->text().toDouble(), boxShowFormula->isChecked(), 
			boxColor->currentItem());

	app->updateLog(result);
	}
}
Esempio n. 9
0
void DialogSavePlot::on_buttonBox_accepted()
{
    QString selectedDir = QFileDialog::getExistingDirectory(this);
    if (selectedDir.isNull() || selectedDir.isEmpty()) return;

    QwtPlotItemList list = plot->itemList();
    QFile plotFile(selectedDir + QDir::separator() + "plot.p");
    plotFile.open(QIODevice::WriteOnly);
    QTextStream plotStream(&plotFile);
    plotStream << "set terminal postscript enhanced color\nset output '| ps2pdf - plot.pdf'\n";

    if (!ui->cbxShowLegend->isChecked())
    {
        plotStream << "set nokey\n";
    }

    QString horizontalAxis = ui->leHorizontalAxis->text();
    if (!horizontalAxis.isNull() && !horizontalAxis.isEmpty())
    {
        plotStream << "set xlabel \"" + horizontalAxis + "\"\n";
    }

    QString verticalAxis = ui->leVerticakAxis->text();
    if (!verticalAxis.isNull() && !verticalAxis.isEmpty())
    {
        plotStream << "set ylabel \"" + verticalAxis + "\"\n";
    }

    QString color;
    if (ui->cbxSameColor->isChecked())
    {
        color = " lt 1";
    }

    plotStream << "plot ";
    bool first = true;
    foreach(const QwtPlotItem *item, list)
    {
        const QString &name = item->title().text();
        if (name.compare("index") == 0) continue;

        QwtPlotCurve *curve = (QwtPlotCurve*)(item);
        if (curve == 0) continue;

        QFile f(selectedDir + QDir::separator() + name);
        f.open(QIODevice::WriteOnly);
        QTextStream out(&f);

        int n = curve->dataSize();
        for (int i = 0; i < n; i++)
        {
            const QPointF &p = curve->data()->sample(i);
            out << p.x() << ' ' << p.y() << '\n';
        }
        out.flush();
        f.close();

        if (first)
        {
            first = false;
        }
        else
        {
            plotStream << ", ";
        }
        plotStream << '\"' + name + '\"' + " w l" + color;
    }
    plotStream << '\n';
    plotStream.flush();
    plotFile.close();
}