From 5891de489db0e172162279247fb633a719fa3756 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 7 Dec 2009 12:43:56 +0100 Subject: option to display graph times relative to the start time This avoids having humongous numbers displayed on the graphs' x axis. Also, the dialog for adding a data set to a graph was cleaned up. * grapher/graph-dialog.glade: Add check box for display of relative time and a label for the data set list. Force the list of data sets to be larger. * grapher/Graph.hxx (_timeBase): new member * grapher/Graph.cxx (draw): Subtract _timeBase from displayed time value. * grapher/GraphWidget.hxx (DataModelColumns): Add a column for a data set's title, which is optional at the moment. * grapher/GraphWidget.hxx (_globalTimeBase, _timeBaseInitialized, _relativeTimesButton, _displayRelativeTimes): new members * grapher/GraphWidget.hxx (GraphWidget): Hook up check button for displaying relative time. (on_expose_event): Determine base time if needed; set base time in graphs. (onDataDialogOpen): Insert graph data set's name (key) and title into the list of data sets. --- grapher/Graph.cxx | 4 ++-- grapher/Graph.hxx | 1 + grapher/GraphWidget.cxx | 46 ++++++++++++++++++++++++++++++++++++++++++---- grapher/GraphWidget.hxx | 7 +++++++ grapher/graph-dialog.glade | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 6 deletions(-) (limited to 'grapher') diff --git a/grapher/Graph.cxx b/grapher/Graph.cxx index b3429ef7..baa1182f 100644 --- a/grapher/Graph.cxx +++ b/grapher/Graph.cxx @@ -14,7 +14,7 @@ namespace systemtap _graphWidth(580), _graphHeight(180), _lineWidth(2), _autoScaling(true), _autoScrolling(true), _zoomFactor(1.0), _xOffset(20.0), _yOffset(0.0), - _playButton(new CairoPlayButton), + _playButton(new CairoPlayButton), _timeBase(0), _left(0), _right(1), _top(5.0), _bottom(0.0) { setOrigin(x, y); @@ -150,7 +150,7 @@ namespace systemtap cr->move_to(x, _yOffset); cr->line_to(x, _graphHeight); std::ostringstream stream; - stream << tickVal; + stream << (tickVal - _timeBase); Cairo::TextExtents extents; cr->get_text_extents(stream.str(), extents); // Room for this label? diff --git a/grapher/Graph.hxx b/grapher/Graph.hxx index 044a66d3..93e23deb 100644 --- a/grapher/Graph.hxx +++ b/grapher/Graph.hxx @@ -39,6 +39,7 @@ namespace systemtap double _xOffset; double _yOffset; std::tr1::shared_ptr _playButton; + int64_t _timeBase; DatasetList& getDatasets() { return _datasets; } int64_t getTimeAtPoint(double x); void window2GraphCoords(double x, double y, double& xgraph, double& ygraph); diff --git a/grapher/GraphWidget.cxx b/grapher/GraphWidget.cxx index cfec0adf..9d5e12f8 100644 --- a/grapher/GraphWidget.cxx +++ b/grapher/GraphWidget.cxx @@ -4,6 +4,9 @@ #include #include +#define __STDC_LIMIT_MACROS +#include + #include #include #include @@ -22,7 +25,7 @@ namespace systemtap GraphWidget::GraphWidget() : _trackingDrag(false), _width(600), _height(200), _mouseX(0.0), - _mouseY(0.0) + _mouseY(0.0), _globalTimeBase(0), _timeBaseInitialized(false) { add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::SCROLL_MASK); @@ -70,6 +73,14 @@ namespace systemtap _listStore = Gtk::ListStore::create(_dataColumns); _dataTreeView->set_model(_listStore); _dataTreeView->append_column("Data", _dataColumns._dataName); + _dataTreeView->append_column("Title", _dataColumns._dataTitle); + _refXmlDataDialog->get_widget("checkbutton1", _relativeTimesButton); + _relativeTimesButton->signal_clicked() + .connect(sigc::mem_fun(*this, + &GraphWidget::onRelativeTimesButtonClicked)); + // Set button's initial value from that in .glade file + _displayRelativeTimes = _relativeTimesButton->get_active(); + } catch (const Gnome::Glade::XmlError& ex ) { @@ -100,6 +111,7 @@ namespace systemtap shared_ptr graph(new Graph(x, y)); _height = y + graph->_height; graph->setOrigin(x, y); + graph->_timeBase = _globalTimeBase; _graphs.push_back(graph); queue_resize(); } @@ -115,8 +127,29 @@ namespace systemtap cr->save(); cr->set_source_rgba(0.0, 0.0, 0.0, 1.0); cr->paint(); + if (!_timeBaseInitialized && !_graphData.empty()) + { + int64_t earliest = INT64_MAX; + for (GraphDataList::iterator gd = _graphData.begin(), + end = _graphData.end(); + gd != end; + ++gd) + { + if (!(*gd)->times.empty() && (*gd)->times[0] < earliest) + earliest = (*gd)->times[0]; + } + if (earliest != INT64_MAX) + { + _globalTimeBase = earliest; + _timeBaseInitialized = true; + } + } for (GraphList::iterator g = _graphs.begin(); g != _graphs.end(); ++g) { + if (_displayRelativeTimes && _timeBaseInitialized) + (*g)->_timeBase = _globalTimeBase; + else + (*g)->_timeBase = 0.0; double x, y; (*g)->getOrigin(x, y); cr->save(); @@ -269,10 +302,9 @@ namespace systemtap { Gtk::TreeModel::iterator litr = _listStore->append(); Gtk::TreeModel::Row row = *litr; + row[_dataColumns._dataName] = (*itr)->name; if (!(*itr)->title.empty()) - row[_dataColumns._dataName] = (*itr)->title; - else - row[_dataColumns._dataName] = (*itr)->name; + row[_dataColumns._dataTitle] = (*itr)->title; row[_dataColumns._graphData] = *itr; } } @@ -326,4 +358,10 @@ namespace systemtap _hover_timeout_connection = Glib::signal_timeout() .connect(sigc::mem_fun(*this, &GraphWidget::onHoverTimeout), 1000); } + + void GraphWidget::onRelativeTimesButtonClicked() + { + _displayRelativeTimes = _relativeTimesButton->get_active(); + queue_draw(); + } } diff --git a/grapher/GraphWidget.hxx b/grapher/GraphWidget.hxx index 61d50e70..ea10720c 100644 --- a/grapher/GraphWidget.hxx +++ b/grapher/GraphWidget.hxx @@ -19,9 +19,11 @@ namespace systemtap DataModelColumns() { add(_dataName); + add(_dataTitle); add(_graphData); } Gtk::TreeModelColumn _dataName; + Gtk::TreeModelColumn _dataTitle; Gtk::TreeModelColumn > _graphData; }; @@ -72,8 +74,13 @@ namespace systemtap std::tr1::shared_ptr _hoverText; double _mouseX; double _mouseY; + int64_t _globalTimeBase; + bool _timeBaseInitialized; std::tr1::shared_ptr getGraphUnderPoint(double x, double y); void establishHoverTimeout(); + Gtk::CheckButton* _relativeTimesButton; + bool _displayRelativeTimes; + void onRelativeTimesButtonClicked(); }; } #endif // SYSTEMTAP_GRAPHWIDGET_H diff --git a/grapher/graph-dialog.glade b/grapher/graph-dialog.glade index cca2e0e3..85c10128 100644 --- a/grapher/graph-dialog.glade +++ b/grapher/graph-dialog.glade @@ -66,6 +66,31 @@ + + + True + Data sets + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + True @@ -83,6 +108,8 @@ + 200 + 100 True True False @@ -159,6 +186,25 @@ True + + + + True + True + Display relative times + True + GTK_RELIEF_NORMAL + True + True + False + True + + + 0 + False + False + + -- cgit