void PfPvPlot::refreshZoneItems() { // clear out any zone curves which are presently defined if (zoneCurves.size()) { QListIterator<QwtPlotCurve *> i(zoneCurves); while (i.hasNext()) { QwtPlotCurve *curve = i.next(); curve->detach(); //delete curve; } } zoneCurves.clear(); // delete any existing power zone labels if (zoneLabels.size()) { QListIterator<PfPvPlotZoneLabel *> i(zoneLabels); while (i.hasNext()) { PfPvPlotZoneLabel *label = i.next(); label->detach(); delete label; } } zoneLabels.clear(); // set zones from ride or athlete and date of // first item in the compare set const Zones *zones; int zone_range = -1; // comparing does zones for items selected not current ride if (context->isCompareIntervals) { zones = context->athlete->zones(); // no athlete zones anyway! if (!zones) return; // use first compare interval date if (context->compareIntervals.count()) { zone_range = zones->whichRange(context->compareIntervals[0].data->startTime().date()); } // still not set if (zone_range == -1) { zone_range = zones->whichRange(QDate::currentDate()); } } else if (rideItem) { zones = rideItem->zones; zone_range = rideItem->zoneRange(); } else { return; // null ride and not compare etc } if (zone_range >= 0) { setCP(zones->getCP(zone_range)); // populate the zone curves QList <int> zone_power = zones->getZoneLows(zone_range); QList <QString> zone_name = zones->getZoneNames(zone_range); int num_zones = zone_power.size(); if (zone_name.size() != num_zones) return; if (num_zones > 0) { QPen *pen = new QPen(); pen->setStyle(Qt::NoPen); QwtArray<double> yvalues; // generate x values for (int z = 0; z < num_zones; z ++) { QwtPlotCurve *curve = new QwtPlotCurve(zone_name[z]); curve->setPen(*pen); QColor brush_color = zoneColor(z, num_zones); brush_color.setHsv(brush_color.hue(), brush_color.saturation() / 4, brush_color.value()); curve->setBrush(brush_color); // fill below the line curve->setZ(1 - 1e-6 * zone_power[z]); // generate data for curve if (z < num_zones - 1) { QwtArray <double> contour_yvalues; int watts = zone_power[z + 1]; int dwatts = (double) watts; for (int i = 0; i < contour_xvalues.size(); i ++) { contour_yvalues.append( (1e6 * contour_xvalues[i] < watts) ? 1e6 : dwatts / contour_xvalues[i]); } curve->setSamples(contour_xvalues, contour_yvalues); } else { // top zone has a curve at "infinite" power QwtArray <double> contour_x; QwtArray <double> contour_y; contour_x.append(contour_xvalues[0]); contour_x.append(contour_xvalues[contour_xvalues.size() - 1]); contour_y.append(1e6); contour_y.append(1e6); curve->setSamples(contour_x, contour_y); } curve->setVisible(shade_zones); curve->attach(this); zoneCurves.append(curve); } delete pen; // generate labels for existing zones for (int z = 0; z < num_zones; z ++) { PfPvPlotZoneLabel *label = new PfPvPlotZoneLabel(this, z); label->setVisible(shade_zones); label->attach(this); zoneLabels.append(label); } } } }
void PfPvPlot::refreshZoneItems() { // clear out any zone curves which are presently defined if (zoneCurves.size()) { QListIterator<QwtPlotCurve *> i(zoneCurves); while (i.hasNext()) { QwtPlotCurve *curve = i.next(); curve->detach(); delete curve; } } zoneCurves.clear(); // delete any existing power zone labels if (zoneLabels.size()) { QListIterator<PfPvPlotZoneLabel *> i(zoneLabels); while (i.hasNext()) { PfPvPlotZoneLabel *label = i.next(); label->detach(); delete label; } } zoneLabels.clear(); // give up for a null ride if (! rideItem) return; const Zones *zones = rideItem->zones; int zone_range = rideItem->zoneRange(); if (zone_range >= 0) { setCP(zones->getCP(zone_range)); // populate the zone curves QList <int> zone_power = zones->getZoneLows(zone_range); QList <QString> zone_name = zones->getZoneNames(zone_range); int num_zones = zone_power.size(); assert(zone_name.size() == num_zones); if (num_zones > 0) { QPen *pen = new QPen(); pen->setStyle(Qt::NoPen); QwtArray<double> yvalues; // generate x values for (int z = 0; z < num_zones; z ++) { QwtPlotCurve *curve = new QwtPlotCurve(zone_name[z]); curve->setPen(*pen); QColor brush_color = zoneColor(z, num_zones); brush_color.setHsv(brush_color.hue(), brush_color.saturation() / 4, brush_color.value()); curve->setBrush(brush_color); // fill below the line curve->setZ(1 - 1e-6 * zone_power[z]); // generate data for curve if (z < num_zones - 1) { QwtArray <double> contour_yvalues; int watts = zone_power[z + 1]; int dwatts = (double) watts; for (int i = 0; i < contour_xvalues.size(); i ++) { contour_yvalues.append( (1e6 * contour_xvalues[i] < watts) ? 1e6 : dwatts / contour_xvalues[i]); } curve->setData(contour_xvalues, contour_yvalues); } else { // top zone has a curve at "infinite" power QwtArray <double> contour_x; QwtArray <double> contour_y; contour_x.append(contour_xvalues[0]); contour_x.append(contour_xvalues[contour_xvalues.size() - 1]); contour_y.append(1e6); contour_y.append(1e6); curve->setData(contour_x, contour_y); } curve->setVisible(shade_zones); curve->attach(this); zoneCurves.append(curve); } delete pen; // generate labels for existing zones for (int z = 0; z < num_zones; z ++) { PfPvPlotZoneLabel *label = new PfPvPlotZoneLabel(this, z); label->setVisible(shade_zones); label->attach(this); zoneLabels.append(label); } } } }
//--------------------------------------------------------------------------- Plot::Plot( size_t streamPos, size_t Type, size_t Group, QWidget *parent ) : QwtPlot( parent ), m_streamPos( streamPos ), m_type( Type ), m_group( Group ) { setAutoReplot( false ); QwtPlotCanvas* canvas = dynamic_cast<QwtPlotCanvas*>( this->canvas() ); if ( canvas ) { canvas->setFrameStyle( QFrame::Plain | QFrame::Panel ); canvas->setLineWidth( 1 ); #if 1 canvas->setPalette( QColor("Cornsilk") ); #endif } setAxisMaxMajor( QwtPlot::yLeft, 0 ); setAxisMaxMinor( QwtPlot::yLeft, 0 ); setAxisScaleDraw( QwtPlot::yLeft, new PlotScaleDrawY() ); enableAxis( QwtPlot::xBottom, false ); // something invalid setAxisScale( QwtPlot::xBottom, -1, 0 ); setAxisScale( QwtPlot::yLeft, -1, 0 ); // Plot grid QwtPlotGrid *grid = new QwtPlotGrid(); grid->enableXMin( true ); grid->enableYMin( true ); grid->setMajorPen( Qt::darkGray, 0, Qt::DotLine ); grid->setMinorPen( Qt::gray, 0 , Qt::DotLine ); grid->attach( this ); m_cursor = new PlotCursor( canvas ); m_cursor->setPosition( 0 ); // curves for( unsigned j = 0; j < PerStreamType[m_type].PerGroup[m_group].Count; ++j ) { QwtPlotCurve* curve = new QwtPlotCurve( PerStreamType[m_type].PerItem[PerStreamType[m_type].PerGroup[m_group].Start + j].Name ); curve->setPen( curveColor( j ) ); curve->setRenderHint( QwtPlotItem::RenderAntialiased ); curve->setZ( curve->z() - j ); //Invert data order (e.g. MAX before MIN) curve->attach( this ); m_curves += curve; } // visual helpers if ( m_type == Type_Video ) switch (m_group) { case Group_Y : Plot_AddHLine( this, 16, 61, 89, 171); Plot_AddHLine( this, 235, 220, 20, 60); break; case Group_U : case Group_V : Plot_AddHLine( this, 16, 61, 89, 171); Plot_AddHLine( this, 240, 220, 20, 60); break; case Group_Sat : Plot_AddHLine( this, 88, 255, 0, 255); Plot_AddHLine( this, 118, 220, 20, 60); break; default : ; } PlotPicker* picker = new PlotPicker( canvas, &PerStreamType[m_type], m_group, &m_curves ); connect( picker, SIGNAL( moved( const QPointF& ) ), SLOT( onPickerMoved( const QPointF& ) ) ); connect( picker, SIGNAL( selected( const QPointF& ) ), SLOT( onPickerMoved( const QPointF& ) ) ); connect( axisWidget( QwtPlot::xBottom ), SIGNAL( scaleDivChanged() ), SLOT( onXScaleChanged() ) ); // legend m_legend = new PlotLegend(); connect( this, SIGNAL( legendDataChanged( const QVariant &, const QList<QwtLegendData> & ) ), m_legend, SLOT( updateLegend( const QVariant &, const QList<QwtLegendData> & ) ) ); updateLegend(); }
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))); }