@@ -79,6 +79,11 @@ RSGraphSource::~RSGraphSource()
7979void RSGraphSource::clear ()
8080{
8181 _points.clear () ;
82+ #if QT_VERSION < 0x040700
83+ _time_orig_msecs = getCurrentMSecsSinceEpoch () ;
84+ #else
85+ _time_orig_msecs = QDateTime::currentMSecsSinceEpoch () ;
86+ #endif
8287}
8388void RSGraphSource::stop ()
8489{
@@ -121,36 +126,50 @@ void RSGraphSource::getSlicedValues(uint min_secs_ago,uint max_secs_ago,std::vec
121126 uint64_t max_ts = lst_it->second .back ().first - min_secs_ago*1000 ; // in _points the TS are w.r.t. now (in reverse) and in ms.
122127 uint64_t min_ts = lst_it->second .back ().first - max_secs_ago*1000 ;
123128
129+ #ifdef GRAPHWIDGET_DEBUG
124130 std::cerr << " Collecting data in \" " << lst_it->first << " \" between ts = " << min_ts << " and " << max_ts << std::endl;
131+ #endif
125132
126133 for (const auto & p:lst_it->second )
127134 {
135+ #ifdef GRAPHWIDGET_DEBUG
128136 std::cerr << " TS = " << p.first ;
129137 std::cerr << " data \" " << lst_it->first << " \" : Found ts = " << p.first << " : value " << p.second ;
138+ #endif
130139
131140 if ((uint64_t )p.first >= min_ts && (uint64_t )p.first <= max_ts)
132141 {
133142 v.first .v += p.second ;
134143 v.second .v ++;
135144
145+ #ifdef GRAPHWIDGET_DEBUG
136146 std::cerr << " Kept." << std::endl;
147+ #endif
137148 }
149+ #ifdef GRAPHWIDGET_DEBUG
138150 else
139151 std::cerr << std::endl;
152+ #endif
140153 }
154+ #ifdef GRAPHWIDGET_DEBUG
141155 std::cerr << " total value = " << v.first .v << " -- " << v.second .v << std::endl;
156+ #endif
142157 }
143158
144159 // now average values when multiple values have been collected.
145160
161+ #ifdef GRAPHWIDGET_DEBUG
146162 std::cerr << " Computed values: " << collected_vals.size () << std::endl;
163+ #endif
147164
148165 for (uint i=0 ;i<collected_vals.size ();++i)
149166 {
150167 const auto & v (collected_vals[i]);
151168
152169 vals.push_back ((v.second .v > 0 )?(v.first .v /v.second .v ):0.0 );
170+ #ifdef GRAPHWIDGET_DEBUG
153171 std::cerr << " \" " << displayName (i).toStdString () << " \" " << vals.back () << " (" << v.second .v << " )" << std::endl;
172+ #endif
154173 }
155174}
156175
@@ -335,15 +354,16 @@ RSGraphWidget::RSGraphWidget(QWidget *parent)
335354 _time_scale = 5 .0f ; // in pixels per second.
336355 _time_filter = 1 .0f ;
337356 _timer = new QTimer ;
338- QObject::connect (_timer,SIGNAL (timeout ()),this ,SLOT (updateIfPossible ())) ;
339-
357+ _slice_proportion = 0.0 ;
340358
341359 _y_scale = 1 .0f ;
342360 _timer->start (1000 );
343361
344362 float FS = QFontMetricsF (font ()).height ();
345363 setMinimumHeight (12 *FS);
346364 _graph_base = FS*GRAPH_BASE;
365+
366+ QObject::connect (_timer,SIGNAL (timeout ()),this ,SLOT (updateIfPossible ())) ;
347367}
348368
349369void RSGraphWidget::updateIfPossible ()
@@ -675,15 +695,27 @@ void RSGraphWidget::paintTotals()
675695 c->addAxis (axisY, Qt::AlignLeft);
676696
677697 std::vector<float > vals;
678- _source->getSlicedValues (0 ,5 ,vals);
698+
699+ qint64 total_duration_secs = _source->totalCollectedTime ()/1000.0 ;
700+ #ifdef GRAPHWIDGET_DEBUG
701+ std::cerr << " Total duration secs: " << total_duration_secs << std::endl;
702+ #endif
703+ // _source->getSlicedValues( total_duration_secs * _slice_proportion,total_duration_secs * _slice_proportion + 5,vals);
704+ _source->getSlicedValues ( 0 ,5 ,vals);
705+
706+ float max_val = 0 .0f ;
707+ for (auto v:vals)
708+ max_val = std::max (max_val,v);
679709
680710 auto pieSeries = new QtCharts::QPieSeries ();
681711
682712 for (uint i=0 ;i<vals.size ();++i)
683713 if ( _masked_entries.find (_source->displayName (i).toStdString ()) == _masked_entries.end () )
684714 {
685715 QtCharts::QPieSlice *slice = pieSeries->append (_source->legend (i,vals[i],false ),vals[i]);
686- slice->setLabelVisible (true );
716+
717+ slice->setColor ( getColor (_source->displayName (i).toStdString ()) );
718+ slice->setLabelVisible (vals[i] > 0.05 *max_val);
687719 }
688720
689721 c->resize (_rec.width (),_rec.height ());
@@ -874,6 +906,10 @@ void RSGraphWidget::mouseMoveEvent(QMouseEvent *e)
874906{
875907 if (_mousePressed)
876908 std::cerr << " e->x() = " << e->x () << std::endl;
909+
910+ setSliceProportion (e->x () / (float )width ());
911+ updateIfPossible ();
912+
877913 QFrame::mouseMoveEvent (e);
878914}
879915void RSGraphWidget::mouseReleaseEvent (QMouseEvent *e)
0 commit comments