QwtDoubleRect Plot::boundingRect () { QMapIterator<int, QwtPlotCurve *> it = d_curves.begin(); QwtPlotCurve *c = (QwtPlotCurve *)it.data(); double minX = c->minXValue(); double minY = c->minYValue(); double maxX = c->maxXValue(); double maxY = c->maxYValue(); it++; for (it; it != d_curves.end(); ++it) { QwtPlotCurve *c = (QwtPlotCurve *)it.data(); if (!c) continue; minX = (c->minXValue() < minX) ? c->minXValue() : minX; maxX = (c->maxXValue() > maxX) ? c->maxXValue() : maxX; minY = (c->minYValue() < minY) ? c->minYValue() : minY; maxY = (c->maxYValue() > maxY) ? c->maxYValue() : maxY; } QwtDoubleRect r; r.setLeft(minX); r.setRight(maxX); r.setTop(minY); r.setBottom(maxY); return r; }
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; } }
void PlotSettingsDialog:: setAutoScale( const std::vector<QwtPlot*>& plots, QwtPlot::Axis axis ) { const double margin = 1.05; for( unsigned int i=0 ; i < plots.size() ; i++ ) { double max = -9e99; double min = 9e99; QwtPlotItemList L = plots[i]->itemList(); for (int id = 0; id < L.size(); ++id) { if (L[id]->rtti() != QwtPlotItem::Rtti_PlotCurve) continue; QwtPlotCurve *curve = dynamic_cast<QwtPlotCurve*>(L[i]); if( axis == QwtPlot::xBottom ) { max = std::max( max, curve->maxXValue() ); min = std::min( min, curve->minXValue() ); } else { max = std::max( max, curve->maxYValue() ); min = std::min( min, curve->minYValue() ); } } plots[i]->setAxisScale( axis, min*(2-margin), max*margin ); plots[i]->replot(); } }
//! 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 ExpDecayDialog::activateCurve(const QString& curveName) { QwtPlotCurve *c = graph->curve(curveName); if (!c) return; ApplicationWindow *app = (ApplicationWindow *)this->parent(); if (!app) return; double start, end; graph->range(curveName, &start, &end); boxStart->setValue(QMIN(start, end)); boxYOffset->setValue(c->minYValue()); if (slopes < 2) boxAmplitude->setValue(c->maxYValue() - c->minYValue()); }
void ExpDecayDialog::activateCurve(const QString &curveName) { QwtPlotCurve *c = graph->curve(curveName); if (!c) return; ApplicationWindow *app = dynamic_cast<ApplicationWindow *>(this->parent()); if (!app) return; int precision = app->fit_output_precision; double start, end; graph->range(graph->curveIndex(curveName), &start, &end); boxStart->setText(QString::number(qMin(start, end))); boxYOffset->setText(QString::number(c->minYValue(), 'g', precision)); if (slopes < 2) boxAmplitude->setText( QString::number(c->maxYValue() - c->minYValue(), 'g', precision)); }