diff options
author | Tim Moore <timoore@redhat.com> | 2009-05-27 10:32:51 +0200 |
---|---|---|
committer | Tim Moore <timoore@redhat.com> | 2009-07-28 10:17:29 +0200 |
commit | 5f4f8b1129659adb2015ce42821faccf8fe6d8d5 (patch) | |
tree | 9fdb07036f2461a01f8efa1f5d07f496191e71bc /grapher/GraphWidget.cxx | |
parent | 95ddfc079a1d9affdb285f7690f8d5623cd7124a (diff) | |
download | systemtap-steved-5f4f8b1129659adb2015ce42821faccf8fe6d8d5.tar.gz systemtap-steved-5f4f8b1129659adb2015ce42821faccf8fe6d8d5.tar.xz systemtap-steved-5f4f8b1129659adb2015ce42821faccf8fe6d8d5.zip |
Templatize GraphData
* grapher/GraphData.hxx (GraphDataBase): new superclass for
GraphData. Split time data out as a separate vector.
(GraphData): Rewrite as template.
* grapher/GraphWidget.cxx (on_expose_event): Reflect GraphData
templatization. Handle events with string values.
* grapher/GraphWidget.hxx (GraphWidget): Keep pointers to
GraphDataBase objects instead of GraphData.
* grapher/StapParser.cxx (parseData): new member function
(ioCallback): Handle new discreet event
* grapher/StapParser.hxx (StapParser): keep pointers to GraphDataBase
objects instead of GraphData
* testsuite/systemtap.examples/general/grapher.stp: Display actual key
pressed for keyboard event
Diffstat (limited to 'grapher/GraphWidget.cxx')
-rw-r--r-- | grapher/GraphWidget.cxx | 85 |
1 files changed, 62 insertions, 23 deletions
diff --git a/grapher/GraphWidget.cxx b/grapher/GraphWidget.cxx index 34b4daf4..d62ec4f3 100644 --- a/grapher/GraphWidget.cxx +++ b/grapher/GraphWidget.cxx @@ -2,6 +2,7 @@ #include <ctime> #include <math.h> #include <sstream> +#include <iostream> #include <iomanip> #include <cairomm/context.h> #include "GraphWidget.hxx" @@ -9,6 +10,8 @@ namespace systemtap { + using std::string; + GraphWidget::GraphWidget() : _left(0.0), _right(1.0), _top(1.0), _bottom(0.0), _lineWidth(10), _autoScaling(true), _autoScrolling(true), _zoomFactor(1.0), @@ -55,7 +58,7 @@ namespace systemtap { } - void GraphWidget::addGraphData(std::tr1::shared_ptr<GraphData> data) + void GraphWidget::addGraphData(std::tr1::shared_ptr<GraphDataBase> data) { _datasets.push_back(data); } @@ -94,9 +97,9 @@ namespace systemtap ditr != de; ++ditr) { - if (!(*ditr)->data.empty()) + if (!(*ditr)->times.empty()) { - double lastDataTime = (*ditr)->data.back().first; + double lastDataTime = (*ditr)->times.back(); if (lastDataTime > latestTime) latestTime = lastDataTime; } @@ -108,16 +111,16 @@ namespace systemtap ditr != de; ++ditr) { - GraphData::List& gdata = (*ditr)->data; - if (gdata.size() <= 1) + GraphDataBase::TimeList& gtimes = (*ditr)->times; + if (gtimes.size() <= 1) continue; double totalDiff = 0.0; - for (GraphData::List::reverse_iterator ritr = gdata.rbegin(), - re = gdata.rend(); - ritr + 1 != gdata.rend(); + for (GraphDataBase::TimeList::reverse_iterator ritr = gtimes.rbegin(), + re = gtimes.rend(); + ritr + 1 != gtimes.rend(); ritr++) { - double timeDiff = ritr->first - (ritr + 1)->first; + double timeDiff = *ritr - *(ritr + 1); if (timeDiff < minDiff || (timeDiff != 0 && minDiff == 0)) minDiff = timeDiff; if (minDiff != 0 @@ -148,35 +151,71 @@ namespace systemtap itr != e; ++itr) { + std::tr1::shared_ptr<GraphData<double> > realData + = std::tr1::dynamic_pointer_cast<GraphData<double> >(*itr); + std::tr1::shared_ptr<GraphData<string> > stringData + = std::tr1::dynamic_pointer_cast<GraphData<string> >(*itr); cr->save(); cr->translate(0.0, height); cr->scale(1.0, -1.0); - GraphData::List::iterator lower - = std::lower_bound((*itr)->data.begin(), (*itr)->data.end(), _left, - GraphData::Compare()); - GraphData::List::iterator upper - = std::upper_bound((*itr)->data.begin(), (*itr)->data.end(), _right, - GraphData::Compare()); - for (GraphData::List::iterator ditr = lower, de = upper; + GraphDataBase::TimeList::iterator lower + = std::lower_bound((*itr)->times.begin(), (*itr)->times.end(), _left); + GraphDataBase::TimeList::iterator upper + = std::upper_bound((*itr)->times.begin(), (*itr)->times.end(), + _right); + // event bar + if ((*itr)->style == GraphDataBase::EVENT) + { + double eventHeight = height * ((*itr)->scale / 100.0); + cr->save(); + cr->set_line_width(3 * _lineWidth); + cr->set_source_rgba((*itr)->color[0], (*itr)->color[1], + (*itr)->color[2], .33); + cr->move_to(0, eventHeight); + cr->line_to(width, eventHeight); + cr->stroke(); + cr->restore(); + } + for (GraphDataBase::TimeList::iterator ditr = lower, de = upper; ditr != de; ++ditr) { + size_t dataIndex = ditr - (*itr)->times.begin(); cr->set_source_rgba((*itr)->color[0], (*itr)->color[1], (*itr)->color[2], 1.0); - if ((*itr)->style == GraphData::BAR) + if ((*itr)->style == GraphDataBase::BAR && realData) { - cr->move_to((ditr->first - _left) * horizScale, 0); - cr->line_to((ditr->first - _left) * horizScale, - ditr->second * height / (*itr)->scale); + cr->move_to((*ditr - _left) * horizScale, 0); + cr->line_to((*ditr - _left) * horizScale, + realData->data[dataIndex] * height / (*itr)->scale); cr->stroke(); } - else + else if ((*itr)->style == GraphDataBase::DOT && realData) { - cr->arc((ditr->first - _left) * horizScale, - ditr->second * height / (*itr)->scale, + cr->arc((*ditr - _left) * horizScale, + realData->data[dataIndex] * height / (*itr)->scale, _lineWidth / 2.0, 0.0, M_PI * 2.0); cr->fill(); } + else if ((*itr)->style == GraphDataBase::EVENT && stringData) + { + double eventHeight = height * ((*itr)->scale / 100.0); + cr->save(); + cr->select_font_face("Sans", Cairo::FONT_SLANT_NORMAL, + Cairo::FONT_WEIGHT_NORMAL); + cr->set_font_size(12.0); + cr->save(); + cr->scale(1.0, -1.0); + cr->move_to((*ditr - _left) * horizScale, + -eventHeight -3.0 * _lineWidth - 2.0); + cr->show_text(stringData->data[dataIndex]); + cr->restore(); + cr->rectangle((*ditr - _left) * horizScale - 1.5 * _lineWidth, + eventHeight - 1.5 * _lineWidth, + 3.0 * _lineWidth, 3.0 * _lineWidth); + cr->fill(); + cr->restore(); + } } cr->restore(); } |