//--------------------------------------------------------------------------- void JrkPlotDialog::createCurve(QString title, QColor cl, bool on, double scale) { QwtPlotCurve *curve; QPen pen; curve = new QwtPlotCurve(title); pen.setColor(cl); pen.setWidth(2); curve->setPen(pen); curve->setPaintAttribute(QwtPlotCurve::ClipPolygons, true); curve->setRenderHint( QwtPlotCurve::RenderAntialiased, true); #if 0 QwtSplineCurveFitter* curveFitter = new QwtSplineCurveFitter(); curveFitter->setSplineSize(500); curve->setCurveFitter(curveFitter); #endif curve->attach(ui->jrkPlot); showCurve(curve, on); jrkdata.push_back(new JrkPlotData(curve, scale, samples())); // qDebug("Scale: %f", scale); }
void AmpPlot::loadFromCSV(QString fileName) { QFile *file; file = new QFile(fileName); if(_loadedCurve) _loadedCurve->detach(); delete(_loadedCurve); _loadedData.clear(); _loadedTime.clear(); if(file->open(QIODevice::ReadOnly)) { QTextStream fileStream(file); QString line; if((line = fileStream.readLine()) != NULL) { QStringList tokens; tokens = line.split(","); if (tokens.size() < 2) return; while(!fileStream.atEnd()) { tokens = fileStream.readLine().split(","); if(tokens.size() < 2) return; _loadedTime.append(tokens.first().toDouble()); _loadedData.append(tokens.last().toDouble()); } } } QFileInfo pathInfo(fileName); _loadedCurve = new QwtPlotCurve(pathInfo.baseName()); _loadedCurve->attach(_plot); _loadedCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _loadedCurve->setPen(QPen(Qt::darkGreen)); _loadedCurve->setVisible(_plot); _loadedCurve->setRawSamples(_loadedTime.data(), _loadedData.data(), _loadedData.size()); showCurve(_loadedCurve, true); _plot->replot(); }
CpuPlot::CpuPlot( QWidget *parent ): QwtPlot( parent ), dataCount( 0 ) { setAutoReplot( false ); QwtPlotCanvas *canvas = new QwtPlotCanvas(); canvas->setBorderRadius( 10 ); setCanvas( canvas ); plotLayout()->setAlignCanvasToScales( true ); QwtLegend *legend = new QwtLegend; legend->setDefaultItemMode( QwtLegendData::Checkable ); insertLegend( legend, QwtPlot::RightLegend ); setAxisTitle( QwtPlot::xBottom, "System Uptime [h:m:s]" ); setAxisScaleDraw( QwtPlot::xBottom, new TimeScaleDraw( cpuStat.upTime() ) ); setAxisScale( QwtPlot::xBottom, 0, HISTORY ); //setAxisLabelRotation( QwtPlot::xBottom, -50.0 ); setAxisLabelRotation( QwtPlot::xBottom, 0.0 ); setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom ); /* In situations, when there is a label at the most right position of the scale, additional space is needed to display the overlapping part of the label would be taken by reducing the width of scale and canvas. To avoid this "jumping canvas" effect, we add a permanent margin. We don't need to do the same for the left border, because there is enough space for the overlapping label below the left scale. */ QwtScaleWidget *scaleWidget = axisWidget( QwtPlot::xBottom ); const int fmh = QFontMetrics( scaleWidget->font() ).height(); scaleWidget->setMinBorderDist( 0, fmh / 2 ); setAxisTitle( QwtPlot::yLeft, "Cpu Usage [%]" ); setAxisScale( QwtPlot::yLeft, 0, 100 ); //attach方法将元素关联到qwtplot空间上 Background *bg = new Background(); bg->attach( this ); CpuPieMarker *pie = new CpuPieMarker(); pie->attach( this ); CpuCurve *curve; curve = new CpuCurve( "System" ); curve->setColor( Qt::red ); curve->attach( this ); data[System].curve = curve; curve = new CpuCurve( "User" ); curve->setColor( Qt::blue ); curve->setZ( curve->z() - 1 ); curve->attach( this ); data[User].curve = curve; curve = new CpuCurve( "Total" ); curve->setColor( Qt::black ); curve->setZ( curve->z() - 2 ); curve->attach( this ); data[Total].curve = curve; curve = new CpuCurve( "Idle" ); curve->setColor( Qt::darkCyan ); curve->setZ( curve->z() - 3 ); curve->attach( this ); data[Idle].curve = curve; showCurve( data[System].curve, true ); showCurve( data[User].curve, true ); showCurve( data[Total].curve, false ); showCurve( data[Idle].curve, false ); for ( int i = 0; i < HISTORY; i++ ) timeData[HISTORY - 1 - i] = i; ( void )startTimer( 1000 ); // 1 second connect( legend, SIGNAL( checked( const QVariant &, bool, int ) ), SLOT( legendChecked( const QVariant &, bool ) ) ); }
void CpuPlot::legendChecked( const QVariant &itemInfo, bool on ) { QwtPlotItem *plotItem = infoToItem( itemInfo ); if ( plotItem ) showCurve( plotItem, on ); }
AmpPlot::AmpPlot(QwtPlot *plot) { //TODO // _picker = new QwtPicker(canvas()); // _picker->setStateMachine(new QwtPickerDragRectMachine()); // _picker->setTrackerMode(QwtPicker::ActiveOnly); // _picker->setRubberBand(QwtPicker::RectRubberBand); _plot = plot; _panner = new QwtPlotPanner(_plot->canvas()); //Panning with the mouse _panner->setOrientations(Qt::Horizontal); //connect(_panner, SIGNAL(moved(int,int)), this, SLOT(pannerMoved(int,int))); _magnifier = new QwtPlotMagnifier(_plot->canvas()); //Zooming with the wheel _plot->canvas()->setBorderRadius(5); _plot->setCanvasBackground(Qt::white); _plot->plotLayout()->setAlignCanvasToScales(true); QwtLegend *legend = new QwtLegend; _plot->insertLegend(legend,QwtPlot::RightLegend); legend->setItemMode(QwtLegend::CheckableItem); connect(_plot,SIGNAL(legendChecked(QwtPlotItem*,bool)),SLOT(showCurve(QwtPlotItem*,bool))); _xMax = DEFAULT_X_MAX; _yMax = DEFAULT_Y_MAX; _plot->setAxisTitle(QwtPlot::xBottom, "ms"); _plot->setAxisScale(QwtPlot::xBottom,0,_xMax); QwtScaleWidget *scaleWidget = _plot->axisWidget(QwtPlot::xBottom); const int fmh = QFontMetrics(scaleWidget->font()).height(); scaleWidget->setMinBorderDist(0, fmh*2); _plot->setAxisTitle(QwtPlot::yLeft,"mA"); _plot->setAxisAutoScale(QwtPlot::yLeft, true); _dataCurve = new QwtPlotCurve("mA"); _dataCurve->attach(_plot); _dataCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _dataCurve->setVisible(_plot); _meanCurve = new QwtPlotCurve("avg mean"); _meanCurve->attach(_plot); _meanCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _meanCurve->setPen(QPen(Qt::red)); _maxCurve = new QwtPlotCurve("max"); _maxCurve->attach(_plot); _maxCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _maxCurve->setPen(QPen(Qt::darkMagenta)); _currentMeanCurve = new QwtPlotCurve("mean"); _currentMeanCurve->attach(_plot); _currentMeanCurve->setRenderHint(QwtPlotItem::RenderAntialiased); _currentMeanCurve->setPen(QPen(Qt::blue)); showCurve(_dataCurve, true); showCurve(_meanCurve, false); showCurve(_maxCurve, false); showCurve(_currentMeanCurve, true); _time = new QTime(); _time->start(); _meanData.append(0.0); _meanTime.append(0.0); _meanData.append(0.0); _meanTime.append(0.0); _maxData.append(0.0); _maxTime.append(0.0); _maxData.append(0.0); _maxTime.append(0.0); _pauseTime = 0; _dataSource = NULL; _loadedCurve = NULL; }
void Graph::showCurve(GraphCurve *curve, bool show) { showCurve(itemToInfo(curve), show, -1); }
void LinePlot::linePlotData(LinePlotData::Ptr data, const std::string& name, QColor color, double offset ) { if (!data) return; // set based on data - record overall min and max if ( (data->minX() < m_xAxisMin) || (data->maxX() > m_xAxisMax) ) { if (data->minX() < m_xAxisMin) m_xAxisMin = data->minX(); if (data->maxX() > m_xAxisMax) m_xAxisMax = data->maxX(); } if (numberOfCurves() == 0) { m_lineThickness = 10; } /// todo - curve collection - shared pointers QwtPlotCurve * curve = new QwtPlotCurve(toQString(name)); if (color == Qt::color0) { // generate new color from color map color = curveColor(m_lastColor); m_lastColor = color; } curve->setPen(curvePen(color)); curve->attach(m_qwtPlot); curve->setData(*data); // check for number of different units (std::string based) QString curveUnits = toQString(data->units()); if (m_leftAxisUnits == "NONE SPECIFIED") { m_leftAxisUnits = curveUnits; this->leftAxisTitleFromUnits(toString(m_leftAxisUnits)); curve->setYAxis(QwtPlot::yLeft); m_qwtPlot->enableAxis(QwtPlot::yRight, false); } else if (m_leftAxisUnits.toUpper() == curveUnits.toUpper()) { curve->setYAxis(QwtPlot::yLeft); m_qwtPlot->enableAxis(QwtPlot::yRight, false); } else if (m_rightAxisUnits == "NONE SPECIFIED") { m_rightAxisUnits = curveUnits; this->rightAxisTitleFromUnits(toString(m_rightAxisUnits)); curve->setYAxis(QwtPlot::yRight); m_qwtPlot->enableAxis(QwtPlot::yRight, true); } else if (m_rightAxisUnits.toUpper() == curveUnits.toUpper()) { curve->setYAxis(QwtPlot::yRight); m_qwtPlot->enableAxis(QwtPlot::yRight, true); } else // more than 2 units - scale all curves { scaleCurves(curve); m_qwtPlot->enableAxis(QwtPlot::yRight, false); this->leftAxisTitle("Scaled"); } /// update legend and replot showCurve(curve, true); // initZoomer(); }
bool CopasiPlot::initFromSpec(const CPlotSpecification* plotspec) { mIgnoreUpdate = true; mpPlotSpecification = plotspec; if (mpZoomer) mpZoomer->setEnabled(false); // size_t k, kmax = mpPlotSpecification->getItems().size(); setTitle(FROM_UTF8(mpPlotSpecification->getTitle())); mCurves.resize(mpPlotSpecification->getItems().size()); mCurves = NULL; std::map< std::string, C2DPlotCurve * >::iterator found; CCopasiVector< CPlotItem >::const_iterator itPlotItem = mpPlotSpecification->getItems().begin(); CCopasiVector< CPlotItem >::const_iterator endPlotItem = mpPlotSpecification->getItems().end(); CVector< bool > Visible(mpPlotSpecification->getItems().size()); Visible = true; bool * pVisible = Visible.array(); for (; itPlotItem != endPlotItem; ++itPlotItem, ++pVisible) { // Qwt does not like it to reuse the curve as this may lead to access // violation. We therefore delete the curves but remember their visibility. if ((found = mCurveMap.find((*itPlotItem)->CCopasiParameter::getKey())) != mCurveMap.end()) { *pVisible = found->second->isVisible(); } } // Remove unused curves if definition has changed std::map< std::string, C2DPlotCurve * >::iterator it = mCurveMap.begin(); std::map< std::string, C2DPlotCurve * >::iterator end = mCurveMap.end(); for (; it != end; ++it) pdelete(it->second); mCurveMap.clear(); itPlotItem = mpPlotSpecification->getItems().begin(); pVisible = Visible.array(); C2DPlotCurve ** ppCurve = mCurves.array(); unsigned long int k = 0; bool needLeft = false; bool needRight = false; for (; itPlotItem != endPlotItem; ++itPlotItem, ++pVisible, ++ppCurve, ++k) { // set up the curve C2DPlotCurve * pCurve = new C2DPlotCurve(&mMutex, (*itPlotItem)->getType(), (*itPlotItem)->getActivity(), FROM_UTF8((*itPlotItem)->getTitle())); *ppCurve = pCurve; mCurveMap[(*itPlotItem)->CCopasiParameter::getKey()] = pCurve; //color handling should be similar for different curve types QColor color; if (pCurve->getType() == CPlotItem::curve2d || pCurve->getType() == CPlotItem::histoItem1d || pCurve->getType() == CPlotItem::bandedGraph) { std::string colorstr = *(*itPlotItem)->getValue("Color").pSTRING; color = CQPlotColors::getColor(colorstr, k); } pCurve->setPen(color); pCurve->attach(this); showCurve(pCurve, *pVisible); if (pCurve->getType() == CPlotItem::curve2d || pCurve->getType() == CPlotItem::bandedGraph) { needLeft = true; pCurve->setRenderHint(QwtPlotItem::RenderAntialiased); unsigned C_INT32 linetype = *(*itPlotItem)->getValue("Line type").pUINT; if (linetype == 0 //line || linetype == 3) //line+symbols { pCurve->setStyle(QwtPlotCurve::Lines); unsigned C_INT32 linesubtype = *(*itPlotItem)->getValue("Line subtype").pUINT; C_FLOAT64 width = *(*itPlotItem)->getValue("Line width").pUDOUBLE; switch (linesubtype) //symbol type { case 1: pCurve->setPen(QPen(QBrush(color), width, Qt::DotLine, Qt::FlatCap)); break; case 2: pCurve->setPen(QPen(QBrush(color), width, Qt::DashLine)); break; case 3: pCurve->setPen(QPen(QBrush(color), width, Qt::DashDotLine)); break; case 4: pCurve->setPen(QPen(QBrush(color), width, Qt::DashDotDotLine)); break; case 0: default: pCurve->setPen(QPen(QBrush(color), width, Qt::SolidLine)); break; } } if (linetype == 1) //points { C_FLOAT64 width = *(*itPlotItem)->getValue("Line width").pUDOUBLE; pCurve->setPen(QPen(color, width, Qt::SolidLine, Qt::RoundCap)); pCurve->setStyle(QwtPlotCurve::Dots); } if (linetype == 2) //only symbols { pCurve->setStyle(QwtPlotCurve::NoCurve); } if (linetype == 2 //symbols || linetype == 3) //line+symbols { unsigned C_INT32 symbolsubtype = *(*itPlotItem)->getValue("Symbol subtype").pUINT; switch (symbolsubtype) //symbol type { case 1: pCurve->setSymbol(QwtSymbol(QwtSymbol::Cross, QBrush(), QPen(QBrush(color), 2), QSize(7, 7))); break; case 2: pCurve->setSymbol(QwtSymbol(QwtSymbol::Ellipse, QBrush(), QPen(QBrush(color), 1), QSize(8, 8))); break; case 0: default: pCurve->setSymbol(QwtSymbol(QwtSymbol::Cross, QBrush(color), QPen(QBrush(color), 1), QSize(5, 5))); break; } } } //2d curves and banded graphs if (pCurve->getType() == CPlotItem::bandedGraph) { //set fill color QColor c = color; c.setAlpha(64); pCurve->setBrush(c); } if (pCurve->getType() == CPlotItem::histoItem1d) { pCurve->setIncrement(*(*itPlotItem)->getValue("increment").pDOUBLE); pCurve->setStyle(QwtPlotCurve::Steps); pCurve->setYAxis(QwtPlot::yRight); pCurve->setCurveAttribute(QwtPlotCurve::Inverted); needRight = true; } } if (plotspec->isLogX()) setAxisScaleEngine(xBottom, new QwtLog10ScaleEngine()); else setAxisScaleEngine(xBottom, new QwtLinearScaleEngine()); setAxisAutoScale(xBottom); if (plotspec->isLogY()) setAxisScaleEngine(yLeft, new QwtLog10ScaleEngine()); else setAxisScaleEngine(yLeft, new QwtLinearScaleEngine()); setAxisAutoScale(yLeft); enableAxis(yLeft, needLeft); if (needRight) { setAxisScaleEngine(yRight, new QwtLinearScaleEngine()); setAxisTitle(yRight, "Percent %"); enableAxis(yRight); } mIgnoreUpdate = false; return true; //TODO really check! }
caStripPlot::caStripPlot(QWidget *parent): QwtPlot(parent) { timerID = false; thisXaxisType = TimeScale; HISTORY = 60; thisUnits = Second; thisPeriod = 60; NumberOfCurves = MAXCURVES; onInit = true; timeInterval = 1.0; setAutoReplot(false); setAutoFillBackground(true); Start = true; // define a grid plotGrid = new QwtPlotGrid(); plotGrid->attach(this); plotLayout()->setAlignCanvasToScales(true); // define our axis if(thisXaxisType == TimeScale) { setAxisScale(QwtPlot::xBottom, 0, HISTORY); } else { setAxisScale(QwtPlot::xBottom, -HISTORY, 0); } setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom); setAxisScale(QwtPlot::yLeft, 0, 1000); if(thisXaxisType == TimeScale) { // due to time scale we need some distance scaleWidget = axisWidget(QwtPlot::xBottom); const int fmh = QFontMetrics(scaleWidget->font()).height(); scaleWidget->setMinBorderDist(fmh * 2, fmh * 2); // define time axis QTime timeNow= QTime::currentTime(); setAxisScaleDraw ( QwtPlot::xBottom, new TimeScaleDraw ( timeNow ) ); } // define our curves for(int i=0; i< MAXCURVES; i++) { curve[i] = new QwtPlotCurve(); errorcurve[i] = new QwtPlotIntervalCurve(); fillcurve[i] = new QwtPlotIntervalCurve(); if(i>0) { curve[i]->setZ(curve[i]->z() - i); fillcurve[i]->setZ(fillcurve[i]->z() - i); errorcurve[i]->setZ(errorcurve[i]->z() - i); } curve[i]->attach(this); errorcurve[i]->attach(this); fillcurve[i]->attach(this); showCurve(i, false); thisYaxisLimitsMax[i] = 100; thisYaxisLimitsMin[i] = 0; } // default colors and styles setTitlePlot(""); setTitleX(""); setTitleY(""); setBackground(Qt::black); setForeground(QColor(133, 190, 232)); setScaleColor(Qt::black); setGrid(true); setGridColor(Qt::gray); for(int i=0; i< MAXCURVES; i++) setStyle(Lines, i); setColor(Qt::white, 0); setColor(Qt::red, 1); setColor(Qt::yellow, 2); setColor(Qt::cyan, 3); setColor(Qt::magenta, 4); setColor(Qt::green, 5); setColor(Qt::blue, 6); setXaxisEnabled(true); setYaxisEnabled(true); setLegendEnabled(true); setAxisFont(QwtPlot::xBottom, QFont("Arial", 10)); setAxisFont(QwtPlot::yLeft, QFont("Arial", 10)); installEventFilter(this); // display timer Timer = new QTimer(this); Timer->setInterval(1000); connect(Timer, SIGNAL(timeout()), this, SLOT(TimeOut())); // data collection thread timerThread = new stripplotthread(); timerThread->start(); timerThread->threadSetTimer(100); timerThread->setPriority(QThread::HighPriority); connect(this, SIGNAL(timerThreadStop()), timerThread, SLOT(runStop())); connect(timerThread, SIGNAL(update()), this, SLOT(TimeOutThread()), Qt::DirectConnection); }
void caStripPlot::defineCurves(QStringList titres, units unit, double period, int width, int nbCurves) { int min, max; NumberOfCurves = nbCurves; Unit = unit; Period = period; scaleWidget->getBorderDistHint(min, max); savedTitres = titres; defineAxis(unit, period); // define curves for(int i=0; i < MAXCURVES; i++) { curvStyle s = Lines; QColor c; if(curve[i] != (QwtPlotCurve*) 0) { s = getStyle(i); c = getColor(i); delete curve[i]; } if(errorcurve[i] != (QwtPlotIntervalCurve*) 0) { delete errorcurve[i]; } if(fillcurve[i] != (QwtPlotIntervalCurve*) 0) { delete fillcurve[i]; } if(i < NumberOfCurves) { // set title and limits to legend QString titre = legendText(i); curve[i] = new QwtPlotCurve(titre); errorcurve[i] = new QwtPlotIntervalCurve(titre); fillcurve[i] = new QwtPlotIntervalCurve(titre); setStyle(s, i); curve[i]->setZ(i); curve[i]->attach(this); fillcurve[i]->setZ(i); fillcurve[i]->attach(this); fillcurve[i]->setItemAttribute(QwtPlotItem::Legend, false); errorcurve[i]->setZ(i); errorcurve[i]->attach(this); errorcurve[i]->setItemAttribute(QwtPlotItem::Legend, false); showCurve(i, false); realMax[i] = maxVal[i] = -1000000; realMin[i] = minVal[i] = 1000000; actVal[i] = realVal[i] = 0; } } showCurve(0, true); // draw legend if(thisLegendshow) { QwtLegend *lgd = new QwtLegend; insertLegend(lgd, QwtPlot::BottomLegend); // set color on legend texts setLegendAttribute(thisScaleColor, QFont("arial",9), COLOR); } RescaleCurves(width, unit, period); }
QwtGrapher::QwtGrapher(QWidget* parent): QwtPlot(parent) { m_values = new TwoDArray<double>(3,100); plotLayout()->setAlignCanvasToScales(true); QwtLegend *legend = new QwtLegend; legend->setItemMode(QwtLegend::CheckableItem); insertLegend(legend, QwtPlot::RightLegend); setAxisTitle(QwtPlot::xBottom, " FitnessCases"); /*setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw(cpuStat.upTime())); setAxisScale(QwtPlot::xBottom, 0, HISTORY); setAxisLabelRotation(QwtPlot::xBottom, -50.0); setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom); */ /* In situations, when there is a label at the most right position of the scale, additional space is needed to display the overlapping part of the label would be taken by reducing the width of scale and canvas. To avoid this "jumping canvas" effect, we add a permanent margin. We don't need to do the same for the left border, because there is enough space for the overlapping label below the left scale. */ QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom); const int fmh = QFontMetrics(scaleWidget->font()).height(); scaleWidget->setMinBorderDist(0, fmh / 2); setAxisTitle(QwtPlot::yLeft, "Ouput") ; //setAxisScale(QwtPlot::yLeft, 0, 100); // Background *bg = new Background(); //bg->attach(this); /*CpuPieMarker *pie = new CpuPieMarker(); pie->attach(this); */ QwtPlotCurve *curve; curve = new QwtPlotCurve("Best"); curve->setPen(QColor(Qt::green)); curve->attach(this); m_curves[0] = curve; curve = new QwtPlotCurve("Average"); curve->setPen(QColor(Qt::blue)); curve->setZ(curve->z() - 1); curve->attach(this); m_curves[1] = curve; curve = new QwtPlotCurve("Worst"); curve->setPen(QColor(Qt::black)); curve->setZ(curve->z() - 2); curve->attach(this); m_curves[2] = curve; showCurve(m_curves[0], true); showCurve(m_curves[1], true); showCurve(m_curves[2], true); connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), SLOT(showCurve(QwtPlotItem *, bool))); }