# HG changeset patch # User John W. Eaton # Date 1328202261 18000 # Node ID 17de694961f5f3ac4c73ae5fe48824baad7ae5d9 # Parent 7a7ce92cff5626b56e9d85aa0b0d235e2dee4c03 make panning work for logscale axes * graphics.cc (do_translate): New static function.: * graphics.cc, graphics.h.in (axes::properties): Use it. Args are now beginning and ending coordinates, not deltas. * __init_fltk__.cc (plot_window::handle): Pass beginning and ending * coordinates to translate_view, not deltas. diff -r 7a7ce92cff56 -r 17de694961f5 src/DLD-FUNCTIONS/__init_fltk__.cc --- a/src/DLD-FUNCTIONS/__init_fltk__.cc Thu Feb 02 11:59:50 2012 -0500 +++ b/src/DLD-FUNCTIONS/__init_fltk__.cc Thu Feb 02 12:04:21 2012 -0500 @@ -1301,7 +1301,7 @@ pixel2pos (ax_obj, Fl::event_x (), Fl::event_y (), x1, y1); if (gui_mode == pan_zoom) - ap.translate_view (x0 - x1, y0 - y1); + ap.translate_view (x0, x1, y0, y1); else if (gui_mode == rotate_zoom) { double daz, del; diff -r 7a7ce92cff56 -r 17de694961f5 src/graphics.cc --- a/src/graphics.cc Thu Feb 02 11:59:50 2012 -0500 +++ b/src/graphics.cc Thu Feb 02 12:04:21 2012 -0500 @@ -6659,8 +6659,68 @@ update_ylim (false); } -void -axes::properties::translate_view (double delta_x, double delta_y) +static Matrix +do_translate (double x0, double x1, const Matrix& lims, bool is_logscale) +{ + Matrix new_lims = lims; + + double lo = lims(0); + double hi = lims(1); + + bool is_negative = lo < 0 && hi < 0; + + double delta; + + if (is_logscale) + { + if (is_negative) + { + double tmp = hi; + hi = std::log10 (-lo); + lo = std::log10 (-tmp); + x0 = -x0; + x1 = -x1; + } + else + { + hi = std::log10 (hi); + lo = std::log10 (lo); + } + + delta = std::log10 (x0) - std::log10 (x1); + } + else + { + delta = x0 - x1; + } + + // Perform the translation + lo += delta; + hi += delta; + + if (is_logscale) + { + if (is_negative) + { + double tmp = -std::pow (10.0, hi); + hi = -std::pow (10.0, lo); + lo = tmp; + } + else + { + lo = std::pow (10.0, lo); + hi = std::pow (10.0, hi); + } + } + + new_lims(0) = lo; + new_lims(1) = hi; + + return new_lims; +} + +void +axes::properties::translate_view (double x0, double x1, double y0, double y1) { // FIXME: Do we need error checking here? Matrix xlims = get_xlim ().matrix_value (); @@ -6680,17 +6740,8 @@ double max_neg_y = -octave_Inf; get_children_limits (miny, maxy, min_pos_y, max_neg_y, kids, 'y'); - if (! xscale_is ("log")) - { - xlims (0) += delta_x; - xlims (1) += delta_x; - } - - if (! yscale_is ("log")) - { - ylims (0) += delta_y; - ylims (1) += delta_y; - } + xlims = do_translate (x0, x1, xlims, xscale_is ("log")); + ylims = do_translate (y0, y1, ylims, yscale_is ("log")); zoom (xlims, ylims, false); } diff -r 7a7ce92cff56 -r 17de694961f5 src/graphics.h.in --- a/src/graphics.h.in Thu Feb 02 11:59:50 2012 -0500 +++ b/src/graphics.h.in Thu Feb 02 12:04:21 2012 -0500 @@ -3663,7 +3663,7 @@ void zoom_about_point (double x, double y, double factor, bool push_to_zoom_stack = true); void zoom (const Matrix& xl, const Matrix& yl, bool push_to_zoom_stack = true); - void translate_view (double delta_x, double delta_y); + void translate_view (double x0, double x1, double y0, double y1); void rotate_view (double delta_az, double delta_el); void unzoom (void); void clear_zoom_stack (void);