281 int aw = a.get_width(); |
282 int aw = a.get_width(); |
282 int ah = a.get_height(); |
283 int ah = a.get_height(); |
283 // add some space |
284 // add some space |
284 aw -= 5; if (aw < 0) aw = 0; |
285 aw -= 5; if (aw < 0) aw = 0; |
285 ah -= 5; if (ah < 0) ah = 0; |
286 ah -= 5; if (ah < 0) ah = 0; |
286 //std::cout << "aw=" << aw << " ah=" << ah << std::endl; |
|
287 |
287 |
288 // get the bounding box of the graph |
288 // get the bounding box of the graph |
289 set_pixels_per_unit(1.0); // I don't really understand why this is necessary |
|
290 double wx1, wy1, wx2, wy2; |
289 double wx1, wy1, wx2, wy2; |
291 double cx1, cy1, cx2, cy2; |
|
292 Gnome::Canvas::Item* pCanvasItem = root(); |
290 Gnome::Canvas::Item* pCanvasItem = root(); |
293 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); |
291 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); |
294 //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl; |
|
295 w2c(wx1, wy1, cx1, cy1); |
|
296 w2c(wx2, wy2, cx2, cy2); |
|
297 //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl; |
|
298 //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl; |
|
299 |
292 |
300 // fit the graph to the window |
293 // fit the graph to the window |
301 double ppu1 = (double) aw / fabs(cx2 - cx1); |
294 double ppu1 = (double) aw / fabs(wx2 - wx1); |
302 double ppu2 = (double) ah / fabs(cy2 - cy1); |
295 double ppu2 = (double) ah / fabs(wy2 - wy1); |
303 //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl; |
296 set_pixels_per_unit((ppu1 < ppu2) ? ppu1 : ppu2); |
304 (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2); |
|
305 } |
297 } |
306 |
298 |
307 void GraphDisplayerCanvas::zoom100() |
299 void GraphDisplayerCanvas::zoom100() |
308 { |
300 { |
309 set_pixels_per_unit(1.0); |
301 set_pixels_per_unit(1.0); |
310 } |
302 } |
311 |
303 |
312 void GraphDisplayerCanvas::updateScrollRegion() |
304 void GraphDisplayerCanvas::updateScrollRegion() |
313 { |
305 { |
314 double wx1, wy1, wx2, wy2; |
306 double wx1, wy1, wx2, wy2; |
315 int cx1, cy1, cx2, cy2; |
|
316 Gnome::Canvas::Item* pCanvasItem = root(); |
307 Gnome::Canvas::Item* pCanvasItem = root(); |
317 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); |
308 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2); |
318 w2c(wx1, wy1, cx1, cy1); |
309 set_scroll_region(wx1, wy1, wx2, wy2); |
319 w2c(wx2, wy2, cx2, cy2); |
310 } |
320 set_scroll_region(cx1, cy1, cx2, cy2); |
|
321 } |
|