void PlotSectorHistogram::updateIntervals( const SectorHistogram &histogram) { _datasCurveIntervals->clear(); QVector<QwtIntervalSample> curveHistogramIntervalsDatas; const int nbIntervals = histogram.nbIntervals(); if ( nbIntervals > 0 ) { QVector< Interval<uint> >::ConstIterator begin = histogram.intervals().begin(); const QVector< Interval<uint> >::ConstIterator end = histogram.intervals().end(); const uint nbSectors = PieChartSingleton::getInstance()->nbSectors(); uint min, max, i; qDebug() << "Intervalles d'angles' :"; while ( begin != end ) { const Interval<uint> ¤tInterval = *begin++; min = currentInterval.min(); max = currentInterval.max(); if ( currentInterval.isValid() ) { _datasCurveIntervals->append(QwtPointPolar( PieChartSingleton::getInstance()->sector(min).minAngle(), 0. )); for ( i=min ; i<=max ; ++i ) { const PiePart ¤tSector = PieChartSingleton::getInstance()->sector(i); _datasCurveIntervals->append(QwtPointPolar(currentSector.minAngle(),histogram[i])); _datasCurveIntervals->append(QwtPointPolar(currentSector.maxAngle(), histogram[i])); curveHistogramIntervalsDatas.append(QwtIntervalSample( histogram[i],currentSector.minAngle(),currentSector.maxAngle())); } _datasCurveIntervals->append(QwtPointPolar( PieChartSingleton::getInstance()->sector(max).maxAngle(), 0. )); } else { _datasCurveIntervals->append(QwtPointPolar( PieChartSingleton::getInstance()->sector(min).minAngle(), 0. )); for ( i=min ; i<nbSectors ; ++i ) { const PiePart ¤tSector = PieChartSingleton::getInstance()->sector(i); _datasCurveIntervals->append(QwtPointPolar(currentSector.minAngle(), histogram[i])); _datasCurveIntervals->append(QwtPointPolar(currentSector.maxAngle(), histogram[i])); curveHistogramIntervalsDatas.append(QwtIntervalSample( histogram[i],currentSector.minAngle(),currentSector.maxAngle())); } for ( i=0 ; i<=max ; ++i ) { const PiePart ¤tSector = PieChartSingleton::getInstance()->sector(i); _datasCurveIntervals->append(QwtPointPolar(currentSector.minAngle(), histogram[i])); _datasCurveIntervals->append(QwtPointPolar(currentSector.maxAngle(), histogram[i])); curveHistogramIntervalsDatas.append(QwtIntervalSample( histogram[i],currentSector.minAngle(),currentSector.maxAngle())); } _datasCurveIntervals->append(QwtPointPolar( PieChartSingleton::getInstance()->sector(max).maxAngle(), 0. )); } qDebug() << " [ " << min << ", " << max << " ] => [" << PieChartSingleton::getInstance()->sector(min).minAngle()*RAD_TO_DEG_FACT << ", " << PieChartSingleton::getInstance()->sector(max).maxAngle()*RAD_TO_DEG_FACT << "] avec largeur = " << (max>min?max-min:360-min+max); } } _histogramIntervals.setSamples(curveHistogramIntervalsDatas); }
/******************************* * Private functions *******************************/ void PlotSectorHistogram::updateDatas( const SectorHistogram &histogram ) { const int nbSectors = histogram.size(); QVector<QwtIntervalSample> datasHistogram(0); if ( nbSectors > 0 ) { datasHistogram.fill(QwtIntervalSample(),nbSectors); _datasCurve->resize(2*nbSectors+1); QVector<QwtPointPolar>::Iterator beginCurve = _datasCurve->begin(); QVector<QwtIntervalSample>::Iterator beginHist = datasHistogram.begin(); int i, value; qreal left, right; for ( i=0 ; i<nbSectors ; ++i ) { const PiePart &part = PieChartSingleton::getInstance()->sector(i); value = histogram[i]; left = part.maxAngle(); right = part.minAngle(); (*beginCurve).setAzimuth(right); (*beginCurve++).setRadius(value); (*beginCurve).setAzimuth(left); (*beginCurve++).setRadius(value); (*beginHist).value = value; (*beginHist++).interval.setInterval(right,left); } (*beginCurve).setAzimuth(PieChartSingleton::getInstance()->sector(0).minAngle()); (*beginCurve).setRadius(histogram[0]); } else { _datasCurve->resize(0); } _histogramData.setSamples(datasHistogram); }
void HistogramWindow::createHistogram(const QVector<int> &data, QwtPlot *plot, QwtPlotHistogram *hist, HistogramWindow::Color color) { QVector<QwtIntervalSample> samples; for(int i = 0; i < data.size(); i++) samples.append(QwtIntervalSample(data[i],i, i+1)); hist->setSamples(samples); hist->attach(plot); QColor penColor, brushColor; switch (color) { case RED: penColor = QColor(255, 0, 0, 100); brushColor = QColor(255, 0, 0, 255); break; case GREEN: penColor = QColor(0, 255, 0, 100); brushColor = QColor(0, 255, 0, 255); break; case BLUE: penColor = QColor(0, 0, 255, 100); brushColor = QColor(0, 0, 255, 255); break; } hist->setPen(QPen(penColor)); hist->setBrush(QBrush(brushColor)); plot->setAxisScale(2, 0, 255); plot->setSizePolicy(this->sizePolicy()); plot->replot(); }
void QmitkHistogramWidget::SetHistogram(HistogramType::ConstPointer itkHistogram) { HistogramType::SizeType size = itkHistogram->GetSize(); HistogramType::IndexType index; HistogramType::MeasurementVectorType currentMeasurementVector; QVector<QwtIntervalSample> intervalSeries(size[0]); for (unsigned int i = 0; i < size[0]; ++i) { index[0] = static_cast<HistogramType::IndexValueType> (i); currentMeasurementVector = itkHistogram->GetMeasurementVector(index); if (currentMeasurementVector[0] != 0.0) { intervalSeries[i] = QwtIntervalSample(static_cast<double> (itkHistogram->GetFrequency(index)), Round(currentMeasurementVector[0]-1), Round(currentMeasurementVector[0])); } } // rebuild the plot m_Plot->detachItems(); m_Histogram = new QmitkHistogram(); m_Histogram->setColor(Qt::darkCyan); m_Histogram->setData(QwtIntervalSeriesData(intervalSeries)); m_Histogram->attach(m_Plot); this->InitializeMarker(); this->InitializeZoomer(); m_Plot->replot(); }
void CBandScope::setSamples(int16_t* data, int length) { for (int i=minoffset; i < length+minoffset; i++) { //qDebug() <<"data="<< data[i-minoffset]; samples[i] = QwtIntervalSample(data[i-minoffset],i,i+1); } bandscope->setSamples(samples); qwtPlot->replot(); }
void Histogram::setValue(const double x, const double y) { QVector<QwtIntervalSample> samples(1); QwtInterval interval(x - 0.4, x + 0.4); interval.setBorderFlags(QwtInterval::ExcludeMaximum); samples[0] = QwtIntervalSample(y, interval); setData(new QwtIntervalSeriesData(samples)); }
void Sample::dataChangeHistogram(const Histogram::GraphicType& type) { QVector<QwtIntervalSample> histogramSamples; QList<StatClass>::const_iterator it = m_classModel.constBegin(); switch(type){ case Histogram::Absolute: while(it != m_classModel.constEnd()){ histogramSamples.append(QwtIntervalSample((*it).absoluteFrequency(),(*it).begin().toDouble(m_classModel.fix()), (*it).end().toDouble(m_classModel.fix()))); it++; } m_histogram.setAxisTitle(QwtPlot::yLeft,"Absolute frequency"); break; case Histogram::Relative: while(it!= m_classModel.constEnd()){ histogramSamples.append(QwtIntervalSample((*it).relativeFrequency().toDouble(m_classModel.fix()), (*it).begin().toDouble(m_classModel.fix()),(*it).end().toDouble(m_classModel.fix()))); it++; } m_histogram.setAxisTitle(QwtPlot::yLeft,"Relative frequency"); break; case Histogram::Percents: while(it !=m_classModel.constEnd()){ histogramSamples.append(QwtIntervalSample((*it).percents().toDouble(m_classModel.fix()), (*it).begin().toDouble(m_classModel.fix()), (*it).end().toDouble(m_classModel.fix()))); it++; } m_histogram.setAxisTitle(QwtPlot::yLeft,"Percents %"); break; default: return; break; } m_histogram.setNewSamples(histogramSamples); m_histogram.replot(); return; }
Plot::Plot( QWidget *parent ): QwtPlot( parent ) { setObjectName( "FriedbergPlot" ); setTitle( "Temperature of Friedberg/Germany" ); setAxisTitle( QwtPlot::xBottom, "2007" ); setAxisScaleDiv( QwtPlot::xBottom, yearScaleDiv() ); setAxisScaleDraw( QwtPlot::xBottom, new YearScaleDraw() ); setAxisTitle( QwtPlot::yLeft, QString( "Temperature [%1C]" ).arg( QChar( 0x00B0 ) ) ); // grid QwtPlotGrid *grid = new Grid; grid->attach( this ); insertLegend( new QwtLegend(), QwtPlot::RightLegend ); const int numDays = 365; QVector<QPointF> averageData( numDays ); QVector<QwtIntervalSample> rangeData( numDays ); for ( int i = 0; i < numDays; i++ ) { const Temperature &t = friedberg2007[i]; averageData[i] = QPointF( double( i ), t.averageValue ); rangeData[i] = QwtIntervalSample( double( i ), QwtInterval( t.minValue, t.maxValue ) ); } insertCurve( "Average", averageData, Qt::black ); insertErrorBars( "Range", rangeData, Qt::blue ); // LeftButton for the zooming // MidButton for the panning // RightButton: zoom out by 1 // Ctrl+RighButton: zoom out to full size QwtPlotZoomer* zoomer = new QwtPlotZoomer( canvas() ); zoomer->setRubberBandPen( QColor( Qt::black ) ); zoomer->setTrackerPen( QColor( Qt::black ) ); zoomer->setMousePattern( QwtEventPattern::MouseSelect2, Qt::RightButton, Qt::ControlModifier ); zoomer->setMousePattern( QwtEventPattern::MouseSelect3, Qt::RightButton ); QwtPlotPanner *panner = new QwtPlotPanner( canvas() ); panner->setMouseButton( Qt::MidButton ); canvas()->setPalette( Qt::darkGray ); canvas()->setBorderRadius( 10 ); }
void Task4::process() { const uint nexp = ui->nexp->value(); const quint8 dx = qFloor(3.32 * log10(nexp)) + 1; QVector<qreal> experiments; srand(QDateTime::currentDateTime().toTime_t()); for (uint i = nexp; i; --i) experiments << 1.0 * rand() / RAND_MAX; qSort(experiments); uint j = 0; uint captured[dx]; memset(captured, 0, dx * sizeof(uint)); foreach (const qreal& v, experiments) { if (v >= (j + 1.0)/dx) ++j; ++captured[j]; } QVector<QwtIntervalSample> samples; for (j = 0; j < dx; ++j) { ui->textBrowser->append( QString::fromUtf8("Интервал [%2/%1; %3/%1]: %4 значений") .arg(dx) .arg(j) .arg(j+1) .arg(captured[j])); samples << QwtIntervalSample(captured[j], 1.0 * j / dx, (j+1.0)/dx); } hist->setSamples(samples); plot->replot(); qreal xi_emp = 0.0; qreal expected = 1.0 * nexp / dx; for (uint j = 0; j < dx; ++j) xi_emp += (captured[j] - expected) * (captured[j] - expected) / expected; ui->textBrowser->append(QString::fromUtf8( "Хи теоретическое: %1. Хи эмперическое: %2.") .arg(chi[dx-4]) .arg(xi_emp)); if (chi[dx-4] > xi_emp) ui->textBrowser->append(QString::fromUtf8( "Нет основание опровергать гипотезу о равномерности распределения")); else ui->textBrowser->append(QString::fromUtf8( "Гипотеза не верна")); }
void Histogram::setValues(uint numValues, QVector<float> *valores) { QVector<QwtIntervalSample> samples(numValues); for (uint i = 0; i < numValues; i++ ) { QwtInterval interval(double(i), i + 1); interval.setBorderFlags(QwtInterval::IncludeBorders); samples[i] = QwtIntervalSample((double)(valores->at(i)), interval); } setData(new QwtIntervalSeriesData(samples)); }
void Histogram::setValues( uint numValues, const double *values ) { QVector<QwtIntervalSample> samples( numValues ); for ( uint i = 0; i < numValues; i++ ) { QwtInterval interval( double( i ), i + 1.0 ); interval.setBorderFlags( QwtInterval::ExcludeMaximum ); samples[i] = QwtIntervalSample( values[i], interval ); } setData( new QwtIntervalSeriesData( samples ) ); }
void CBandScope::setSamples(QString data) { // Offset of those samples bool ok; int offset = data.mid(3,2).toInt(&ok,16); for(int i=0; i < 16; i++) { // update sample at position with new value double sample = data.mid(5+i*2,2).toInt(&ok,16); samples[offset+i] = QwtIntervalSample(sample,offset+i,offset+i+1); } // Update samples bandscope->setSamples(samples); qwtPlot->replot(); }
int main( int argc, char **argv ) { //using HistogramItem = QwtPlotItem; using HistogramItem = QwtPlotHistogram; //using QwtIntervalData = QwtSeriesData<QwtIntervalSample>; QApplication a(argc, argv); QwtPlot plot; plot.setCanvasBackground(QColor(Qt::white)); plot.setTitle("Histogram"); QwtPlotGrid *grid = new QwtPlotGrid; grid->enableXMin(true); grid->enableYMin(true); grid->setMajorPen(QPen(Qt::black, 0, Qt::DotLine)); grid->setMinorPen(QPen(Qt::gray, 0 , Qt::DotLine)); grid->attach(&plot); HistogramItem *histogram = new HistogramItem; //histogram->setColor(Qt::darkCyan); const int numValues = 20; //QwtArray<QwtDoubleInterval> intervals(numValues); QwtArray<QwtIntervalSample> intervals(numValues); QwtArray<double> values(numValues); double pos = 0.0; for ( int i = 0; i < (int)intervals.size(); i++ ) { //const int width = 5 + rand() % 15; const int value = rand() % 100; //intervals[i] = QwtDoubleInterval(pos, pos + double(width)); intervals[i] = QwtIntervalSample(value, pos, pos + double(width)); //values[i] = value; pos += width; } //histogram->setData(QwtIntervalData(intervals, values)); histogram->setSamples(intervals); //histogram->setSamples(QwtIntervalData(intervals, values)); //QwtIntervalData d; //histogram->setData(d); histogram->attach(&plot); plot.setAxisScale(QwtPlot::yLeft, 0.0, 100.0); plot.setAxisScale(QwtPlot::xBottom, 0.0, pos); plot.replot(); plot.resize(600,400); plot.show(); return a.exec(); }
void PlotKnotPithProfile::update( const KnotPithProfile & histogram ) { QVector<QwtIntervalSample> datasHistogram(0); if ( histogram.size() > 0 ) { datasHistogram.reserve(histogram.size()); int i=0; QVector<qreal>::ConstIterator begin = histogram.begin(); const QVector<qreal>::ConstIterator end = histogram.end(); while ( begin != end ) { datasHistogram.append(QwtIntervalSample(qAcos(*begin++)*RAD_TO_DEG_FACT,i,i+1)); ++i; } } _histogramData.setSamples(datasHistogram); }
void PlotIntensityDistributionHistogram::updateDatas( const IntensityDistributionHistogram &histogram, const Interval<int> &intensityInterval ) { QVector<QwtIntervalSample> datasHistogram(0); if ( histogram.size() > 0 ) { datasHistogram.reserve(histogram.size()); int i=intensityInterval.min(); QVector<qreal>::ConstIterator begin = histogram.begin(); const QVector<qreal>::ConstIterator end = histogram.end(); while ( begin != end ) { datasHistogram.append(QwtIntervalSample(*begin++,i,i+1)); ++i; } } _histogramData.setSamples(datasHistogram); }
void PlotEllipticalAccumulationHistogram::updateDatas( const EllipticalAccumulationHistogram & histogram ) { QVector<QwtIntervalSample> datasHistogram(0); if ( histogram.size() > 0 ) { datasHistogram.reserve(histogram.size()); int i=0; QVector<qreal>::ConstIterator begin = histogram.begin(); const QVector<qreal>::ConstIterator end = histogram.end(); while ( begin != end ) { datasHistogram.append(QwtIntervalSample(*begin++,i,i+1)); ++i; } } _histogramData.setSamples(datasHistogram); }
void PlotEllipticalAccumulationHistogram::updateMaximums( const EllipticalAccumulationHistogram & histogram ) { QVector<QwtIntervalSample> datasMaximums(0); if ( histogram.nbMaximums() > 0 ) { datasMaximums.reserve(histogram.nbMaximums()); int slice; QVector<uint>::ConstIterator begin = histogram.maximums().begin(); const QVector<uint>::ConstIterator end = histogram.maximums().end(); while ( begin != end ) { slice = *begin++; datasMaximums.append(QwtIntervalSample(histogram[slice],slice,slice+1)); } } _histogramMaximums.setSamples(datasMaximums); }
int qfit::plotLinearData() { /* standard data */ data_plot = new QwtPlotCurve("data"); data_plot->setSamples(&xdata.at(0), &ydata.at(0), xdata.size()); data_plot->setSymbol(new QwtSymbol(QwtSymbol::XCross, Qt::NoBrush, QPen(Qt::black), QSize(8, 8))); data_plot->setStyle(QwtPlotCurve::NoCurve); data_plot->setRenderHint(QwtPlotItem::RenderAntialiased); /* error bars */ range_plot = new QwtPlotIntervalCurve("range"); QVector<QwtIntervalSample> range(xdata.size()); for(int i = 0; i < (int)xdata.size(); i++) { range[i] = QwtIntervalSample(xdata.at(i), ydata.at(i) - yerrors.at(i), ydata.at(i) + yerrors.at(i)); } QwtIntervalSymbol *errorbar = new QwtIntervalSymbol(QwtIntervalSymbol::Bar); errorbar->setPen(QPen(Qt::black, 1)); range_plot->setSamples(range); range_plot->setSymbol(errorbar); range_plot->setStyle(QwtPlotIntervalCurve::NoCurve); /* model */ FitTools::LinearFitResult tmp = fit->getLinearResult(); double x[2], y[2]; x[0] = xdata.at(0); x[1] = xdata.back(); y[0] = tmp.m * x[0] + tmp.q; y[1] = tmp.m * x[1] + tmp.q; model_plot = new QwtPlotCurve("y=mx+q"); model_plot->setSamples(x, y, 2); model_plot->setPen(QPen(Qt::red, 1)); model_plot->setRenderHint(QwtPlotItem::RenderAntialiased); data_plot->attach(qwtPlot); range_plot->attach(qwtPlot); model_plot->attach(qwtPlot); return(0); }
void RangeSelectWidget::updateHistogram() { const ndimdata::DataStatistic &statistic(m_statistic); const QVector<size_t> bins = QVector<size_t>::fromStdVector(statistic.histogram); double min = statistic.min; double max = statistic.max; double bin_width = (max - min) / bins.size(); double previous = min; double current = min + bin_width; QVector<QwtIntervalSample> samples; for (int i = 0; i < bins.size(); ++i, previous = current, current += bin_width) samples << QwtIntervalSample(bins[i] + std::numeric_limits<double>::epsilon(), previous, current); histogram->setSamples(new HistogramSeriesData(samples)); // ui->histogram->setAxisScale(QwtPlot::xBottom, min, max); zoneData->setInterval(QwtInterval(statistic.min, statistic.max)); }
void QgsCurveEditorWidget::updateHistogram() { if ( !mHistogram ) return; //draw histogram QBrush histoBrush( QColor( 0, 0, 0, 70 ) ); delete mPlotHistogram; mPlotHistogram = createPlotHistogram( histoBrush ); QVector<QwtIntervalSample> dataHisto; int bins = 40; QList<double> edges = mHistogram->binEdges( bins ); QList<int> counts = mHistogram->counts( bins ); // scale counts to 0->1 double max = *std::max_element( counts.constBegin(), counts.constEnd() ); // scale bin edges to fit in 0->1 range if ( !qgsDoubleNear( mMinValueRange, mMaxValueRange ) ) { std::transform( edges.begin(), edges.end(), edges.begin(), [this]( double d ) -> double { return ( d - mMinValueRange ) / ( mMaxValueRange - mMinValueRange ); } ); } for ( int bin = 0; bin < bins; ++bin ) { double binValue = counts.at( bin ) / max; double upperEdge = edges.at( bin + 1 ); dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge ); } mPlotHistogram->setSamples( dataHisto ); mPlotHistogram->attach( mPlot ); mPlot->replot(); }
void PlotNearestPointsHistogram::updateIntervals( const NearestPointsHistogram & histogram ) { QVector<QwtIntervalSample> dataIntervals(0); if ( histogram.nbIntervals() > 0 ) { dataIntervals.reserve(histogram.nbIntervals()); uint i, min, max; QVector< Interval<uint> >::ConstIterator begin = histogram.intervals().begin(); const QVector< Interval<uint> >::ConstIterator end = histogram.intervals().end(); qDebug() << "Intervalles de nœuds :"; while ( begin != end ) { min = (*begin).min(); max = (*begin++).max(); for ( i=min ; i<=max ; ++i ) { dataIntervals.append(QwtIntervalSample(histogram[i],i,i+1)); } qDebug() << " [ " << min << ", " << max << " ] avec largeur = " << max-min; } } _histogramIntervals.setSamples(dataIntervals); }
void caStripPlot::RescaleCurves(int width, units unit, double period) { HISTORY = width; // equals canvas width if(unit == Millisecond) { timeInterval = period / (double) HISTORY; INTERVAL = period / 1000.0; } else if(unit == Second) { timeInterval = 1000.0 * period / (double) HISTORY; INTERVAL = period; } else if(unit == Minute) { timeInterval = 1000.0 * period * 60.0 / (double) HISTORY; INTERVAL = period * 60; } else { // printf("\nunknown unit\n"); timeInterval = 1000.0 * period * 60.0 / (double) HISTORY; INTERVAL = period; } mutex.lock(); for(int i=0; i < MAXCURVES; i++) { // define interval data for error and fill curves rangeData[i].clear(); fillData[i].clear(); if(i==0) base.clear(); for ( int j = 0; j < MULTFOROVERLAPPINGTIMES * HISTORY; j++ ) { rangeData[i].append(QwtIntervalSample(0, QwtInterval(0.0, 0.0))); fillData[i].append(QwtIntervalSample(0, QwtInterval(0.0, 0.0))); if(i==0) base.append(QwtIntervalSample(0, QwtInterval(0.0, 0.0))); } } for(int i=0; i < NumberOfCurves; i++) { if(thisStyle[i] == FillUnder) fillcurve[i]->setSamples(fillData[i].toVector()); errorcurve[i]->setSamples(rangeData[i].toVector()); } mutex.unlock(); // define update rate dataCount = 0; updateRate = (int) (100.0 / timeInterval / 2.0); if(updateRate < 1) updateRate=1; //printf("\n width=%d period=%f timerInterval=%d updaterate=%d\n", HISTORY, period, (int) timeInterval, updateRate); timerCount = 0; if(timerID) { // change display timer interval int interval = qMax((int)timeInterval, 20); Timer->setInterval(interval); Timer->start(); // stop run method of thread and redefine repetition time then start run emit timerThreadStop(); timerThread->wait(200); timerThread->threadSetTimer((int) timeInterval); timerThread->start(); } replot(); }
// data collection done by timerthread void caStripPlot::TimeOutThread() { int c, i; double elapsedTime = 0.0; QwtIntervalSample tmp; double value = 0.0; double elapsed=0.0; if(!timerID) return; mutex.lock(); int dataCountLimit = (int) (MULTFOROVERLAPPINGTIMES * HISTORY -1); // we need an exact time scale if(Start) { Start = false; ftime(&timeStart); } ftime(&timeNow); elapsedTime = ((double) timeNow.time + (double) timeNow.millitm / (double)1000) - ((double) timeStart.time + (double) timeStart.millitm / (double)1000); timeData = INTERVAL + elapsedTime; if(dataCount > 1) { // shift data and our timebase for the fixed scale if(thisXaxisType != TimeScale) { for (c = 0; c < NumberOfCurves; c++ ) { // shift left and cur last rangeData[c].prepend(tmp); rangeData[c].removeLast(); if(thisStyle[c] == FillUnder) { fillData[c].prepend(tmp); fillData[c].removeLast(); } } base.prepend(tmp); base.removeLast(); elapsed = elapsedTime + INTERVAL; for (i = dataCount; i > 0; i-- ) { value = base[i].value - elapsed; // correct value to fit again inside the interval if(Unit == Millisecond) { value = value * 1000.0; } else if(Unit == Minute) { value = value / 60.0; } for (c = 0; c < NumberOfCurves; c++ ) { rangeData[c][i].value = fillData[c][i].value = value; } } // shift data } else { for (c = 0; c < NumberOfCurves; c++ ) { rangeData[c].prepend(tmp); if(thisStyle[c] == FillUnder) fillData[c].prepend(tmp); rangeData[c].removeLast(); if(thisStyle[c] == FillUnder) fillData[c].removeLast(); } } } // advance data points if (dataCount < dataCountLimit) dataCount++; // update last point for (int c = 0; c < NumberOfCurves; c++ ) { double y0, y1, y2, y3; // smallest vertical width of error bar must not be zero y0 = transform(QwtPlot::yLeft, minVal[c]); y1 = transform(QwtPlot::yLeft, maxVal[c]); if(qAbs(y1-y0) < 2.0) y0 = y0 + 1.0; y1= y1 - 1.0; y2 = invTransform(QwtPlot::yLeft, (int) (y0+0.5)); y3 = invTransform(QwtPlot::yLeft, (int) (y1+0.5)); // set the range into the array rangeData[c][0] = QwtIntervalSample( timeData, QwtInterval(y2, y3)); // and set also the base time if(thisXaxisType != TimeScale) { base[0] = QwtIntervalSample( timeData, QwtInterval(y2, y3)); } // and to fillunder we add a range to the fill curve if(thisStyle[c] == FillUnder) { double value, height, y4, y5; if(minVal[c] < 0.0) value = y0; else value = y1; height = canvas()->contentsRect().height(); y1 = transform(QwtPlot::yLeft, 0.0); if(y1 > height) y1 = height; if(y1 < 0.0) y1 =0.0; y4 = invTransform(QwtPlot::yLeft, (int) (value+0.5)); y5 = invTransform(QwtPlot::yLeft, (int) (y1+0.5)); // set the range into the array fillData[c][0] = QwtIntervalSample( timeData, QwtInterval(y4, y5)); } } // keep max and min for (int c = 0; c < NumberOfCurves; c++ ) { maxVal[c] = minVal[c] = actVal[c]; realMax[c] = realMin[c] = realVal[c]; } mutex.unlock(); }
// // Fetch the new set of events, merging them into the existing sets // - "Points" curve has an entry for *every* event to be displayed. // - "Span" curve has an entry for all *begin/end* flagged events. // These are initially unpaired, unless PMDA is playing games, and // so usually min/max is used as a placeholder until corresponding // begin/end event arrives. // - "Drop" curve has an entry to match up events with the parents. // The parent is the root "span" (terminology on loan from Dapper) // void TracingItem::updateEventRecords(TracingEngine *engine, QmcMetric *metric, int index) { if (metric->error(index) == 0) { QVector<QmcEventRecord> const &records = metric->eventRecords(index); int slot = 0, parentSlot = -1; QString name; // First lookup the event "slot" (aka "span" / y-axis-entry) // Strategy is to use the ID from the event (if one exists), // which must be mapped to a y-axis integer-based index. If // no ID, we fall back to metric instance ID, else just zero. // if (metric->hasInstances()) { if (metric->explicitInsts()) index = 0; slot = metric->instIndex(index); name = metric->instName(index); } else { name = metric->name(); } addTraceSpan(engine, name, slot); for (int i = 0; i < records.size(); i++) { QmcEventRecord const &record = records.at(i); my.events.append(TracingEvent(record, metric->metricID(), index)); TracingEvent &event = my.events.last(); if (event.hasIdentifier() && name == QString::null) { addTraceSpan(engine, event.spanID(), slot); } // this adds the basic point (ellipse), all events get one my.points.append(QPointF(event.timestamp(), slot)); parentSlot = -1; if (event.hasParent()) { // lookup parent in yMap parentSlot = engine->getTraceSpan(event.rootID(), parentSlot); if (parentSlot == -1) addTraceSpan(engine, event.rootID(), parentSlot); // do this on start/end only? (or if first?) my.drops.append(QwtIntervalSample(event.timestamp(), QwtInterval(slot, parentSlot))); } #if DESPERATE QString timestamp = QmcSource::timeStringBrief(record.timestamp()); console->post(PmChart::DebugForce, "TracingItem::updateEventRecords: " "[%s] span: %s (slot=%d) id=%s, root: %s (slot=%d,id=%s), start=%s end=%s", (const char *)timestamp.toLatin1(), (const char *)event.spanID().toLatin1(), slot, event.hasIdentifier() ? "y" : "n", (const char *)event.rootID().toLatin1(), parentSlot, event.hasParent() ? "y" : "n", event.hasStartFlag() ? "y" : "n", event.hasEndFlag() ? "y" : "n"); #endif if (event.hasStartFlag()) { if (!my.spans.isEmpty()) { QwtIntervalSample &active = my.spans.last(); // did we get a start, then another start? // (if so, just end the previous span now) if (active.interval.maxValue() == my.maxSpanTime) active.interval.setMaxValue(event.timestamp()); } // no matter what, we'll start a new span here my.spans.append(QwtIntervalSample(slot, QwtInterval(event.timestamp(), my.maxSpanTime))); } if (event.hasEndFlag()) { if (!my.spans.isEmpty()) { QwtIntervalSample &active = my.spans.last(); // did we get an end, then another end? // (if so, move previous span end to now) if (active.interval.maxValue() == my.maxSpanTime) active.interval.setMaxValue(event.timestamp()); } else { // got an end, but we haven't seen a start my.spans.append(QwtIntervalSample(index, QwtInterval(my.minSpanTime, event.timestamp()))); } } // Have not yet handled missed events (i.e. event.missed()) // Could have a separate list of events? (render differently?) } } else { #if DESPERATE // // TODO: need to track this failure point, and ensure that the // begin/end spans do not cross this boundary. // console->post(PmChart::DebugForce, "TracingItem::updateEventRecords: NYI error path: %d (%s)", metric->error(index), pmErrStr(metric->error(index))); #endif } }
void QgsHistogramWidget::drawHistogram() { // clear plot mpPlot->detachItems(); //ensure all children get removed mpPlot->setAutoDelete( true ); // Set axis titles if ( !mXAxisTitle.isEmpty() ) mpPlot->setAxisTitle( QwtPlot::xBottom, mXAxisTitle ); if ( !mYAxisTitle.isEmpty() ) mpPlot->setAxisTitle( QwtPlot::yLeft, mYAxisTitle ); mpPlot->setAxisFont( QwtPlot::xBottom, this->font() ); mpPlot->setAxisFont( QwtPlot::yLeft, this->font() ); QFont titleFont = this->font(); titleFont.setBold( true ); QwtText xAxisText = mpPlot->axisTitle( QwtPlot::xBottom ); xAxisText.setFont( titleFont ); mpPlot->setAxisTitle( QwtPlot::xBottom, xAxisText ); QwtText yAxisText = mpPlot->axisTitle( QwtPlot::yLeft ); yAxisText.setFont( titleFont ); mpPlot->setAxisTitle( QwtPlot::yLeft, yAxisText ); mpPlot->setAxisAutoScale( QwtPlot::yLeft ); mpPlot->setAxisAutoScale( QwtPlot::xBottom ); // add a grid QwtPlotGrid *grid = new QwtPlotGrid(); grid->enableX( false ); grid->setPen( mGridPen ); grid->attach( mpPlot ); // make colors list mHistoColors.clear(); Q_FOREACH ( const QgsRendererRange &range, mRanges ) { mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black ); } //draw histogram QwtPlotHistogram *plotHistogram = nullptr; plotHistogram = createPlotHistogram( !mRanges.isEmpty() ? mRanges.at( 0 ).label() : QString(), !mRanges.isEmpty() ? QBrush( mHistoColors.at( 0 ) ) : mBrush, !mRanges.isEmpty() ? Qt::NoPen : mPen ); QVector<QwtIntervalSample> dataHisto; int bins = mBinsSpinBox->value(); QList<double> edges = mHistogram.binEdges( bins ); QList<int> counts = mHistogram.counts( bins ); int rangeIndex = 0; int lastValue = 0; for ( int bin = 0; bin < bins; ++bin ) { int binValue = counts.at( bin ); //current bin crosses two graduated ranges, so we split between //two histogram items if ( rangeIndex < mRanges.count() - 1 && edges.at( bin ) > mRanges.at( rangeIndex ).upperValue() ) { rangeIndex++; plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); plotHistogram = createPlotHistogram( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) ); dataHisto.clear(); dataHisto << QwtIntervalSample( lastValue, mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) ); } double upperEdge = !mRanges.isEmpty() ? qMin( edges.at( bin + 1 ), mRanges.at( rangeIndex ).upperValue() ) : edges.at( bin + 1 ); dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge ); lastValue = binValue; } plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); mRangeMarkers.clear(); Q_FOREACH ( const QgsRendererRange &range, mRanges ) { QwtPlotMarker *rangeMarker = new QwtPlotMarker(); rangeMarker->attach( mpPlot ); rangeMarker->setLineStyle( QwtPlotMarker::VLine ); rangeMarker->setXValue( range.upperValue() ); rangeMarker->setLabel( QString::number( range.upperValue() ) ); rangeMarker->setLabelOrientation( Qt::Vertical ); rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop ); rangeMarker->show(); mRangeMarkers << rangeMarker; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RicGridStatisticsDialog::setHistogramData(RimGridView* view) { deletePlotItems(m_historgramPlot); deletePlotItems(m_aggregatedPlot); if (view && view->overlayInfoConfig()) { Rim3dOverlayInfoConfig* overlayInfo = view->overlayInfoConfig(); auto hist = new QwtPlotHistogram("Histogram"); auto aggr = new QwtPlotCurve("Aggregated"); hist->setBrush(QBrush(QColor(Qt::darkCyan))); hist->setZ(-1); aggr->setStyle(QwtPlotCurve::Steps); aggr->setCurveAttribute(QwtPlotCurve::Inverted); Rim3dOverlayInfoConfig::HistogramData histogramData = overlayInfo->histogramData(); if (histogramData.isValid()) { QVector<QwtIntervalSample> histSamples; QVector<QPointF> aggrSamples; double xStep = (histogramData.max - histogramData.min) / (*histogramData.histogram).size(); double xCurr = histogramData.min; double aggrValue = 0.0; for (size_t value : *histogramData.histogram) { double xNext = xCurr + xStep; histSamples.push_back(QwtIntervalSample(value, xCurr, xNext)); aggrValue += value; aggrSamples.push_back(QPointF(xCurr, aggrValue)); xCurr = xNext; } // Axis double xAxisSize = histogramData.max - histogramData.min; double xAxisExtension = xAxisSize * 0.02; m_historgramPlot->setAxisScale(QwtPlot::xBottom, histogramData.min - xAxisExtension, histogramData.max + xAxisExtension); m_aggregatedPlot->setAxisScale(QwtPlot::xBottom, histogramData.min - xAxisExtension, histogramData.max + xAxisExtension); // Set y axis label area width m_historgramPlot->axisScaleDraw(QwtPlot::yLeft)->setMinimumExtent(60); m_aggregatedPlot->axisScaleDraw(QwtPlot::yLeft)->setMinimumExtent(60); // Samples hist->setSamples(histSamples); aggr->setSamples(aggrSamples); hist->attach(m_historgramPlot); aggr->attach(m_aggregatedPlot); // Markers setMarkers(histogramData, m_historgramPlot); setMarkers(histogramData, m_aggregatedPlot); } } // Refresh plot m_historgramPlot->replot(); m_aggregatedPlot->replot(); }
void QgsHistogramWidget::drawHistogram() { if ( !mVectorLayer || mSourceFieldExp.isEmpty() ) return; QApplication::setOverrideCursor( Qt::WaitCursor ); if ( mValues.empty() ) { bool ok; mValues = mVectorLayer->getDoubleValues( mSourceFieldExp, ok ); if ( ! ok ) { QApplication::restoreOverrideCursor(); return; } qSort( mValues.begin(), mValues.end() ); mHistogram.setValues( mValues ); mBinsSpinBox->blockSignals( true ); mBinsSpinBox->setValue( qMax( mHistogram.optimalNumberBins(), 30 ) ); mBinsSpinBox->blockSignals( false ); mStats.setStatistics( QgsStatisticalSummary::StDev ); mStats.calculate( mValues ); } // clear plot mpPlot->detachItems(); //ensure all children get removed mpPlot->setAutoDelete( true ); // Set axis titles mpPlot->setAxisTitle( QwtPlot::xBottom, QObject::tr( "Value" ) ); mpPlot->setAxisTitle( QwtPlot::yLeft, QObject::tr( "Count" ) ); mpPlot->setAxisAutoScale( QwtPlot::yLeft ); mpPlot->setAxisAutoScale( QwtPlot::xBottom ); // add a grid QwtPlotGrid * grid = new QwtPlotGrid(); grid->enableX( false ); grid->setPen( mGridPen ); grid->attach( mpPlot ); // make colors list mHistoColors.clear(); foreach ( QgsRendererRangeV2 range, mRanges ) { mHistoColors << ( range.symbol() ? range.symbol()->color() : Qt::black ); } //draw histogram #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 QwtPlotHistogram * plotHistogram = 0; plotHistogram = createPlotHistogram( mRanges.count() > 0 ? mRanges.at( 0 ).label() : QString(), mRanges.count() > 0 ? QBrush( mHistoColors.at( 0 ) ) : mBrush, mRanges.count() > 0 ? Qt::NoPen : mPen ); #else HistogramItem *plotHistogramItem = 0; plotHistogramItem = createHistoItem( mRanges.count() > 0 ? mRanges.at( 0 ).label() : QString(), mRanges.count() > 0 ? QBrush( mHistoColors.at( 0 ) ) : mBrush, mRanges.count() > 0 ? Qt::NoPen : mPen ); #endif #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 QVector<QwtIntervalSample> dataHisto; #else // we safely assume that QT>=4.0 (min version is 4.7), therefore QwtArray is a QVector, so don't set size here QwtArray<QwtDoubleInterval> intervalsHisto; QwtArray<double> valuesHisto; #endif int bins = mBinsSpinBox->value(); QList<double> edges = mHistogram.binEdges( bins ); QList<int> counts = mHistogram.counts( bins ); int rangeIndex = 0; int lastValue = 0; for ( int bin = 0; bin < bins; ++bin ) { int binValue = counts.at( bin ); //current bin crosses two graduated ranges, so we split between //two histogram items if ( rangeIndex < mRanges.count() - 1 && edges.at( bin ) > mRanges.at( rangeIndex ).upperValue() ) { rangeIndex++; #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); plotHistogram = createPlotHistogram( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) ); dataHisto.clear(); dataHisto << QwtIntervalSample( lastValue, mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) ); #else plotHistogramItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) ); plotHistogramItem->attach( mpPlot ); plotHistogramItem = createHistoItem( mRanges.at( rangeIndex ).label(), mHistoColors.at( rangeIndex ) ); intervalsHisto.clear(); valuesHisto.clear(); intervalsHisto.append( QwtDoubleInterval( mRanges.at( rangeIndex - 1 ).upperValue(), edges.at( bin ) ) ); valuesHisto.append( lastValue ); #endif } double upperEdge = mRanges.count() > 0 ? qMin( edges.at( bin + 1 ), mRanges.at( rangeIndex ).upperValue() ) : edges.at( bin + 1 ); #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 dataHisto << QwtIntervalSample( binValue, edges.at( bin ), upperEdge ); #else intervalsHisto.append( QwtDoubleInterval( edges.at( bin ), upperEdge ) ); valuesHisto.append( double( binValue ) ); #endif lastValue = binValue; } #if defined(QWT_VERSION) && QWT_VERSION>=0x060000 plotHistogram->setSamples( dataHisto ); plotHistogram->attach( mpPlot ); #else plotHistogramItem->setData( QwtIntervalData( intervalsHisto, valuesHisto ) ); plotHistogramItem->attach( mpPlot ); #endif mRangeMarkers.clear(); foreach ( QgsRendererRangeV2 range, mRanges ) { QwtPlotMarker* rangeMarker = new QwtPlotMarker(); rangeMarker->attach( mpPlot ); rangeMarker->setLineStyle( QwtPlotMarker::VLine ); rangeMarker->setXValue( range.upperValue() ); rangeMarker->setLabel( QString::number( range.upperValue() ) ); rangeMarker->setLabelOrientation( Qt::Vertical ); rangeMarker->setLabelAlignment( Qt::AlignLeft | Qt::AlignTop ); rangeMarker->show(); mRangeMarkers << rangeMarker; }