From bb91631807ad833a92d011895ad7ca1872e02745 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 29 Jul 2009 13:11:10 +0200 Subject: Draw multiple graphs * grapher/Graph.cxx (Graph constructor): Initialize graph dimensions. (draw): Don't clear the drawing area. * grapher/GraphWidget.hxx (GraphWidget): Add dimensions and on_size_request() method. * grapher/GraphWidget.cxx (GraphWidget constructor): Initialize dimensions. (addGraph): New method. (on_size_request): New method to pass widget's size to parent widgets * grapher/grapher.cxx (GrapherWindow constructor): add "add graph" action. (addGraph): New method. --- grapher/Graph.cxx | 7 ++----- grapher/GraphWidget.cxx | 26 +++++++++++++++++++++++--- grapher/GraphWidget.hxx | 4 ++++ grapher/grapher.cxx | 10 ++++++++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/grapher/Graph.cxx b/grapher/Graph.cxx index e1ea01f6..7f9b2607 100644 --- a/grapher/Graph.cxx +++ b/grapher/Graph.cxx @@ -10,7 +10,8 @@ namespace systemtap using namespace std::tr1; Graph::Graph(double x, double y) - : _graphX(0), _graphY(0), + : _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) @@ -78,10 +79,6 @@ namespace systemtap double horizScale = _zoomFactor * _graphWidth / ( _right - _left); cr->translate(20.0, 0.0); cr->set_line_width(_lineWidth); - cr->save(); - cr->set_source_rgba(0.0, 0.0, 0.0, 1.0); - cr->paint(); - cr->restore(); for (DatasetList::iterator itr = _datasets.begin(), e = _datasets.end(); itr != e; diff --git a/grapher/GraphWidget.cxx b/grapher/GraphWidget.cxx index 53c7645d..c4613fd7 100644 --- a/grapher/GraphWidget.cxx +++ b/grapher/GraphWidget.cxx @@ -12,7 +12,7 @@ namespace systemtap using namespace std::tr1; GraphWidget::GraphWidget() - : _trackingDrag(false) + : _trackingDrag(false), _width(600), _height(200) { add_events(Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::SCROLL_MASK); @@ -33,8 +33,6 @@ namespace systemtap .connect(sigc::mem_fun(*this, &GraphWidget::on_scroll_event), false); // Temporary testing of multiple graphs shared_ptr graph(new Graph); - graph->_graphHeight = 180; - graph->_graphWidth = 580; _graphs.push_back(graph); } @@ -46,6 +44,22 @@ namespace systemtap { _graphs[0]->addGraphData(data); } + + void GraphWidget::addGraph() + { + shared_ptr graph(new Graph); + double x = 0.0; + double y = 0.0; + if (!_graphs.empty()) + { + _graphs.back()->getOrigin(x, y); + y += _graphs.back()->_height + 10; + _height = y + graph->_height; + } + graph->setOrigin(x, y); + _graphs.push_back(graph); + queue_resize(); + } bool GraphWidget::on_expose_event(GdkEventExpose* event) { @@ -174,4 +188,10 @@ namespace systemtap queue_draw(); return true; } + + void GraphWidget::on_size_request(Gtk::Requisition* req) + { + req->width = _width; + req->height = _height; + } } diff --git a/grapher/GraphWidget.hxx b/grapher/GraphWidget.hxx index c15f8fcd..25476f5f 100644 --- a/grapher/GraphWidget.hxx +++ b/grapher/GraphWidget.hxx @@ -18,6 +18,7 @@ namespace systemtap GraphWidget(); virtual ~GraphWidget(); void addGraphData(std::tr1::shared_ptr data); + void addGraph(); protected: typedef std::vector > GraphList; @@ -34,11 +35,14 @@ namespace systemtap virtual bool on_button_release_event(GdkEventButton* event); virtual bool on_scroll_event(GdkEventScroll* event); bool on_timeout(); + virtual void on_size_request(Gtk::Requisition* req); bool _trackingDrag; double _dragOriginX; double _dragOriginY; double _dragOrigLeft; double _dragOrigRight; + double _width; + double _height; }; } #endif // SYSTEMTAP_GRAPHWIDGET_H diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index 95ac232d..ad7023f2 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -32,6 +32,7 @@ public: GraphWidget w; protected: virtual void on_menu_file_quit(); + void addGraph(); // menu support Glib::RefPtr m_refUIManager; Glib::RefPtr m_refActionGroup; @@ -48,6 +49,8 @@ GrapherWindow::GrapherWindow() m_refActionGroup = Gtk::ActionGroup::create(); //File menu: m_refActionGroup->add(Gtk::Action::create("FileMenu", "File")); + m_refActionGroup->add(Gtk::Action::create("AddGraph", "Add graph"), + sigc::mem_fun(*this, &GrapherWindow::addGraph)); m_refActionGroup->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), sigc::mem_fun(*this, &GrapherWindow::on_menu_file_quit)); m_refUIManager = Gtk::UIManager::create(); @@ -59,6 +62,7 @@ GrapherWindow::GrapherWindow() "" " " " " + " " " " " " " " @@ -136,3 +140,9 @@ int main(int argc, char** argv) ; return 0; } + +void GrapherWindow::addGraph() +{ + w.addGraph(); + +} -- cgit