From c10fce7d6aaa57a4f94f9d7aeea906597456f7ce Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 2 Dec 2009 19:27:07 +0100 Subject: Make the hover text conform to data displayed. Start of code to be more selective about the association between the hover text and the underling graph. Also, show the data set name in hover text. * grapher/GraphStyle.hxx (dataIndexAtPoint): New virtual function. * grapher/GraphStyle.cxx (dataIndexAtPoint): Implementation for bar graphs * grapher/GraphWidget.cxx (onHoverTimeout): Use dataIndexAtPoint. --- grapher/GraphWidget.cxx | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'grapher/GraphWidget.cxx') diff --git a/grapher/GraphWidget.cxx b/grapher/GraphWidget.cxx index 9a203d87..9067988a 100644 --- a/grapher/GraphWidget.cxx +++ b/grapher/GraphWidget.cxx @@ -276,20 +276,23 @@ namespace systemtap if (!_hoverText) _hoverText = shared_ptr(new CairoTextBox()); _hoverText->setOrigin(_mouseX + 5, _mouseY - 5); - int64_t t = g->getTimeAtPoint(_mouseX); Graph::DatasetList& dataSets = g->getDatasets(); - if (!dataSets.empty()) - { - shared_ptr gdbase = dataSets[0]; - GraphDataBase::TimeList::iterator itime - = std::lower_bound(gdbase->times.begin(), gdbase->times.end(), t); - if (itime != gdbase->times.end()) { - size_t index = distance(gdbase->times.begin(), itime); - _hoverText->contents = gdbase->elementAsString(index); - _hoverText->setVisible(true); - queue_draw(); + for (Graph::DatasetList::reverse_iterator ritr = dataSets.rbegin(), + end = dataSets.rend(); + ritr != end; + ++ritr) + { + ssize_t index + = (*ritr)->style->dataIndexAtPoint(_mouseX, _mouseY, *ritr, g); + if (index >= 0) + { + _hoverText->contents = (*ritr)->name + + ": " + (*ritr)->elementAsString(index); + _hoverText->setVisible(true); + queue_draw(); + break; } - } + } } return false; } -- cgit