summaryrefslogtreecommitdiffstats
path: root/grapher/GraphStyle.cxx
diff options
context:
space:
mode:
authorTim Moore <timoore@redhat.com>2009-12-03 19:31:08 +0100
committerTim Moore <timoore@redhat.com>2009-12-03 19:31:08 +0100
commit03ebf81c360e429ef1e4f8bae48fe524f712589a (patch)
treef16a68b7f8cb14224d0e38181fea21617c93e9d8 /grapher/GraphStyle.cxx
parentc10fce7d6aaa57a4f94f9d7aeea906597456f7ce (diff)
downloadsystemtap-steved-03ebf81c360e429ef1e4f8bae48fe524f712589a.tar.gz
systemtap-steved-03ebf81c360e429ef1e4f8bae48fe524f712589a.tar.xz
systemtap-steved-03ebf81c360e429ef1e4f8bae48fe524f712589a.zip
Hover text for event-style graphs
Don't draw the data value for an event; only display it in hover text. * grapher/Graph.hxx (window2GraphCoords): new function * grapher/Graph.cxx (window2GraphCoords): ditto * grapher/GraphStyle.cxx (GraphStyleEvent::dataIndexAtPoint): new function implementation.
Diffstat (limited to 'grapher/GraphStyle.cxx')
-rw-r--r--grapher/GraphStyle.cxx48
1 files changed, 35 insertions, 13 deletions
diff --git a/grapher/GraphStyle.cxx b/grapher/GraphStyle.cxx
index 55fc73f4..cf3855e3 100644
--- a/grapher/GraphStyle.cxx
+++ b/grapher/GraphStyle.cxx
@@ -132,20 +132,9 @@ namespace systemtap
ditr != de;
++ditr)
{
- size_t dataIndex = ditr - graphData->times.begin();
+ // size_t dataIndex = ditr - graphData->times.begin();
double eventHeight = graph->_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->set_source_rgba(graphData->color[0], graphData->color[1],
- graphData->color[2], 1.0);
- cr->save();
- cr->scale(1.0, -1.0);
- cr->move_to((*ditr - left) * horizScale,
- -eventHeight - 3.0 * graph->_lineWidth - 2.0);
- cr->show_text(stringData->data[dataIndex]);
- cr->restore();
cr->rectangle((*ditr - left) * horizScale - 1.5 * graph->_lineWidth,
eventHeight - 1.5 * graph->_lineWidth,
3.0 * graph->_lineWidth, 3.0 * graph->_lineWidth);
@@ -153,5 +142,38 @@ namespace systemtap
cr->restore();
}
}
-
+
+ ssize_t GraphStyleEvent::dataIndexAtPoint(double x, double y,
+ shared_ptr<GraphDataBase> graphData,
+ shared_ptr<Graph> graph)
+ {
+ shared_ptr<GraphData<string> > stringData
+ = dynamic_pointer_cast<GraphData<string> >(graphData);
+ if (!stringData)
+ return -1;
+ int64_t left, right;
+ double top, bottom;
+ graph->getExtents(left, right, top, bottom);
+ double horizScale = (graph->_zoomFactor * graph->_graphWidth
+ / static_cast<double>(right - left));
+ double eventHeight = graph->_graphHeight * (graphData->scale / 100.0);
+ GraphDataBase::TimeList::iterator lower
+ = lower_bound(graphData->times.begin(), graphData->times.end(), left);
+ GraphDataBase::TimeList::iterator upper
+ = upper_bound(graphData->times.begin(), graphData->times.end(), right);
+ // easier to transform x,y into graph coordinates
+ double xgraph, ygraph;
+ graph->window2GraphCoords(x, y, xgraph, ygraph);
+ double yrect = eventHeight - 1.5 * graph->_lineWidth;
+ for (GraphDataBase::TimeList::iterator ditr = lower, de = upper;
+ ditr != de;
+ ++ditr)
+ {
+ double xrect = (*ditr - left) * horizScale - 1.5 * graph->_lineWidth;
+ if (xrect <= xgraph && xgraph < xrect + 3.0 * graph->_lineWidth
+ && yrect <= ygraph && ygraph < yrect + 3.0 * graph->_lineWidth)
+ return static_cast<ssize_t>(distance(lower, ditr));
+ }
+ return -1;
+ }
}