Node antigravity and edge elasticity based graph layout redesigner.
1 #include "graph_displayer_canvas.h"
4 void GraphDisplayerCanvas::zoomIn()
7 (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
10 propertyChange(false, N_RADIUS);
11 propertyChange(true, E_WIDTH);
15 void GraphDisplayerCanvas::zoomOut()
18 (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
21 propertyChange(true, E_WIDTH);
22 propertyChange(false, N_RADIUS);
26 void GraphDisplayerCanvas::zoomFit()
30 // get the height and width of the canvas
31 Gtk::Allocation a = get_allocation();
32 int aw = a.get_width();
33 int ah = a.get_height();
35 // get the bounding box of the graph
37 double x1, y1, x2, y2;
38 root()->get_bounds(x1, y1, x2, y2);
40 // fit the graph to the window
41 double ppu1 = (double) aw / fabs(x2 - x1);
42 double ppu2 = (double) ah / fabs(y2 - y1);
43 set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2);
47 propertyChange(true, E_WIDTH);
48 propertyChange(false, N_RADIUS);
52 void GraphDisplayerCanvas::zoom100()
55 set_pixels_per_unit(1.0);
59 propertyChange(true, E_WIDTH);
60 propertyChange(false, N_RADIUS);
64 void GraphDisplayerCanvas::updateScrollRegion()
66 // get_bounds() yields something sane only when no updates are pending
67 // and it returns a sufficient, not an exact bounding box
69 double x1, y1, x2, y2;
70 root()->get_bounds(x1, y1, x2, y2);
71 set_scroll_region(x1, y1, x2, y2);