summaryrefslogtreecommitdiffstats
path: root/grapher/Graph.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'grapher/Graph.cxx')
-rw-r--r--grapher/Graph.cxx123
1 files changed, 34 insertions, 89 deletions
diff --git a/grapher/Graph.cxx b/grapher/Graph.cxx
index a7fe6fcf..55ffcdf2 100644
--- a/grapher/Graph.cxx
+++ b/grapher/Graph.cxx
@@ -13,8 +13,9 @@ namespace systemtap
: _width(600), _height(200), _graphX(0), _graphY(0),
_graphWidth(580), _graphHeight(180),
_lineWidth(2), _autoScaling(true), _autoScrolling(true),
- _zoomFactor(1.0), _playButton(new CairoPlayButton),
- _left(0.0), _right(1.0), _top(5.0), _bottom(0.0)
+ _zoomFactor(1.0), _xOffset(20.0), _yOffset(0.0),
+ _playButton(new CairoPlayButton),
+ _left(0), _right(1), _top(5.0), _bottom(0.0)
{
setOrigin(x, y);
_graphX = x;
@@ -30,7 +31,7 @@ namespace systemtap
// line separation
int linesPossible = (int)(_graphWidth / (_lineWidth + 2.0));
// Find latest time.
- double latestTime = 0.0;
+ int64_t latestTime = 0;
for (DatasetList::iterator ditr = _datasets.begin(),
de = _datasets.end();
ditr != de;
@@ -38,13 +39,13 @@ namespace systemtap
{
if (!(*ditr)->times.empty())
{
- double lastDataTime = (*ditr)->times.back();
+ int64_t lastDataTime = (*ditr)->times.back();
if (lastDataTime > latestTime)
latestTime = lastDataTime;
}
}
- double minDiff = 0.0;
- double maxTotal = 0.0;
+ int64_t minDiff = 0;
+ int64_t maxTotal = 0;
for (DatasetList::iterator ditr = _datasets.begin(),
de = _datasets.end();
ditr != de;
@@ -59,11 +60,11 @@ namespace systemtap
ritr + 1 != gtimes.rend();
ritr++)
{
- double timeDiff = *ritr - *(ritr + 1);
+ int64_t timeDiff = *ritr - *(ritr + 1);
if (timeDiff < minDiff || (timeDiff != 0 && minDiff == 0))
minDiff = timeDiff;
if (minDiff != 0
- && (totalDiff + timeDiff) / minDiff > linesPossible)
+ && ((totalDiff + timeDiff) / minDiff + 1) > linesPossible)
break;
totalDiff += timeDiff;
}
@@ -75,11 +76,12 @@ namespace systemtap
if (maxTotal != 0)
_left = latestTime - maxTotal;
else
- _left = _right - 1.0;
+ _left = _right - 1;
}
cr->save();
- double horizScale = _zoomFactor * _graphWidth / ( _right - _left);
- cr->translate(20.0, 0.0);
+ double horizScale
+ = _zoomFactor * _graphWidth / static_cast<double>(_right - _left);
+ cr->translate(_xOffset, _yOffset);
cr->set_line_width(_lineWidth);
for (DatasetList::iterator itr = _datasets.begin(), e = _datasets.end();
@@ -87,74 +89,10 @@ namespace systemtap
++itr)
{
shared_ptr<GraphDataBase> graphData = *itr;
- shared_ptr<GraphData<double> > realData
- = dynamic_pointer_cast<GraphData<double> >(*itr);
- shared_ptr<GraphData<string> > stringData
- = dynamic_pointer_cast<GraphData<string> >(*itr);
cr->save();
cr->translate(0.0, _graphHeight);
cr->scale(1.0, -1.0);
- GraphDataBase::TimeList::iterator lower
- = std::lower_bound(graphData->times.begin(), graphData->times.end(),
- _left);
- GraphDataBase::TimeList::iterator upper
- = std::upper_bound(graphData->times.begin(), graphData->times.end(),
- _right);
- // event bar
- if (graphData->style == GraphDataBase::EVENT)
- {
- double eventHeight = _graphHeight * (graphData->scale / 100.0);
- cr->save();
- cr->set_line_width(3 * _lineWidth);
- cr->set_source_rgba(graphData->color[0], graphData->color[1],
- graphData->color[2], .33);
- cr->move_to(0, eventHeight);
- cr->line_to(_graphWidth, eventHeight);
- cr->stroke();
- cr->restore();
- }
- for (GraphDataBase::TimeList::iterator ditr = lower, de = upper;
- ditr != de;
- ++ditr)
- {
- size_t dataIndex = ditr - graphData->times.begin();
- cr->set_source_rgba(graphData->color[0], graphData->color[1],
- graphData->color[2], 1.0);
- if (graphData->style == GraphDataBase::BAR && realData)
- {
- cr->move_to((*ditr - _left) * horizScale, 0);
- cr->line_to((*ditr - _left) * horizScale,
- realData->data[dataIndex] * _graphHeight
- / graphData->scale);
- cr->stroke();
- }
- else if (graphData->style == GraphDataBase::DOT && realData)
- {
- cr->arc((*ditr - _left) * horizScale,
- realData->data[dataIndex] * _graphHeight / graphData->scale,
- _lineWidth / 2.0, 0.0, M_PI * 2.0);
- cr->fill();
- }
- else if (graphData->style == GraphDataBase::EVENT && stringData)
- {
- double eventHeight = _graphHeight * (graphData->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();
- }
- }
+ graphData->style->draw(graphData, this, cr);
cr->restore();
cr->save();
cr->select_font_face("Sans", Cairo::FONT_SLANT_NORMAL,
@@ -186,9 +124,10 @@ namespace systemtap
}
cr->restore();
// Draw axes
- double diff = _right - _left;
- double majorUnit = pow(10.0, floor(log(diff) / log(10.0)));
- double startTime = ceil(_left / majorUnit) * majorUnit;
+ double diff = static_cast<double>(_right - _left);
+ int64_t majorUnit
+ = static_cast<int64_t>(pow(10.0, floor(log(diff) / log(10.0))));
+ int64_t startTime = (_left / majorUnit) * majorUnit;
cr->save();
cr->set_source_rgba(1.0, 1.0, 1.0, .9);
cr->set_line_cap(Cairo::LINE_CAP_BUTT);
@@ -196,28 +135,28 @@ namespace systemtap
cr->select_font_face("Sans", Cairo::FONT_SLANT_NORMAL,
Cairo::FONT_WEIGHT_NORMAL);
cr->set_font_size(10.0);
- cr->move_to(20.0, 0.0);
- cr->line_to(20.0, _height);
- cr->move_to(20.0, _graphHeight);
+ cr->move_to(_xOffset, _yOffset);
+ cr->line_to(_xOffset, _height);
+ cr->move_to(_xOffset, _graphHeight);
cr->line_to(_graphWidth, _graphHeight);
cr->stroke();
std::valarray<double> dash(1);
dash[0] = _graphHeight / 10;
cr->set_dash(dash, 0);
double prevTextAdvance = 0;
- for (double tickVal = startTime; tickVal <= _right; tickVal += majorUnit)
+ for (int64_t tickVal = startTime; tickVal <= _right; tickVal += majorUnit)
{
- double x = (tickVal - _left) * horizScale + 20.0;
- cr->move_to(x, 0.0);
+ double x = (tickVal - _left) * horizScale + _xOffset;
+ cr->move_to(x, _yOffset);
cr->line_to(x, _graphHeight);
- cr->move_to(x, _graphHeight - 5);
std::ostringstream stream;
- stream << std::fixed << std::setprecision(0) << tickVal;
+ stream << tickVal;
Cairo::TextExtents extents;
cr->get_text_extents(stream.str(), extents);
// Room for this label?
if (x + extents.x_bearing > prevTextAdvance)
{
+ cr->move_to(x, _graphHeight + 5 + extents.height);
cr->show_text(stream.str());
prevTextAdvance = x + extents.x_advance;
}
@@ -239,7 +178,7 @@ namespace systemtap
_datasets.push_back(data);
}
- void Graph::getExtents(double& left, double& right, double& top,
+ void Graph::getExtents(int64_t& left, int64_t& right, double& top,
double& bottom) const
{
left = _left;
@@ -248,7 +187,7 @@ namespace systemtap
bottom = _bottom;
}
- void Graph::setExtents(double left, double right, double top, double bottom)
+ void Graph::setExtents(int64_t left, int64_t right, double top, double bottom)
{
_left = left;
_right = right;
@@ -260,4 +199,10 @@ namespace systemtap
{
return x >= _x0 && x < _x0 + _width && y >= _y0 && y < _y0 + _height;
}
+
+ int64_t Graph::getTimeAtPoint(double x)
+ {
+ return (_left
+ + (_right - _left) * ((x - _xOffset)/(_zoomFactor * _graphWidth)));
+ }
}